Bug 1388006 - a11y module should use TextEditor and HTMLEditor instead of nsIEditor r?surkov draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 07 Aug 2017 17:42:50 +0900
changeset 646317 3c2f1fa98367f95e951916a935890b5f2723ae0f
parent 646265 b95b1638db48fc3d450b95b98da6bcd2f9326d2f
child 646319 ed9e14879c16bd88798112749b9c9b54b56be24a
push id74068
push usermasayuki@d-toybox.com
push dateTue, 15 Aug 2017 03:59:07 +0000
reviewerssurkov
bugs1388006
milestone57.0a1
Bug 1388006 - a11y module should use TextEditor and HTMLEditor instead of nsIEditor r?surkov Accessibility module uses nsIEditor (and nsIPlaintextEditor). However, now, it can use TextEditor and HTMLEditor. So, it should use them. Note that this patch makes HTMLTextFieldAccessible::GetEditor() use nsITextControlElement::GetTextEditor() instead of nsIDOMNSEditableElement::GetEditor() but this won't change actual behavior since both implementation of HTMLInputElement and HTMLTextareaElement are just call shared internal methods. MozReview-Commit-ID: HxHMGVSvWFv
accessible/generic/DocAccessible.cpp
accessible/generic/DocAccessible.h
accessible/generic/HyperTextAccessible-inl.h
accessible/generic/HyperTextAccessible.cpp
accessible/generic/HyperTextAccessible.h
accessible/html/HTMLFormControlAccessible.cpp
accessible/html/HTMLFormControlAccessible.h
--- a/accessible/generic/DocAccessible.cpp
+++ b/accessible/generic/DocAccessible.cpp
@@ -41,16 +41,18 @@
 #include "nsIScrollableFrame.h"
 #include "nsUnicharUtils.h"
 #include "nsIURI.h"
 #include "nsIWebNavigation.h"
 #include "nsFocusManager.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/EventStates.h"
+#include "mozilla/HTMLEditor.h"
+#include "mozilla/TextEditor.h"
 #include "mozilla/dom/TabChild.h"
 #include "mozilla/dom/DocumentType.h"
 #include "mozilla/dom/Element.h"
 
 #ifdef MOZ_XUL
 #include "nsIXULDocument.h"
 #endif
 
@@ -261,18 +263,18 @@ DocAccessible::NativeState()
     state |= states::BUSY;
 
   nsIFrame* frame = GetFrame();
   if (!frame ||
       !frame->IsVisibleConsideringAncestors(nsIFrame::VISIBILITY_CROSS_CHROME_CONTENT_BOUNDARY)) {
     state |= states::INVISIBLE | states::OFFSCREEN;
   }
 
-  nsCOMPtr<nsIEditor> editor = GetEditor();
-  state |= editor ? states::EDITABLE : states::READONLY;
+  RefPtr<TextEditor> textEditor = GetEditor();
+  state |= textEditor ? states::EDITABLE : states::READONLY;
 
   return state;
 }
 
 uint64_t
 DocAccessible::NativeInteractiveState() const
 {
   // Document is always focusable.
@@ -332,17 +334,17 @@ DocAccessible::TakeFocus()
   // Focus the document.
   nsFocusManager* fm = nsFocusManager::GetFocusManager();
   nsCOMPtr<nsIDOMElement> newFocus;
   fm->MoveFocus(mDocumentNode->GetWindow(), nullptr,
                 nsFocusManager::MOVEFOCUS_ROOT, 0, getter_AddRefs(newFocus));
 }
 
 // HyperTextAccessible method
-already_AddRefed<nsIEditor>
+already_AddRefed<TextEditor>
 DocAccessible::GetEditor() const
 {
   // Check if document is editable (designMode="on" case). Otherwise check if
   // the html:body (for HTML document case) or document element is editable.
   if (!mDocumentNode->HasFlag(NODE_IS_EDITABLE) &&
       (!mContent || !mContent->HasFlag(NODE_IS_EDITABLE)))
     return nullptr;
 
@@ -351,25 +353,27 @@ DocAccessible::GetEditor() const
     return nullptr;
   }
 
   nsCOMPtr<nsIEditingSession> editingSession;
   docShell->GetEditingSession(getter_AddRefs(editingSession));
   if (!editingSession)
     return nullptr; // No editing session interface
 
-  nsCOMPtr<nsIEditor> editor;
-  editingSession->GetEditorForWindow(mDocumentNode->GetWindow(), getter_AddRefs(editor));
-  if (!editor)
+  RefPtr<HTMLEditor> htmlEditor =
+    editingSession->GetHTMLEditorForWindow(mDocumentNode->GetWindow());
+  if (!htmlEditor) {
     return nullptr;
+  }
 
   bool isEditable = false;
-  editor->GetIsDocumentEditable(&isEditable);
-  if (isEditable)
-    return editor.forget();
+  htmlEditor->GetIsDocumentEditable(&isEditable);
+  if (isEditable) {
+    return htmlEditor.forget();
+  }
 
   return nullptr;
 }
 
 // DocAccessible public method
 
 void
 DocAccessible::URL(nsAString& aURL) const
--- a/accessible/generic/DocAccessible.h
+++ b/accessible/generic/DocAccessible.h
@@ -11,27 +11,29 @@
 #include "HyperTextAccessibleWrap.h"
 #include "AccEvent.h"
 
 #include "nsAutoPtr.h"
 #include "nsClassHashtable.h"
 #include "nsDataHashtable.h"
 #include "nsIDocument.h"
 #include "nsIDocumentObserver.h"
-#include "nsIEditor.h"
 #include "nsIObserver.h"
 #include "nsIScrollPositionListener.h"
 #include "nsITimer.h"
 #include "nsIWeakReference.h"
 
 class nsAccessiblePivot;
 
 const uint32_t kDefaultCacheLength = 128;
 
 namespace mozilla {
+
+class TextEditor;
+
 namespace a11y {
 
 class DocManager;
 class NotificationController;
 class DocAccessibleChild;
 class RelatedAccIterator;
 template<class Class, class ... Args>
 class TNotification;
@@ -81,17 +83,17 @@ public:
 
 #ifdef A11Y_LOG
   virtual nsresult HandleAccEvent(AccEvent* aEvent) override;
 #endif
 
   virtual nsRect RelativeBounds(nsIFrame** aRelativeFrame) const override;
 
   // HyperTextAccessible
-  virtual already_AddRefed<nsIEditor> GetEditor() const override;
+  virtual already_AddRefed<TextEditor> GetEditor() const override;
 
   // DocAccessible
 
   /**
    * Return document URL.
    */
   void URL(nsAString& aURL) const;
 
--- a/accessible/generic/HyperTextAccessible-inl.h
+++ b/accessible/generic/HyperTextAccessible-inl.h
@@ -8,19 +8,20 @@
 
 #include "HyperTextAccessible.h"
 
 #include "nsAccUtils.h"
 
 #include "nsIClipboard.h"
 #include "nsIEditor.h"
 #include "nsIPersistentProperties2.h"
-#include "nsIPlaintextEditor.h"
 #include "nsFrameSelection.h"
 
+#include "mozilla/TextEditor.h"
+
 namespace mozilla {
 namespace a11y {
 
 inline bool
 HyperTextAccessible::IsValidOffset(int32_t aOffset)
 {
   index_t offset = ConvertMagicOffset(aOffset);
   return offset.IsValid() && offset <= CharacterCount();
@@ -55,77 +56,75 @@ HyperTextAccessible::AddToSelection(int3
 inline void
 HyperTextAccessible::ReplaceText(const nsAString& aText)
 {
   // We need to call DeleteText() even if there is no contents because we need
   // to ensure to move focus to the editor via SetSelectionRange() called in
   // DeleteText().
   DeleteText(0, CharacterCount());
 
-  nsCOMPtr<nsIEditor> editor = GetEditor();
-  nsCOMPtr<nsIPlaintextEditor> plaintextEditor(do_QueryInterface(editor));
-  if (!plaintextEditor) {
+  RefPtr<TextEditor> textEditor = GetEditor();
+  if (!textEditor) {
     return;
   }
 
   // DeleteText() may cause inserting <br> element in some cases. Let's
   // select all again and replace whole contents.
-  editor->SelectAll();
+  textEditor->SelectAll();
 
-  plaintextEditor->InsertText(aText);
+  textEditor->InsertText(aText);
 }
 
 inline void
 HyperTextAccessible::InsertText(const nsAString& aText, int32_t aPosition)
 {
-  nsCOMPtr<nsIEditor> editor = GetEditor();
-  nsCOMPtr<nsIPlaintextEditor> peditor(do_QueryInterface(editor));
-  if (peditor) {
+  RefPtr<TextEditor> textEditor = GetEditor();
+  if (textEditor) {
     SetSelectionRange(aPosition, aPosition);
-    peditor->InsertText(aText);
+    textEditor->InsertText(aText);
   }
 }
 
 inline void
 HyperTextAccessible::CopyText(int32_t aStartPos, int32_t aEndPos)
   {
-    nsCOMPtr<nsIEditor> editor = GetEditor();
-    if (editor) {
+    RefPtr<TextEditor> textEditor = GetEditor();
+    if (textEditor) {
       SetSelectionRange(aStartPos, aEndPos);
-      editor->Copy();
+      textEditor->Copy();
     }
   }
 
 inline void
 HyperTextAccessible::CutText(int32_t aStartPos, int32_t aEndPos)
   {
-    nsCOMPtr<nsIEditor> editor = GetEditor();
-    if (editor) {
+    RefPtr<TextEditor> textEditor = GetEditor();
+    if (textEditor) {
       SetSelectionRange(aStartPos, aEndPos);
-      editor->Cut();
+      textEditor->Cut();
     }
   }
 
 inline void
 HyperTextAccessible::DeleteText(int32_t aStartPos, int32_t aEndPos)
 {
-  nsCOMPtr<nsIEditor> editor = GetEditor();
-  if (editor) {
+  RefPtr<TextEditor> textEditor = GetEditor();
+  if (textEditor) {
     SetSelectionRange(aStartPos, aEndPos);
-    editor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
+    textEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
   }
 }
 
 inline void
 HyperTextAccessible::PasteText(int32_t aPosition)
 {
-  nsCOMPtr<nsIEditor> editor = GetEditor();
-  if (editor) {
+  RefPtr<TextEditor> textEditor = GetEditor();
+  if (textEditor) {
     SetSelectionRange(aPosition, aPosition);
-    editor->Paste(nsIClipboard::kGlobalClipboard);
+    textEditor->Paste(nsIClipboard::kGlobalClipboard);
   }
 }
 
 inline index_t
 HyperTextAccessible::ConvertMagicOffset(int32_t aOffset) const
 {
   if (aOffset == nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT)
     return CharacterCount();
--- a/accessible/generic/HyperTextAccessible.cpp
+++ b/accessible/generic/HyperTextAccessible.cpp
@@ -32,16 +32,17 @@
 #include "nsITextControlElement.h"
 #include "nsIMathMLFrame.h"
 #include "nsTextFragment.h"
 #include "mozilla/BinarySearch.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/MathAlgorithms.h"
+#include "mozilla/TextEditor.h"
 #include "gfxSkipChars.h"
 #include <algorithm>
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // HyperTextAccessible
@@ -382,26 +383,22 @@ HyperTextAccessible::OffsetsToDOMRange(i
 }
 
 DOMPoint
 HyperTextAccessible::OffsetToDOMPoint(int32_t aOffset)
 {
   // 0 offset is valid even if no children. In this case the associated editor
   // is empty so return a DOM point for editor root element.
   if (aOffset == 0) {
-    nsCOMPtr<nsIEditor> editor = GetEditor();
-    if (editor) {
+    RefPtr<TextEditor> textEditor = GetEditor();
+    if (textEditor) {
       bool isEmpty = false;
-      editor->GetDocumentIsEmpty(&isEmpty);
+      textEditor->GetDocumentIsEmpty(&isEmpty);
       if (isEmpty) {
-        nsCOMPtr<nsIDOMElement> editorRootElm;
-        editor->GetRootElement(getter_AddRefs(editorRootElm));
-
-        nsCOMPtr<nsINode> editorRoot(do_QueryInterface(editorRootElm));
-        return DOMPoint(editorRoot, 0);
+        return DOMPoint(textEditor->GetRoot(), 0);
       }
     }
   }
 
   int32_t childIdx = GetChildIndexAtOffset(aOffset);
   if (childIdx == -1)
     return DOMPoint();
 
@@ -1288,17 +1285,17 @@ HyperTextAccessible::TextBounds(int32_t 
     prevOffset = nextOffset;
     offset1 = 0;
   }
 
   nsAccUtils::ConvertScreenCoordsTo(&bounds.x, &bounds.y, aCoordType, this);
   return bounds;
 }
 
-already_AddRefed<nsIEditor>
+already_AddRefed<TextEditor>
 HyperTextAccessible::GetEditor() const
 {
   if (!mContent->HasFlag(NODE_IS_EDITABLE)) {
     // If we're inside an editable container, then return that container's editor
     Accessible* ancestor = Parent();
     while (ancestor) {
       HyperTextAccessible* hyperText = ancestor->AsHyperText();
       if (hyperText) {
@@ -1314,37 +1311,36 @@ HyperTextAccessible::GetEditor() const
   }
 
   nsCOMPtr<nsIDocShell> docShell = nsCoreUtils::GetDocShellFor(mContent);
   nsCOMPtr<nsIEditingSession> editingSession;
   docShell->GetEditingSession(getter_AddRefs(editingSession));
   if (!editingSession)
     return nullptr; // No editing session interface
 
-  nsCOMPtr<nsIEditor> editor;
   nsIDocument* docNode = mDoc->DocumentNode();
-  editingSession->GetEditorForWindow(docNode->GetWindow(),
-                                     getter_AddRefs(editor));
-  return editor.forget();
+  RefPtr<HTMLEditor> htmlEditor =
+    editingSession->GetHTMLEditorForWindow(docNode->GetWindow());
+  return htmlEditor.forget();
 }
 
 /**
   * =================== Caret & Selection ======================
   */
 
 nsresult
 HyperTextAccessible::SetSelectionRange(int32_t aStartPos, int32_t aEndPos)
 {
   // Before setting the selection range, we need to ensure that the editor
   // is initialized. (See bug 804927.)
   // Otherwise, it's possible that lazy editor initialization will override
   // the selection we set here and leave the caret at the end of the text.
   // By calling GetEditor here, we ensure that editor initialization is
   // completed before we set the selection.
-  nsCOMPtr<nsIEditor> editor = GetEditor();
+  RefPtr<TextEditor> textEditor = GetEditor();
 
   bool isFocusable = InteractiveState() & states::FOCUSABLE;
 
   // If accessible is focusable then focus it before setting the selection to
   // neglect control's selection changes on focus if any (for example, inputs
   // that do select all on focus).
   // some input controls
   if (isFocusable)
@@ -1553,23 +1549,21 @@ HyperTextAccessible::GetSelectionDOMRang
   if (!frameSelection ||
       frameSelection->GetDisplaySelection() <= nsISelectionController::SELECTION_HIDDEN)
     return;
 
   dom::Selection* domSel = frameSelection->GetSelection(aSelectionType);
   if (!domSel)
     return;
 
-  nsCOMPtr<nsINode> startNode = GetNode();
+  nsINode* startNode = GetNode();
 
-  nsCOMPtr<nsIEditor> editor = GetEditor();
-  if (editor) {
-    nsCOMPtr<nsIDOMElement> editorRoot;
-    editor->GetRootElement(getter_AddRefs(editorRoot));
-    startNode = do_QueryInterface(editorRoot);
+  RefPtr<TextEditor> textEditor = GetEditor();
+  if (textEditor) {
+    startNode = textEditor->GetRoot();
   }
 
   if (!startNode)
     return;
 
   uint32_t childCount = startNode->GetChildCount();
   nsresult rv = domSel->
     GetRangesForIntervalArray(startNode, 0, startNode, childCount, true, aRanges);
--- a/accessible/generic/HyperTextAccessible.h
+++ b/accessible/generic/HyperTextAccessible.h
@@ -12,21 +12,20 @@
 #include "nsDirection.h"
 #include "WordMovementType.h"
 #include "nsIFrame.h"
 
 #include "nsISelectionController.h"
 
 class nsFrameSelection;
 class nsRange;
-class nsIEditor;
 class nsIWidget;
 
 namespace mozilla {
-
+class TextEditor;
 namespace dom {
 class Selection;
 }
 
 namespace a11y {
 
 class TextRange;
 
@@ -418,18 +417,19 @@ public:
   void InsertText(const nsAString& aText, int32_t aPosition);
   void CopyText(int32_t aStartPos, int32_t aEndPos);
   void CutText(int32_t aStartPos, int32_t aEndPos);
   void DeleteText(int32_t aStartPos, int32_t aEndPos);
   void PasteText(int32_t aPosition);
 
   /**
    * Return the editor associated with the accessible.
+   * The result may be either TextEditor or HTMLEditor.
    */
-  virtual already_AddRefed<nsIEditor> GetEditor() const;
+  virtual already_AddRefed<TextEditor> GetEditor() const;
 
   /**
    * Return DOM selection object for the accessible.
    */
   dom::Selection* DOMSelection() const;
 
 protected:
   virtual ~HyperTextAccessible() { }
--- a/accessible/html/HTMLFormControlAccessible.cpp
+++ b/accessible/html/HTMLFormControlAccessible.cpp
@@ -10,30 +10,31 @@
 #include "nsEventShell.h"
 #include "nsTextEquivUtils.h"
 #include "Relation.h"
 #include "Role.h"
 #include "States.h"
 
 #include "nsContentList.h"
 #include "mozilla/dom/HTMLInputElement.h"
-#include "nsIDOMNSEditableElement.h"
 #include "nsIDOMHTMLTextAreaElement.h"
 #include "nsIEditor.h"
 #include "nsIFormControl.h"
 #include "nsIPersistentProperties2.h"
 #include "nsISelectionController.h"
 #include "nsIServiceManager.h"
+#include "nsITextControlElement.h"
 #include "nsITextControlFrame.h"
 #include "nsNameSpaceManager.h"
 #include "mozilla/dom/ScriptSettings.h"
 
 #include "mozilla/EventStates.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/TextEditor.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // HTMLCheckboxAccessible
 ////////////////////////////////////////////////////////////////////////////////
@@ -454,27 +455,26 @@ HTMLTextFieldAccessible::DoAction(uint8_
 {
   if (aIndex != 0)
     return false;
 
   TakeFocus();
   return true;
 }
 
-already_AddRefed<nsIEditor>
+already_AddRefed<TextEditor>
 HTMLTextFieldAccessible::GetEditor() const
 {
-  nsCOMPtr<nsIDOMNSEditableElement> editableElt(do_QueryInterface(mContent));
-  if (!editableElt)
+  nsCOMPtr<nsITextControlElement> textControlElement =
+    do_QueryInterface(mContent);
+  if (!textControlElement) {
     return nullptr;
-
-  nsCOMPtr<nsIEditor> editor;
-  editableElt->GetEditor(getter_AddRefs(editor));
-
-  return editor.forget();
+  }
+  RefPtr<TextEditor> textEditor = textControlElement->GetTextEditor();
+  return textEditor.forget();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // HTMLTextFieldAccessible: Widgets
 
 bool
 HTMLTextFieldAccessible::IsWidget() const
 {
--- a/accessible/html/HTMLFormControlAccessible.h
+++ b/accessible/html/HTMLFormControlAccessible.h
@@ -5,16 +5,17 @@
 
 #ifndef MOZILLA_A11Y_HTMLFormControlAccessible_H_
 #define MOZILLA_A11Y_HTMLFormControlAccessible_H_
 
 #include "FormControlAccessible.h"
 #include "HyperTextAccessibleWrap.h"
 
 namespace mozilla {
+class TextEditor;
 namespace a11y {
 
 /**
  * Accessible for HTML progress element.
  */
 typedef ProgressMeterAccessible<1> HTMLProgressMeterAccessible;
 
 /**
@@ -111,17 +112,17 @@ class HTMLTextFieldAccessible final : pu
 public:
   enum { eAction_Click = 0 };
 
   HTMLTextFieldAccessible(nsIContent* aContent, DocAccessible* aDoc);
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // HyperTextAccessible
-  virtual already_AddRefed<nsIEditor> GetEditor() const override;
+  virtual already_AddRefed<TextEditor> GetEditor() const override;
 
   // Accessible
   virtual void Value(nsString& aValue) override;
   virtual void ApplyARIAState(uint64_t* aState) const override;
   virtual mozilla::a11y::role NativeRole() override;
   virtual uint64_t NativeState() override;
   virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() override;