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

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

Issue 2702523003: [DevTools] Continue GlassPane refactoring. (Closed)
Patch Set: element Created 3 years, 10 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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 }; 46 };
47 47
48 /** 48 /**
49 * @implements {UI.ListDelegate} 49 * @implements {UI.ListDelegate}
50 */ 50 */
51 UI.SuggestBox = class { 51 UI.SuggestBox = class {
52 /** 52 /**
53 * @param {!UI.SuggestBoxDelegate} suggestBoxDelegate 53 * @param {!UI.SuggestBoxDelegate} suggestBoxDelegate
54 * @param {number=} maxItemsHeight 54 * @param {number=} maxItemsHeight
55 * @param {boolean=} captureEnter 55 * @param {boolean=} captureEnter
56 * @suppressGlobalPropertiesCheck
57 */ 56 */
58 constructor(suggestBoxDelegate, maxItemsHeight, captureEnter) { 57 constructor(suggestBoxDelegate, maxItemsHeight, captureEnter) {
59 this._suggestBoxDelegate = suggestBoxDelegate; 58 this._suggestBoxDelegate = suggestBoxDelegate;
60 this._maxItemsHeight = maxItemsHeight; 59 this._maxItemsHeight = maxItemsHeight;
61 this._captureEnter = captureEnter; 60 this._captureEnter = captureEnter;
62 this._rowHeight = 17; 61 this._rowHeight = 17;
63 this._userInteracted = false; 62 this._userInteracted = false;
64 this._userEnteredText = ''; 63 this._userEnteredText = '';
65 /** @type {?string} */ 64 /** @type {?string} */
66 this._onlyCompletion = null; 65 this._onlyCompletion = null;
67 66
68 /** @type {!UI.ListControl<!UI.SuggestBox.Suggestion>} */ 67 /** @type {!UI.ListControl<!UI.SuggestBox.Suggestion>} */
69 this._list = new UI.ListControl(this, UI.ListMode.EqualHeightItems); 68 this._list = new UI.ListControl(this, UI.ListMode.EqualHeightItems);
70 this._element = this._list.element; 69 this._element = this._list.element;
71 this._element.classList.add('suggest-box'); 70 this._element.classList.add('suggest-box');
72 this._element.addEventListener('mousedown', event => event.preventDefault(), true); 71 this._element.addEventListener('mousedown', event => event.preventDefault(), true);
73 72
74 // TODO(dgozman): take document in constructor. 73 this._glassPane = new UI.GlassPane();
75 this._glassPane =
76 new UI.GlassPane(document, false /* dimmed */, false /* blockPointerEven ts */, this.hide.bind(this));
77 this._glassPane.setAnchorBehavior(UI.GlassPane.AnchorBehavior.PreferBottom); 74 this._glassPane.setAnchorBehavior(UI.GlassPane.AnchorBehavior.PreferBottom);
75 this._glassPane.setSetOutsideClickCallback(this.hide.bind(this));
78 var shadowRoot = UI.createShadowRootWithCoreStyles(this._glassPane.contentEl ement, 'ui/suggestBox.css'); 76 var shadowRoot = UI.createShadowRootWithCoreStyles(this._glassPane.contentEl ement, 'ui/suggestBox.css');
79 shadowRoot.appendChild(this._element); 77 shadowRoot.appendChild(this._element);
80 } 78 }
81 79
82 /** 80 /**
83 * @return {boolean} 81 * @return {boolean}
84 */ 82 */
85 visible() { 83 visible() {
86 return this._glassPane.visible(); 84 return this._glassPane.isShowing();
87 } 85 }
88 86
89 /** 87 /**
90 * @param {!AnchorBox} anchorBox 88 * @param {!AnchorBox} anchorBox
91 */ 89 */
92 setPosition(anchorBox) { 90 setPosition(anchorBox) {
93 this._glassPane.setContentAnchorBox(anchorBox); 91 this._glassPane.setContentAnchorBox(anchorBox);
94 } 92 }
95 93
96 /** 94 /**
(...skipping 20 matching lines...) Expand all
117 var length = (items[i].title || items[i].text).length + (items[i].subtitle || '').length; 115 var length = (items[i].title || items[i].text).length + (items[i].subtitle || '').length;
118 if (length > maxLength) { 116 if (length > maxLength) {
119 maxLength = length; 117 maxLength = length;
120 maxItem = items[i]; 118 maxItem = items[i];
121 } 119 }
122 } 120 }
123 var element = this.createElementForItem(/** @type {!UI.SuggestBox.Suggestion } */ (maxItem)); 121 var element = this.createElementForItem(/** @type {!UI.SuggestBox.Suggestion } */ (maxItem));
124 return Math.min(kMaxWidth, UI.measurePreferredSize(element, this._element).w idth); 122 return Math.min(kMaxWidth, UI.measurePreferredSize(element, this._element).w idth);
125 } 123 }
126 124
125 /**
126 * @suppressGlobalPropertiesCheck
127 */
127 _show() { 128 _show() {
128 if (this.visible()) 129 if (this.visible())
129 return; 130 return;
130 this._glassPane.show(); 131 // TODO(dgozman): take document as a parameter.
132 this._glassPane.showGlassPane(document);
131 this._rowHeight = 133 this._rowHeight =
132 UI.measurePreferredSize(this.createElementForItem({text: '1', subtitle: '12'}), this._element).height; 134 UI.measurePreferredSize(this.createElementForItem({text: '1', subtitle: '12'}), this._element).height;
133 } 135 }
134 136
135 hide() { 137 hide() {
136 if (!this.visible()) 138 if (!this.visible())
137 return; 139 return;
138 this._userInteracted = false; 140 this._userInteracted = false;
139 this._glassPane.hide(); 141 this._glassPane.hideGlassPane();
140 } 142 }
141 143
142 /** 144 /**
143 * @param {boolean=} isIntermediateSuggestion 145 * @param {boolean=} isIntermediateSuggestion
144 * @return {boolean} 146 * @return {boolean}
145 */ 147 */
146 _applySuggestion(isIntermediateSuggestion) { 148 _applySuggestion(isIntermediateSuggestion) {
147 if (this._onlyCompletion) { 149 if (this._onlyCompletion) {
148 this._suggestBoxDelegate.applySuggestion(this._onlyCompletion, isIntermedi ateSuggestion); 150 this._suggestBoxDelegate.applySuggestion(this._onlyCompletion, isIntermedi ateSuggestion);
149 return true; 151 return true;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 359
358 /** 360 /**
359 * @typedef {!{text: string, subtitle: (string|undefined), iconType: (string|und efined), priority: (number|undefined), isSecondary: (boolean|undefined), title: (string|undefined)}} 361 * @typedef {!{text: string, subtitle: (string|undefined), iconType: (string|und efined), priority: (number|undefined), isSecondary: (boolean|undefined), title: (string|undefined)}}
360 */ 362 */
361 UI.SuggestBox.Suggestion; 363 UI.SuggestBox.Suggestion;
362 364
363 /** 365 /**
364 * @typedef {!Array<!UI.SuggestBox.Suggestion>} 366 * @typedef {!Array<!UI.SuggestBox.Suggestion>}
365 */ 367 */
366 UI.SuggestBox.Suggestions; 368 UI.SuggestBox.Suggestions;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698