| 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 26 matching lines...) Expand all Loading... |
| 37 /** @type {!Array.<!WebInspector.ToolbarItem>} */ | 37 /** @type {!Array.<!WebInspector.ToolbarItem>} */ |
| 38 this._items = []; | 38 this._items = []; |
| 39 this.element = parentElement ? parentElement.createChild("div", "toolbar") :
createElementWithClass("div", "toolbar"); | 39 this.element = parentElement ? parentElement.createChild("div", "toolbar") :
createElementWithClass("div", "toolbar"); |
| 40 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element)
; | 40 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element)
; |
| 41 this._shadowRoot.appendChild(WebInspector.Widget.createStyleElement("ui/tool
bar.css")); | 41 this._shadowRoot.appendChild(WebInspector.Widget.createStyleElement("ui/tool
bar.css")); |
| 42 this._contentElement = this._shadowRoot.createChild("div", "toolbar-shadow")
; | 42 this._contentElement = this._shadowRoot.createChild("div", "toolbar-shadow")
; |
| 43 this._contentElement.createChild("content"); | 43 this._contentElement.createChild("content"); |
| 44 } | 44 } |
| 45 | 45 |
| 46 WebInspector.Toolbar.prototype = { | 46 WebInspector.Toolbar.prototype = { |
| 47 makeNarrow: function() | |
| 48 { | |
| 49 this._contentElement.classList.add("narrow"); | |
| 50 }, | |
| 51 | |
| 52 makeVertical: function() | 47 makeVertical: function() |
| 53 { | 48 { |
| 54 this._contentElement.classList.add("vertical"); | 49 this._contentElement.classList.add("vertical"); |
| 55 }, | 50 }, |
| 56 | 51 |
| 57 /** | 52 /** |
| 58 * @param {boolean} enabled | 53 * @param {boolean} enabled |
| 59 */ | 54 */ |
| 60 setEnabled: function(enabled) | 55 setEnabled: function(enabled) |
| 61 { | 56 { |
| 62 for (var item of this._items) | 57 for (var item of this._items) |
| 63 item.setEnabled(enabled); | 58 item.setEnabled(enabled); |
| 64 }, | 59 }, |
| 65 | 60 |
| 66 /** | 61 /** |
| 67 * @param {!WebInspector.ToolbarItem} item | 62 * @param {!WebInspector.ToolbarItem} item |
| 68 */ | 63 */ |
| 69 appendToolbarItem: function(item) | 64 appendToolbarItem: function(item) |
| 70 { | 65 { |
| 71 this._items.push(item); | 66 this._items.push(item); |
| 67 item._toolbar = this; |
| 72 this._contentElement.insertBefore(item.element, this._contentElement.las
tChild); | 68 this._contentElement.insertBefore(item.element, this._contentElement.las
tChild); |
| 69 this._hideSeparatorDupes(); |
| 70 }, |
| 71 |
| 72 appendSeparator: function() |
| 73 { |
| 74 this.appendToolbarItem(new WebInspector.ToolbarSeparator()); |
| 73 }, | 75 }, |
| 74 | 76 |
| 75 removeToolbarItems: function() | 77 removeToolbarItems: function() |
| 76 { | 78 { |
| 79 for (var item of this._items) |
| 80 delete item._toolbar; |
| 77 this._items = []; | 81 this._items = []; |
| 78 this._contentElement.removeChildren(); | 82 this._contentElement.removeChildren(); |
| 79 this._contentElement.createChild("content"); | 83 this._contentElement.createChild("content"); |
| 80 }, | 84 }, |
| 81 | 85 |
| 82 /** | 86 /** |
| 83 * @param {string} color | 87 * @param {string} color |
| 84 */ | 88 */ |
| 85 setColor: function(color) | 89 setColor: function(color) |
| 86 { | 90 { |
| 87 var style = createElement("style"); | 91 var style = createElement("style"); |
| 88 style.textContent = "button.toolbar-item .glyph { background-color: " +
color + " !important }"; | 92 style.textContent = "button.toolbar-item .glyph { background-color: " +
color + " !important }"; |
| 89 this._shadowRoot.appendChild(style); | 93 this._shadowRoot.appendChild(style); |
| 90 }, | 94 }, |
| 91 | 95 |
| 92 /** | 96 /** |
| 93 * @param {string} color | 97 * @param {string} color |
| 94 */ | 98 */ |
| 95 setToggledColor: function(color) | 99 setToggledColor: function(color) |
| 96 { | 100 { |
| 97 var style = createElement("style"); | 101 var style = createElement("style"); |
| 98 style.textContent = "button.toolbar-item.toggled-on .glyph { background-
color: " + color + " !important }"; | 102 style.textContent = "button.toolbar-item.toggled-on .glyph { background-
color: " + color + " !important }"; |
| 99 this._shadowRoot.appendChild(style); | 103 this._shadowRoot.appendChild(style); |
| 104 }, |
| 105 |
| 106 _hideSeparatorDupes: function() |
| 107 { |
| 108 // Don't hide first and last separators if they were added explicitly. |
| 109 var previousIsSeparator = true; |
| 110 var lastSeparator; |
| 111 for (var i = 1; i < this._items.length; ++i) { |
| 112 if (this._items[i] instanceof WebInspector.ToolbarSeparator) { |
| 113 this._items[i].setVisible(!previousIsSeparator); |
| 114 previousIsSeparator = true; |
| 115 lastSeparator = this._items[i]; |
| 116 continue; |
| 117 } |
| 118 if (this._items[i].visible()) { |
| 119 previousIsSeparator = false; |
| 120 lastSeparator = null; |
| 121 } |
| 122 } |
| 123 if (lastSeparator && lastSeparator !== this._items.peekLast()) |
| 124 lastSeparator.setVisible(false); |
| 100 } | 125 } |
| 101 } | 126 } |
| 102 | 127 |
| 103 /** | 128 /** |
| 104 * @constructor | 129 * @constructor |
| 105 * @extends {WebInspector.Object} | 130 * @extends {WebInspector.Object} |
| 106 * @param {!Element} element | 131 * @param {!Element} element |
| 107 */ | 132 */ |
| 108 WebInspector.ToolbarItem = function(element) | 133 WebInspector.ToolbarItem = function(element) |
| 109 { | 134 { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 140 | 165 |
| 141 /** | 166 /** |
| 142 * @param {boolean} x | 167 * @param {boolean} x |
| 143 */ | 168 */ |
| 144 setVisible: function(x) | 169 setVisible: function(x) |
| 145 { | 170 { |
| 146 if (this._visible === x) | 171 if (this._visible === x) |
| 147 return; | 172 return; |
| 148 this.element.classList.toggle("hidden", !x); | 173 this.element.classList.toggle("hidden", !x); |
| 149 this._visible = x; | 174 this._visible = x; |
| 175 if (this._toolbar && !(this instanceof WebInspector.ToolbarSeparator)) |
| 176 this._toolbar._hideSeparatorDupes(); |
| 150 }, | 177 }, |
| 151 | 178 |
| 152 __proto__: WebInspector.Object.prototype | 179 __proto__: WebInspector.Object.prototype |
| 153 } | 180 } |
| 154 | 181 |
| 155 /** | 182 /** |
| 156 * @constructor | 183 * @constructor |
| 157 * @extends {WebInspector.ToolbarItem} | 184 * @extends {WebInspector.ToolbarItem} |
| 158 * @param {!Array.<string>} counters | 185 * @param {!Array.<string>} counters |
| 159 */ | 186 */ |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 buttons.push(mainButtonClone); | 507 buttons.push(mainButtonClone); |
| 481 | 508 |
| 482 var document = this.element.ownerDocument; | 509 var document = this.element.ownerDocument; |
| 483 document.documentElement.addEventListener("mouseup", mouseUp, false); | 510 document.documentElement.addEventListener("mouseup", mouseUp, false); |
| 484 | 511 |
| 485 var optionsGlassPane = new WebInspector.GlassPane(document); | 512 var optionsGlassPane = new WebInspector.GlassPane(document); |
| 486 var optionsBar = new WebInspector.Toolbar(optionsGlassPane.element); | 513 var optionsBar = new WebInspector.Toolbar(optionsGlassPane.element); |
| 487 | 514 |
| 488 optionsBar.element.classList.add("fill"); | 515 optionsBar.element.classList.add("fill"); |
| 489 optionsBar._contentElement.classList.add("floating"); | 516 optionsBar._contentElement.classList.add("floating"); |
| 490 const buttonHeight = 23; | 517 const buttonHeight = 26; |
| 491 | 518 |
| 492 var hostButtonPosition = this.element.totalOffset(); | 519 var hostButtonPosition = this.element.totalOffset(); |
| 493 | 520 |
| 494 var topNotBottom = hostButtonPosition.top + buttonHeight * buttons.lengt
h < document.documentElement.offsetHeight; | 521 var topNotBottom = hostButtonPosition.top + buttonHeight * buttons.lengt
h < document.documentElement.offsetHeight; |
| 495 | 522 |
| 496 if (topNotBottom) | 523 if (topNotBottom) |
| 497 buttons = buttons.reverse(); | 524 buttons = buttons.reverse(); |
| 498 | 525 |
| 499 optionsBar.element.style.height = (buttonHeight * buttons.length) + "px"
; | 526 optionsBar.element.style.height = (buttonHeight * buttons.length) + "px"
; |
| 500 if (topNotBottom) | 527 if (topNotBottom) |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 } | 972 } |
| 946 Promise.all(promises).then(appendItemsInOrder.bind(this)); | 973 Promise.all(promises).then(appendItemsInOrder.bind(this)); |
| 947 | 974 |
| 948 /** | 975 /** |
| 949 * @param {!Runtime.Extension} extension | 976 * @param {!Runtime.Extension} extension |
| 950 * @return {!Promise.<?WebInspector.ToolbarItem>} | 977 * @return {!Promise.<?WebInspector.ToolbarItem>} |
| 951 */ | 978 */ |
| 952 function resolveItem(extension) | 979 function resolveItem(extension) |
| 953 { | 980 { |
| 954 var descriptor = extension.descriptor(); | 981 var descriptor = extension.descriptor(); |
| 955 if (!descriptor.className) | 982 if (descriptor["separator"]) |
| 983 return Promise.resolve(/** @type {?WebInspector.ToolbarItem} */(
new WebInspector.ToolbarSeparator())); |
| 984 if (!descriptor["className"]) |
| 956 return Promise.resolve(new WebInspector.ToolbarButton(WebInspect
or.UIString(descriptor["title"]), descriptor["elementClass"])).then(attachHandle
r); | 985 return Promise.resolve(new WebInspector.ToolbarButton(WebInspect
or.UIString(descriptor["title"]), descriptor["elementClass"])).then(attachHandle
r); |
| 957 return extension.instancePromise().then(fetchItemFromProvider).then(
attachHandler); | 986 return extension.instancePromise().then(fetchItemFromProvider).then(
attachHandler); |
| 958 | 987 |
| 959 /** | 988 /** |
| 960 * @param {!Object} provider | 989 * @param {!Object} provider |
| 961 */ | 990 */ |
| 962 function fetchItemFromProvider(provider) | 991 function fetchItemFromProvider(provider) |
| 963 { | 992 { |
| 964 return /** @type {!WebInspector.ToolbarItem.Provider} */ (provid
er).item(); | 993 return /** @type {!WebInspector.ToolbarItem.Provider} */ (provid
er).item(); |
| 965 } | 994 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 990 for (var i = 0; i < items.length; ++i) { | 1019 for (var i = 0; i < items.length; ++i) { |
| 991 var item = items[i]; | 1020 var item = items[i]; |
| 992 if (item) | 1021 if (item) |
| 993 this.appendToolbarItem(item); | 1022 this.appendToolbarItem(item); |
| 994 } | 1023 } |
| 995 } | 1024 } |
| 996 }, | 1025 }, |
| 997 | 1026 |
| 998 __proto__: WebInspector.Toolbar.prototype | 1027 __proto__: WebInspector.Toolbar.prototype |
| 999 } | 1028 } |
| OLD | NEW |