From eea1784f2dba89c27828a70b3150e8fb5971a135 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Sun, 24 Nov 2019 05:38:02 +0000 Subject: [PATCH] Bug 1597679 - part 2: Make `nsITextControlElement` inherit `nsGenericHTMLFormElementWithState` r=smaug Sub classes of `nsITextControlElement` are only `HTMLInputElement` and `HTMLTextAreaElement`. And both base class is `nsGenericHTMLFormElementWithState`. Therefore, we can make `nsITextControlElement` inherit `nsGenericHTMLFormElementWithState` and make `HTMLInputElement` and `HTMLTextAreaElement` inherit `nsITextControlElement`. Then, we can get rid of a lot of QI between `nsINode`/`nsIContent`/`Element` and `nsITextControlElement` (and note that some of them in a hot path). Additionally, this patch renames `nsITextControlElement` to `mozilla::TextControlElement`. Differential Revision: https://phabricator.services.mozilla.com/D54330 --HG-- rename : dom/html/nsITextControlElement.h => dom/html/TextControlElement.h extra : moz-landing-system : lando --- accessible/generic/HyperTextAccessible.cpp | 1 - accessible/html/HTMLFormControlAccessible.cpp | 6 +- accessible/html/HTMLFormControlAccessible.h | 3 +- dom/base/Document.cpp | 14 +- dom/base/Document.h | 2 +- dom/base/Element.cpp | 7 +- dom/base/Element.h | 2 +- dom/base/nsContentAreaDragDrop.cpp | 14 +- dom/base/nsContentUtils.cpp | 4 +- dom/base/nsCopySupport.cpp | 2 +- dom/base/nsIContent.h | 1 - dom/base/nsINode.h | 2 + dom/events/EventStateManager.cpp | 1 - dom/events/WheelHandlingHelper.cpp | 6 +- dom/html/HTMLInputElement.cpp | 103 +++++------- dom/html/HTMLInputElement.h | 77 +++++---- dom/html/HTMLTextAreaElement.cpp | 101 ++++-------- dom/html/HTMLTextAreaElement.h | 70 ++++---- ...tControlElement.h => TextControlElement.h} | 110 +++++++------ dom/html/TextControlState.cpp | 155 +++++++++--------- dom/html/TextControlState.h | 18 +- dom/html/TextInputListener.h | 6 +- dom/html/moz.build | 2 +- dom/html/nsGenericHTMLElement.cpp | 1 - ...t_undo_redo_stack_after_setting_value.html | 2 +- .../spellcheck/src/mozInlineSpellChecker.cpp | 4 +- layout/forms/nsTextControlFrame.cpp | 148 +++++++++-------- layout/forms/nsTextControlFrame.h | 18 +- 28 files changed, 418 insertions(+), 462 deletions(-) rename dom/html/{nsITextControlElement.h => TextControlElement.h} (63%) diff --git a/accessible/generic/HyperTextAccessible.cpp b/accessible/generic/HyperTextAccessible.cpp index f15d4d70bd7b..5593333021f6 100644 --- a/accessible/generic/HyperTextAccessible.cpp +++ b/accessible/generic/HyperTextAccessible.cpp @@ -28,7 +28,6 @@ #include "nsPersistentProperties.h" #include "nsIScrollableFrame.h" #include "nsIServiceManager.h" -#include "nsITextControlElement.h" #include "nsIMathMLFrame.h" #include "nsRange.h" #include "nsTextFragment.h" diff --git a/accessible/html/HTMLFormControlAccessible.cpp b/accessible/html/HTMLFormControlAccessible.cpp index c7da3a0af52e..b0d76236c397 100644 --- a/accessible/html/HTMLFormControlAccessible.cpp +++ b/accessible/html/HTMLFormControlAccessible.cpp @@ -21,7 +21,6 @@ #include "nsIPersistentProperties2.h" #include "nsISelectionController.h" #include "nsIServiceManager.h" -#include "nsITextControlElement.h" #include "nsITextControlFrame.h" #include "nsNameSpaceManager.h" #include "mozilla/dom/ScriptSettings.h" @@ -29,6 +28,7 @@ #include "mozilla/EventStates.h" #include "mozilla/FloatingPoint.h" #include "mozilla/Preferences.h" +#include "mozilla/TextControlElement.h" #include "mozilla/TextEditor.h" using namespace mozilla; @@ -385,8 +385,8 @@ bool HTMLTextFieldAccessible::DoAction(uint8_t aIndex) const { } already_AddRefed HTMLTextFieldAccessible::GetEditor() const { - nsCOMPtr textControlElement = - do_QueryInterface(mContent); + RefPtr textControlElement = + TextControlElement::FromNodeOrNull(mContent); if (!textControlElement) { return nullptr; } diff --git a/accessible/html/HTMLFormControlAccessible.h b/accessible/html/HTMLFormControlAccessible.h index 9881b2c9946b..940d01fa0183 100644 --- a/accessible/html/HTMLFormControlAccessible.h +++ b/accessible/html/HTMLFormControlAccessible.h @@ -73,7 +73,8 @@ class HTMLTextFieldAccessible final : public HyperTextAccessibleWrap { HyperTextAccessibleWrap) // HyperTextAccessible - virtual already_AddRefed GetEditor() const override; + MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual already_AddRefed GetEditor() + const override; // Accessible virtual void Value(nsString& aValue) const override; diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 097d85b6f40d..62e59a53b97e 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -39,6 +39,7 @@ #include "mozilla/StaticPrefs_privacy.h" #include "mozilla/StaticPrefs_security.h" #include "mozilla/StorageAccess.h" +#include "mozilla/TextControlElement.h" #include "mozilla/TextEditor.h" #include "mozilla/URLDecorationStripper.h" #include "mozilla/URLExtraData.h" @@ -283,7 +284,6 @@ #include "nsDOMCaretPosition.h" #include "nsViewportInfo.h" #include "mozilla/StaticPtr.h" -#include "nsITextControlElement.h" #include "nsIHttpChannelInternal.h" #include "nsISecurityConsoleMessage.h" #include "nsCharSeparatedTokenizer.h" @@ -5009,14 +5009,12 @@ nsresult Document::TurnEditingOff() { // Editor resets selection since it is being destroyed. But if focus is // still into editable control, we have to initialize selection again. - nsFocusManager* fm = nsFocusManager::GetFocusManager(); - if (fm) { - Element* element = fm->GetFocusedElement(); - nsCOMPtr txtCtrl = do_QueryInterface(element); - if (txtCtrl) { - RefPtr textEditor = txtCtrl->GetTextEditor(); + if (nsFocusManager* fm = nsFocusManager::GetFocusManager()) { + if (RefPtr textControlElement = + TextControlElement::FromNodeOrNull(fm->GetFocusedElement())) { + RefPtr textEditor = textControlElement->GetTextEditor(); if (textEditor) { - textEditor->ReinitializeSelection(*element); + textEditor->ReinitializeSelection(*textControlElement); } } } diff --git a/dom/base/Document.h b/dom/base/Document.h index e341c8e1c681..07c36279f8c5 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -1892,7 +1892,7 @@ class Document : public nsINode, /* Midas implementation */ nsCommandManager* GetMidasCommandManager(); - nsresult TurnEditingOff(); + MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult TurnEditingOff(); // MOZ_CAN_RUN_SCRIPT_BOUNDARY because this is called from all sorts // of places, and I'm pretty sure the exact ExecCommand call it diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 96edd2baf806..c24a88d958b0 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -77,6 +77,7 @@ #include "mozilla/RestyleManager.h" #include "mozilla/ScrollTypes.h" #include "mozilla/SizeOfState.h" +#include "mozilla/TextControlElement.h" #include "mozilla/TextEditor.h" #include "mozilla/TextEvents.h" #include "mozilla/dom/DirectionalityUtils.h" @@ -133,7 +134,6 @@ #include "mozilla/dom/NodeListBinding.h" #include "nsStyledElement.h" -#include "nsITextControlElement.h" #include "nsITextControlFrame.h" #include "nsISupportsImpl.h" #include "mozilla/dom/CSSPseudoElement.h" @@ -3568,8 +3568,9 @@ void Element::InsertAdjacentText(const nsAString& aWhere, } TextEditor* Element::GetTextEditorInternal() { - nsCOMPtr textCtrl = do_QueryInterface(this); - return textCtrl ? textCtrl->GetTextEditor() : nullptr; + TextControlElement* textControlElement = TextControlElement::FromNode(this); + return textControlElement ? MOZ_KnownLive(textControlElement)->GetTextEditor() + : nullptr; } nsresult Element::SetBoolAttr(nsAtom* aAttr, bool aValue) { diff --git a/dom/base/Element.h b/dom/base/Element.h index 91c658839a98..598f8a718953 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -1501,7 +1501,7 @@ class Element : public FragmentOrElement { /** * Locate a TextEditor rooted at this content node, if there is one. */ - mozilla::TextEditor* GetTextEditorInternal(); + MOZ_CAN_RUN_SCRIPT_BOUNDARY mozilla::TextEditor* GetTextEditorInternal(); /** * Gets value of boolean attribute. Only works for attributes in null diff --git a/dom/base/nsContentAreaDragDrop.cpp b/dom/base/nsContentAreaDragDrop.cpp index c2bb8fd992b9..3cb87dad2bd9 100644 --- a/dom/base/nsContentAreaDragDrop.cpp +++ b/dom/base/nsContentAreaDragDrop.cpp @@ -31,7 +31,6 @@ #include "nsIContent.h" #include "nsIContentInlines.h" #include "nsIImageLoadingContent.h" -#include "nsITextControlElement.h" #include "nsUnicharUtils.h" #include "nsIURL.h" #include "nsIURIMutator.h" @@ -49,6 +48,7 @@ #include "nsIMIMEInfo.h" #include "nsRange.h" #include "BrowserParent.h" +#include "mozilla/TextControlElement.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/HTMLAreaElement.h" #include "mozilla/dom/HTMLAnchorElement.h" @@ -513,11 +513,11 @@ nsresult DragDataProducer::Produce(DataTransfer* aDataTransfer, bool* aCanDrag, nsIContent* editingElement = mSelectionTargetNode->IsEditable() ? mSelectionTargetNode->GetEditingHost() : nullptr; - nsCOMPtr textControl = - nsITextControlElement::GetTextControlElementFromEditingHost( - editingElement); - if (textControl) { - nsISelectionController* selcon = textControl->GetSelectionController(); + RefPtr textControlElement = + TextControlElement::GetTextControlElementFromEditingHost(editingElement); + if (textControlElement) { + nsISelectionController* selcon = + textControlElement->GetSelectionController(); if (selcon) { selection = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL); @@ -556,7 +556,7 @@ nsresult DragDataProducer::Produce(DataTransfer* aDataTransfer, bool* aCanDrag, return NS_OK; } - if (isChromeShell && textControl) { + if (isChromeShell && textControlElement) { // Only use the selection if the target node is in the selection. if (!selection->ContainsNode(*mSelectionTargetNode, false, IgnoreErrors())) return NS_OK; diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 1208ce14e19c..45a1156cfd6f 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -4087,9 +4087,7 @@ nsresult nsContentUtils::DispatchInputEvent(Element* aEventTargetElement, } #ifdef DEBUG else { - nsCOMPtr textControlElement = - do_QueryInterface(aEventTargetElement); - MOZ_ASSERT(!textControlElement, + MOZ_ASSERT(!aEventTargetElement->IsTextControlElement(), "The event target may have editor, but we've not known it yet."); } #endif // #ifdef DEBUG diff --git a/dom/base/nsCopySupport.cpp b/dom/base/nsCopySupport.cpp index ea09989b5352..86a14c72ed67 100644 --- a/dom/base/nsCopySupport.cpp +++ b/dom/base/nsCopySupport.cpp @@ -876,7 +876,7 @@ bool nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, // there is unmasked range but it's collapsed or it'll be masked // automatically, the selected password shouldn't be copied into the // clipboard. - if (HTMLInputElement* inputElement = + if (RefPtr inputElement = HTMLInputElement::FromNodeOrNull(sourceContent)) { if (TextEditor* textEditor = inputElement->GetTextEditor()) { if (textEditor->IsPasswordEditor() && diff --git a/dom/base/nsIContent.h b/dom/base/nsIContent.h index ceec46db93df..5f847a6f5d67 100644 --- a/dom/base/nsIContent.h +++ b/dom/base/nsIContent.h @@ -21,7 +21,6 @@ class nsAttrValue; class nsAttrName; class nsTextFragment; class nsIFrame; -class nsITextControlElement; namespace mozilla { class EventChainPreVisitor; diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index 03ad00ec2952..31d6b9471760 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -488,6 +488,8 @@ class nsINode : public mozilla::dom::EventTarget { */ bool IsElement() const { return GetBoolFlag(NodeIsElement); } + virtual bool IsTextControlElement() const { return false; } + /** * Return this node as an Element. Should only be used for nodes * for which IsElement() is true. This is defined inline in Element.h. diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 67e6f721ade7..e2a46af8f21b 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -53,7 +53,6 @@ #include "mozilla/dom/Document.h" #include "nsIFrame.h" #include "nsFrameLoaderOwner.h" -#include "nsITextControlElement.h" #include "nsIWidget.h" #include "nsPresContext.h" #include "nsGkAtoms.h" diff --git a/dom/events/WheelHandlingHelper.cpp b/dom/events/WheelHandlingHelper.cpp index b7d9c6dccf35..09f16ad6d704 100644 --- a/dom/events/WheelHandlingHelper.cpp +++ b/dom/events/WheelHandlingHelper.cpp @@ -15,6 +15,7 @@ #include "mozilla/PresShell.h" #include "mozilla/StaticPrefs_mousewheel.h" #include "mozilla/StaticPrefs_test.h" +#include "mozilla/TextControlElement.h" #include "mozilla/dom/WheelEventBinding.h" #include "nsCOMPtr.h" #include "nsContentUtils.h" @@ -23,7 +24,6 @@ #include "mozilla/dom/Document.h" #include "DocumentInlines.h" // for Document and HTMLBodyElement #include "nsIScrollableFrame.h" -#include "nsITextControlElement.h" #include "nsITimer.h" #include "nsPluginFrame.h" #include "nsPresContext.h" @@ -87,11 +87,11 @@ WheelHandlingUtils::GetDisregardedWheelScrollDirection(const nsIFrame* aFrame) { if (!content) { return Nothing(); } - nsCOMPtr ctrl = do_QueryInterface( + TextControlElement* textControlElement = TextControlElement::FromNodeOrNull( content->IsInNativeAnonymousSubtree() ? content->GetClosestNativeAnonymousSubtreeRootParent() : content); - if (!ctrl || !ctrl->IsSingleLineTextControl()) { + if (!textControlElement || !textControlElement->IsSingleLineTextControl()) { return Nothing(); } // Disregard scroll in the block-flow direction by mouse wheel on a diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index cb5930243682..edaa265a39fe 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -24,7 +24,6 @@ #include "nsCRTGlue.h" #include "nsQueryObject.h" -#include "nsITextControlElement.h" #include "nsIRadioVisitor.h" #include "InputType.h" @@ -945,8 +944,8 @@ static nsresult FireEventForAccessibility(HTMLInputElement* aTarget, HTMLInputElement::HTMLInputElement( already_AddRefed&& aNodeInfo, FromParser aFromParser, FromClone aFromClone) - : nsGenericHTMLFormElementWithState(std::move(aNodeInfo), aFromParser, - kInputDefaultType->value), + : TextControlElement(std::move(aNodeInfo), aFromParser, + kInputDefaultType->value), mAutocompleteAttrState(nsContentUtils::eAutocompleteAttrState_Unknown), mAutocompleteInfoState(nsContentUtils::eAutocompleteAttrState_Unknown), mDisabledChanged(false), @@ -1037,8 +1036,8 @@ TextControlState* HTMLInputElement::GetEditorState() const { NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLInputElement) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED( - HTMLInputElement, nsGenericHTMLFormElementWithState) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLInputElement, + TextControlElement) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mValidity) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mControllers) if (tmp->IsSingleLineTextControl(false)) { @@ -1050,8 +1049,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED( } NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED( - HTMLInputElement, nsGenericHTMLFormElementWithState) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLInputElement, + TextControlElement) NS_IMPL_CYCLE_COLLECTION_UNLINK(mValidity) NS_IMPL_CYCLE_COLLECTION_UNLINK(mControllers) if (tmp->IsSingleLineTextControl(false)) { @@ -1064,9 +1063,11 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED( // XXX should unlink more? NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED( - HTMLInputElement, nsGenericHTMLFormElementWithState, nsITextControlElement, - imgINotificationObserver, nsIImageLoadingContent, nsIConstraintValidation) +NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLInputElement, + TextControlElement, + imgINotificationObserver, + nsIImageLoadingContent, + nsIConstraintValidation) // nsINode @@ -2234,11 +2235,11 @@ TextEditor* HTMLInputElement::GetTextEditorFromState() { return nullptr; } -NS_IMETHODIMP_(TextEditor*) -HTMLInputElement::GetTextEditor() { return GetTextEditorFromState(); } +TextEditor* HTMLInputElement::GetTextEditor() { + return GetTextEditorFromState(); +} -NS_IMETHODIMP_(TextEditor*) -HTMLInputElement::GetTextEditorWithoutCreation() { +TextEditor* HTMLInputElement::GetTextEditorWithoutCreation() { TextControlState* state = GetEditorState(); if (!state) { return nullptr; @@ -2246,8 +2247,7 @@ HTMLInputElement::GetTextEditorWithoutCreation() { return state->GetTextEditorWithoutCreation(); } -NS_IMETHODIMP_(nsISelectionController*) -HTMLInputElement::GetSelectionController() { +nsISelectionController* HTMLInputElement::GetSelectionController() { TextControlState* state = GetEditorState(); if (state) { return state->GetSelectionController(); @@ -2263,8 +2263,7 @@ nsFrameSelection* HTMLInputElement::GetConstFrameSelection() { return nullptr; } -NS_IMETHODIMP -HTMLInputElement::BindToFrame(nsTextControlFrame* aFrame) { +nsresult HTMLInputElement::BindToFrame(nsTextControlFrame* aFrame) { TextControlState* state = GetEditorState(); if (state) { return state->BindToFrame(aFrame); @@ -2272,16 +2271,14 @@ HTMLInputElement::BindToFrame(nsTextControlFrame* aFrame) { return NS_ERROR_FAILURE; } -NS_IMETHODIMP_(void) -HTMLInputElement::UnbindFromFrame(nsTextControlFrame* aFrame) { +void HTMLInputElement::UnbindFromFrame(nsTextControlFrame* aFrame) { TextControlState* state = GetEditorState(); if (state && aFrame) { state->UnbindFromFrame(aFrame); } } -NS_IMETHODIMP -HTMLInputElement::CreateEditor() { +nsresult HTMLInputElement::CreateEditor() { TextControlState* state = GetEditorState(); if (state) { return state->PrepareEditor(); @@ -2289,16 +2286,14 @@ HTMLInputElement::CreateEditor() { return NS_ERROR_FAILURE; } -NS_IMETHODIMP_(void) -HTMLInputElement::UpdateOverlayTextVisibility(bool aNotify) { +void HTMLInputElement::UpdateOverlayTextVisibility(bool aNotify) { TextControlState* state = GetEditorState(); if (state) { state->UpdateOverlayTextVisibility(aNotify); } } -NS_IMETHODIMP_(bool) -HTMLInputElement::GetPlaceholderVisibility() { +bool HTMLInputElement::GetPlaceholderVisibility() { TextControlState* state = GetEditorState(); if (!state) { return false; @@ -2307,24 +2302,21 @@ HTMLInputElement::GetPlaceholderVisibility() { return state->GetPlaceholderVisibility(); } -NS_IMETHODIMP_(void) -HTMLInputElement::SetPreviewValue(const nsAString& aValue) { +void HTMLInputElement::SetPreviewValue(const nsAString& aValue) { TextControlState* state = GetEditorState(); if (state) { state->SetPreviewText(aValue, true); } } -NS_IMETHODIMP_(void) -HTMLInputElement::GetPreviewValue(nsAString& aValue) { +void HTMLInputElement::GetPreviewValue(nsAString& aValue) { TextControlState* state = GetEditorState(); if (state) { state->GetPreviewText(aValue); } } -NS_IMETHODIMP_(void) -HTMLInputElement::EnablePreview() { +void HTMLInputElement::EnablePreview() { if (mIsPreviewEnabled) { return; } @@ -2335,11 +2327,9 @@ HTMLInputElement::EnablePreview() { nsChangeHint_ReconstructFrame); } -NS_IMETHODIMP_(bool) -HTMLInputElement::IsPreviewEnabled() { return mIsPreviewEnabled; } +bool HTMLInputElement::IsPreviewEnabled() { return mIsPreviewEnabled; } -NS_IMETHODIMP_(bool) -HTMLInputElement::GetPreviewVisibility() { +bool HTMLInputElement::GetPreviewVisibility() { TextControlState* state = GetEditorState(); if (!state) { return false; @@ -2733,8 +2723,7 @@ nsresult HTMLInputElement::SetValueInternal(const nsAString& aValue, return NS_OK; } -NS_IMETHODIMP -HTMLInputElement::SetValueChanged(bool aValueChanged) { +nsresult HTMLInputElement::SetValueChanged(bool aValueChanged) { bool valueChangedBefore = mValueChanged; mValueChanged = aValueChanged; @@ -6716,21 +6705,17 @@ nsresult HTMLInputElement::GetValidationMessage(nsAString& aValidationMessage, return mInputType->GetValidationMessage(aValidationMessage, aType); } -NS_IMETHODIMP_(bool) -HTMLInputElement::IsSingleLineTextControl() const { +bool HTMLInputElement::IsSingleLineTextControl() const { return IsSingleLineTextControl(false); } -NS_IMETHODIMP_(bool) -HTMLInputElement::IsTextArea() const { return false; } +bool HTMLInputElement::IsTextArea() const { return false; } -NS_IMETHODIMP_(bool) -HTMLInputElement::IsPasswordTextControl() const { +bool HTMLInputElement::IsPasswordTextControl() const { return mType == NS_FORM_INPUT_PASSWORD; } -NS_IMETHODIMP_(int32_t) -HTMLInputElement::GetCols() { +int32_t HTMLInputElement::GetCols() { // Else we know (assume) it is an input with size attr const nsAttrValue* attr = GetParsedAttr(nsGkAtoms::size); if (attr && attr->Type() == nsAttrValue::eInteger) { @@ -6743,16 +6728,13 @@ HTMLInputElement::GetCols() { return DEFAULT_COLS; } -NS_IMETHODIMP_(int32_t) -HTMLInputElement::GetWrapCols() { +int32_t HTMLInputElement::GetWrapCols() { return 0; // only textarea's can have wrap cols } -NS_IMETHODIMP_(int32_t) -HTMLInputElement::GetRows() { return DEFAULT_ROWS; } +int32_t HTMLInputElement::GetRows() { return DEFAULT_ROWS; } -NS_IMETHODIMP_(void) -HTMLInputElement::GetDefaultValueFromContent(nsAString& aValue) { +void HTMLInputElement::GetDefaultValueFromContent(nsAString& aValue) { TextControlState* state = GetEditorState(); if (state) { GetDefaultValue(aValue); @@ -6764,28 +6746,24 @@ HTMLInputElement::GetDefaultValueFromContent(nsAString& aValue) { } } -NS_IMETHODIMP_(bool) -HTMLInputElement::ValueChanged() const { return mValueChanged; } +bool HTMLInputElement::ValueChanged() const { return mValueChanged; } -NS_IMETHODIMP_(void) -HTMLInputElement::GetTextEditorValue(nsAString& aValue, - bool aIgnoreWrap) const { +void HTMLInputElement::GetTextEditorValue(nsAString& aValue, + bool aIgnoreWrap) const { TextControlState* state = GetEditorState(); if (state) { state->GetValue(aValue, aIgnoreWrap); } } -NS_IMETHODIMP_(void) -HTMLInputElement::InitializeKeyboardEventListeners() { +void HTMLInputElement::InitializeKeyboardEventListeners() { TextControlState* state = GetEditorState(); if (state) { state->InitializeKeyboardEventListeners(); } } -NS_IMETHODIMP_(void) -HTMLInputElement::OnValueChanged(bool aNotify, ValueChangeKind aKind) { +void HTMLInputElement::OnValueChanged(bool aNotify, ValueChangeKind aKind) { if (aKind != ValueChangeKind::Internal) { mLastValueChangeWasInteractive = aKind == ValueChangeKind::UserInteraction; } @@ -6804,8 +6782,7 @@ HTMLInputElement::OnValueChanged(bool aNotify, ValueChangeKind aKind) { } } -NS_IMETHODIMP_(bool) -HTMLInputElement::HasCachedSelection() { +bool HTMLInputElement::HasCachedSelection() { bool isCached = false; TextControlState* state = GetEditorState(); if (state) { diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h index 1ff482f6b53e..d1cf3a41ee6b 100644 --- a/dom/html/HTMLInputElement.h +++ b/dom/html/HTMLInputElement.h @@ -9,6 +9,7 @@ #include "mozilla/Attributes.h" #include "mozilla/Decimal.h" +#include "mozilla/TextControlElement.h" #include "mozilla/TextControlState.h" #include "mozilla/UniquePtr.h" #include "mozilla/Variant.h" @@ -19,7 +20,6 @@ #include "mozilla/dom/UnionTypes.h" #include "nsGenericHTMLElement.h" #include "nsImageLoadingContent.h" -#include "nsITextControlElement.h" #include "nsITimer.h" #include "nsCOMPtr.h" #include "nsIConstraintValidation.h" @@ -117,9 +117,8 @@ class UploadLastDir final : public nsIObserver, public nsSupportsWeakReference { }; }; -class HTMLInputElement final : public nsGenericHTMLFormElementWithState, +class HTMLInputElement final : public TextControlElement, public nsImageLoadingContent, - public nsITextControlElement, public nsIConstraintValidation { friend class AfterSetFilesOrDirectoriesCallback; friend class DispatchChangeEventCallback; @@ -214,43 +213,42 @@ class HTMLInputElement final : public nsGenericHTMLFormElementWithState, virtual void RemoveStates(EventStates aStates) override; public: - // nsITextControlElement - NS_IMETHOD SetValueChanged(bool aValueChanged) override; - NS_IMETHOD_(bool) IsSingleLineTextControl() const override; - NS_IMETHOD_(bool) IsTextArea() const override; - NS_IMETHOD_(bool) IsPasswordTextControl() const override; - NS_IMETHOD_(int32_t) GetCols() override; - NS_IMETHOD_(int32_t) GetWrapCols() override; - NS_IMETHOD_(int32_t) GetRows() override; - NS_IMETHOD_(void) GetDefaultValueFromContent(nsAString& aValue) override; - NS_IMETHOD_(bool) ValueChanged() const override; - NS_IMETHOD_(void) - GetTextEditorValue(nsAString& aValue, bool aIgnoreWrap) const override; - NS_IMETHOD_(TextEditor*) GetTextEditor() override; - NS_IMETHOD_(TextEditor*) GetTextEditorWithoutCreation() override; - NS_IMETHOD_(nsISelectionController*) GetSelectionController() override; - NS_IMETHOD_(nsFrameSelection*) GetConstFrameSelection() override; - NS_IMETHOD_(TextControlState*) GetTextControlState() const override { + // TextControlElement + virtual nsresult SetValueChanged(bool aValueChanged) override; + virtual bool IsSingleLineTextControl() const override; + virtual bool IsTextArea() const override; + virtual bool IsPasswordTextControl() const override; + virtual int32_t GetCols() override; + virtual int32_t GetWrapCols() override; + virtual int32_t GetRows() override; + virtual void GetDefaultValueFromContent(nsAString& aValue) override; + virtual bool ValueChanged() const override; + virtual void GetTextEditorValue(nsAString& aValue, + bool aIgnoreWrap) const override; + MOZ_CAN_RUN_SCRIPT TextEditor* GetTextEditor() override; + virtual TextEditor* GetTextEditorWithoutCreation() override; + virtual nsISelectionController* GetSelectionController() override; + virtual nsFrameSelection* GetConstFrameSelection() override; + virtual TextControlState* GetTextControlState() const override { return GetEditorState(); } - NS_IMETHOD BindToFrame(nsTextControlFrame* aFrame) override; - MOZ_CAN_RUN_SCRIPT_BOUNDARY - NS_IMETHOD_(void) UnbindFromFrame(nsTextControlFrame* aFrame) override; - MOZ_CAN_RUN_SCRIPT_BOUNDARY - NS_IMETHOD CreateEditor() override; - NS_IMETHOD_(void) UpdateOverlayTextVisibility(bool aNotify) override; - NS_IMETHOD_(void) SetPreviewValue(const nsAString& aValue) override; - NS_IMETHOD_(void) GetPreviewValue(nsAString& aValue) override; - NS_IMETHOD_(void) EnablePreview() override; - NS_IMETHOD_(bool) IsPreviewEnabled() override; - NS_IMETHOD_(bool) GetPlaceholderVisibility() override; - NS_IMETHOD_(bool) GetPreviewVisibility() override; - NS_IMETHOD_(void) InitializeKeyboardEventListeners() override; - NS_IMETHOD_(void) OnValueChanged(bool aNotify, ValueChangeKind) override; + virtual nsresult BindToFrame(nsTextControlFrame* aFrame) override; + MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void UnbindFromFrame( + nsTextControlFrame* aFrame) override; + MOZ_CAN_RUN_SCRIPT virtual nsresult CreateEditor() override; + virtual void UpdateOverlayTextVisibility(bool aNotify) override; + virtual void SetPreviewValue(const nsAString& aValue) override; + virtual void GetPreviewValue(nsAString& aValue) override; + virtual void EnablePreview() override; + virtual bool IsPreviewEnabled() override; + virtual bool GetPlaceholderVisibility() override; + virtual bool GetPreviewVisibility() override; + virtual void InitializeKeyboardEventListeners() override; + virtual void OnValueChanged(bool aNotify, ValueChangeKind) override; virtual void GetValueFromSetRangeText(nsAString& aValue) override; - MOZ_CAN_RUN_SCRIPT_BOUNDARY - virtual nsresult SetValueFromSetRangeText(const nsAString& aValue) override; - NS_IMETHOD_(bool) HasCachedSelection() override; + MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual nsresult SetValueFromSetRangeText( + const nsAString& aValue) override; + virtual bool HasCachedSelection() override; // Methods for nsFormFillController so it can do selection operations on input // types the HTML spec doesn't support them on, like "email". @@ -291,8 +289,7 @@ class HTMLInputElement final : public nsGenericHTMLFormElementWithState, MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLInputElement, - nsGenericHTMLFormElementWithState) + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLInputElement, TextControlElement) static UploadLastDir* gUploadLastDir; // create and destroy the static UploadLastDir object for remembering @@ -871,7 +868,7 @@ class HTMLInputElement final : public nsGenericHTMLFormElementWithState, JS::Handle aGivenProto) override; // Pull IsSingleLineTextControl into our scope, otherwise it'd be hidden - // by the nsITextControlElement version. + // by the TextControlElement version. using nsGenericHTMLFormElementWithState::IsSingleLineTextControl; /** diff --git a/dom/html/HTMLTextAreaElement.cpp b/dom/html/HTMLTextAreaElement.cpp index 1075c84a7c66..7571c36ca97c 100644 --- a/dom/html/HTMLTextAreaElement.cpp +++ b/dom/html/HTMLTextAreaElement.cpp @@ -51,8 +51,7 @@ namespace dom { HTMLTextAreaElement::HTMLTextAreaElement( already_AddRefed&& aNodeInfo, FromParser aFromParser) - : nsGenericHTMLFormElementWithState(std::move(aNodeInfo), aFromParser, - NS_FORM_TEXTAREA), + : TextControlElement(std::move(aNodeInfo), aFromParser, NS_FORM_TEXTAREA), mValueChanged(false), mLastValueChangeWasInteractive(false), mHandlingSelect(false), @@ -82,8 +81,8 @@ HTMLTextAreaElement::~HTMLTextAreaElement() { NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTextAreaElement) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED( - HTMLTextAreaElement, nsGenericHTMLFormElementWithState) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTextAreaElement, + TextControlElement) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mValidity) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mControllers) if (tmp->mState) { @@ -91,8 +90,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED( } NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED( - HTMLTextAreaElement, nsGenericHTMLFormElementWithState) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLTextAreaElement, + TextControlElement) NS_IMPL_CYCLE_COLLECTION_UNLINK(mValidity) NS_IMPL_CYCLE_COLLECTION_UNLINK(mControllers) if (tmp->mState) { @@ -101,8 +100,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED( NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLTextAreaElement, - nsGenericHTMLFormElementWithState, - nsITextControlElement, + TextControlElement, nsIMutationObserver, nsIConstraintValidation) @@ -218,76 +216,64 @@ void HTMLTextAreaElement::GetValueInternal(nsAString& aValue, mState->GetValue(aValue, aIgnoreWrap); } -NS_IMETHODIMP_(TextEditor*) -HTMLTextAreaElement::GetTextEditor() { +TextEditor* HTMLTextAreaElement::GetTextEditor() { MOZ_ASSERT(mState); return mState->GetTextEditor(); } -NS_IMETHODIMP_(TextEditor*) -HTMLTextAreaElement::GetTextEditorWithoutCreation() { +TextEditor* HTMLTextAreaElement::GetTextEditorWithoutCreation() { MOZ_ASSERT(mState); return mState->GetTextEditorWithoutCreation(); } -NS_IMETHODIMP_(nsISelectionController*) -HTMLTextAreaElement::GetSelectionController() { +nsISelectionController* HTMLTextAreaElement::GetSelectionController() { MOZ_ASSERT(mState); return mState->GetSelectionController(); } -NS_IMETHODIMP_(nsFrameSelection*) -HTMLTextAreaElement::GetConstFrameSelection() { +nsFrameSelection* HTMLTextAreaElement::GetConstFrameSelection() { MOZ_ASSERT(mState); return mState->GetConstFrameSelection(); } -NS_IMETHODIMP -HTMLTextAreaElement::BindToFrame(nsTextControlFrame* aFrame) { +nsresult HTMLTextAreaElement::BindToFrame(nsTextControlFrame* aFrame) { MOZ_ASSERT(mState); return mState->BindToFrame(aFrame); } -NS_IMETHODIMP_(void) -HTMLTextAreaElement::UnbindFromFrame(nsTextControlFrame* aFrame) { +void HTMLTextAreaElement::UnbindFromFrame(nsTextControlFrame* aFrame) { MOZ_ASSERT(mState); if (aFrame) { mState->UnbindFromFrame(aFrame); } } -NS_IMETHODIMP -HTMLTextAreaElement::CreateEditor() { +nsresult HTMLTextAreaElement::CreateEditor() { MOZ_ASSERT(mState); return mState->PrepareEditor(); } -NS_IMETHODIMP_(void) -HTMLTextAreaElement::UpdateOverlayTextVisibility(bool aNotify) { +void HTMLTextAreaElement::UpdateOverlayTextVisibility(bool aNotify) { MOZ_ASSERT(mState); mState->UpdateOverlayTextVisibility(aNotify); } -NS_IMETHODIMP_(bool) -HTMLTextAreaElement::GetPlaceholderVisibility() { +bool HTMLTextAreaElement::GetPlaceholderVisibility() { MOZ_ASSERT(mState); return mState->GetPlaceholderVisibility(); } -NS_IMETHODIMP_(void) -HTMLTextAreaElement::SetPreviewValue(const nsAString& aValue) { +void HTMLTextAreaElement::SetPreviewValue(const nsAString& aValue) { MOZ_ASSERT(mState); mState->SetPreviewText(aValue, true); } -NS_IMETHODIMP_(void) -HTMLTextAreaElement::GetPreviewValue(nsAString& aValue) { +void HTMLTextAreaElement::GetPreviewValue(nsAString& aValue) { MOZ_ASSERT(mState); mState->GetPreviewText(aValue); } -NS_IMETHODIMP_(void) -HTMLTextAreaElement::EnablePreview() { +void HTMLTextAreaElement::EnablePreview() { if (mIsPreviewEnabled) { return; } @@ -298,11 +284,9 @@ HTMLTextAreaElement::EnablePreview() { nsChangeHint_ReconstructFrame); } -NS_IMETHODIMP_(bool) -HTMLTextAreaElement::IsPreviewEnabled() { return mIsPreviewEnabled; } +bool HTMLTextAreaElement::IsPreviewEnabled() { return mIsPreviewEnabled; } -NS_IMETHODIMP_(bool) -HTMLTextAreaElement::GetPreviewVisibility() { +bool HTMLTextAreaElement::GetPreviewVisibility() { MOZ_ASSERT(mState); return mState->GetPreviewVisibility(); } @@ -360,8 +344,7 @@ void HTMLTextAreaElement::SetUserInput(const nsAString& aValue, TextControlState::eSetValue_MoveCursorToEndIfValueChanged); } -NS_IMETHODIMP -HTMLTextAreaElement::SetValueChanged(bool aValueChanged) { +nsresult HTMLTextAreaElement::SetValueChanged(bool aValueChanged) { MOZ_ASSERT(mState); bool previousValue = mValueChanged; @@ -1083,23 +1066,18 @@ nsresult HTMLTextAreaElement::GetValidationMessage( return rv; } -NS_IMETHODIMP_(bool) -HTMLTextAreaElement::IsSingleLineTextControl() const { return false; } +bool HTMLTextAreaElement::IsSingleLineTextControl() const { return false; } -NS_IMETHODIMP_(bool) -HTMLTextAreaElement::IsTextArea() const { return true; } +bool HTMLTextAreaElement::IsTextArea() const { return true; } -NS_IMETHODIMP_(bool) -HTMLTextAreaElement::IsPasswordTextControl() const { return false; } +bool HTMLTextAreaElement::IsPasswordTextControl() const { return false; } -NS_IMETHODIMP_(int32_t) -HTMLTextAreaElement::GetCols() { return Cols(); } +int32_t HTMLTextAreaElement::GetCols() { return Cols(); } -NS_IMETHODIMP_(int32_t) -HTMLTextAreaElement::GetWrapCols() { +int32_t HTMLTextAreaElement::GetWrapCols() { nsHTMLTextWrap wrapProp; - nsITextControlElement::GetWrapPropertyEnum(this, wrapProp); - if (wrapProp == nsITextControlElement::eHTMLTextWrap_Off) { + TextControlElement::GetWrapPropertyEnum(this, wrapProp); + if (wrapProp == TextControlElement::eHTMLTextWrap_Off) { // do not wrap when wrap=off return 0; } @@ -1108,8 +1086,7 @@ HTMLTextAreaElement::GetWrapCols() { return GetCols(); } -NS_IMETHODIMP_(int32_t) -HTMLTextAreaElement::GetRows() { +int32_t HTMLTextAreaElement::GetRows() { const nsAttrValue* attr = GetParsedAttr(nsGkAtoms::rows); if (attr && attr->Type() == nsAttrValue::eInteger) { int32_t rows = attr->GetIntegerValue(); @@ -1119,29 +1096,24 @@ HTMLTextAreaElement::GetRows() { return DEFAULT_ROWS_TEXTAREA; } -NS_IMETHODIMP_(void) -HTMLTextAreaElement::GetDefaultValueFromContent(nsAString& aValue) { +void HTMLTextAreaElement::GetDefaultValueFromContent(nsAString& aValue) { GetDefaultValue(aValue, IgnoreErrors()); } -NS_IMETHODIMP_(bool) -HTMLTextAreaElement::ValueChanged() const { return mValueChanged; } +bool HTMLTextAreaElement::ValueChanged() const { return mValueChanged; } -NS_IMETHODIMP_(void) -HTMLTextAreaElement::GetTextEditorValue(nsAString& aValue, - bool aIgnoreWrap) const { +void HTMLTextAreaElement::GetTextEditorValue(nsAString& aValue, + bool aIgnoreWrap) const { MOZ_ASSERT(mState); mState->GetValue(aValue, aIgnoreWrap); } -NS_IMETHODIMP_(void) -HTMLTextAreaElement::InitializeKeyboardEventListeners() { +void HTMLTextAreaElement::InitializeKeyboardEventListeners() { MOZ_ASSERT(mState); mState->InitializeKeyboardEventListeners(); } -NS_IMETHODIMP_(void) -HTMLTextAreaElement::OnValueChanged(bool aNotify, ValueChangeKind aKind) { +void HTMLTextAreaElement::OnValueChanged(bool aNotify, ValueChangeKind aKind) { if (aKind != ValueChangeKind::Internal) { mLastValueChangeWasInteractive = aKind == ValueChangeKind::UserInteraction; } @@ -1158,8 +1130,7 @@ HTMLTextAreaElement::OnValueChanged(bool aNotify, ValueChangeKind aKind) { } } -NS_IMETHODIMP_(bool) -HTMLTextAreaElement::HasCachedSelection() { +bool HTMLTextAreaElement::HasCachedSelection() { MOZ_ASSERT(mState); return mState->IsSelectionCached(); } diff --git a/dom/html/HTMLTextAreaElement.h b/dom/html/HTMLTextAreaElement.h index d1e6e49c5884..4bae95caa9d3 100644 --- a/dom/html/HTMLTextAreaElement.h +++ b/dom/html/HTMLTextAreaElement.h @@ -8,11 +8,11 @@ #define mozilla_dom_HTMLTextAreaElement_h #include "mozilla/Attributes.h" +#include "mozilla/TextControlElement.h" #include "mozilla/TextControlState.h" #include "mozilla/TextEditor.h" #include "mozilla/dom/HTMLFormElement.h" #include "mozilla/dom/HTMLInputElementBinding.h" -#include "nsITextControlElement.h" #include "nsIControllers.h" #include "nsCOMPtr.h" #include "nsGenericHTMLElement.h" @@ -34,8 +34,7 @@ namespace dom { class HTMLFormSubmission; -class HTMLTextAreaElement final : public nsGenericHTMLFormElementWithState, - public nsITextControlElement, +class HTMLTextAreaElement final : public TextControlElement, public nsStubMutationObserver, public nsIConstraintValidation { public: @@ -69,43 +68,42 @@ class HTMLTextAreaElement final : public nsGenericHTMLFormElementWithState, virtual EventStates IntrinsicState() const override; - // nsITextControlElemet - NS_IMETHOD SetValueChanged(bool aValueChanged) override; - NS_IMETHOD_(bool) IsSingleLineTextControl() const override; - NS_IMETHOD_(bool) IsTextArea() const override; - NS_IMETHOD_(bool) IsPasswordTextControl() const override; - NS_IMETHOD_(int32_t) GetCols() override; - NS_IMETHOD_(int32_t) GetWrapCols() override; - NS_IMETHOD_(int32_t) GetRows() override; - NS_IMETHOD_(void) GetDefaultValueFromContent(nsAString& aValue) override; - NS_IMETHOD_(bool) ValueChanged() const override; - NS_IMETHOD_(void) - GetTextEditorValue(nsAString& aValue, bool aIgnoreWrap) const override; - NS_IMETHOD_(TextEditor*) GetTextEditor() override; - NS_IMETHOD_(TextEditor*) GetTextEditorWithoutCreation() override; - NS_IMETHOD_(nsISelectionController*) GetSelectionController() override; - NS_IMETHOD_(nsFrameSelection*) GetConstFrameSelection() override; - NS_IMETHOD_(TextControlState*) GetTextControlState() const override { + // TextControlElement + virtual nsresult SetValueChanged(bool aValueChanged) override; + virtual bool IsSingleLineTextControl() const override; + virtual bool IsTextArea() const override; + virtual bool IsPasswordTextControl() const override; + virtual int32_t GetCols() override; + virtual int32_t GetWrapCols() override; + virtual int32_t GetRows() override; + virtual void GetDefaultValueFromContent(nsAString& aValue) override; + virtual bool ValueChanged() const override; + virtual void GetTextEditorValue(nsAString& aValue, + bool aIgnoreWrap) const override; + MOZ_CAN_RUN_SCRIPT virtual TextEditor* GetTextEditor() override; + virtual TextEditor* GetTextEditorWithoutCreation() override; + virtual nsISelectionController* GetSelectionController() override; + virtual nsFrameSelection* GetConstFrameSelection() override; + virtual TextControlState* GetTextControlState() const override { return mState; } - NS_IMETHOD BindToFrame(nsTextControlFrame* aFrame) override; - MOZ_CAN_RUN_SCRIPT_BOUNDARY - NS_IMETHOD_(void) UnbindFromFrame(nsTextControlFrame* aFrame) override; - MOZ_CAN_RUN_SCRIPT_BOUNDARY - NS_IMETHOD CreateEditor() override; - NS_IMETHOD_(void) UpdateOverlayTextVisibility(bool aNotify) override; - NS_IMETHOD_(bool) GetPlaceholderVisibility() override; - NS_IMETHOD_(bool) GetPreviewVisibility() override; - NS_IMETHOD_(void) SetPreviewValue(const nsAString& aValue) override; - NS_IMETHOD_(void) GetPreviewValue(nsAString& aValue) override; - NS_IMETHOD_(void) EnablePreview() override; - NS_IMETHOD_(bool) IsPreviewEnabled() override; - NS_IMETHOD_(void) InitializeKeyboardEventListeners() override; - NS_IMETHOD_(void) OnValueChanged(bool aNotify, ValueChangeKind) override; + virtual nsresult BindToFrame(nsTextControlFrame* aFrame) override; + MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void UnbindFromFrame( + nsTextControlFrame* aFrame) override; + MOZ_CAN_RUN_SCRIPT virtual nsresult CreateEditor() override; + virtual void UpdateOverlayTextVisibility(bool aNotify) override; + virtual bool GetPlaceholderVisibility() override; + virtual bool GetPreviewVisibility() override; + virtual void SetPreviewValue(const nsAString& aValue) override; + virtual void GetPreviewValue(nsAString& aValue) override; + virtual void EnablePreview() override; + virtual bool IsPreviewEnabled() override; + virtual void InitializeKeyboardEventListeners() override; + virtual void OnValueChanged(bool aNotify, ValueChangeKind) override; virtual void GetValueFromSetRangeText(nsAString& aValue) override; MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual nsresult SetValueFromSetRangeText(const nsAString& aValue) override; - NS_IMETHOD_(bool) HasCachedSelection() override; + virtual bool HasCachedSelection() override; // nsIContent virtual nsresult BindToTree(BindContext&, nsINode& aParent) override; @@ -149,7 +147,7 @@ class HTMLTextAreaElement final : public nsGenericHTMLFormElementWithState, NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTextAreaElement, - nsGenericHTMLFormElementWithState) + TextControlElement) // nsIConstraintValidation bool IsTooLong(); diff --git a/dom/html/nsITextControlElement.h b/dom/html/TextControlElement.h similarity index 63% rename from dom/html/nsITextControlElement.h rename to dom/html/TextControlElement.h index 5d1d18db086b..453f04dbd6b2 100644 --- a/dom/html/nsITextControlElement.h +++ b/dom/html/TextControlElement.h @@ -4,12 +4,13 @@ * 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/. */ -#ifndef nsITextControlElement_h___ -#define nsITextControlElement_h___ +#ifndef mozilla_TextControlElement_h +#define mozilla_TextControlElement_h + +#include "mozilla/dom/FromParser.h" +#include "mozilla/dom/NodeInfo.h" +#include "nsGenericHTMLElement.h" -#include "nsISupports.h" -#include "nsCOMPtr.h" -#include "nsStringFwd.h" class nsIContent; class nsISelectionController; class nsFrameSelection; @@ -21,76 +22,74 @@ class ErrorResult; class TextControlState; class TextEditor; -namespace dom { -class Element; -} // namespace dom -} // namespace mozilla - -// IID for the nsITextControl interface -#define NS_ITEXTCONTROLELEMENT_IID \ - { \ - 0x3df7db6d, 0xa548, 0x4e20, { \ - 0x97, 0xfd, 0x75, 0xa3, 0x31, 0xa2, 0xf3, 0xd4 \ - } \ - } - /** - * This interface is used for the text control frame to get the editor and + * This abstract class is used for the text control frame to get the editor and * selection controller objects, and some helper properties. */ -class nsITextControlElement : public nsISupports { +class TextControlElement : public nsGenericHTMLFormElementWithState { public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITEXTCONTROLELEMENT_IID) + TextControlElement(already_AddRefed&& aNodeInfo, + dom::FromParser aFromParser, uint8_t aType) + : nsGenericHTMLFormElementWithState(std::move(aNodeInfo), aFromParser, + aType){}; + + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextControlElement, + nsGenericHTMLFormElementWithState) + + bool IsTextControlElement() const final { return true; } + + NS_IMPL_FROMNODE_HELPER(TextControlElement, IsTextControlElement()) /** * Tell the control that value has been deliberately changed (or not). */ - NS_IMETHOD SetValueChanged(bool changed) = 0; + virtual nsresult SetValueChanged(bool changed) = 0; /** * Find out whether this is a single line text control. (text or password) * @return whether this is a single line text control */ - NS_IMETHOD_(bool) IsSingleLineTextControl() const = 0; + virtual bool IsSingleLineTextControl() const = 0; /** * Find out whether this control is a textarea. * @return whether this is a textarea text control */ - NS_IMETHOD_(bool) IsTextArea() const = 0; + virtual bool IsTextArea() const = 0; /** * Find out whether this is a password control (input type=password) * @return whether this is a password ontrol */ - NS_IMETHOD_(bool) IsPasswordTextControl() const = 0; + virtual bool IsPasswordTextControl() const = 0; /** * Get the cols attribute (if textarea) or a default * @return the number of columns to use */ - NS_IMETHOD_(int32_t) GetCols() = 0; + virtual int32_t GetCols() = 0; /** * Get the column index to wrap at, or -1 if we shouldn't wrap */ - NS_IMETHOD_(int32_t) GetWrapCols() = 0; + virtual int32_t GetWrapCols() = 0; /** * Get the rows attribute (if textarea) or a default * @return the number of rows to use */ - NS_IMETHOD_(int32_t) GetRows() = 0; + virtual int32_t GetRows() = 0; /** * Get the default value of the text control */ - NS_IMETHOD_(void) GetDefaultValueFromContent(nsAString& aValue) = 0; + virtual void GetDefaultValueFromContent(nsAString& aValue) = 0; /** * Return true if the value of the control has been changed. */ - NS_IMETHOD_(bool) ValueChanged() const = 0; + virtual bool ValueChanged() const = 0; /** * Get the current value of the text editor. @@ -99,8 +98,8 @@ class nsITextControlElement : public nsISupports { * @param aIgnoreWrap whether to ignore the text wrapping behavior specified * for the element. */ - NS_IMETHOD_(void) - GetTextEditorValue(nsAString& aValue, bool aIgnoreWrap) const = 0; + virtual void GetTextEditorValue(nsAString& aValue, + bool aIgnoreWrap) const = 0; /** * Get the editor object associated with the text editor. @@ -110,79 +109,80 @@ class nsITextControlElement : public nsISupports { * If you need editor only when the editor is there, you should use * GetTextEditorWithoutCreation(). */ - NS_IMETHOD_(mozilla::TextEditor*) GetTextEditor() = 0; - NS_IMETHOD_(mozilla::TextEditor*) GetTextEditorWithoutCreation() = 0; + MOZ_CAN_RUN_SCRIPT virtual TextEditor* GetTextEditor() = 0; + virtual TextEditor* GetTextEditorWithoutCreation() = 0; /** * Get the selection controller object associated with the text editor. * The return value is null if the control does not support an editor * (for example, if it is a checkbox.) */ - NS_IMETHOD_(nsISelectionController*) GetSelectionController() = 0; + virtual nsISelectionController* GetSelectionController() = 0; - NS_IMETHOD_(nsFrameSelection*) GetConstFrameSelection() = 0; + virtual nsFrameSelection* GetConstFrameSelection() = 0; - NS_IMETHOD_(mozilla::TextControlState*) GetTextControlState() const = 0; + virtual TextControlState* GetTextControlState() const = 0; /** * Binds a frame to the text control. This is performed when a frame * is created for the content node. */ - NS_IMETHOD BindToFrame(nsTextControlFrame* aFrame) = 0; + virtual nsresult BindToFrame(nsTextControlFrame* aFrame) = 0; /** * Unbinds a frame from the text control. This is performed when a frame * belonging to a content node is destroyed. */ - NS_IMETHOD_(void) UnbindFromFrame(nsTextControlFrame* aFrame) = 0; + MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void UnbindFromFrame( + nsTextControlFrame* aFrame) = 0; /** * Creates an editor for the text control. This should happen when * a frame has been created for the text control element, but the created * editor may outlive the frame itself. */ - NS_IMETHOD CreateEditor() = 0; + MOZ_CAN_RUN_SCRIPT virtual nsresult CreateEditor() = 0; /** * Update preview value for the text control. */ - NS_IMETHOD_(void) SetPreviewValue(const nsAString& aValue) = 0; + virtual void SetPreviewValue(const nsAString& aValue) = 0; /** * Get the current preview value for text control. */ - NS_IMETHOD_(void) GetPreviewValue(nsAString& aValue) = 0; + virtual void GetPreviewValue(nsAString& aValue) = 0; /** * Enable preview for text control. */ - NS_IMETHOD_(void) EnablePreview() = 0; + virtual void EnablePreview() = 0; /** * Find out whether this control enables preview for form autofoll. */ - NS_IMETHOD_(bool) IsPreviewEnabled() = 0; + virtual bool IsPreviewEnabled() = 0; /** * Initialize the keyboard event listeners. */ - NS_IMETHOD_(void) InitializeKeyboardEventListeners() = 0; + virtual void InitializeKeyboardEventListeners() = 0; /** * Update the visibility of both the placholder and preview text based on the * element's state. */ - NS_IMETHOD_(void) UpdateOverlayTextVisibility(bool aNotify) = 0; + virtual void UpdateOverlayTextVisibility(bool aNotify) = 0; /** * Returns the current expected placeholder visibility state. */ - NS_IMETHOD_(bool) GetPlaceholderVisibility() = 0; + virtual bool GetPlaceholderVisibility() = 0; /** * Returns the current expected preview visibility state. */ - NS_IMETHOD_(bool) GetPreviewVisibility() = 0; + virtual bool GetPreviewVisibility() = 0; enum class ValueChangeKind { Internal, @@ -193,8 +193,7 @@ class nsITextControlElement : public nsISupports { /** * Callback called whenever the value is changed. */ - NS_IMETHOD_(void) - OnValueChanged(bool aNotify, ValueChangeKind) = 0; + virtual void OnValueChanged(bool aNotify, ValueChangeKind) = 0; /** * Helpers for value manipulation from SetRangeText. @@ -223,12 +222,15 @@ class nsITextControlElement : public nsISupports { * Note that this function has the side effect of making the editor for input * elements be initialized eagerly. */ - NS_IMETHOD_(bool) HasCachedSelection() = 0; + virtual bool HasCachedSelection() = 0; - static already_AddRefed + static already_AddRefed GetTextControlElementFromEditingHost(nsIContent* aHost); + + protected: + virtual ~TextControlElement() = default; }; -NS_DEFINE_STATIC_IID_ACCESSOR(nsITextControlElement, NS_ITEXTCONTROLELEMENT_IID) +} // namespace mozilla -#endif // nsITextControlElement_h___ +#endif // mozilla_TextControlElement_h diff --git a/dom/html/TextControlState.cpp b/dom/html/TextControlState.cpp index cb2de848121c..af6abb2a7253 100644 --- a/dom/html/TextControlState.cpp +++ b/dom/html/TextControlState.cpp @@ -49,13 +49,30 @@ #include "mozilla/KeyEventHandler.h" #include "mozilla/dom/KeyboardEvent.h" +namespace mozilla { + +using namespace dom; + /***************************************************************************** - * nsITextControlElement + * TextControlElement *****************************************************************************/ +NS_IMPL_CYCLE_COLLECTION_CLASS(TextControlElement) + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED( + TextControlElement, nsGenericHTMLFormElementWithState) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED( + TextControlElement, nsGenericHTMLFormElementWithState) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0( + TextControlElement, nsGenericHTMLFormElementWithState) + /*static*/ -bool nsITextControlElement::GetWrapPropertyEnum( - nsIContent* aContent, nsITextControlElement::nsHTMLTextWrap& aWrapProp) { +bool TextControlElement::GetWrapPropertyEnum( + nsIContent* aContent, TextControlElement::nsHTMLTextWrap& aWrapProp) { // soft is the default; "physical" defaults to soft as well because all other // browsers treat it that way and there is no real reason to maintain physical // and virtual as separate entities if no one else does. Only hard and off @@ -82,23 +99,18 @@ bool nsITextControlElement::GetWrapPropertyEnum( } /*static*/ -already_AddRefed -nsITextControlElement::GetTextControlElementFromEditingHost(nsIContent* aHost) { +already_AddRefed +TextControlElement::GetTextControlElementFromEditingHost(nsIContent* aHost) { if (!aHost) { return nullptr; } - nsCOMPtr parent = - do_QueryInterface(aHost->GetParent()); - + RefPtr parent = + TextControlElement::FromNodeOrNull(aHost->GetParent()); return parent.forget(); } -namespace mozilla { - -using namespace dom; - -using ValueChangeKind = nsITextControlElement::ValueChangeKind; +using ValueChangeKind = TextControlElement::ValueChangeKind; inline nsresult SetEditorFlagsIfNecessary(EditorBase& aEditorBase, uint32_t aFlags) { @@ -793,7 +805,7 @@ nsresult TextInputSelectionController::CheckVisibilityContent( * mozilla::TextInputListener *****************************************************************************/ -TextInputListener::TextInputListener(nsITextControlElement* aTxtCtrlElement) +TextInputListener::TextInputListener(TextControlElement* aTxtCtrlElement) : mFrame(nullptr), mTxtCtrlElement(aTxtCtrlElement), mTextControlState(aTxtCtrlElement ? aTxtCtrlElement->GetTextControlState() @@ -949,8 +961,8 @@ TextInputListener::HandleEvent(Event* aEvent) { // XXX Do we execute only one handler even if the handler neither stops // propagation nor prevents default of the event? - nsCOMPtr target = do_QueryInterface(mTxtCtrlElement); - nsresult rv = handler->ExecuteHandler(target, aEvent); + RefPtr textControlElement(mTxtCtrlElement); + nsresult rv = handler->ExecuteHandler(textControlElement, aEvent); if (NS_SUCCEEDED(rv)) { return rv; } @@ -1271,9 +1283,7 @@ class MOZ_STACK_CLASS AutoTextControlHandlingState { } return mParent ? mParent->IsHandling(aTextControlAction) : false; } - nsITextControlElement* GetTextControlElement() const { - return mTextCtrlElement; - } + TextControlElement* GetTextControlElement() const { return mTextCtrlElement; } TextInputListener* GetTextInputListener() const { return mTextInputListener; } uint32_t GetSetValueFlags() const { MOZ_ASSERT(Is(TextControlAction::SetValue)); @@ -1317,7 +1327,7 @@ class MOZ_STACK_CLASS AutoTextControlHandlingState { // mTextCtrlElement grabs TextControlState::mTextCtrlElement since // if the text control element releases mTextControlState, only this // can guarantee the instance of the text control element. - nsCOMPtr const mTextCtrlElement; + RefPtr const mTextCtrlElement; // mTextInputListener grabs TextControlState::mTextListener because if // TextControlState is unbind from the frame, it's released. RefPtr const mTextInputListener; @@ -1338,7 +1348,7 @@ AutoTArray* TextControlState::sReleasedInstances = nullptr; bool TextControlState::sHasShutDown = false; -TextControlState::TextControlState(nsITextControlElement* aOwningElement) +TextControlState::TextControlState(TextControlElement* aOwningElement) : mTextCtrlElement(aOwningElement), mBoundFrame(nullptr), mEverInited(false), @@ -1357,7 +1367,7 @@ TextControlState::TextControlState(nsITextControlElement* aOwningElement) } TextControlState* TextControlState::Construct( - nsITextControlElement* aOwningElement) { + TextControlElement* aOwningElement) { if (sReleasedInstances && !sReleasedInstances->IsEmpty()) { TextControlState* state = sReleasedInstances->LastElement(); sReleasedInstances->RemoveLastElement(); @@ -1581,8 +1591,7 @@ nsresult TextControlState::BindToFrame(nsTextControlFrame* aFrame) { // If an editor exists from before, prepare it for usage if (mTextEditor) { - nsCOMPtr content = do_QueryInterface(mTextCtrlElement); - if (NS_WARN_IF(!content)) { + if (NS_WARN_IF(!mTextCtrlElement)) { return NS_ERROR_FAILURE; } @@ -1598,7 +1607,7 @@ nsresult TextControlState::BindToFrame(nsTextControlFrame* aFrame) { } nsContentUtils::AddScriptRunner( - new PrepareEditorEvent(*this, content, currentValue)); + new PrepareEditorEvent(*this, mTextCtrlElement, currentValue)); } return NS_OK; @@ -1644,6 +1653,9 @@ nsresult TextControlState::PrepareEditor(const nsAString* aValue) { return NS_ERROR_NOT_INITIALIZED; } } + + MOZ_ASSERT(mTextCtrlElement); + AutoTextControlHandlingState preparingEditor( *this, TextControlAction::PrepareEditor); @@ -1751,16 +1763,15 @@ nsresult TextControlState::PrepareEditor(const nsAString* aValue) { if (!SuppressEventHandlers(presContext)) { nsCOMPtr controllers; - nsCOMPtr content = do_QueryInterface(mTextCtrlElement); - HTMLInputElement* inputElement = HTMLInputElement::FromNodeOrNull(content); - if (inputElement) { + if (HTMLInputElement* inputElement = + HTMLInputElement::FromNodeOrNull(mTextCtrlElement)) { rv = inputElement->GetControllers(getter_AddRefs(controllers)); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } } else { HTMLTextAreaElement* textAreaElement = - HTMLTextAreaElement::FromNodeOrNull(content); + HTMLTextAreaElement::FromNodeOrNull(mTextCtrlElement); if (!textAreaElement) { return NS_ERROR_FAILURE; } @@ -1804,28 +1815,26 @@ nsresult TextControlState::PrepareEditor(const nsAString* aValue) { // Set max text field length newTextEditor->SetMaxTextLength(GetMaxLength()); - if (nsCOMPtr element = do_QueryInterface(mTextCtrlElement)) { - editorFlags = newTextEditor->Flags(); + editorFlags = newTextEditor->Flags(); - // Check if the readonly attribute is set. - if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::readonly)) { - editorFlags |= nsIPlaintextEditor::eEditorReadonlyMask; - } - - // Check if the disabled attribute is set. - // TODO: call IsDisabled() here! - if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) { - editorFlags |= nsIPlaintextEditor::eEditorDisabledMask; - } - - // Disable the selection if necessary. - if (newTextEditor->IsDisabled()) { - mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_OFF); - } - - SetEditorFlagsIfNecessary(*newTextEditor, editorFlags); + // Check if the readonly attribute is set. + if (mTextCtrlElement->HasAttr(kNameSpaceID_None, nsGkAtoms::readonly)) { + editorFlags |= nsIPlaintextEditor::eEditorReadonlyMask; } + // Check if the disabled attribute is set. + // TODO: call IsDisabled() here! + if (mTextCtrlElement->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) { + editorFlags |= nsIPlaintextEditor::eEditorDisabledMask; + } + + // Disable the selection if necessary. + if (newTextEditor->IsDisabled()) { + mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_OFF); + } + + SetEditorFlagsIfNecessary(*newTextEditor, editorFlags); + if (shouldInitializeEditor) { // Hold on to the newly created editor preDestroyer.Swap(mTextEditor); @@ -1872,7 +1881,7 @@ nsresult TextControlState::PrepareEditor(const nsAString* aValue) { "Failed to disable undo/redo transaction"); } else { DebugOnly enabledUndoRedo = - newTextEditor->EnableUndoRedo(nsITextControlElement::DEFAULT_UNDO_CAP); + newTextEditor->EnableUndoRedo(TextControlElement::DEFAULT_UNDO_CAP); NS_WARNING_ASSERTION(enabledUndoRedo, "Failed to enable undo/redo transaction"); } @@ -2072,9 +2081,8 @@ void TextControlState::SetSelectionRange( if (changed) { // It sure would be nice if we had an existing Element* or so to work with. - nsCOMPtr node = do_QueryInterface(mTextCtrlElement); RefPtr asyncDispatcher = - new AsyncEventDispatcher(node, NS_LITERAL_STRING("select"), + new AsyncEventDispatcher(mTextCtrlElement, NS_LITERAL_STRING("select"), CanBubble::eYes, ChromeOnlyDispatch::eNo); asyncDispatcher->PostDOMEvent(); } @@ -2390,13 +2398,12 @@ void TextControlState::UnbindFromFrame(nsTextControlFrame* aFrame) { // Clean up the controller if (!SuppressEventHandlers(mBoundFrame->PresContext())) { nsCOMPtr controllers; - nsCOMPtr content = do_QueryInterface(mTextCtrlElement); - HTMLInputElement* inputElement = HTMLInputElement::FromNodeOrNull(content); - if (inputElement) { + if (HTMLInputElement* inputElement = + HTMLInputElement::FromNodeOrNull(mTextCtrlElement)) { inputElement->GetControllers(getter_AddRefs(controllers)); } else { HTMLTextAreaElement* textAreaElement = - HTMLTextAreaElement::FromNodeOrNull(content); + HTMLTextAreaElement::FromNodeOrNull(mTextCtrlElement); if (textAreaElement) { textAreaElement->GetControllers(getter_AddRefs(controllers)); } @@ -2433,8 +2440,8 @@ void TextControlState::UnbindFromFrame(nsTextControlFrame* aFrame) { if (mTextListener) { mTextListener->SetFrame(nullptr); - nsCOMPtr target = do_QueryInterface(mTextCtrlElement); - EventListenerManager* manager = target->GetExistingListenerManager(); + EventListenerManager* manager = + mTextCtrlElement->GetExistingListenerManager(); if (manager) { manager->RemoveEventListenerByType(mTextListener, NS_LITERAL_STRING("keydown"), @@ -2463,13 +2470,12 @@ void TextControlState::UnbindFromFrame(nsTextControlFrame* aFrame) { } int32_t TextControlState::GetMaxLength() { - nsCOMPtr content = do_QueryInterface(mTextCtrlElement); - nsGenericHTMLElement* element = nsGenericHTMLElement::FromNodeOrNull(content); - if (NS_WARN_IF(!element)) { + if (NS_WARN_IF(!mTextCtrlElement)) { return -1; } - const nsAttrValue* attr = element->GetParsedAttr(nsGkAtoms::maxlength); + const nsAttrValue* attr = + mTextCtrlElement->GetParsedAttr(nsGkAtoms::maxlength); return attr && attr->Type() == nsAttrValue::eInteger ? attr->GetIntegerValue() : -1; } @@ -2502,11 +2508,10 @@ void TextControlState::GetValue(nsAString& aValue, bool aIgnoreWrap) const { nsIDocumentEncoder::OutputPersistNBSP | nsIDocumentEncoder::OutputBodyOnly); if (!aIgnoreWrap) { - nsITextControlElement::nsHTMLTextWrap wrapProp; - nsCOMPtr content = do_QueryInterface(mTextCtrlElement); - if (content && - nsITextControlElement::GetWrapPropertyEnum(content, wrapProp) && - wrapProp == nsITextControlElement::eHTMLTextWrap_Hard) { + TextControlElement::nsHTMLTextWrap wrapProp; + if (mTextCtrlElement && + TextControlElement::GetWrapPropertyEnum(mTextCtrlElement, wrapProp) && + wrapProp == TextControlElement::eHTMLTextWrap_Hard) { flags |= nsIDocumentEncoder::OutputWrap; } } @@ -2885,12 +2890,11 @@ bool TextControlState::SetValueWithoutTextEditor( // the user operation which changes editor value with a built-in function // like autocomplete, password manager, session restore, etc. if (aHandlingSetValue.GetSetValueFlags() & eSetValue_BySetUserInput) { - nsCOMPtr element = - do_QueryInterface(aHandlingSetValue.GetTextControlElement()); - MOZ_ASSERT(element); + MOZ_ASSERT(aHandlingSetValue.GetTextControlElement()); MOZ_ASSERT(!aHandlingSetValue.GetSettingValue().IsVoid()); DebugOnly rvIgnored = nsContentUtils::DispatchInputEvent( - element, EditorInputType::eInsertReplacementText, nullptr, + MOZ_KnownLive(aHandlingSetValue.GetTextControlElement()), + EditorInputType::eInsertReplacementText, nullptr, nsContentUtils::InputEventOptions( aHandlingSetValue.GetSettingValue())); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), @@ -2929,8 +2933,8 @@ bool TextControlState::HasNonEmptyValue() { void TextControlState::InitializeKeyboardEventListeners() { // register key listeners - nsCOMPtr target = do_QueryInterface(mTextCtrlElement); - EventListenerManager* manager = target->GetOrCreateListenerManager(); + EventListenerManager* manager = + mTextCtrlElement->GetOrCreateListenerManager(); if (manager) { manager->AddEventListenerByType(mTextListener, NS_LITERAL_STRING("keydown"), TrustedEventsAtSystemGroupBubble()); @@ -2988,8 +2992,8 @@ void TextControlState::UpdateOverlayTextVisibility(bool aNotify) { mPlaceholderVisibility = valueIsEmpty && previewValue.IsEmpty(); if (mPlaceholderVisibility && !StaticPrefs::dom_placeholder_show_on_focus()) { - nsCOMPtr content = do_QueryInterface(mTextCtrlElement); - mPlaceholderVisibility = !nsContentUtils::IsFocusedContent(content); + mPlaceholderVisibility = + !nsContentUtils::IsFocusedContent(mTextCtrlElement); } if (mBoundFrame && aNotify) { @@ -2999,8 +3003,7 @@ void TextControlState::UpdateOverlayTextVisibility(bool aNotify) { void TextControlState::HideSelectionIfBlurred() { MOZ_ASSERT(mSelCon, "Should have a selection controller if we have a frame!"); - nsCOMPtr content = do_QueryInterface(mTextCtrlElement); - if (!nsContentUtils::IsFocusedContent(content)) { + if (!nsContentUtils::IsFocusedContent(mTextCtrlElement)) { mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_HIDDEN); } } diff --git a/dom/html/TextControlState.h b/dom/html/TextControlState.h index ac10d827e0fa..b3f1f32a78ce 100644 --- a/dom/html/TextControlState.h +++ b/dom/html/TextControlState.h @@ -8,22 +8,20 @@ #define mozilla_TextControlState_h #include "mozilla/Assertions.h" -#include "nsString.h" -#include "nsITextControlElement.h" -#include "nsITextControlFrame.h" -#include "nsCycleCollectionParticipant.h" -#include "mozilla/dom/Element.h" #include "mozilla/Attributes.h" #include "mozilla/Maybe.h" +#include "mozilla/TextControlElement.h" #include "mozilla/TextEditor.h" #include "mozilla/WeakPtr.h" +#include "mozilla/dom/Element.h" #include "mozilla/dom/HTMLInputElementBinding.h" #include "mozilla/dom/Nullable.h" +#include "nsCycleCollectionParticipant.h" +#include "nsITextControlFrame.h" class nsTextControlFrame; class nsISelectionController; class nsFrameSelection; -class nsITextControlElement; class nsFrame; namespace mozilla { @@ -50,7 +48,7 @@ class HTMLInputElement; * * This class is held as a member of HTMLInputElement and HTMLTextAreaElement. * The public functions in this class include the public APIs which dom/ - * uses. Layout code uses the nsITextControlElement interface to invoke + * uses. Layout code uses the TextControlElement interface to invoke * functions on this class. * * The design motivation behind this class is maintaining all of the things @@ -141,7 +139,7 @@ class TextControlState final : public SupportsWeakPtr { MOZ_DECLARE_WEAKREFERENCE_TYPENAME(TextControlState) - static TextControlState* Construct(nsITextControlElement* aOwningElement); + static TextControlState* Construct(TextControlElement* aOwningElement); static void Shutdown(); @@ -383,7 +381,7 @@ class TextControlState final : public SupportsWeakPtr { } private: - explicit TextControlState(nsITextControlElement* aOwningElement); + explicit TextControlState(TextControlElement* aOwningElement); MOZ_CAN_RUN_SCRIPT_BOUNDARY ~TextControlState(); /** @@ -444,7 +442,7 @@ class TextControlState final : public SupportsWeakPtr { // The text control element owns this object, and ensures that this object // has a smaller lifetime except the owner releases the instance while it // does something with this. - nsITextControlElement* MOZ_NON_OWNING_REF mTextCtrlElement; + TextControlElement* MOZ_NON_OWNING_REF mTextCtrlElement; RefPtr mSelCon; RefPtr mRestoringSelection; RefPtr mTextEditor; diff --git a/dom/html/TextInputListener.h b/dom/html/TextInputListener.h index 9e3c52586d91..205ebe103dee 100644 --- a/dom/html/TextInputListener.h +++ b/dom/html/TextInputListener.h @@ -14,10 +14,10 @@ #include "nsWeakReference.h" class nsIFrame; -class nsITextControlElement; class nsTextControlFrame; namespace mozilla { +class TextControlElement; class TextControlState; namespace dom { @@ -27,7 +27,7 @@ class Selection; class TextInputListener final : public nsIDOMEventListener, public nsSupportsWeakReference { public: - explicit TextInputListener(nsITextControlElement* aTextControlElement); + explicit TextInputListener(TextControlElement* aTextControlElement); void SetFrame(nsIFrame* aTextControlFrame) { mFrame = aTextControlFrame; } void SettingValue(bool aValue) { mSettingValue = aValue; } @@ -73,7 +73,7 @@ class TextInputListener final : public nsIDOMEventListener, protected: nsIFrame* mFrame; - nsITextControlElement* const mTxtCtrlElement; + TextControlElement* const mTxtCtrlElement; WeakPtr const mTextControlState; bool mSelectionWasCollapsed; diff --git a/dom/html/moz.build b/dom/html/moz.build index a0feae03c78a..95d03565132b 100644 --- a/dom/html/moz.build +++ b/dom/html/moz.build @@ -40,10 +40,10 @@ EXPORTS += [ 'nsIHTMLCollection.h', 'nsIRadioGroupContainer.h', 'nsIRadioVisitor.h', - 'nsITextControlElement.h', ] EXPORTS.mozilla += [ + 'TextControlElement.h', 'TextControlState.h', 'TextInputListener.h', ] diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 141252a455fb..926d40f66ee9 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -74,7 +74,6 @@ #include "nsLayoutUtils.h" #include "mozAutoDocUpdate.h" #include "nsHtml5Module.h" -#include "nsITextControlElement.h" #include "mozilla/dom/ElementInlines.h" #include "HTMLFieldSetElement.h" #include "nsTextNode.h" diff --git a/editor/libeditor/tests/test_undo_redo_stack_after_setting_value.html b/editor/libeditor/tests/test_undo_redo_stack_after_setting_value.html index f529cfe20bc5..bc6b033664fd 100644 --- a/editor/libeditor/tests/test_undo_redo_stack_after_setting_value.html +++ b/editor/libeditor/tests/test_undo_redo_stack_after_setting_value.html @@ -79,7 +79,7 @@ SimpleTest.waitForFocus(function() { let transactionManager = editor.transactionManager; is(transactionManager.numberOfUndoItems, 2, editableElement.tagName + ": Initially, there should be 2 undo items"); - // Defined as nsITextControlElement::DEFAULT_UNDO_CAP + // Defined as TextControlElement::DEFAULT_UNDO_CAP is(transactionManager.maxTransactionCount, 1000, editableElement.tagName + ": Initially, transaction manager should be able to have 1,000 undo items"); diff --git a/extensions/spellcheck/src/mozInlineSpellChecker.cpp b/extensions/spellcheck/src/mozInlineSpellChecker.cpp index c3e00a3995b3..07216479fa06 100644 --- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp +++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp @@ -64,7 +64,6 @@ #include "nsRange.h" #include "nsContentUtils.h" #include "nsIObserverService.h" -#include "nsITextControlElement.h" #include "prtime.h" using namespace mozilla; @@ -1088,8 +1087,7 @@ bool mozInlineSpellChecker::ShouldSpellCheckNode(TextEditor* aTextEditor, while (node && node->IsInNativeAnonymousSubtree()) { node = node->GetParent(); } - nsCOMPtr textControl = do_QueryInterface(node); - if (textControl) { + if (node && node->IsTextControlElement()) { return true; } } diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index 493bf534026d..9e1eb0cb8301 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -132,9 +132,10 @@ void nsTextControlFrame::DestroyFrom(nsIFrame* aDestructRoot, // Unbind the text editor state object from the frame. The editor will live // on, but things like controllers will be released. - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - NS_ASSERTION(txtCtrl, "Content not a text control element"); - txtCtrl->UnbindFromFrame(this); + RefPtr textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); + textControlElement->UnbindFromFrame(this); nsCheckboxRadioFrame::RegUnRegAccessKey(static_cast(this), false); @@ -258,13 +259,14 @@ nsresult nsTextControlFrame::EnsureEditorInitialized() { // Make sure that editor init doesn't do things that would kill us off // (especially off the script blockers it'll create for its DOM mutations). { - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - MOZ_ASSERT(txtCtrl, "Content not a text control element"); + RefPtr textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); // Hide selection changes during the initialization, as webpages should not // be aware of these initializations AutoHideSelectionChanges hideSelectionChanges( - txtCtrl->GetConstFrameSelection()); + textControlElement->GetConstFrameSelection()); nsAutoScriptBlocker scriptBlocker; @@ -296,7 +298,7 @@ nsresult nsTextControlFrame::EnsureEditorInitialized() { #endif // Create an editor for the frame, if one doesn't already exist - nsresult rv = txtCtrl->CreateEditor(); + nsresult rv = textControlElement->CreateEditor(); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_STATE(weakFrame.IsAlive()); @@ -309,9 +311,9 @@ nsresult nsTextControlFrame::EnsureEditorInitialized() { // Set the selection to the end of the text field (bug 1287655), // but only if the contents has changed (bug 1337392). - if (txtCtrl->ValueChanged()) { + if (textControlElement->ValueChanged()) { nsAutoString val; - txtCtrl->GetTextEditorValue(val, true); + textControlElement->GetTextEditorValue(val, true); position = val.Length(); } @@ -405,14 +407,14 @@ nsresult nsTextControlFrame::CreateAnonymousContent( AddStateBits(NS_FRAME_INDEPENDENT_SELECTION); - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - MOZ_ASSERT(txtCtrl, "Content not a text control element"); - + RefPtr textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); nsresult rv = CreateRootNode(); NS_ENSURE_SUCCESS(rv, rv); // Bind the frame to its text control - rv = txtCtrl->BindToFrame(this); + rv = textControlElement->BindToFrame(this); NS_ENSURE_SUCCESS(rv, rv); aElements.AppendElement(mRootNode); @@ -422,7 +424,7 @@ nsresult nsTextControlFrame::CreateAnonymousContent( // For textareas, UpdateValueDisplay doesn't initialize the visibility // status of the placeholder because it returns early, so we have to // do that manually here. - txtCtrl->UpdateOverlayTextVisibility(true); + textControlElement->UpdateOverlayTextVisibility(true); } aElements.AppendElement(mPlaceholderDiv); } @@ -446,8 +448,10 @@ bool nsTextControlFrame::ShouldInitializeEagerly() const { // Also, input elements which have a cached selection should get eager // editor initialization. - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - if (txtCtrl->HasCachedSelection()) { + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); + if (textControlElement->HasCachedSelection()) { return true; } @@ -508,8 +512,10 @@ void nsTextControlFrame::CreatePlaceholderIfNeeded() { } void nsTextControlFrame::CreatePreviewIfNeeded() { - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - if (!txtCtrl->IsPreviewEnabled()) { + RefPtr textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); + if (!textControlElement->IsPreviewEnabled()) { return; } @@ -693,10 +699,11 @@ bool nsTextControlFrame::IsXULCollapsed() { NS_IMETHODIMP nsTextControlFrame::ScrollOnFocusEvent::Run() { if (mFrame) { - nsCOMPtr txtCtrl = - do_QueryInterface(mFrame->GetContent()); - NS_ASSERTION(txtCtrl, "Content not a text control element"); - nsISelectionController* selCon = txtCtrl->GetSelectionController(); + TextControlElement* textControlElement = + TextControlElement::FromNode(mFrame->GetContent()); + MOZ_ASSERT(textControlElement); + nsISelectionController* selCon = + textControlElement->GetSelectionController(); if (selCon) { mFrame->mScrollEvent.Forget(); selCon->ScrollSelectionIntoView( @@ -710,8 +717,9 @@ nsTextControlFrame::ScrollOnFocusEvent::Run() { // IMPLEMENTING NS_IFORMCONTROLFRAME void nsTextControlFrame::SetFocus(bool aOn, bool aRepaint) { - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - NS_ASSERTION(txtCtrl, "Content not a text control element"); + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); // Revoke the previous scroll event if one exists mScrollEvent.Revoke(); @@ -719,14 +727,14 @@ void nsTextControlFrame::SetFocus(bool aOn, bool aRepaint) { // If 'dom.placeholeder.show_on_focus' preference is 'false', focusing or // blurring the frame can have an impact on the placeholder visibility. if (mPlaceholderDiv) { - txtCtrl->UpdateOverlayTextVisibility(true); + textControlElement->UpdateOverlayTextVisibility(true); } if (!aOn) { return; } - nsISelectionController* selCon = txtCtrl->GetSelectionController(); + nsISelectionController* selCon = textControlElement->GetSelectionController(); if (!selCon) { return; } @@ -814,9 +822,10 @@ nsTextControlFrame::GetTextEditor() { return nullptr; } - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - MOZ_ASSERT(txtCtrl, "Content not a text control element"); - RefPtr textEditor = txtCtrl->GetTextEditor(); + RefPtr textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); + RefPtr textEditor = textControlElement->GetTextEditor(); return textEditor.forget(); } @@ -840,9 +849,10 @@ nsresult nsTextControlFrame::SetSelectionInternal( NS_ENSURE_SUCCESS(rv, rv); // Get the selection, clear it and add the new range to it! - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - NS_ASSERTION(txtCtrl, "Content not a text control element"); - nsISelectionController* selCon = txtCtrl->GetSelectionController(); + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); + nsISelectionController* selCon = textControlElement->GetSelectionController(); NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE); RefPtr selection = @@ -874,9 +884,10 @@ nsresult nsTextControlFrame::SetSelectionInternal( } nsresult nsTextControlFrame::ScrollSelectionIntoView() { - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - NS_ASSERTION(txtCtrl, "Content not a text control element"); - nsISelectionController* selCon = txtCtrl->GetSelectionController(); + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); + nsISelectionController* selCon = textControlElement->GetSelectionController(); if (selCon) { // Scroll the selection into view (see bug 231389). return selCon->ScrollSelectionIntoView( @@ -1035,9 +1046,10 @@ nsresult nsTextControlFrame::OffsetToDOMPoint(uint32_t aOffset, nsresult nsTextControlFrame::AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute, int32_t aModType) { - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - NS_ASSERTION(txtCtrl, "Content not a text control element"); - nsISelectionController* selCon = txtCtrl->GetSelectionController(); + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); + nsISelectionController* selCon = textControlElement->GetSelectionController(); const bool needEditor = nsGkAtoms::maxlength == aAttribute || nsGkAtoms::readonly == aAttribute || nsGkAtoms::disabled == aAttribute || nsGkAtoms::spellcheck == aAttribute; @@ -1112,11 +1124,12 @@ nsresult nsTextControlFrame::AttributeChanged(int32_t aNameSpaceID, } void nsTextControlFrame::GetText(nsString& aText) { - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - NS_ASSERTION(txtCtrl, "Content not a text control element"); + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); if (IsSingleLineTextControl()) { // There will be no line breaks so we can ignore the wrap property. - txtCtrl->GetTextEditorValue(aText, true); + textControlElement->GetTextEditorValue(aText, true); } else { HTMLTextAreaElement* textArea = HTMLTextAreaElement::FromNode(mContent); if (textArea) { @@ -1158,9 +1171,10 @@ void nsTextControlFrame::SetInitialChildList(ChildListID aListID, if (nsIFrame* first = PrincipalChildList().FirstChild()) { first->AddStateBits(NS_FRAME_REFLOW_ROOT); - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - NS_ASSERTION(txtCtrl, "Content not a text control element"); - txtCtrl->InitializeKeyboardEventListeners(); + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); + textControlElement->InitializeKeyboardEventListeners(); nsPoint* contentScrollPos = GetProperty(ContentScrollPos()); if (contentScrollPos) { @@ -1179,22 +1193,19 @@ void nsTextControlFrame::SetInitialChildList(ChildListID aListID, } void nsTextControlFrame::SetValueChanged(bool aValueChanged) { - nsCOMPtr txtCtrl = - HTMLInputElement::FromNode(GetContent()); - if (!txtCtrl) { - txtCtrl = HTMLTextAreaElement::FromNode(GetContent()); - } - MOZ_ASSERT(txtCtrl, "Content not a text control element"); + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); if (mPlaceholderDiv) { AutoWeakFrame weakFrame(this); - txtCtrl->UpdateOverlayTextVisibility(true); + textControlElement->UpdateOverlayTextVisibility(true); if (!weakFrame.IsAlive()) { return; } } - txtCtrl->SetValueChanged(aValueChanged); + textControlElement->SetValueChanged(aValueChanged); } nsresult nsTextControlFrame::UpdateValueDisplay(bool aNotify, @@ -1226,15 +1237,16 @@ nsresult nsTextControlFrame::UpdateValueDisplay(bool aNotify, NS_ENSURE_TRUE(textContent, NS_ERROR_UNEXPECTED); - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - MOZ_ASSERT(txtCtrl); + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); // Get the current value of the textfield from the content. nsAutoString value; if (aValue) { value = *aValue; } else { - txtCtrl->GetTextEditorValue(value, true); + textControlElement->GetTextEditorValue(value, true); } // Update the display of the placeholder value and preview text if needed. @@ -1242,7 +1254,7 @@ nsresult nsTextControlFrame::UpdateValueDisplay(bool aNotify, // EnsureEditorInitialized takes care of this. if ((mPlaceholderDiv || mPreviewDiv) && !aBeforeEditorInit) { AutoWeakFrame weakFrame(this); - txtCtrl->UpdateOverlayTextVisibility(aNotify); + textControlElement->UpdateOverlayTextVisibility(aNotify); NS_ENSURE_STATE(weakFrame.IsAlive()); } @@ -1262,20 +1274,21 @@ nsTextControlFrame::GetOwnedSelectionController( nsISelectionController** aSelCon) { NS_ENSURE_ARG_POINTER(aSelCon); - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - NS_ASSERTION(txtCtrl, "Content not a text control element"); + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); - *aSelCon = txtCtrl->GetSelectionController(); + *aSelCon = textControlElement->GetSelectionController(); NS_IF_ADDREF(*aSelCon); return NS_OK; } nsFrameSelection* nsTextControlFrame::GetOwnedFrameSelection() { - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - NS_ASSERTION(txtCtrl, "Content not a text control element"); - - return txtCtrl->GetConstFrameSelection(); + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); + return textControlElement->GetConstFrameSelection(); } UniquePtr nsTextControlFrame::SaveState() { @@ -1325,8 +1338,9 @@ void nsTextControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, */ DO_GLOBAL_REFLOW_COUNT_DSP("nsTextControlFrame"); - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); - NS_ASSERTION(txtCtrl, "Content not a text control element!"); + TextControlElement* textControlElement = + TextControlElement::FromNode(GetContent()); + MOZ_ASSERT(textControlElement); DisplayBorderBackgroundOutline(aBuilder, aLists); @@ -1341,9 +1355,9 @@ void nsTextControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, // If the frame is the placeholder or preview frame, we should only show // it if it has to be visible. if (!((kid->GetContent() == mPlaceholderDiv && - !txtCtrl->GetPlaceholderVisibility()) || + !textControlElement->GetPlaceholderVisibility()) || (kid->GetContent() == mPreviewDiv && - !txtCtrl->GetPreviewVisibility()))) { + !textControlElement->GetPreviewVisibility()))) { BuildDisplayListForChild(aBuilder, kid, set, 0); } kid = kid->GetNextSibling(); diff --git a/layout/forms/nsTextControlFrame.h b/layout/forms/nsTextControlFrame.h index 8e45b0b7ca12..4565b5bb9ae2 100644 --- a/layout/forms/nsTextControlFrame.h +++ b/layout/forms/nsTextControlFrame.h @@ -8,12 +8,12 @@ #define nsTextControlFrame_h___ #include "mozilla/Attributes.h" +#include "mozilla/TextControlElement.h" #include "mozilla/dom/Element.h" #include "nsContainerFrame.h" #include "nsIAnonymousContentCreator.h" #include "nsIContent.h" #include "nsITextControlFrame.h" -#include "nsITextControlElement.h" #include "nsIStatefulFrame.h" class nsISelectionController; @@ -130,7 +130,8 @@ class nsTextControlFrame final : public nsContainerFrame, //==== NSITEXTCONTROLFRAME - NS_IMETHOD_(already_AddRefed) GetTextEditor() override; + MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD_(already_AddRefed) + GetTextEditor() override; NS_IMETHOD SetSelectionRange(uint32_t aSelectionStart, uint32_t aSelectionEnd, SelectionDirection aDirection = eNone) override; NS_IMETHOD GetOwnedSelectionController( @@ -142,7 +143,8 @@ class nsTextControlFrame final : public nsContainerFrame, * @throws NS_ERROR_NOT_INITIALIZED if mEditor has not been created * @throws various and sundry other things */ - virtual nsresult EnsureEditorInitialized() override; + MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual nsresult EnsureEditorInitialized() + override; //==== END NSITEXTCONTROLFRAME @@ -185,11 +187,11 @@ class nsTextControlFrame final : public nsContainerFrame, nsresult MaybeBeginSecureKeyboardInput(); void MaybeEndSecureKeyboardInput(); -#define DEFINE_TEXTCTRL_CONST_FORWARDER(type, name) \ - type name() const { \ - nsCOMPtr txtCtrl = do_QueryInterface(GetContent()); \ - NS_ASSERTION(txtCtrl, "Content not a text control element"); \ - return txtCtrl->name(); \ +#define DEFINE_TEXTCTRL_CONST_FORWARDER(type, name) \ + type name() const { \ + mozilla::TextControlElement* textControlElement = \ + mozilla::TextControlElement::FromNode(GetContent()); \ + return textControlElement->name(); \ } DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsSingleLineTextControl)