Shadow DOM for img element
authorshinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jul 2012 08:27:27 +0000 (08:27 +0000)
committershinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jul 2012 08:27:27 +0000 (08:27 +0000)
commit0caab5c0c847bbe25ba5999876c6211bf25f752b
tree1ee3bd65d3b3678b0f1f4c587b9383ac81f8d368
parent3d38b209c2ced959bb0a04ea907bdeb9c27d1852
Shadow DOM for img element
https://bugs.webkit.org/show_bug.cgi?id=90532

Reviewed by Hajime Morita.

Source/WebCore:

This patch adds Shadow DOM support for img element.

According to the Shadow DOM spec, img element should behave like having a user agent Shadow DOM.
However, if we add Shadow DOM to img by default, it will cause performance regression and memory bloat.

So, we would like to postpone adding a Shadow DOM to img until when we really need it. In other words,
we add our User Agent Shadow DOM to img just before a user adds Author Shadow DOM.

The User Agent Shadow DOM for img has only one element, which displays an image. If img has
a Shadow DOM, img will behave like <span style="display: inline-block"> by default. The display style can
be chagned using CSS though.

This patch also adds ImageLoaderClient. The element we render an image and the element we take an argument
from were the same, however not they might be different. We would like to encapsulate the fact into
ImageLoaderClient.

Tests: fast/dom/shadow/shadowdom-for-image-alt-update.html
       fast/dom/shadow/shadowdom-for-image-alt.html
       fast/dom/shadow/shadowdom-for-image-content.html
       fast/dom/shadow/shadowdom-for-image-dynamic.html
       fast/dom/shadow/shadowdom-for-image-event-click.html
       fast/dom/shadow/shadowdom-for-image-in-shadowdom.html
       fast/dom/shadow/shadowdom-for-image-map.html
       fast/dom/shadow/shadowdom-for-image-style.html
       fast/dom/shadow/shadowdom-for-image-with-multiple-shadow.html
       fast/dom/shadow/shadowdom-for-image-with-width-and-height.html
       fast/dom/shadow/shadowdom-for-image.html

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* css/html.css:
(img):
* html/HTMLImageElement.cpp:
(WebCore::ImageElement::setImageIfNecessary):
(WebCore):
(WebCore::ImageElement::createRendererForImage):
(WebCore::HTMLImageElement::willAddAuthorShadowRoot): When we don't have a user agent Shadow DOM yet
we add it.
(WebCore::HTMLImageElement::createShadowSubtree):
(WebCore::HTMLImageElement::imageElement):
(WebCore::HTMLImageElement::parseAttribute):
(WebCore::HTMLImageElement::createRenderer): If a user agent Shadow DOM is attached, we create
Renderer from style, instead of creating RenderImage.
(WebCore::HTMLImageElement::attach):
(WebCore::HTMLImageElement::innerElement):
* html/HTMLImageElement.h:
(WebCore):
(ImageElement):
(HTMLImageElement):
(WebCore::HTMLImageElement::sourceElement):
(WebCore::HTMLImageElement::refSourceElement):
(WebCore::HTMLImageElement::derefSourceElement):
(WebCore::HTMLImageElement::imageRenderer):
(WebCore::HTMLImageElement::imageLoader):
(WebCore::isHTMLImageElement):
(WebCore::toHTMLImageElement):
* html/HTMLImageLoader.cpp:
(WebCore::HTMLImageLoader::HTMLImageLoader):
(WebCore::HTMLImageLoader::dispatchLoadEvent):
(WebCore::HTMLImageLoader::sourceURI):
(WebCore::HTMLImageLoader::notifyFinished):
* html/HTMLImageLoader.h:
(HTMLImageLoader):
* html/HTMLInputElement.h:
* html/HTMLObjectElement.h:
* html/HTMLPlugInElement.h:
* html/HTMLTagNames.in:
* html/HTMLVideoElement.h:
* html/shadow/ImageInnerElement.cpp: Added.
(WebCore):
(WebCore::ImageInnerElement::ImageInnerElement):
(WebCore::ImageInnerElement::hostImage):
(WebCore::ImageInnerElement::imageLoader):
(WebCore::ImageInnerElement::attach):
(WebCore::ImageInnerElement::createRenderer):
* html/shadow/ImageInnerElement.h: Added.
(WebCore):
(ImageInnerElement):
(WebCore::ImageInnerElement::imageRenderer):
(WebCore::ImageInnerElement::create):
(WebCore::isImageInnerElement):
(WebCore::toImageInnerElement):
* loader/ImageLoader.cpp:
(WebCore::ImageLoader::ImageLoader):
(WebCore::ImageLoader::~ImageLoader):
(WebCore):
(WebCore::ImageLoader::document):
(WebCore::ImageLoader::updateFromElement):
(WebCore::ImageLoader::notifyFinished):
(WebCore::ImageLoader::renderImageResource):
(WebCore::ImageLoader::updatedHasPendingLoadEvent):
(WebCore::ImageLoader::dispatchPendingBeforeLoadEvent):
(WebCore::ImageLoader::dispatchPendingLoadEvent):
(WebCore::ImageLoader::dispatchPendingErrorEvent):
* loader/ImageLoader.h:
(WebCore):
(ImageLoader):
(WebCore::ImageLoader::client):
* loader/ImageLoaderClient.h: Added.
(WebCore):
(ImageLoaderClient): Provides the necessary interfaces to ImageLoader.
(WebCore::ImageLoaderClient::~ImageLoaderClient):
(ImageLoaderClientBase):
(WebCore::ImageLoaderClientBase::sourceElement):
(WebCore::ImageLoaderClientBase::imageElement):
(WebCore::ImageLoaderClientBase::refSourceElement):
(WebCore::ImageLoaderClientBase::derefSourceElement):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::paintIntoRect):
(WebCore::RenderImage::imageMap):
(WebCore::RenderImage::updateAltText):
(WebCore::RenderImage::hostImageElement):
(WebCore):
* rendering/RenderImage.h:
(WebCore):
(RenderImage):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::shouldRespectImageOrientation):
* svg/SVGImageElement.h:
(SVGImageElement):
* svg/SVGImageLoader.cpp:
(WebCore::SVGImageLoader::SVGImageLoader):
(WebCore::SVGImageLoader::dispatchLoadEvent):
(WebCore::SVGImageLoader::sourceURI):
* svg/SVGImageLoader.h:
(SVGImageLoader):

LayoutTests:

Contains the following test cases.
(1) ShadowDOM is attached to an img element and use a shadow element
(2) ShadowDOM is attached to an img element and use a content element
(3) width and height are specified
(4) src attribute is dynamically changed
(5) multiple ShadowDOMs are attached to an img element
(6) ShadowDOM is attached to an img element in Shadow DOM
(7) event retargetting
(8) img with display: none, display: inline, display: block
(9) image map
(10) alt text
(11) alt text with dynamic update

* fast/dom/shadow/shadowdom-for-image-alt-expected.html: Added.
* fast/dom/shadow/shadowdom-for-image-alt-update-expected.html: Added.
* fast/dom/shadow/shadowdom-for-image-alt-update.html: Added.
* fast/dom/shadow/shadowdom-for-image-alt.html: Added.
* fast/dom/shadow/shadowdom-for-image-content-expected.html: Added.
* fast/dom/shadow/shadowdom-for-image-content.html: Added.
* fast/dom/shadow/shadowdom-for-image-dynamic-expected.html: Added.
* fast/dom/shadow/shadowdom-for-image-dynamic.html: Added.
* fast/dom/shadow/shadowdom-for-image-event-click-expected.txt: Added.
* fast/dom/shadow/shadowdom-for-image-event-click.html: Added.
* fast/dom/shadow/shadowdom-for-image-expected.html: Added.
* fast/dom/shadow/shadowdom-for-image-in-shadowdom-expected.html: Added.
* fast/dom/shadow/shadowdom-for-image-in-shadowdom.html: Added.
* fast/dom/shadow/shadowdom-for-image-map-expected.txt: Added.
* fast/dom/shadow/shadowdom-for-image-map.html: Added.
* fast/dom/shadow/shadowdom-for-image-style-expected.html: Added.
* fast/dom/shadow/shadowdom-for-image-style.html: Added.
* fast/dom/shadow/shadowdom-for-image-with-multiple-shadow-expected.html: Added.
* fast/dom/shadow/shadowdom-for-image-with-multiple-shadow.html: Added.
* fast/dom/shadow/shadowdom-for-image-with-width-and-height-expected.html: Added.
* fast/dom/shadow/shadowdom-for-image-with-width-and-height.html: Added.
* fast/dom/shadow/shadowdom-for-image.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@122824 268f45cc-cd09-0410-ab3c-d52691b4dbfc
51 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/shadow/shadowdom-for-image-alt-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-alt-update-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-alt-update.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-alt.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-content-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-content.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-dynamic-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-dynamic.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-event-click-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-event-click.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-in-shadowdom-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-in-shadowdom.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-map-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-map.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-style-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-style.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-with-multiple-shadow-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-with-multiple-shadow.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-with-width-and-height-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image-with-width-and-height.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadowdom-for-image.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/html.css
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageElement.h
Source/WebCore/html/HTMLImageLoader.cpp
Source/WebCore/html/HTMLImageLoader.h
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/html/HTMLObjectElement.h
Source/WebCore/html/HTMLPlugInElement.h
Source/WebCore/html/HTMLTagNames.in
Source/WebCore/html/HTMLVideoElement.h
Source/WebCore/html/shadow/ImageInnerElement.cpp [new file with mode: 0644]
Source/WebCore/html/shadow/ImageInnerElement.h [new file with mode: 0644]
Source/WebCore/loader/ImageLoader.cpp
Source/WebCore/loader/ImageLoader.h
Source/WebCore/loader/ImageLoaderClient.h [new file with mode: 0644]
Source/WebCore/rendering/RenderImage.cpp
Source/WebCore/rendering/RenderImage.h
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/svg/SVGImageElement.h
Source/WebCore/svg/SVGImageLoader.cpp
Source/WebCore/svg/SVGImageLoader.h