2010-09-16 Darin Adler <darin@apple.com>
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Sep 2010 19:40:49 +0000 (19:40 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Sep 2010 19:40:49 +0000 (19:40 +0000)
        Reviewed by Andreas Kling.

        Reduce use of HTMLInputElement::inputType so we can remove it later
        https://bugs.webkit.org/show_bug.cgi?id=45903

        * src/DOMUtilitiesPrivate.cpp:
        (WebKit::elementHasLegalLinkAttribute): Use isImageButton.
        * src/WebPasswordFormUtils.cpp:
        (WebKit::findPasswordFormFields): Use isPasswordField.
        * src/WebSearchableFormData.cpp:
        (WebCore::IsInDefaultState): Use isCheckbox and isRadioButton.
        (WebCore::HasSuitableTextElement): Use isFileUpload and isPasswordField.
2010-09-16  Darin Adler  <darin@apple.com>

        Reviewed by Andreas Kling.

        Reduce use of HTMLInputElement::inputType so we can remove it later
        https://bugs.webkit.org/show_bug.cgi?id=45903

        * WebCoreSupport/DumpRenderTreeSupportQt.cpp:
        (DumpRenderTreeSupportQt::elementDoesAutoCompleteForElementWithId):
        Use isPasswordField.
2010-09-16  Darin Adler  <darin@apple.com>

        Reviewed by Andreas Kling.

        Reduce use of HTMLInputElement::inputType so we can remove it later
        https://bugs.webkit.org/show_bug.cgi?id=45903

        * WebFrame.cpp:
        (WebFrame::elementDoesAutoComplete): Use isPasswordField.
        (WebFrame::elementIsPassword): Use isPasswordField.
2010-09-16  Darin Adler  <darin@apple.com>

        Reviewed by Andreas Kling.

        Reduce use of HTMLInputElement::inputType so we can remove it later
        https://bugs.webkit.org/show_bug.cgi?id=45903

        * WebView/WebHTMLRepresentation.mm:
        (-[WebHTMLRepresentation elementDoesAutoComplete:]): Use isPasswordField.
        (-[WebHTMLRepresentation elementIsPassword:]): Use isPasswordField.
2010-09-16  Darin Adler  <darin@apple.com>

        Reviewed by Andreas Kling.

        Reduce use of HTMLInputElement::inputType so we can remove it later
        https://bugs.webkit.org/show_bug.cgi?id=45903

        * accessibility/AccessibilityRenderObject.cpp:
        (WebCore::AccessibilityRenderObject::isFileUploadButton): Use isFileUpload.
        (WebCore::AccessibilityRenderObject::isInputImage): Use isImageButton.
        (WebCore::AccessibilityRenderObject::determineAccessibilityRole): Use
        isCheckbox and isRadioButton.

        * css/CSSStyleSelector.cpp:
        (WebCore::CSSStyleSelector::adjustRenderStyle): Use isImageButton.

        * editing/Editor.cpp:
        (WebCore::Editor::setBaseWritingDirection): Use isTextField.

        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::doApply): Use isPasswordField.

        * editing/SelectionController.cpp:
        (WebCore::SelectionController::isInPasswordField): Use isPasswordField.

        * html/HTMLInputElement.h: Added isFileUpload, isImageButton, and isSubmitButton.

        * page/Chrome.cpp:
        (WebCore::Chrome::setToolTip): Use isSubmitButton and isFileUpload.

        * page/DragController.cpp:
        (WebCore::asFileInput): Use isFileUpload.

        * page/EventHandler.cpp:
        (WebCore::isSubmitImage): Use isImageButton.

        * rendering/RenderFileUploadControl.cpp:
        (WebCore::RenderFileUploadControl::updateFromElement): Use isFileUpload.

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

21 files changed:
WebCore/ChangeLog
WebCore/accessibility/AccessibilityRenderObject.cpp
WebCore/css/CSSStyleSelector.cpp
WebCore/editing/Editor.cpp
WebCore/editing/ReplaceSelectionCommand.cpp
WebCore/editing/SelectionController.cpp
WebCore/html/HTMLInputElement.h
WebCore/page/Chrome.cpp
WebCore/page/DragController.cpp
WebCore/page/EventHandler.cpp
WebCore/rendering/RenderFileUploadControl.cpp
WebKit/chromium/ChangeLog
WebKit/chromium/src/DOMUtilitiesPrivate.cpp
WebKit/chromium/src/WebPasswordFormUtils.cpp
WebKit/chromium/src/WebSearchableFormData.cpp
WebKit/mac/ChangeLog
WebKit/mac/WebView/WebHTMLRepresentation.mm
WebKit/qt/ChangeLog
WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
WebKit/win/ChangeLog
WebKit/win/WebFrame.cpp

index 36b1b3f..aae333d 100644 (file)
@@ -1,3 +1,42 @@
+2010-09-16  Darin Adler  <darin@apple.com>
+
+        Reviewed by Andreas Kling.
+
+        Reduce use of HTMLInputElement::inputType so we can remove it later
+        https://bugs.webkit.org/show_bug.cgi?id=45903
+
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::isFileUploadButton): Use isFileUpload.
+        (WebCore::AccessibilityRenderObject::isInputImage): Use isImageButton.
+        (WebCore::AccessibilityRenderObject::determineAccessibilityRole): Use
+        isCheckbox and isRadioButton.
+
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::adjustRenderStyle): Use isImageButton.
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::setBaseWritingDirection): Use isTextField.
+
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::doApply): Use isPasswordField.
+
+        * editing/SelectionController.cpp:
+        (WebCore::SelectionController::isInPasswordField): Use isPasswordField.
+
+        * html/HTMLInputElement.h: Added isFileUpload, isImageButton, and isSubmitButton.
+
+        * page/Chrome.cpp:
+        (WebCore::Chrome::setToolTip): Use isSubmitButton and isFileUpload.
+
+        * page/DragController.cpp:
+        (WebCore::asFileInput): Use isFileUpload.
+
+        * page/EventHandler.cpp:
+        (WebCore::isSubmitImage): Use isImageButton.
+
+        * rendering/RenderFileUploadControl.cpp:
+        (WebCore::RenderFileUploadControl::updateFromElement): Use isFileUpload.
+
 2010-09-16  Pavel Podivilov  <podivilov@chromium.org>
 
         Reviewed by Pavel Feldman.
index b2c5023..5ca78ca 100644 (file)
@@ -503,7 +503,7 @@ bool AccessibilityRenderObject::isFileUploadButton() const
 {
     if (m_renderer && m_renderer->node() && m_renderer->node()->hasTagName(inputTag)) {
         HTMLInputElement* input = static_cast<HTMLInputElement*>(m_renderer->node());
-        return input->inputType() == HTMLInputElement::FILE;
+        return input->isFileUpload();
     }
     
     return false;
@@ -514,7 +514,7 @@ bool AccessibilityRenderObject::isInputImage() const
     Node* elementNode = node();
     if (roleValue() == ButtonRole && elementNode && elementNode->hasTagName(inputTag)) {
         HTMLInputElement* input = static_cast<HTMLInputElement*>(elementNode);
-        return input->inputType() == HTMLInputElement::IMAGE;
+        return input->isImageButton();
     }
     
     return false;
@@ -3036,9 +3036,9 @@ AccessibilityRole AccessibilityRenderObject::determineAccessibilityRole()
 
     if (node && node->hasTagName(inputTag)) {
         HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
-        if (input->inputType() == HTMLInputElement::CHECKBOX)
+        if (input->isCheckbox())
             return CheckBoxRole;
-        if (input->inputType() == HTMLInputElement::RADIO)
+        if (input->isRadioButton())
             return RadioButtonRole;
         if (input->isTextButton())
             return ButtonRole;
index 89e16fa..b22ba8f 100644 (file)
@@ -1796,7 +1796,7 @@ void CSSStyleSelector::adjustRenderStyle(RenderStyle* style, Element *e)
     if (e && e->isFormControlElement() && style->fontSize() >= 11) {
         // Don't apply intrinsic margins to image buttons.  The designer knows how big the images are,
         // so we have to treat all image buttons as though they were explicitly sized.
-        if (!e->hasTagName(inputTag) || static_cast<HTMLInputElement*>(e)->inputType() != HTMLInputElement::IMAGE)
+        if (!e->hasTagName(inputTag) || !static_cast<HTMLInputElement*>(e)->isImageButton())
             addIntrinsicMargins(style);
     }
 
index 125ecfa..24c1680 100644 (file)
@@ -1451,9 +1451,7 @@ void Editor::toggleUnderline()
 void Editor::setBaseWritingDirection(WritingDirection direction)
 {
     Node* focusedNode = frame()->document()->focusedNode();
-    if (focusedNode && (focusedNode->hasTagName(textareaTag)
-                        || (focusedNode->hasTagName(inputTag) && (static_cast<HTMLInputElement*>(focusedNode)->inputType() == HTMLInputElement::TEXT
-                                                                || static_cast<HTMLInputElement*>(focusedNode)->inputType() == HTMLInputElement::SEARCH)))) {
+    if (focusedNode && (focusedNode->hasTagName(textareaTag) || (focusedNode->hasTagName(inputTag) && static_cast<HTMLInputElement*>(focusedNode)->isTextField()))) {
         if (direction == NaturalWritingDirection)
             return;
         static_cast<HTMLElement*>(focusedNode)->setAttribute(dirAttr, direction == LeftToRightWritingDirection ? "ltr" : "rtl");
index e754aef..49bdaca 100644 (file)
@@ -1062,7 +1062,7 @@ void ReplaceSelectionCommand::doApply()
     if (m_smartReplace && currentRoot) {
         // Disable smart replace for password fields.
         Node* start = currentRoot->shadowAncestorNode();
-        if (start->hasTagName(inputTag) && static_cast<HTMLInputElement*>(start)->inputType() == HTMLInputElement::PASSWORD)
+        if (start->hasTagName(inputTag) && static_cast<HTMLInputElement*>(start)->isPasswordField())
             m_smartReplace = false;
     }
     if (m_smartReplace) {
index 1a0c031..c04fe25 100644 (file)
@@ -1332,7 +1332,7 @@ bool SelectionController::isInPasswordField() const
     if (!startNode->hasTagName(inputTag))
         return false;
     
-    return static_cast<HTMLInputElement*>(startNode)->inputType() == HTMLInputElement::PASSWORD;
+    return static_cast<HTMLInputElement*>(startNode)->isPasswordField();
 }
 
 bool SelectionController::caretRendersInsideNode(Node* node) const
index e023796..a29ed02 100644 (file)
@@ -102,16 +102,22 @@ public:
     void stepUpFromRenderer(int);
 
     bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; }
+
     virtual bool isRadioButton() const { return m_type == RADIO; }
     virtual bool isTextField() const;
     virtual bool isSearchField() const { return m_type == SEARCH; }
     virtual bool isInputTypeHidden() const { return m_type == HIDDEN; }
     virtual bool isPasswordField() const { return m_type == PASSWORD; }
     virtual bool isCheckbox() const { return m_type == CHECKBOX; }
-    bool isTelephoneField() const { return m_type == TELEPHONE; }
-    bool isNumberField() const { return m_type == NUMBER; }
+
     bool isEmailField() const { return m_type == EMAIL; }
-    bool isUrlField() const { return m_type == URL; }
+    bool isFileUpload() const { return m_type == FILE; }
+    bool isImageButton() const { return m_type == IMAGE; }
+    bool isNumberField() const { return m_type == NUMBER; }
+    bool isSubmitButton() const { return m_type == SUBMIT; }
+    bool isTelephoneField() const { return m_type == TELEPHONE; }
+    bool isURLField() const { return m_type == URL; }
+
 #if ENABLE(INPUT_SPEECH)
     virtual bool isSpeechEnabled() const;
 #endif    
index bff0100..8feedce 100644 (file)
@@ -350,7 +350,7 @@ void Chrome::setToolTip(const HitTestResult& result)
             // Get tooltip representing form action, if relevant
             if (node->hasTagName(inputTag)) {
                 HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
-                if (input->inputType() == HTMLInputElement::SUBMIT)
+                if (input->isSubmitButton())
                     if (HTMLFormElement* form = input->form()) {
                         toolTip = form->action();
                         if (form->renderer())
@@ -379,7 +379,7 @@ void Chrome::setToolTip(const HitTestResult& result)
         if (Node* node = result.innerNonSharedNode()) {
             if (node->hasTagName(inputTag)) {
                 HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
-                if (input->inputType() == HTMLInputElement::FILE) {
+                if (input->isFileUpload()) {
                     FileList* files = input->files();
                     unsigned listSize = files->length();
                     if (files && listSize > 1) {
index b55b7a1..0ba3a70 100644 (file)
@@ -255,17 +255,17 @@ static HTMLInputElement* asFileInput(Node* node)
     // The button for a FILE input is a sub element with no set input type
     // In order to get around this problem we assume any non-FILE input element
     // is this internal button, and try querying the shadow parent node.
-    if (node->hasTagName(HTMLNames::inputTag) && node->isShadowNode() && static_cast<HTMLInputElement*>(node)->inputType() != HTMLInputElement::FILE)
-      node = node->shadowParentNode();
+    if (node->hasTagName(HTMLNames::inputTag) && node->isShadowNode() && !static_cast<HTMLInputElement*>(node)->isFileUpload())
+        node = node->shadowParentNode();
 
     if (!node || !node->hasTagName(HTMLNames::inputTag))
         return 0;
 
-    HTMLInputElement* inputElem = static_cast<HTMLInputElement*>(node);
-    if (inputElem->inputType() == HTMLInputElement::FILE)
-        return inputElem;
+    HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(node);
+    if (!inputElement->isFileUpload())
+        return 0;
 
-    return 0;
+    return inputElement;
 }
 
 static Element* elementUnderMouse(Document* documentUnderMouse, const IntPoint& p)
index bec55de..c0a87a3 100644 (file)
@@ -1045,8 +1045,7 @@ Frame* EventHandler::subframeForTargetNode(Node* node)
 
 static bool isSubmitImage(Node* node)
 {
-    return node && node->hasTagName(inputTag)
-        && static_cast<HTMLInputElement*>(node)->inputType() == HTMLInputElement::IMAGE;
+    return node && node->hasTagName(inputTag) && static_cast<HTMLInputElement*>(node)->isImageButton();
 }
 
 // Returns true if the node's editable block is not current focused for editing
index f31ca20..7e2d617 100644 (file)
@@ -142,7 +142,7 @@ Chrome* RenderFileUploadControl::chrome() const
 void RenderFileUploadControl::updateFromElement()
 {
     HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(node());
-    ASSERT(inputElement->inputType() == HTMLInputElement::FILE);
+    ASSERT(inputElement->isFileUpload());
     
     if (!m_button) {
         m_button = ShadowInputElement::create(inputElement);
index 299f856..b819d56 100644 (file)
@@ -1,3 +1,18 @@
+2010-09-16  Darin Adler  <darin@apple.com>
+
+        Reviewed by Andreas Kling.
+
+        Reduce use of HTMLInputElement::inputType so we can remove it later
+        https://bugs.webkit.org/show_bug.cgi?id=45903
+
+        * src/DOMUtilitiesPrivate.cpp:
+        (WebKit::elementHasLegalLinkAttribute): Use isImageButton.
+        * src/WebPasswordFormUtils.cpp:
+        (WebKit::findPasswordFormFields): Use isPasswordField.
+        * src/WebSearchableFormData.cpp:
+        (WebCore::IsInDefaultState): Use isCheckbox and isRadioButton.
+        (WebCore::HasSuitableTextElement): Use isFileUpload and isPasswordField.
+
 2010-09-16  Kenneth Russell  <kbr@google.com>
 
         Reviewed by James Robinson.
index 4081db6..6f952f7 100644 (file)
@@ -97,7 +97,7 @@ bool elementHasLegalLinkAttribute(const Element* element,
         if (element->hasTagName(HTMLNames::inputTag)) {
             const HTMLInputElement* input =
             static_cast<const HTMLInputElement*>(element);
-            if (input->inputType() == HTMLInputElement::IMAGE)
+            if (input->isImageButton())
                 return true;
         }
     } else if (attrName == HTMLNames::hrefAttr) {
index e5d5411..a34b17a 100644 (file)
@@ -79,8 +79,8 @@ void findPasswordFormFields(HTMLFormElement* form, PasswordFormFields* fields)
             continue;
 
         if ((fields->passwords.size() < maxPasswords)
-            && (inputElement->inputType() == HTMLInputElement::PASSWORD)
-            && (inputElement->autoComplete())) {
+            && inputElement->isPasswordField()
+            && inputElement->autoComplete()) {
             if (fields->passwords.isEmpty())
                 firstPasswordIndex = i;
             fields->passwords.append(inputElement);
@@ -98,6 +98,7 @@ void findPasswordFormFields(HTMLFormElement* form, PasswordFormFields* fields)
             if (!inputElement->isEnabledFormControl())
                 continue;
 
+            // FIXME: This needs to use a function other than inputType.
             if ((inputElement->inputType() == HTMLInputElement::TEXT)
                 && (inputElement->autoComplete())) {
                 fields->userName = inputElement;
index 1864514..ba8a4f2 100644 (file)
@@ -131,7 +131,7 @@ bool IsInDefaultState(const HTMLFormControlElement* formElement)
 {
     if (formElement->hasTagName(HTMLNames::inputTag)) {
         const HTMLInputElement* inputElement = static_cast<const HTMLInputElement*>(formElement);
-        if (inputElement->inputType() == HTMLInputElement::CHECKBOX || inputElement->inputType() == HTMLInputElement::RADIO)
+        if (inputElement->isCheckbox() || inputElement->isRadioButton())
             return inputElement->checked() == inputElement->defaultChecked();
     } else if (formElement->hasTagName(HTMLNames::selectTag))
         return IsSelectInDefaultState(static_cast<const HTMLSelectElement*>(formElement));
@@ -166,19 +166,24 @@ bool HasSuitableTextElement(const HTMLFormElement* form, Vector<char>* encodedSt
 
         bool isTextElement = false;
         if (formElement->hasTagName(HTMLNames::inputTag)) {
+            if (static_cast<const HTMLInputElement*>(formElement)->isFileUpload()) {
+                // Too big, don't try to index this.
+                return 0;
+            }
+
+            if (static_cast<const HTMLInputElement*>(formElement)->isPasswordField()) {
+                // Don't store passwords! This is most likely an https anyway.
+                return 0;
+            }
+
+            // FIXME: This needs to use a function on HTMLInputElement other than inputType.
+            // Also, it's not clear why TEXT should be handled differently than, say, SEARCH.
             switch (static_cast<const HTMLInputElement*>(formElement)->inputType()) {
             case HTMLInputElement::TEXT:
             case HTMLInputElement::ISINDEX:
                 isTextElement = true;
                 break;
-            case HTMLInputElement::PASSWORD:
-                // Don't store passwords! This is most likely an https anyway.
-                // Fall through.
-            case HTMLInputElement::FILE:
-                // Too big, don't try to index this.
-                return 0;
             default:
-                // All other input types are indexable.
                 break;
             }
       }
index e8c86fb..6c1d080 100644 (file)
@@ -1,3 +1,14 @@
+2010-09-16  Darin Adler  <darin@apple.com>
+
+        Reviewed by Andreas Kling.
+
+        Reduce use of HTMLInputElement::inputType so we can remove it later
+        https://bugs.webkit.org/show_bug.cgi?id=45903
+
+        * WebView/WebHTMLRepresentation.mm:
+        (-[WebHTMLRepresentation elementDoesAutoComplete:]): Use isPasswordField.
+        (-[WebHTMLRepresentation elementIsPassword:]): Use isPasswordField.
+
 2010-09-16  Patrick Gansterer  <paroga@paroga.com>
 
         Reviewed by Darin Adler.
index 307617e..2699472 100644 (file)
@@ -306,15 +306,14 @@ static HTMLInputElement* inputElementFromDOMElement(DOMElement* element)
     HTMLInputElement* inputElement = inputElementFromDOMElement(element);
     return inputElement
         && inputElement->isTextField()
-        && inputElement->inputType() != HTMLInputElement::PASSWORD
+        && !inputElement->isPasswordField()
         && inputElement->autoComplete();
 }
 
 - (BOOL)elementIsPassword:(DOMElement *)element
 {
     HTMLInputElement* inputElement = inputElementFromDOMElement(element);
-    return inputElement
-        && inputElement->inputType() == HTMLInputElement::PASSWORD;
+    return inputElement && inputElement->isPasswordField();
 }
 
 - (DOMElement *)formForElement:(DOMElement *)element
index bd4b2c2..a970404 100644 (file)
@@ -1,3 +1,14 @@
+2010-09-16  Darin Adler  <darin@apple.com>
+
+        Reviewed by Andreas Kling.
+
+        Reduce use of HTMLInputElement::inputType so we can remove it later
+        https://bugs.webkit.org/show_bug.cgi?id=45903
+
+        * WebCoreSupport/DumpRenderTreeSupportQt.cpp:
+        (DumpRenderTreeSupportQt::elementDoesAutoCompleteForElementWithId):
+        Use isPasswordField.
+
 2010-09-16  Robert Hogan  <robert@webkit.org>
 
         Reviewed by Antonio Gomes.
index c4ad199..ed7ac32 100644 (file)
@@ -533,9 +533,7 @@ bool DumpRenderTreeSupportQt::elementDoesAutoCompleteForElementWithId(QWebFrame*
     if (!inputElement)
         return false;
 
-    return (inputElement->isTextField()
-            && inputElement->inputType() != HTMLInputElement::PASSWORD
-            && inputElement->autoComplete());
+    return inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->autoComplete();
 }
 
 void DumpRenderTreeSupportQt::setEditingBehavior(QWebPage* page, const QString& editingBehavior)
index 6f6a75d..41b6fa9 100644 (file)
@@ -1,3 +1,14 @@
+2010-09-16  Darin Adler  <darin@apple.com>
+
+        Reviewed by Andreas Kling.
+
+        Reduce use of HTMLInputElement::inputType so we can remove it later
+        https://bugs.webkit.org/show_bug.cgi?id=45903
+
+        * WebFrame.cpp:
+        (WebFrame::elementDoesAutoComplete): Use isPasswordField.
+        (WebFrame::elementIsPassword): Use isPasswordField.
+
 2010-09-14  Ada Chan  <adachan@apple.com>
 
         Reviewed by Adam Roben.
index d7f95e3..843f33a 100644 (file)
@@ -1185,7 +1185,7 @@ HRESULT WebFrame::elementDoesAutoComplete(IDOMElement *element, BOOL *result)
     if (!inputElement)
         *result = false;
     else
-        *result = inputElement->isTextField() && inputElement->inputType() != HTMLInputElement::PASSWORD && inputElement->autoComplete();
+        *result = inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->autoComplete();
 
     return S_OK;
 }
@@ -1390,9 +1390,8 @@ HRESULT WebFrame::controlsInForm(IDOMElement* form, IDOMElement** controls, int*
 
 HRESULT WebFrame::elementIsPassword(IDOMElement *element, bool *result)
 {
-    HTMLInputElement *inputElement = inputElementFromDOMElement(element);
-    *result = inputElement != 0
-        && inputElement->inputType() == HTMLInputElement::PASSWORD;
+    HTMLInputElement* inputElement = inputElementFromDOMElement(element);
+    *result = inputElement && inputElement->isPasswordField();
     return S_OK;
 }