| 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.ImageView = class extends WebInspector.SimpleView { | 32 SourceFrame.ImageView = 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('Image')); | 38 super(Common.UIString('Image')); |
| 39 this.registerRequiredCSS('source_frame/imageView.css'); | 39 this.registerRequiredCSS('source_frame/imageView.css'); |
| 40 this.element.classList.add('image-view'); | 40 this.element.classList.add('image-view'); |
| 41 this._url = contentProvider.contentURL(); | 41 this._url = contentProvider.contentURL(); |
| 42 this._parsedURL = new WebInspector.ParsedURL(this._url); | 42 this._parsedURL = new Common.ParsedURL(this._url); |
| 43 this._mimeType = mimeType; | 43 this._mimeType = mimeType; |
| 44 this._contentProvider = contentProvider; | 44 this._contentProvider = contentProvider; |
| 45 this._sizeLabel = new WebInspector.ToolbarText(); | 45 this._sizeLabel = new UI.ToolbarText(); |
| 46 this._dimensionsLabel = new WebInspector.ToolbarText(); | 46 this._dimensionsLabel = new UI.ToolbarText(); |
| 47 this._mimeTypeLabel = new WebInspector.ToolbarText(mimeType); | 47 this._mimeTypeLabel = new UI.ToolbarText(mimeType); |
| 48 } | 48 } |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * @override | 51 * @override |
| 52 * @return {!Array<!WebInspector.ToolbarItem>} | 52 * @return {!Array<!UI.ToolbarItem>} |
| 53 */ | 53 */ |
| 54 syncToolbarItems() { | 54 syncToolbarItems() { |
| 55 return [ | 55 return [ |
| 56 this._sizeLabel, new WebInspector.ToolbarSeparator(), this._dimensionsLabe
l, new WebInspector.ToolbarSeparator(), | 56 this._sizeLabel, new UI.ToolbarSeparator(), this._dimensionsLabel, new UI.
ToolbarSeparator(), |
| 57 this._mimeTypeLabel | 57 this._mimeTypeLabel |
| 58 ]; | 58 ]; |
| 59 } | 59 } |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * @override | 62 * @override |
| 63 */ | 63 */ |
| 64 wasShown() { | 64 wasShown() { |
| 65 this._createContentIfNeeded(); | 65 this._createContentIfNeeded(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 _createContentIfNeeded() { | 68 _createContentIfNeeded() { |
| 69 if (this._container) | 69 if (this._container) |
| 70 return; | 70 return; |
| 71 | 71 |
| 72 this._container = this.element.createChild('div', 'image'); | 72 this._container = this.element.createChild('div', 'image'); |
| 73 var imagePreviewElement = this._container.createChild('img', 'resource-image
-view'); | 73 var imagePreviewElement = this._container.createChild('img', 'resource-image
-view'); |
| 74 imagePreviewElement.addEventListener('contextmenu', this._contextMenu.bind(t
his), true); | 74 imagePreviewElement.addEventListener('contextmenu', this._contextMenu.bind(t
his), true); |
| 75 | 75 |
| 76 this._contentProvider.requestContent().then(onContentAvailable.bind(this)); | 76 this._contentProvider.requestContent().then(onContentAvailable.bind(this)); |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * @param {?string} content | 79 * @param {?string} content |
| 80 * @this {WebInspector.ImageView} | 80 * @this {SourceFrame.ImageView} |
| 81 */ | 81 */ |
| 82 function onContentAvailable(content) { | 82 function onContentAvailable(content) { |
| 83 var imageSrc = WebInspector.ContentProvider.contentAsDataURL(content, this
._mimeType, true); | 83 var imageSrc = Common.ContentProvider.contentAsDataURL(content, this._mime
Type, true); |
| 84 if (imageSrc === null) | 84 if (imageSrc === null) |
| 85 imageSrc = this._url; | 85 imageSrc = this._url; |
| 86 imagePreviewElement.src = imageSrc; | 86 imagePreviewElement.src = imageSrc; |
| 87 this._sizeLabel.setText(Number.bytesToString(this._base64ToSize(content)))
; | 87 this._sizeLabel.setText(Number.bytesToString(this._base64ToSize(content)))
; |
| 88 this._dimensionsLabel.setText( | 88 this._dimensionsLabel.setText( |
| 89 WebInspector.UIString('%d × %d', imagePreviewElement.naturalWidth, ima
gePreviewElement.naturalHeight)); | 89 Common.UIString('%d × %d', imagePreviewElement.naturalWidth, imagePrev
iewElement.naturalHeight)); |
| 90 } | 90 } |
| 91 this._imagePreviewElement = imagePreviewElement; | 91 this._imagePreviewElement = imagePreviewElement; |
| 92 } | 92 } |
| 93 | 93 |
| 94 /** | 94 /** |
| 95 * @param {?string} content | 95 * @param {?string} content |
| 96 * @return {number} | 96 * @return {number} |
| 97 */ | 97 */ |
| 98 _base64ToSize(content) { | 98 _base64ToSize(content) { |
| 99 if (!content || !content.length) | 99 if (!content || !content.length) |
| 100 return 0; | 100 return 0; |
| 101 var size = (content.length || 0) * 3 / 4; | 101 var size = (content.length || 0) * 3 / 4; |
| 102 if (content.length > 0 && content[content.length - 1] === '=') | 102 if (content.length > 0 && content[content.length - 1] === '=') |
| 103 size--; | 103 size--; |
| 104 if (content.length > 1 && content[content.length - 2] === '=') | 104 if (content.length > 1 && content[content.length - 2] === '=') |
| 105 size--; | 105 size--; |
| 106 return size; | 106 return size; |
| 107 } | 107 } |
| 108 | 108 |
| 109 _contextMenu(event) { | 109 _contextMenu(event) { |
| 110 var contextMenu = new WebInspector.ContextMenu(event); | 110 var contextMenu = new UI.ContextMenu(event); |
| 111 if (!this._parsedURL.isDataURL()) | 111 if (!this._parsedURL.isDataURL()) |
| 112 contextMenu.appendItem(WebInspector.UIString.capitalize('Copy ^image URL')
, this._copyImageURL.bind(this)); | 112 contextMenu.appendItem(Common.UIString.capitalize('Copy ^image URL'), this
._copyImageURL.bind(this)); |
| 113 if (this._imagePreviewElement.src) | 113 if (this._imagePreviewElement.src) |
| 114 contextMenu.appendItem( | 114 contextMenu.appendItem( |
| 115 WebInspector.UIString.capitalize('Copy ^image as Data URI'), this._cop
yImageAsDataURL.bind(this)); | 115 Common.UIString.capitalize('Copy ^image as Data URI'), this._copyImage
AsDataURL.bind(this)); |
| 116 contextMenu.appendItem(WebInspector.UIString.capitalize('Open ^image in ^new
^tab'), this._openInNewTab.bind(this)); | 116 contextMenu.appendItem(Common.UIString.capitalize('Open ^image in ^new ^tab'
), this._openInNewTab.bind(this)); |
| 117 contextMenu.appendItem(WebInspector.UIString.capitalize('Save\u2026'), this.
_saveImage.bind(this)); | 117 contextMenu.appendItem(Common.UIString.capitalize('Save\u2026'), this._saveI
mage.bind(this)); |
| 118 contextMenu.show(); | 118 contextMenu.show(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 _copyImageAsDataURL() { | 121 _copyImageAsDataURL() { |
| 122 InspectorFrontendHost.copyText(this._imagePreviewElement.src); | 122 InspectorFrontendHost.copyText(this._imagePreviewElement.src); |
| 123 } | 123 } |
| 124 | 124 |
| 125 _copyImageURL() { | 125 _copyImageURL() { |
| 126 InspectorFrontendHost.copyText(this._url); | 126 InspectorFrontendHost.copyText(this._url); |
| 127 } | 127 } |
| 128 | 128 |
| 129 _saveImage() { | 129 _saveImage() { |
| 130 var link = createElement('a'); | 130 var link = createElement('a'); |
| 131 link.download = this._parsedURL.displayName; | 131 link.download = this._parsedURL.displayName; |
| 132 link.href = this._url; | 132 link.href = this._url; |
| 133 link.click(); | 133 link.click(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 _openInNewTab() { | 136 _openInNewTab() { |
| 137 InspectorFrontendHost.openInNewTab(this._url); | 137 InspectorFrontendHost.openInNewTab(this._url); |
| 138 } | 138 } |
| 139 }; | 139 }; |
| OLD | NEW |