| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 WebInspector.Toolbar = class { | 34 UI.Toolbar = class { |
| 35 /** | 35 /** |
| 36 * @param {string} className | 36 * @param {string} className |
| 37 * @param {!Element=} parentElement | 37 * @param {!Element=} parentElement |
| 38 */ | 38 */ |
| 39 constructor(className, parentElement) { | 39 constructor(className, parentElement) { |
| 40 /** @type {!Array.<!WebInspector.ToolbarItem>} */ | 40 /** @type {!Array.<!UI.ToolbarItem>} */ |
| 41 this._items = []; | 41 this._items = []; |
| 42 this._reverse = false; | 42 this._reverse = false; |
| 43 this.element = parentElement ? parentElement.createChild('div') : createElem
ent('div'); | 43 this.element = parentElement ? parentElement.createChild('div') : createElem
ent('div'); |
| 44 this.element.className = className; | 44 this.element.className = className; |
| 45 this.element.classList.add('toolbar'); | 45 this.element.classList.add('toolbar'); |
| 46 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element,
'ui/toolbar.css'); | 46 this._shadowRoot = UI.createShadowRootWithCoreStyles(this.element, 'ui/toolb
ar.css'); |
| 47 this._contentElement = this._shadowRoot.createChild('div', 'toolbar-shadow')
; | 47 this._contentElement = this._shadowRoot.createChild('div', 'toolbar-shadow')
; |
| 48 this._insertionPoint = this._contentElement.createChild('content'); | 48 this._insertionPoint = this._contentElement.createChild('content'); |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * @param {!WebInspector.Action} action | 52 * @param {!UI.Action} action |
| 53 * @param {!Array<!WebInspector.ToolbarButton>=} toggledOptions | 53 * @param {!Array<!UI.ToolbarButton>=} toggledOptions |
| 54 * @param {!Array<!WebInspector.ToolbarButton>=} untoggledOptions | 54 * @param {!Array<!UI.ToolbarButton>=} untoggledOptions |
| 55 * @return {!WebInspector.ToolbarItem} | 55 * @return {!UI.ToolbarItem} |
| 56 */ | 56 */ |
| 57 static createActionButton(action, toggledOptions, untoggledOptions) { | 57 static createActionButton(action, toggledOptions, untoggledOptions) { |
| 58 var button = new WebInspector.ToolbarToggle(action.title(), action.icon(), a
ction.toggledIcon()); | 58 var button = new UI.ToolbarToggle(action.title(), action.icon(), action.togg
ledIcon()); |
| 59 button.setToggleWithRedColor(action.toggleWithRedColor()); | 59 button.setToggleWithRedColor(action.toggleWithRedColor()); |
| 60 button.addEventListener('click', action.execute, action); | 60 button.addEventListener('click', action.execute, action); |
| 61 action.addEventListener(WebInspector.Action.Events.Enabled, enabledChanged); | 61 action.addEventListener(UI.Action.Events.Enabled, enabledChanged); |
| 62 action.addEventListener(WebInspector.Action.Events.Toggled, toggled); | 62 action.addEventListener(UI.Action.Events.Toggled, toggled); |
| 63 /** @type {?WebInspector.LongClickController} */ | 63 /** @type {?UI.LongClickController} */ |
| 64 var longClickController = null; | 64 var longClickController = null; |
| 65 /** @type {?Array<!WebInspector.ToolbarButton>} */ | 65 /** @type {?Array<!UI.ToolbarButton>} */ |
| 66 var longClickButtons = null; | 66 var longClickButtons = null; |
| 67 /** @type {?Element} */ | 67 /** @type {?Element} */ |
| 68 var longClickGlyph = null; | 68 var longClickGlyph = null; |
| 69 toggled(); | 69 toggled(); |
| 70 return button; | 70 return button; |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * @param {!WebInspector.Event} event | 73 * @param {!Common.Event} event |
| 74 */ | 74 */ |
| 75 function enabledChanged(event) { | 75 function enabledChanged(event) { |
| 76 button.setEnabled(/** @type {boolean} */ (event.data)); | 76 button.setEnabled(/** @type {boolean} */ (event.data)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 function toggled() { | 79 function toggled() { |
| 80 button.setToggled(action.toggled()); | 80 button.setToggled(action.toggled()); |
| 81 if (action.title()) | 81 if (action.title()) |
| 82 WebInspector.Tooltip.install(button.element, action.title(), action.id()
); | 82 UI.Tooltip.install(button.element, action.title(), action.id()); |
| 83 updateOptions(); | 83 updateOptions(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 function updateOptions() { | 86 function updateOptions() { |
| 87 var buttons = action.toggled() ? (toggledOptions || null) : (untoggledOpti
ons || null); | 87 var buttons = action.toggled() ? (toggledOptions || null) : (untoggledOpti
ons || null); |
| 88 | 88 |
| 89 if (buttons && buttons.length) { | 89 if (buttons && buttons.length) { |
| 90 if (!longClickController) { | 90 if (!longClickController) { |
| 91 longClickController = new WebInspector.LongClickController(button.elem
ent, showOptions); | 91 longClickController = new UI.LongClickController(button.element, showO
ptions); |
| 92 longClickGlyph = WebInspector.Icon.create('largeicon-longclick-triangl
e', 'long-click-glyph'); | 92 longClickGlyph = UI.Icon.create('largeicon-longclick-triangle', 'long-
click-glyph'); |
| 93 button.element.appendChild(longClickGlyph); | 93 button.element.appendChild(longClickGlyph); |
| 94 longClickButtons = buttons; | 94 longClickButtons = buttons; |
| 95 } | 95 } |
| 96 } else { | 96 } else { |
| 97 if (longClickController) { | 97 if (longClickController) { |
| 98 longClickController.dispose(); | 98 longClickController.dispose(); |
| 99 longClickController = null; | 99 longClickController = null; |
| 100 longClickGlyph.remove(); | 100 longClickGlyph.remove(); |
| 101 longClickGlyph = null; | 101 longClickGlyph = null; |
| 102 longClickButtons = null; | 102 longClickButtons = null; |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 function showOptions() { | 107 function showOptions() { |
| 108 var buttons = longClickButtons.slice(); | 108 var buttons = longClickButtons.slice(); |
| 109 var mainButtonClone = new WebInspector.ToolbarToggle(action.title(), actio
n.icon(), action.toggledIcon()); | 109 var mainButtonClone = new UI.ToolbarToggle(action.title(), action.icon(),
action.toggledIcon()); |
| 110 mainButtonClone.addEventListener('click', clicked); | 110 mainButtonClone.addEventListener('click', clicked); |
| 111 | 111 |
| 112 /** | 112 /** |
| 113 * @param {!WebInspector.Event} event | 113 * @param {!Common.Event} event |
| 114 */ | 114 */ |
| 115 function clicked(event) { | 115 function clicked(event) { |
| 116 button._clicked(/** @type {!Event} */ (event.data)); | 116 button._clicked(/** @type {!Event} */ (event.data)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 mainButtonClone.setToggled(action.toggled()); | 119 mainButtonClone.setToggled(action.toggled()); |
| 120 buttons.push(mainButtonClone); | 120 buttons.push(mainButtonClone); |
| 121 | 121 |
| 122 var document = button.element.ownerDocument; | 122 var document = button.element.ownerDocument; |
| 123 document.documentElement.addEventListener('mouseup', mouseUp, false); | 123 document.documentElement.addEventListener('mouseup', mouseUp, false); |
| 124 | 124 |
| 125 var optionsGlassPane = new WebInspector.GlassPane(document); | 125 var optionsGlassPane = new UI.GlassPane(document); |
| 126 var optionsBar = new WebInspector.Toolbar('fill', optionsGlassPane.element
); | 126 var optionsBar = new UI.Toolbar('fill', optionsGlassPane.element); |
| 127 optionsBar._contentElement.classList.add('floating'); | 127 optionsBar._contentElement.classList.add('floating'); |
| 128 const buttonHeight = 26; | 128 const buttonHeight = 26; |
| 129 | 129 |
| 130 var hostButtonPosition = button.element.totalOffset(); | 130 var hostButtonPosition = button.element.totalOffset(); |
| 131 | 131 |
| 132 var topNotBottom = hostButtonPosition.top + buttonHeight * buttons.length
< document.documentElement.offsetHeight; | 132 var topNotBottom = hostButtonPosition.top + buttonHeight * buttons.length
< document.documentElement.offsetHeight; |
| 133 | 133 |
| 134 if (topNotBottom) | 134 if (topNotBottom) |
| 135 buttons = buttons.reverse(); | 135 buttons = buttons.reverse(); |
| 136 | 136 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 buttons[i]._clicked(e); | 175 buttons[i]._clicked(e); |
| 176 break; | 176 break; |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 /** | 183 /** |
| 184 * @param {string} actionId | 184 * @param {string} actionId |
| 185 * @return {?WebInspector.ToolbarItem} | 185 * @return {?UI.ToolbarItem} |
| 186 */ | 186 */ |
| 187 static createActionButtonForId(actionId) { | 187 static createActionButtonForId(actionId) { |
| 188 var action = WebInspector.actionRegistry.action(actionId); | 188 var action = UI.actionRegistry.action(actionId); |
| 189 return /** @type {?WebInspector.ToolbarItem} */ (action ? WebInspector.Toolb
ar.createActionButton(action) : null); | 189 return /** @type {?UI.ToolbarItem} */ (action ? UI.Toolbar.createActionButto
n(action) : null); |
| 190 } | 190 } |
| 191 | 191 |
| 192 /** | 192 /** |
| 193 * @param {boolean=} reverse | 193 * @param {boolean=} reverse |
| 194 */ | 194 */ |
| 195 makeWrappable(reverse) { | 195 makeWrappable(reverse) { |
| 196 this._contentElement.classList.add('wrappable'); | 196 this._contentElement.classList.add('wrappable'); |
| 197 this._reverse = !!reverse; | 197 this._reverse = !!reverse; |
| 198 if (reverse) | 198 if (reverse) |
| 199 this._contentElement.classList.add('wrappable-reverse'); | 199 this._contentElement.classList.add('wrappable-reverse'); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 217 | 217 |
| 218 /** | 218 /** |
| 219 * @param {boolean} enabled | 219 * @param {boolean} enabled |
| 220 */ | 220 */ |
| 221 setEnabled(enabled) { | 221 setEnabled(enabled) { |
| 222 for (var item of this._items) | 222 for (var item of this._items) |
| 223 item.setEnabled(enabled); | 223 item.setEnabled(enabled); |
| 224 } | 224 } |
| 225 | 225 |
| 226 /** | 226 /** |
| 227 * @param {!WebInspector.ToolbarItem} item | 227 * @param {!UI.ToolbarItem} item |
| 228 */ | 228 */ |
| 229 appendToolbarItem(item) { | 229 appendToolbarItem(item) { |
| 230 this._items.push(item); | 230 this._items.push(item); |
| 231 item._toolbar = this; | 231 item._toolbar = this; |
| 232 if (this._reverse) | 232 if (this._reverse) |
| 233 this._contentElement.insertBefore(item.element, this._insertionPoint.nextS
ibling); | 233 this._contentElement.insertBefore(item.element, this._insertionPoint.nextS
ibling); |
| 234 else | 234 else |
| 235 this._contentElement.insertBefore(item.element, this._insertionPoint); | 235 this._contentElement.insertBefore(item.element, this._insertionPoint); |
| 236 this._hideSeparatorDupes(); | 236 this._hideSeparatorDupes(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 appendSeparator() { | 239 appendSeparator() { |
| 240 this.appendToolbarItem(new WebInspector.ToolbarSeparator()); | 240 this.appendToolbarItem(new UI.ToolbarSeparator()); |
| 241 } | 241 } |
| 242 | 242 |
| 243 appendSpacer() { | 243 appendSpacer() { |
| 244 this.appendToolbarItem(new WebInspector.ToolbarSeparator(true)); | 244 this.appendToolbarItem(new UI.ToolbarSeparator(true)); |
| 245 } | 245 } |
| 246 | 246 |
| 247 /** | 247 /** |
| 248 * @param {string} text | 248 * @param {string} text |
| 249 */ | 249 */ |
| 250 appendText(text) { | 250 appendText(text) { |
| 251 this.appendToolbarItem(new WebInspector.ToolbarText(text)); | 251 this.appendToolbarItem(new UI.ToolbarText(text)); |
| 252 } | 252 } |
| 253 | 253 |
| 254 removeToolbarItems() { | 254 removeToolbarItems() { |
| 255 for (var item of this._items) | 255 for (var item of this._items) |
| 256 delete item._toolbar; | 256 delete item._toolbar; |
| 257 this._items = []; | 257 this._items = []; |
| 258 this._contentElement.removeChildren(); | 258 this._contentElement.removeChildren(); |
| 259 this._insertionPoint = this._contentElement.createChild('content'); | 259 this._insertionPoint = this._contentElement.createChild('content'); |
| 260 } | 260 } |
| 261 | 261 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 279 } | 279 } |
| 280 | 280 |
| 281 _hideSeparatorDupes() { | 281 _hideSeparatorDupes() { |
| 282 if (!this._items.length) | 282 if (!this._items.length) |
| 283 return; | 283 return; |
| 284 // Don't hide first and last separators if they were added explicitly. | 284 // Don't hide first and last separators if they were added explicitly. |
| 285 var previousIsSeparator = false; | 285 var previousIsSeparator = false; |
| 286 var lastSeparator; | 286 var lastSeparator; |
| 287 var nonSeparatorVisible = false; | 287 var nonSeparatorVisible = false; |
| 288 for (var i = 0; i < this._items.length; ++i) { | 288 for (var i = 0; i < this._items.length; ++i) { |
| 289 if (this._items[i] instanceof WebInspector.ToolbarSeparator) { | 289 if (this._items[i] instanceof UI.ToolbarSeparator) { |
| 290 this._items[i].setVisible(!previousIsSeparator); | 290 this._items[i].setVisible(!previousIsSeparator); |
| 291 previousIsSeparator = true; | 291 previousIsSeparator = true; |
| 292 lastSeparator = this._items[i]; | 292 lastSeparator = this._items[i]; |
| 293 continue; | 293 continue; |
| 294 } | 294 } |
| 295 if (this._items[i].visible()) { | 295 if (this._items[i].visible()) { |
| 296 previousIsSeparator = false; | 296 previousIsSeparator = false; |
| 297 lastSeparator = null; | 297 lastSeparator = null; |
| 298 nonSeparatorVisible = true; | 298 nonSeparatorVisible = true; |
| 299 } | 299 } |
| 300 } | 300 } |
| 301 if (lastSeparator && lastSeparator !== this._items.peekLast()) | 301 if (lastSeparator && lastSeparator !== this._items.peekLast()) |
| 302 lastSeparator.setVisible(false); | 302 lastSeparator.setVisible(false); |
| 303 | 303 |
| 304 this.element.classList.toggle('hidden', !!lastSeparator && lastSeparator.vis
ible() && !nonSeparatorVisible); | 304 this.element.classList.toggle('hidden', !!lastSeparator && lastSeparator.vis
ible() && !nonSeparatorVisible); |
| 305 } | 305 } |
| 306 | 306 |
| 307 /** | 307 /** |
| 308 * @param {string} location | 308 * @param {string} location |
| 309 */ | 309 */ |
| 310 appendLocationItems(location) { | 310 appendLocationItems(location) { |
| 311 var extensions = self.runtime.extensions(WebInspector.ToolbarItem.Provider); | 311 var extensions = self.runtime.extensions(UI.ToolbarItem.Provider); |
| 312 var promises = []; | 312 var promises = []; |
| 313 for (var i = 0; i < extensions.length; ++i) { | 313 for (var i = 0; i < extensions.length; ++i) { |
| 314 if (extensions[i].descriptor()['location'] === location) | 314 if (extensions[i].descriptor()['location'] === location) |
| 315 promises.push(resolveItem(extensions[i])); | 315 promises.push(resolveItem(extensions[i])); |
| 316 } | 316 } |
| 317 Promise.all(promises).then(appendItemsInOrder.bind(this)); | 317 Promise.all(promises).then(appendItemsInOrder.bind(this)); |
| 318 | 318 |
| 319 /** | 319 /** |
| 320 * @param {!Runtime.Extension} extension | 320 * @param {!Runtime.Extension} extension |
| 321 * @return {!Promise.<?WebInspector.ToolbarItem>} | 321 * @return {!Promise.<?UI.ToolbarItem>} |
| 322 */ | 322 */ |
| 323 function resolveItem(extension) { | 323 function resolveItem(extension) { |
| 324 var descriptor = extension.descriptor(); | 324 var descriptor = extension.descriptor(); |
| 325 if (descriptor['separator']) | 325 if (descriptor['separator']) |
| 326 return Promise.resolve(/** @type {?WebInspector.ToolbarItem} */ (new Web
Inspector.ToolbarSeparator())); | 326 return Promise.resolve(/** @type {?UI.ToolbarItem} */ (new UI.ToolbarSep
arator())); |
| 327 if (descriptor['actionId']) | 327 if (descriptor['actionId']) |
| 328 return Promise.resolve(WebInspector.Toolbar.createActionButtonForId(desc
riptor['actionId'])); | 328 return Promise.resolve(UI.Toolbar.createActionButtonForId(descriptor['ac
tionId'])); |
| 329 return extension.instance().then(fetchItemFromProvider); | 329 return extension.instance().then(fetchItemFromProvider); |
| 330 | 330 |
| 331 /** | 331 /** |
| 332 * @param {!Object} provider | 332 * @param {!Object} provider |
| 333 */ | 333 */ |
| 334 function fetchItemFromProvider(provider) { | 334 function fetchItemFromProvider(provider) { |
| 335 return /** @type {!WebInspector.ToolbarItem.Provider} */ (provider).item
(); | 335 return /** @type {!UI.ToolbarItem.Provider} */ (provider).item(); |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 /** | 339 /** |
| 340 * @param {!Array.<?WebInspector.ToolbarItem>} items | 340 * @param {!Array.<?UI.ToolbarItem>} items |
| 341 * @this {WebInspector.Toolbar} | 341 * @this {UI.Toolbar} |
| 342 */ | 342 */ |
| 343 function appendItemsInOrder(items) { | 343 function appendItemsInOrder(items) { |
| 344 for (var i = 0; i < items.length; ++i) { | 344 for (var i = 0; i < items.length; ++i) { |
| 345 var item = items[i]; | 345 var item = items[i]; |
| 346 if (item) | 346 if (item) |
| 347 this.appendToolbarItem(item); | 347 this.appendToolbarItem(item); |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 } | 350 } |
| 351 }; | 351 }; |
| 352 | 352 |
| 353 /** | 353 /** |
| 354 * @unrestricted | 354 * @unrestricted |
| 355 */ | 355 */ |
| 356 WebInspector.ToolbarItem = class extends WebInspector.Object { | 356 UI.ToolbarItem = class extends Common.Object { |
| 357 /** | 357 /** |
| 358 * @param {!Element} element | 358 * @param {!Element} element |
| 359 */ | 359 */ |
| 360 constructor(element) { | 360 constructor(element) { |
| 361 super(); | 361 super(); |
| 362 this.element = element; | 362 this.element = element; |
| 363 this.element.classList.add('toolbar-item'); | 363 this.element.classList.add('toolbar-item'); |
| 364 this._visible = true; | 364 this._visible = true; |
| 365 this._enabled = true; | 365 this._enabled = true; |
| 366 this.element.addEventListener('mouseenter', this._mouseEnter.bind(this), fal
se); | 366 this.element.addEventListener('mouseenter', this._mouseEnter.bind(this), fal
se); |
| 367 this.element.addEventListener('mouseleave', this._mouseLeave.bind(this), fal
se); | 367 this.element.addEventListener('mouseleave', this._mouseLeave.bind(this), fal
se); |
| 368 } | 368 } |
| 369 | 369 |
| 370 /** | 370 /** |
| 371 * @param {string} title | 371 * @param {string} title |
| 372 */ | 372 */ |
| 373 setTitle(title) { | 373 setTitle(title) { |
| 374 if (this._title === title) | 374 if (this._title === title) |
| 375 return; | 375 return; |
| 376 this._title = title; | 376 this._title = title; |
| 377 WebInspector.Tooltip.install(this.element, title); | 377 UI.Tooltip.install(this.element, title); |
| 378 } | 378 } |
| 379 | 379 |
| 380 _mouseEnter() { | 380 _mouseEnter() { |
| 381 this.element.classList.add('hover'); | 381 this.element.classList.add('hover'); |
| 382 } | 382 } |
| 383 | 383 |
| 384 _mouseLeave() { | 384 _mouseLeave() { |
| 385 this.element.classList.remove('hover'); | 385 this.element.classList.remove('hover'); |
| 386 } | 386 } |
| 387 | 387 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 407 } | 407 } |
| 408 | 408 |
| 409 /** | 409 /** |
| 410 * @param {boolean} x | 410 * @param {boolean} x |
| 411 */ | 411 */ |
| 412 setVisible(x) { | 412 setVisible(x) { |
| 413 if (this._visible === x) | 413 if (this._visible === x) |
| 414 return; | 414 return; |
| 415 this.element.classList.toggle('hidden', !x); | 415 this.element.classList.toggle('hidden', !x); |
| 416 this._visible = x; | 416 this._visible = x; |
| 417 if (this._toolbar && !(this instanceof WebInspector.ToolbarSeparator)) | 417 if (this._toolbar && !(this instanceof UI.ToolbarSeparator)) |
| 418 this._toolbar._hideSeparatorDupes(); | 418 this._toolbar._hideSeparatorDupes(); |
| 419 } | 419 } |
| 420 }; | 420 }; |
| 421 | 421 |
| 422 /** | 422 /** |
| 423 * @unrestricted | 423 * @unrestricted |
| 424 */ | 424 */ |
| 425 WebInspector.ToolbarText = class extends WebInspector.ToolbarItem { | 425 UI.ToolbarText = class extends UI.ToolbarItem { |
| 426 /** | 426 /** |
| 427 * @param {string=} text | 427 * @param {string=} text |
| 428 */ | 428 */ |
| 429 constructor(text) { | 429 constructor(text) { |
| 430 super(createElementWithClass('div', 'toolbar-text')); | 430 super(createElementWithClass('div', 'toolbar-text')); |
| 431 this.element.classList.add('toolbar-text'); | 431 this.element.classList.add('toolbar-text'); |
| 432 this.setText(text || ''); | 432 this.setText(text || ''); |
| 433 } | 433 } |
| 434 | 434 |
| 435 /** | 435 /** |
| 436 * @param {string} text | 436 * @param {string} text |
| 437 */ | 437 */ |
| 438 setText(text) { | 438 setText(text) { |
| 439 this.element.textContent = text; | 439 this.element.textContent = text; |
| 440 } | 440 } |
| 441 }; | 441 }; |
| 442 | 442 |
| 443 /** | 443 /** |
| 444 * @unrestricted | 444 * @unrestricted |
| 445 */ | 445 */ |
| 446 WebInspector.ToolbarButton = class extends WebInspector.ToolbarItem { | 446 UI.ToolbarButton = class extends UI.ToolbarItem { |
| 447 /** | 447 /** |
| 448 * @param {string} title | 448 * @param {string} title |
| 449 * @param {string=} glyph | 449 * @param {string=} glyph |
| 450 * @param {string=} text | 450 * @param {string=} text |
| 451 */ | 451 */ |
| 452 constructor(title, glyph, text) { | 452 constructor(title, glyph, text) { |
| 453 super(createElementWithClass('button', 'toolbar-button')); | 453 super(createElementWithClass('button', 'toolbar-button')); |
| 454 this.element.addEventListener('click', this._clicked.bind(this), false); | 454 this.element.addEventListener('click', this._clicked.bind(this), false); |
| 455 this.element.addEventListener('mousedown', this._mouseDown.bind(this), false
); | 455 this.element.addEventListener('mousedown', this._mouseDown.bind(this), false
); |
| 456 this.element.addEventListener('mouseup', this._mouseUp.bind(this), false); | 456 this.element.addEventListener('mouseup', this._mouseUp.bind(this), false); |
| 457 | 457 |
| 458 this._glyphElement = WebInspector.Icon.create('', 'toolbar-glyph hidden'); | 458 this._glyphElement = UI.Icon.create('', 'toolbar-glyph hidden'); |
| 459 this.element.appendChild(this._glyphElement); | 459 this.element.appendChild(this._glyphElement); |
| 460 this._textElement = this.element.createChild('div', 'toolbar-text hidden'); | 460 this._textElement = this.element.createChild('div', 'toolbar-text hidden'); |
| 461 | 461 |
| 462 this.setTitle(title); | 462 this.setTitle(title); |
| 463 if (glyph) | 463 if (glyph) |
| 464 this.setGlyph(glyph); | 464 this.setGlyph(glyph); |
| 465 this.setText(text || ''); | 465 this.setText(text || ''); |
| 466 this._title = ''; | 466 this._title = ''; |
| 467 } | 467 } |
| 468 | 468 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 494 */ | 494 */ |
| 495 setBackgroundImage(iconURL) { | 495 setBackgroundImage(iconURL) { |
| 496 this.element.style.backgroundImage = 'url(' + iconURL + ')'; | 496 this.element.style.backgroundImage = 'url(' + iconURL + ')'; |
| 497 } | 497 } |
| 498 | 498 |
| 499 /** | 499 /** |
| 500 * @param {number=} width | 500 * @param {number=} width |
| 501 */ | 501 */ |
| 502 turnIntoSelect(width) { | 502 turnIntoSelect(width) { |
| 503 this.element.classList.add('toolbar-has-dropdown'); | 503 this.element.classList.add('toolbar-has-dropdown'); |
| 504 var dropdownArrowIcon = WebInspector.Icon.create('smallicon-dropdown-arrow',
'toolbar-dropdown-arrow'); | 504 var dropdownArrowIcon = UI.Icon.create('smallicon-dropdown-arrow', 'toolbar-
dropdown-arrow'); |
| 505 this.element.appendChild(dropdownArrowIcon); | 505 this.element.appendChild(dropdownArrowIcon); |
| 506 if (width) | 506 if (width) |
| 507 this.element.style.width = width + 'px'; | 507 this.element.style.width = width + 'px'; |
| 508 } | 508 } |
| 509 | 509 |
| 510 /** | 510 /** |
| 511 * @param {!Event} event | 511 * @param {!Event} event |
| 512 */ | 512 */ |
| 513 _clicked(event) { | 513 _clicked(event) { |
| 514 var defaultPrevented = this.dispatchEventToListeners('click', event); | 514 var defaultPrevented = this.dispatchEventToListeners('click', event); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 526 * @param {!Event} event | 526 * @param {!Event} event |
| 527 */ | 527 */ |
| 528 _mouseUp(event) { | 528 _mouseUp(event) { |
| 529 this.dispatchEventToListeners('mouseup', event); | 529 this.dispatchEventToListeners('mouseup', event); |
| 530 } | 530 } |
| 531 }; | 531 }; |
| 532 | 532 |
| 533 /** | 533 /** |
| 534 * @unrestricted | 534 * @unrestricted |
| 535 */ | 535 */ |
| 536 WebInspector.ToolbarInput = class extends WebInspector.ToolbarItem { | 536 UI.ToolbarInput = class extends UI.ToolbarItem { |
| 537 /** | 537 /** |
| 538 * @param {string=} placeholder | 538 * @param {string=} placeholder |
| 539 * @param {number=} growFactor | 539 * @param {number=} growFactor |
| 540 */ | 540 */ |
| 541 constructor(placeholder, growFactor) { | 541 constructor(placeholder, growFactor) { |
| 542 super(createElementWithClass('input', 'toolbar-item')); | 542 super(createElementWithClass('input', 'toolbar-item')); |
| 543 this.element.addEventListener('input', this._onChangeCallback.bind(this), fa
lse); | 543 this.element.addEventListener('input', this._onChangeCallback.bind(this), fa
lse); |
| 544 if (growFactor) | 544 if (growFactor) |
| 545 this.element.style.flexGrow = growFactor; | 545 this.element.style.flexGrow = growFactor; |
| 546 if (placeholder) | 546 if (placeholder) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 557 } | 557 } |
| 558 | 558 |
| 559 /** | 559 /** |
| 560 * @return {string} | 560 * @return {string} |
| 561 */ | 561 */ |
| 562 value() { | 562 value() { |
| 563 return this.element.value; | 563 return this.element.value; |
| 564 } | 564 } |
| 565 | 565 |
| 566 _onChangeCallback() { | 566 _onChangeCallback() { |
| 567 this.dispatchEventToListeners(WebInspector.ToolbarInput.Event.TextChanged, t
his.element.value); | 567 this.dispatchEventToListeners(UI.ToolbarInput.Event.TextChanged, this.elemen
t.value); |
| 568 } | 568 } |
| 569 }; | 569 }; |
| 570 | 570 |
| 571 WebInspector.ToolbarInput.Event = { | 571 UI.ToolbarInput.Event = { |
| 572 TextChanged: 'TextChanged' | 572 TextChanged: 'TextChanged' |
| 573 }; | 573 }; |
| 574 | 574 |
| 575 /** | 575 /** |
| 576 * @unrestricted | 576 * @unrestricted |
| 577 */ | 577 */ |
| 578 WebInspector.ToolbarToggle = class extends WebInspector.ToolbarButton { | 578 UI.ToolbarToggle = class extends UI.ToolbarButton { |
| 579 /** | 579 /** |
| 580 * @param {string} title | 580 * @param {string} title |
| 581 * @param {string=} glyph | 581 * @param {string=} glyph |
| 582 * @param {string=} toggledGlyph | 582 * @param {string=} toggledGlyph |
| 583 */ | 583 */ |
| 584 constructor(title, glyph, toggledGlyph) { | 584 constructor(title, glyph, toggledGlyph) { |
| 585 super(title, glyph, ''); | 585 super(title, glyph, ''); |
| 586 this._toggled = false; | 586 this._toggled = false; |
| 587 this._untoggledGlyph = glyph; | 587 this._untoggledGlyph = glyph; |
| 588 this._toggledGlyph = toggledGlyph; | 588 this._toggledGlyph = toggledGlyph; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 614 */ | 614 */ |
| 615 setToggleWithRedColor(toggleWithRedColor) { | 615 setToggleWithRedColor(toggleWithRedColor) { |
| 616 this.element.classList.toggle('toolbar-toggle-with-red-color', toggleWithRed
Color); | 616 this.element.classList.toggle('toolbar-toggle-with-red-color', toggleWithRed
Color); |
| 617 } | 617 } |
| 618 }; | 618 }; |
| 619 | 619 |
| 620 | 620 |
| 621 /** | 621 /** |
| 622 * @unrestricted | 622 * @unrestricted |
| 623 */ | 623 */ |
| 624 WebInspector.ToolbarMenuButton = class extends WebInspector.ToolbarButton { | 624 UI.ToolbarMenuButton = class extends UI.ToolbarButton { |
| 625 /** | 625 /** |
| 626 * @param {function(!WebInspector.ContextMenu)} contextMenuHandler | 626 * @param {function(!UI.ContextMenu)} contextMenuHandler |
| 627 * @param {boolean=} useSoftMenu | 627 * @param {boolean=} useSoftMenu |
| 628 */ | 628 */ |
| 629 constructor(contextMenuHandler, useSoftMenu) { | 629 constructor(contextMenuHandler, useSoftMenu) { |
| 630 super('', 'largeicon-menu'); | 630 super('', 'largeicon-menu'); |
| 631 this._contextMenuHandler = contextMenuHandler; | 631 this._contextMenuHandler = contextMenuHandler; |
| 632 this._useSoftMenu = !!useSoftMenu; | 632 this._useSoftMenu = !!useSoftMenu; |
| 633 } | 633 } |
| 634 | 634 |
| 635 /** | 635 /** |
| 636 * @override | 636 * @override |
| (...skipping 12 matching lines...) Expand all Loading... |
| 649 /** | 649 /** |
| 650 * @param {!Event} event | 650 * @param {!Event} event |
| 651 */ | 651 */ |
| 652 _trigger(event) { | 652 _trigger(event) { |
| 653 delete this._triggerTimeout; | 653 delete this._triggerTimeout; |
| 654 | 654 |
| 655 // Throttling avoids entering a bad state on Macs when rapidly triggering co
ntext menus just | 655 // Throttling avoids entering a bad state on Macs when rapidly triggering co
ntext menus just |
| 656 // after the window gains focus. See crbug.com/655556 | 656 // after the window gains focus. See crbug.com/655556 |
| 657 if (this._lastTriggerTime && Date.now() - this._lastTriggerTime < 300) | 657 if (this._lastTriggerTime && Date.now() - this._lastTriggerTime < 300) |
| 658 return; | 658 return; |
| 659 var contextMenu = new WebInspector.ContextMenu( | 659 var contextMenu = new UI.ContextMenu( |
| 660 event, this._useSoftMenu, this.element.totalOffsetLeft(), | 660 event, this._useSoftMenu, this.element.totalOffsetLeft(), |
| 661 this.element.totalOffsetTop() + this.element.offsetHeight); | 661 this.element.totalOffsetTop() + this.element.offsetHeight); |
| 662 this._contextMenuHandler(contextMenu); | 662 this._contextMenuHandler(contextMenu); |
| 663 contextMenu.show(); | 663 contextMenu.show(); |
| 664 this._lastTriggerTime = Date.now(); | 664 this._lastTriggerTime = Date.now(); |
| 665 } | 665 } |
| 666 | 666 |
| 667 /** | 667 /** |
| 668 * @override | 668 * @override |
| 669 * @param {!Event} event | 669 * @param {!Event} event |
| 670 */ | 670 */ |
| 671 _clicked(event) { | 671 _clicked(event) { |
| 672 if (!this._triggerTimeout) | 672 if (!this._triggerTimeout) |
| 673 return; | 673 return; |
| 674 clearTimeout(this._triggerTimeout); | 674 clearTimeout(this._triggerTimeout); |
| 675 this._trigger(event); | 675 this._trigger(event); |
| 676 } | 676 } |
| 677 }; | 677 }; |
| 678 | 678 |
| 679 /** | 679 /** |
| 680 * @unrestricted | 680 * @unrestricted |
| 681 */ | 681 */ |
| 682 WebInspector.ToolbarSettingToggle = class extends WebInspector.ToolbarToggle { | 682 UI.ToolbarSettingToggle = class extends UI.ToolbarToggle { |
| 683 /** | 683 /** |
| 684 * @param {!WebInspector.Setting} setting | 684 * @param {!Common.Setting} setting |
| 685 * @param {string} glyph | 685 * @param {string} glyph |
| 686 * @param {string} title | 686 * @param {string} title |
| 687 * @param {string=} toggledTitle | 687 * @param {string=} toggledTitle |
| 688 */ | 688 */ |
| 689 constructor(setting, glyph, title, toggledTitle) { | 689 constructor(setting, glyph, title, toggledTitle) { |
| 690 super(title, glyph); | 690 super(title, glyph); |
| 691 this._defaultTitle = title; | 691 this._defaultTitle = title; |
| 692 this._toggledTitle = toggledTitle || title; | 692 this._toggledTitle = toggledTitle || title; |
| 693 this._setting = setting; | 693 this._setting = setting; |
| 694 this._settingChanged(); | 694 this._settingChanged(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 707 */ | 707 */ |
| 708 _clicked(event) { | 708 _clicked(event) { |
| 709 this._setting.set(!this.toggled()); | 709 this._setting.set(!this.toggled()); |
| 710 super._clicked(event); | 710 super._clicked(event); |
| 711 } | 711 } |
| 712 }; | 712 }; |
| 713 | 713 |
| 714 /** | 714 /** |
| 715 * @unrestricted | 715 * @unrestricted |
| 716 */ | 716 */ |
| 717 WebInspector.ToolbarSeparator = class extends WebInspector.ToolbarItem { | 717 UI.ToolbarSeparator = class extends UI.ToolbarItem { |
| 718 /** | 718 /** |
| 719 * @param {boolean=} spacer | 719 * @param {boolean=} spacer |
| 720 */ | 720 */ |
| 721 constructor(spacer) { | 721 constructor(spacer) { |
| 722 super(createElementWithClass('div', spacer ? 'toolbar-spacer' : 'toolbar-div
ider')); | 722 super(createElementWithClass('div', spacer ? 'toolbar-spacer' : 'toolbar-div
ider')); |
| 723 } | 723 } |
| 724 }; | 724 }; |
| 725 | 725 |
| 726 /** | 726 /** |
| 727 * @interface | 727 * @interface |
| 728 */ | 728 */ |
| 729 WebInspector.ToolbarItem.Provider = function() {}; | 729 UI.ToolbarItem.Provider = function() {}; |
| 730 | 730 |
| 731 WebInspector.ToolbarItem.Provider.prototype = { | 731 UI.ToolbarItem.Provider.prototype = { |
| 732 /** | 732 /** |
| 733 * @return {?WebInspector.ToolbarItem} | 733 * @return {?UI.ToolbarItem} |
| 734 */ | 734 */ |
| 735 item: function() {} | 735 item: function() {} |
| 736 }; | 736 }; |
| 737 | 737 |
| 738 /** | 738 /** |
| 739 * @interface | 739 * @interface |
| 740 */ | 740 */ |
| 741 WebInspector.ToolbarItem.ItemsProvider = function() {}; | 741 UI.ToolbarItem.ItemsProvider = function() {}; |
| 742 | 742 |
| 743 WebInspector.ToolbarItem.ItemsProvider.prototype = { | 743 UI.ToolbarItem.ItemsProvider.prototype = { |
| 744 /** | 744 /** |
| 745 * @return {!Array<!WebInspector.ToolbarItem>} | 745 * @return {!Array<!UI.ToolbarItem>} |
| 746 */ | 746 */ |
| 747 toolbarItems: function() {} | 747 toolbarItems: function() {} |
| 748 }; | 748 }; |
| 749 | 749 |
| 750 /** | 750 /** |
| 751 * @unrestricted | 751 * @unrestricted |
| 752 */ | 752 */ |
| 753 WebInspector.ToolbarComboBox = class extends WebInspector.ToolbarItem { | 753 UI.ToolbarComboBox = class extends UI.ToolbarItem { |
| 754 /** | 754 /** |
| 755 * @param {?function(!Event)} changeHandler | 755 * @param {?function(!Event)} changeHandler |
| 756 * @param {string=} className | 756 * @param {string=} className |
| 757 */ | 757 */ |
| 758 constructor(changeHandler, className) { | 758 constructor(changeHandler, className) { |
| 759 super(createElementWithClass('span', 'toolbar-select-container')); | 759 super(createElementWithClass('span', 'toolbar-select-container')); |
| 760 | 760 |
| 761 this._selectElement = this.element.createChild('select', 'toolbar-item'); | 761 this._selectElement = this.element.createChild('select', 'toolbar-item'); |
| 762 var dropdownArrowIcon = WebInspector.Icon.create('smallicon-dropdown-arrow',
'toolbar-dropdown-arrow'); | 762 var dropdownArrowIcon = UI.Icon.create('smallicon-dropdown-arrow', 'toolbar-
dropdown-arrow'); |
| 763 this.element.appendChild(dropdownArrowIcon); | 763 this.element.appendChild(dropdownArrowIcon); |
| 764 if (changeHandler) | 764 if (changeHandler) |
| 765 this._selectElement.addEventListener('change', changeHandler, false); | 765 this._selectElement.addEventListener('change', changeHandler, false); |
| 766 if (className) | 766 if (className) |
| 767 this._selectElement.classList.add(className); | 767 this._selectElement.classList.add(className); |
| 768 } | 768 } |
| 769 | 769 |
| 770 /** | 770 /** |
| 771 * @return {!HTMLSelectElement} | 771 * @return {!HTMLSelectElement} |
| 772 */ | 772 */ |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 * @param {number} width | 863 * @param {number} width |
| 864 */ | 864 */ |
| 865 setMaxWidth(width) { | 865 setMaxWidth(width) { |
| 866 this._selectElement.style.maxWidth = width + 'px'; | 866 this._selectElement.style.maxWidth = width + 'px'; |
| 867 } | 867 } |
| 868 }; | 868 }; |
| 869 | 869 |
| 870 /** | 870 /** |
| 871 * @unrestricted | 871 * @unrestricted |
| 872 */ | 872 */ |
| 873 WebInspector.ToolbarCheckbox = class extends WebInspector.ToolbarItem { | 873 UI.ToolbarCheckbox = class extends UI.ToolbarItem { |
| 874 /** | 874 /** |
| 875 * @param {string} text | 875 * @param {string} text |
| 876 * @param {string=} title | 876 * @param {string=} title |
| 877 * @param {!WebInspector.Setting=} setting | 877 * @param {!Common.Setting=} setting |
| 878 * @param {function()=} listener | 878 * @param {function()=} listener |
| 879 */ | 879 */ |
| 880 constructor(text, title, setting, listener) { | 880 constructor(text, title, setting, listener) { |
| 881 super(createCheckboxLabel(text)); | 881 super(createCheckboxLabel(text)); |
| 882 this.element.classList.add('checkbox'); | 882 this.element.classList.add('checkbox'); |
| 883 this.inputElement = this.element.checkboxElement; | 883 this.inputElement = this.element.checkboxElement; |
| 884 if (title) | 884 if (title) |
| 885 this.element.title = title; | 885 this.element.title = title; |
| 886 if (setting) | 886 if (setting) |
| 887 WebInspector.SettingsUI.bindCheckbox(this.inputElement, setting); | 887 UI.SettingsUI.bindCheckbox(this.inputElement, setting); |
| 888 if (listener) | 888 if (listener) |
| 889 this.inputElement.addEventListener('click', listener, false); | 889 this.inputElement.addEventListener('click', listener, false); |
| 890 } | 890 } |
| 891 | 891 |
| 892 /** | 892 /** |
| 893 * @return {boolean} | 893 * @return {boolean} |
| 894 */ | 894 */ |
| 895 checked() { | 895 checked() { |
| 896 return this.inputElement.checked; | 896 return this.inputElement.checked; |
| 897 } | 897 } |
| 898 | 898 |
| 899 /** | 899 /** |
| 900 * @param {boolean} value | 900 * @param {boolean} value |
| 901 */ | 901 */ |
| 902 setChecked(value) { | 902 setChecked(value) { |
| 903 this.inputElement.checked = value; | 903 this.inputElement.checked = value; |
| 904 } | 904 } |
| 905 }; | 905 }; |
| OLD | NEW |