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
This commit is contained in:
Masayuki Nakano
2019-11-24 05:38:02 +00:00
parent 9e55df6e86
commit 018bf53100
28 changed files with 418 additions and 462 deletions

View File

@@ -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<mozilla::dom::NodeInfo>&& 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) {