2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * @extends {WebInspector.VBox}
33 * @param {string} mimeType
34 * @param {!WebInspector.ContentProvider} contentProvider
36 WebInspector
.ImageView = function(url
, mimeType
, contentProvider
)
38 WebInspector
.VBox
.call(this);
39 this.registerRequiredCSS("source_frame/imageView.css");
40 this.element
.classList
.add("image-view");
42 this._parsedURL
= new WebInspector
.ParsedURL(url
);
43 this._mimeType
= mimeType
;
44 this._contentProvider
= contentProvider
;
47 WebInspector
.ImageView
.prototype = {
50 this._createContentIfNeeded();
53 _createContentIfNeeded: function()
58 var imageContainer
= this.element
.createChild("div", "image");
59 var imagePreviewElement
= imageContainer
.createChild("img", "resource-image-view");
60 imagePreviewElement
.addEventListener("contextmenu", this._contextMenu
.bind(this), true);
62 this._container
= this.element
.createChild("div", "info");
63 this._container
.createChild("h1", "title").textContent
= this._parsedURL
.displayName
;
65 var infoListElement
= createElementWithClass("dl", "infoList");
67 WebInspector
.Resource
.populateImageSource(this._url
, this._mimeType
, this._contentProvider
, imagePreviewElement
);
68 this._contentProvider
.requestContent(onContentAvailable
.bind(this));
71 * @param {?string} content
72 * @this {WebInspector.ImageView}
74 function onContentAvailable(content
)
76 var resourceSize
= this._base64ToSize(content
);
78 var imageProperties
= [
79 { name
: WebInspector
.UIString("Dimensions"), value
: WebInspector
.UIString("%d × %d", imagePreviewElement
.naturalWidth
, imagePreviewElement
.naturalHeight
) },
80 { name
: WebInspector
.UIString("File size"), value
: Number
.bytesToString(resourceSize
) },
81 { name
: WebInspector
.UIString("MIME type"), value
: this._mimeType
}
84 infoListElement
.removeChildren();
85 for (var i
= 0; i
< imageProperties
.length
; ++i
) {
86 infoListElement
.createChild("dt").textContent
= imageProperties
[i
].name
;
87 infoListElement
.createChild("dd").textContent
= imageProperties
[i
].value
;
89 infoListElement
.createChild("dt").textContent
= WebInspector
.UIString("URL");
90 infoListElement
.createChild("dd").appendChild(WebInspector
.linkifyURLAsNode(this._url
, undefined, undefined, true));
91 this._container
.appendChild(infoListElement
);
93 this._imagePreviewElement
= imagePreviewElement
;
97 * @param {?string} content
100 _base64ToSize: function(content
)
102 if (!content
|| !content
.length
)
104 var size
= (content
.length
|| 0) * 3 / 4;
105 if (content
.length
> 0 && content
[content
.length
- 1] === "=")
107 if (content
.length
> 1 && content
[content
.length
- 2] === "=")
112 _contextMenu: function(event
)
114 var contextMenu
= new WebInspector
.ContextMenu(event
);
115 contextMenu
.appendItem(WebInspector
.UIString
.capitalize("Copy ^image URL"), this._copyImageURL
.bind(this));
116 if (this._imagePreviewElement
.src
)
117 contextMenu
.appendItem(WebInspector
.UIString
.capitalize("Copy ^image as Data URL"), this._copyImageAsDataURL
.bind(this));
118 contextMenu
.appendItem(WebInspector
.UIString
.capitalize("Open ^image in ^new ^tab"), this._openInNewTab
.bind(this));
122 _copyImageAsDataURL: function()
124 InspectorFrontendHost
.copyText(this._imagePreviewElement
.src
);
127 _copyImageURL: function()
129 InspectorFrontendHost
.copyText(this._url
);
132 _openInNewTab: function()
134 InspectorFrontendHost
.openInNewTab(this._url
);
137 __proto__
: WebInspector
.VBox
.prototype