Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {HTMLSpanElement} | 7 * @extends {HTMLSpanElement} |
| 8 */ | 8 */ |
| 9 UI.Icon = class extends HTMLSpanElement { | 9 UI.Icon = class extends HTMLSpanElement { |
| 10 constructor() { | 10 constructor() { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 this._descriptor = null; | 37 this._descriptor = null; |
| 38 /** @type {string} */ | 38 /** @type {string} */ |
| 39 this._iconType = ''; | 39 this._iconType = ''; |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * @param {string} iconType | 43 * @param {string} iconType |
| 44 */ | 44 */ |
| 45 setIconType(iconType) { | 45 setIconType(iconType) { |
| 46 if (this._descriptor) { | 46 if (this._descriptor) { |
| 47 this.style.removeProperty(this._propertyName()); | 47 this.style.removeProperty('-webkit-mask-position'); |
| 48 this.style.removeProperty('background-position'); | |
| 48 this.style.removeProperty('width'); | 49 this.style.removeProperty('width'); |
| 49 this.style.removeProperty('height'); | 50 this.style.removeProperty('height'); |
| 50 this.style.removeProperty('transform'); | 51 this.style.removeProperty('transform'); |
| 51 this.classList.remove(this._spritesheetClass()); | 52 this._toggleClasses(false); |
| 52 this.classList.remove(this._iconType); | |
| 53 this._iconType = ''; | 53 this._iconType = ''; |
| 54 this._descriptor = null; | 54 this._descriptor = null; |
| 55 } | 55 } |
| 56 var descriptor = UI.Icon.Descriptors[iconType] || null; | 56 var descriptor = UI.Icon.Descriptors[iconType] || null; |
| 57 if (descriptor) { | 57 if (descriptor) { |
| 58 this._iconType = iconType; | 58 this._iconType = iconType; |
| 59 this._descriptor = descriptor; | 59 this._descriptor = descriptor; |
| 60 this.style.setProperty(this._propertyName(), this._propertyValue()); | 60 this.style.setProperty('-webkit-mask-position', this._propertyValue()); |
| 61 this.style.setProperty('background-position', this._propertyValue()); | |
| 61 this.style.setProperty('width', this._descriptor.width + 'px'); | 62 this.style.setProperty('width', this._descriptor.width + 'px'); |
| 62 this.style.setProperty('height', this._descriptor.height + 'px'); | 63 this.style.setProperty('height', this._descriptor.height + 'px'); |
| 63 if (this._descriptor.transform) | 64 if (this._descriptor.transform) |
| 64 this.style.setProperty('transform', this._descriptor.transform); | 65 this.style.setProperty('transform', this._descriptor.transform); |
| 65 this.classList.add(this._spritesheetClass()); | 66 this._toggleClasses(true); |
| 66 this.classList.add(this._iconType); | |
| 67 } else if (iconType) { | 67 } else if (iconType) { |
| 68 throw new Error(`ERROR: failed to find icon descriptor for type: ${iconTyp e}`); | 68 throw new Error(`ERROR: failed to find icon descriptor for type: ${iconTyp e}`); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * @return {string} | 73 * @param {boolean} value |
| 74 */ | 74 */ |
| 75 _spritesheetClass() { | 75 _toggleClasses(value) { |
| 76 return 'spritesheet-' + this._descriptor.spritesheet + (this._descriptor.isM ask ? '-mask' : ''); | 76 this.classList.toggle('spritesheet-' + this._descriptor.spritesheet, value); |
| 77 this.classList.toggle(this._iconType, value); | |
| 78 this.classList.toggle('icon-mask', value && this._descriptor.isMask); | |
|
dgozman
2016/11/30 17:52:13
!!this._descriptor.isMask
lushnikov
2016/11/30 20:29:17
Done.
| |
| 77 } | 79 } |
| 78 | 80 |
| 79 /** | 81 /** |
| 80 * @return {string} | |
| 81 */ | |
| 82 _propertyName() { | |
| 83 return this._descriptor.isMask ? '-webkit-mask-position' : 'background-posit ion'; | |
| 84 } | |
| 85 | |
| 86 /** | |
| 87 * @return {string} | 82 * @return {string} |
| 88 */ | 83 */ |
| 89 _propertyValue() { | 84 _propertyValue() { |
| 90 return `${this._descriptor.x}px ${this._descriptor.y}px`; | 85 return `${this._descriptor.x}px ${this._descriptor.y}px`; |
| 91 } | 86 } |
| 92 }; | 87 }; |
| 93 | 88 |
| 94 /** @typedef {{x: number, y: number, width: number, height: number, spritesheet: string, isMask: (boolean|undefined)}} */ | 89 /** @typedef {{x: number, y: number, width: number, height: number, spritesheet: string, isMask: (boolean|undefined)}} */ |
| 95 UI.Icon.Descriptor; | 90 UI.Icon.Descriptor; |
| 96 | 91 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 'largeicon-hide-bottom-sidebar': { | 194 'largeicon-hide-bottom-sidebar': { |
| 200 x: -192, | 195 x: -192, |
| 201 y: -72, | 196 y: -72, |
| 202 width: 28, | 197 width: 28, |
| 203 height: 24, | 198 height: 24, |
| 204 spritesheet: 'largeicons', | 199 spritesheet: 'largeicons', |
| 205 isMask: true, | 200 isMask: true, |
| 206 transform: 'translate(4px, 1px) rotate(-90deg)' | 201 transform: 'translate(4px, 1px) rotate(-90deg)' |
| 207 }, | 202 }, |
| 208 }; | 203 }; |
| OLD | NEW |