Commit 20679e21 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move two functions of HTMLInputElement

* Fold HTMLInputElement::IsInRequiredRadioButtonGroup() into
  RadioInputType::ValueMissing(), which was the only caller.

* Move HTMLInputElement::CheckedRadioButtonForGroup() to RadioInputType
  because it is used only by RadioInputType.

* Make HTMLInputElement::GetRadioButtonGroupScope public because now it is
  used by RadioInputType.

This CL has no behavior changes.

Change-Id: I1811e208cf071d4e657d9f88e393dfdd1d2fe800
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1982512Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727845}
parent 66c3b1b0
...@@ -1781,22 +1781,6 @@ bool HTMLInputElement::ShouldAppearIndeterminate() const { ...@@ -1781,22 +1781,6 @@ bool HTMLInputElement::ShouldAppearIndeterminate() const {
return input_type_->ShouldAppearIndeterminate(); return input_type_->ShouldAppearIndeterminate();
} }
bool HTMLInputElement::IsInRequiredRadioButtonGroup() {
// TODO(tkent): Remove type check.
DCHECK_EQ(type(), input_type_names::kRadio);
if (RadioButtonGroupScope* scope = GetRadioButtonGroupScope())
return scope->IsInRequiredGroup(this);
return false;
}
HTMLInputElement* HTMLInputElement::CheckedRadioButtonForGroup() {
if (checked())
return this;
if (RadioButtonGroupScope* scope = GetRadioButtonGroupScope())
return scope->CheckedButtonForGroup(GetName());
return nullptr;
}
RadioButtonGroupScope* HTMLInputElement::GetRadioButtonGroupScope() const { RadioButtonGroupScope* HTMLInputElement::GetRadioButtonGroupScope() const {
// FIXME: Remove type check. // FIXME: Remove type check.
if (type() != input_type_names::kRadio) if (type() != input_type_names::kRadio)
......
...@@ -127,6 +127,9 @@ class CORE_EXPORT HTMLInputElement ...@@ -127,6 +127,9 @@ class CORE_EXPORT HTMLInputElement
bool ShouldAppearChecked() const; bool ShouldAppearChecked() const;
bool ShouldAppearIndeterminate() const override; bool ShouldAppearIndeterminate() const override;
// Returns null if this isn't associated with any radio button group.
RadioButtonGroupScope* GetRadioButtonGroupScope() const;
unsigned size() const; unsigned size() const;
bool SizeShouldIncludeDecoration(int& preferred_size) const; bool SizeShouldIncludeDecoration(int& preferred_size) const;
...@@ -245,9 +248,6 @@ class CORE_EXPORT HTMLInputElement ...@@ -245,9 +248,6 @@ class CORE_EXPORT HTMLInputElement
// Associated <datalist> options which match to the current INPUT value. // Associated <datalist> options which match to the current INPUT value.
HeapVector<Member<HTMLOptionElement>> FilteredDataListOptions() const; HeapVector<Member<HTMLOptionElement>> FilteredDataListOptions() const;
HTMLInputElement* CheckedRadioButtonForGroup();
bool IsInRequiredRadioButtonGroup();
// Functions for InputType classes. // Functions for InputType classes.
void SetNonAttributeValue(const String&); void SetNonAttributeValue(const String&);
void SetNonAttributeValueByUserEdit(const String&); void SetNonAttributeValueByUserEdit(const String&);
...@@ -409,8 +409,6 @@ class CORE_EXPORT HTMLInputElement ...@@ -409,8 +409,6 @@ class CORE_EXPORT HTMLInputElement
void SetListAttributeTargetObserver(ListAttributeTargetObserver*); void SetListAttributeTargetObserver(ListAttributeTargetObserver*);
void ResetListAttributeTargetObserver(); void ResetListAttributeTargetObserver();
// Returns null if this isn't associated with any radio button group.
RadioButtonGroupScope* GetRadioButtonGroupScope() const;
void AddToRadioButtonGroup(); void AddToRadioButtonGroup();
void RemoveFromRadioButtonGroup(); void RemoveFromRadioButtonGroup();
scoped_refptr<ComputedStyle> CustomStyleForLayoutObject() override; scoped_refptr<ComputedStyle> CustomStyleForLayoutObject() override;
......
...@@ -56,8 +56,12 @@ const AtomicString& RadioInputType::FormControlType() const { ...@@ -56,8 +56,12 @@ const AtomicString& RadioInputType::FormControlType() const {
} }
bool RadioInputType::ValueMissing(const String&) const { bool RadioInputType::ValueMissing(const String&) const {
return GetElement().IsInRequiredRadioButtonGroup() && HTMLInputElement& input = GetElement();
!GetElement().CheckedRadioButtonForGroup(); if (auto* scope = input.GetRadioButtonGroupScope())
return scope->IsInRequiredGroup(&input) && !CheckedRadioButtonForGroup();
// TODO(crbug.com/883723): This function should work even if this radio
// button doesn't belong to any RadioButtonGroupScope.
return false;
} }
String RadioInputType::ValueMissingText() const { String RadioInputType::ValueMissingText() const {
...@@ -175,7 +179,7 @@ bool RadioInputType::IsKeyboardFocusable() const { ...@@ -175,7 +179,7 @@ bool RadioInputType::IsKeyboardFocusable() const {
// Allow keyboard focus if we're checked or if nothing in the group is // Allow keyboard focus if we're checked or if nothing in the group is
// checked. // checked.
return GetElement().checked() || !GetElement().CheckedRadioButtonForGroup(); return GetElement().checked() || !CheckedRadioButtonForGroup();
} }
bool RadioInputType::ShouldSendChangeEventAfterCheckedChanged() { bool RadioInputType::ShouldSendChangeEventAfterCheckedChanged() {
...@@ -197,7 +201,7 @@ ClickHandlingState* RadioInputType::WillDispatchClick() { ...@@ -197,7 +201,7 @@ ClickHandlingState* RadioInputType::WillDispatchClick() {
ClickHandlingState* state = MakeGarbageCollected<ClickHandlingState>(); ClickHandlingState* state = MakeGarbageCollected<ClickHandlingState>();
state->checked = GetElement().checked(); state->checked = GetElement().checked();
state->checked_radio_button = GetElement().CheckedRadioButtonForGroup(); state->checked_radio_button = CheckedRadioButtonForGroup();
GetElement().setChecked(true, TextFieldEventBehavior::kDispatchChangeEvent); GetElement().setChecked(true, TextFieldEventBehavior::kDispatchChangeEvent);
is_in_click_handler_ = true; is_in_click_handler_ = true;
return state; return state;
...@@ -225,7 +229,7 @@ void RadioInputType::DidDispatchClick(Event& event, ...@@ -225,7 +229,7 @@ void RadioInputType::DidDispatchClick(Event& event,
} }
bool RadioInputType::ShouldAppearIndeterminate() const { bool RadioInputType::ShouldAppearIndeterminate() const {
return !GetElement().CheckedRadioButtonForGroup(); return !CheckedRadioButtonForGroup();
} }
HTMLInputElement* RadioInputType::NextRadioButtonInGroup( HTMLInputElement* RadioInputType::NextRadioButtonInGroup(
...@@ -247,4 +251,13 @@ HTMLInputElement* RadioInputType::NextRadioButtonInGroup( ...@@ -247,4 +251,13 @@ HTMLInputElement* RadioInputType::NextRadioButtonInGroup(
return nullptr; return nullptr;
} }
HTMLInputElement* RadioInputType::CheckedRadioButtonForGroup() const {
HTMLInputElement& input = GetElement();
if (input.checked())
return &input;
if (auto* scope = input.GetRadioButtonGroupScope())
return scope->CheckedButtonForGroup(input.GetName());
return nullptr;
}
} // namespace blink } // namespace blink
...@@ -59,6 +59,7 @@ class RadioInputType final : public BaseCheckableInputType { ...@@ -59,6 +59,7 @@ class RadioInputType final : public BaseCheckableInputType {
HTMLInputElement* FindNextFocusableRadioButtonInGroup(HTMLInputElement*, HTMLInputElement* FindNextFocusableRadioButtonInGroup(HTMLInputElement*,
bool); bool);
HTMLInputElement* CheckedRadioButtonForGroup() const;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment