Bug 1401706: Remove redundant boolean members from nsTextControlFrame. r?bholley draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 22 Sep 2017 07:33:41 +0200
changeset 669420 5d7206f080b53b28d7cede49a24093a283874afb
parent 669419 b910052d2d403908b9731d955236438c14077f04
child 669421 e25706cc7425eaac7b17a58ad01d242bdbd13c0e
push id81322
push userbmo:emilio@crisal.io
push dateSat, 23 Sep 2017 02:02:53 +0000
reviewersbholley
bugs1401706
milestone58.0a1
Bug 1401706: Remove redundant boolean members from nsTextControlFrame. r?bholley MozReview-Commit-ID: Ka81vlPMa88 Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
layout/forms/nsTextControlFrame.cpp
layout/forms/nsTextControlFrame.h
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -118,18 +118,16 @@ private:
   nsTextControlFrame& mFrame;
 };
 
 nsTextControlFrame::nsTextControlFrame(nsStyleContext* aContext)
   : nsContainerFrame(aContext, kClassID)
   , mFirstBaseline(NS_INTRINSIC_WIDTH_UNKNOWN)
   , mEditorHasBeenInitialized(false)
   , mIsProcessing(false)
-  , mUsePlaceholder(false)
-  , mUsePreview(false)
 #ifdef DEBUG
   , mInEditorInitialization(false)
 #endif
 {
   ClearCachedValue();
 }
 
 nsTextControlFrame::~nsTextControlFrame()
@@ -492,38 +490,38 @@ void
 nsTextControlFrame::CreatePlaceholderIfNeeded()
 {
   MOZ_ASSERT(!mPlaceholderDiv);
 
   // Do we need a placeholder node?
   nsAutoString placeholderTxt;
   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder, placeholderTxt);
   nsContentUtils::RemoveNewlines(placeholderTxt);
-  mUsePlaceholder = !placeholderTxt.IsEmpty();
+
+  if (placeholderTxt.IsEmpty()) {
+    return;
+  }
 
-  // Create the placeholder anonymous content if needed.
-  if (mUsePlaceholder) {
-    mPlaceholderDiv = CreateEmptyDivWithTextNode(*this);
-    // Associate ::placeholder pseudo-element with the placeholder node.
-    mPlaceholderDiv->SetPseudoElementType(CSSPseudoElementType::placeholder);
-    mPlaceholderDiv->GetFirstChild()->SetText(placeholderTxt, false);
-  }
+  mPlaceholderDiv = CreateEmptyDivWithTextNode(*this);
+  // Associate ::placeholder pseudo-element with the placeholder node.
+  mPlaceholderDiv->SetPseudoElementType(CSSPseudoElementType::placeholder);
+  mPlaceholderDiv->GetFirstChild()->SetText(placeholderTxt, false);
 }
 
 void
 nsTextControlFrame::CreatePreviewIfNeeded()
 {
   nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
-  mUsePreview = txtCtrl->IsPreviewEnabled();
+  if (!txtCtrl->IsPreviewEnabled()) {
+    return;
+  }
 
-  if (mUsePreview) {
-    mPreviewDiv = CreateEmptyDivWithTextNode(*this);
-    mPreviewDiv->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
-                         NS_LITERAL_STRING("preview-div"), false);
-  }
+  mPreviewDiv = CreateEmptyDivWithTextNode(*this);
+  mPreviewDiv->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
+                       NS_LITERAL_STRING("preview-div"), false);
 }
 
 void
 nsTextControlFrame::AppendAnonymousContentTo(
   nsTArray<nsIContent*>& aElements,
   uint32_t aFilter)
 {
   aElements.AppendElement(mRootNode);
@@ -737,17 +735,17 @@ void nsTextControlFrame::SetFocus(bool a
   nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
   NS_ASSERTION(txtCtrl, "Content not a text control element");
 
   // Revoke the previous scroll event if one exists
   mScrollEvent.Revoke();
 
   // If 'dom.placeholeder.show_on_focus' preference is 'false', focusing or
   // blurring the frame can have an impact on the placeholder visibility.
-  if (mUsePlaceholder) {
+  if (mPlaceholderDiv) {
     txtCtrl->UpdateOverlayTextVisibility(true);
   }
 
   if (!aOn) {
     return;
   }
 
   nsISelectionController* selCon = txtCtrl->GetSelectionController();
@@ -1240,17 +1238,17 @@ nsTextControlFrame::SetInitialChildList(
 
 void
 nsTextControlFrame::SetValueChanged(bool aValueChanged)
 {
   nsCOMPtr<nsITextControlElement> txtCtrl =
     GetContent()->GetAsTextControlElement();
   MOZ_ASSERT(txtCtrl, "Content not a text control element");
 
-  if (mUsePlaceholder) {
+  if (mPlaceholderDiv) {
     AutoWeakFrame weakFrame(this);
     txtCtrl->UpdateOverlayTextVisibility(true);
     if (!weakFrame.IsAlive()) {
       return;
     }
   }
 
   txtCtrl->SetValueChanged(aValueChanged);
@@ -1263,18 +1261,16 @@ nsTextControlFrame::UpdateValueDisplay(b
                                        const nsAString *aValue)
 {
   if (!IsSingleLineTextControl()) // textareas don't use this
     return NS_OK;
 
   NS_PRECONDITION(mRootNode, "Must have a div content\n");
   NS_PRECONDITION(!mEditorHasBeenInitialized,
                   "Do not call this after editor has been initialized");
-  NS_ASSERTION(!mUsePlaceholder || mPlaceholderDiv,
-               "A placeholder div must exist");
 
   nsIContent* textContent = mRootNode->GetChildAt(0);
   if (!textContent) {
     // Set up a textnode with our value
     RefPtr<nsTextNode> textNode =
       new nsTextNode(mContent->NodeInfo()->NodeInfoManager());
     textNode->MarkAsMaybeModifiedFrequently();
 
@@ -1293,18 +1289,17 @@ nsTextControlFrame::UpdateValueDisplay(b
     value = *aValue;
   } else {
     txtCtrl->GetTextEditorValue(value, true);
   }
 
   // Update the display of the placeholder value and preview text if needed.
   // We don't need to do this if we're about to initialize the editor, since
   // EnsureEditorInitialized takes care of this.
-  if ((mUsePlaceholder || mUsePreview) && !aBeforeEditorInit)
-  {
+  if ((mPlaceholderDiv || mPreviewDiv) && !aBeforeEditorInit) {
     AutoWeakFrame weakFrame(this);
     txtCtrl->UpdateOverlayTextVisibility(aNotify);
     NS_ENSURE_STATE(weakFrame.IsAlive());
   }
 
   if (aBeforeEditorInit && value.IsEmpty()) {
     mRootNode->RemoveChildAt(0, true);
     return NS_OK;
--- a/layout/forms/nsTextControlFrame.h
+++ b/layout/forms/nsTextControlFrame.h
@@ -387,20 +387,16 @@ private:
 
   // Our first baseline, or NS_INTRINSIC_WIDTH_UNKNOWN if we have a pending
   // Reflow.
   nscoord mFirstBaseline;
 
   // these packed bools could instead use the high order bits on mState, saving 4 bytes
   bool mEditorHasBeenInitialized;
   bool mIsProcessing;
-  // Keep track if we have asked a placeholder node creation.
-  bool mUsePlaceholder;
-  // Similarly for preview node creation.
-  bool mUsePreview;
 
 #ifdef DEBUG
   bool mInEditorInitialization;
   friend class EditorInitializerEntryTracker;
 #endif
 
   nsRevocableEventPtr<ScrollOnFocusEvent> mScrollEvent;
 };