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 {
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 {
// FIXME: Remove type check.
if (type() != input_type_names::kRadio)
......
......@@ -127,6 +127,9 @@ class CORE_EXPORT HTMLInputElement
bool ShouldAppearChecked() const;
bool ShouldAppearIndeterminate() const override;
// Returns null if this isn't associated with any radio button group.
RadioButtonGroupScope* GetRadioButtonGroupScope() const;
unsigned size() const;
bool SizeShouldIncludeDecoration(int& preferred_size) const;
......@@ -245,9 +248,6 @@ class CORE_EXPORT HTMLInputElement
// Associated <datalist> options which match to the current INPUT value.
HeapVector<Member<HTMLOptionElement>> FilteredDataListOptions() const;
HTMLInputElement* CheckedRadioButtonForGroup();
bool IsInRequiredRadioButtonGroup();
// Functions for InputType classes.
void SetNonAttributeValue(const String&);
void SetNonAttributeValueByUserEdit(const String&);
......@@ -409,8 +409,6 @@ class CORE_EXPORT HTMLInputElement
void SetListAttributeTargetObserver(ListAttributeTargetObserver*);
void ResetListAttributeTargetObserver();
// Returns null if this isn't associated with any radio button group.
RadioButtonGroupScope* GetRadioButtonGroupScope() const;
void AddToRadioButtonGroup();
void RemoveFromRadioButtonGroup();
scoped_refptr<ComputedStyle> CustomStyleForLayoutObject() override;
......
......@@ -56,8 +56,12 @@ const AtomicString& RadioInputType::FormControlType() const {
}
bool RadioInputType::ValueMissing(const String&) const {
return GetElement().IsInRequiredRadioButtonGroup() &&
!GetElement().CheckedRadioButtonForGroup();
HTMLInputElement& input = GetElement();
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 {
......@@ -175,7 +179,7 @@ bool RadioInputType::IsKeyboardFocusable() const {
// Allow keyboard focus if we're checked or if nothing in the group is
// checked.
return GetElement().checked() || !GetElement().CheckedRadioButtonForGroup();
return GetElement().checked() || !CheckedRadioButtonForGroup();
}
bool RadioInputType::ShouldSendChangeEventAfterCheckedChanged() {
......@@ -197,7 +201,7 @@ ClickHandlingState* RadioInputType::WillDispatchClick() {
ClickHandlingState* state = MakeGarbageCollected<ClickHandlingState>();
state->checked = GetElement().checked();
state->checked_radio_button = GetElement().CheckedRadioButtonForGroup();
state->checked_radio_button = CheckedRadioButtonForGroup();
GetElement().setChecked(true, TextFieldEventBehavior::kDispatchChangeEvent);
is_in_click_handler_ = true;
return state;
......@@ -225,7 +229,7 @@ void RadioInputType::DidDispatchClick(Event& event,
}
bool RadioInputType::ShouldAppearIndeterminate() const {
return !GetElement().CheckedRadioButtonForGroup();
return !CheckedRadioButtonForGroup();
}
HTMLInputElement* RadioInputType::NextRadioButtonInGroup(
......@@ -247,4 +251,13 @@ HTMLInputElement* RadioInputType::NextRadioButtonInGroup(
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
......@@ -59,6 +59,7 @@ class RadioInputType final : public BaseCheckableInputType {
HTMLInputElement* FindNextFocusableRadioButtonInGroup(HTMLInputElement*,
bool);
HTMLInputElement* CheckedRadioButtonForGroup() const;
};
} // 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