Bug 1388004 - part2: Make nsGenericHTMLElement::GetAssociatedEditor() return TextEditor instead of nsIEditor r?smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 07 Aug 2017 16:53:59 +0900
changeset 645259 c587b5696649ac2cca9d51e130cc301f0bdb6f4e
parent 645258 68226981d224969b8f193c425d0feea63b5d3798
child 645260 274aae656d7acd52c8c19ad31e9ab7fa60490400
push id73720
push usermasayuki@d-toybox.com
push dateSat, 12 Aug 2017 03:32:40 +0000
reviewerssmaug
bugs1388004
milestone57.0a1
Bug 1388004 - part2: Make nsGenericHTMLElement::GetAssociatedEditor() return TextEditor instead of nsIEditor r?smaug nsGenericHTMLElement::GetAssociatedEditor() retrieves TextEditor if the element is <input type="text"> or something, or <textarea>, or if it's editable, HTMLEditor associated to the document. So, this method can return TextEditor (HTMLEditor is a subclass of TextEditor). MozReview-Commit-ID: BvpFPaPLY70
dom/html/HTMLBodyElement.cpp
dom/html/HTMLBodyElement.h
dom/html/nsGenericHTMLElement.cpp
dom/html/nsGenericHTMLElement.h
--- a/dom/html/HTMLBodyElement.cpp
+++ b/dom/html/HTMLBodyElement.cpp
@@ -2,25 +2,25 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "HTMLBodyElement.h"
 #include "mozilla/dom/HTMLBodyElementBinding.h"
 #include "mozilla/GenericSpecifiedValuesInlines.h"
+#include "mozilla/HTMLEditor.h"
 #include "mozilla/TextEditor.h"
 #include "nsAttrValueInlines.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsIDocument.h"
 #include "nsHTMLStyleSheet.h"
-#include "nsIEditor.h"
 #include "nsMappedAttributes.h"
 #include "nsIDocShell.h"
 #include "nsRuleWalker.h"
 #include "nsGlobalWindow.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Body)
 
 namespace mozilla {
@@ -387,17 +387,17 @@ HTMLBodyElement::IsAttributeMapped(const
     attributes,
     sCommonAttributeMap,
     sBackgroundAttributeMap,
   };
 
   return FindAttributeDependence(aAttribute, map);
 }
 
-already_AddRefed<nsIEditor>
+already_AddRefed<TextEditor>
 HTMLBodyElement::GetAssociatedEditor()
 {
   RefPtr<TextEditor> textEditor = GetTextEditorInternal();
   if (textEditor) {
     return textEditor.forget();
   }
 
   // Make sure this is the actual body of the document
@@ -411,19 +411,18 @@ HTMLBodyElement::GetAssociatedEditor()
     return nullptr;
   }
 
   nsCOMPtr<nsIDocShell> docShell = presContext->GetDocShell();
   if (!docShell) {
     return nullptr;
   }
 
-  nsCOMPtr<nsIEditor> editor;
-  docShell->GetEditor(getter_AddRefs(editor));
-  return editor.forget();
+  RefPtr<HTMLEditor> htmlEditor = docShell->GetHTMLEditor();
+  return htmlEditor.forget();
 }
 
 bool
 HTMLBodyElement::IsEventAttributeNameInternal(nsIAtom *aName)
 {
   return nsContentUtils::IsEventAttributeName(aName,
                                               EventNameType_HTML |
                                               EventNameType_HTMLBodyOrFramesetOnly);
--- a/dom/html/HTMLBodyElement.h
+++ b/dom/html/HTMLBodyElement.h
@@ -7,16 +7,19 @@
 #define HTMLBodyElement_h___
 
 #include "mozilla/Attributes.h"
 #include "nsGenericHTMLElement.h"
 #include "nsIDOMHTMLBodyElement.h"
 #include "nsIStyleRule.h"
 
 namespace mozilla {
+
+class TextEditor;
+
 namespace dom {
 
 class OnBeforeUnloadEventHandlerNonNull;
 
 class HTMLBodyElement final : public nsGenericHTMLElement,
                               public nsIDOMHTMLBodyElement
 {
 public:
@@ -100,17 +103,17 @@ public:
   }
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
                               nsIAtom* aAttribute,
                               const nsAString& aValue,
                               nsAttrValue& aResult) override;
   virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const override;
-  virtual already_AddRefed<nsIEditor> GetAssociatedEditor() override;
+  virtual already_AddRefed<TextEditor> GetAssociatedEditor() override;
   virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                          bool aPreallocateChildren) const override;
 
   virtual bool IsEventAttributeNameInternal(nsIAtom* aName) override;
 
 
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                               nsIContent* aBindingParent,
--- a/dom/html/nsGenericHTMLElement.cpp
+++ b/dom/html/nsGenericHTMLElement.cpp
@@ -71,17 +71,16 @@
 #include "nsIDOMHTMLFormElement.h"
 #include "mozilla/dom/HTMLFormElement.h"
 #include "nsFocusManager.h"
 #include "nsAttrValueOrString.h"
 
 #include "mozilla/InternalMutationEvent.h"
 #include "nsDOMStringMap.h"
 
-#include "nsIEditor.h"
 #include "nsLayoutUtils.h"
 #include "mozAutoDocUpdate.h"
 #include "nsHtml5Module.h"
 #include "nsITextControlElement.h"
 #include "mozilla/dom/ElementInlines.h"
 #include "HTMLFieldSetElement.h"
 #include "nsTextNode.h"
 #include "HTMLBRElement.h"
@@ -2654,17 +2653,17 @@ nsGenericHTMLElement::DispatchSimulatedC
 {
   WidgetMouseEvent event(aIsTrusted, eMouseClick, nullptr,
                          WidgetMouseEvent::eReal);
   event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD;
   event.mFlags.mIsPositionless = true;
   return EventDispatcher::Dispatch(ToSupports(aElement), aPresContext, &event);
 }
 
-already_AddRefed<nsIEditor>
+already_AddRefed<TextEditor>
 nsGenericHTMLElement::GetAssociatedEditor()
 {
   // If contenteditable is ever implemented, it might need to do something different here?
 
   RefPtr<TextEditor> textEditor = GetTextEditorInternal();
   return textEditor.forget();
 }
 
@@ -2690,19 +2689,19 @@ nsGenericHTMLElement::IsCurrentBodyEleme
 
 // static
 void
 nsGenericHTMLElement::SyncEditorsOnSubtree(nsIContent* content)
 {
   /* Sync this node */
   nsGenericHTMLElement* element = FromContent(content);
   if (element) {
-    nsCOMPtr<nsIEditor> editor = element->GetAssociatedEditor();
-    if (editor) {
-      editor->SyncRealTimeSpell();
+    RefPtr<TextEditor> textEditor = element->GetAssociatedEditor();
+    if (textEditor) {
+      textEditor->SyncRealTimeSpell();
     }
   }
 
   /* Sync all children */
   for (nsIContent* child = content->GetFirstChild();
        child;
        child = child->GetNextSibling()) {
     SyncEditorsOnSubtree(child);
--- a/dom/html/nsGenericHTMLElement.h
+++ b/dom/html/nsGenericHTMLElement.h
@@ -18,17 +18,16 @@
 #include "nsIDOMHTMLMenuElement.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/dom/DOMRect.h"
 #include "mozilla/dom/ValidityState.h"
 #include "mozilla/dom/Element.h"
 
 class nsDOMTokenList;
 class nsIDOMHTMLMenuElement;
-class nsIEditor;
 class nsIFormControlFrame;
 class nsIFrame;
 class nsILayoutHistoryState;
 class nsIURI;
 class nsPresState;
 struct nsSize;
 
 namespace mozilla {
@@ -911,24 +910,24 @@ protected:
   {
     nsAutoString value;
     value.AppendFloat(aValue);
 
     SetHTMLAttr(aAttr, value, aRv);
   }
 
   /**
-   * Locates the nsIEditor associated with this node.  In general this is
+   * Locates the TextEditor associated with this node.  In general this is
    * equivalent to GetEditorInternal(), but for designmode or contenteditable,
    * this may need to get an editor that's not actually on this element's
    * associated TextControlFrame.  This is used by the spellchecking routines
    * to get the editor affected by changing the spellcheck attribute on this
    * node.
    */
-  virtual already_AddRefed<nsIEditor> GetAssociatedEditor();
+  virtual already_AddRefed<mozilla::TextEditor> GetAssociatedEditor();
 
   /**
    * Get the frame's offset information for offsetTop/Left/Width/Height.
    * Returns the parent the offset is relative to.
    * @note This method flushes pending notifications (FlushType::Layout).
    * @param aRect the offset information [OUT]
    */
   mozilla::dom::Element* GetOffsetRect(mozilla::CSSIntRect& aRect);