OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv
ed. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv
ed. |
5 * Copyright (C) 2010 Google Inc. All rights reserved. | 5 * Copyright (C) 2010 Google Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
21 */ | 21 */ |
22 | 22 |
23 #include "config.h" | 23 #include "config.h" |
24 #include "core/html/HTMLImageElement.h" | 24 #include "core/html/HTMLImageElement.h" |
25 | 25 |
26 #include "CSSPropertyNames.h" | 26 #include "CSSPropertyNames.h" |
27 #include "HTMLNames.h" | 27 #include "HTMLNames.h" |
28 #include "RuntimeEnabledFeatures.h" | 28 #include "RuntimeEnabledFeatures.h" |
29 #include "bindings/v8/ScriptEventListener.h" | 29 #include "bindings/v8/ScriptEventListener.h" |
| 30 #include "core/css/parser/SizesAttributeParser.h" |
30 #include "core/dom/Attribute.h" | 31 #include "core/dom/Attribute.h" |
31 #include "core/fetch/ImageResource.h" | 32 #include "core/fetch/ImageResource.h" |
32 #include "core/html/HTMLAnchorElement.h" | 33 #include "core/html/HTMLAnchorElement.h" |
33 #include "core/html/HTMLCanvasElement.h" | 34 #include "core/html/HTMLCanvasElement.h" |
34 #include "core/html/HTMLFormElement.h" | 35 #include "core/html/HTMLFormElement.h" |
35 #include "core/html/canvas/CanvasRenderingContext.h" | 36 #include "core/html/canvas/CanvasRenderingContext.h" |
36 #include "core/html/parser/HTMLParserIdioms.h" | 37 #include "core/html/parser/HTMLParserIdioms.h" |
37 #include "core/html/parser/HTMLSrcsetParser.h" | 38 #include "core/html/parser/HTMLSrcsetParser.h" |
38 #include "core/rendering/RenderImage.h" | 39 #include "core/rendering/RenderImage.h" |
39 | 40 |
40 using namespace std; | 41 using namespace std; |
41 | 42 |
42 namespace WebCore { | 43 namespace WebCore { |
43 | 44 |
44 using namespace HTMLNames; | 45 using namespace HTMLNames; |
45 | 46 |
46 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form) | 47 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form) |
47 : HTMLElement(imgTag, document) | 48 : HTMLElement(imgTag, document) |
48 , m_imageLoader(this) | 49 , m_imageLoader(this) |
49 , m_compositeOperator(CompositeSourceOver) | 50 , m_compositeOperator(CompositeSourceOver) |
50 , m_imageDevicePixelRatio(1.0f) | 51 , m_imageDevicePixelRatio(1.0f) |
51 , m_formWasSetByParser(false) | 52 , m_formWasSetByParser(false) |
| 53 , m_effectiveSize(0) |
52 { | 54 { |
53 ScriptWrappable::init(this); | 55 ScriptWrappable::init(this); |
54 if (form && form->inDocument()) { | 56 if (form && form->inDocument()) { |
55 m_form = form->createWeakPtr(); | 57 m_form = form->createWeakPtr(); |
56 m_formWasSetByParser = true; | 58 m_formWasSetByParser = true; |
57 m_form->associate(*this); | 59 m_form->associate(*this); |
58 m_form->didAssociateByParser(); | 60 m_form->didAssociateByParser(); |
59 } | 61 } |
60 } | 62 } |
61 | 63 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 int effectiveSize = -1; // FIXME - hook up the real value from `size
s` | 160 int effectiveSize = -1; // FIXME - hook up the real value from `size
s` |
159 ImageCandidate candidate = bestFitSourceForImageAttributes(document(
).devicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute
(srcsetAttr)); | 161 ImageCandidate candidate = bestFitSourceForImageAttributes(document(
).devicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute
(srcsetAttr)); |
160 m_bestFitImageURL = candidate.toAtomicString(); | 162 m_bestFitImageURL = candidate.toAtomicString(); |
161 float candidateScaleFactor = candidate.scaleFactor(); | 163 float candidateScaleFactor = candidate.scaleFactor(); |
162 if (candidateScaleFactor > 0) | 164 if (candidateScaleFactor > 0) |
163 m_imageDevicePixelRatio = 1 / candidateScaleFactor; | 165 m_imageDevicePixelRatio = 1 / candidateScaleFactor; |
164 if (renderer() && renderer()->isImage()) | 166 if (renderer() && renderer()->isImage()) |
165 toRenderImage(renderer())->setImageDevicePixelRatio(m_imageDevic
ePixelRatio); | 167 toRenderImage(renderer())->setImageDevicePixelRatio(m_imageDevic
ePixelRatio); |
166 } | 168 } |
167 m_imageLoader.updateFromElementIgnoringPreviousError(); | 169 m_imageLoader.updateFromElementIgnoringPreviousError(); |
| 170 } else if (RuntimeEnabledFeatures::pictureSizesEnabled() && name == sizesAtt
r) { |
| 171 m_effectiveSize = SizesAttributeParser::findEffectiveSize(value, MediaVa
lues::create(document(), MediaValues::DynamicMode)); |
168 } else if (name == usemapAttr) { | 172 } else if (name == usemapAttr) { |
169 setIsLink(!value.isNull()); | 173 setIsLink(!value.isNull()); |
170 } else if (name == compositeAttr) { | 174 } else if (name == compositeAttr) { |
171 // FIXME: images don't support blend modes in their compositing attribut
e. | 175 // FIXME: images don't support blend modes in their compositing attribut
e. |
172 blink::WebBlendMode blendOp = blink::WebBlendModeNormal; | 176 blink::WebBlendMode blendOp = blink::WebBlendModeNormal; |
173 if (!parseCompositeAndBlendOperator(value, m_compositeOperator, blendOp)
) | 177 if (!parseCompositeAndBlendOperator(value, m_compositeOperator, blendOp)
) |
174 m_compositeOperator = CompositeSourceOver; | 178 m_compositeOperator = CompositeSourceOver; |
175 } else { | 179 } else { |
176 HTMLElement::parseAttribute(name, value); | 180 HTMLElement::parseAttribute(name, value); |
177 } | 181 } |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if (!image) | 471 if (!image) |
468 return FloatSize(); | 472 return FloatSize(); |
469 LayoutSize size; | 473 LayoutSize size; |
470 size = image->imageSizeForRenderer(renderer(), 1.0f); // FIXME: Not sure abo
ut this. | 474 size = image->imageSizeForRenderer(renderer(), 1.0f); // FIXME: Not sure abo
ut this. |
471 if (renderer() && renderer()->isRenderImage() && image->image() && !image->i
mage()->hasRelativeWidth()) | 475 if (renderer() && renderer()->isRenderImage() && image->image() && !image->i
mage()->hasRelativeWidth()) |
472 size.scale(toRenderImage(renderer())->imageDevicePixelRatio()); | 476 size.scale(toRenderImage(renderer())->imageDevicePixelRatio()); |
473 return size; | 477 return size; |
474 } | 478 } |
475 | 479 |
476 } | 480 } |
OLD | NEW |