Bug 1628192 - Use more const declarations on editor classes. r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D70146

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Makoto Kato 2020-04-13 01:43:41 +00:00
parent 8c7529f5d0
commit 67f4ec1ac0
6 changed files with 81 additions and 90 deletions

View File

@ -5387,7 +5387,7 @@ bool EditorBase::IsModifiableNode(const nsINode& aNode) const {
return !AsHTMLEditor() || aNode.IsEditable();
}
nsIContent* EditorBase::GetFocusedContent() {
nsIContent* EditorBase::GetFocusedContent() const {
EventTarget* piTarget = GetDOMEventTarget();
if (!piTarget) {
return nullptr;
@ -5404,12 +5404,11 @@ nsIContent* EditorBase::GetFocusedContent() {
return (content == piTarget) ? content : nullptr;
}
already_AddRefed<nsIContent> EditorBase::GetFocusedContentForIME() {
nsCOMPtr<nsIContent> content = GetFocusedContent();
return content.forget();
nsIContent* EditorBase::GetFocusedContentForIME() const {
return GetFocusedContent();
}
bool EditorBase::IsActiveInDOMWindow() {
bool EditorBase::IsActiveInDOMWindow() const {
EventTarget* piTarget = GetDOMEventTarget();
if (!piTarget) {
return false;
@ -5420,7 +5419,7 @@ bool EditorBase::IsActiveInDOMWindow() {
return false; // Do we need to check the singleton instance??
}
RefPtr<Document> document = GetDocument();
Document* document = GetDocument();
if (NS_WARN_IF(!document)) {
return false;
}

View File

@ -423,7 +423,7 @@ class EditorBase : public nsIEditor,
MOZ_CAN_RUN_SCRIPT virtual nsresult HandleKeyPressEvent(
WidgetKeyboardEvent* aKeyboardEvent);
virtual dom::EventTarget* GetDOMEventTarget() = 0;
virtual dom::EventTarget* GetDOMEventTarget() const = 0;
/**
* Similar to the setter for wrapWidth, but just sets the editor
@ -560,13 +560,13 @@ class EditorBase : public nsIEditor,
/**
* Get the focused content, if we're focused. Returns null otherwise.
*/
virtual nsIContent* GetFocusedContent();
virtual nsIContent* GetFocusedContent() const;
/**
* Get the focused content for the argument of some IMEStateManager's
* methods.
*/
virtual already_AddRefed<nsIContent> GetFocusedContentForIME();
virtual nsIContent* GetFocusedContentForIME() const;
/**
* Whether the aGUIEvent should be handled by this editor or not. When this
@ -2259,7 +2259,7 @@ class EditorBase : public nsIEditor,
* returns true but GetFocusedContent() returns null, it means that this
* editor was focused when the DOM window was active.
*/
virtual bool IsActiveInDOMWindow();
virtual bool IsActiveInDOMWindow() const;
/**
* FindBetterInsertionPoint() tries to look for better insertion point which
@ -2531,7 +2531,7 @@ class EditorBase : public nsIEditor,
/**
* Get the input event target. This might return null.
*/
virtual already_AddRefed<Element> GetInputEventTargetElement() = 0;
virtual already_AddRefed<Element> GetInputEventTargetElement() const = 0;
/**
* Return true if spellchecking should be enabled for this editor.

View File

@ -4094,7 +4094,7 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
}
nsIContent* HTMLEditor::GetPriorHTMLSibling(nsINode* aNode,
SkipWhitespace aSkipWS) {
SkipWhitespace aSkipWS) const {
MOZ_ASSERT(aNode);
nsIContent* node = aNode->GetPreviousSibling();
@ -4106,7 +4106,7 @@ nsIContent* HTMLEditor::GetPriorHTMLSibling(nsINode* aNode,
}
nsIContent* HTMLEditor::GetNextHTMLSibling(nsINode* aNode,
SkipWhitespace aSkipWS) {
SkipWhitespace aSkipWS) const {
MOZ_ASSERT(aNode);
nsIContent* node = aNode->GetNextSibling();
@ -4118,7 +4118,7 @@ nsIContent* HTMLEditor::GetNextHTMLSibling(nsINode* aNode,
}
nsIContent* HTMLEditor::GetPreviousHTMLElementOrTextInternal(
nsINode& aNode, bool aNoBlockCrossing) {
nsINode& aNode, bool aNoBlockCrossing) const {
if (NS_WARN_IF(!GetActiveEditingHost())) {
return nullptr;
}
@ -4128,7 +4128,7 @@ nsIContent* HTMLEditor::GetPreviousHTMLElementOrTextInternal(
template <typename PT, typename CT>
nsIContent* HTMLEditor::GetPreviousHTMLElementOrTextInternal(
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing) {
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing) const {
if (NS_WARN_IF(!GetActiveEditingHost())) {
return nullptr;
}
@ -4137,7 +4137,7 @@ nsIContent* HTMLEditor::GetPreviousHTMLElementOrTextInternal(
}
nsIContent* HTMLEditor::GetPreviousEditableHTMLNodeInternal(
nsINode& aNode, bool aNoBlockCrossing) {
nsINode& aNode, bool aNoBlockCrossing) const {
if (NS_WARN_IF(!GetActiveEditingHost())) {
return nullptr;
}
@ -4147,7 +4147,7 @@ nsIContent* HTMLEditor::GetPreviousEditableHTMLNodeInternal(
template <typename PT, typename CT>
nsIContent* HTMLEditor::GetPreviousEditableHTMLNodeInternal(
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing) {
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing) const {
if (NS_WARN_IF(!GetActiveEditingHost())) {
return nullptr;
}
@ -4156,7 +4156,7 @@ nsIContent* HTMLEditor::GetPreviousEditableHTMLNodeInternal(
}
nsIContent* HTMLEditor::GetNextHTMLElementOrTextInternal(
nsINode& aNode, bool aNoBlockCrossing) {
nsINode& aNode, bool aNoBlockCrossing) const {
if (NS_WARN_IF(!GetActiveEditingHost())) {
return nullptr;
}
@ -4166,7 +4166,7 @@ nsIContent* HTMLEditor::GetNextHTMLElementOrTextInternal(
template <typename PT, typename CT>
nsIContent* HTMLEditor::GetNextHTMLElementOrTextInternal(
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing) {
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing) const {
if (NS_WARN_IF(!GetActiveEditingHost())) {
return nullptr;
}
@ -4233,7 +4233,7 @@ nsIContent* HTMLEditor::GetLastEditableChild(nsINode& aNode) const {
return child;
}
nsIContent* HTMLEditor::GetFirstEditableLeaf(nsINode& aNode) {
nsIContent* HTMLEditor::GetFirstEditableLeaf(nsINode& aNode) const {
nsCOMPtr<nsIContent> child = GetLeftmostChild(&aNode);
while (child && (!IsEditable(child) || child->HasChildren())) {
child = GetNextEditableHTMLNode(*child);
@ -4247,7 +4247,7 @@ nsIContent* HTMLEditor::GetFirstEditableLeaf(nsINode& aNode) {
return child;
}
nsIContent* HTMLEditor::GetLastEditableLeaf(nsINode& aNode) {
nsIContent* HTMLEditor::GetLastEditableLeaf(nsINode& aNode) const {
nsCOMPtr<nsIContent> child = GetRightmostChild(&aNode, false);
while (child && (!IsEditable(child) || child->HasChildren())) {
child = GetPreviousEditableHTMLNode(*child);
@ -5008,15 +5008,15 @@ nsresult HTMLEditor::GetReturnInParagraphCreatesNewParagraph(
return NS_OK;
}
nsIContent* HTMLEditor::GetFocusedContent() {
nsIContent* HTMLEditor::GetFocusedContent() const {
nsFocusManager* focusManager = nsFocusManager::GetFocusManager();
if (NS_WARN_IF(!focusManager)) {
return nullptr;
}
nsCOMPtr<nsIContent> focusedContent = focusManager->GetFocusedElement();
nsIContent* focusedContent = focusManager->GetFocusedElement();
RefPtr<Document> document = GetDocument();
Document* document = GetDocument();
if (NS_WARN_IF(!document)) {
return nullptr;
}
@ -5032,7 +5032,7 @@ nsIContent* HTMLEditor::GetFocusedContent() {
if (inDesignMode) {
return OurWindowHasFocus() &&
focusedContent->IsInclusiveDescendantOf(document)
? focusedContent.get()
? focusedContent
: nullptr;
}
@ -5045,30 +5045,29 @@ nsIContent* HTMLEditor::GetFocusedContent() {
return nullptr;
}
// If our window is focused, we're focused.
return OurWindowHasFocus() ? focusedContent.get() : nullptr;
return OurWindowHasFocus() ? focusedContent : nullptr;
}
already_AddRefed<nsIContent> HTMLEditor::GetFocusedContentForIME() {
nsCOMPtr<nsIContent> focusedContent = GetFocusedContent();
nsIContent* HTMLEditor::GetFocusedContentForIME() const {
nsIContent* focusedContent = GetFocusedContent();
if (!focusedContent) {
return nullptr;
}
RefPtr<Document> document = GetDocument();
Document* document = GetDocument();
if (NS_WARN_IF(!document)) {
return nullptr;
}
return document->HasFlag(NODE_IS_EDITABLE) ? nullptr
: focusedContent.forget();
return document->HasFlag(NODE_IS_EDITABLE) ? nullptr : focusedContent;
}
bool HTMLEditor::IsActiveInDOMWindow() {
bool HTMLEditor::IsActiveInDOMWindow() const {
nsFocusManager* focusManager = nsFocusManager::GetFocusManager();
if (NS_WARN_IF(!focusManager)) {
return false;
}
RefPtr<Document> document = GetDocument();
Document* document = GetDocument();
if (NS_WARN_IF(!document)) {
return false;
}
@ -5164,16 +5163,15 @@ void HTMLEditor::NotifyEditingHostMaybeChanged() {
}
}
EventTarget* HTMLEditor::GetDOMEventTarget() {
EventTarget* HTMLEditor::GetDOMEventTarget() const {
// Don't use getDocument here, because we have no way of knowing
// whether Init() was ever called. So we need to get the document
// ourselves, if it exists.
MOZ_ASSERT(IsInitialized(), "The HTMLEditor has not been initialized yet");
nsCOMPtr<EventTarget> target = GetDocument();
return target;
return GetDocument();
}
bool HTMLEditor::ShouldReplaceRootElement() {
bool HTMLEditor::ShouldReplaceRootElement() const {
if (!mRootElement) {
// If we don't know what is our root element, we should find our root.
return true;
@ -5225,17 +5223,17 @@ void HTMLEditor::NotifyRootChanged() {
SyncRealTimeSpell();
}
Element* HTMLEditor::GetBodyElement() {
Element* HTMLEditor::GetBodyElement() const {
MOZ_ASSERT(IsInitialized(), "The HTMLEditor hasn't been initialized yet");
RefPtr<Document> document = GetDocument();
Document* document = GetDocument();
if (NS_WARN_IF(!document)) {
return nullptr;
}
return document->GetBody();
}
already_AddRefed<nsINode> HTMLEditor::GetFocusedNode() {
nsCOMPtr<nsIContent> focusedContent = GetFocusedContent();
nsINode* HTMLEditor::GetFocusedNode() const {
nsIContent* focusedContent = GetFocusedContent();
if (!focusedContent) {
return nullptr;
}
@ -5247,30 +5245,24 @@ already_AddRefed<nsINode> HTMLEditor::GetFocusedNode() {
nsFocusManager* focusManager = nsFocusManager::GetFocusManager();
NS_ASSERTION(focusManager, "Focus manager is null");
RefPtr<Element> focusedElement = focusManager->GetFocusedElement();
Element* focusedElement = focusManager->GetFocusedElement();
if (focusedElement) {
return focusedElement.forget();
return focusedElement;
}
RefPtr<Document> document = GetDocument();
return document.forget();
return GetDocument();
}
bool HTMLEditor::OurWindowHasFocus() {
nsIFocusManager* focusManager = nsFocusManager::GetFocusManager();
bool HTMLEditor::OurWindowHasFocus() const {
nsFocusManager* focusManager = nsFocusManager::GetFocusManager();
if (NS_WARN_IF(!focusManager)) {
return false;
}
nsCOMPtr<mozIDOMWindowProxy> focusedWindow;
DebugOnly<nsresult> rvIgnored =
focusManager->GetFocusedWindow(getter_AddRefs(focusedWindow));
nsPIDOMWindowOuter* focusedWindow = focusManager->GetFocusedWindow();
if (!focusedWindow) {
return false;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored),
"nsFocusManager::GetFocusedWindow() failed, but ignored");
RefPtr<Document> document = GetDocument();
Document* document = GetDocument();
if (NS_WARN_IF(!document)) {
return false;
}
@ -5387,7 +5379,7 @@ nsresult HTMLEditor::GetPreferredIMEState(IMEState* aState) {
return NS_OK;
}
already_AddRefed<Element> HTMLEditor::GetInputEventTargetElement() {
already_AddRefed<Element> HTMLEditor::GetInputEventTargetElement() const {
RefPtr<Element> target = GetActiveEditingHost();
return target.forget();
}

View File

@ -168,10 +168,10 @@ class HTMLEditor final : public TextEditor,
MOZ_CAN_RUN_SCRIPT virtual nsresult HandleKeyPressEvent(
WidgetKeyboardEvent* aKeyboardEvent) override;
virtual nsIContent* GetFocusedContent() override;
virtual already_AddRefed<nsIContent> GetFocusedContentForIME() override;
virtual bool IsActiveInDOMWindow() override;
virtual dom::EventTarget* GetDOMEventTarget() override;
virtual nsIContent* GetFocusedContent() const override;
virtual nsIContent* GetFocusedContentForIME() const override;
virtual bool IsActiveInDOMWindow() const override;
virtual dom::EventTarget* GetDOMEventTarget() const override;
virtual Element* FindSelectionRoot(nsINode* aNode) const override;
virtual bool IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent) override;
virtual nsresult GetPreferredIMEState(widget::IMEState* aState) override;
@ -1037,7 +1037,7 @@ class HTMLEditor final : public TextEditor,
*/
enum class SkipWhitespace { Yes, No };
nsIContent* GetPriorHTMLSibling(nsINode* aNode,
SkipWhitespace = SkipWhitespace::No);
SkipWhitespace = SkipWhitespace::No) const;
/**
* GetNextHTMLSibling() returns the next editable sibling, if there is
@ -1045,7 +1045,7 @@ class HTMLEditor final : public TextEditor,
* whitespace.
*/
nsIContent* GetNextHTMLSibling(nsINode* aNode,
SkipWhitespace = SkipWhitespace::No);
SkipWhitespace = SkipWhitespace::No) const;
// Helper for GetPriorHTMLSibling/GetNextHTMLSibling.
static bool SkippableWhitespace(nsINode* aNode, SkipWhitespace aSkipWS) {
@ -1058,20 +1058,20 @@ class HTMLEditor final : public TextEditor,
* EditorBase::GetPreviousElementOrText*() but this won't return nodes
* outside active editing host.
*/
nsIContent* GetPreviousHTMLElementOrText(nsINode& aNode) {
nsIContent* GetPreviousHTMLElementOrText(nsINode& aNode) const {
return GetPreviousHTMLElementOrTextInternal(aNode, false);
}
nsIContent* GetPreviousHTMLElementOrTextInBlock(nsINode& aNode) {
nsIContent* GetPreviousHTMLElementOrTextInBlock(nsINode& aNode) const {
return GetPreviousHTMLElementOrTextInternal(aNode, true);
}
template <typename PT, typename CT>
nsIContent* GetPreviousHTMLElementOrText(
const EditorDOMPointBase<PT, CT>& aPoint) {
const EditorDOMPointBase<PT, CT>& aPoint) const {
return GetPreviousHTMLElementOrTextInternal(aPoint, false);
}
template <typename PT, typename CT>
nsIContent* GetPreviousHTMLElementOrTextInBlock(
const EditorDOMPointBase<PT, CT>& aPoint) {
const EditorDOMPointBase<PT, CT>& aPoint) const {
return GetPreviousHTMLElementOrTextInternal(aPoint, true);
}
@ -1080,30 +1080,30 @@ class HTMLEditor final : public TextEditor,
* of above methods. Please don't use this method directly.
*/
nsIContent* GetPreviousHTMLElementOrTextInternal(nsINode& aNode,
bool aNoBlockCrossing);
bool aNoBlockCrossing) const;
template <typename PT, typename CT>
nsIContent* GetPreviousHTMLElementOrTextInternal(
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing);
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing) const;
/**
* GetPreviousEditableHTMLNode*() methods are similar to
* EditorBase::GetPreviousEditableNode() but this won't return nodes outside
* active editing host.
*/
nsIContent* GetPreviousEditableHTMLNode(nsINode& aNode) {
nsIContent* GetPreviousEditableHTMLNode(nsINode& aNode) const {
return GetPreviousEditableHTMLNodeInternal(aNode, false);
}
nsIContent* GetPreviousEditableHTMLNodeInBlock(nsINode& aNode) {
nsIContent* GetPreviousEditableHTMLNodeInBlock(nsINode& aNode) const {
return GetPreviousEditableHTMLNodeInternal(aNode, true);
}
template <typename PT, typename CT>
nsIContent* GetPreviousEditableHTMLNode(
const EditorDOMPointBase<PT, CT>& aPoint) {
const EditorDOMPointBase<PT, CT>& aPoint) const {
return GetPreviousEditableHTMLNodeInternal(aPoint, false);
}
template <typename PT, typename CT>
nsIContent* GetPreviousEditableHTMLNodeInBlock(
const EditorDOMPointBase<PT, CT>& aPoint) {
const EditorDOMPointBase<PT, CT>& aPoint) const {
return GetPreviousEditableHTMLNodeInternal(aPoint, true);
}
@ -1112,10 +1112,10 @@ class HTMLEditor final : public TextEditor,
* of above methods. Please don't use this method directly.
*/
nsIContent* GetPreviousEditableHTMLNodeInternal(nsINode& aNode,
bool aNoBlockCrossing);
bool aNoBlockCrossing) const;
template <typename PT, typename CT>
nsIContent* GetPreviousEditableHTMLNodeInternal(
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing);
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing) const;
/**
* GetNextHTMLElementOrText*() methods are similar to
@ -1127,20 +1127,20 @@ class HTMLEditor final : public TextEditor,
* On the other hand, methods which take |nsINode&| start to search from
* next node of aNode.
*/
nsIContent* GetNextHTMLElementOrText(nsINode& aNode) {
nsIContent* GetNextHTMLElementOrText(nsINode& aNode) const {
return GetNextHTMLElementOrTextInternal(aNode, false);
}
nsIContent* GetNextHTMLElementOrTextInBlock(nsINode& aNode) {
nsIContent* GetNextHTMLElementOrTextInBlock(nsINode& aNode) const {
return GetNextHTMLElementOrTextInternal(aNode, true);
}
template <typename PT, typename CT>
nsIContent* GetNextHTMLElementOrText(
const EditorDOMPointBase<PT, CT>& aPoint) {
const EditorDOMPointBase<PT, CT>& aPoint) const {
return GetNextHTMLElementOrTextInternal(aPoint, false);
}
template <typename PT, typename CT>
nsIContent* GetNextHTMLElementOrTextInBlock(
const EditorDOMPointBase<PT, CT>& aPoint) {
const EditorDOMPointBase<PT, CT>& aPoint) const {
return GetNextHTMLElementOrTextInternal(aPoint, true);
}
@ -1149,10 +1149,10 @@ class HTMLEditor final : public TextEditor,
* of above methods. Please don't use this method directly.
*/
nsIContent* GetNextHTMLElementOrTextInternal(nsINode& aNode,
bool aNoBlockCrossing);
bool aNoBlockCrossing) const;
template <typename PT, typename CT>
nsIContent* GetNextHTMLElementOrTextInternal(
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing);
const EditorDOMPointBase<PT, CT>& aPoint, bool aNoBlockCrossing) const;
/**
* GetNextEditableHTMLNode*() methods are similar to
@ -1196,8 +1196,8 @@ class HTMLEditor final : public TextEditor,
nsIContent* GetFirstEditableChild(nsINode& aNode) const;
nsIContent* GetLastEditableChild(nsINode& aNode) const;
nsIContent* GetFirstEditableLeaf(nsINode& aNode);
nsIContent* GetLastEditableLeaf(nsINode& aNode);
nsIContent* GetFirstEditableLeaf(nsINode& aNode) const;
nsIContent* GetLastEditableLeaf(nsINode& aNode) const;
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult GetInlinePropertyBase(
nsAtom& aHTMLProperty, nsAtom* aAttribute, const nsAString* aValue,
@ -3604,18 +3604,18 @@ class HTMLEditor final : public TextEditor,
virtual nsresult InstallEventListeners() override;
virtual void RemoveEventListeners() override;
bool ShouldReplaceRootElement();
bool ShouldReplaceRootElement() const;
MOZ_CAN_RUN_SCRIPT void NotifyRootChanged();
Element* GetBodyElement();
Element* GetBodyElement() const;
/**
* Get the focused node of this editor.
* @return If the editor has focus, this returns the focused node.
* Otherwise, returns null.
*/
already_AddRefed<nsINode> GetFocusedNode();
nsINode* GetFocusedNode() const;
virtual already_AddRefed<Element> GetInputEventTargetElement() override;
virtual already_AddRefed<Element> GetInputEventTargetElement() const override;
/**
* Return TRUE if aElement is a table-related elemet and caret was set.
@ -4155,7 +4155,7 @@ class HTMLEditor final : public TextEditor,
/**
* Whether the outer window of the DOM event target has focus or not.
*/
bool OurWindowHasFocus();
bool OurWindowHasFocus() const;
/**
* This function is used to insert a string of HTML input optionally with some

View File

@ -1427,7 +1427,7 @@ void TextEditor::OnCompositionEnd(
NotifyEditorObservers(eNotifyEditorObserversOfEnd);
}
already_AddRefed<Element> TextEditor::GetInputEventTargetElement() {
already_AddRefed<Element> TextEditor::GetInputEventTargetElement() const {
nsCOMPtr<Element> target = do_QueryInterface(mEventTarget);
return target.forget();
}
@ -2130,7 +2130,7 @@ nsresult TextEditor::SelectEntireDocument() {
return error.StealNSResult();
}
EventTarget* TextEditor::GetDOMEventTarget() { return mEventTarget; }
EventTarget* TextEditor::GetDOMEventTarget() const { return mEventTarget; }
nsresult TextEditor::SetAttributeOrEquivalent(Element* aElement,
nsAtom* aAttribute,

View File

@ -171,7 +171,7 @@ class TextEditor : public EditorBase, public nsITimerCallback, public nsINamed {
MOZ_CAN_RUN_SCRIPT virtual nsresult HandleKeyPressEvent(
WidgetKeyboardEvent* aKeyboardEvent) override;
virtual dom::EventTarget* GetDOMEventTarget() override;
virtual dom::EventTarget* GetDOMEventTarget() const override;
/**
* PasteAsAction() pastes clipboard content to Selection. This method
@ -825,7 +825,7 @@ class TextEditor : public EditorBase, public nsITimerCallback, public nsINamed {
*/
bool EnsureComposition(WidgetCompositionEvent& aCompositionEvent);
virtual already_AddRefed<Element> GetInputEventTargetElement() override;
virtual already_AddRefed<Element> GetInputEventTargetElement() const override;
/**
* See SetUnmaskRange() and SetUnmaskRangeAndNotify() for the detail.