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

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: Added a run-time flag, marking this feature as experimental 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
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"
35 #include "core/rendering/RenderImage.h" 36 #include "core/rendering/RenderImage.h"
36 37
37 using namespace std; 38 using namespace std;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 addHTMLLengthToStyle(style, CSSPropertyMarginLeft, value); 101 addHTMLLengthToStyle(style, CSSPropertyMarginLeft, value);
101 addHTMLLengthToStyle(style, CSSPropertyMarginRight, value); 102 addHTMLLengthToStyle(style, CSSPropertyMarginRight, value);
102 } else if (name == alignAttr) 103 } else if (name == alignAttr)
103 applyAlignmentAttributeToStyle(value, style); 104 applyAlignmentAttributeToStyle(value, style);
104 else if (name == valignAttr) 105 else if (name == valignAttr)
105 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, value); 106 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, value);
106 else 107 else
107 HTMLElement::collectStyleForPresentationAttribute(name, value, style); 108 HTMLElement::collectStyleForPresentationAttribute(name, value, style);
108 } 109 }
109 110
111 const AtomicString HTMLImageElement::imageSourceURL() const
112 {
113 return m_bestFitImageURL.isEmpty() ? fastGetAttribute(srcAttr) : m_bestFitIm ageURL;
do-not-use 2013/09/12 08:23:53 Wouldn't isNull() suffice? Can bestFitSourceForIma
Yoav Weiss 2013/09/12 09:30:20 m_bestFitImageURL is initialized as an empty strin
do-not-use 2013/09/12 09:56:37 To be clear the default constructor for String cre
114 }
115
110 void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value) 116 void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value)
111 { 117 {
112 if (name == altAttr) { 118 if (name == altAttr) {
113 if (renderer() && renderer()->isImage()) 119 if (renderer() && renderer()->isImage())
114 toRenderImage(renderer())->updateAltText(); 120 toRenderImage(renderer())->updateAltText();
115 } else if (name == srcAttr) 121 } else if (name == srcAttr || name == srcsetAttr) {
122 if (RuntimeEnabledFeatures::srcsetEnabled())
123 m_bestFitImageURL = bestFitSourceForImageAttributes(document().devic ePixelRatio(), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr));
116 m_imageLoader.updateFromElementIgnoringPreviousError(); 124 m_imageLoader.updateFromElementIgnoringPreviousError();
125 }
117 else if (name == usemapAttr) 126 else if (name == usemapAttr)
118 setIsLink(!value.isNull()); 127 setIsLink(!value.isNull());
119 else if (name == onbeforeloadAttr) 128 else if (name == onbeforeloadAttr)
120 setAttributeEventListener(eventNames().beforeloadEvent, createAttributeE ventListener(this, name, value)); 129 setAttributeEventListener(eventNames().beforeloadEvent, createAttributeE ventListener(this, name, value));
121 else if (name == compositeAttr) { 130 else if (name == compositeAttr) {
122 // FIXME: images don't support blend modes in their compositing attribut e. 131 // FIXME: images don't support blend modes in their compositing attribut e.
123 BlendMode blendOp = BlendModeNormal; 132 BlendMode blendOp = BlendModeNormal;
124 if (!parseCompositeAndBlendOperator(value, m_compositeOperator, blendOp) ) 133 if (!parseCompositeAndBlendOperator(value, m_compositeOperator, blendOp) )
125 m_compositeOperator = CompositeSourceOver; 134 m_compositeOperator = CompositeSourceOver;
126 } else 135 } else
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 376
368 Image* HTMLImageElement::imageContents() 377 Image* HTMLImageElement::imageContents()
369 { 378 {
370 if (!m_imageLoader.imageComplete()) 379 if (!m_imageLoader.imageComplete())
371 return 0; 380 return 0;
372 381
373 return m_imageLoader.image()->image(); 382 return m_imageLoader.image()->image();
374 } 383 }
375 384
376 } 385 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698