Bug 1394583 - Remove default properties from nsIHTMLEditor. r=masayuki.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 25 Aug 2017 16:59:17 +1000
changeset 429444 5d8fdaa9efc827fa1bf532ce6c92fbb6b39b5e28
parent 429443 4f02d9b8e2ecd4f1f70fd7e9c31575c8ac16e2b5
child 429445 ad9b9c71e04bef1db50a913b154730cd16905edb
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)
reviewersmasayuki
bugs1394583
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 1394583 - Remove default properties from nsIHTMLEditor. r=masayuki. nsIHTMLEditor's addDefaultProperty(), removeDefaultProperty(), removeAllDefaultProperties() methods are never used -- not from C++ code or script, in either mozilla-central or comm-central. So this patch removes them. This means that HMLTEditor::mDefaultStyles is never used, so the patch removes it and all the code that manipulates it as well.
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
editor/libeditor/HTMLStyleEditor.cpp
editor/nsIHTMLEditor.idl
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -4549,48 +4549,16 @@ HTMLEditRules::CreateStyleForInsertText(
 {
   MOZ_ASSERT(mHTMLEditor->mTypeInState);
 
   bool weDidSomething = false;
   NS_ENSURE_STATE(aSelection.GetRangeAt(0));
   nsCOMPtr<nsINode> node = aSelection.GetRangeAt(0)->GetStartContainer();
   int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
 
-  // next examine our present style and make sure default styles are either
-  // present or explicitly overridden.  If neither, add the default style to
-  // the TypeInState
-  int32_t length = mHTMLEditor->mDefaultStyles.Length();
-  for (int32_t j = 0; j < length; j++) {
-    PropItem* propItem = mHTMLEditor->mDefaultStyles[j];
-    MOZ_ASSERT(propItem);
-    bool bFirst, bAny, bAll;
-
-    // GetInlineProperty also examine TypeInState.  The only gotcha here is
-    // that a cleared property looks like an unset property.  For now I'm
-    // assuming that's not a problem: that default styles will always be
-    // multivalue styles (like font face or size) where clearing the style
-    // means we want to go back to the default.  If we ever wanted a "toggle"
-    // style like bold for a default, though, I'll have to add code to detect
-    // the difference between unset and explicitly cleared, else user would
-    // never be able to unbold, for instance.
-    nsAutoString curValue;
-    NS_ENSURE_STATE(mHTMLEditor);
-    nsresult rv =
-      mHTMLEditor->GetInlinePropertyBase(*propItem->tag, &propItem->attr,
-                                         nullptr, &bFirst, &bAny, &bAll,
-                                         &curValue, false);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (!bAny) {
-      // no style set for this prop/attr
-      mHTMLEditor->mTypeInState->SetProp(propItem->tag, propItem->attr,
-                                         propItem->value);
-    }
-  }
-
   nsCOMPtr<Element> rootElement = aDoc.GetRootElement();
   NS_ENSURE_STATE(rootElement);
 
   // process clearing any styles first
   UniquePtr<PropItem> item =
     Move(mHTMLEditor->mTypeInState->TakeClearProperty());
   while (item && node != rootElement) {
     NS_ENSURE_STATE(mHTMLEditor);
@@ -7336,17 +7304,17 @@ HTMLEditRules::ReapplyCachedStyles()
       if (!bAny) {
         // then check typeinstate and html style
         NS_ENSURE_STATE(mHTMLEditor);
         nsresult rv =
           mHTMLEditor->GetInlinePropertyBase(*mCachedStyles[i].tag,
                                              &(mCachedStyles[i].attr),
                                              &(mCachedStyles[i].value),
                                              &bFirst, &bAny, &bAll,
-                                             &curValue, false);
+                                             &curValue);
         NS_ENSURE_SUCCESS(rv, rv);
       }
       // This style has disappeared through deletion.  Let's add the styles to
       // mTypeInState when same style isn't applied to the node already.
       if ((!bAny || IsStyleCachePreservingAction(mTheAction)) &&
            (!styleAtInsertionPoint[i].mPresent ||
             styleAtInsertionPoint[i].value != mCachedStyles[i].value)) {
         NS_ENSURE_STATE(mHTMLEditor);
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -157,19 +157,16 @@ HTMLEditor::~HTMLEditor()
     if (listener) {
       selection->RemoveSelectionListener(listener);
     }
   }
 
   mTypeInState = nullptr;
   mSelectionListenerP = nullptr;
 
-  // free any default style propItems
-  RemoveAllDefaultProperties();
-
   if (mLinkHandler && IsInitialized()) {
     nsCOMPtr<nsIPresShell> ps = GetPresShell();
 
     if (ps && ps->GetPresContext()) {
       ps->GetPresContext()->SetLinkHandler(mLinkHandler);
     }
   }
 
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -224,22 +224,16 @@ public:
   }
   nsresult GetAbsolutelyPositionedSelectionContainer(nsINode** aContainer);
   Element* GetPositionedElement() const
   {
     return mAbsolutelyPositionedObject;
   }
   nsresult GetElementZIndex(Element* aElement, int32_t* aZindex);
 
-  nsresult AddDefaultProperty(nsIAtom* aProperty,
-                              const nsAString& aAttribute,
-                              const nsAString& aValue);
-  nsresult RemoveDefaultProperty(nsIAtom* aProperty,
-                                 const nsAString& aAttribute,
-                                 const nsAString& aValue);
   nsresult SetInlineProperty(nsIAtom* aProperty,
                              const nsAString& aAttribute,
                              const nsAString& aValue);
   nsresult GetInlineProperty(nsIAtom* aProperty,
                              const nsAString& aAttribute,
                              const nsAString& aValue,
                              bool* aFirst,
                              bool* aAny,
@@ -754,17 +748,16 @@ protected:
   nsresult SplitStyleAboveRange(nsRange* aRange,
                                 nsIAtom* aProperty,
                                 const nsAString* aAttribute);
   nsresult SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
                                 nsIAtom* aProperty,
                                 const nsAString* aAttribute,
                                 nsIContent** aOutLeftNode = nullptr,
                                 nsIContent** aOutRightNode = nullptr);
-  nsresult ApplyDefaultProperties();
   nsresult RemoveStyleInside(nsIContent& aNode,
                              nsIAtom* aProperty,
                              const nsAString* aAttribute,
                              const bool aChildrenOnly = false);
   nsresult RemoveInlinePropertyImpl(nsIAtom* aProperty,
                                     const nsAString* aAttribute);
 
   bool NodeIsProperty(nsINode& aNode);
@@ -815,18 +808,17 @@ protected:
   nsIContent* GetLastEditableLeaf(nsINode& aNode);
 
   nsresult GetInlinePropertyBase(nsIAtom& aProperty,
                                  const nsAString* aAttribute,
                                  const nsAString* aValue,
                                  bool* aFirst,
                                  bool* aAny,
                                  bool* aAll,
-                                 nsAString* outValue,
-                                 bool aCheckDefaults = true);
+                                 nsAString* outValue);
   bool HasStyleOrIdOrClass(Element* aElement);
   nsresult RemoveElementIfNoStyleOrIdOrClass(Element& aElement);
 
   /**
    * Whether the outer window of the DOM event target has focus or not.
    */
   bool OurWindowHasFocus();
 
@@ -897,19 +889,16 @@ protected:
 
   nsString mLastStyleSheetURL;
   nsString mLastOverrideStyleSheetURL;
 
   // Maintain a list of associated style sheets and their urls.
   nsTArray<nsString> mStyleSheetURLs;
   nsTArray<RefPtr<StyleSheet>> mStyleSheets;
 
-  // an array for holding default style settings
-  nsTArray<PropItem*> mDefaultStyles;
-
 protected:
   // ANONYMOUS UTILS
   void RemoveListenerAndDeleteRef(const nsAString& aEvent,
                                   nsIDOMEventListener* aListener,
                                   bool aUseCapture,
                                   ManualNACPtr aElement,
                                   nsIPresShell* aShell);
   void DeleteRefToAnonymousNode(ManualNACPtr aContent,
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -50,80 +50,16 @@ IsEmptyTextNode(HTMLEditor* aThis, nsINo
 {
   bool isEmptyTextNode = false;
   return EditorBase::IsTextNode(aNode) &&
          NS_SUCCEEDED(aThis->IsEmptyNode(aNode, &isEmptyTextNode)) &&
          isEmptyTextNode;
 }
 
 NS_IMETHODIMP
-HTMLEditor::AddDefaultProperty(const nsAString& aProperty,
-                               const nsAString& aAttribute,
-                               const nsAString& aValue)
-{
-  return AddDefaultProperty(NS_Atomize(aProperty).take(), aAttribute, aValue);
-}
-
-nsresult
-HTMLEditor::AddDefaultProperty(nsIAtom* aProperty,
-                               const nsAString& aAttribute,
-                               const nsAString& aValue)
-{
-  nsString outValue;
-  int32_t index;
-  nsString attr(aAttribute);
-  if (TypeInState::FindPropInList(aProperty, attr, &outValue,
-                                  mDefaultStyles, index)) {
-    PropItem *item = mDefaultStyles[index];
-    item->value = aValue;
-  } else {
-    nsString value(aValue);
-    PropItem *propItem = new PropItem(aProperty, attr, value);
-    mDefaultStyles.AppendElement(propItem);
-  }
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-HTMLEditor::RemoveDefaultProperty(const nsAString& aProperty,
-                                  const nsAString& aAttribute,
-                                  const nsAString& aValue)
-{
-  return RemoveDefaultProperty(NS_Atomize(aProperty).take(), aAttribute,
-                               aValue);
-}
-
-nsresult
-HTMLEditor::RemoveDefaultProperty(nsIAtom* aProperty,
-                                  const nsAString& aAttribute,
-                                  const nsAString& aValue)
-{
-  nsString outValue;
-  int32_t index;
-  nsString attr(aAttribute);
-  if (TypeInState::FindPropInList(aProperty, attr, &outValue,
-                                  mDefaultStyles, index)) {
-    delete mDefaultStyles[index];
-    mDefaultStyles.RemoveElementAt(index);
-  }
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-HTMLEditor::RemoveAllDefaultProperties()
-{
-  size_t defcon = mDefaultStyles.Length();
-  for (size_t j = 0; j < defcon; j++) {
-    delete mDefaultStyles[j];
-  }
-  mDefaultStyles.Clear();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 HTMLEditor::SetInlineProperty(const nsAString& aProperty,
                               const nsAString& aAttribute,
                               const nsAString& aValue)
 {
   return SetInlineProperty(NS_Atomize(aProperty).take(), aAttribute, aValue);
 }
 
 nsresult
@@ -711,30 +647,16 @@ HTMLEditor::ClearStyle(nsCOMPtr<nsINode>
 bool
 HTMLEditor::NodeIsProperty(nsINode& aNode)
 {
   return IsContainer(&aNode) && IsEditable(&aNode) && !IsBlockNode(&aNode) &&
          !aNode.IsHTMLElement(nsGkAtoms::a);
 }
 
 nsresult
-HTMLEditor::ApplyDefaultProperties()
-{
-  size_t defcon = mDefaultStyles.Length();
-  for (size_t j = 0; j < defcon; j++) {
-    PropItem *propItem = mDefaultStyles[j];
-    NS_ENSURE_TRUE(propItem, NS_ERROR_NULL_POINTER);
-    nsresult rv =
-      SetInlineProperty(propItem->tag, propItem->attr, propItem->value);
-    NS_ENSURE_SUCCESS(rv, rv);
-  }
-  return NS_OK;
-}
-
-nsresult
 HTMLEditor::RemoveStyleInside(nsIContent& aNode,
                               nsIAtom* aProperty,
                               const nsAString* aAttribute,
                               const bool aChildrenOnly /* = false */)
 {
   if (aNode.GetAsText()) {
     return NS_OK;
   }
@@ -992,18 +914,17 @@ HTMLEditor::IsAtEndOfNode(nsINode& aNode
 
 nsresult
 HTMLEditor::GetInlinePropertyBase(nsIAtom& aProperty,
                                   const nsAString* aAttribute,
                                   const nsAString* aValue,
                                   bool* aFirst,
                                   bool* aAny,
                                   bool* aAll,
-                                  nsAString* outValue,
-                                  bool aCheckDefaults)
+                                  nsAString* outValue)
 {
   *aAny = false;
   *aAll = true;
   *aFirst = false;
   bool first = true;
 
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
@@ -1048,31 +969,16 @@ HTMLEditor::GetInlinePropertyBase(nsIAto
           outValue->Assign(tOutString);
         }
         return NS_OK;
       }
 
       isSet = IsTextPropertySetByContent(collapsedNode, &aProperty,
                                          aAttribute, aValue, outValue);
       *aFirst = *aAny = *aAll = isSet;
-
-      if (!isSet && aCheckDefaults) {
-        // Style not set, but if it is a default then it will appear if content
-        // is inserted, so we should report it as set (analogous to
-        // TypeInState).
-        int32_t index;
-        if (aAttribute && TypeInState::FindPropInList(&aProperty, *aAttribute,
-                                                      outValue, mDefaultStyles,
-                                                      index)) {
-          *aFirst = *aAny = *aAll = true;
-          if (outValue) {
-            outValue->Assign(mDefaultStyles[index]->value);
-          }
-        }
-      }
       return NS_OK;
     }
 
     // Non-collapsed selection
     nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
 
     nsAutoString firstValue, theValue;
 
@@ -1231,17 +1137,17 @@ NS_IMETHODIMP
 HTMLEditor::RemoveAllInlineProperties()
 {
   AutoPlaceholderBatch batchIt(this);
   AutoRules beginRulesSniffing(this, EditAction::resetTextProperties,
                                nsIEditor::eNext);
 
   nsresult rv = RemoveInlinePropertyImpl(nullptr, nullptr);
   NS_ENSURE_SUCCESS(rv, rv);
-  return ApplyDefaultProperties();
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::RemoveInlineProperty(const nsAString& aProperty,
                                  const nsAString& aAttribute)
 {
   return RemoveInlineProperty(NS_Atomize(aProperty).take(), aAttribute);
 }
--- a/editor/nsIHTMLEditor.idl
+++ b/editor/nsIHTMLEditor.idl
@@ -32,53 +32,16 @@ interface nsIHTMLEditor : nsISupports
   const short eLeft = 0;
   const short eCenter = 1;
   const short eRight = 2;
   const short eJustify = 3;
 
 
   /* ------------ Inline property methods -------------- */
 
-
-  /**
-   * AddDefaultProperty() registers a default style property with the editor
-   *
-   * @param aProperty   the property to set by default
-   * @param aAttribute  the attribute of the property, if applicable.
-   *                    May be null.
-   *                    Example: aProperty="font", aAttribute="color"
-   * @param aValue      if aAttribute is not null, the value of the attribute.
-   *                    Example: aProperty="font", aAttribute="color",
-   *                             aValue="0x00FFFF"
-   */
-  void addDefaultProperty(in AString aProperty,
-                          in AString aAttribute,
-                          in AString aValue);
-
-  /**
-   * RemoveDefaultProperty() unregisters a default style property with the editor
-   *
-   * @param aProperty   the property to remove from defaults
-   * @param aAttribute  the attribute of the property, if applicable.
-   *                    May be null.
-   *                    Example: aProperty="font", aAttribute="color"
-   * @param aValue      if aAttribute is not null, the value of the attribute.
-   *                    Example: aProperty="font", aAttribute="color",
-   *                             aValue="0x00FFFF"
-   */
-  void removeDefaultProperty(in AString aProperty,
-                             in AString aAttribute,
-                             in AString aValue);
-
-  /**
-   * RemoveAllDefaultProperties() unregisters all default style properties with the editor
-   *
-   */
-  void removeAllDefaultProperties();
-
   /**
    * SetInlineProperty() sets the aggregate properties on the current selection
    *
    * @param aProperty   the property to set on the selection
    * @param aAttribute  the attribute of the property, if applicable.
    *                    May be null.
    *                    Example: aProperty="font", aAttribute="color"
    * @param aValue      if aAttribute is not null, the value of the attribute.