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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/SoftContextMenu.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. 2 * Copyright (C) 2011 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 /** 26 /**
27 * @unrestricted 27 * @unrestricted
28 */ 28 */
29 WebInspector.SoftContextMenu = class { 29 UI.SoftContextMenu = class {
30 /** 30 /**
31 * @param {!Array.<!InspectorFrontendHostAPI.ContextMenuDescriptor>} items 31 * @param {!Array.<!InspectorFrontendHostAPI.ContextMenuDescriptor>} items
32 * @param {function(string)} itemSelectedCallback 32 * @param {function(string)} itemSelectedCallback
33 * @param {!WebInspector.SoftContextMenu=} parentMenu 33 * @param {!UI.SoftContextMenu=} parentMenu
34 */ 34 */
35 constructor(items, itemSelectedCallback, parentMenu) { 35 constructor(items, itemSelectedCallback, parentMenu) {
36 this._items = items; 36 this._items = items;
37 this._itemSelectedCallback = itemSelectedCallback; 37 this._itemSelectedCallback = itemSelectedCallback;
38 this._parentMenu = parentMenu; 38 this._parentMenu = parentMenu;
39 } 39 }
40 40
41 /** 41 /**
42 * @param {!Document} document 42 * @param {!Document} document
43 * @param {number} x 43 * @param {number} x
44 * @param {number} y 44 * @param {number} y
45 */ 45 */
46 show(document, x, y) { 46 show(document, x, y) {
47 if (!this._items.length) 47 if (!this._items.length)
48 return; 48 return;
49 49
50 this._document = document; 50 this._document = document;
51 this._x = x; 51 this._x = x;
52 this._y = y; 52 this._y = y;
53 this._time = new Date().getTime(); 53 this._time = new Date().getTime();
54 54
55 // Create context menu. 55 // Create context menu.
56 this.element = createElementWithClass('div', 'soft-context-menu'); 56 this.element = createElementWithClass('div', 'soft-context-menu');
57 var root = WebInspector.createShadowRootWithCoreStyles(this.element, 'ui/sof tContextMenu.css'); 57 var root = UI.createShadowRootWithCoreStyles(this.element, 'ui/softContextMe nu.css');
58 this._contextMenuElement = root.createChild('div'); 58 this._contextMenuElement = root.createChild('div');
59 this.element.style.top = y + 'px'; 59 this.element.style.top = y + 'px';
60 var subMenuOverlap = 3; 60 var subMenuOverlap = 3;
61 this.element.style.left = (this._parentMenu ? x - subMenuOverlap : x) + 'px' ; 61 this.element.style.left = (this._parentMenu ? x - subMenuOverlap : x) + 'px' ;
62 62
63 this._contextMenuElement.tabIndex = 0; 63 this._contextMenuElement.tabIndex = 0;
64 this._contextMenuElement.addEventListener('mouseup', (e) => e.consume(), fal se); 64 this._contextMenuElement.addEventListener('mouseup', (e) => e.consume(), fal se);
65 this._contextMenuElement.addEventListener('keydown', this._menuKeyDown.bind( this), false); 65 this._contextMenuElement.addEventListener('keydown', this._menuKeyDown.bind( this), false);
66 66
67 for (var i = 0; i < this._items.length; ++i) 67 for (var i = 0; i < this._items.length; ++i)
(...skipping 10 matching lines...) Expand all
78 this._discardMenuOnResizeListener = this._discardMenu.bind(this, true); 78 this._discardMenuOnResizeListener = this._discardMenu.bind(this, true);
79 document.defaultView.addEventListener('resize', this._discardMenuOnResizeL istener, false); 79 document.defaultView.addEventListener('resize', this._discardMenuOnResizeL istener, false);
80 } else { 80 } else {
81 this._parentMenu._parentGlassPaneElement().appendChild(this.element); 81 this._parentMenu._parentGlassPaneElement().appendChild(this.element);
82 } 82 }
83 83
84 // Re-position menu in case it does not fit. 84 // Re-position menu in case it does not fit.
85 if (document.body.offsetWidth < this.element.offsetLeft + this.element.offse tWidth) { 85 if (document.body.offsetWidth < this.element.offsetLeft + this.element.offse tWidth) {
86 this.element.style.left = 86 this.element.style.left =
87 Math.max( 87 Math.max(
88 WebInspector.Dialog.modalHostView().element.totalOffsetLeft(), thi s._parentMenu ? 88 UI.Dialog.modalHostView().element.totalOffsetLeft(), this._parentM enu ?
89 this._parentMenu.element.offsetLeft - this.element.offsetWidth + subMenuOverlap : 89 this._parentMenu.element.offsetLeft - this.element.offsetWidth + subMenuOverlap :
90 document.body.offsetWidth - this.element.offsetWidth) + 90 document.body.offsetWidth - this.element.offsetWidth) +
91 'px'; 91 'px';
92 } 92 }
93 93
94 // Move submenus upwards if it does not fit. 94 // Move submenus upwards if it does not fit.
95 if (this._parentMenu && document.body.offsetHeight < this.element.offsetTop + this.element.offsetHeight) { 95 if (this._parentMenu && document.body.offsetHeight < this.element.offsetTop + this.element.offsetHeight) {
96 y = Math.max( 96 y = Math.max(
97 WebInspector.Dialog.modalHostView().element.totalOffsetTop(), 97 UI.Dialog.modalHostView().element.totalOffsetTop(),
98 document.body.offsetHeight - this.element.offsetHeight); 98 document.body.offsetHeight - this.element.offsetHeight);
99 this.element.style.top = y + 'px'; 99 this.element.style.top = y + 'px';
100 } 100 }
101 101
102 var maxHeight = WebInspector.Dialog.modalHostView().element.offsetHeight; 102 var maxHeight = UI.Dialog.modalHostView().element.offsetHeight;
103 maxHeight -= y - WebInspector.Dialog.modalHostView().element.totalOffsetTop( ); 103 maxHeight -= y - UI.Dialog.modalHostView().element.totalOffsetTop();
104 this.element.style.maxHeight = maxHeight + 'px'; 104 this.element.style.maxHeight = maxHeight + 'px';
105 105
106 this._focus(); 106 this._focus();
107 } 107 }
108 108
109 discard() { 109 discard() {
110 this._discardMenu(true); 110 this._discardMenu(true);
111 } 111 }
112 112
113 _parentGlassPaneElement() { 113 _parentGlassPaneElement() {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 213 }
214 214
215 _showSubMenu(menuItemElement) { 215 _showSubMenu(menuItemElement) {
216 if (menuItemElement._subMenuTimer) { 216 if (menuItemElement._subMenuTimer) {
217 clearTimeout(menuItemElement._subMenuTimer); 217 clearTimeout(menuItemElement._subMenuTimer);
218 delete menuItemElement._subMenuTimer; 218 delete menuItemElement._subMenuTimer;
219 } 219 }
220 if (this._subMenu) 220 if (this._subMenu)
221 return; 221 return;
222 222
223 this._subMenu = new WebInspector.SoftContextMenu(menuItemElement._subItems, this._itemSelectedCallback, this); 223 this._subMenu = new UI.SoftContextMenu(menuItemElement._subItems, this._item SelectedCallback, this);
224 var topPadding = 4; 224 var topPadding = 4;
225 this._subMenu.show( 225 this._subMenu.show(
226 this._document, menuItemElement.totalOffsetLeft() + menuItemElement.offs etWidth, 226 this._document, menuItemElement.totalOffsetLeft() + menuItemElement.offs etWidth,
227 menuItemElement.totalOffsetTop() - 1 - topPadding); 227 menuItemElement.totalOffsetTop() - 1 - topPadding);
228 } 228 }
229 229
230 _hideSubMenu() { 230 _hideSubMenu() {
231 if (!this._subMenu) 231 if (!this._subMenu)
232 return; 232 return;
233 this._subMenu._discardSubMenus(); 233 this._subMenu._discardSubMenus();
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 385
386 _discardSubMenus() { 386 _discardSubMenus() {
387 if (this._subMenu) 387 if (this._subMenu)
388 this._subMenu._discardSubMenus(); 388 this._subMenu._discardSubMenus();
389 if (this.element) 389 if (this.element)
390 this.element.remove(); 390 this.element.remove();
391 if (this._parentMenu) 391 if (this._parentMenu)
392 delete this._parentMenu._subMenu; 392 delete this._parentMenu._subMenu;
393 } 393 }
394 }; 394 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698