~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/inspector/front-end/NavigatorView.js

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Google Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are
 
6
 * met:
 
7
 *
 
8
 * 1. Redistributions of source code must retain the above copyright
 
9
 * notice, this list of conditions and the following disclaimer.
 
10
 *
 
11
 * 2. Redistributions in binary form must reproduce the above
 
12
 * copyright notice, this list of conditions and the following disclaimer
 
13
 * in the documentation and/or other materials provided with the
 
14
 * distribution.
 
15
 *
 
16
 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
 
17
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
18
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
19
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
 
20
 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
21
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
22
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
26
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
27
 */
 
28
 
 
29
/**
 
30
 * @extends {WebInspector.View}
 
31
 * @constructor
 
32
 */
 
33
WebInspector.NavigatorView = function()
 
34
{
 
35
    WebInspector.View.call(this);
 
36
    this.registerRequiredCSS("navigatorView.css");
 
37
 
 
38
    this._treeSearchBoxElement = document.createElement("div");
 
39
    this._treeSearchBoxElement.className = "navigator-tree-search-box";
 
40
    this.element.appendChild(this._treeSearchBoxElement);
 
41
 
 
42
    var scriptsTreeElement = document.createElement("ol");
 
43
    this._scriptsTree = new WebInspector.NavigatorTreeOutline(this._treeSearchBoxElement, scriptsTreeElement);
 
44
 
 
45
    var scriptsOutlineElement = document.createElement("div");
 
46
    scriptsOutlineElement.addStyleClass("outline-disclosure");
 
47
    scriptsOutlineElement.addStyleClass("navigator");
 
48
    scriptsOutlineElement.appendChild(scriptsTreeElement);
 
49
 
 
50
    this.element.addStyleClass("fill");
 
51
    this.element.addStyleClass("navigator-container");
 
52
    this.element.appendChild(scriptsOutlineElement);
 
53
    this.setDefaultFocusedElement(this._scriptsTree.element);
 
54
 
 
55
    this._folderTreeElements = {};
 
56
    this._scriptTreeElementsByUISourceCode = new Map();
 
57
 
 
58
    WebInspector.settings.showScriptFolders.addChangeListener(this._showScriptFoldersSettingChanged.bind(this));
 
59
}
 
60
 
 
61
 
 
62
WebInspector.NavigatorView.Events = {
 
63
    ItemSelected: "ItemSelected",
 
64
    FileRenamed: "FileRenamed"
 
65
}
 
66
 
 
67
WebInspector.NavigatorView.prototype = {
 
68
    /**
 
69
     * @param {WebInspector.UISourceCode} uiSourceCode
 
70
     */
 
71
    addUISourceCode: function(uiSourceCode)
 
72
    {
 
73
        if (this._scriptTreeElementsByUISourceCode.get(uiSourceCode))
 
74
            return;
 
75
 
 
76
        var scriptTreeElement = new WebInspector.NavigatorSourceTreeElement(this, uiSourceCode, "");
 
77
        this._scriptTreeElementsByUISourceCode.put(uiSourceCode, scriptTreeElement);
 
78
        this._updateScriptTitle(uiSourceCode);
 
79
        this._addUISourceCodeListeners(uiSourceCode);
 
80
 
 
81
        var folderTreeElement = this.getOrCreateFolderTreeElement(uiSourceCode);
 
82
        folderTreeElement.appendChild(scriptTreeElement);
 
83
    },
 
84
 
 
85
    _uiSourceCodeTitleChanged: function(event)
 
86
    {
 
87
        var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.target);
 
88
        this._updateScriptTitle(uiSourceCode)
 
89
    },
 
90
 
 
91
    _uiSourceCodeWorkingCopyChanged: function(event)
 
92
    {
 
93
        var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.target);
 
94
        this._updateScriptTitle(uiSourceCode)
 
95
    },
 
96
 
 
97
    _uiSourceCodeWorkingCopyCommitted: function(event)
 
98
    {
 
99
        var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.target);
 
100
        this._updateScriptTitle(uiSourceCode)
 
101
    },
 
102
 
 
103
    _uiSourceCodeFormattedChanged: function(event)
 
104
    {
 
105
        var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.target);
 
106
        this._updateScriptTitle(uiSourceCode);
 
107
    },
 
108
 
 
109
    /**
 
110
     * @param {WebInspector.UISourceCode} uiSourceCode
 
111
     * @param {boolean=} ignoreIsDirty
 
112
     */
 
113
    _updateScriptTitle: function(uiSourceCode, ignoreIsDirty)
 
114
    {
 
115
        var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
 
116
        if (!scriptTreeElement)
 
117
            return;
 
118
 
 
119
        var titleText;
 
120
        if (uiSourceCode.parsedURL.isValid) {
 
121
            titleText = uiSourceCode.parsedURL.lastPathComponent;
 
122
            if (uiSourceCode.parsedURL.queryParams)
 
123
                titleText += "?" + uiSourceCode.parsedURL.queryParams;
 
124
        } else if (uiSourceCode.parsedURL)
 
125
            titleText = uiSourceCode.parsedURL.url;
 
126
        if (!titleText)
 
127
            titleText = WebInspector.UIString("(program)");
 
128
        if (!ignoreIsDirty && uiSourceCode.isDirty())
 
129
            titleText = "*" + titleText;
 
130
        scriptTreeElement.titleText = titleText;
 
131
    },
 
132
 
 
133
    /**
 
134
     * @param {WebInspector.UISourceCode} uiSourceCode
 
135
     * @return {boolean}
 
136
     */
 
137
    isScriptSourceAdded: function(uiSourceCode)
 
138
    {
 
139
        var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
 
140
        return !!scriptTreeElement;
 
141
    },
 
142
 
 
143
    /**
 
144
     * @param {WebInspector.UISourceCode} uiSourceCode
 
145
     */
 
146
    revealUISourceCode: function(uiSourceCode)
 
147
    {
 
148
        if (this._scriptsTree.selectedTreeElement)
 
149
            this._scriptsTree.selectedTreeElement.deselect();
 
150
 
 
151
        this._lastSelectedUISourceCode = uiSourceCode;
 
152
 
 
153
        var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
 
154
        scriptTreeElement.revealAndSelect(true);
 
155
    },
 
156
 
 
157
    /**
 
158
     * @param {WebInspector.UISourceCode} uiSourceCode
 
159
     * @param {boolean} focusSource
 
160
     */
 
161
    _scriptSelected: function(uiSourceCode, focusSource)
 
162
    {
 
163
        this._lastSelectedUISourceCode = uiSourceCode;
 
164
        var data = { uiSourceCode: uiSourceCode, focusSource: focusSource};
 
165
        this.dispatchEventToListeners(WebInspector.NavigatorView.Events.ItemSelected, data);
 
166
    },
 
167
 
 
168
    /**
 
169
     * @param {WebInspector.UISourceCode} uiSourceCode
 
170
     */
 
171
    removeUISourceCode: function(uiSourceCode)
 
172
    {
 
173
        var treeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
 
174
        while (treeElement) {
 
175
            var parent = treeElement.parent;
 
176
            if (parent) {
 
177
                if (treeElement instanceof WebInspector.NavigatorFolderTreeElement)
 
178
                    delete this._folderTreeElements[treeElement.folderIdentifier];
 
179
                parent.removeChild(treeElement);
 
180
                if (parent.children.length)
 
181
                    break;
 
182
            }
 
183
            treeElement = parent;
 
184
        }
 
185
        this._scriptTreeElementsByUISourceCode.remove(uiSourceCode);
 
186
        this._removeUISourceCodeListeners(uiSourceCode);
 
187
    },
 
188
 
 
189
    /**
 
190
     * @param {WebInspector.UISourceCode} uiSourceCode
 
191
     */
 
192
    _addUISourceCodeListeners: function(uiSourceCode)
 
193
    {
 
194
        uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleChanged, this);
 
195
        uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWorkingCopyChanged, this);
 
196
        uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWorkingCopyCommitted, this);
 
197
        uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._uiSourceCodeFormattedChanged, this);
 
198
    },
 
199
 
 
200
    /**
 
201
     * @param {WebInspector.UISourceCode} uiSourceCode
 
202
     */
 
203
    _removeUISourceCodeListeners: function(uiSourceCode)
 
204
    {
 
205
        uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleChanged, this);
 
206
        uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWorkingCopyChanged, this);
 
207
        uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWorkingCopyCommitted, this);
 
208
        uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._uiSourceCodeFormattedChanged, this);
 
209
    },
 
210
 
 
211
    _showScriptFoldersSettingChanged: function()
 
212
    {
 
213
        var uiSourceCodes = this._scriptsTree.scriptTreeElements();
 
214
        this.reset();
 
215
 
 
216
        for (var i = 0; i < uiSourceCodes.length; ++i)
 
217
            this.addUISourceCode(uiSourceCodes[i]);
 
218
 
 
219
        if (this._lastSelectedUISourceCode)
 
220
            this.revealUISourceCode(this._lastSelectedUISourceCode);
 
221
    },
 
222
 
 
223
    _fileRenamed: function(uiSourceCode, newTitle)
 
224
    {    
 
225
        var data = { uiSourceCode: uiSourceCode, name: newTitle };
 
226
        this.dispatchEventToListeners(WebInspector.NavigatorView.Events.FileRenamed, data);
 
227
    },
 
228
 
 
229
    /**
 
230
     * @param {WebInspector.UISourceCode} uiSourceCode
 
231
     * @param {function(boolean)=} callback
 
232
     */
 
233
    rename: function(uiSourceCode, callback)
 
234
    {
 
235
        var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
 
236
        if (!scriptTreeElement)
 
237
            return;
 
238
 
 
239
        // Tree outline should be marked as edited as well as the tree element to prevent search from starting.
 
240
        var treeOutlineElement = scriptTreeElement.treeOutline.element;
 
241
        WebInspector.markBeingEdited(treeOutlineElement, true);
 
242
 
 
243
        function commitHandler(element, newTitle, oldTitle)
 
244
        {
 
245
            if (newTitle && newTitle !== oldTitle)
 
246
                this._fileRenamed(uiSourceCode, newTitle);
 
247
            afterEditing.call(this, true);
 
248
        }
 
249
 
 
250
        function cancelHandler()
 
251
        {
 
252
            afterEditing.call(this, false);
 
253
        }
 
254
 
 
255
        /**
 
256
         * @param {boolean} committed
 
257
         */
 
258
        function afterEditing(committed)
 
259
        {
 
260
            WebInspector.markBeingEdited(treeOutlineElement, false);
 
261
            this._updateScriptTitle(uiSourceCode);
 
262
            if (callback)
 
263
                callback(committed);
 
264
        }
 
265
 
 
266
        var editingConfig = new WebInspector.EditingConfig(commitHandler.bind(this), cancelHandler.bind(this));
 
267
        this._updateScriptTitle(uiSourceCode, true);
 
268
        WebInspector.startEditing(scriptTreeElement.titleElement, editingConfig);
 
269
        window.getSelection().setBaseAndExtent(scriptTreeElement.titleElement, 0, scriptTreeElement.titleElement, 1);
 
270
    },
 
271
 
 
272
    reset: function()
 
273
    {
 
274
        var uiSourceCodes = this._scriptsTree.scriptTreeElements;
 
275
        for (var i = 0; i < uiSourceCodes.length; ++i)
 
276
            this._removeUISourceCodeListeners(uiSourceCodes[i]);
 
277
 
 
278
        this._scriptsTree.stopSearch();
 
279
        this._scriptsTree.removeChildren();
 
280
        this._folderTreeElements = {};
 
281
        this._scriptTreeElementsByUISourceCode.clear();
 
282
    },
 
283
 
 
284
    /**
 
285
     * @param {string} folderIdentifier
 
286
     * @param {string} domain
 
287
     * @param {string} folderName
 
288
     */
 
289
    createFolderTreeElement: function(parentFolderElement, folderIdentifier, domain, folderName)
 
290
    {
 
291
        var folderTreeElement = new WebInspector.NavigatorFolderTreeElement(folderIdentifier, domain, folderName);
 
292
        parentFolderElement.appendChild(folderTreeElement);
 
293
        this._folderTreeElements[folderIdentifier] = folderTreeElement;
 
294
        return folderTreeElement;
 
295
    },
 
296
 
 
297
    /**
 
298
     * @param {WebInspector.UISourceCode} uiSourceCode
 
299
     */
 
300
    getOrCreateFolderTreeElement: function(uiSourceCode)
 
301
    {
 
302
        return this._getOrCreateFolderTreeElement(uiSourceCode.parsedURL.host, uiSourceCode.parsedURL.folderPathComponents);
 
303
    },
 
304
 
 
305
    /**
 
306
     * @param {string} domain
 
307
     * @param {string} folderName
 
308
     */
 
309
    _getOrCreateFolderTreeElement: function(domain, folderName)
 
310
    {
 
311
        var folderIdentifier = domain + "/" + folderName;
 
312
        
 
313
        if (this._folderTreeElements[folderIdentifier])
 
314
            return this._folderTreeElements[folderIdentifier];
 
315
 
 
316
        var showScriptFolders = WebInspector.settings.showScriptFolders.get();
 
317
 
 
318
        if ((!domain && !folderName) || !showScriptFolders)
 
319
            return this._scriptsTree;
 
320
 
 
321
        var parentFolderElement;
 
322
        if (!folderName)
 
323
            parentFolderElement = this._scriptsTree;
 
324
        else
 
325
            parentFolderElement = this._getOrCreateFolderTreeElement(domain, "");
 
326
        
 
327
        return this.createFolderTreeElement(parentFolderElement, folderIdentifier, domain, folderName);
 
328
    },
 
329
 
 
330
    handleContextMenu: function(event, uiSourceCode)
 
331
    {
 
332
        var contextMenu = new WebInspector.ContextMenu(event);
 
333
        contextMenu.appendApplicableItems(uiSourceCode);
 
334
        contextMenu.show();
 
335
    },
 
336
 
 
337
    __proto__: WebInspector.View.prototype
 
338
}
 
339
 
 
340
/**
 
341
 * @constructor
 
342
 * @extends {TreeOutline}
 
343
 * @param {Element} treeSearchBoxElement
 
344
 * @param {Element} element
 
345
 */
 
346
WebInspector.NavigatorTreeOutline = function(treeSearchBoxElement, element)
 
347
{
 
348
    TreeOutline.call(this, element);
 
349
    this.element = element;
 
350
 
 
351
    this._treeSearchBoxElement = treeSearchBoxElement;
 
352
    
 
353
    this.comparator = WebInspector.NavigatorTreeOutline._treeElementsCompare;
 
354
 
 
355
    this.searchable = true;
 
356
    this.searchInputElement = document.createElement("input");
 
357
}
 
358
 
 
359
WebInspector.NavigatorTreeOutline._treeElementsCompare = function compare(treeElement1, treeElement2)
 
360
{
 
361
    // Insert in the alphabetical order, first domains, then folders, then scripts.
 
362
    function typeWeight(treeElement)
 
363
    {
 
364
        if (treeElement instanceof WebInspector.NavigatorFolderTreeElement) {
 
365
            if (treeElement.isDomain) {
 
366
                if (treeElement.titleText === WebInspector.inspectedPageDomain)
 
367
                    return 1;
 
368
                return 2;
 
369
            }
 
370
            return 3;
 
371
        }
 
372
        return 4;
 
373
    }
 
374
 
 
375
    var typeWeight1 = typeWeight(treeElement1);
 
376
    var typeWeight2 = typeWeight(treeElement2);
 
377
 
 
378
    var result;
 
379
    if (typeWeight1 > typeWeight2)
 
380
        result = 1;
 
381
    else if (typeWeight1 < typeWeight2)
 
382
        result = -1;
 
383
    else {
 
384
        var title1 = treeElement1.titleText;
 
385
        var title2 = treeElement2.titleText;
 
386
        result = title1.localeCompare(title2);
 
387
    }
 
388
    return result;
 
389
}
 
390
 
 
391
WebInspector.NavigatorTreeOutline.prototype = {
 
392
   /**
 
393
    * @return {Array.<WebInspector.UISourceCode>}
 
394
    */
 
395
   scriptTreeElements: function()
 
396
   {
 
397
       var result = [];
 
398
       if (this.children.length) {
 
399
           for (var treeElement = this.children[0]; treeElement; treeElement = treeElement.traverseNextTreeElement(false, this, true)) {
 
400
               if (treeElement instanceof WebInspector.NavigatorSourceTreeElement)
 
401
                   result.push(treeElement.uiSourceCode);
 
402
           }
 
403
       }
 
404
       return result;
 
405
   },
 
406
 
 
407
   searchStarted: function()
 
408
   {
 
409
       this._treeSearchBoxElement.appendChild(this.searchInputElement);
 
410
       this._treeSearchBoxElement.addStyleClass("visible");
 
411
   },
 
412
 
 
413
   searchFinished: function()
 
414
   {
 
415
       this._treeSearchBoxElement.removeChild(this.searchInputElement);
 
416
       this._treeSearchBoxElement.removeStyleClass("visible");
 
417
   },
 
418
 
 
419
    __proto__: TreeOutline.prototype
 
420
}
 
421
 
 
422
/**
 
423
 * @constructor
 
424
 * @extends {TreeElement}
 
425
 * @param {string} title
 
426
 * @param {Array.<string>} iconClasses
 
427
 * @param {boolean} hasChildren
 
428
 * @param {boolean=} noIcon
 
429
 */
 
430
WebInspector.BaseNavigatorTreeElement = function(title, iconClasses, hasChildren, noIcon)
 
431
{
 
432
    TreeElement.call(this, "", null, hasChildren);
 
433
    this._titleText = title;
 
434
    this._iconClasses = iconClasses;
 
435
    this._noIcon = noIcon;
 
436
}
 
437
 
 
438
WebInspector.BaseNavigatorTreeElement.prototype = {
 
439
    onattach: function()
 
440
    {
 
441
        this.listItemElement.removeChildren();
 
442
        if (this._iconClasses) {
 
443
            for (var i = 0; i < this._iconClasses.length; ++i)
 
444
                this.listItemElement.addStyleClass(this._iconClasses[i]);
 
445
        }
 
446
 
 
447
        var selectionElement = document.createElement("div");
 
448
        selectionElement.className = "selection";
 
449
        this.listItemElement.appendChild(selectionElement);
 
450
 
 
451
        if (!this._noIcon) {
 
452
            this.imageElement = document.createElement("img");
 
453
            this.imageElement.className = "icon";
 
454
            this.listItemElement.appendChild(this.imageElement);
 
455
        }
 
456
        
 
457
        this.titleElement = document.createElement("div");
 
458
        this.titleElement.className = "base-navigator-tree-element-title";
 
459
        this._titleTextNode = document.createTextNode("");
 
460
        this._titleTextNode.textContent = this._titleText;
 
461
        this.titleElement.appendChild(this._titleTextNode);
 
462
        this.listItemElement.appendChild(this.titleElement);
 
463
        this.expand();
 
464
    },
 
465
 
 
466
    onreveal: function()
 
467
    {
 
468
        if (this.listItemElement)
 
469
            this.listItemElement.scrollIntoViewIfNeeded(true);
 
470
    },
 
471
 
 
472
    /**
 
473
     * @return {string}
 
474
     */
 
475
    get titleText()
 
476
    {
 
477
        return this._titleText;
 
478
    },
 
479
 
 
480
    set titleText(titleText)
 
481
    {
 
482
        if (this._titleText === titleText)
 
483
            return;
 
484
        this._titleText = titleText || "";
 
485
        if (this.titleElement)
 
486
            this.titleElement.textContent = this._titleText;
 
487
    },
 
488
    
 
489
    /**
 
490
     * @param {string} searchText
 
491
     */
 
492
    matchesSearchText: function(searchText)
 
493
    {
 
494
        return this.titleText.match(new RegExp("^" + searchText.escapeForRegExp(), "i"));
 
495
    },
 
496
 
 
497
    __proto__: TreeElement.prototype
 
498
}
 
499
 
 
500
/**
 
501
 * @constructor
 
502
 * @extends {WebInspector.BaseNavigatorTreeElement}
 
503
 * @param {string} folderIdentifier
 
504
 * @param {string} domain
 
505
 * @param {string} folderName
 
506
 */
 
507
WebInspector.NavigatorFolderTreeElement = function(folderIdentifier, domain, folderName)
 
508
{
 
509
    this._folderIdentifier = folderIdentifier;
 
510
    this._folderName = folderName;
 
511
    
 
512
    var iconClass = this.isDomain ? "navigator-domain-tree-item" : "navigator-folder-tree-item";
 
513
    var title = this.isDomain ? domain : folderName.substring(1);
 
514
 
 
515
    WebInspector.BaseNavigatorTreeElement.call(this, title, [iconClass], true);
 
516
    this.tooltip = folderName;
 
517
}
 
518
 
 
519
WebInspector.NavigatorFolderTreeElement.prototype = {
 
520
    /**
 
521
     * @return {string}
 
522
     */
 
523
    get folderIdentifier()
 
524
    {
 
525
        return this._folderIdentifier;
 
526
    },
 
527
 
 
528
    /**
 
529
     * @return {boolean}
 
530
     */
 
531
    get isDomain()
 
532
    {
 
533
        return this._folderName === "";
 
534
    },
 
535
    
 
536
    onattach: function()
 
537
    {
 
538
        WebInspector.BaseNavigatorTreeElement.prototype.onattach.call(this);
 
539
        if (this.isDomain && this.titleText != WebInspector.inspectedPageDomain)
 
540
            this.collapse();
 
541
        else
 
542
            this.expand();
 
543
    },
 
544
 
 
545
    __proto__: WebInspector.BaseNavigatorTreeElement.prototype
 
546
}
 
547
 
 
548
/**
 
549
 * @constructor
 
550
 * @extends {WebInspector.BaseNavigatorTreeElement}
 
551
 * @param {WebInspector.NavigatorView} navigatorView
 
552
 * @param {WebInspector.UISourceCode} uiSourceCode
 
553
 * @param {string} title
 
554
 */
 
555
WebInspector.NavigatorSourceTreeElement = function(navigatorView, uiSourceCode, title)
 
556
{
 
557
    WebInspector.BaseNavigatorTreeElement.call(this, title, ["navigator-" + uiSourceCode.contentType().name() + "-tree-item"], false);
 
558
    this._navigatorView = navigatorView;
 
559
    this._uiSourceCode = uiSourceCode;
 
560
    this.tooltip = uiSourceCode.url;
 
561
}
 
562
 
 
563
WebInspector.NavigatorSourceTreeElement.prototype = {
 
564
    /**
 
565
     * @return {WebInspector.UISourceCode}
 
566
     */
 
567
    get uiSourceCode()
 
568
    {
 
569
        return this._uiSourceCode;
 
570
    },
 
571
 
 
572
    onattach: function()
 
573
    {
 
574
        WebInspector.BaseNavigatorTreeElement.prototype.onattach.call(this);
 
575
        this.listItemElement.draggable = true;
 
576
        this.listItemElement.addEventListener("click", this._onclick.bind(this), false);
 
577
        this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), false);
 
578
        this.listItemElement.addEventListener("mousedown", this._onmousedown.bind(this), false);
 
579
        this.listItemElement.addEventListener("dragstart", this._ondragstart.bind(this), false);
 
580
    },
 
581
 
 
582
    _onmousedown: function(event)
 
583
    {
 
584
        if (event.which === 1) // Warm-up data for drag'n'drop
 
585
            this._uiSourceCode.requestContent(callback.bind(this));
 
586
        /**
 
587
         * @param {?string} content
 
588
         * @param {boolean} contentEncoded
 
589
         * @param {string} mimeType
 
590
         */
 
591
        function callback(content, contentEncoded, mimeType)
 
592
        {
 
593
            this._warmedUpContent = content;
 
594
        }
 
595
    },
 
596
 
 
597
    _ondragstart: function(event)
 
598
    {
 
599
        event.dataTransfer.setData("text/plain", this._warmedUpContent);
 
600
        event.dataTransfer.effectAllowed = "copy";
 
601
        return true;
 
602
    },
 
603
 
 
604
    onspace: function()
 
605
    {
 
606
        this._navigatorView._scriptSelected(this.uiSourceCode, true);
 
607
        return true;
 
608
    },
 
609
 
 
610
    /**
 
611
     * @param {Event} event
 
612
     */
 
613
    _onclick: function(event)
 
614
    {
 
615
        this._navigatorView._scriptSelected(this.uiSourceCode, false);
 
616
    },
 
617
 
 
618
    /**
 
619
     * @param {Event} event
 
620
     */
 
621
    ondblclick: function(event)
 
622
    {
 
623
        var middleClick = event.button === 1;
 
624
        this._navigatorView._scriptSelected(this.uiSourceCode, !middleClick);
 
625
    },
 
626
 
 
627
    onenter: function()
 
628
    {
 
629
        this._navigatorView._scriptSelected(this.uiSourceCode, true);
 
630
        return true;
 
631
    },
 
632
 
 
633
    /**
 
634
     * @param {Event} event
 
635
     */
 
636
    _handleContextMenuEvent: function(event)
 
637
    {
 
638
        this._navigatorView.handleContextMenu(event, this._uiSourceCode);
 
639
    },
 
640
 
 
641
    __proto__: WebInspector.BaseNavigatorTreeElement.prototype
 
642
}