Bug 1574852 - part 4: Move `HTMLEditRules::GetInlineStyles()` to `HTMLEditor` r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 22 Aug 2019 01:10:30 +0000
changeset 489381 bfbdc9ba712ca0dd9e6b3b1d98f9eadcf1c584c0
parent 489380 152bfc05a5091be5d366580d6cbdd1e6fd54eb79
child 489382 de895ee6de420cf0296962aace1530a48cab1cc0
push id93296
push usermasayuki@d-toybox.com
push dateThu, 22 Aug 2019 03:56:02 +0000
treeherderautoland@bfbdc9ba712c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1574852
milestone70.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 1574852 - part 4: Move `HTMLEditRules::GetInlineStyles()` to `HTMLEditor` r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D42774
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
editor/libeditor/HTMLEditor.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -9116,53 +9116,53 @@ Element* HTMLEditRules::GetTopEnclosingM
 
 nsresult HTMLEditRules::CacheInlineStyles(nsINode* aNode) {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   if (NS_WARN_IF(!aNode)) {
     return NS_ERROR_INVALID_ARG;
   }
 
-  nsresult rv = GetInlineStyles(
-      aNode,
-      HTMLEditorRef().TopLevelEditSubActionDataRef().mCachedInlineStyles);
+  nsresult rv = MOZ_KnownLive(HTMLEditorRef())
+                    .GetInlineStyles(*aNode, HTMLEditorRef()
+                                                 .TopLevelEditSubActionDataRef()
+                                                 .mCachedInlineStyles);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
-nsresult HTMLEditRules::GetInlineStyles(nsINode* aNode,
-                                        AutoStyleCacheArray& aStyleCacheArray) {
-  MOZ_ASSERT(IsEditorDataAvailable());
-  MOZ_ASSERT(aNode);
-
-  bool useCSS = HTMLEditorRef().IsCSSEnabled();
+nsresult HTMLEditor::GetInlineStyles(nsINode& aNode,
+                                     AutoStyleCacheArray& aStyleCacheArray) {
+  MOZ_ASSERT(IsEditActionDataAvailable());
+
+  bool useCSS = IsCSSEnabled();
 
   for (StyleCache& styleCache : aStyleCacheArray) {
     // If type-in state is set, don't intervene
     bool typeInSet, unused;
-    HTMLEditorRef().mTypeInState->GetTypingState(
-        typeInSet, unused, styleCache.mTag, styleCache.mAttr, nullptr);
+    mTypeInState->GetTypingState(typeInSet, unused, styleCache.mTag,
+                                 styleCache.mAttr, nullptr);
     if (typeInSet) {
       continue;
     }
 
     bool isSet = false;
     nsAutoString outValue;
     // Don't use CSS for <font size>, we don't support it usefully (bug 780035)
     if (!useCSS || (styleCache.mTag == nsGkAtoms::font &&
                     styleCache.mAttr == nsGkAtoms::size)) {
-      isSet = HTMLEditorRef().IsTextPropertySetByContent(
-          aNode, styleCache.mTag, styleCache.mAttr, nullptr, &outValue);
+      isSet = IsTextPropertySetByContent(&aNode, styleCache.mTag,
+                                         styleCache.mAttr, nullptr, &outValue);
     } else {
       isSet = CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(
-          aNode, styleCache.mTag, styleCache.mAttr, outValue,
+          &aNode, styleCache.mTag, styleCache.mAttr, outValue,
           CSSEditUtils::eComputed);
-      if (NS_WARN_IF(!CanHandleEditAction())) {
+      if (NS_WARN_IF(Destroyed())) {
         return NS_ERROR_EDITOR_DESTROYED;
       }
     }
     if (isSet) {
       styleCache.mPresent = true;
       styleCache.mValue.Assign(outValue);
     }
   }
@@ -9191,17 +9191,18 @@ nsresult HTMLEditRules::ReapplyCachedSty
           ? atStartOfSelection.Container()->AsContent()
           : nullptr;
   if (!selNode) {
     // Nothing to do
     return NS_OK;
   }
 
   AutoStyleCacheArray styleCacheArrayAtInsertionPoint;
-  nsresult rv = GetInlineStyles(selNode, styleCacheArrayAtInsertionPoint);
+  nsresult rv = MOZ_KnownLive(HTMLEditorRef())
+                    .GetInlineStyles(*selNode, styleCacheArrayAtInsertionPoint);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv == NS_ERROR_EDITOR_DESTROYED ? NS_ERROR_EDITOR_DESTROYED : NS_OK;
   }
 
   for (size_t i = 0; i < styleCacheArrayAtInsertionPoint.Length(); ++i) {
     StyleCache& styleCacheAtInsertionPoint = styleCacheArrayAtInsertionPoint[i];
     StyleCache& styleCacheBeforeEdit =
         HTMLEditorRef().TopLevelEditSubActionDataRef().mCachedInlineStyles[i];
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -53,17 +53,17 @@ class Selection;
 class HTMLEditRules : public TextEditRules {
  public:
   HTMLEditRules();
 
   // TextEditRules methods
   MOZ_CAN_RUN_SCRIPT
   virtual nsresult Init(TextEditor* aTextEditor) override;
   virtual nsresult DetachEditor() override;
-  virtual nsresult BeforeEdit() override;
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual nsresult BeforeEdit() override;
   MOZ_CAN_RUN_SCRIPT virtual nsresult AfterEdit() override;
   // NOTE: Don't mark WillDoAction() nor DidDoAction() as MOZ_CAN_RUN_SCRIPT
   //       because they are too generic and doing it makes a lot of public
   //       editor methods marked as MOZ_CAN_RUN_SCRIPT too, but some of them
   //       may not causes running script.  So, ideal fix must be that we make
   //       each method callsed by this method public.
   MOZ_CAN_RUN_SCRIPT_BOUNDARY
   virtual nsresult WillDoAction(EditSubActionInfo& aInfo, bool* aCancel,
@@ -1109,24 +1109,24 @@ class HTMLEditRules : public TextEditRul
   MOZ_CAN_RUN_SCRIPT
   MOZ_MUST_USE nsresult RemoveListStructure(Element& aListElement);
 
   /**
    * CacheInlineStyles() caches style of aNode into mCachedInlineStyles of
    * TopLevelEditSubAction.  This may cause flushing layout at retrieving
    * computed value of CSS properties.
    */
-  MOZ_MUST_USE nsresult CacheInlineStyles(nsINode* aNode);
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult CacheInlineStyles(nsINode* aNode);
 
   /**
    * ReapplyCachedStyles() restores some styles which are disappeared during
    * handling edit action and it should be restored.  This may cause flushing
    * layout at retrieving computed value of CSS properties.
    */
-  MOZ_MUST_USE nsresult ReapplyCachedStyles();
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult ReapplyCachedStyles();
 
   void ClearCachedStyles();
 
   /**
    * InsertBRElementToEmptyListItemsAndTableCellsInRange() inserts
    * <br> element into empty list item or table cell elements between
    * aStartRef and aEndRef.
    */
@@ -1298,24 +1298,16 @@ class HTMLEditRules : public TextEditRul
   MOZ_MUST_USE nsresult ChangeMarginStart(Element& aElement, bool aIncrease);
 
   /**
    * DocumentModifiedWorker() is called by DocumentModified() either
    * synchronously or asynchronously.
    */
   MOZ_CAN_RUN_SCRIPT void DocumentModifiedWorker();
 
-  /**
-   * GetInlineStyles() retrieves the style of aNode and modifies each item of
-   * aStyleCacheArray.  This might cause flushing layout at retrieving computed
-   * values of CSS properties.
-   */
-  MOZ_MUST_USE nsresult GetInlineStyles(nsINode* aNode,
-                                        AutoStyleCacheArray& aStyleCacheArray);
-
  protected:
   HTMLEditor* mHTMLEditor;
   bool mInitialized;
 };
 
 }  // namespace mozilla
 
 #endif  // #ifndef HTMLEditRules_h
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -1099,16 +1099,25 @@ class HTMLEditor final : public TextEdit
   /**
    * OnModifyDocument() is called when the editor is changed.  This should
    * be called only by HTMLEditRules::DocumentModifiedWorker() to call
    * HTMLEditRules::OnModifyDocument() with AutoEditActionDataSetter
    * instance.
    */
   MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult OnModifyDocument();
 
+ protected:  // edit sub-action handler
+  /**
+   * GetInlineStyles() retrieves the style of aNode and modifies each item of
+   * aStyleCacheArray.  This might cause flushing layout at retrieving computed
+   * values of CSS properties.
+   */
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
+  GetInlineStyles(nsINode& aNode, AutoStyleCacheArray& aStyleCacheArray);
+
  protected:  // Called by helper classes.
   virtual void OnStartToHandleTopLevelEditSubAction(
       EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
   MOZ_CAN_RUN_SCRIPT
   virtual void OnEndHandlingTopLevelEditSubAction() override;
 
  protected:  // Shouldn't be used by friend classes
   virtual ~HTMLEditor();