Add support for getting an element in shadow root by its id into a window.internals...
authorhayato@chromium.org <hayato@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Aug 2011 12:25:53 +0000 (12:25 +0000)
committerhayato@chromium.org <hayato@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Aug 2011 12:25:53 +0000 (12:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=64587

Reviewed by Hajime Morita.

.:

* Source/autotools/symbols.filter:

Source/WebCore:

Test: fast/dom/shadow/get-element-by-id-in-shadow-root.html

* WebCore.exp.in:
* testing/Internals.cpp:
(WebCore::Internals::getElementByIdInShadowRoot):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit2:

* win/WebKit2.def:
* win/WebKit2CFLite.def:

LayoutTests:

* fast/dom/shadow/get-element-by-id-in-shadow-root-expected.txt: Added.
* fast/dom/shadow/get-element-by-id-in-shadow-root.html: Added.
* fast/dom/shadow/resources/create-dom.js: Added.
(createShadow):
(createDom):

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

14 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-root-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-root.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/resources/create-dom.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit2/ChangeLog
Source/WebKit2/win/WebKit2.def
Source/WebKit2/win/WebKit2CFLite.def
Source/autotools/symbols.filter

index c98161b005483cc9d2fb4f1c8a3ae0c9a410cc6d..35722153a7b8bc28d09bdcfbf65d5d8f8ae217a4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-08-01  Hayato Ito  <hayato@chromium.org>
+
+        Add support for getting an element in shadow root by its id into a window.internals object.
+        https://bugs.webkit.org/show_bug.cgi?id=64587
+
+        Reviewed by Hajime Morita.
+
+        * Source/autotools/symbols.filter:
+
 2011-08-01  Neil Roberts  <neil@linux.intel.com>
 
         build: Fix finding the headers for GStreamer
index 28413e2c03946662c5b662995dce71cfb19f9c47..3b8ec50030b1f7919411fbe80b0efc78e3312375 100644 (file)
@@ -1,3 +1,16 @@
+2011-08-01  Hayato Ito  <hayato@chromium.org>
+
+        Add support for getting an element in shadow root by its id into a window.internals object.
+        https://bugs.webkit.org/show_bug.cgi?id=64587
+
+        Reviewed by Hajime Morita.
+
+        * fast/dom/shadow/get-element-by-id-in-shadow-root-expected.txt: Added.
+        * fast/dom/shadow/get-element-by-id-in-shadow-root.html: Added.
+        * fast/dom/shadow/resources/create-dom.js: Added.
+        (createShadow):
+        (createDom):
+
 2011-08-01  Yury Semikhatsky  <yurys@chromium.org>
 
         Web Inspector: typing an expression in an iframe leads to multiple "Unsafe JavaScript attempt to access frame..." errors
diff --git a/LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-root-expected.txt b/LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-root-expected.txt
new file mode 100644 (file)
index 0000000..9ad3b1b
--- /dev/null
@@ -0,0 +1,12 @@
+Tests to ensure that internals.getElementByIdInTreeScope can get an element in TreeScope by its id. Can only run within DRT
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS getElementInShadow('divA/inputB').id is "inputB"
+PASS getElementInShadow('divA/divC').id is "divC"
+PASS getElementInShadow('divA/divC/inputD').id is "inputD"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-root.html b/LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-root.html
new file mode 100644 (file)
index 0000000..d07fa00
--- /dev/null
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="resources/create-dom.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description("Tests to ensure that internals.getElementByIdInTreeScope can get an element in TreeScope by its id. Can only run within DRT");
+
+function getElementInShadow(path)
+{
+    var ids = path.split('/');
+    var element = document.getElementById(ids[0]);
+    for (var i = 1; element != null && i < ids.length; ++i) {
+        var shadowRoot = internals.shadowRoot(element);
+        element = internals.getElementByIdInShadowRoot(shadowRoot, ids[i]);
+    }
+    return element;
+}
+
+function prepareDomTree(parent)
+{
+    parent.appendChild(
+        createShadow('div', {'id': 'divA'},
+                     createDom('input', {'id': 'inputB'}),
+                     createShadow('div', {'id': 'divC'},
+                                  createDom('input', {'id': 'inputD'}))));
+}
+
+function test()
+{
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+    prepareDomTree(document.body);
+    shouldBeEqualToString("getElementInShadow('divA/inputB').id", 'inputB');
+    shouldBeEqualToString("getElementInShadow('divA/divC').id", 'divC');
+    shouldBeEqualToString("getElementInShadow('divA/divC/inputD').id", 'inputD');
+}
+
+test();
+
+var successfullyParsed = true;
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/shadow/resources/create-dom.js b/LayoutTests/fast/dom/shadow/resources/create-dom.js
new file mode 100644 (file)
index 0000000..a2751ad
--- /dev/null
@@ -0,0 +1,24 @@
+// This function can take optional child elements as arguments[2:].
+function createShadow(tagName, attributes)
+{
+    var element = document.createElement(tagName);
+    for (var name in attributes)
+        element.setAttribute(name, attributes[name]);
+    var shadow = internals.ensureShadowRoot(element);
+    var childElements = Array.prototype.slice.call(arguments, 2);
+    for (var i = 0; i < childElements.length; ++i)
+        shadow.appendChild(childElements[i]);
+    return element;
+}
+
+// This function can take optional child elements as arguments[2:].
+function createDom(tagName, attributes)
+{
+    var element = document.createElement(tagName);
+    for (var name in attributes)
+        element.setAttribute(name, attributes[name]);
+    var childElements = Array.prototype.slice.call(arguments, 2);
+    for (var i = 0; i < childElements.length; ++i)
+        element.appendChild(childElements[i]);
+    return element;
+}
index e3a5f950ebc33d6f713142c6998e0d2bb3321fca..9412a71bda1971995cbfb974fcc5c267aee9e871 100644 (file)
@@ -1,3 +1,33 @@
+2011-08-01  Hayato Ito  <hayato@chromium.org>
+
+        Add support for getting an element in shadow root by its id into a window.internals object.
+        https://bugs.webkit.org/show_bug.cgi?id=64587
+
+        Reviewed by Hajime Morita.
+
+        Test: fast/dom/shadow/get-element-by-id-in-shadow-root.html
+
+        * WebCore.exp.in:
+        * testing/Internals.cpp:
+        (WebCore::Internals::getElementByIdInShadowRoot):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
+2011-07-15  Hayato Ito  <hayato@chromium.org>
+
+        Add support for retrieving an element in TreeScope by id to window.internals object.
+        https://bugs.webkit.org/show_bug.cgi?id=64587
+
+        Reviewed by Hajime Morita.
+
+        Test: fast/dom/shadow/get-element-by-id-in-shadow.html
+
+        * WebCore.exp.in:
+        * testing/Internals.cpp:
+        (WebCore::Internals::getElementByIdInTreeScope):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2011-08-01  Yury Semikhatsky  <yurys@chromium.org>
 
         Web Inspector: typing an expression in an iframe leads to multiple "Unsafe JavaScript attempt to access frame..." errors
index e176f9150962554454a393a42dea50c00bf1ce88..115f00d58f21ebc5bceaf8b494f904efc89a6437 100644 (file)
@@ -1342,6 +1342,7 @@ __ZNK7WebCore9FrameView23documentBackgroundColorEv
 __ZNK7WebCore9FrameView28isEnclosedInCompositingLayerEv
 __ZNK7WebCore9PageCache10frameCountEv
 __ZNK7WebCore9PageCache21autoreleasedPageCountEv
+__ZNK7WebCore9TreeScope14getElementByIdERKN3WTF12AtomicStringE
 __ZTVN7WebCore12ChromeClientE
 __ZTVN7WebCore12JSDOMWrapperE
 __ZTVN7WebCore16IconDatabaseBaseE
index 40312eb69ae012abd26cd3bf097f7d7b54cd95c4..6ef5ea20b071965666a68d4fa6de560fd0aba7e4 100644 (file)
@@ -72,6 +72,15 @@ PassRefPtr<Element> Internals::createShadowContentElement(Document* document, Ex
     return ShadowContentElement::create(document);
 }
 
+Element* Internals::getElementByIdInShadowRoot(Node* shadowRoot, const String& id, ExceptionCode& ec)
+{
+    if (!shadowRoot || !shadowRoot->isShadowRoot()) {
+        ec = INVALID_ACCESS_ERR;
+        return 0;
+    }
+    return toShadowRoot(shadowRoot)->getElementById(id);
+}
+
 String Internals::elementRenderTreeAsText(Element* element, ExceptionCode& ec)
 {
     if (!element) {
index 941d98550a5f14936622d29c08df3f49a6c5c38c..9d3fc532f17c145362c0f652bc8f7cdead732dbc 100644 (file)
@@ -54,6 +54,7 @@ public:
     Element* includerFor(Node*, ExceptionCode&);
     String shadowPseudoId(Element*, ExceptionCode&);
     PassRefPtr<Element> createShadowContentElement(Document*, ExceptionCode&);
+    Element* getElementByIdInShadowRoot(Node* shadowRoot, const String& id, ExceptionCode&);
 
 #if ENABLE(INSPECTOR)
     void setInspectorResourcesDataSizeLimits(Document*, int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionCode&);
index f2fbf960dce4adc7a8767f6790da8d39477b774e..ff652046eb06783ec862d105150f2c901e0cac0c 100644 (file)
@@ -36,6 +36,7 @@ module window {
         void removeShadowRoot(in Element host) raises (DOMException);
         DOMString shadowPseudoId(in Element element) raises (DOMException);
         Element createShadowContentElement(in Document document) raises(DOMException);
+        Element getElementByIdInShadowRoot(in Node shadowRoot, in DOMString id) raises(DOMException);
 
         void setInspectorResourcesDataSizeLimits(in Document document, in long maximumResourcesContentSize, in long maximumSingleResourceContentSize) raises(DOMException);
 
index 643814cf26d00a4ee3b7a52bfcaaf2c82681af3a..85ab41fec86af43cc76a71396c20330d8dca456e 100644 (file)
@@ -1,3 +1,13 @@
+2011-08-01  Hayato Ito  <hayato@chromium.org>
+
+        Add support for getting an element in shadow root by its id into a window.internals object.
+        https://bugs.webkit.org/show_bug.cgi?id=64587
+
+        Reviewed by Hajime Morita.
+
+        * win/WebKit2.def:
+        * win/WebKit2CFLite.def:
+
 2011-08-01  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r92108.
index 370686af73a3de7e80fc639579c3c293f284b6b5..59a301e08f845ca80201f929aeba7d5a27317027 100644 (file)
@@ -151,6 +151,7 @@ EXPORTS
         ?ensureShadowRoot@Element@WebCore@@QAEPAVShadowRoot@2@XZ
         ?externalRepresentation@WebCore@@YA?AVString@WTF@@PAVElement@1@I@Z
         ?getCachedDOMStructure@WebCore@@YAPAVStructure@JSC@@PAVJSDOMGlobalObject@1@PBUClassInfo@3@@Z
+        ?getElementById@TreeScope@WebCore@@QBEPAVElement@2@ABVAtomicString@WTF@@@Z
         ?isPreloaded@CachedResourceLoader@WebCore@@QBE_NABVString@WTF@@@Z
         ?jsStringSlowCase@WebCore@@YA?AVJSValue@JSC@@PAVExecState@3@AAV?$HashMap@PAVStringImpl@WTF@@V?$Weak@VJSString@JSC@@@JSC@@UStringHash@2@U?$HashTraits@PAVStringImpl@WTF@@@2@U?$HashTraits@V?$Weak@VJSString@JSC@@@JSC@@@2@@WTF@@PAVStringImpl@6@@Z
         ?page@Document@WebCore@@QBEPAVPage@2@XZ
index 4a05735e8c665fb84b2bf0a29349dfdd6edd1671..9dda75139fe77cfefd44678f868c47901018ac66 100644 (file)
@@ -143,6 +143,7 @@ EXPORTS
         ?ensureShadowRoot@Element@WebCore@@QAEPAVShadowRoot@2@XZ
         ?externalRepresentation@WebCore@@YA?AVString@WTF@@PAVElement@1@I@Z
         ?getCachedDOMStructure@WebCore@@YAPAVStructure@JSC@@PAVJSDOMGlobalObject@1@PBUClassInfo@3@@Z
+        ?getElementById@TreeScope@WebCore@@QBEPAVElement@2@ABVAtomicString@WTF@@@Z
         ?isPreloaded@CachedResourceLoader@WebCore@@QBE_NABVString@WTF@@@Z
         ?toJS@WebCore@@YA?AVJSValue@JSC@@PAVExecState@3@PAVJSDOMGlobalObject@1@PAVClientRect@1@@Z
         ?updateLayoutIgnorePendingStylesheets@Document@WebCore@@QAEXXZ
@@ -156,4 +157,4 @@ EXPORTS
         ?toElement@WebCore@@YAPAVElement@1@VJSValue@JSC@@@Z
         ?toJS@WebCore@@YA?AVJSValue@JSC@@PAVExecState@3@PAVJSDOMGlobalObject@1@PAVNode@1@@Z
         ?toNode@WebCore@@YAPAVNode@1@VJSValue@JSC@@@Z
-        ?virtualFunctionToPreventWeakVtable@JSDOMWrapper@WebCore@@MAEXXZ
\ No newline at end of file
+        ?virtualFunctionToPreventWeakVtable@JSDOMWrapper@WebCore@@MAEXXZ
index 88a93a9ad8a7e68b1582f4f8979caef9d5d2032e..f80bc3d6fd554de6e5f98eabbd5d366716973406 100644 (file)
@@ -60,6 +60,7 @@ _ZNK7WebCore20CachedResourceLoader11isPreloadedERKN3WTF6StringE;
 _ZNK7WebCore6JSNode21pushEventHandlerScopeEPN3JSC9ExecStateEPNS1_14ScopeChainNodeE;
 _ZNK7WebCore7Element10shadowRootEv;
 _ZNK7WebCore8Document4pageEv;
+_ZNK7WebCore9TreeScope14getElementByIdERKN3WTF12AtomicStringE;
 local:
 _Z*;
 cti*;