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

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

Issue 23861003: Enable srcset support in HTMLImageElement (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed a flaky test Created 7 years, 3 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 "bindings/v8/ScriptEventListener.h" 29 #include "bindings/v8/ScriptEventListener.h"
29 #include "core/dom/Attribute.h" 30 #include "core/dom/Attribute.h"
30 #include "core/dom/EventNames.h" 31 #include "core/dom/EventNames.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/HTMLFormElement.h" 34 #include "core/html/HTMLFormElement.h"
34 #include "core/html/parser/HTMLParserIdioms.h" 35 #include "core/html/parser/HTMLParserIdioms.h"
36 #include "core/html/parser/HTMLSrcsetParser.h"
35 #include "core/rendering/RenderImage.h" 37 #include "core/rendering/RenderImage.h"
36 38
37 using namespace std; 39 using namespace std;
38 40
39 namespace WebCore { 41 namespace WebCore {
40 42
41 using namespace HTMLNames; 43 using namespace HTMLNames;
42 44
43 HTMLImageElement::HTMLImageElement(const QualifiedName& tagName, Document& docum ent, HTMLFormElement* form) 45 HTMLImageElement::HTMLImageElement(const QualifiedName& tagName, Document& docum ent, HTMLFormElement* form)
44 : HTMLElement(tagName, document) 46 : HTMLElement(tagName, document)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 addHTMLLengthToStyle(style, CSSPropertyMarginLeft, value); 102 addHTMLLengthToStyle(style, CSSPropertyMarginLeft, value);
101 addHTMLLengthToStyle(style, CSSPropertyMarginRight, value); 103 addHTMLLengthToStyle(style, CSSPropertyMarginRight, value);
102 } else if (name == alignAttr) 104 } else if (name == alignAttr)
103 applyAlignmentAttributeToStyle(value, style); 105 applyAlignmentAttributeToStyle(value, style);
104 else if (name == valignAttr) 106 else if (name == valignAttr)
105 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, value); 107 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, value);
106 else 108 else
107 HTMLElement::collectStyleForPresentationAttribute(name, value, style); 109 HTMLElement::collectStyleForPresentationAttribute(name, value, style);
108 } 110 }
109 111
112 const AtomicString HTMLImageElement::imageSourceURL() const
113 {
114 return m_bestFitImageURL.isNull() ? fastGetAttribute(srcAttr) : m_bestFitIma geURL;
115 }
116
110 void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value) 117 void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value)
111 { 118 {
112 if (name == altAttr) { 119 if (name == altAttr) {
113 if (renderer() && renderer()->isImage()) 120 if (renderer() && renderer()->isImage())
114 toRenderImage(renderer())->updateAltText(); 121 toRenderImage(renderer())->updateAltText();
115 } else if (name == srcAttr) 122 } else if (name == srcAttr || name == srcsetAttr) {
123 if (RuntimeEnabledFeatures::srcsetEnabled())
124 m_bestFitImageURL = bestFitSourceForImageAttributes(document().devic ePixelRatio(), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr));
116 m_imageLoader.updateFromElementIgnoringPreviousError(); 125 m_imageLoader.updateFromElementIgnoringPreviousError();
126 }
117 else if (name == usemapAttr) 127 else if (name == usemapAttr)
118 setIsLink(!value.isNull()); 128 setIsLink(!value.isNull());
119 else if (name == onbeforeloadAttr) 129 else if (name == onbeforeloadAttr)
120 setAttributeEventListener(eventNames().beforeloadEvent, createAttributeE ventListener(this, name, value)); 130 setAttributeEventListener(eventNames().beforeloadEvent, createAttributeE ventListener(this, name, value));
121 else if (name == compositeAttr) { 131 else if (name == compositeAttr) {
122 // FIXME: images don't support blend modes in their compositing attribut e. 132 // FIXME: images don't support blend modes in their compositing attribut e.
123 BlendMode blendOp = BlendModeNormal; 133 BlendMode blendOp = BlendModeNormal;
124 if (!parseCompositeAndBlendOperator(value, m_compositeOperator, blendOp) ) 134 if (!parseCompositeAndBlendOperator(value, m_compositeOperator, blendOp) )
125 m_compositeOperator = CompositeSourceOver; 135 m_compositeOperator = CompositeSourceOver;
126 } else 136 } else
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 377
368 Image* HTMLImageElement::imageContents() 378 Image* HTMLImageElement::imageContents()
369 { 379 {
370 if (!m_imageLoader.imageComplete()) 380 if (!m_imageLoader.imageComplete())
371 return 0; 381 return 0;
372 382
373 return m_imageLoader.image()->image(); 383 return m_imageLoader.image()->image();
374 } 384 }
375 385
376 } 386 }
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