Bug 1388004 - part1: Make nsContentUtils::GetHTMLEditor() return HTMLEditor* rather than nsIEditor* r?smaug
nsContentUtils::GetHTMLEditor() currently returns nsIEditor* since editor of doc shell may be any type of editors such as TextEditor or editor object which is implemented by JS. However, nsIEditor is now a builtin class. So, it can return HTMLEditor.
MozReview-Commit-ID: 3YoFOplZa7W
--- a/accessible/generic/HyperTextAccessible.h
+++ b/accessible/generic/HyperTextAccessible.h
@@ -12,16 +12,17 @@
#include "nsDirection.h"
#include "WordMovementType.h"
#include "nsIFrame.h"
#include "nsISelectionController.h"
class nsFrameSelection;
class nsRange;
+class nsIEditor;
class nsIWidget;
namespace mozilla {
namespace dom {
class Selection;
}
--- a/dom/base/FragmentOrElement.cpp
+++ b/dom/base/FragmentOrElement.cpp
@@ -18,16 +18,17 @@
#include "mozilla/dom/FragmentOrElement.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/DeclarationBlockInlines.h"
#include "mozilla/EffectSet.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/EventStates.h"
+#include "mozilla/HTMLEditor.h"
#include "mozilla/ServoRestyleManager.h"
#include "mozilla/TextEditor.h"
#include "mozilla/URLExtraData.h"
#include "mozilla/dom/Attr.h"
#include "nsDOMAttributeMap.h"
#include "nsIAtom.h"
#include "mozilla/dom/NodeInfo.h"
#include "mozilla/dom/Event.h"
@@ -266,22 +267,22 @@ nsIContent::GetDesiredIMEState()
nsIPresShell* ps = doc->GetShell();
if (!ps) {
return IMEState(IMEState::DISABLED);
}
nsPresContext* pc = ps->GetPresContext();
if (!pc) {
return IMEState(IMEState::DISABLED);
}
- nsIEditor* editor = nsContentUtils::GetHTMLEditor(pc);
- if (!editor) {
+ HTMLEditor* htmlEditor = nsContentUtils::GetHTMLEditor(pc);
+ if (!htmlEditor) {
return IMEState(IMEState::DISABLED);
}
IMEState state;
- editor->GetPreferredIMEState(&state);
+ htmlEditor->GetPreferredIMEState(&state);
return state;
}
bool
nsIContent::HasIndependentSelection()
{
nsIFrame* frame = GetPrimaryFrame();
return (frame && frame->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION);
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -8,16 +8,17 @@
* Implementation of mozilla::dom::Selection
*/
#include "mozilla/dom/Selection.h"
#include "mozilla/Attributes.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/EventStates.h"
+#include "mozilla/HTMLEditor.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsFrameSelection.h"
#include "nsISelectionListener.h"
#include "nsContentCID.h"
#include "nsDeviceContext.h"
#include "nsIContent.h"
@@ -68,18 +69,16 @@
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/SelectionBinding.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/Telemetry.h"
#include "mozilla/layers/ScrollInputMethods.h"
#include "nsViewManager.h"
-#include "nsIEditor.h"
-#include "nsIHTMLEditor.h"
#include "nsFocusManager.h"
#include "nsPIDOMWindow.h"
using namespace mozilla;
using namespace mozilla::dom;
using mozilla::layers::ScrollInputMethod;
//#define DEBUG_TABLE 1
@@ -3325,18 +3324,18 @@ Selection::GetDocument() const
nsPIDOMWindowOuter*
Selection::GetWindow() const
{
nsIDocument* document = GetDocument();
return document ? document->GetWindow() : nullptr;
}
-nsIEditor*
-Selection::GetEditor() const
+HTMLEditor*
+Selection::GetHTMLEditor() const
{
nsPresContext* presContext = GetPresContext();
if (!presContext) {
return nullptr;
}
return nsContentUtils::GetHTMLEditor(presContext);
}
@@ -3712,17 +3711,17 @@ Selection::NotifySelectionListeners()
// browsers don't do it either.
if (mSelectionType == SelectionType::eNormal &&
calledByJSRestorer.SavedValue()) {
nsPIDOMWindowOuter* window = GetWindow();
nsIDocument* document = GetDocument();
// If the document is in design mode or doesn't have contenteditable
// element, we don't need to move focus.
if (window && document && !document->HasFlag(NODE_IS_EDITABLE) &&
- GetEditor()) {
+ GetHTMLEditor()) {
RefPtr<Element> newEditingHost = GetCommonEditingHostForAllRanges();
nsFocusManager* fm = nsFocusManager::GetFocusManager();
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
nsIContent* focusedContent =
fm->GetFocusedDescendant(window, false, getter_AddRefs(focusedWindow));
nsCOMPtr<Element> focusedElement = do_QueryInterface(focusedContent);
// When all selected ranges are in an editing host, it should take focus.
// But otherwise, we shouldn't move focus since Chromium doesn't move
--- a/dom/base/Selection.h
+++ b/dom/base/Selection.h
@@ -19,28 +19,27 @@
#include "nsRange.h"
#include "nsThreadUtils.h"
#include "nsWrapperCache.h"
struct CachedOffsetForFrame;
class nsAutoScrollTimer;
class nsIContentIterator;
class nsIDocument;
-class nsIEditor;
class nsIFrame;
-class nsIHTMLEditor;
class nsFrameSelection;
class nsPIDOMWindowOuter;
struct SelectionDetails;
struct SelectionCustomColors;
class nsCopySupport;
class nsHTMLCopyEncoder;
namespace mozilla {
class ErrorResult;
+class HTMLEditor;
struct AutoPrepareFocusRange;
} // namespace mozilla
struct RangeData
{
explicit RangeData(nsRange* aRange)
: mRange(aRange)
{}
@@ -385,17 +384,17 @@ private:
/**
* Helper method for AddItem.
*/
nsresult AddItemInternal(nsRange* aRange, int32_t* aOutIndex);
nsIDocument* GetDocument() const;
nsPIDOMWindowOuter* GetWindow() const;
- nsIEditor* GetEditor() const;
+ HTMLEditor* GetHTMLEditor() const;
/**
* GetCommonEditingHostForAllRanges() returns common editing host of all
* ranges if there is. If at least one of the ranges is in non-editable
* element, returns nullptr. See following examples for the detail:
*
* <div id="a" contenteditable>
* an[cestor
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -60,16 +60,17 @@
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/dom/XULCommandEvent.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/workers/ServiceWorkerManager.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
+#include "mozilla/HTMLEditor.h"
#include "mozilla/IMEStateManager.h"
#include "mozilla/InternalMutationEvent.h"
#include "mozilla/Likely.h"
#include "mozilla/ManualNAC.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/TextEvents.h"
@@ -132,17 +133,16 @@
#include "nsIDOMElement.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMNode.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMWindowUtils.h"
#include "nsIDragService.h"
-#include "nsIEditor.h"
#include "nsIFormControl.h"
#include "nsIForm.h"
#include "nsIFragmentContentSink.h"
#include "nsContainerFrame.h"
#include "nsIHTMLDocument.h"
#include "nsIIdleService.h"
#include "nsIImageLoadingContent.h"
#include "nsIInterfaceRequestor.h"
@@ -7547,28 +7547,26 @@ nsContentUtils::GetSelectionInTextContro
}
MOZ_ASSERT(startOffset <= endOffset);
aOutStartOffset = startOffset;
aOutEndOffset = endOffset;
}
-nsIEditor*
+HTMLEditor*
nsContentUtils::GetHTMLEditor(nsPresContext* aPresContext)
{
nsCOMPtr<nsIDocShell> docShell(aPresContext->GetDocShell());
bool isEditable;
if (!docShell ||
NS_FAILED(docShell->GetEditable(&isEditable)) || !isEditable)
return nullptr;
- nsCOMPtr<nsIEditor> editor;
- docShell->GetEditor(getter_AddRefs(editor));
- return editor;
+ return docShell->GetHTMLEditor();
}
bool
nsContentUtils::IsContentInsertionPoint(nsIContent* aContent)
{
// Check if the content is a XBL insertion point.
if (aContent->IsActiveChildrenElement()) {
return true;
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -66,17 +66,16 @@ class nsIDocShellTreeItem;
class nsIDocumentLoaderFactory;
class nsIDOMDocument;
class nsIDOMDocumentFragment;
class nsIDOMEvent;
class nsIDOMHTMLInputElement;
class nsIDOMKeyEvent;
class nsIDOMNode;
class nsIDragSession;
-class nsIEditor;
class nsIEventTarget;
class nsIFragmentContentSink;
class nsIFrame;
class nsIImageLoadingContent;
class nsIInterfaceRequestor;
class nsIIOService;
class nsILineBreaker;
class nsILoadInfo;
@@ -122,16 +121,17 @@ template<class E> class nsCOMArray;
template<class K, class V> class nsDataHashtable;
template<class K, class V> class nsRefPtrHashtable;
template<class T> class nsReadingIterator;
namespace mozilla {
class Dispatcher;
class ErrorResult;
class EventListenerManager;
+class HTMLEditor;
namespace dom {
struct CustomElementDefinition;
class DocumentFragment;
class Element;
class EventTarget;
class IPCDataTransfer;
class IPCDataTransferItem;
@@ -2618,17 +2618,23 @@ public:
* @param aOffset Offset as calculated by GetContentOffsetsFromPoint
* @param aOutOffset Output adjusted offset
*
* @see GetSelectionInTextControl for the original basis of this function.
*/
static int32_t GetAdjustedOffsetInTextControl(nsIFrame* aOffsetFrame,
int32_t aOffset);
- static nsIEditor* GetHTMLEditor(nsPresContext* aPresContext);
+ /**
+ * Returns pointer to HTML editor instance for the aPresContext when there is.
+ * The HTML editor is shared by contenteditable elements or used in
+ * designMode. When there are no contenteditable elements and the document
+ * is not in designMode, this returns nullptr.
+ */
+ static mozilla::HTMLEditor* GetHTMLEditor(nsPresContext* aPresContext);
/**
* Returns true if the browser.dom.window.dump.enabled pref is set.
*/
static bool DOMWindowDumpEnabled();
/**
* Returns true if the privacy.donottrackheader.enabled pref is set.
--- a/layout/generic/nsFrameSelection.cpp
+++ b/layout/generic/nsFrameSelection.cpp
@@ -8,16 +8,17 @@
* Implementation of nsFrameSelection
*/
#include "nsFrameSelection.h"
#include "mozilla/Attributes.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/EventStates.h"
+#include "mozilla/HTMLEditor.h"
#include "mozilla/PresShell.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsISelectionListener.h"
#include "nsContentCID.h"
#include "nsDeviceContext.h"
#include "nsIContent.h"
@@ -77,18 +78,16 @@ static NS_DEFINE_CID(kFrameTraversalCID,
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/SelectionBinding.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/Telemetry.h"
#include "mozilla/layers/ScrollInputMethods.h"
-#include "nsIEditor.h"
-#include "nsIHTMLEditor.h"
#include "nsFocusManager.h"
#include "nsPIDOMWindow.h"
using namespace mozilla;
using namespace mozilla::dom;
using mozilla::layers::ScrollInputMethod;
//#define DEBUG_TABLE 1
@@ -1453,20 +1452,20 @@ nsFrameSelection::TakeFocus(nsIContent*
//once we do that, the next time we get a takefocus, check the parent tree.
//if we are no longer inside same table ,cell then switch to table selection mode.
// BUT only do this in an editor
NS_ENSURE_STATE(mShell);
bool editableCell = false;
RefPtr<nsPresContext> context = mShell->GetPresContext();
if (context) {
- nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(nsContentUtils::GetHTMLEditor(context));
- if (editor) {
+ RefPtr<HTMLEditor> htmlEditor = nsContentUtils::GetHTMLEditor(context);
+ if (htmlEditor) {
nsINode* cellparent = GetCellParent(aNewFocus);
- nsCOMPtr<nsINode> editorHostNode = editor->GetActiveEditingHost();
+ nsCOMPtr<nsINode> editorHostNode = htmlEditor->GetActiveEditingHost();
editableCell = cellparent && editorHostNode &&
nsContentUtils::ContentIsDescendantOf(cellparent, editorHostNode);
if (editableCell) {
mCellParent = cellparent;
#ifdef DEBUG_TABLE_SELECTION
printf(" * TakeFocus - Collapsing into new cell\n");
#endif
}