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

Side by Side Diff: sky/engine/core/html/HTMLImageElement.cpp

Issue 706093002: Remove <picture> and <source>. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 | « sky/engine/core/html/HTMLImageElement.h ('k') | sky/engine/core/html/HTMLPictureElement.h » ('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 "core/CSSPropertyNames.h" 26 #include "core/CSSPropertyNames.h"
27 #include "core/HTMLNames.h" 27 #include "core/HTMLNames.h"
28 #include "core/MediaTypeNames.h" 28 #include "core/MediaTypeNames.h"
29 #include "core/css/MediaQueryListListener.h"
29 #include "core/css/MediaQueryMatcher.h" 30 #include "core/css/MediaQueryMatcher.h"
30 #include "core/css/MediaValuesDynamic.h" 31 #include "core/css/MediaValuesDynamic.h"
31 #include "core/css/parser/SizesAttributeParser.h" 32 #include "core/css/parser/SizesAttributeParser.h"
32 #include "core/dom/Attribute.h" 33 #include "core/dom/Attribute.h"
33 #include "core/dom/NodeTraversal.h" 34 #include "core/dom/NodeTraversal.h"
34 #include "core/fetch/ImageResource.h" 35 #include "core/fetch/ImageResource.h"
35 #include "core/frame/UseCounter.h" 36 #include "core/frame/UseCounter.h"
36 #include "core/html/HTMLAnchorElement.h" 37 #include "core/html/HTMLAnchorElement.h"
37 #include "core/html/HTMLCanvasElement.h" 38 #include "core/html/HTMLCanvasElement.h"
38 #include "core/html/HTMLSourceElement.h"
39 #include "core/html/canvas/CanvasRenderingContext.h" 39 #include "core/html/canvas/CanvasRenderingContext.h"
40 #include "core/html/parser/HTMLParserIdioms.h" 40 #include "core/html/parser/HTMLParserIdioms.h"
41 #include "core/html/parser/HTMLSrcsetParser.h" 41 #include "core/html/parser/HTMLSrcsetParser.h"
42 #include "core/inspector/ConsoleMessage.h" 42 #include "core/inspector/ConsoleMessage.h"
43 #include "core/rendering/RenderImage.h" 43 #include "core/rendering/RenderImage.h"
44 #include "platform/MIMETypeRegistry.h" 44 #include "platform/MIMETypeRegistry.h"
45 #include "platform/RuntimeEnabledFeatures.h" 45 #include "platform/RuntimeEnabledFeatures.h"
46 46
47 namespace blink { 47 namespace blink {
48 48
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // lets figure out the alt text.. magic stuff 176 // lets figure out the alt text.. magic stuff
177 // http://www.w3.org/TR/1998/REC-html40-19980424/appendix/notes.html#altgen 177 // http://www.w3.org/TR/1998/REC-html40-19980424/appendix/notes.html#altgen
178 // also heavily discussed by Hixie on bugzilla 178 // also heavily discussed by Hixie on bugzilla
179 const AtomicString& alt = getAttribute(HTMLNames::altAttr); 179 const AtomicString& alt = getAttribute(HTMLNames::altAttr);
180 if (!alt.isNull()) 180 if (!alt.isNull())
181 return alt; 181 return alt;
182 // fall back to title attribute 182 // fall back to title attribute
183 return getAttribute(HTMLNames::titleAttr); 183 return getAttribute(HTMLNames::titleAttr);
184 } 184 }
185 185
186 static bool supportedImageType(const String& type)
187 {
188 return MIMETypeRegistry::isSupportedImagePrefixedMIMEType(type);
189 }
190
191 // http://picture.responsiveimages.org/#update-source-set
192 ImageCandidate HTMLImageElement::findBestFitImageFromPictureParent()
193 {
194 ASSERT(isMainThread());
195 Node* parent = parentNode();
196 if (!parent || !isHTMLPictureElement(*parent))
197 return ImageCandidate();
198 for (Node* child = parent->firstChild(); child; child = child->nextSibling() ) {
199 if (child == this)
200 return ImageCandidate();
201
202 if (!isHTMLSourceElement(*child))
203 continue;
204
205 HTMLSourceElement* source = toHTMLSourceElement(child);
206 if (!source->getAttribute(HTMLNames::srcAttr).isNull())
207 UseCounter::countDeprecation(document(), UseCounter::PictureSourceSr c);
208 String srcset = source->getAttribute(HTMLNames::srcsetAttr);
209 if (srcset.isEmpty())
210 continue;
211 String type = source->getAttribute(HTMLNames::typeAttr);
212 if (!type.isEmpty() && !supportedImageType(type))
213 continue;
214
215 if (!source->mediaQueryMatches())
216 continue;
217
218 String sizes = source->getAttribute(HTMLNames::sizesAttr);
219 if (!sizes.isNull())
220 UseCounter::count(document(), UseCounter::Sizes);
221 SizesAttributeParser parser = SizesAttributeParser(MediaValuesDynamic::c reate(document()), sizes);
222 unsigned effectiveSize = parser.length();
223 m_effectiveSizeViewportDependant = parser.viewportDependant();
224 ImageCandidate candidate = bestFitSourceForSrcsetAttribute(document().de vicePixelRatio(), effectiveSize, source->getAttribute(HTMLNames::srcsetAttr));
225 if (candidate.isEmpty())
226 continue;
227 return candidate;
228 }
229 return ImageCandidate();
230 }
231
232 RenderObject* HTMLImageElement::createRenderer(RenderStyle* style) 186 RenderObject* HTMLImageElement::createRenderer(RenderStyle* style)
233 { 187 {
234 RenderImage* image = new RenderImage(this); 188 RenderImage* image = new RenderImage(this);
235 image->setImageResource(RenderImageResource::create()); 189 image->setImageResource(RenderImageResource::create());
236 image->setImageDevicePixelRatio(m_imageDevicePixelRatio); 190 image->setImageDevicePixelRatio(m_imageDevicePixelRatio);
237 return image; 191 return image;
238 } 192 }
239 193
240 bool HTMLImageElement::canStartSelection() const 194 bool HTMLImageElement::canStartSelection() const
241 { 195 {
(...skipping 21 matching lines...) Expand all
263 renderImageResource->setImageResource(imageLoader().image()); 217 renderImageResource->setImageResource(imageLoader().image());
264 218
265 } 219 }
266 } 220 }
267 221
268 Node::InsertionNotificationRequest HTMLImageElement::insertedInto(ContainerNode* insertionPoint) 222 Node::InsertionNotificationRequest HTMLImageElement::insertedInto(ContainerNode* insertionPoint)
269 { 223 {
270 if (m_listener) 224 if (m_listener)
271 document().mediaQueryMatcher().addViewportListener(m_listener.get()); 225 document().mediaQueryMatcher().addViewportListener(m_listener.get());
272 226
273 bool imageWasModified = false;
274 if (RuntimeEnabledFeatures::pictureEnabled()) {
275 ImageCandidate candidate = findBestFitImageFromPictureParent();
276 if (!candidate.isEmpty()) {
277 setBestFitURLAndDPRFromImageCandidate(candidate);
278 imageWasModified = true;
279 }
280 }
281
282 // If we have been inserted from a renderer-less document, 227 // If we have been inserted from a renderer-less document,
283 // our loader may have not fetched the image, so do it now. 228 // our loader may have not fetched the image, so do it now.
284 if ((insertionPoint->inDocument() && !imageLoader().image()) || imageWasModi fied) 229 if ((insertionPoint->inDocument() && !imageLoader().image()))
285 imageLoader().updateFromElement(ImageLoader::UpdateNormal, m_elementCrea tedByParser ? ImageLoader::ForceLoadImmediately : ImageLoader::LoadNormally); 230 imageLoader().updateFromElement(ImageLoader::UpdateNormal, m_elementCrea tedByParser ? ImageLoader::ForceLoadImmediately : ImageLoader::LoadNormally);
286 231
287 return HTMLElement::insertedInto(insertionPoint); 232 return HTMLElement::insertedInto(insertionPoint);
288 } 233 }
289 234
290 void HTMLImageElement::removedFrom(ContainerNode* insertionPoint) 235 void HTMLImageElement::removedFrom(ContainerNode* insertionPoint)
291 { 236 {
292 if (m_listener) 237 if (m_listener)
293 document().mediaQueryMatcher().removeViewportListener(m_listener.get()); 238 document().mediaQueryMatcher().removeViewportListener(m_listener.get());
294 HTMLElement::removedFrom(insertionPoint); 239 HTMLElement::removedFrom(insertionPoint);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 LayoutSize size; 440 LayoutSize size;
496 size = image->imageSizeForRenderer(renderer(), 1.0f); // FIXME: Not sure abo ut this. 441 size = image->imageSizeForRenderer(renderer(), 1.0f); // FIXME: Not sure abo ut this.
497 if (renderer() && renderer()->isRenderImage() && image->image() && !image->i mage()->hasRelativeWidth()) 442 if (renderer() && renderer()->isRenderImage() && image->image() && !image->i mage()->hasRelativeWidth())
498 size.scale(toRenderImage(renderer())->imageDevicePixelRatio()); 443 size.scale(toRenderImage(renderer())->imageDevicePixelRatio());
499 return size; 444 return size;
500 } 445 }
501 446
502 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be havior) 447 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be havior)
503 { 448 {
504 bool foundURL = false; 449 bool foundURL = false;
505 if (RuntimeEnabledFeatures::pictureEnabled()) {
506 ImageCandidate candidate = findBestFitImageFromPictureParent();
507 if (!candidate.isEmpty()) {
508 setBestFitURLAndDPRFromImageCandidate(candidate);
509 foundURL = true;
510 }
511 }
512
513 if (!foundURL) { 450 if (!foundURL) {
ojan 2014/11/06 23:00:59 Nit: you don't need this if-statement.
514 unsigned effectiveSize = 0; 451 unsigned effectiveSize = 0;
515 if (RuntimeEnabledFeatures::pictureSizesEnabled()) { 452 if (RuntimeEnabledFeatures::pictureSizesEnabled()) {
516 String sizes = getAttribute(HTMLNames::sizesAttr); 453 String sizes = getAttribute(HTMLNames::sizesAttr);
517 if (!sizes.isNull()) 454 if (!sizes.isNull())
518 UseCounter::count(document(), UseCounter::Sizes); 455 UseCounter::count(document(), UseCounter::Sizes);
519 SizesAttributeParser parser = SizesAttributeParser(MediaValuesDynami c::create(document()), sizes); 456 SizesAttributeParser parser = SizesAttributeParser(MediaValuesDynami c::create(document()), sizes);
520 effectiveSize = parser.length(); 457 effectiveSize = parser.length();
521 m_effectiveSizeViewportDependant = parser.viewportDependant(); 458 m_effectiveSizeViewportDependant = parser.viewportDependant();
522 } 459 }
523 ImageCandidate candidate = bestFitSourceForImageAttributes( 460 ImageCandidate candidate = bestFitSourceForImageAttributes(
524 document().devicePixelRatio(), effectiveSize, 461 document().devicePixelRatio(), effectiveSize,
525 getAttribute(HTMLNames::srcAttr), getAttribute(HTMLNames::srcsetAttr )); 462 getAttribute(HTMLNames::srcAttr), getAttribute(HTMLNames::srcsetAttr ));
526 setBestFitURLAndDPRFromImageCandidate(candidate); 463 setBestFitURLAndDPRFromImageCandidate(candidate);
527 } 464 }
528 if (m_intrinsicSizingViewportDependant && m_effectiveSizeViewportDependant & & !m_listener.get()) { 465 if (m_intrinsicSizingViewportDependant && m_effectiveSizeViewportDependant & & !m_listener.get()) {
529 m_listener = ViewportChangeListener::create(this); 466 m_listener = ViewportChangeListener::create(this);
530 document().mediaQueryMatcher().addViewportListener(m_listener.get()); 467 document().mediaQueryMatcher().addViewportListener(m_listener.get());
531 } 468 }
532 imageLoader().updateFromElement(behavior); 469 imageLoader().updateFromElement(behavior);
533 } 470 }
534 471
535 const KURL& HTMLImageElement::sourceURL() const 472 const KURL& HTMLImageElement::sourceURL() const
536 { 473 {
537 return cachedImage()->response().url(); 474 return cachedImage()->response().url();
538 } 475 }
539 476
540 } 477 }
OLDNEW
« no previous file with comments | « sky/engine/core/html/HTMLImageElement.h ('k') | sky/engine/core/html/HTMLPictureElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698