Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: Source/core/html/HTMLImageElement.cpp

Issue 224733011: A sizes attribute parser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed rebase Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/html/HTMLImageElement.h ('k') | Source/core/html/HTMLImageElement.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/MediaValuesDynamic.h"
31 #include "core/css/parser/SizesAttributeParser.h"
30 #include "core/dom/Attribute.h" 32 #include "core/dom/Attribute.h"
31 #include "core/fetch/ImageResource.h" 33 #include "core/fetch/ImageResource.h"
32 #include "core/html/HTMLAnchorElement.h" 34 #include "core/html/HTMLAnchorElement.h"
33 #include "core/html/HTMLCanvasElement.h" 35 #include "core/html/HTMLCanvasElement.h"
34 #include "core/html/HTMLFormElement.h" 36 #include "core/html/HTMLFormElement.h"
35 #include "core/html/canvas/CanvasRenderingContext.h" 37 #include "core/html/canvas/CanvasRenderingContext.h"
36 #include "core/html/parser/HTMLParserIdioms.h" 38 #include "core/html/parser/HTMLParserIdioms.h"
37 #include "core/html/parser/HTMLSrcsetParser.h" 39 #include "core/html/parser/HTMLSrcsetParser.h"
38 #include "core/rendering/RenderImage.h" 40 #include "core/rendering/RenderImage.h"
39 41
40 using namespace std; 42 using namespace std;
41 43
42 namespace WebCore { 44 namespace WebCore {
43 45
44 using namespace HTMLNames; 46 using namespace HTMLNames;
45 47
46 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form) 48 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form)
47 : HTMLElement(imgTag, document) 49 : HTMLElement(imgTag, document)
48 , m_imageLoader(this) 50 , m_imageLoader(this)
49 , m_compositeOperator(CompositeSourceOver) 51 , m_compositeOperator(CompositeSourceOver)
50 , m_imageDevicePixelRatio(1.0f) 52 , m_imageDevicePixelRatio(1.0f)
51 , m_formWasSetByParser(false) 53 , m_formWasSetByParser(false)
54 , m_effectiveSize(0)
52 { 55 {
53 ScriptWrappable::init(this); 56 ScriptWrappable::init(this);
54 if (form && form->inDocument()) { 57 if (form && form->inDocument()) {
55 m_form = form->createWeakPtr(); 58 m_form = form->createWeakPtr();
56 m_formWasSetByParser = true; 59 m_formWasSetByParser = true;
57 m_form->associate(*this); 60 m_form->associate(*this);
58 m_form->didAssociateByParser(); 61 m_form->didAssociateByParser();
59 } 62 }
60 } 63 }
61 64
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } else if (name == srcAttr || name == srcsetAttr) { 159 } else if (name == srcAttr || name == srcsetAttr) {
157 int effectiveSize = -1; // FIXME - hook up the real value from `sizes` 160 int effectiveSize = -1; // FIXME - hook up the real value from `sizes`
158 ImageCandidate candidate = bestFitSourceForImageAttributes(document().de vicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute(src setAttr)); 161 ImageCandidate candidate = bestFitSourceForImageAttributes(document().de vicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute(src setAttr));
159 m_bestFitImageURL = candidate.toAtomicString(); 162 m_bestFitImageURL = candidate.toAtomicString();
160 float candidateScaleFactor = candidate.scaleFactor(); 163 float candidateScaleFactor = candidate.scaleFactor();
161 if (candidateScaleFactor > 0) 164 if (candidateScaleFactor > 0)
162 m_imageDevicePixelRatio = 1 / candidateScaleFactor; 165 m_imageDevicePixelRatio = 1 / candidateScaleFactor;
163 if (renderer() && renderer()->isImage()) 166 if (renderer() && renderer()->isImage())
164 toRenderImage(renderer())->setImageDevicePixelRatio(m_imageDevicePix elRatio); 167 toRenderImage(renderer())->setImageDevicePixelRatio(m_imageDevicePix elRatio);
165 m_imageLoader.updateFromElementIgnoringPreviousError(); 168 m_imageLoader.updateFromElementIgnoringPreviousError();
169 } else if (RuntimeEnabledFeatures::pictureSizesEnabled() && name == sizesAtt r) {
170 m_effectiveSize = SizesAttributeParser::findEffectiveSize(value, MediaVa luesDynamic::create(document()));
166 } else if (name == usemapAttr) { 171 } else if (name == usemapAttr) {
167 setIsLink(!value.isNull()); 172 setIsLink(!value.isNull());
168 } else if (name == compositeAttr) { 173 } else if (name == compositeAttr) {
169 // FIXME: images don't support blend modes in their compositing attribut e. 174 // FIXME: images don't support blend modes in their compositing attribut e.
170 blink::WebBlendMode blendOp = blink::WebBlendModeNormal; 175 blink::WebBlendMode blendOp = blink::WebBlendModeNormal;
171 if (!parseCompositeAndBlendOperator(value, m_compositeOperator, blendOp) ) 176 if (!parseCompositeAndBlendOperator(value, m_compositeOperator, blendOp) )
172 m_compositeOperator = CompositeSourceOver; 177 m_compositeOperator = CompositeSourceOver;
173 } else { 178 } else {
174 HTMLElement::parseAttribute(name, value); 179 HTMLElement::parseAttribute(name, value);
175 } 180 }
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 if (!image) 470 if (!image)
466 return FloatSize(); 471 return FloatSize();
467 LayoutSize size; 472 LayoutSize size;
468 size = image->imageSizeForRenderer(renderer(), 1.0f); // FIXME: Not sure abo ut this. 473 size = image->imageSizeForRenderer(renderer(), 1.0f); // FIXME: Not sure abo ut this.
469 if (renderer() && renderer()->isRenderImage() && image->image() && !image->i mage()->hasRelativeWidth()) 474 if (renderer() && renderer()->isRenderImage() && image->image() && !image->i mage()->hasRelativeWidth())
470 size.scale(toRenderImage(renderer())->imageDevicePixelRatio()); 475 size.scale(toRenderImage(renderer())->imageDevicePixelRatio());
471 return size; 476 return size;
472 } 477 }
473 478
474 } 479 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLImageElement.h ('k') | Source/core/html/HTMLImageElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698