Bug 1485925 - part 1: Create HTMLEditor::HideResizersInternal() for internal use r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 06 Sep 2018 05:02:46 +0000
changeset 490768 e8bab0bb121e3cbf089dfabfd2f87ca67d237d22
parent 490767 90ccd18ef84ba275143de2c65d45cd9a820fb66c
child 490769 eaeb3044541381a90d22a90974923f6e0ab27fc4
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1485925
milestone64.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 1485925 - part 1: Create HTMLEditor::HideResizersInternal() for internal use r=m_kato HTMLEditor::HideResizers() is an XPCOM method, so, we should create non-virtual method for internal use. Differential Revision: https://phabricator.services.mozilla.com/D4923
editor/libeditor/HTMLAnonymousNodeEditor.cpp
editor/libeditor/HTMLEditor.h
editor/libeditor/HTMLEditorObjectResizer.cpp
editor/libeditor/HTMLInlineTableEditor.cpp
editor/nsIHTMLObjectResizer.idl
--- a/editor/libeditor/HTMLAnonymousNodeEditor.cpp
+++ b/editor/libeditor/HTMLAnonymousNodeEditor.cpp
@@ -289,19 +289,19 @@ HTMLEditor::HideAnonymousEditingUIs()
     HideGrabber();
     NS_ASSERTION(!mAbsolutelyPositionedObject, "HideGrabber failed");
   }
   if (mInlineEditedCell) {
     HideInlineTableEditingUI();
     NS_ASSERTION(!mInlineEditedCell, "HideInlineTableEditingUI failed");
   }
   if (mResizedObject) {
-    DebugOnly<nsresult> rv = HideResizers();
-    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HideResizers() failed");
-    NS_ASSERTION(!mResizedObject, "HideResizers failed");
+    DebugOnly<nsresult> rv = HideResizersInternal();
+    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HideResizersInternal() failed");
+    NS_ASSERTION(!mResizedObject, "HideResizersInternal() failed");
   }
 }
 
 void
 HTMLEditor::HideAnonymousEditingUIsIfUnnecessary()
 {
   // XXX Perhaps, this is wrong approach to hide multiple UIs because
   //     hiding one UI may causes overwriting existing UI with newly
@@ -316,19 +316,19 @@ HTMLEditor::HideAnonymousEditingUIsIfUnn
     // XXX If we're resizing a table element, we need to cancel or commit the
     //     operation now.
     HideInlineTableEditingUI();
     NS_ASSERTION(!mInlineEditedCell, "HideInlineTableEditingUI failed");
   }
   if (!IsObjectResizerEnabled() && mResizedObject) {
     // XXX If we're resizing something, we need to cancel or commit the
     //     operation now.
-    DebugOnly<nsresult> rv = HideResizers();
-    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HideResizers() failed");
-    NS_ASSERTION(!mResizedObject, "HideResizers failed");
+    DebugOnly<nsresult> rv = HideResizersInternal();
+    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HideResizersInternal() failed");
+    NS_ASSERTION(!mResizedObject, "HideResizersInternal() failed");
   }
 }
 
 NS_IMETHODIMP
 HTMLEditor::CheckSelectionStateForAnonymousButtons(Selection* aSelection)
 {
   if (NS_WARN_IF(!aSelection)) {
     return NS_ERROR_INVALID_ARG;
@@ -421,24 +421,24 @@ HTMLEditor::RefereshEditingUI(Selection&
   if (IsAbsolutePositionEditorEnabled() && mAbsolutelyPositionedObject &&
       absPosElement != mAbsolutelyPositionedObject) {
     HideGrabber();
     NS_ASSERTION(!mAbsolutelyPositionedObject, "HideGrabber failed");
   }
 
   if (IsObjectResizerEnabled() && mResizedObject &&
       mResizedObject != focusElement) {
-    // Perhaps, even if HideResizers() failed, we should try to hide inline
-    // table editing UI.  However, it returns error only when we cannot do
-    // anything.  So, it's okay for now.
-    nsresult rv = HideResizers();
+    // Perhaps, even if HideResizersInternal() failed, we should try to hide
+    // inline table editing UI.  However, it returns error only when we cannot
+    // do anything.  So, it's okay for now.
+    nsresult rv = HideResizersInternal();
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
-    NS_ASSERTION(!mResizedObject, "HideResizers failed");
+    NS_ASSERTION(!mResizedObject, "HideResizersInternal() failed");
   }
 
   if (IsInlineTableEditorEnabled() && mInlineEditedCell &&
       mInlineEditedCell != cellElement) {
     // XXX HideInlineTableEditingUI() won't return error.  Should be change it
     //     void later.
     HideInlineTableEditingUI();
     NS_ASSERTION(!mInlineEditedCell, "HideInlineTableEditingUI failed");
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -1799,16 +1799,22 @@ protected: // Shouldn't be used by frien
   nsresult SetAllResizersPosition();
 
   /**
    * Shows active resizers around an element's frame
    * @param aResizedElement [IN] a DOM Element
    */
   nsresult ShowResizersInternal(Element& aResizedElement);
 
+  /**
+   * Hide resizers if they are visible.  If this is called while there is no
+   * visible resizers, this does not return error, but does nothing.
+   */
+  nsresult HideResizersInternal();
+
   ManualNACPtr CreateResizer(int16_t aLocation, nsIContent& aParentContent);
   void SetAnonymousElementPosition(int32_t aX, int32_t aY,
                                    Element* aResizer);
 
   ManualNACPtr CreateShadow(nsIContent& aParentContent,
                             Element& aOriginalObject);
   nsresult SetShadowPosition(Element* aShadow, Element* aOriginalObject,
                              int32_t aOriginalObjectX,
--- a/editor/libeditor/HTMLEditorObjectResizer.cpp
+++ b/editor/libeditor/HTMLEditorObjectResizer.cpp
@@ -236,17 +236,17 @@ HTMLEditor::RefreshResizers()
   return SetShadowPosition(mResizingShadow, mResizedObject,
                            mResizedObjectX, mResizedObjectY);
 }
 
 nsresult
 HTMLEditor::ShowResizersInternal(Element& aResizedElement)
 {
   // When we have visible resizers, we cannot show new resizers.
-  // So, the caller should call HideResizers() first.
+  // So, the caller should call HideResizersInternal() first.
   if (NS_WARN_IF(mResizedObject)) {
     return NS_ERROR_UNEXPECTED;
   }
 
   nsCOMPtr<nsIContent> parentContent = aResizedElement.GetParent();
   if (NS_WARN_IF(!parentContent)) {
     return NS_ERROR_FAILURE;
   }
@@ -364,25 +364,35 @@ HTMLEditor::ShowResizersInternal(Element
 
     // XXX Even when it failed to add event listener, should we need to set
     //     _moz_resizing attribute?
     aResizedElement.SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_resizing,
                             NS_LITERAL_STRING("true"), true);
     return NS_OK;
   } while (true);
 
-  DebugOnly<nsresult> rv = HideResizers();
+  DebugOnly<nsresult> rv = HideResizersInternal();
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                        "Failed to clean up unnecessary resizers");
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 HTMLEditor::HideResizers()
 {
+  nsresult rv = HideResizersInternal();
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+  return NS_OK;
+}
+
+nsresult
+HTMLEditor::HideResizersInternal()
+{
   if (NS_WARN_IF(!mResizedObject)) {
     return NS_OK;
   }
 
   // get the presshell's document observer interface.
   nsCOMPtr<nsIPresShell> presShell = GetPresShell();
   NS_WARNING_ASSERTION(presShell, "There is no presShell");
   // We allow the pres shell to be null; when it is, we presume there
@@ -463,30 +473,30 @@ HTMLEditor::HideResizers()
 
   // Remove resize event listener from the window.
   if (!resizeEventListener) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIDocument> doc = GetDocument();
   if (NS_WARN_IF(!doc)) {
-    return NS_ERROR_NULL_POINTER;
+    return NS_ERROR_FAILURE;
   }
 
   // nsIDocument::GetWindow() may return nullptr when HTMLEditor is destroyed
   // while the document is being unloaded.  If we cannot retrieve window as
   // expected, let's ignore it.
   nsPIDOMWindowOuter* window = doc->GetWindow();
   if (NS_WARN_IF(!window)) {
     return NS_OK;
   }
 
   nsCOMPtr<EventTarget> targetOfWindow = do_QueryInterface(window);
   if (NS_WARN_IF(!targetOfWindow)) {
-    return NS_ERROR_NULL_POINTER;
+    return NS_ERROR_FAILURE;
   }
   targetOfWindow->RemoveEventListener(NS_LITERAL_STRING("resize"),
                                       resizeEventListener, false);
 
   return NS_OK;
 }
 
 void
--- a/editor/libeditor/HTMLInlineTableEditor.cpp
+++ b/editor/libeditor/HTMLInlineTableEditor.cpp
@@ -176,17 +176,18 @@ HTMLEditor::DoInlineTableEditingAction(c
   // InsertTableRow might causes reframe
   if (Destroyed()) {
     return NS_OK;
   }
 
   if (hideUI) {
     HideInlineTableEditingUI();
     if (hideResizersWithInlineTableUI) {
-      HideResizers();
+      DebugOnly<nsresult> rv = HideResizersInternal();
+      NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to hide resizers");
     }
   }
 
   return NS_OK;
 }
 
 void
 HTMLEditor::AddMouseClickListener(Element* aElement)
--- a/editor/nsIHTMLObjectResizer.idl
+++ b/editor/nsIHTMLObjectResizer.idl
@@ -29,17 +29,18 @@ interface nsIHTMLObjectResizer : nsISupp
   readonly attribute Element resizedObject;
 
   /**
    * a boolean indicating if object resizing is enabled in the editor
    */
   attribute boolean objectResizingEnabled;
 
   /**
-   * Hide resizers if they are visible
+   * Hide resizers if they are visible.  If this is called while there is no
+   * visible resizers, this does not throw exception, just does nothing.
    */
   void hideResizers();
 
   /**
    * Refresh visible resizers
    */
   void refreshResizers();
 };