Bug 1387317 - part4: Make editor flag setters use new AddFlags() or RemoveFlags() if useful r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 08 Aug 2017 12:36:29 +0900
changeset 426925 de61ab519b71e5c70814b622d6d1fcedc67d5e96
parent 426924 052c275f31668433978e39ecdd7c18ef4e8045bc
child 426926 b131a336d02f715d73724704cc54517b4929d33a
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1387317
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1387317 - part4: Make editor flag setters use new AddFlags() or RemoveFlags() if useful r=m_kato MozReview-Commit-ID: EMDeGfK37Lx
dom/html/nsTextEditorState.cpp
editor/composer/nsComposerDocumentCommands.cpp
editor/libeditor/EditorBase.cpp
layout/forms/nsTextControlFrame.cpp
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -1563,18 +1563,19 @@ nsTextEditorState::PrepareEditor(const n
       editorFlags |= nsIPlaintextEditor::eEditorReadonlyMask;
 
     // Check if the disabled attribute is set.
     // TODO: call IsDisabled() here!
     if (content->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled))
       editorFlags |= nsIPlaintextEditor::eEditorDisabledMask;
 
     // Disable the selection if necessary.
-    if (editorFlags & nsIPlaintextEditor::eEditorDisabledMask)
+    if (newTextEditor->IsDisabled()) {
       mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_OFF);
+    }
 
     newTextEditor->SetFlags(editorFlags);
   }
 
   if (shouldInitializeEditor) {
     // Hold on to the newly created editor
     preDestroyer.Swap(mTextEditor);
   }
--- a/editor/composer/nsComposerDocumentCommands.cpp
+++ b/editor/composer/nsComposerDocumentCommands.cpp
@@ -227,26 +227,19 @@ nsSetDocumentStateCommand::DoCommandPara
     return textEditor->ResetModificationCount();
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly")) {
     NS_ENSURE_ARG_POINTER(aParams);
     bool isReadOnly;
     nsresult rvRO = aParams->GetBooleanValue(STATE_ATTRIBUTE, &isReadOnly);
     NS_ENSURE_SUCCESS(rvRO, rvRO);
-
-    uint32_t flags;
-    textEditor->GetFlags(&flags);
-    if (isReadOnly) {
-      flags |= nsIPlaintextEditor::eEditorReadonlyMask;
-    } else {
-      flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask);
-    }
-
-    return textEditor->SetFlags(flags);
+    return isReadOnly ?
+      textEditor->AddFlags(nsIPlaintextEditor::eEditorReadonlyMask) :
+      textEditor->RemoveFlags(nsIPlaintextEditor::eEditorReadonlyMask);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS")) {
     NS_ENSURE_ARG_POINTER(aParams);
     HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
     if (NS_WARN_IF(!htmlEditor)) {
       return NS_ERROR_INVALID_ARG;
     }
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1330,20 +1330,19 @@ EditorBase::RemoveAttribute(Element* aEl
   RefPtr<ChangeAttributeTransaction> transaction =
     CreateTxnForRemoveAttribute(*aElement, *aAttribute);
   return DoTransaction(transaction);
 }
 
 bool
 EditorBase::OutputsMozDirty()
 {
-  // Return true for Composer (!eEditorAllowInteraction) or mail
-  // (eEditorMailMask), but false for webpages.
-  return !(mFlags & nsIPlaintextEditor::eEditorAllowInteraction) ||
-          (mFlags & nsIPlaintextEditor::eEditorMailMask);
+  // Return true for Composer (!IsInteractionAllowed()) or mail
+  // (IsMailEditor()), but false for webpages.
+  return !IsInteractionAllowed() || IsMailEditor();
 }
 
 NS_IMETHODIMP
 EditorBase::MarkNodeDirty(nsIDOMNode* aNode)
 {
   // Mark the node dirty, but not for webpages (bug 599983)
   if (!OutputsMozDirty()) {
     return NS_OK;
@@ -4999,18 +4998,17 @@ nsresult
 EditorBase::DetermineCurrentDirection()
 {
   // Get the current root direction from its frame
   nsIContent* rootElement = GetExposedRoot();
   NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
 
   // If we don't have an explicit direction, determine our direction
   // from the content's direction
-  if (!(mFlags & (nsIPlaintextEditor::eEditorLeftToRight |
-                  nsIPlaintextEditor::eEditorRightToLeft))) {
+  if (!IsRightToLeft() && !IsLeftToRight()) {
     nsIFrame* frame = rootElement->GetPrimaryFrame();
     NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
 
     // Set the flag here, to enable us to use the same code path below.
     // It will be flipped before returning from the function.
     if (frame->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
       mFlags |= nsIPlaintextEditor::eEditorRightToLeft;
     } else {
@@ -5026,24 +5024,24 @@ EditorBase::SwitchTextDirection()
 {
   // Get the current root direction from its frame
   nsIContent* rootElement = GetExposedRoot();
 
   nsresult rv = DetermineCurrentDirection();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Apply the opposite direction
-  if (mFlags & nsIPlaintextEditor::eEditorRightToLeft) {
-    NS_ASSERTION(!(mFlags & nsIPlaintextEditor::eEditorLeftToRight),
+  if (IsRightToLeft()) {
+    NS_ASSERTION(!IsLeftToRight(),
                  "Unexpected mutually exclusive flag");
     mFlags &= ~nsIPlaintextEditor::eEditorRightToLeft;
     mFlags |= nsIPlaintextEditor::eEditorLeftToRight;
     rv = rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("ltr"), true);
-  } else if (mFlags & nsIPlaintextEditor::eEditorLeftToRight) {
-    NS_ASSERTION(!(mFlags & nsIPlaintextEditor::eEditorRightToLeft),
+  } else if (IsLeftToRight()) {
+    NS_ASSERTION(!IsRightToLeft(),
                  "Unexpected mutually exclusive flag");
     mFlags |= nsIPlaintextEditor::eEditorRightToLeft;
     mFlags &= ~nsIPlaintextEditor::eEditorLeftToRight;
     rv = rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("rtl"), true);
   }
 
   if (NS_SUCCEEDED(rv)) {
     FireInputEvent();
@@ -5058,24 +5056,24 @@ EditorBase::SwitchTextDirectionTo(uint32
   // Get the current root direction from its frame
   nsIContent* rootElement = GetExposedRoot();
 
   nsresult rv = DetermineCurrentDirection();
   NS_ENSURE_SUCCESS_VOID(rv);
 
   // Apply the requested direction
   if (aDirection == nsIPlaintextEditor::eEditorLeftToRight &&
-      (mFlags & nsIPlaintextEditor::eEditorRightToLeft)) {
+      IsRightToLeft()) {
     NS_ASSERTION(!(mFlags & nsIPlaintextEditor::eEditorLeftToRight),
                  "Unexpected mutually exclusive flag");
     mFlags &= ~nsIPlaintextEditor::eEditorRightToLeft;
     mFlags |= nsIPlaintextEditor::eEditorLeftToRight;
     rv = rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("ltr"), true);
   } else if (aDirection == nsIPlaintextEditor::eEditorRightToLeft &&
-             (mFlags & nsIPlaintextEditor::eEditorLeftToRight)) {
+             IsLeftToRight()) {
     NS_ASSERTION(!(mFlags & nsIPlaintextEditor::eEditorRightToLeft),
                  "Unexpected mutually exclusive flag");
     mFlags |= nsIPlaintextEditor::eEditorRightToLeft;
     mFlags &= ~nsIPlaintextEditor::eEditorLeftToRight;
     rv = rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("rtl"), true);
   }
 
   if (NS_SUCCEEDED(rv)) {
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -1000,52 +1000,52 @@ nsTextControlFrame::AttributeChanged(int
       } else { // unset the maxLength attribute
         textEditor->SetMaxTextLength(-1);
       }
     }
     return NS_OK;
   }
 
   if (nsGkAtoms::readonly == aAttribute) {
-    uint32_t flags;
-    textEditor->GetFlags(&flags);
     if (AttributeExists(nsGkAtoms::readonly)) { // set readonly
-      flags |= nsIPlaintextEditor::eEditorReadonlyMask;
       if (nsContentUtils::IsFocusedContent(mContent)) {
         selCon->SetCaretEnabled(false);
       }
+      textEditor->AddFlags(nsIPlaintextEditor::eEditorReadonlyMask);
     } else { // unset readonly
-      flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask);
       if (!textEditor->IsDisabled() &&
           nsContentUtils::IsFocusedContent(mContent)) {
         selCon->SetCaretEnabled(true);
       }
+      textEditor->RemoveFlags(nsIPlaintextEditor::eEditorReadonlyMask);
     }
-    textEditor->SetFlags(flags);
     return NS_OK;
   }
 
   if (nsGkAtoms::disabled == aAttribute) {
-    uint32_t flags;
-    textEditor->GetFlags(&flags);
     int16_t displaySelection = nsISelectionController::SELECTION_OFF;
     const bool focused = nsContentUtils::IsFocusedContent(mContent);
     const bool hasAttr = AttributeExists(nsGkAtoms::disabled);
+    bool disable;
     if (hasAttr) { // set disabled
-      flags |= nsIPlaintextEditor::eEditorDisabledMask;
+      disable = true;
     } else { // unset disabled
-      flags &= ~(nsIPlaintextEditor::eEditorDisabledMask);
+      disable = false;
       displaySelection = focused ? nsISelectionController::SELECTION_ON
                                  : nsISelectionController::SELECTION_HIDDEN;
     }
     selCon->SetDisplaySelection(displaySelection);
     if (focused) {
       selCon->SetCaretEnabled(!hasAttr);
     }
-    textEditor->SetFlags(flags);
+    if (disable) {
+      textEditor->AddFlags(nsIPlaintextEditor::eEditorDisabledMask);
+    } else {
+      textEditor->RemoveFlags(nsIPlaintextEditor::eEditorDisabledMask);
+    }
     return NS_OK;
   }
 
   if (!mEditorHasBeenInitialized && nsGkAtoms::value == aAttribute) {
     UpdateValueDisplay(true);
     return NS_OK;
   }