Skip to content

Commit

Permalink
Move HTMLSelectElement::UpdateListBoxSelection() to ListBoxSelectType
Browse files Browse the repository at this point in the history
Also, this CL makes SelectType::UpdateMultiSelectFocus() a private
function of ListBoxSelectType. Only ListBoxSelectType needs it.

This CL has no behavior changes.

Bug: 1052232
Change-Id: Idc6a86adc0ad9cd4c8d51caa51a2d58251f9e254
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2098138
Auto-Submit: Kent Tamura <[email protected]>
Commit-Queue: Yoshifumi Inoue <[email protected]>
Reviewed-by: Yoshifumi Inoue <[email protected]>
Cr-Commit-Position: refs/heads/master@{#749457}
  • Loading branch information
tkent-google authored and Commit Bot committed Mar 12, 2020
1 parent 30750ca commit 31b4286
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 52 deletions.
40 changes: 0 additions & 40 deletions third_party/blink/renderer/core/html/forms/html_select_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -554,46 +554,6 @@ void HTMLSelectElement::SetActiveSelectionEnd(HTMLOptionElement* option) {
active_selection_end_ = option;
}

void HTMLSelectElement::UpdateListBoxSelection(bool deselect_other_options,
bool scroll) {
DCHECK(GetLayoutObject());
DCHECK(!UsesMenuList() || is_multiple_);

int active_selection_anchor_index =
active_selection_anchor_ ? active_selection_anchor_->index() : -1;
int active_selection_end_index =
active_selection_end_ ? active_selection_end_->index() : -1;
int start =
std::min(active_selection_anchor_index, active_selection_end_index);
int end = std::max(active_selection_anchor_index, active_selection_end_index);

int i = 0;
for (auto* const option : GetOptionList()) {
if (option->IsDisabledFormControl() || !option->GetLayoutObject()) {
++i;
continue;
}
if (i >= start && i <= end) {
option->SetSelectedState(active_selection_state_);
option->SetDirty(true);
} else if (deselect_other_options ||
i >= static_cast<int>(
cached_state_for_active_selection_.size())) {
option->SetSelectedState(false);
option->SetDirty(true);
} else {
option->SetSelectedState(cached_state_for_active_selection_[i]);
}
++i;
}

select_type_->UpdateMultiSelectFocus();
SetNeedsValidityCheck();
if (scroll)
ScrollToSelection();
NotifyFormStateChanged();
}

void HTMLSelectElement::ListBoxOnChange() {
DCHECK(!UsesMenuList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ class CORE_EXPORT HTMLSelectElement final
wtf_size_t SearchOptionsForValue(const String&,
wtf_size_t list_index_start,
wtf_size_t list_index_end) const;
void UpdateListBoxSelection(bool deselect_other_options, bool scroll = true);
void SetIndexToSelectOnCancel(int list_index);
void SetSuggestedOption(HTMLOptionElement*);

Expand Down
53 changes: 45 additions & 8 deletions third_party/blink/renderer/core/html/forms/select_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,13 @@ class ListBoxSelectType final : public SelectType {
explicit ListBoxSelectType(HTMLSelectElement& select) : SelectType(select) {}
bool DefaultEventHandler(const Event& event) override;
void DidSetSuggestedOption(HTMLOptionElement* option) override;
void UpdateMultiSelectFocus() override;
void SelectAll() override;

private:
HTMLOptionElement* NextSelectableOptionPageAway(HTMLOptionElement*,
SkipDirection) const;
// Update :-internal-multi-select-focus state of selected OPTIONs.
void UpdateMultiSelectFocus();
void ToggleSelection(HTMLOptionElement& option);
enum class SelectionMode {
kDeselectOthers,
Expand All @@ -622,6 +623,7 @@ class ListBoxSelectType final : public SelectType {
};
void UpdateSelectedState(HTMLOptionElement* clicked_option,
SelectionMode mode);
void UpdateListBoxSelection(bool deselect_other_options, bool scroll = true);

bool is_in_non_contiguous_selection_ = false;
};
Expand Down Expand Up @@ -708,11 +710,11 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
return false;

select_->SetActiveSelectionEnd(option);
select_->UpdateListBoxSelection(false);
UpdateListBoxSelection(false);
} else {
select_->SetActiveSelectionAnchor(option);
select_->SetActiveSelectionEnd(option);
select_->UpdateListBoxSelection(true);
UpdateListBoxSelection(true);
}
}
}
Expand Down Expand Up @@ -838,7 +840,7 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
select_->ScrollToOption(end_option);
if (select_new_item || is_in_non_contiguous_selection_) {
if (select_new_item) {
select_->UpdateListBoxSelection(deselect_others);
UpdateListBoxSelection(deselect_others);
select_->ListBoxOnChange();
}
UpdateMultiSelectFocus();
Expand Down Expand Up @@ -911,7 +913,7 @@ void ListBoxSelectType::SelectAll() {
select_->SetActiveSelectionAnchor(NextSelectableOption(nullptr));
select_->SetActiveSelectionEnd(PreviousSelectableOption(nullptr));

select_->UpdateListBoxSelection(false, false);
UpdateListBoxSelection(false, false);
select_->ListBoxOnChange();
select_->SetNeedsValidityCheck();
}
Expand Down Expand Up @@ -988,7 +990,44 @@ void ListBoxSelectType::UpdateSelectedState(HTMLOptionElement* clicked_option,
select_->SetActiveSelectionAnchor(clicked_option);

select_->SetActiveSelectionEnd(clicked_option);
select_->UpdateListBoxSelection(mode != SelectionMode::kNotChangeOthers);
UpdateListBoxSelection(mode != SelectionMode::kNotChangeOthers);
}

void ListBoxSelectType::UpdateListBoxSelection(bool deselect_other_options,
bool scroll) {
DCHECK(select_->GetLayoutObject());
HTMLOptionElement* const anchor_option = select_->active_selection_anchor_;
HTMLOptionElement* const end_option = select_->active_selection_end_;
const int anchor_index = anchor_option ? anchor_option->index() : -1;
const int end_index = end_option ? end_option->index() : -1;
const int start = std::min(anchor_index, end_index);
const int end = std::max(anchor_index, end_index);

int i = 0;
for (auto* const option : select_->GetOptionList()) {
if (option->IsDisabledFormControl() || !option->GetLayoutObject()) {
++i;
continue;
}
if (i >= start && i <= end) {
option->SetSelectedState(select_->active_selection_state_);
option->SetDirty(true);
} else if (deselect_other_options ||
i >= static_cast<int>(
select_->cached_state_for_active_selection_.size())) {
option->SetSelectedState(false);
option->SetDirty(true);
} else {
option->SetSelectedState(select_->cached_state_for_active_selection_[i]);
}
++i;
}

UpdateMultiSelectFocus();
select_->SetNeedsValidityCheck();
if (scroll)
select_->ScrollToSelection();
select_->NotifyFormStateChanged();
}

// ============================================================================
Expand Down Expand Up @@ -1041,8 +1080,6 @@ const ComputedStyle* SelectType::OptionStyle() const {

void SelectType::MaximumOptionWidthMightBeChanged() const {}

void SelectType::UpdateMultiSelectFocus() {}

void SelectType::SelectAll() {
NOTREACHED();
}
Expand Down
3 changes: 0 additions & 3 deletions third_party/blink/renderer/core/html/forms/select_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ class SelectType : public GarbageCollected<SelectType> {
virtual const ComputedStyle* OptionStyle() const;
virtual void MaximumOptionWidthMightBeChanged() const;

// Update :-internal-multi-select-focus state of selected OPTIONs.
virtual void UpdateMultiSelectFocus();

virtual void SelectAll();

virtual void ShowPopup();
Expand Down

0 comments on commit 31b4286

Please sign in to comment.