| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple 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 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * @unrestricted | 30 * @unrestricted |
| 31 */ | 31 */ |
| 32 WebInspector.FontView = class extends WebInspector.SimpleView { | 32 SourceFrame.FontView = class extends UI.SimpleView { |
| 33 /** | 33 /** |
| 34 * @param {string} mimeType | 34 * @param {string} mimeType |
| 35 * @param {!WebInspector.ContentProvider} contentProvider | 35 * @param {!Common.ContentProvider} contentProvider |
| 36 */ | 36 */ |
| 37 constructor(mimeType, contentProvider) { | 37 constructor(mimeType, contentProvider) { |
| 38 super(WebInspector.UIString('Font')); | 38 super(Common.UIString('Font')); |
| 39 this.registerRequiredCSS('source_frame/fontView.css'); | 39 this.registerRequiredCSS('source_frame/fontView.css'); |
| 40 this.element.classList.add('font-view'); | 40 this.element.classList.add('font-view'); |
| 41 this._url = contentProvider.contentURL(); | 41 this._url = contentProvider.contentURL(); |
| 42 this._mimeType = mimeType; | 42 this._mimeType = mimeType; |
| 43 this._contentProvider = contentProvider; | 43 this._contentProvider = contentProvider; |
| 44 this._mimeTypeLabel = new WebInspector.ToolbarText(mimeType); | 44 this._mimeTypeLabel = new UI.ToolbarText(mimeType); |
| 45 } | 45 } |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * @override | 48 * @override |
| 49 * @return {!Array<!WebInspector.ToolbarItem>} | 49 * @return {!Array<!UI.ToolbarItem>} |
| 50 */ | 50 */ |
| 51 syncToolbarItems() { | 51 syncToolbarItems() { |
| 52 return [this._mimeTypeLabel]; | 52 return [this._mimeTypeLabel]; |
| 53 } | 53 } |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * @param {string} uniqueFontName | 56 * @param {string} uniqueFontName |
| 57 * @param {?string} content | 57 * @param {?string} content |
| 58 */ | 58 */ |
| 59 _onFontContentLoaded(uniqueFontName, content) { | 59 _onFontContentLoaded(uniqueFontName, content) { |
| 60 var url = content ? WebInspector.ContentProvider.contentAsDataURL(content, t
his._mimeType, true) : this._url; | 60 var url = content ? Common.ContentProvider.contentAsDataURL(content, this._m
imeType, true) : this._url; |
| 61 this.fontStyleElement.textContent = | 61 this.fontStyleElement.textContent = |
| 62 String.sprintf('@font-face { font-family: "%s"; src: url(%s); }', unique
FontName, url); | 62 String.sprintf('@font-face { font-family: "%s"; src: url(%s); }', unique
FontName, url); |
| 63 } | 63 } |
| 64 | 64 |
| 65 _createContentIfNeeded() { | 65 _createContentIfNeeded() { |
| 66 if (this.fontPreviewElement) | 66 if (this.fontPreviewElement) |
| 67 return; | 67 return; |
| 68 | 68 |
| 69 var uniqueFontName = 'WebInspectorFontPreview' + (++WebInspector.FontView._f
ontId); | 69 var uniqueFontName = 'WebInspectorFontPreview' + (++SourceFrame.FontView._fo
ntId); |
| 70 | 70 |
| 71 this.fontStyleElement = createElement('style'); | 71 this.fontStyleElement = createElement('style'); |
| 72 this._contentProvider.requestContent().then(this._onFontContentLoaded.bind(t
his, uniqueFontName)); | 72 this._contentProvider.requestContent().then(this._onFontContentLoaded.bind(t
his, uniqueFontName)); |
| 73 this.element.appendChild(this.fontStyleElement); | 73 this.element.appendChild(this.fontStyleElement); |
| 74 | 74 |
| 75 var fontPreview = createElement('div'); | 75 var fontPreview = createElement('div'); |
| 76 for (var i = 0; i < WebInspector.FontView._fontPreviewLines.length; ++i) { | 76 for (var i = 0; i < SourceFrame.FontView._fontPreviewLines.length; ++i) { |
| 77 if (i > 0) | 77 if (i > 0) |
| 78 fontPreview.createChild('br'); | 78 fontPreview.createChild('br'); |
| 79 fontPreview.createTextChild(WebInspector.FontView._fontPreviewLines[i]); | 79 fontPreview.createTextChild(SourceFrame.FontView._fontPreviewLines[i]); |
| 80 } | 80 } |
| 81 this.fontPreviewElement = fontPreview.cloneNode(true); | 81 this.fontPreviewElement = fontPreview.cloneNode(true); |
| 82 this.fontPreviewElement.style.setProperty('font-family', uniqueFontName); | 82 this.fontPreviewElement.style.setProperty('font-family', uniqueFontName); |
| 83 this.fontPreviewElement.style.setProperty('visibility', 'hidden'); | 83 this.fontPreviewElement.style.setProperty('visibility', 'hidden'); |
| 84 | 84 |
| 85 this._dummyElement = fontPreview; | 85 this._dummyElement = fontPreview; |
| 86 this._dummyElement.style.visibility = 'hidden'; | 86 this._dummyElement.style.visibility = 'hidden'; |
| 87 this._dummyElement.style.zIndex = '-1'; | 87 this._dummyElement.style.zIndex = '-1'; |
| 88 this._dummyElement.style.display = 'inline'; | 88 this._dummyElement.style.display = 'inline'; |
| 89 this._dummyElement.style.position = 'absolute'; | 89 this._dummyElement.style.position = 'absolute'; |
| 90 this._dummyElement.style.setProperty('font-family', uniqueFontName); | 90 this._dummyElement.style.setProperty('font-family', uniqueFontName); |
| 91 this._dummyElement.style.setProperty('font-size', WebInspector.FontView._mea
sureFontSize + 'px'); | 91 this._dummyElement.style.setProperty('font-size', SourceFrame.FontView._meas
ureFontSize + 'px'); |
| 92 | 92 |
| 93 this.element.appendChild(this.fontPreviewElement); | 93 this.element.appendChild(this.fontPreviewElement); |
| 94 } | 94 } |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * @override | 97 * @override |
| 98 */ | 98 */ |
| 99 wasShown() { | 99 wasShown() { |
| 100 this._createContentIfNeeded(); | 100 this._createContentIfNeeded(); |
| 101 | 101 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 const containerWidth = this.element.offsetWidth - 50; | 139 const containerWidth = this.element.offsetWidth - 50; |
| 140 const containerHeight = this.element.offsetHeight - 30; | 140 const containerHeight = this.element.offsetHeight - 30; |
| 141 | 141 |
| 142 if (!height || !width || !containerWidth || !containerHeight) { | 142 if (!height || !width || !containerWidth || !containerHeight) { |
| 143 this.fontPreviewElement.style.removeProperty('font-size'); | 143 this.fontPreviewElement.style.removeProperty('font-size'); |
| 144 return; | 144 return; |
| 145 } | 145 } |
| 146 | 146 |
| 147 var widthRatio = containerWidth / width; | 147 var widthRatio = containerWidth / width; |
| 148 var heightRatio = containerHeight / height; | 148 var heightRatio = containerHeight / height; |
| 149 var finalFontSize = Math.floor(WebInspector.FontView._measureFontSize * Math
.min(widthRatio, heightRatio)) - 2; | 149 var finalFontSize = Math.floor(SourceFrame.FontView._measureFontSize * Math.
min(widthRatio, heightRatio)) - 2; |
| 150 | 150 |
| 151 this.fontPreviewElement.style.setProperty('font-size', finalFontSize + 'px',
null); | 151 this.fontPreviewElement.style.setProperty('font-size', finalFontSize + 'px',
null); |
| 152 } | 152 } |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 WebInspector.FontView._fontPreviewLines = | 155 SourceFrame.FontView._fontPreviewLines = |
| 156 ['ABCDEFGHIJKLM', 'NOPQRSTUVWXYZ', 'abcdefghijklm', 'nopqrstuvwxyz', '123456
7890']; | 156 ['ABCDEFGHIJKLM', 'NOPQRSTUVWXYZ', 'abcdefghijklm', 'nopqrstuvwxyz', '123456
7890']; |
| 157 | 157 |
| 158 WebInspector.FontView._fontId = 0; | 158 SourceFrame.FontView._fontId = 0; |
| 159 | 159 |
| 160 WebInspector.FontView._measureFontSize = 50; | 160 SourceFrame.FontView._measureFontSize = 50; |
| OLD | NEW |