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

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

Issue 481753002: Use Shadow DOM to display fallback content for images (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated 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
Index: Source/core/html/HTMLImageLoader.cpp
diff --git a/Source/core/html/HTMLImageLoader.cpp b/Source/core/html/HTMLImageLoader.cpp
index 44fc879fe2f85abc3b3d5fe90ff5fef691766d39..3af5488be4aab50951e69409816efc90cf9d6df9 100644
--- a/Source/core/html/HTMLImageLoader.cpp
+++ b/Source/core/html/HTMLImageLoader.cpp
@@ -24,15 +24,38 @@
#include "core/HTMLNames.h"
#include "core/dom/Element.h"
+#include "core/dom/Microtask.h"
#include "core/events/Event.h"
#include "core/fetch/ImageResource.h"
-#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLObjectElement.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "platform/Logging.h"
+#include "public/platform/WebThread.h"
namespace blink {
+using namespace HTMLNames;
+
+class HTMLImageLoader::EnsureFallbackContentTask : public blink::WebThread::Task {
pdr. 2014/11/14 07:34:17 A Timer with startOneShot seems like it would be m
+public:
+ static PassOwnPtr<EnsureFallbackContentTask> create(HTMLElement* element)
+ {
+ return adoptPtr(new EnsureFallbackContentTask(element));
+ }
+
+ EnsureFallbackContentTask(HTMLElement* element)
+ : m_element(element)
+ {
+ }
+ virtual void run() override
pdr. 2014/11/14 07:34:17 Nit: missing newline.
+ {
+ m_element->ensureFallbackContent();
+ }
+
+private:
+ HTMLElement* m_element;
+};
+
HTMLImageLoader::HTMLImageLoader(Element* node)
: ImageLoader(node)
{
@@ -61,17 +84,36 @@ String HTMLImageLoader::sourceURI(const AtomicString& attr) const
return stripLeadingAndTrailingHTMLSpaces(attr);
}
+void HTMLImageLoader::noImageResourceToLoad()
+{
+ // FIXME: Use fallback content even when there is no alt-text. The only blocker is the large amount of rebaselining it requires.
+ if (!toHTMLElement(element())->altText().isEmpty())
+ toHTMLElement(element())->ensureFallbackContent();
+}
+
void HTMLImageLoader::notifyFinished(Resource*)
{
ImageResource* cachedImage = image();
- RefPtrWillBeRawPtr<Element> element = this->element();
ImageLoader::notifyFinished(cachedImage);
bool loadError = cachedImage->errorOccurred() || cachedImage->response().httpStatusCode() >= 400;
+ if (loadError)
+ ensureFallbackContent();
+ else
+ toHTMLElement(element())->ensurePrimaryContent();
- if (loadError && isHTMLObjectElement(*element))
- toHTMLObjectElement(element)->renderFallbackContent();
+ if (loadError && isHTMLObjectElement(element()))
+ toHTMLObjectElement(element())->renderFallbackContent();
}
+void HTMLImageLoader::ensureFallbackContent()
+{
+ if (image()->url().protocolIsData()) {
+ OwnPtr<EnsureFallbackContentTask> task = EnsureFallbackContentTask::create(toHTMLElement(element()));
+ Microtask::enqueueMicrotask(task.release());
+ } else {
+ toHTMLElement(element())->ensureFallbackContent();
+ }
+}
}

Powered by Google App Engine
This is Rietveld 408576698