[Refactoring] Use userAgentShadowRoot() to take user agent shadow root.
authorshinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jul 2012 08:56:12 +0000 (08:56 +0000)
committershinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jul 2012 08:56:12 +0000 (08:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=91716

Reviewed by Hajime Morita.

We have introduced Element::userAgentShadowRoot in r123071 to take user agent shadow root.
We have used shadow()->oldestShadowRoot() to take the user agent shadow root, however its code intention was
not so clear. Using userAgentShadowRoot() will make it clearer.

No new tests, simple refactoring.

* html/ColorInputType.cpp:
(WebCore::ColorInputType::createShadowSubtree):
(WebCore::ColorInputType::shadowColorSwatch):
* html/FileInputType.cpp:
(WebCore::FileInputType::createShadowSubtree):
(WebCore::FileInputType::multipleAttributeChanged):
* html/HTMLDetailsElement.cpp:
(WebCore::HTMLDetailsElement::findMainSummary):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::willAddAuthorShadowRoot):
(WebCore::HTMLImageElement::imageElement):
(WebCore::HTMLImageElement::innerElement):
* html/HTMLKeygenElement.cpp:
(WebCore::HTMLKeygenElement::shadowSelect):
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::innerTextElement):
(WebCore::HTMLTextAreaElement::updatePlaceholderText):
* html/InputType.cpp:
(WebCore::InputType::destroyShadowSubtree):
* html/RangeInputType.cpp:
(WebCore::RangeInputType::handleMouseDownEvent):
(WebCore::RangeInputType::createShadowSubtree):
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::createShadowSubtree):
(WebCore::TextFieldInputType::updatePlaceholderText):
* html/ValidationMessage.cpp:
(WebCore::ValidationMessage::deleteBubbleTree):
* html/shadow/SliderThumbElement.cpp:
(WebCore::sliderThumbElementOf):
(WebCore::trackLimiterElementOf):

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

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/ColorInputType.cpp
Source/WebCore/html/FileInputType.cpp
Source/WebCore/html/HTMLDetailsElement.cpp
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLKeygenElement.cpp
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/html/InputType.cpp
Source/WebCore/html/RangeInputType.cpp
Source/WebCore/html/TextFieldInputType.cpp
Source/WebCore/html/ValidationMessage.cpp
Source/WebCore/html/shadow/SliderThumbElement.cpp

index 35dbfb3..c9bb0d3 100644 (file)
@@ -1,3 +1,47 @@
+2012-07-19  Shinya Kawanaka  <shinyak@chromium.org>
+
+        [Refactoring] Use userAgentShadowRoot() to take user agent shadow root.
+        https://bugs.webkit.org/show_bug.cgi?id=91716
+
+        Reviewed by Hajime Morita.
+
+        We have introduced Element::userAgentShadowRoot in r123071 to take user agent shadow root.
+        We have used shadow()->oldestShadowRoot() to take the user agent shadow root, however its code intention was
+        not so clear. Using userAgentShadowRoot() will make it clearer.
+
+        No new tests, simple refactoring.
+
+        * html/ColorInputType.cpp:
+        (WebCore::ColorInputType::createShadowSubtree):
+        (WebCore::ColorInputType::shadowColorSwatch):
+        * html/FileInputType.cpp:
+        (WebCore::FileInputType::createShadowSubtree):
+        (WebCore::FileInputType::multipleAttributeChanged):
+        * html/HTMLDetailsElement.cpp:
+        (WebCore::HTMLDetailsElement::findMainSummary):
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::willAddAuthorShadowRoot):
+        (WebCore::HTMLImageElement::imageElement):
+        (WebCore::HTMLImageElement::innerElement):
+        * html/HTMLKeygenElement.cpp:
+        (WebCore::HTMLKeygenElement::shadowSelect):
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::innerTextElement):
+        (WebCore::HTMLTextAreaElement::updatePlaceholderText):
+        * html/InputType.cpp:
+        (WebCore::InputType::destroyShadowSubtree):
+        * html/RangeInputType.cpp:
+        (WebCore::RangeInputType::handleMouseDownEvent):
+        (WebCore::RangeInputType::createShadowSubtree):
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::createShadowSubtree):
+        (WebCore::TextFieldInputType::updatePlaceholderText):
+        * html/ValidationMessage.cpp:
+        (WebCore::ValidationMessage::deleteBubbleTree):
+        * html/shadow/SliderThumbElement.cpp:
+        (WebCore::sliderThumbElementOf):
+        (WebCore::trackLimiterElementOf):
+
 2012-07-19  Keishi Hattori  <keishi@webkit.org>
 
         Redraw slider tick marks when datalist changes.
index 1ececc2..601d28e 100644 (file)
@@ -117,7 +117,7 @@ void ColorInputType::createShadowSubtree()
     ExceptionCode ec = 0;
     wrapperElement->appendChild(colorSwatch.release(), ec);
     ASSERT(!ec);
-    element()->shadow()->oldestShadowRoot()->appendChild(wrapperElement.release(), ec);
+    element()->userAgentShadowRoot()->appendChild(wrapperElement.release(), ec);
     ASSERT(!ec);
     
     updateColorSwatch();
@@ -191,7 +191,7 @@ void ColorInputType::updateColorSwatch()
 
 HTMLElement* ColorInputType::shadowColorSwatch() const
 {
-    ShadowRoot* shadow = element()->shadow()->oldestShadowRoot();
+    ShadowRoot* shadow = element()->userAgentShadowRoot();
     return shadow ? toHTMLElement(shadow->firstChild()->firstChild()) : 0;
 }
 
index f39733d..7a75e13 100644 (file)
@@ -297,13 +297,13 @@ void FileInputType::createShadowSubtree()
 {
     ASSERT(element()->shadow());
     ExceptionCode ec = 0;
-    element()->shadow()->oldestShadowRoot()->appendChild(element()->multiple() ? UploadButtonElement::createForMultiple(element()->document()): UploadButtonElement::create(element()->document()), ec);
+    element()->userAgentShadowRoot()->appendChild(element()->multiple() ? UploadButtonElement::createForMultiple(element()->document()): UploadButtonElement::create(element()->document()), ec);
 }
 
 void FileInputType::multipleAttributeChanged()
 {
     ASSERT(element()->shadow());
-    UploadButtonElement* button = static_cast<UploadButtonElement*>(element()->shadow()->oldestShadowRoot()->firstChild());
+    UploadButtonElement* button = static_cast<UploadButtonElement*>(element()->userAgentShadowRoot()->firstChild());
     if (button)
         button->setValue(element()->multiple() ? fileButtonChooseMultipleFilesLabel() : fileButtonChooseFileLabel());
 }
index 531bd33..a80fe62 100644 (file)
@@ -124,7 +124,7 @@ Element* HTMLDetailsElement::findMainSummary() const
             return toElement(child);
     }
 
-    return static_cast<DetailsSummaryElement*>(shadow()->oldestShadowRoot()->firstChild())->fallbackSummary();
+    return static_cast<DetailsSummaryElement*>(userAgentShadowRoot()->firstChild())->fallbackSummary();
 }
 
 void HTMLDetailsElement::parseAttribute(const Attribute& attribute)
index 2992b6a..e3138e6 100644 (file)
@@ -96,7 +96,7 @@ HTMLImageElement::~HTMLImageElement()
 
 void HTMLImageElement::willAddAuthorShadowRoot()
 {
-    if (shadow()->oldestShadowRoot())
+    if (userAgentShadowRoot())
         return;
 
     createShadowSubtree();
@@ -112,9 +112,9 @@ void HTMLImageElement::createShadowSubtree()
 
 Element* HTMLImageElement::imageElement()
 {
-    if (ElementShadow* elementShadow = shadow()) {
-        ASSERT(elementShadow->oldestShadowRoot()->firstChild()->hasTagName(webkitInnerImageTag));
-        return toElement(elementShadow->oldestShadowRoot()->firstChild());
+    if (ShadowRoot* root = userAgentShadowRoot()) {
+        ASSERT(root->firstChild()->hasTagName(webkitInnerImageTag));
+        return toElement(root->firstChild());
     }
 
     return this;
@@ -409,8 +409,8 @@ void HTMLImageElement::setItemValueText(const String& value, ExceptionCode&)
 
 inline ImageInnerElement* HTMLImageElement::innerElement() const
 {
-    ASSERT(shadow());
-    return toImageInnerElement(shadow()->oldestShadowRoot()->firstChild());
+    ASSERT(userAgentShadowRoot());
+    return toImageInnerElement(userAgentShadowRoot()->firstChild());
 }
 
 }
index a1b032e..cfe2d8e 100644 (file)
@@ -136,7 +136,7 @@ bool HTMLKeygenElement::shouldSaveAndRestoreFormControlState() const
 
 HTMLSelectElement* HTMLKeygenElement::shadowSelect() const
 {
-    ShadowRoot* root = this->shadow()->oldestShadowRoot();
+    ShadowRoot* root = userAgentShadowRoot();
     return root ? toHTMLSelectElement(root->firstChild()) : 0;
 }
 
index d07a972..bad8571 100644 (file)
@@ -294,7 +294,7 @@ String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue,
 
 HTMLElement* HTMLTextAreaElement::innerTextElement() const
 {
-    Node* node = shadow()->oldestShadowRoot()->firstChild();
+    Node* node = userAgentShadowRoot()->firstChild();
     ASSERT(!node || node->hasTagName(divTag));
     return toHTMLElement(node);
 }
@@ -505,7 +505,7 @@ void HTMLTextAreaElement::updatePlaceholderText()
     String placeholderText = strippedPlaceholder();
     if (placeholderText.isEmpty()) {
         if (m_placeholder) {
-            shadow()->oldestShadowRoot()->removeChild(m_placeholder.get(), ec);
+            userAgentShadowRoot()->removeChild(m_placeholder.get(), ec);
             ASSERT(!ec);
             m_placeholder.clear();
         }
@@ -514,7 +514,7 @@ void HTMLTextAreaElement::updatePlaceholderText()
     if (!m_placeholder) {
         m_placeholder = HTMLDivElement::create(document());
         m_placeholder->setShadowPseudoId("-webkit-input-placeholder");
-        shadow()->oldestShadowRoot()->insertBefore(m_placeholder, innerTextElement()->nextSibling(), ec);
+        userAgentShadowRoot()->insertBefore(m_placeholder, innerTextElement()->nextSibling(), ec);
         ASSERT(!ec);
     }
     m_placeholder->setInnerText(placeholderText, ec);
index db86f89..9ce6aa6 100644 (file)
@@ -453,12 +453,10 @@ void InputType::createShadowSubtree()
 
 void InputType::destroyShadowSubtree()
 {
-    ElementShadow* shadow = element()->shadow();
-    if (!shadow)
+    ShadowRoot* root = element()->userAgentShadowRoot();
+    if (!root)
         return;
 
-    ShadowRoot* root = shadow->oldestShadowRoot();
-    ASSERT(root->type() == ShadowRoot::UserAgentShadowRoot);
     root->removeAllChildren();
 
     // It's ok to clear contents of all other ShadowRoots because they must have
index bf2d49f..c793bfb 100644 (file)
@@ -137,7 +137,7 @@ void RangeInputType::handleMouseDownEvent(MouseEvent* event)
     if (event->button() != LeftButton || !targetNode)
         return;
     ASSERT(element()->shadow());
-    if (targetNode != element() && !targetNode->isDescendantOf(element()->shadow()->oldestShadowRoot()))
+    if (targetNode != element() && !targetNode->isDescendantOf(element()->userAgentShadowRoot()))
         return;
     SliderThumbElement* thumb = sliderThumbElementOf(element());
     if (targetNode == thumb)
@@ -244,7 +244,7 @@ void RangeInputType::createShadowSubtree()
     RefPtr<HTMLElement> container = SliderContainerElement::create(document);
     container->appendChild(track.release(), ec);
     container->appendChild(TrackLimiterElement::create(document), ec);
-    element()->shadow()->oldestShadowRoot()->appendChild(container.release(), ec);
+    element()->userAgentShadowRoot()->appendChild(container.release(), ec);
 }
 
 RenderObject* RangeInputType::createRenderer(RenderArena* arena, RenderStyle*) const
index 632816b..10ed8fb 100644 (file)
@@ -246,11 +246,11 @@ void TextFieldInputType::createShadowSubtree()
     ExceptionCode ec = 0;
     m_innerText = TextControlInnerTextElement::create(document);
     if (!createsContainer) {
-        element()->shadow()->oldestShadowRoot()->appendChild(m_innerText, ec);
+        element()->userAgentShadowRoot()->appendChild(m_innerText, ec);
         return;
     }
 
-    ShadowRoot* shadowRoot = element()->shadow()->oldestShadowRoot();
+    ShadowRoot* shadowRoot = element()->userAgentShadowRoot();
     m_container = HTMLDivElement::create(document);
     m_container->setShadowPseudoId("-webkit-textfield-decoration-container");
     shadowRoot->appendChild(m_container, ec);
@@ -417,7 +417,7 @@ void TextFieldInputType::updatePlaceholderText()
     if (!m_placeholder) {
         m_placeholder = HTMLDivElement::create(element()->document());
         m_placeholder->setShadowPseudoId("-webkit-input-placeholder");
-        element()->shadow()->oldestShadowRoot()->insertBefore(m_placeholder, m_container ? m_container->nextSibling() : innerTextElement()->nextSibling(), ec);
+        element()->userAgentShadowRoot()->insertBefore(m_placeholder, m_container ? m_container->nextSibling() : innerTextElement()->nextSibling(), ec);
         ASSERT(!ec);
     }
     m_placeholder->setInnerText(placeholderText, ec);
index b63d883..1901f46 100644 (file)
@@ -196,7 +196,7 @@ void ValidationMessage::deleteBubbleTree(Timer<ValidationMessage>*)
         m_messageBody = 0;
         HTMLElement* host = toHTMLElement(m_element);
         ExceptionCode ec;
-        host->shadow()->oldestShadowRoot()->removeChild(m_bubble.get(), ec);
+        host->userAgentShadowRoot()->removeChild(m_bubble.get(), ec);
         m_bubble = 0;
     }
     m_message = String();
index 522c4a4..564dbb4 100644 (file)
@@ -74,7 +74,7 @@ inline static bool hasVerticalAppearance(HTMLInputElement* input)
 SliderThumbElement* sliderThumbElementOf(Node* node)
 {
     ASSERT(node);
-    ShadowRoot* shadow = node->toInputElement()->shadow()->oldestShadowRoot();
+    ShadowRoot* shadow = node->toInputElement()->userAgentShadowRoot();
     ASSERT(shadow);
     Node* thumb = shadow->firstChild()->firstChild()->firstChild();
     ASSERT(thumb);
@@ -424,8 +424,7 @@ const AtomicString& TrackLimiterElement::shadowPseudoId() const
 TrackLimiterElement* trackLimiterElementOf(Node* node)
 {
     ASSERT(node);
-    ASSERT(node->toInputElement()->shadow());
-    ShadowRoot* shadow = node->toInputElement()->shadow()->oldestShadowRoot();
+    ShadowRoot* shadow = node->toInputElement()->userAgentShadowRoot();
     ASSERT(shadow);
     Node* limiter = shadow->firstChild()->lastChild();
     ASSERT(limiter);