2011-06-28 Kent Tamura <tkent@chromium.org>
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Jun 2011 09:20:58 +0000 (09:20 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Jun 2011 09:20:58 +0000 (09:20 +0000)
        Reviewed by Hajime Morita.

        Use RefPtr for the HTMLElement data members of TextFieldInptType
        and SearchInputType.
        https://bugs.webkit.org/show_bug.cgi?id=63511

        No new tests because of no behavior change.

        * html/SearchInputType.cpp:
        (WebCore::SearchInputType::SearchInputType):
        No need to initialize the element members explicitly because
        RefPtr constructor works well.
        (WebCore::SearchInputType::createShadowSubtree):
        Substitute an element to a data member, and don't call RefPtr<>::release().
        (WebCore::SearchInputType::innerBlockElement):
        Moved from the header file, and adjustment for RefPtr<>.
        (WebCore::SearchInputType::resultsButtonElement): ditto.
        (WebCore::SearchInputType::cancelButtonElement): ditto.
        (WebCore::SearchInputType::destroyShadowSubtree):
         Adjustment for RefPtr<>.
        * html/SearchInputType.h:
         - Move accessor functions to the cpp file because they are virtual.
         - Change element data member types: HTMLElement* -> RefPtr<HTMLElement>.
        * html/TextFieldInputType.cpp:
        (WebCore::TextFieldInputType::TextFieldInputType):
        No need to initialize the element members explicitly because
        RefPtr constructor works well.
        (WebCore::TextFieldInputType::~TextFieldInputType):
        Explicityly defines the destructor in the cpp file to avoid to
        make it implicitly in the header file. If the destructor was made
        in the header file, we would need to include HTMLElement.h in the
        header file.
        (WebCore::TextFieldInputType::createShadowSubtree):
        - Don't call RenderTheme::themeForPage().
        - Substitute an element to a data member, and don't call RefPtr<>::release().
        (WebCore::TextFieldInputType::setInnerTextElement):
         Moved from the header file to avoid to include HTMLElement.h.
        (WebCore::TextFieldInputType::setSpeechButtonElement): ditto.
        (WebCore::TextFieldInputType::innerTextElement):
        Moved from the header file, and adjustment for RefPtr<>.
        (WebCore::TextFieldInputType::innerSpinButtonElement): ditto.
        (WebCore::TextFieldInputType::speechButtonElement): ditto.
        (WebCore::TextFieldInputType::destroyShadowSubtree):
         Adjustment for RefPtr<>.
        * html/TextFieldInputType.h:
         - Move accessor functions to the cpp file because they are virtual.
         - Change element data member types: HTMLElement* -> RefPtr<HTMLElement>.

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

Source/WebCore/ChangeLog
Source/WebCore/html/SearchInputType.cpp
Source/WebCore/html/SearchInputType.h
Source/WebCore/html/TextFieldInputType.cpp
Source/WebCore/html/TextFieldInputType.h

index d549fa9..e12637b 100644 (file)
@@ -1,3 +1,53 @@
+2011-06-28  Kent Tamura  <tkent@chromium.org>
+
+        Reviewed by Hajime Morita.
+
+        Use RefPtr for the HTMLElement data members of TextFieldInptType
+        and SearchInputType.
+        https://bugs.webkit.org/show_bug.cgi?id=63511
+
+        No new tests because of no behavior change.
+
+        * html/SearchInputType.cpp:
+        (WebCore::SearchInputType::SearchInputType):
+        No need to initialize the element members explicitly because
+        RefPtr constructor works well.
+        (WebCore::SearchInputType::createShadowSubtree):
+        Substitute an element to a data member, and don't call RefPtr<>::release().
+        (WebCore::SearchInputType::innerBlockElement):
+        Moved from the header file, and adjustment for RefPtr<>.
+        (WebCore::SearchInputType::resultsButtonElement): ditto.
+        (WebCore::SearchInputType::cancelButtonElement): ditto.
+        (WebCore::SearchInputType::destroyShadowSubtree):
+         Adjustment for RefPtr<>.
+        * html/SearchInputType.h:
+         - Move accessor functions to the cpp file because they are virtual.
+         - Change element data member types: HTMLElement* -> RefPtr<HTMLElement>.
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::TextFieldInputType):
+        No need to initialize the element members explicitly because
+        RefPtr constructor works well.
+        (WebCore::TextFieldInputType::~TextFieldInputType):
+        Explicityly defines the destructor in the cpp file to avoid to
+        make it implicitly in the header file. If the destructor was made
+        in the header file, we would need to include HTMLElement.h in the
+        header file.
+        (WebCore::TextFieldInputType::createShadowSubtree):
+        - Don't call RenderTheme::themeForPage().
+        - Substitute an element to a data member, and don't call RefPtr<>::release().
+        (WebCore::TextFieldInputType::setInnerTextElement):
+         Moved from the header file to avoid to include HTMLElement.h.
+        (WebCore::TextFieldInputType::setSpeechButtonElement): ditto.
+        (WebCore::TextFieldInputType::innerTextElement):
+        Moved from the header file, and adjustment for RefPtr<>.
+        (WebCore::TextFieldInputType::innerSpinButtonElement): ditto.
+        (WebCore::TextFieldInputType::speechButtonElement): ditto.
+        (WebCore::TextFieldInputType::destroyShadowSubtree):
+         Adjustment for RefPtr<>.
+        * html/TextFieldInputType.h:
+         - Move accessor functions to the cpp file because they are virtual.
+         - Change element data member types: HTMLElement* -> RefPtr<HTMLElement>.
+
 2011-06-28  Felician Marton  <marton.felician.zoltan@stud.u-szeged.hu>
 
         Reviewed by Nikolas Zimmermann.
index 6feddea..ad798af 100644 (file)
@@ -40,9 +40,6 @@ namespace WebCore {
 
 inline SearchInputType::SearchInputType(HTMLInputElement* element)
     : BaseTextInputType(element)
-    , m_innerBlock(0)
-    , m_resultsButton(0)
-    , m_cancelButton(0)
 {
 }
 
@@ -69,43 +66,52 @@ bool SearchInputType::isSearchField() const
 void SearchInputType::createShadowSubtree()
 {
     ASSERT(!m_innerBlock);
-    ASSERT(!innerTextElement());
     ASSERT(!m_resultsButton);
     ASSERT(!m_cancelButton);
 
     ExceptionCode ec = 0;
     Document* document = element()->document();
-    RefPtr<HTMLElement> inner = TextControlInnerElement::create(document);
-    m_innerBlock = inner.get();
-    element()->ensureShadowRoot()->appendChild(inner.release(), ec);
+    m_innerBlock = TextControlInnerElement::create(document);
+    element()->ensureShadowRoot()->appendChild(m_innerBlock, ec);
 
 #if ENABLE(INPUT_SPEECH)
     if (element()->isSpeechEnabled()) {
-        RefPtr<HTMLElement> speech = InputFieldSpeechButtonElement::create(document);
-        setSpeechButtonElement(speech.get());
-        element()->ensureShadowRoot()->appendChild(speech.release(), ec);
+        setSpeechButtonElement(InputFieldSpeechButtonElement::create(document));
+        element()->ensureShadowRoot()->appendChild(speechButtonElement(), ec);
     }
 #endif
 
-    RefPtr<HTMLElement> results = SearchFieldResultsButtonElement::create(document);
-    m_resultsButton = results.get();
-    m_innerBlock->appendChild(results.release(), ec);
+    m_resultsButton = SearchFieldResultsButtonElement::create(document);
+    m_innerBlock->appendChild(m_resultsButton, ec);
 
-    RefPtr<HTMLElement> innerText = TextControlInnerTextElement::create(document);
-    setInnerTextElement(innerText.get());
-    m_innerBlock->appendChild(innerText.release(), ec);
+    setInnerTextElement(TextControlInnerTextElement::create(document));
+    m_innerBlock->appendChild(innerTextElement(), ec);
 
-    RefPtr<HTMLElement> cancel = SearchFieldCancelButtonElement::create(element()->document());
-    m_cancelButton = cancel.get();
-    m_innerBlock->appendChild(cancel.release(), ec);
+    m_cancelButton = SearchFieldCancelButtonElement::create(element()->document());
+    m_innerBlock->appendChild(m_cancelButton, ec);
+}
+
+HTMLElement* SearchInputType::innerBlockElement() const
+{
+    return m_innerBlock.get();
+}
+
+HTMLElement* SearchInputType::resultsButtonElement() const
+{
+    return m_resultsButton.get();
+}
+
+HTMLElement* SearchInputType::cancelButtonElement() const
+{
+    return m_cancelButton.get();
 }
 
 void SearchInputType::destroyShadowSubtree()
 {
     TextFieldInputType::destroyShadowSubtree();
-    m_innerBlock = 0;
-    m_resultsButton = 0;
-    m_cancelButton = 0;
+    m_innerBlock.clear();
+    m_resultsButton.clear();
+    m_cancelButton.clear();
 }
 
 
index c130d3c..6d43a3c 100644 (file)
@@ -51,13 +51,13 @@ private:
     virtual const AtomicString& formControlType() const;
     virtual bool shouldRespectSpeechAttribute();
     virtual bool isSearchField() const;
-    virtual HTMLElement* innerBlockElement() const { return m_innerBlock; }
-    virtual HTMLElement* resultsButtonElement() const { return m_resultsButton; }
-    virtual HTMLElement* cancelButtonElement() const { return m_cancelButton; }
+    virtual HTMLElement* innerBlockElement() const;
+    virtual HTMLElement* resultsButtonElement() const;
+    virtual HTMLElement* cancelButtonElement() const;
 
-    HTMLElement* m_innerBlock;
-    HTMLElement* m_resultsButton;
-    HTMLElement* m_cancelButton;
+    RefPtr<HTMLElement> m_innerBlock;
+    RefPtr<HTMLElement> m_resultsButton;
+    RefPtr<HTMLElement> m_cancelButton;
 };
 
 } // namespace WebCore
index 19bbdef..ae6d57a 100644 (file)
@@ -36,6 +36,7 @@
 #include "Frame.h"
 #include "HTMLInputElement.h"
 #include "KeyboardEvent.h"
+#include "Page.h"
 #include "RenderTextControlSingleLine.h"
 #include "RenderTheme.h"
 #include "ShadowRoot.h"
@@ -49,11 +50,10 @@ namespace WebCore {
 
 TextFieldInputType::TextFieldInputType(HTMLInputElement* element)
     : InputType(element)
-    , m_innerText(0)
-    , m_innerSpinButton(0)
-#if ENABLE(INPUT_SPEECH)
-    , m_speechButton(0)
-#endif
+{
+}
+
+TextFieldInputType::~TextFieldInputType()
 {
 }
 
@@ -134,7 +134,9 @@ void TextFieldInputType::createShadowSubtree()
     ASSERT(!m_innerText);
     ASSERT(!m_innerSpinButton);
 
-    bool shouldHaveSpinButton = RenderTheme::themeForPage(element()->document()->page())->shouldHaveSpinButton(element());
+    Document* document = element()->document();
+    RefPtr<RenderTheme> theme = document->page() ? document->page()->theme() : RenderTheme::defaultTheme();
+    bool shouldHaveSpinButton = theme->shouldHaveSpinButton(element());
     bool hasDecorations = shouldHaveSpinButton;
 #if ENABLE(INPUT_SPEECH)
     if (element()->isSpeechEnabled())
@@ -142,37 +144,63 @@ void TextFieldInputType::createShadowSubtree()
 #endif
 
     ExceptionCode ec = 0;
-    Document* document = element()->document();
-    RefPtr<HTMLElement> innerText = TextControlInnerTextElement::create(document);
-    m_innerText = innerText.get();
-    element()->ensureShadowRoot()->appendChild(innerText.release(), ec);
+    m_innerText = TextControlInnerTextElement::create(document);
+    element()->ensureShadowRoot()->appendChild(m_innerText, ec);
     if (!hasDecorations)
         return;
 
 #if ENABLE(INPUT_SPEECH)
     ASSERT(!m_speechButton);
     if (element()->isSpeechEnabled()) {
-        RefPtr<HTMLElement> speech = InputFieldSpeechButtonElement::create(document);
-        m_speechButton = speech.get();
-        element()->ensureShadowRoot()->appendChild(speech.release(), ec);
+        m_speechButton = InputFieldSpeechButtonElement::create(document);
+        element()->ensureShadowRoot()->appendChild(m_speechButton, ec);
     }
 #endif
 
     if (shouldHaveSpinButton) {
-        RefPtr<HTMLElement> inner = SpinButtonElement::create(document);
-        m_innerSpinButton = inner.get();
-        element()->ensureShadowRoot()->appendChild(inner.release(), ec);
+        m_innerSpinButton = SpinButtonElement::create(document);
+        element()->ensureShadowRoot()->appendChild(m_innerSpinButton, ec);
     }
 }
 
+void TextFieldInputType::setInnerTextElement(PassRefPtr<HTMLElement> element)
+{
+    m_innerText = element;
+}
+
+#if ENABLE(INPUT_SPEECH)
+void TextFieldInputType::setSpeechButtonElement(PassRefPtr<HTMLElement> element)
+{
+    m_speechButton = element;
+}
+#endif
+
+HTMLElement* TextFieldInputType::innerTextElement() const
+{
+    ASSERT(m_innerText);
+    return m_innerText.get();
+}
+
+HTMLElement* TextFieldInputType::innerSpinButtonElement() const
+{
+    return m_innerSpinButton.get();
+}
+
+#if ENABLE(INPUT_SPEECH)
+HTMLElement* TextFieldInputType::speechButtonElement() const
+{
+    return m_speechButton.get();
+}
+#endif
+
 void TextFieldInputType::destroyShadowSubtree()
 {
     InputType::destroyShadowSubtree();
-    m_innerText = 0;
+    m_innerText.clear();
 #if ENABLE(INPUT_SPEECH)
-    m_speechButton = 0;
+    m_speechButton.clear();
 #endif
-    m_innerSpinButton = 0;
+    m_innerSpinButton.clear();
 }
 
 bool TextFieldInputType::shouldUseInputMethod() const
index ecb6606..16cbc31 100644 (file)
@@ -40,23 +40,24 @@ namespace WebCore {
 class TextFieldInputType : public InputType {
 protected:
     TextFieldInputType(HTMLInputElement*);
+    virtual ~TextFieldInputType();
     virtual bool canSetSuggestedValue();
     virtual void handleKeydownEvent(KeyboardEvent*);
     void handleKeydownEventForSpinButton(KeyboardEvent*);
     void handleWheelEventForSpinButton(WheelEvent*);
 
-    virtual HTMLElement* innerTextElement() const { return m_innerText; }
-    virtual HTMLElement* innerSpinButtonElement() const { return m_innerSpinButton; }
+    virtual HTMLElement* innerTextElement() const;
+    virtual HTMLElement* innerSpinButtonElement() const;
 #if ENABLE(INPUT_SPEECH)
-    virtual HTMLElement* speechButtonElement() const { return m_speechButton; }
+    virtual HTMLElement* speechButtonElement() const;
 #endif
 
 protected:
     virtual void createShadowSubtree();
     virtual void destroyShadowSubtree();
-    void setInnerTextElement(HTMLElement* element) { m_innerText = element; }
+    void setInnerTextElement(PassRefPtr<HTMLElement>);
 #if ENABLE(INPUT_SPEECH)
-    void setSpeechButtonElement(HTMLElement* element) { m_speechButton = element; }
+    void setSpeechButtonElement(PassRefPtr<HTMLElement>);
 #endif
 
 private:
@@ -70,10 +71,10 @@ private:
     virtual String sanitizeValue(const String&);
     virtual bool shouldRespectListAttribute();
 
-    HTMLElement* m_innerText;
-    HTMLElement* m_innerSpinButton;
+    RefPtr<HTMLElement> m_innerText;
+    RefPtr<HTMLElement> m_innerSpinButton;
 #if ENABLE(INPUT_SPEECH)
-    HTMLElement* m_speechButton;
+    RefPtr<HTMLElement> m_speechButton;
 #endif
 };