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

Unified Diff: Source/core/html/HTMLImageElement.cpp

Issue 696123002: Revert of Use Shadow DOM to display fallback content for images (Closed) Base URL: svn://svn.chromium.org/blink/trunk
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLImageElement.h ('k') | Source/core/html/HTMLImageFallbackHelper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLImageElement.cpp
diff --git a/Source/core/html/HTMLImageElement.cpp b/Source/core/html/HTMLImageElement.cpp
index 43e26a0bd26da8973f09a890f41cb24f5ef94084..87fd4081ee0621865cb56d38ea18ac4495fa308b 100644
--- a/Source/core/html/HTMLImageElement.cpp
+++ b/Source/core/html/HTMLImageElement.cpp
@@ -32,19 +32,16 @@
#include "core/css/parser/SizesAttributeParser.h"
#include "core/dom/Attribute.h"
#include "core/dom/NodeTraversal.h"
-#include "core/dom/shadow/ShadowRoot.h"
#include "core/fetch/ImageResource.h"
#include "core/frame/UseCounter.h"
#include "core/html/HTMLAnchorElement.h"
#include "core/html/HTMLCanvasElement.h"
#include "core/html/HTMLFormElement.h"
-#include "core/html/HTMLImageFallbackHelper.h"
#include "core/html/HTMLSourceElement.h"
#include "core/html/canvas/CanvasRenderingContext.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/html/parser/HTMLSrcsetParser.h"
#include "core/inspector/ConsoleMessage.h"
-#include "core/rendering/RenderBlockFlow.h"
#include "core/rendering/RenderImage.h"
#include "platform/ContentType.h"
#include "platform/MIMETypeRegistry.h"
@@ -87,10 +84,7 @@
, m_formWasSetByParser(false)
, m_elementCreatedByParser(createdByParser)
, m_intrinsicSizingViewportDependant(false)
- , m_useFallbackContent(false)
- , m_isFallbackImage(false)
-{
- setHasCustomStyleCallbacks();
+{
if (form && form->inDocument()) {
#if ENABLE(OILPAN)
m_form = form;
@@ -241,13 +235,9 @@
void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
- if (name == altAttr || name == titleAttr) {
- if (userAgentShadowRoot()) {
- Element* text = userAgentShadowRoot()->getElementById("alttext");
- String value = altText();
- if (text && text->textContent() != value)
- text->setTextContent(altText());
- }
+ if (name == altAttr) {
+ if (renderer() && renderer()->isImage())
+ toRenderImage(renderer())->updateAltText();
} else if (name == srcAttr || name == srcsetAttr || name == sizesAttr) {
selectSourceURL(ImageLoader::UpdateIgnorePreviousError);
} else if (name == usemapAttr) {
@@ -257,7 +247,7 @@
}
}
-String HTMLImageElement::altText() const
+const AtomicString& HTMLImageElement::altText() const
{
// lets figure out the alt text.. magic stuff
// http://www.w3.org/TR/1998/REC-html40-19980424/appendix/notes.html#altgen
@@ -323,9 +313,6 @@
if (style->hasContent())
return RenderObject::createObject(this, style);
- if (m_useFallbackContent)
- return new RenderBlockFlow(this);
-
RenderImage* image = new RenderImage(this);
image->setImageResource(RenderImageResource::create());
image->setImageDevicePixelRatio(m_imageDevicePixelRatio);
@@ -350,9 +337,13 @@
if (renderImageResource->hasImage())
return;
+ // If we have no image at all because we have no src attribute, set
+ // image height and width for the alt text instead.
if (!imageLoader().image() && !renderImageResource->cachedImage())
- return;
- renderImageResource->setImageResource(imageLoader().image());
+ renderImage->setImageSizeForAltText();
+ else
+ renderImageResource->setImageResource(imageLoader().image());
+
}
}
@@ -375,7 +366,7 @@
// If we have been inserted from a renderer-less document,
// our loader may have not fetched the image, so do it now.
if ((insertionPoint->inDocument() && !imageLoader().image()) || imageWasModified)
- imageLoader().updateFromElement(ImageLoader::UpdateNormal);
+ imageLoader().updateFromElement(ImageLoader::UpdateNormal, m_elementCreatedByParser ? ImageLoader::ForceLoadImmediately : ImageLoader::LoadNormally);
return HTMLElement::insertedInto(insertionPoint);
}
@@ -654,11 +645,6 @@
document().mediaQueryMatcher().addViewportListener(m_listener);
}
imageLoader().updateFromElement(behavior);
-
- if (imageLoader().image() || (imageLoader().hasPendingActivity() && !imageSourceURL().isEmpty()))
- ensurePrimaryContent();
- else
- ensureFallbackContent();
}
const KURL& HTMLImageElement::sourceURL() const
@@ -666,49 +652,4 @@
return cachedImage()->response().url();
}
-void HTMLImageElement::didAddUserAgentShadowRoot(ShadowRoot&)
-{
- HTMLImageFallbackHelper::createAltTextShadowTree(*this);
-}
-
-void HTMLImageElement::ensureFallbackContent()
-{
- if (m_useFallbackContent || m_isFallbackImage)
- return;
- setUseFallbackContent();
- reattachFallbackContent();
-}
-
-void HTMLImageElement::ensurePrimaryContent()
-{
- if (!m_useFallbackContent)
- return;
- m_useFallbackContent = false;
- reattachFallbackContent();
-}
-
-void HTMLImageElement::reattachFallbackContent()
-{
- // This can happen inside of attach() in the middle of a recalcStyle so we need to
- // reattach synchronously here.
- if (document().inStyleRecalc())
- reattach();
- else
- lazyReattachIfAttached();
-}
-
-PassRefPtr<RenderStyle> HTMLImageElement::customStyleForRenderer()
-{
- RefPtr<RenderStyle> newStyle = originalStyleForRenderer();
-
- if (!m_useFallbackContent)
- return newStyle;
- return HTMLImageFallbackHelper::customStyleForAltText(*this, newStyle);
-}
-
-void HTMLImageElement::setUseFallbackContent()
-{
- m_useFallbackContent = true;
- ensureUserAgentShadowRoot();
-}
-}
+}
« no previous file with comments | « Source/core/html/HTMLImageElement.h ('k') | Source/core/html/HTMLImageFallbackHelper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698