Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: chrome/resources/Inspector/inspector.js

Issue 334023: Remove Inspector directory in prep for ref build rev. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/reference_builds/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com).
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 var Preferences = {
31 ignoreWhitespace: true,
32 showUserAgentStyles: true,
33 maxInlineTextChildLength: 80,
34 minConsoleHeight: 75,
35 minSidebarWidth: 100,
36 minElementsSidebarWidth: 200,
37 minScriptsSidebarWidth: 200,
38 showInheritedComputedStyleProperties: false,
39 styleRulesExpandedState: {},
40 showMissingLocalizedStrings: false
41 }
42
43 var WebInspector = {
44 resources: [],
45 resourceURLMap: {},
46 missingLocalizedStrings: {},
47
48 get previousFocusElement()
49 {
50 return this._previousFocusElement;
51 },
52
53 get currentFocusElement()
54 {
55 return this._currentFocusElement;
56 },
57
58 set currentFocusElement(x)
59 {
60 if (this._currentFocusElement !== x)
61 this._previousFocusElement = this._currentFocusElement;
62 this._currentFocusElement = x;
63
64 if (this._currentFocusElement) {
65 this._currentFocusElement.focus();
66
67 // Make a caret selection inside the new element if there isn't a ra nge selection and
68 // there isn't already a caret selection inside.
69 var selection = window.getSelection();
70 if (selection.isCollapsed && !this._currentFocusElement.isInsertionC aretInside()) {
71 var selectionRange = document.createRange();
72 selectionRange.setStart(this._currentFocusElement, 0);
73 selectionRange.setEnd(this._currentFocusElement, 0);
74
75 selection.removeAllRanges();
76 selection.addRange(selectionRange);
77 }
78 } else if (this._previousFocusElement)
79 this._previousFocusElement.blur();
80 },
81
82 get currentPanel()
83 {
84 return this._currentPanel;
85 },
86
87 set currentPanel(x)
88 {
89 if (this._currentPanel === x)
90 return;
91
92 if (this._currentPanel)
93 this._currentPanel.hide();
94
95 this._currentPanel = x;
96
97 this.updateSearchLabel();
98
99 if (x) {
100 x.show();
101
102 if (this.currentQuery) {
103 if (x.performSearch) {
104 function performPanelSearch()
105 {
106 this.updateSearchMatchesCount();
107
108 x.currentQuery = this.currentQuery;
109 x.performSearch(this.currentQuery);
110 }
111
112 // Perform the search on a timeout so the panel switches fas t.
113 setTimeout(performPanelSearch.bind(this), 0);
114 } else {
115 // Update to show Not found for panels that can't be searche d.
116 this.updateSearchMatchesCount();
117 }
118 }
119 }
120 },
121
122 get attached()
123 {
124 return this._attached;
125 },
126
127 set attached(x)
128 {
129 if (this._attached === x)
130 return;
131
132 this._attached = x;
133
134 this.updateSearchLabel();
135
136 var dockToggleButton = document.getElementById("dock-status-bar-item");
137 var body = document.body;
138
139 if (x) {
140 InspectorController.attach();
141 body.removeStyleClass("detached");
142 body.addStyleClass("attached");
143 dockToggleButton.title = WebInspector.UIString("Undock into separate window.");
144 } else {
145 InspectorController.detach();
146 body.removeStyleClass("attached");
147 body.addStyleClass("detached");
148 dockToggleButton.title = WebInspector.UIString("Dock to main window. ");
149 }
150 },
151
152 get errors()
153 {
154 return this._errors || 0;
155 },
156
157 set errors(x)
158 {
159 x = Math.max(x, 0);
160
161 if (this._errors === x)
162 return;
163 this._errors = x;
164 this._updateErrorAndWarningCounts();
165 },
166
167 get warnings()
168 {
169 return this._warnings || 0;
170 },
171
172 set warnings(x)
173 {
174 x = Math.max(x, 0);
175
176 if (this._warnings === x)
177 return;
178 this._warnings = x;
179 this._updateErrorAndWarningCounts();
180 },
181
182 _updateErrorAndWarningCounts: function()
183 {
184 var errorWarningElement = document.getElementById("error-warning-count") ;
185 if (!errorWarningElement)
186 return;
187
188 if (!this.errors && !this.warnings) {
189 errorWarningElement.addStyleClass("hidden");
190 return;
191 }
192
193 errorWarningElement.removeStyleClass("hidden");
194
195 errorWarningElement.removeChildren();
196
197 if (this.errors) {
198 var errorElement = document.createElement("span");
199 errorElement.id = "error-count";
200 errorElement.textContent = this.errors;
201 errorWarningElement.appendChild(errorElement);
202 }
203
204 if (this.warnings) {
205 var warningsElement = document.createElement("span");
206 warningsElement.id = "warning-count";
207 warningsElement.textContent = this.warnings;
208 errorWarningElement.appendChild(warningsElement);
209 }
210
211 if (this.errors) {
212 if (this.warnings) {
213 if (this.errors == 1) {
214 if (this.warnings == 1)
215 errorWarningElement.title = WebInspector.UIString("%d er ror, %d warning", this.errors, this.warnings);
216 else
217 errorWarningElement.title = WebInspector.UIString("%d er ror, %d warnings", this.errors, this.warnings);
218 } else if (this.warnings == 1)
219 errorWarningElement.title = WebInspector.UIString("%d errors , %d warning", this.errors, this.warnings);
220 else
221 errorWarningElement.title = WebInspector.UIString("%d errors , %d warnings", this.errors, this.warnings);
222 } else if (this.errors == 1)
223 errorWarningElement.title = WebInspector.UIString("%d error", th is.errors);
224 else
225 errorWarningElement.title = WebInspector.UIString("%d errors", t his.errors);
226 } else if (this.warnings == 1)
227 errorWarningElement.title = WebInspector.UIString("%d warning", this .warnings);
228 else if (this.warnings)
229 errorWarningElement.title = WebInspector.UIString("%d warnings", thi s.warnings);
230 else
231 errorWarningElement.title = null;
232 },
233
234 get hoveredDOMNode()
235 {
236 return this._hoveredDOMNode;
237 },
238
239 set hoveredDOMNode(x)
240 {
241 if (objectsAreSame(this._hoveredDOMNode, x))
242 return;
243
244 this._hoveredDOMNode = x;
245
246 if (this._hoveredDOMNode)
247 this._updateHoverHighlightSoon(this.showingDOMNodeHighlight ? 50 : 5 00);
248 else
249 this._updateHoverHighlight();
250 },
251
252 _updateHoverHighlightSoon: function(delay)
253 {
254 if ("_updateHoverHighlightTimeout" in this)
255 clearTimeout(this._updateHoverHighlightTimeout);
256 this._updateHoverHighlightTimeout = setTimeout(this._updateHoverHighligh t.bind(this), delay);
257 },
258
259 _updateHoverHighlight: function()
260 {
261 if ("_updateHoverHighlightTimeout" in this) {
262 clearTimeout(this._updateHoverHighlightTimeout);
263 delete this._updateHoverHighlightTimeout;
264 }
265
266 if (this._hoveredDOMNode) {
267 InspectorController.highlightDOMNode(this._hoveredDOMNode);
268 this.showingDOMNodeHighlight = true;
269 } else {
270 InspectorController.hideDOMNodeHighlight();
271 this.showingDOMNodeHighlight = false;
272 }
273 }
274 }
275
276 WebInspector.loaded = function()
277 {
278 var platform = InspectorController.platform();
279 document.body.addStyleClass("platform-" + platform);
280
281 this.console = new WebInspector.Console();
282 this.panels = {
283 elements: new WebInspector.ElementsPanel(),
284 resources: new WebInspector.ResourcesPanel(),
285 // We don't use next tabs, so don't show them.
286 //scripts: new WebInspector.ScriptsPanel(),
287 //profiles: new WebInspector.ProfilesPanel(),
288 //databases: new WebInspector.DatabasesPanel()
289 };
290
291 var toolbarElement = document.getElementById("toolbar");
292 var previousToolbarItem = toolbarElement.children[0];
293
294 for (var panelName in this.panels) {
295 var panel = this.panels[panelName];
296 var panelToolbarItem = panel.toolbarItem;
297 panelToolbarItem.addEventListener("click", this._toolbarItemClicked.bind (this));
298 if (previousToolbarItem)
299 toolbarElement.insertBefore(panelToolbarItem, previousToolbarItem.ne xtSibling);
300 else
301 toolbarElement.insertBefore(panelToolbarItem, toolbarElement.firstCh ild);
302 previousToolbarItem = panelToolbarItem;
303 }
304
305 this.currentPanel = this.panels.elements;
306
307 this.resourceCategories = {
308 documents: new WebInspector.ResourceCategory(WebInspector.UIString("Docu ments"), "documents"),
309 stylesheets: new WebInspector.ResourceCategory(WebInspector.UIString("St ylesheets"), "stylesheets"),
310 images: new WebInspector.ResourceCategory(WebInspector.UIString("Images" ), "images"),
311 scripts: new WebInspector.ResourceCategory(WebInspector.UIString("Script s"), "scripts"),
312 xhr: new WebInspector.ResourceCategory(WebInspector.UIString("XHR"), "xh r"),
313 fonts: new WebInspector.ResourceCategory(WebInspector.UIString("Fonts"), "fonts"),
314 other: new WebInspector.ResourceCategory(WebInspector.UIString("Other"), "other")
315 };
316
317 this.Tips = {
318 ResourceNotCompressed: {id: 0, message: WebInspector.UIString("You could save bandwidth by having your web server compress this transfer with gzip or zl ib.")}
319 };
320
321 this.Warnings = {
322 IncorrectMIMEType: {id: 0, message: WebInspector.UIString("Resource inte rpreted as %s but transferred with MIME type %s.")}
323 };
324
325 this.addMainEventListeners(document);
326
327 window.addEventListener("unload", this.windowUnload.bind(this), true);
328 window.addEventListener("resize", this.windowResize.bind(this), true);
329
330 document.addEventListener("focus", this.focusChanged.bind(this), true);
331 document.addEventListener("keydown", this.documentKeyDown.bind(this), true);
332 document.addEventListener("keyup", this.documentKeyUp.bind(this), true);
333 document.addEventListener("beforecopy", this.documentCanCopy.bind(this), tru e);
334 document.addEventListener("copy", this.documentCopy.bind(this), true);
335
336 var mainPanelsElement = document.getElementById("main-panels");
337 mainPanelsElement.handleKeyEvent = this.mainKeyDown.bind(this);
338 mainPanelsElement.handleKeyUpEvent = this.mainKeyUp.bind(this);
339 mainPanelsElement.handleCopyEvent = this.mainCopy.bind(this);
340
341 // Focus the mainPanelsElement in a timeout so it happens after the initial focus,
342 // so it doesn't get reset to the first toolbar button. This initial focus h appens
343 // on Mac when the window is made key and the WebHTMLView becomes the first responder.
344 setTimeout(function() { WebInspector.currentFocusElement = mainPanelsElement }, 0);
345
346 var dockToggleButton = document.getElementById("dock-status-bar-item");
347 dockToggleButton.addEventListener("click", this.toggleAttach.bind(this), fal se);
348
349 if (this.attached)
350 dockToggleButton.title = WebInspector.UIString("Undock into separate win dow.");
351 else
352 dockToggleButton.title = WebInspector.UIString("Dock to main window.");
353
354 var errorWarningCount = document.getElementById("error-warning-count");
355 errorWarningCount.addEventListener("click", this.console.show.bind(this.cons ole), false);
356 this._updateErrorAndWarningCounts();
357
358 var searchField = document.getElementById("search");
359 searchField.addEventListener("keydown", this.searchKeyDown.bind(this), false );
360 searchField.addEventListener("keyup", this.searchKeyUp.bind(this), false);
361 searchField.addEventListener("search", this.performSearch.bind(this), false) ; // when the search is emptied
362
363 document.getElementById("toolbar").addEventListener("mousedown", this.toolba rDragStart, true);
364 document.getElementById("close-button").addEventListener("click", this.close , true);
365
366 InspectorController.loaded();
367 }
368
369 var windowLoaded = function()
370 {
371 var localizedStringsURL = InspectorController.localizedStringsURL();
372 if (localizedStringsURL) {
373 var localizedStringsScriptElement = document.createElement("script");
374 localizedStringsScriptElement.addEventListener("load", WebInspector.load ed.bind(WebInspector), false);
375 localizedStringsScriptElement.type = "text/javascript";
376 localizedStringsScriptElement.src = localizedStringsURL;
377 document.getElementsByTagName("head").item(0).appendChild(localizedStrin gsScriptElement);
378 } else
379 WebInspector.loaded();
380
381 window.removeEventListener("load", windowLoaded, false);
382 delete windowLoaded;
383 };
384
385 window.addEventListener("load", windowLoaded, false);
386
387 WebInspector.windowUnload = function(event)
388 {
389 InspectorController.windowUnloading();
390 }
391
392 WebInspector.windowResize = function(event)
393 {
394 if (this.currentPanel && this.currentPanel.resize)
395 this.currentPanel.resize();
396 }
397
398 WebInspector.windowFocused = function(event)
399 {
400 if (event.target.nodeType === Node.DOCUMENT_NODE)
401 document.body.removeStyleClass("inactive");
402 }
403
404 WebInspector.windowBlured = function(event)
405 {
406 if (event.target.nodeType === Node.DOCUMENT_NODE)
407 document.body.addStyleClass("inactive");
408 }
409
410 WebInspector.focusChanged = function(event)
411 {
412 this.currentFocusElement = event.target;
413 }
414
415 WebInspector.setAttachedWindow = function(attached)
416 {
417 this.attached = attached;
418 }
419
420 WebInspector.close = function(event)
421 {
422 InspectorController.closeWindow();
423 }
424
425 WebInspector.documentClick = function(event)
426 {
427 var anchor = event.target.enclosingNodeOrSelfWithNodeName("a");
428 if (!anchor)
429 return;
430
431 // Prevent the link from navigating, since we don't do any navigation by fol lowing links normally.
432 event.preventDefault();
433
434 function followLink()
435 {
436 // FIXME: support webkit-html-external-link links here.
437 if (anchor.href in WebInspector.resourceURLMap) {
438 if (anchor.hasStyleClass("webkit-html-external-link")) {
439 anchor.removeStyleClass("webkit-html-external-link");
440 anchor.addStyleClass("webkit-html-resource-link");
441 }
442
443 WebInspector.showResourceForURL(anchor.href, anchor.lineNumber, anch or.preferredPanel);
444 } else {
445 var profileStringRegEx = new RegExp("webkit-profile://.+/([0-9]+)");
446 var profileString = profileStringRegEx.exec(anchor.href);
447 if (profileString)
448 WebInspector.showProfileById(profileString[1])
449 }
450 }
451
452 if (WebInspector.followLinkTimeout)
453 clearTimeout(WebInspector.followLinkTimeout);
454
455 if (anchor.preventFollowOnDoubleClick) {
456 // Start a timeout if this is the first click, if the timeout is cancele d
457 // before it fires, then a double clicked happened or another link was c licked.
458 if (event.detail === 1)
459 WebInspector.followLinkTimeout = setTimeout(followLink, 333);
460 return;
461 }
462
463 followLink();
464 }
465
466 WebInspector.documentKeyDown = function(event)
467 {
468 if (!this.currentFocusElement)
469 return;
470 if (this.currentFocusElement.handleKeyEvent)
471 this.currentFocusElement.handleKeyEvent(event);
472 else if (this.currentFocusElement.id && this.currentFocusElement.id.length & & WebInspector[this.currentFocusElement.id + "KeyDown"])
473 WebInspector[this.currentFocusElement.id + "KeyDown"](event);
474
475 if (!event.handled) {
476 var isMac = InspectorController.platform().indexOf("mac-") === 0;
477
478 switch (event.keyIdentifier) {
479 case "U+001B": // Escape key
480 this.console.visible = !this.console.visible;
481 event.preventDefault();
482 break;
483
484 case "U+0046": // F key
485 if (isMac)
486 var isFindKey = event.metaKey && !event.ctrlKey && !event.al tKey && !event.shiftKey;
487 else
488 var isFindKey = event.ctrlKey && !event.metaKey && !event.al tKey && !event.shiftKey;
489
490 if (isFindKey) {
491 var searchField = document.getElementById("search");
492 searchField.focus();
493 searchField.select();
494 event.preventDefault();
495 }
496
497 break;
498
499 case "U+0047": // G key
500 if (isMac)
501 var isFindAgainKey = event.metaKey && !event.ctrlKey && !eve nt.altKey;
502 else
503 var isFindAgainKey = event.ctrlKey && !event.metaKey && !eve nt.altKey;
504
505 if (isFindAgainKey) {
506 if (event.shiftKey) {
507 if (this.currentPanel.jumpToPreviousSearchResult)
508 this.currentPanel.jumpToPreviousSearchResult();
509 } else if (this.currentPanel.jumpToNextSearchResult)
510 this.currentPanel.jumpToNextSearchResult();
511 event.preventDefault();
512 }
513
514 break;
515 }
516 }
517 }
518
519 WebInspector.documentKeyUp = function(event)
520 {
521 if (!this.currentFocusElement || !this.currentFocusElement.handleKeyUpEvent)
522 return;
523 this.currentFocusElement.handleKeyUpEvent(event);
524 }
525
526 WebInspector.documentCanCopy = function(event)
527 {
528 if (!this.currentFocusElement)
529 return;
530 // Calling preventDefault() will say "we support copying, so enable the Copy menu".
531 if (this.currentFocusElement.handleCopyEvent)
532 event.preventDefault();
533 else if (this.currentFocusElement.id && this.currentFocusElement.id.length & & WebInspector[this.currentFocusElement.id + "Copy"])
534 event.preventDefault();
535 }
536
537 WebInspector.documentCopy = function(event)
538 {
539 if (!this.currentFocusElement)
540 return;
541 if (this.currentFocusElement.handleCopyEvent)
542 this.currentFocusElement.handleCopyEvent(event);
543 else if (this.currentFocusElement.id && this.currentFocusElement.id.length & & WebInspector[this.currentFocusElement.id + "Copy"])
544 WebInspector[this.currentFocusElement.id + "Copy"](event);
545 }
546
547 WebInspector.mainKeyDown = function(event)
548 {
549 if (this.currentPanel && this.currentPanel.handleKeyEvent)
550 this.currentPanel.handleKeyEvent(event);
551 }
552
553 WebInspector.mainKeyUp = function(event)
554 {
555 if (this.currentPanel && this.currentPanel.handleKeyUpEvent)
556 this.currentPanel.handleKeyUpEvent(event);
557 }
558
559 WebInspector.mainCopy = function(event)
560 {
561 if (this.currentPanel && this.currentPanel.handleCopyEvent)
562 this.currentPanel.handleCopyEvent(event);
563 }
564
565 WebInspector.animateStyle = function(animations, duration, callback, complete)
566 {
567 if (complete === undefined)
568 complete = 0;
569 var slice = (1000 / 30); // 30 frames per second
570
571 var defaultUnit = "px";
572 var propertyUnit = {opacity: ""};
573
574 for (var i = 0; i < animations.length; ++i) {
575 var animation = animations[i];
576 var element = null;
577 var start = null;
578 var current = null;
579 var end = null;
580 for (key in animation) {
581 if (key === "element")
582 element = animation[key];
583 else if (key === "start")
584 start = animation[key];
585 else if (key === "current")
586 current = animation[key];
587 else if (key === "end")
588 end = animation[key];
589 }
590
591 if (!element || !end)
592 continue;
593
594 var computedStyle = element.ownerDocument.defaultView.getComputedStyle(e lement);
595 if (!start) {
596 start = {};
597 for (key in end)
598 start[key] = parseInt(computedStyle.getPropertyValue(key));
599 animation.start = start;
600 } else if (complete == 0)
601 for (key in start)
602 element.style.setProperty(key, start[key] + (key in propertyUnit ? propertyUnit[key] : defaultUnit));
603
604 if (!current) {
605 current = {};
606 for (key in start)
607 current[key] = start[key];
608 animation.current = current;
609 }
610
611 function cubicInOut(t, b, c, d)
612 {
613 if ((t/=d/2) < 1) return c/2*t*t*t + b;
614 return c/2*((t-=2)*t*t + 2) + b;
615 }
616
617 var style = element.style;
618 for (key in end) {
619 var startValue = start[key];
620 var currentValue = current[key];
621 var endValue = end[key];
622 if ((complete + slice) < duration) {
623 var delta = (endValue - startValue) / (duration / slice);
624 var newValue = cubicInOut(complete, startValue, endValue - start Value, duration);
625 style.setProperty(key, newValue + (key in propertyUnit ? propert yUnit[key] : defaultUnit));
626 current[key] = newValue;
627 } else {
628 style.setProperty(key, endValue + (key in propertyUnit ? propert yUnit[key] : defaultUnit));
629 }
630 }
631 }
632
633 if (complete < duration)
634 setTimeout(WebInspector.animateStyle, slice, animations, duration, callb ack, complete + slice);
635 else if (callback)
636 callback();
637 }
638
639 WebInspector.updateSearchLabel = function()
640 {
641 if (!this.currentPanel)
642 return;
643
644 var newLabel = WebInspector.UIString("Search %s", this.currentPanel.toolbarI temLabel);
645 if (this.attached)
646 document.getElementById("search").setAttribute("placeholder", newLabel);
647 else {
648 document.getElementById("search").removeAttribute("placeholder");
649 document.getElementById("search-toolbar-label").textContent = newLabel;
650 }
651 }
652
653 WebInspector.toggleAttach = function()
654 {
655 this.attached = !this.attached;
656 }
657
658 WebInspector.toolbarDragStart = function(event)
659 {
660 if (!WebInspector.attached && InspectorController.platform() !== "mac-leopar d")
661 return;
662
663 var target = event.target;
664 if (target.hasStyleClass("toolbar-item") && target.hasStyleClass("toggleable "))
665 return;
666
667 var toolbar = document.getElementById("toolbar");
668 if (target !== toolbar && !target.hasStyleClass("toolbar-item"))
669 return;
670
671 toolbar.lastScreenX = event.screenX;
672 toolbar.lastScreenY = event.screenY;
673
674 WebInspector.elementDragStart(toolbar, WebInspector.toolbarDrag, WebInspecto r.toolbarDragEnd, event, (WebInspector.attached ? "row-resize" : "default"));
675 }
676
677 WebInspector.toolbarDragEnd = function(event)
678 {
679 var toolbar = document.getElementById("toolbar");
680
681 WebInspector.elementDragEnd(event);
682
683 delete toolbar.lastScreenX;
684 delete toolbar.lastScreenY;
685 }
686
687 WebInspector.toolbarDrag = function(event)
688 {
689 var toolbar = document.getElementById("toolbar");
690
691 if (WebInspector.attached) {
692 var height = window.innerHeight - (event.screenY - toolbar.lastScreenY);
693
694 InspectorController.setAttachedWindowHeight(height);
695 } else {
696 var x = event.screenX - toolbar.lastScreenX;
697 var y = event.screenY - toolbar.lastScreenY;
698
699 // We cannot call window.moveBy here because it restricts the movement
700 // of the window at the edges.
701 InspectorController.moveByUnrestricted(x, y);
702 }
703
704 toolbar.lastScreenX = event.screenX;
705 toolbar.lastScreenY = event.screenY;
706
707 event.preventDefault();
708 }
709
710 WebInspector.elementDragStart = function(element, dividerDrag, elementDragEnd, e vent, cursor)
711 {
712 if (this._elementDraggingEventListener || this._elementEndDraggingEventListe ner)
713 this.elementDragEnd(event);
714
715 this._elementDraggingEventListener = dividerDrag;
716 this._elementEndDraggingEventListener = elementDragEnd;
717
718 document.addEventListener("mousemove", dividerDrag, true);
719 document.addEventListener("mouseup", elementDragEnd, true);
720
721 document.body.style.cursor = cursor;
722
723 event.preventDefault();
724 }
725
726 WebInspector.elementDragEnd = function(event)
727 {
728 document.removeEventListener("mousemove", this._elementDraggingEventListener , true);
729 document.removeEventListener("mouseup", this._elementEndDraggingEventListene r, true);
730
731 document.body.style.removeProperty("cursor");
732
733 delete this._elementDraggingEventListener;
734 delete this._elementEndDraggingEventListener;
735
736 event.preventDefault();
737 }
738
739 WebInspector.showConsole = function()
740 {
741 this.console.show();
742 }
743
744 WebInspector.showElementsPanel = function()
745 {
746 this.currentPanel = this.panels.elements;
747 }
748
749 WebInspector.showResourcesPanel = function()
750 {
751 this.currentPanel = this.panels.resources;
752 }
753
754 WebInspector.showScriptsPanel = function()
755 {
756 this.currentPanel = this.panels.scripts;
757 }
758
759 WebInspector.showProfilesPanel = function()
760 {
761 this.currentPanel = this.panels.profiles;
762 }
763
764 WebInspector.showDatabasesPanel = function()
765 {
766 this.currentPanel = this.panels.databases;
767 }
768
769 WebInspector.addResource = function(resource)
770 {
771 this.resources.push(resource);
772 this.resourceURLMap[resource.url] = resource;
773
774 if (resource.mainResource) {
775 this.mainResource = resource;
776 this.panels.elements.reset();
777 }
778
779 if (this.panels.resources)
780 this.panels.resources.addResource(resource);
781 }
782
783 WebInspector.removeResource = function(resource)
784 {
785 resource.category.removeResource(resource);
786 delete this.resourceURLMap[resource.url];
787
788 this.resources.remove(resource, true);
789
790 if (this.panels.resources)
791 this.panels.resources.removeResource(resource);
792 }
793
794 WebInspector.addDatabase = function(database)
795 {
796 this.panels.databases.addDatabase(database);
797 }
798
799 WebInspector.addDOMStorage = function(domStorage)
800 {
801 this.panels.databases.addDOMStorage(domStorage);
802 }
803
804 WebInspector.debuggerWasEnabled = function()
805 {
806 this.panels.scripts.debuggerWasEnabled();
807 }
808
809 WebInspector.debuggerWasDisabled = function()
810 {
811 this.panels.scripts.debuggerWasDisabled();
812 }
813
814 WebInspector.profilerWasEnabled = function()
815 {
816 this.panels.profiles.profilerWasEnabled();
817 }
818
819 WebInspector.profilerWasDisabled = function()
820 {
821 this.panels.profiles.profilerWasDisabled();
822 }
823
824 WebInspector.parsedScriptSource = function(sourceID, sourceURL, source, starting Line)
825 {
826 this.panels.scripts.addScript(sourceID, sourceURL, source, startingLine);
827 }
828
829 WebInspector.failedToParseScriptSource = function(sourceURL, source, startingLin e, errorLine, errorMessage)
830 {
831 this.panels.scripts.addScript(null, sourceURL, source, startingLine, errorLi ne, errorMessage);
832 }
833
834 WebInspector.pausedScript = function()
835 {
836 this.panels.scripts.debuggerPaused();
837 }
838
839 WebInspector.populateInterface = function()
840 {
841 for (var panelName in this.panels) {
842 var panel = this.panels[panelName];
843 if ("populateInterface" in panel)
844 panel.populateInterface();
845 }
846 }
847
848 WebInspector.reset = function()
849 {
850 for (var panelName in this.panels) {
851 var panel = this.panels[panelName];
852 if ("reset" in panel)
853 panel.reset();
854 }
855
856 for (var category in this.resourceCategories)
857 this.resourceCategories[category].removeAllResources();
858
859 this.resources = [];
860 this.resourceURLMap = {};
861 this.hoveredDOMNode = null;
862
863 delete this.mainResource;
864
865 this.console.clearMessages();
866 }
867
868 WebInspector.inspectedWindowCleared = function(inspectedWindow)
869 {
870 this.panels.elements.inspectedWindowCleared(inspectedWindow);
871 }
872
873 WebInspector.resourceURLChanged = function(resource, oldURL)
874 {
875 delete this.resourceURLMap[oldURL];
876 this.resourceURLMap[resource.url] = resource;
877 }
878
879 WebInspector.addMessageToConsole = function(msg)
880 {
881 this.console.addMessage(msg);
882 }
883
884 WebInspector.addProfile = function(profile)
885 {
886 this.panels.profiles.addProfile(profile);
887 }
888
889 WebInspector.setRecordingProfile = function(isProfiling)
890 {
891 this.panels.profiles.setRecordingProfile(isProfiling);
892 }
893
894 WebInspector.drawLoadingPieChart = function(canvas, percent) {
895 var g = canvas.getContext("2d");
896 var darkColor = "rgb(122, 168, 218)";
897 var lightColor = "rgb(228, 241, 251)";
898 var cx = 8;
899 var cy = 8;
900 var r = 7;
901
902 g.beginPath();
903 g.arc(cx, cy, r, 0, Math.PI * 2, false);
904 g.closePath();
905
906 g.lineWidth = 1;
907 g.strokeStyle = darkColor;
908 g.fillStyle = lightColor;
909 g.fill();
910 g.stroke();
911
912 var startangle = -Math.PI / 2;
913 var endangle = startangle + (percent * Math.PI * 2);
914
915 g.beginPath();
916 g.moveTo(cx, cy);
917 g.arc(cx, cy, r, startangle, endangle, false);
918 g.closePath();
919
920 g.fillStyle = darkColor;
921 g.fill();
922 }
923
924 WebInspector.updateFocusedNode = function(node)
925 {
926 if (!node)
927 // FIXME: Should we deselect if null is passed in?
928 return;
929
930 this.currentPanel = this.panels.elements;
931 this.panels.elements.focusedDOMNode = node;
932 }
933
934 WebInspector.displayNameForURL = function(url)
935 {
936 if (!url)
937 return "";
938 var resource = this.resourceURLMap[url];
939 if (resource)
940 return resource.displayName;
941 return url.trimURL(WebInspector.mainResource ? WebInspector.mainResource.dom ain : "");
942 }
943
944 WebInspector.resourceForURL = function(url)
945 {
946 if (url in this.resourceURLMap)
947 return this.resourceURLMap[url];
948
949 // No direct match found. Search for resources that contain
950 // a substring of the URL.
951 for (var resourceURL in this.resourceURLMap) {
952 if (resourceURL.hasSubstring(url))
953 return this.resourceURLMap[resourceURL];
954 }
955
956 return null;
957 }
958
959 WebInspector.showResourceForURL = function(url, line, preferredPanel)
960 {
961 var resource = this.resourceForURL(url);
962 if (!resource)
963 return false;
964
965 if (preferredPanel && preferredPanel in WebInspector.panels) {
966 var panel = this.panels[preferredPanel];
967 if (!("showResource" in panel))
968 panel = null;
969 else if ("canShowResource" in panel && !panel.canShowResource(resource))
970 panel = null;
971 }
972
973 this.currentPanel = panel || this.panels.resources;
974 if (!this.currentPanel)
975 return false;
976 this.currentPanel.showResource(resource, line);
977 return true;
978 }
979
980 WebInspector.linkifyStringAsFragment = function(string)
981 {
982 var container = document.createDocumentFragment();
983 var linkStringRegEx = new RegExp("(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}://|www\\.)[\ \w$\\-_+*'=\\|/\\\\(){}[\\]%@&#~,:;.!?]{2,}[\\w$\\-_+*=\\|/\\\\({%@&#~]");
984
985 while (string) {
986 var linkString = linkStringRegEx.exec(string);
987 if (!linkString)
988 break;
989
990 linkString = linkString[0];
991 var title = linkString;
992 var linkIndex = string.indexOf(linkString);
993 var nonLink = string.substring(0, linkIndex);
994 container.appendChild(document.createTextNode(nonLink));
995
996 var profileStringRegEx = new RegExp("webkit-profile://(.+)/[0-9]+");
997 var profileStringMatches = profileStringRegEx.exec(title);
998 var profileTitle;
999 if (profileStringMatches)
1000 profileTitle = profileStringMatches[1];
1001 if (profileTitle)
1002 title = WebInspector.panels.profiles.displayTitleForProfileLink(prof ileTitle);
1003
1004 var realURL = (linkString.indexOf("www.") === 0 ? "http://" + linkString : linkString);
1005 container.appendChild(WebInspector.linkifyURLAsNode(realURL, title, null , (realURL in WebInspector.resourceURLMap)));
1006 string = string.substring(linkIndex + linkString.length, string.length);
1007 }
1008
1009 if (string)
1010 container.appendChild(document.createTextNode(string));
1011
1012 return container;
1013 }
1014
1015 WebInspector.showProfileById = function(uid) {
1016 WebInspector.showProfilesPanel();
1017 WebInspector.panels.profiles.showProfileById(uid);
1018 }
1019
1020 WebInspector.linkifyURLAsNode = function(url, linkText, classes, isExternal)
1021 {
1022 if (!linkText)
1023 linkText = url;
1024 classes = (classes ? classes + " " : "");
1025 classes += isExternal ? "webkit-html-external-link" : "webkit-html-resource- link";
1026
1027 var a = document.createElement("a");
1028 a.href = url;
1029 a.className = classes;
1030 a.title = url;
1031 a.target = "_blank";
1032 a.textContent = linkText;
1033
1034 return a;
1035 }
1036
1037 WebInspector.linkifyURL = function(url, linkText, classes, isExternal)
1038 {
1039 // Use the DOM version of this function so as to avoid needing to escape att ributes.
1040 // FIXME: Get rid of linkifyURL entirely.
1041 return WebInspector.linkifyURLAsNode(url, linkText, classes, isExternal).out erHTML;
1042 }
1043
1044 WebInspector.addMainEventListeners = function(doc)
1045 {
1046 doc.defaultView.addEventListener("focus", this.windowFocused.bind(this), tru e);
1047 doc.defaultView.addEventListener("blur", this.windowBlured.bind(this), true) ;
1048 doc.addEventListener("click", this.documentClick.bind(this), true);
1049 }
1050
1051 WebInspector.searchKeyDown = function(event)
1052 {
1053 if (event.keyIdentifier !== "Enter")
1054 return;
1055
1056 // Call preventDefault since this was the Enter key. This prevents a "search " event
1057 // from firing for key down. We handle the Enter key on key up in searchKeyU p. This
1058 // stops performSearch from being called twice in a row.
1059 event.preventDefault();
1060 }
1061
1062 WebInspector.searchKeyUp = function(event)
1063 {
1064 if (event.keyIdentifier !== "Enter")
1065 return;
1066
1067 // Select all of the text so the user can easily type an entirely new query.
1068 event.target.select();
1069
1070 // Only call performSearch if the Enter key was pressed. Otherwise the searc h
1071 // performance is poor because of searching on every key. The search field h as
1072 // the incremental attribute set, so we still get incremental searches.
1073 this.performSearch(event);
1074 }
1075
1076 WebInspector.performSearch = function(event)
1077 {
1078 var query = event.target.value;
1079 var forceSearch = event.keyIdentifier === "Enter";
1080
1081 if (!query || !query.length || (!forceSearch && query.length < 3)) {
1082 delete this.currentQuery;
1083
1084 for (var panelName in this.panels) {
1085 var panel = this.panels[panelName];
1086 if (panel.currentQuery && panel.searchCanceled)
1087 panel.searchCanceled();
1088 delete panel.currentQuery;
1089 }
1090
1091 this.updateSearchMatchesCount();
1092
1093 return;
1094 }
1095
1096 if (query === this.currentPanel.currentQuery && this.currentPanel.currentQue ry === this.currentQuery) {
1097 // When this is the same query and a forced search, jump to the next
1098 // search result for a good user experience.
1099 if (forceSearch && this.currentPanel.jumpToNextSearchResult)
1100 this.currentPanel.jumpToNextSearchResult();
1101 return;
1102 }
1103
1104 this.currentQuery = query;
1105
1106 this.updateSearchMatchesCount();
1107
1108 if (!this.currentPanel.performSearch)
1109 return;
1110
1111 this.currentPanel.currentQuery = query;
1112 this.currentPanel.performSearch(query);
1113 }
1114
1115 WebInspector.updateSearchMatchesCount = function(matches, panel)
1116 {
1117 if (!panel)
1118 panel = this.currentPanel;
1119
1120 panel.currentSearchMatches = matches;
1121
1122 if (panel !== this.currentPanel)
1123 return;
1124
1125 if (!this.currentPanel.currentQuery) {
1126 document.getElementById("search-results-matches").addStyleClass("hidden" );
1127 return;
1128 }
1129
1130 if (matches) {
1131 if (matches === 1)
1132 var matchesString = WebInspector.UIString("1 match");
1133 else
1134 var matchesString = WebInspector.UIString("%d matches", matches);
1135 } else
1136 var matchesString = WebInspector.UIString("Not Found");
1137
1138 var matchesToolbarElement = document.getElementById("search-results-matches" );
1139 matchesToolbarElement.removeStyleClass("hidden");
1140 matchesToolbarElement.textContent = matchesString;
1141 }
1142
1143 WebInspector.UIString = function(string)
1144 {
1145 if (window.localizedStrings && string in window.localizedStrings)
1146 string = window.localizedStrings[string];
1147 else {
1148 if (!(string in this.missingLocalizedStrings)) {
1149 console.error("Localized string \"" + string + "\" not found.");
1150 this.missingLocalizedStrings[string] = true;
1151 }
1152
1153 if (Preferences.showMissingLocalizedStrings)
1154 string += " (not localized)";
1155 }
1156
1157 return String.vsprintf(string, Array.prototype.slice.call(arguments, 1));
1158 }
1159
1160 WebInspector.isBeingEdited = function(element)
1161 {
1162 return element.__editing;
1163 }
1164
1165 WebInspector.startEditing = function(element, committedCallback, cancelledCallba ck, context)
1166 {
1167 if (element.__editing)
1168 return;
1169 element.__editing = true;
1170
1171 var oldText = element.textContent;
1172 var oldHandleKeyEvent = element.handleKeyEvent;
1173
1174 element.addStyleClass("editing");
1175
1176 var oldTabIndex = element.tabIndex;
1177 if (element.tabIndex < 0)
1178 element.tabIndex = 0;
1179
1180 function blurEventListener() {
1181 editingCommitted.call(element);
1182 }
1183
1184 function cleanUpAfterEditing() {
1185 delete this.__editing;
1186
1187 this.removeStyleClass("editing");
1188 this.tabIndex = oldTabIndex;
1189 this.scrollTop = 0;
1190 this.scrollLeft = 0;
1191
1192 this.handleKeyEvent = oldHandleKeyEvent;
1193 element.removeEventListener("blur", blurEventListener, false);
1194
1195 if (element === WebInspector.currentFocusElement || element.isAncestor(W ebInspector.currentFocusElement))
1196 WebInspector.currentFocusElement = WebInspector.previousFocusElement ;
1197 }
1198
1199 function editingCancelled() {
1200 this.innerText = oldText;
1201
1202 cleanUpAfterEditing.call(this);
1203
1204 cancelledCallback(this, context);
1205 }
1206
1207 function editingCommitted() {
1208 cleanUpAfterEditing.call(this);
1209
1210 committedCallback(this, this.textContent, oldText, context);
1211 }
1212
1213 element.handleKeyEvent = function(event) {
1214 if (oldHandleKeyEvent)
1215 oldHandleKeyEvent(event);
1216 if (event.handled)
1217 return;
1218
1219 if (event.keyIdentifier === "Enter") {
1220 editingCommitted.call(element);
1221 event.preventDefault();
1222 } else if (event.keyCode === 27) { // Escape key
1223 editingCancelled.call(element);
1224 event.preventDefault();
1225 event.handled = true;
1226 }
1227 }
1228
1229 element.addEventListener("blur", blurEventListener, false);
1230
1231 WebInspector.currentFocusElement = element;
1232 }
1233
1234 WebInspector._toolbarItemClicked = function(event)
1235 {
1236 var toolbarItem = event.currentTarget;
1237 this.currentPanel = toolbarItem.panel;
1238 }
1239
1240 // This table maps MIME types to the Resource.Types which are valid for them.
1241 // The following line:
1242 // "text/html": {0: 1},
1243 // means that text/html is a valid MIME type for resources that have type
1244 // WebInspector.Resource.Type.Document (which has a value of 0).
1245 WebInspector.MIMETypes = {
1246 "text/html": {0: true},
1247 "text/xml": {0: true},
1248 "text/plain": {0: true},
1249 "application/xhtml+xml": {0: true},
1250 "text/css": {1: true},
1251 "text/xsl": {1: true},
1252 "image/jpeg": {2: true},
1253 "image/png": {2: true},
1254 "image/gif": {2: true},
1255 "image/bmp": {2: true},
1256 "image/x-icon": {2: true},
1257 "image/x-xbitmap": {2: true},
1258 "font/ttf": {3: true},
1259 "font/opentype": {3: true},
1260 "application/x-font-type1": {3: true},
1261 "application/x-font-ttf": {3: true},
1262 "application/x-truetype-font": {3: true},
1263 "text/javascript": {4: true},
1264 "text/ecmascript": {4: true},
1265 "application/javascript": {4: true},
1266 "application/ecmascript": {4: true},
1267 "application/x-javascript": {4: true},
1268 "text/javascript1.1": {4: true},
1269 "text/javascript1.2": {4: true},
1270 "text/javascript1.3": {4: true},
1271 "text/jscript": {4: true},
1272 "text/livescript": {4: true},
1273 }
1274
1275
1276 // Stubs for some methods called in ElementsPanel.js which are not yet
1277 // supported by Chrome version of InspectorController
1278 InspectorController.wrapCallback = function f(a) {
1279 return a;
1280 };
1281
1282 InspectorController.searchingForNode = function() {
1283 return false;
1284 };
1285
1286 InspectorController.toggleNodeSearch = function() {
1287 };
1288
1289 InspectorController.isWindowVisible = function() {
1290 return true;
1291 };
1292
1293 InspectorController.closeWindow = function() {
1294 };
1295
1296 InspectorController.clearMessages = function() {
1297 };
1298
1299 InspectorController.setAttachedWindowHeight = function(height) {
1300 };
1301
1302 InspectorController.moveByUnrestricted = function(x, y) {
1303 };
OLDNEW
« no previous file with comments | « chrome/resources/Inspector/inspector.html ('k') | chrome/resources/Inspector/quirks-overrides.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698