[Shadow DOM] Implement Element::createShadowRoot()
authormorrita@google.com <morrita@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Nov 2012 09:38:43 +0000 (09:38 +0000)
committermorrita@google.com <morrita@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Nov 2012 09:38:43 +0000 (09:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=102911

Reviewed by Kentaro Hara.

Source/WebCore:

Added an API implementation and exposed it.

This is basically an alias of the ShadowRoot constructor, which
will be removed as bug 102913.

Test: fast/dom/shadow/shadow-aware-create-shdow-root.html

* bindings/gobject/GNUmakefile.am:
* dom/Element.cpp:
(WebCore::Element::createShadowRoot):
(WebCore):
* dom/Element.h:
(Element):
* dom/Element.idl:

LayoutTests:

The coverage might not seem comprehensive at a glance. However,
this is just an alias of ShadowRoot constructor and there are
bunch of test cases which cover it.

As bug 102913 will convert such callsites to use createShadowRoot(),
the API will get be covered well then.

* fast/dom/shadow/shadow-aware-create-shdow-root-expected.txt: Added.
* fast/dom/shadow/shadow-aware-create-shdow-root.html: Added.
  Further ShadowAware API will come here.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@135693 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/shadow/shadow-aware-create-shadow-root-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadow-aware-create-shadow-root.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/gobject/GNUmakefile.am
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/Element.idl

index 504e061..28c675a 100644 (file)
@@ -1,3 +1,21 @@
+2012-11-26  Hajime Morrita  <morrita@google.com>
+
+        [Shadow DOM] Implement Element::createShadowRoot()
+        https://bugs.webkit.org/show_bug.cgi?id=102911
+
+        Reviewed by Kentaro Hara.
+
+        The coverage might not seem comprehensive at a glance. However,
+        this is just an alias of ShadowRoot constructor and there are
+        bunch of test cases which cover it.
+
+        As bug 102913 will convert such callsites to use createShadowRoot(),
+        the API will get be covered well then.
+
+        * fast/dom/shadow/shadow-aware-create-shdow-root-expected.txt: Added.
+        * fast/dom/shadow/shadow-aware-create-shdow-root.html: Added.
+          Further ShadowAware API will come here.
+
 2012-11-26  Alexander Pavlov  <apavlov@chromium.org>
 
         [Chromium] Unreviewed, mark platform/chromium/fast/forms/calendar-picker/week-picker-key-operations.html as flaky (date-dependent).
diff --git a/LayoutTests/fast/dom/shadow/shadow-aware-create-shadow-root-expected.txt b/LayoutTests/fast/dom/shadow/shadow-aware-create-shadow-root-expected.txt
new file mode 100644 (file)
index 0000000..fee6c33
--- /dev/null
@@ -0,0 +1,13 @@
+Tests for ShadowAware JS APIs.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS root1.constructor is window.WebKitShadowRoot
+PASS root1 is not root2
+PASS root1 is window.internals.oldestShadowRoot(host)
+PASS root2 is window.internals.youngestShadowRoot(host)
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/shadow/shadow-aware-create-shadow-root.html b/LayoutTests/fast/dom/shadow/shadow-aware-create-shadow-root.html
new file mode 100644 (file)
index 0000000..93b1743
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+description("Tests for ShadowAware JS APIs.");
+
+// ShadowAware.createShadowRoot()
+var host = document.createElement('div');
+var root1 = host.createShadowRoot();
+var root2 = host.createShadowRoot();
+shouldBe("root1.constructor", "window.WebKitShadowRoot");
+shouldNotBe("root1", "root2");
+shouldBe("root1", "window.internals.oldestShadowRoot(host)");
+shouldBe("root2", "window.internals.youngestShadowRoot(host)");
+
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
index 3847a52..dd1f158 100644 (file)
@@ -1,3 +1,25 @@
+2012-11-26  Hajime Morrita  <morrita@google.com>
+
+        [Shadow DOM] Implement Element::createShadowRoot()
+        https://bugs.webkit.org/show_bug.cgi?id=102911
+
+        Reviewed by Kentaro Hara.
+
+        Added an API implementation and exposed it.
+
+        This is basically an alias of the ShadowRoot constructor, which
+        will be removed as bug 102913.
+
+        Test: fast/dom/shadow/shadow-aware-create-shdow-root.html
+
+        * bindings/gobject/GNUmakefile.am:
+        * dom/Element.cpp:
+        (WebCore::Element::createShadowRoot):
+        (WebCore):
+        * dom/Element.h:
+        (Element):
+        * dom/Element.idl:
+
 2012-11-26  Jon Lee  <jonlee@apple.com>
 
         Extend EventDispatcher::dispatchSimulatedClick to allow sending a mouseover event
index 88ed16c..ce87bb5 100644 (file)
@@ -237,6 +237,8 @@ webkitgtk_gdom_built_sources += \
        DerivedSources/webkit/WebKitDOMRangePrivate.h \
        DerivedSources/webkit/WebKitDOMScreen.cpp \
        DerivedSources/webkit/WebKitDOMScreenPrivate.h \
+       DerivedSources/webkit/WebKitDOMShadowRoot.cpp \
+       DerivedSources/webkit/WebKitDOMShadowRootPrivate.h \
        DerivedSources/webkit/WebKitDOMStorage.cpp \
        DerivedSources/webkit/WebKitDOMStorageInfo.cpp \
        DerivedSources/webkit/WebKitDOMStorageInfoPrivate.h \
index 3cb04f0..a4f7d72 100644 (file)
@@ -1440,6 +1440,11 @@ ElementShadow* Element::ensureShadow()
     return data->m_shadow.get();
 }
 
+PassRefPtr<ShadowRoot> Element::createShadowRoot(ExceptionCode& ec)
+{
+    return ShadowRoot::create(this, ec);
+}
+
 ShadowRoot* Element::userAgentShadowRoot() const
 {
     if (ElementShadow* elementShadow = shadow()) {
index 5f11ec9..82339c9 100644 (file)
@@ -275,6 +275,8 @@ public:
 
     ElementShadow* shadow() const;
     ElementShadow* ensureShadow();
+    PassRefPtr<ShadowRoot> createShadowRoot(ExceptionCode&);
+
     virtual void willAddAuthorShadowRoot() { }
     virtual bool areAuthorShadowsAllowed() const { return true; }
 
index 8b6622d..8769c63 100644 (file)
     readonly attribute Element nextElementSibling;
     readonly attribute unsigned long childElementCount;
 
-#if defined(ENABLE_SHADOW_DOM)
+    // ShadowAware API
+#if defined(ENABLE_SHADOW_DOM) && ENABLE_SHADOW_DOM
     [Reflect, V8EnabledAtRuntime=shadowDOM] attribute DOMString pseudo;
+    [V8EnabledAtRuntime=shadowDOM] ShadowRoot createShadowRoot() raises(DOMException);
 #endif
 
     // DOM 4