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

Side by Side Diff: Source/devtools/front_end/ui/SuggestBox.js

Issue 663083004: [DevTools] Remove remaining usages of global properties. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed review comments Created 6 years, 2 months 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
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 * @param {!WebInspector.SuggestBoxDelegate} suggestBoxDelegate 53 * @param {!WebInspector.SuggestBoxDelegate} suggestBoxDelegate
54 * @param {number=} maxItemsHeight 54 * @param {number=} maxItemsHeight
55 */ 55 */
56 WebInspector.SuggestBox = function(suggestBoxDelegate, maxItemsHeight) 56 WebInspector.SuggestBox = function(suggestBoxDelegate, maxItemsHeight)
57 { 57 {
58 this._suggestBoxDelegate = suggestBoxDelegate; 58 this._suggestBoxDelegate = suggestBoxDelegate;
59 this._length = 0; 59 this._length = 0;
60 this._selectedIndex = -1; 60 this._selectedIndex = -1;
61 this._selectedElement = null; 61 this._selectedElement = null;
62 this._maxItemsHeight = maxItemsHeight; 62 this._maxItemsHeight = maxItemsHeight;
63 this._bodyElement = document.body;
64 this._maybeHideBound = this._maybeHide.bind(this); 63 this._maybeHideBound = this._maybeHide.bind(this);
65 this._element = createElementWithClass("div", "suggest-box"); 64 this._element = createElementWithClass("div", "suggest-box");
66 this._element.addEventListener("mousedown", this._onBoxMouseDown.bind(this), true); 65 this._element.addEventListener("mousedown", this._onBoxMouseDown.bind(this), true);
67 } 66 }
68 67
69 WebInspector.SuggestBox.prototype = { 68 WebInspector.SuggestBox.prototype = {
70 /** 69 /**
71 * @return {boolean} 70 * @return {boolean}
72 */ 71 */
73 visible: function() 72 visible: function()
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 130 }
132 event.preventDefault(); 131 event.preventDefault();
133 }, 132 },
134 133
135 _maybeHide: function() 134 _maybeHide: function()
136 { 135 {
137 if (!this._hideTimeoutId) 136 if (!this._hideTimeoutId)
138 this._hideTimeoutId = window.setTimeout(this.hide.bind(this), 0); 137 this._hideTimeoutId = window.setTimeout(this.hide.bind(this), 0);
139 }, 138 },
140 139
140 /**
141 * @private // FIXME: this is a workaround for validator bug (http://crbug.c om/425506).
142 * // FIXME: make SuggestBox work for multiple documents.
143 * @suppressGlobalPropertiesCheck
144 */
141 _show: function() 145 _show: function()
142 { 146 {
143 if (this.visible()) 147 if (this.visible())
144 return; 148 return;
145 this._overlay = new WebInspector.SuggestBox.Overlay(); 149 this._overlay = new WebInspector.SuggestBox.Overlay();
150 this._bodyElement = document.body;
146 this._bodyElement.addEventListener("mousedown", this._maybeHideBound, tr ue); 151 this._bodyElement.addEventListener("mousedown", this._maybeHideBound, tr ue);
147 152
148 this._leftSpacerElement = this._overlay.element.createChild("div", "sugg est-box-left-spacer"); 153 this._leftSpacerElement = this._overlay.element.createChild("div", "sugg est-box-left-spacer");
149 this._horizontalElement = this._overlay.element.createChild("div", "sugg est-box-horizontal"); 154 this._horizontalElement = this._overlay.element.createChild("div", "sugg est-box-horizontal");
150 this._topSpacerElement = this._horizontalElement.createChild("div", "sug gest-box-top-spacer"); 155 this._topSpacerElement = this._horizontalElement.createChild("div", "sug gest-box-top-spacer");
151 this._horizontalElement.appendChild(this._element); 156 this._horizontalElement.appendChild(this._element);
152 this._bottomSpacerElement = this._horizontalElement.createChild("div", " suggest-box-bottom-spacer"); 157 this._bottomSpacerElement = this._horizontalElement.createChild("div", " suggest-box-bottom-spacer");
153 }, 158 },
154 159
155 hide: function() 160 hide: function()
156 { 161 {
157 if (!this.visible()) 162 if (!this.visible())
158 return; 163 return;
159 164
160 this._bodyElement.removeEventListener("mousedown", this._maybeHideBound, true); 165 this._bodyElement.removeEventListener("mousedown", this._maybeHideBound, true);
166 delete this._bodyElement;
161 this._element.remove(); 167 this._element.remove();
162 this._overlay.dispose(); 168 this._overlay.dispose();
163 delete this._overlay; 169 delete this._overlay;
164 delete this._selectedElement; 170 delete this._selectedElement;
165 this._selectedIndex = -1; 171 this._selectedIndex = -1;
166 delete this._lastAnchorBox; 172 delete this._lastAnchorBox;
167 }, 173 },
168 174
169 removeFromElement: function() 175 removeFromElement: function()
170 { 176 {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 this.acceptSuggestion(); 409 this.acceptSuggestion();
404 410
405 // Report the event as non-handled if there is no selected item, 411 // Report the event as non-handled if there is no selected item,
406 // to commit the input or handle it otherwise. 412 // to commit the input or handle it otherwise.
407 return hasSelectedItem; 413 return hasSelectedItem;
408 } 414 }
409 } 415 }
410 416
411 /** 417 /**
412 * @constructor 418 * @constructor
419 * // FIXME: make SuggestBox work for multiple documents.
420 * @suppressGlobalPropertiesCheck
413 */ 421 */
414 WebInspector.SuggestBox.Overlay = function() 422 WebInspector.SuggestBox.Overlay = function()
415 { 423 {
416 this.element = createElementWithClass("div", "suggest-box-overlay"); 424 this.element = createElementWithClass("div", "suggest-box-overlay");
417 this._resize(); 425 this._resize();
418 document.body.appendChild(this.element); 426 document.body.appendChild(this.element);
419 } 427 }
420 428
421 WebInspector.SuggestBox.Overlay.prototype = { 429 WebInspector.SuggestBox.Overlay.prototype = {
422 _resize: function() 430 _resize: function()
423 { 431 {
424 var container = WebInspector.Dialog.modalHostView().element; 432 var container = WebInspector.Dialog.modalHostView().element;
425 var containerBox = container.boxInWindow(container.ownerDocument.default View); 433 var containerBox = container.boxInWindow(container.ownerDocument.default View);
426 434
427 this.element.style.left = containerBox.x + "px"; 435 this.element.style.left = containerBox.x + "px";
428 this.element.style.top = containerBox.y + "px"; 436 this.element.style.top = containerBox.y + "px";
429 this.element.style.height = containerBox.height + "px"; 437 this.element.style.height = containerBox.height + "px";
430 this.element.style.width = containerBox.width + "px"; 438 this.element.style.width = containerBox.width + "px";
431 }, 439 },
432 440
433 dispose: function() 441 dispose: function()
434 { 442 {
435 this.element.remove(); 443 this.element.remove();
436 } 444 }
437 } 445 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ui/StatusBarButton.js ('k') | Source/devtools/front_end/ui/TextPrompt.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698