Reviewed by Adele.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 26 Feb 2005 01:41:13 +0000 (01:41 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 26 Feb 2005 01:41:13 +0000 (01:41 +0000)
        - fixed <rdar://problem/4025618> Crash while searching at hollywoodvideo.com

        * khtml/html/html_formimpl.h: Added valueWithDefault.
        * khtml/html/html_formimpl.cpp:
        (DOM::HTMLInputElementImpl::appendFormData): Call valueWithDefault instead of going at the render object
        to try to get the default value; there may be no render object if this is display:none.
        (DOM::HTMLInputElementImpl::valueWithDefault): Added. Knows about the defaults for "submit" and "reset"
        buttons; otherwise just returns the value as-is.

        * khtml/rendering/render_form.h: Removed the defaultLabel member functions.
        * khtml/rendering/render_form.cpp:
        (RenderSubmitButton::rawText): Call valueWithDefault instead of using defaultLabel function here on
        the render side. The DOM needs to know how to deal with the default anyway for form submission.
        (RenderSubmitButton::defaultLabel): Removed.
        (RenderResetButton::defaultLabel): Removed.
        (RenderPushButton::defaultLabel): Removed.

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/html/html_formimpl.cpp
WebCore/khtml/html/html_formimpl.h
WebCore/khtml/rendering/render_form.cpp
WebCore/khtml/rendering/render_form.h

index 58d84f4cc2b605956bae1413cd19fb9d636f508f..ed45ffebe6a30d0051f64b0b65836f5209dd2dc4 100644 (file)
@@ -1,3 +1,24 @@
+2005-02-25  Darin Adler  <darin@apple.com>
+
+        Reviewed by Adele.
+
+        - fixed <rdar://problem/4025618> Crash while searching at hollywoodvideo.com
+
+        * khtml/html/html_formimpl.h: Added valueWithDefault.
+        * khtml/html/html_formimpl.cpp:
+        (DOM::HTMLInputElementImpl::appendFormData): Call valueWithDefault instead of going at the render object
+        to try to get the default value; there may be no render object if this is display:none.
+        (DOM::HTMLInputElementImpl::valueWithDefault): Added. Knows about the defaults for "submit" and "reset"
+        buttons; otherwise just returns the value as-is.
+
+        * khtml/rendering/render_form.h: Removed the defaultLabel member functions.
+        * khtml/rendering/render_form.cpp:
+        (RenderSubmitButton::rawText): Call valueWithDefault instead of using defaultLabel function here on
+        the render side. The DOM needs to know how to deal with the default anyway for form submission.
+        (RenderSubmitButton::defaultLabel): Removed.
+        (RenderResetButton::defaultLabel): Removed.
+        (RenderPushButton::defaultLabel): Removed.
+
 2005-02-25  Darin Adler  <darin@apple.com>
 
         Reviewed by John.
index fc7f0564d217c682ee71ccbb844d5dcd4b0e90f0..990947194c321d75a7a7c7f0f49cb0e88e48865c 100644 (file)
@@ -1813,9 +1813,7 @@ bool HTMLInputElementImpl::appendFormData(FormDataList &encoding, bool multipart
         case SUBMIT:
             if (m_activeSubmit)
             {
-                QString enc_str = value().string();
-                if (enc_str.isEmpty())
-                    enc_str = static_cast<RenderSubmitButton*>(m_render)->defaultLabel();
+                QString enc_str = valueWithDefault().string();
                 if (!enc_str.isEmpty()) {
                     encoding.appendData(name(), enc_str);
                     return true;
@@ -1926,6 +1924,45 @@ DOMString HTMLInputElementImpl::value() const
     return value;
 }
 
+DOMString HTMLInputElementImpl::valueWithDefault() const
+{
+    DOMString v = value();
+    if (v.isEmpty()) {
+        switch (m_type) {
+            case RESET:
+#if APPLE_CHANGES
+                v = resetButtonDefaultLabel();
+#else
+                v = i18n("Reset");
+#endif
+                break;
+
+            case SUBMIT:
+#if APPLE_CHANGES
+                v = submitButtonDefaultLabel();
+#else
+                v = i18n("Submit");
+#endif
+                break;
+
+            case BUTTON:
+            case CHECKBOX:
+            case FILE:
+            case HIDDEN:
+            case IMAGE:
+            case ISINDEX:
+            case PASSWORD:
+            case RADIO:
+        #if APPLE_CHANGES
+            case RANGE:
+            case SEARCH:
+        #endif
+            case TEXT:
+                break;
+        }
+    }
+    return v;
+}
 
 void HTMLInputElementImpl::setValue(const DOMString &value)
 {
index d9377630e821385c69859f1f76541914b373e86f..841ade069ec27fdb138f551b9ac3258fb4abc33c 100644 (file)
@@ -315,6 +315,8 @@ public:
     DOMString value() const;
     void setValue(const DOMString &);
 
+    DOMString valueWithDefault() const;
+
     void setValueFromRenderer(const DOMString &);
     bool valueMatchesRenderer() const { return m_valueMatchesRenderer; }
     void setValueMatchesRenderer() { m_valueMatchesRenderer = true; }
index 134ede72f72e16dd5fe2c348bcecaf1c1a5dd11e..857384a05a92bdbb73a9f14660ae3e96464713bf 100644 (file)
@@ -362,7 +362,6 @@ void RenderRadioButton::calcMinMaxWidth()
 
 // -------------------------------------------------------------------------------
 
-
 RenderSubmitButton::RenderSubmitButton(HTMLInputElementImpl *element)
     : RenderButton(element)
 {
@@ -375,7 +374,7 @@ RenderSubmitButton::RenderSubmitButton(HTMLInputElementImpl *element)
 
 QString RenderSubmitButton::rawText()
 {
-    QString value = element()->value().isEmpty() ? defaultLabel() : element()->value().string();
+    QString value = element()->valueWithDefault().string();
     value = value.stripWhiteSpace();
     value.replace(QChar('\\'), backslashAsCurrencySymbol());
 #if APPLE_CHANGES
@@ -446,15 +445,6 @@ void RenderSubmitButton::updateFromElement()
     RenderFormElement::updateFromElement();
 }
 
-QString RenderSubmitButton::defaultLabel()
-{
-#if APPLE_CHANGES
-    return submitButtonDefaultLabel();
-#else
-    return i18n("Submit");
-#endif
-}
-
 short RenderSubmitButton::baselinePosition( bool f, bool isRootLineBox ) const
 {
     return RenderFormElement::baselinePosition( f, isRootLineBox );
@@ -470,33 +460,22 @@ RenderImageButton::RenderImageButton(HTMLInputElementImpl *element)
 
 // -------------------------------------------------------------------------------
 
+// FIXME: No real reason to need separate classes for RenderResetButton and
+// RenderSubmitButton now that the default label is handled on the DOM side.
 RenderResetButton::RenderResetButton(HTMLInputElementImpl *element)
     : RenderSubmitButton(element)
 {
 }
 
-QString RenderResetButton::defaultLabel()
-{
-#if APPLE_CHANGES
-    return resetButtonDefaultLabel();
-#else
-    return i18n("Reset");
-#endif
-}
-
-
 // -------------------------------------------------------------------------------
 
+// FIXME: No real reason to need separate classes for RenderPushButton and
+// RenderSubmitButton now that the default label is handled on the DOM side.
 RenderPushButton::RenderPushButton(HTMLInputElementImpl *element)
     : RenderSubmitButton(element)
 {
 }
 
-QString RenderPushButton::defaultLabel()
-{
-    return QString::null;
-}
-
 // -------------------------------------------------------------------------------
 
 #if !APPLE_CHANGES
index d40a49f38a00ffbfc3ad5de8686e1922af8114a6..e3f3b936719fe4c03d3473e757725977e88791ec 100644 (file)
@@ -184,8 +184,6 @@ public:
 
     virtual const char *renderName() const { return "RenderSubmitButton"; }
 
-    virtual QString defaultLabel();
-
     virtual void calcMinMaxWidth();
     virtual void updateFromElement();
     virtual short baselinePosition( bool, bool ) const;
@@ -217,8 +215,6 @@ public:
     RenderResetButton(DOM::HTMLInputElementImpl *element);
 
     virtual const char *renderName() const { return "RenderResetButton"; }
-
-    virtual QString defaultLabel();
 };
 
 // -------------------------------------------------------------------------
@@ -227,8 +223,6 @@ class RenderPushButton : public RenderSubmitButton
 {
 public:
     RenderPushButton(DOM::HTMLInputElementImpl *element);
-
-    virtual QString defaultLabel();
 };
 
 // -------------------------------------------------------------------------