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

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

Issue 2627953003: Make `getComputedStyle` return the correct style for collapsed <img> elements. (Closed)
Patch Set: Rebase. Created 3 years, 10 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 | « third_party/WebKit/Source/core/html/HTMLImageElement.h ('k') | no next file » | 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 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights
5 * reserved. 5 * reserved.
6 * Copyright (C) 2010 Google Inc. All rights reserved. 6 * Copyright (C) 2010 Google Inc. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 document().devicePixelRatio(), sourceSize(*source), 327 document().devicePixelRatio(), sourceSize(*source),
328 source->fastGetAttribute(srcsetAttr), &document()); 328 source->fastGetAttribute(srcsetAttr), &document());
329 if (candidate.isEmpty()) 329 if (candidate.isEmpty())
330 continue; 330 continue;
331 m_source = source; 331 m_source = source;
332 return candidate; 332 return candidate;
333 } 333 }
334 return ImageCandidate(); 334 return ImageCandidate();
335 } 335 }
336 336
337 bool HTMLImageElement::layoutObjectIsNeeded(const ComputedStyle& style) {
338 return m_layoutDisposition != LayoutDisposition::Collapsed &&
339 HTMLElement::layoutObjectIsNeeded(style);
340 }
341
342 LayoutObject* HTMLImageElement::createLayoutObject(const ComputedStyle& style) { 337 LayoutObject* HTMLImageElement::createLayoutObject(const ComputedStyle& style) {
343 const ContentData* contentData = style.contentData(); 338 const ContentData* contentData = style.contentData();
344 if (contentData && contentData->isImage()) { 339 if (contentData && contentData->isImage()) {
345 const StyleImage* contentImage = toImageContentData(contentData)->image(); 340 const StyleImage* contentImage = toImageContentData(contentData)->image();
346 bool errorOccurred = contentImage && contentImage->cachedImage() && 341 bool errorOccurred = contentImage && contentImage->cachedImage() &&
347 contentImage->cachedImage()->errorOccurred(); 342 contentImage->cachedImage()->errorOccurred();
348 if (!errorOccurred) 343 if (!errorOccurred)
349 return LayoutObject::createObject(this, style); 344 return LayoutObject::createObject(this, style);
350 } 345 }
351 346
352 switch (m_layoutDisposition) { 347 switch (m_layoutDisposition) {
353 case LayoutDisposition::FallbackContent: 348 case LayoutDisposition::FallbackContent:
354 return new LayoutBlockFlow(this); 349 return new LayoutBlockFlow(this);
355 case LayoutDisposition::PrimaryContent: { 350 case LayoutDisposition::PrimaryContent: {
356 LayoutImage* image = new LayoutImage(this); 351 LayoutImage* image = new LayoutImage(this);
357 image->setImageResource(LayoutImageResource::create()); 352 image->setImageResource(LayoutImageResource::create());
358 image->setImageDevicePixelRatio(m_imageDevicePixelRatio); 353 image->setImageDevicePixelRatio(m_imageDevicePixelRatio);
359 return image; 354 return image;
360 } 355 }
361 case LayoutDisposition::Collapsed: // Falls through. 356 case LayoutDisposition::Collapsed: // Falls through.
362 default: 357 default:
363 NOTREACHED(); 358 NOTREACHED();
364 return nullptr; 359 return nullptr;
365 } 360 }
366 } 361 }
367 362
368 void HTMLImageElement::attachLayoutTree(const AttachContext& context) { 363 void HTMLImageElement::attachLayoutTree(const AttachContext& context) {
369 HTMLElement::attachLayoutTree(context); 364 HTMLElement::attachLayoutTree(context);
370
371 if (layoutObject() && layoutObject()->isImage()) { 365 if (layoutObject() && layoutObject()->isImage()) {
372 LayoutImage* layoutImage = toLayoutImage(layoutObject()); 366 LayoutImage* layoutImage = toLayoutImage(layoutObject());
373 LayoutImageResource* layoutImageResource = layoutImage->imageResource(); 367 LayoutImageResource* layoutImageResource = layoutImage->imageResource();
374 if (m_isFallbackImage) { 368 if (m_isFallbackImage) {
375 float deviceScaleFactor = blink::deviceScaleFactor(layoutImage->frame()); 369 float deviceScaleFactor = blink::deviceScaleFactor(layoutImage->frame());
376 std::pair<Image*, float> brokenImageAndImageScaleFactor = 370 std::pair<Image*, float> brokenImageAndImageScaleFactor =
377 ImageResourceContent::brokenImage(deviceScaleFactor); 371 ImageResourceContent::brokenImage(deviceScaleFactor);
378 ImageResourceContent* newImageResource = 372 ImageResourceContent* newImageResource =
379 ImageResourceContent::create(brokenImageAndImageScaleFactor.first); 373 ImageResourceContent::create(brokenImageAndImageScaleFactor.first);
380 layoutImage->imageResource()->setImageResource(newImageResource); 374 layoutImage->imageResource()->setImageResource(newImageResource);
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 imageLoader().image()->resourceError().shouldCollapseInitiator(); 840 imageLoader().image()->resourceError().shouldCollapseInitiator();
847 setLayoutDisposition(resourceErrorIndicatesElementShouldBeCollapsed 841 setLayoutDisposition(resourceErrorIndicatesElementShouldBeCollapsed
848 ? LayoutDisposition::Collapsed 842 ? LayoutDisposition::Collapsed
849 : LayoutDisposition::FallbackContent); 843 : LayoutDisposition::FallbackContent);
850 } 844 }
851 845
852 void HTMLImageElement::ensurePrimaryContent() { 846 void HTMLImageElement::ensurePrimaryContent() {
853 setLayoutDisposition(LayoutDisposition::PrimaryContent); 847 setLayoutDisposition(LayoutDisposition::PrimaryContent);
854 } 848 }
855 849
850 bool HTMLImageElement::isCollapsed() const {
851 return m_layoutDisposition == LayoutDisposition::Collapsed;
852 }
853
856 void HTMLImageElement::setLayoutDisposition(LayoutDisposition layoutDisposition, 854 void HTMLImageElement::setLayoutDisposition(LayoutDisposition layoutDisposition,
857 bool forceReattach) { 855 bool forceReattach) {
858 if (m_layoutDisposition == layoutDisposition && !forceReattach) 856 if (m_layoutDisposition == layoutDisposition && !forceReattach)
859 return; 857 return;
860 858
861 m_layoutDisposition = layoutDisposition; 859 m_layoutDisposition = layoutDisposition;
862 860
863 // This can happen inside of attachLayoutTree() in the middle of a recalcStyle 861 // This can happen inside of attachLayoutTree() in the middle of a recalcStyle
864 // so we need to reattach synchronously here. 862 // so we need to reattach synchronously here.
865 if (document().inStyleRecalc()) { 863 if (document().inStyleRecalc()) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 void HTMLImageElement::associateWith(HTMLFormElement* form) { 919 void HTMLImageElement::associateWith(HTMLFormElement* form) {
922 if (form && form->isConnected()) { 920 if (form && form->isConnected()) {
923 m_form = form; 921 m_form = form;
924 m_formWasSetByParser = true; 922 m_formWasSetByParser = true;
925 m_form->associate(*this); 923 m_form->associate(*this);
926 m_form->didAssociateByParser(); 924 m_form->didAssociateByParser();
927 } 925 }
928 }; 926 };
929 927
930 } // namespace blink 928 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLImageElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698