Bug 1336349 - Merge GetIsDocumentEditable implementation to EditorBase. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 03 Feb 2017 16:22:50 +0900
changeset 340874 448a2d9d62c2951f6da51cd9ff5aa96ac88c67e8
parent 340873 21f71652e49132a779ceccba50f92765a38154c1
child 340875 3504f8cdd850178af9a2f2a5a1361a8e347a87e6
push id36938
push userm_kato@ga2.so-net.ne.jp
push dateMon, 06 Feb 2017 05:00:05 +0000
treeherderautoland@448a2d9d62c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1336349
milestone54.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 1336349 - Merge GetIsDocumentEditable implementation to EditorBase. r=masayuki GetIsDocumentEditable is implemnted in EditorBase, TextEditor, and HTMLEditor. This is virtual method, we won't use EditorBase::GetIsDocumentEditable. Also, TextEditor::GetIsDocumentEditable and HTMLEditor::GetIsDocumentEditable are same implementation. So we should merge this to EditorBase. MozReview-Commit-ID: 62euqUaYAuY
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
editor/libeditor/TextEditor.cpp
editor/libeditor/TextEditor.h
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -540,17 +540,17 @@ EditorBase::GetIsSelectionEditable(bool*
   return NS_OK;
 }
 
 NS_IMETHODIMP
 EditorBase::GetIsDocumentEditable(bool* aIsDocumentEditable)
 {
   NS_ENSURE_ARG_POINTER(aIsDocumentEditable);
   nsCOMPtr<nsIDocument> doc = GetDocument();
-  *aIsDocumentEditable = !!doc;
+  *aIsDocumentEditable = doc && IsModifiable();
 
   return NS_OK;
 }
 
 already_AddRefed<nsIDocument>
 EditorBase::GetDocument()
 {
   NS_PRECONDITION(mDocWeak, "bad state, mDocWeak weak pointer not initialized");
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -852,16 +852,21 @@ public:
            IsInteractionAllowed();
   }
 
   bool HasIndependentSelection() const
   {
     return !!mSelConWeak;
   }
 
+  bool IsModifiable() const
+  {
+    return !IsReadonly();
+  }
+
   /**
    * Get the input event target. This might return null.
    */
   virtual already_AddRefed<nsIContent> GetInputEventTargetContent() = 0;
 
   /**
    * Get the focused content, if we're focused.  Returns null otherwise.
    */
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -969,33 +969,16 @@ HTMLEditor::IsVisBreak(nsINode* aNode)
   if (visType & WSType::block) {
     return false;
   }
 
   return true;
 }
 
 NS_IMETHODIMP
-HTMLEditor::GetIsDocumentEditable(bool* aIsDocumentEditable)
-{
-  NS_ENSURE_ARG_POINTER(aIsDocumentEditable);
-
-  nsCOMPtr<nsIDOMDocument> doc = GetDOMDocument();
-  *aIsDocumentEditable = doc && IsModifiable();
-
-  return NS_OK;
-}
-
-bool
-HTMLEditor::IsModifiable()
-{
-  return !IsReadonly();
-}
-
-NS_IMETHODIMP
 HTMLEditor::UpdateBaseURL()
 {
   nsCOMPtr<nsIDocument> doc = GetDocument();
   NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
   // Look for an HTML <base> tag
   RefPtr<nsContentList> nodeList =
     doc->GetElementsByTagName(NS_LITERAL_STRING("base"));
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -102,17 +102,16 @@ public:
 
   bool GetReturnInParagraphCreatesNewParagraph();
   Element* GetSelectionContainer();
 
   // nsIEditor overrides
   NS_IMETHOD GetPreferredIMEState(widget::IMEState* aState) override;
 
   // TextEditor overrides
-  NS_IMETHOD GetIsDocumentEditable(bool* aIsDocumentEditable) override;
   NS_IMETHOD BeginningOfDocument() override;
   virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent) override;
   virtual already_AddRefed<nsIContent> GetFocusedContent() override;
   virtual already_AddRefed<nsIContent> GetFocusedContentForIME() override;
   virtual bool IsActiveInDOMWindow() override;
   virtual already_AddRefed<dom::EventTarget> GetDOMEventTarget() override;
   virtual Element* GetEditorRoot() override;
   virtual already_AddRefed<nsIContent> FindSelectionRoot(
@@ -666,21 +665,16 @@ protected:
    * Utility routine to possibly adjust the insertion position when
    * inserting a block level element.
    */
   void NormalizeEOLInsertPosition(nsINode* firstNodeToInsert,
                                   nsCOMPtr<nsIDOMNode>* insertParentNode,
                                   int32_t* insertOffset);
 
   /**
-   * Small utility routine to test the eEditorReadonly bit.
-   */
-  bool IsModifiable();
-
-  /**
    * Helpers for block transformations.
    */
   nsresult MakeDefinitionItem(const nsAString& aItemType);
   nsresult InsertBasicBlock(const nsAString& aBlockType);
 
   /**
    * Increase/decrease the font size of selection.
    */
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -324,34 +324,16 @@ TextEditor::InitRules()
 {
   if (!mRules) {
     // instantiate the rules for this text editor
     mRules = new TextEditRules();
   }
   return mRules->Init(this);
 }
 
-
-NS_IMETHODIMP
-TextEditor::GetIsDocumentEditable(bool* aIsDocumentEditable)
-{
-  NS_ENSURE_ARG_POINTER(aIsDocumentEditable);
-
-  nsCOMPtr<nsIDOMDocument> doc = GetDOMDocument();
-  *aIsDocumentEditable = doc && IsModifiable();
-
-  return NS_OK;
-}
-
-bool
-TextEditor::IsModifiable()
-{
-  return !IsReadonly();
-}
-
 nsresult
 TextEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
 {
   // NOTE: When you change this method, you should also change:
   //   * editor/libeditor/tests/test_texteditor_keyevent_handling.html
   //   * editor/libeditor/tests/test_htmleditor_keyevent_handling.html
   //
   // And also when you add new key handling, you need to change the subclass's
--- a/editor/libeditor/TextEditor.h
+++ b/editor/libeditor/TextEditor.h
@@ -75,17 +75,16 @@ public:
   using EditorBase::RemoveAttributeOrEquivalent;
   using EditorBase::SetAttributeOrEquivalent;
 
   NS_IMETHOD Init(nsIDOMDocument* aDoc, nsIContent* aRoot,
                   nsISelectionController* aSelCon, uint32_t aFlags,
                   const nsAString& aValue) override;
 
   NS_IMETHOD GetDocumentIsEmpty(bool* aDocumentIsEmpty) override;
-  NS_IMETHOD GetIsDocumentEditable(bool* aIsDocumentEditable) override;
 
   NS_IMETHOD DeleteSelection(EDirection aAction,
                              EStripWrappers aStripWrappers) override;
 
   NS_IMETHOD SetDocumentCharacterSet(const nsACString& characterSet) override;
 
   NS_IMETHOD Undo(uint32_t aCount) override;
   NS_IMETHOD Redo(uint32_t aCount) override;
@@ -208,21 +207,16 @@ protected:
 
   /**
    * Shared outputstring; returns whether selection is collapsed and resulting
    * string.
    */
   nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed,
                               nsAString& aResult);
 
-  /**
-   * Small utility routine to test the eEditorReadonly bit.
-   */
-  bool IsModifiable();
-
   enum PasswordFieldAllowed
   {
     ePasswordFieldAllowed,
     ePasswordFieldNotAllowed
   };
   bool CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed);
   bool FireClipboardEvent(EventMessage aEventMessage,
                           int32_t aSelectionType,