Bug 867950 - Refactor HTMLInputElement::{Clone,RestoreState,SaveState}() to use GetValueMode() instead of mType. r=smaug
authorMounir Lamouri <mounir.lamouri@gmail.com>
Fri, 03 May 2013 18:17:09 +0100
changeset 130761 c75cee3cbf74e72c712138bd7b5a84df1de60ab7
parent 130760 6d1242311151f2597cc546784026e4a095879c7e
child 130762 29a70c8e22ccd9e1324c308d5a249fed4c0cc7fb
push id1579
push userphilringnalda@gmail.com
push dateSat, 04 May 2013 04:38:04 +0000
treeherderfx-team@a56432a42a41 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs867950
milestone23.0a1
Bug 867950 - Refactor HTMLInputElement::{Clone,RestoreState,SaveState}() to use GetValueMode() instead of mType. r=smaug
content/html/content/src/HTMLInputElement.cpp
--- a/content/html/content/src/HTMLInputElement.cpp
+++ b/content/html/content/src/HTMLInputElement.cpp
@@ -728,61 +728,49 @@ HTMLInputElement::Clone(nsINodeInfo* aNo
 
   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
   nsRefPtr<HTMLInputElement> it =
     new HTMLInputElement(ni.forget(), NOT_FROM_PARSER);
 
   nsresult rv = const_cast<HTMLInputElement*>(this)->CopyInnerTo(it);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  switch (mType) {
-    case NS_FORM_INPUT_EMAIL:
-    case NS_FORM_INPUT_SEARCH:
-    case NS_FORM_INPUT_TEXT:
-    case NS_FORM_INPUT_PASSWORD:
-    case NS_FORM_INPUT_TEL:
-    case NS_FORM_INPUT_URL:
-    case NS_FORM_INPUT_NUMBER:
-    case NS_FORM_INPUT_DATE:
-    case NS_FORM_INPUT_TIME:
-    case NS_FORM_INPUT_RANGE:
+  switch (GetValueMode()) {
+    case VALUE_MODE_VALUE:
       if (mValueChanged) {
         // We don't have our default value anymore.  Set our value on
         // the clone.
         nsAutoString value;
         GetValueInternal(value);
         // SetValueInternal handles setting the VALUE_CHANGED bit for us
         it->SetValueInternal(value, false, true);
       }
       break;
-    case NS_FORM_INPUT_FILE:
+    case VALUE_MODE_FILENAME:
       if (it->OwnerDoc()->IsStaticDocument()) {
         // We're going to be used in print preview.  Since the doc is static
         // we can just grab the pretty string and use it as wallpaper
         GetDisplayFileName(it->mStaticDocFileList);
       } else {
         it->mFiles.Clear();
         it->mFiles.AppendObjects(mFiles);
       }
       break;
-    case NS_FORM_INPUT_RADIO:
-    case NS_FORM_INPUT_CHECKBOX:
+    case VALUE_MODE_DEFAULT_ON:
       if (mCheckedChanged) {
         // We no longer have our original checked state.  Set our
         // checked state on the clone.
         it->DoSetChecked(mChecked, false, true);
       }
       break;
-    case NS_FORM_INPUT_IMAGE:
-      if (it->OwnerDoc()->IsStaticDocument()) {
+    case VALUE_MODE_DEFAULT:
+      if (mType == NS_FORM_INPUT_IMAGE && it->OwnerDoc()->IsStaticDocument()) {
         CreateStaticImageClone(it);
       }
       break;
-    default:
-      break;
   }
 
   it.forget(aResult);
   return NS_OK;
 }
 
 nsresult
 HTMLInputElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
@@ -4410,63 +4398,50 @@ HTMLInputElement::SubmitNamesValues(nsFo
   return aFormSubmission->AddNameValuePair(name, value);
 }
 
 
 NS_IMETHODIMP
 HTMLInputElement::SaveState()
 {
   nsRefPtr<HTMLInputElementState> inputState;
-  switch (mType) {
-    case NS_FORM_INPUT_CHECKBOX:
-    case NS_FORM_INPUT_RADIO:
-      {
-        if (mCheckedChanged) {
-          inputState = new HTMLInputElementState();
-          inputState->SetChecked(mChecked);
-        }
+  switch (GetValueMode()) {
+    case VALUE_MODE_DEFAULT_ON:
+      if (mCheckedChanged) {
+        inputState = new HTMLInputElementState();
+        inputState->SetChecked(mChecked);
+      }
+      break;
+    case VALUE_MODE_FILENAME:
+      if (mFiles.Count()) {
+        inputState = new HTMLInputElementState();
+        inputState->SetFiles(mFiles);
+      }
+      break;
+    case VALUE_MODE_VALUE:
+    case VALUE_MODE_DEFAULT:
+      // VALUE_MODE_DEFAULT shouldn't have their value saved except 'hidden',
+      // mType shouldn't be NS_FORM_INPUT_PASSWORD and value should have changed.
+      if ((GetValueMode() == VALUE_MODE_DEFAULT &&
+           mType != NS_FORM_INPUT_HIDDEN) ||
+          mType == NS_FORM_INPUT_PASSWORD || !mValueChanged) {
         break;
       }
 
-    // Never save passwords in session history
-    case NS_FORM_INPUT_PASSWORD:
+      inputState = new HTMLInputElementState();
+      nsAutoString value;
+      GetValue(value);
+      DebugOnly<nsresult> rv =
+        nsLinebreakConverter::ConvertStringLineBreaks(
+             value,
+             nsLinebreakConverter::eLinebreakPlatform,
+             nsLinebreakConverter::eLinebreakContent);
+      NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!");
+      inputState->SetValue(value);
       break;
-    case NS_FORM_INPUT_EMAIL:
-    case NS_FORM_INPUT_SEARCH:
-    case NS_FORM_INPUT_TEXT:
-    case NS_FORM_INPUT_TEL:
-    case NS_FORM_INPUT_URL:
-    case NS_FORM_INPUT_HIDDEN:
-    case NS_FORM_INPUT_NUMBER:
-    case NS_FORM_INPUT_DATE:
-    case NS_FORM_INPUT_TIME:
-    case NS_FORM_INPUT_RANGE:
-      {
-        if (mValueChanged) {
-          inputState = new HTMLInputElementState();
-          nsAutoString value;
-          GetValue(value);
-          DebugOnly<nsresult> rv =
-            nsLinebreakConverter::ConvertStringLineBreaks(
-                 value,
-                 nsLinebreakConverter::eLinebreakPlatform,
-                 nsLinebreakConverter::eLinebreakContent);
-          NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!");
-          inputState->SetValue(value);
-       }
-      break;
-    }
-    case NS_FORM_INPUT_FILE:
-      {
-        if (mFiles.Count()) {
-          inputState = new HTMLInputElementState();
-          inputState->SetFiles(mFiles);
-        }
-        break;
-      }
   }
 
   nsresult rv = NS_OK;
   nsPresState* state = nullptr;
   if (inputState) {
     rv = GetPrimaryPresState(this, &state);
     if (state) {
       state->SetStateProperty(inputState);
@@ -4600,47 +4575,39 @@ bool
 HTMLInputElement::RestoreState(nsPresState* aState)
 {
   bool restoredCheckedState = false;
 
   nsCOMPtr<HTMLInputElementState> inputState
     (do_QueryInterface(aState->GetStateProperty()));
 
   if (inputState) {
-    switch (mType) {
-      case NS_FORM_INPUT_CHECKBOX:
-      case NS_FORM_INPUT_RADIO:
-        {
-          if (inputState->IsCheckedSet()) {
-            restoredCheckedState = true;
-            DoSetChecked(inputState->GetChecked(), true, true);
-          }
-          break;
+    switch (GetValueMode()) {
+      case VALUE_MODE_DEFAULT_ON:
+        if (inputState->IsCheckedSet()) {
+          restoredCheckedState = true;
+          DoSetChecked(inputState->GetChecked(), true, true);
         }
-
-      case NS_FORM_INPUT_EMAIL:
-      case NS_FORM_INPUT_SEARCH:
-      case NS_FORM_INPUT_TEXT:
-      case NS_FORM_INPUT_TEL:
-      case NS_FORM_INPUT_URL:
-      case NS_FORM_INPUT_HIDDEN:
-      case NS_FORM_INPUT_NUMBER:
-      case NS_FORM_INPUT_DATE:
-      case NS_FORM_INPUT_TIME:
-      case NS_FORM_INPUT_RANGE:
-        {
-          SetValueInternal(inputState->GetValue(), false, true);
-          break;
-        }
-      case NS_FORM_INPUT_FILE:
+        break;
+      case VALUE_MODE_FILENAME:
         {
           const nsCOMArray<nsIDOMFile>& files = inputState->GetFiles();
           SetFiles(files, true);
+        }
+        break;
+      case VALUE_MODE_VALUE:
+      case VALUE_MODE_DEFAULT:
+        if (GetValueMode() == VALUE_MODE_DEFAULT &&
+            mType != NS_FORM_INPUT_HIDDEN) {
           break;
         }
+
+        SetValueInternal(inputState->GetValue(), false, true);
+        break;
+        break;
     }
   }
 
   if (aState->IsDisabledSet()) {
     SetDisabled(aState->GetDisabled());
   }
 
   return restoredCheckedState;