Commit 3f0a36cd authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move HTMLSelectElement::UpdateSelectedState() to ListBoxSelectType

This CL has no behavior changes.

Bug: 1052232
Change-Id: I733476b0febb6bb0db715b6710d69c4dd857b469
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2094874
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749021}
parent 9a91e044
......@@ -1193,56 +1193,6 @@ bool HTMLSelectElement::PopupIsVisible() const {
return select_type_->PopupIsVisible();
}
void HTMLSelectElement::UpdateSelectedState(HTMLOptionElement* clicked_option,
bool multi,
bool shift) {
DCHECK(!UsesMenuList());
DCHECK(clicked_option);
// Save the selection so it can be compared to the new selection when
// dispatching change events during mouseup, or after autoscroll finishes.
SaveLastSelection();
active_selection_state_ = true;
bool shift_select = is_multiple_ && shift;
bool multi_select = is_multiple_ && multi && !shift;
// Keep track of whether an active selection (like during drag selection),
// should select or deselect.
if (clicked_option->Selected() && multi_select) {
active_selection_state_ = false;
clicked_option->SetSelectedState(false);
clicked_option->SetDirty(true);
}
// If we're not in any special multiple selection mode, then deselect all
// other items, excluding the clicked option. If no option was clicked, then
// this will deselect all items in the list.
if (!shift_select && !multi_select)
DeselectItemsWithoutValidation(clicked_option);
// If the anchor hasn't been set, and we're doing a single selection or a
// shift selection, then initialize the anchor to the first selected index.
if (!active_selection_anchor_ && !multi_select)
SetActiveSelectionAnchor(SelectedOption());
// Set the selection state of the clicked option.
if (!clicked_option->IsDisabledFormControl()) {
clicked_option->SetSelectedState(true);
clicked_option->SetDirty(true);
}
// If there was no selectedIndex() for the previous initialization, or If
// we're doing a single selection, or a multiple selection (using cmd or
// ctrl), then initialize the anchor index to the listIndex that just got
// clicked.
if (!active_selection_anchor_ || !shift_select)
SetActiveSelectionAnchor(clicked_option);
SetActiveSelectionEnd(clicked_option);
UpdateListBoxSelection(!multi_select);
}
int HTMLSelectElement::ListIndexForOption(const HTMLOptionElement& option) {
const ListItems& items = GetListItems();
wtf_size_t length = items.size();
......
......@@ -254,7 +254,6 @@ class CORE_EXPORT HTMLSelectElement final
HTMLOptionElement* element_to_exclude = nullptr);
void ParseMultipleAttribute(const AtomicString&);
HTMLOptionElement* LastSelectedOption() const;
void UpdateSelectedState(HTMLOptionElement*, bool multi, bool shift);
wtf_size_t SearchOptionsForValue(const String&,
wtf_size_t list_index_start,
wtf_size_t list_index_end) const;
......
......@@ -615,6 +615,9 @@ class ListBoxSelectType final : public SelectType {
HTMLOptionElement* NextSelectableOptionPageAway(HTMLOptionElement*,
SkipDirection) const;
void ToggleSelection(HTMLOptionElement& option);
void UpdateSelectedState(HTMLOptionElement* clicked_option,
bool multi,
bool shift);
bool is_in_non_contiguous_selection_ = false;
};
......@@ -632,7 +635,7 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
// Convert to coords relative to the list box if needed.
if (HTMLOptionElement* option = EventTargetOption(*gesture_event)) {
if (!select_->IsDisabledFormControl()) {
select_->UpdateSelectedState(option, true, gesture_event->shiftKey());
UpdateSelectedState(option, true, gesture_event->shiftKey());
select_->ListBoxOnChange();
}
return true;
......@@ -654,11 +657,11 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
if (HTMLOptionElement* option = EventTargetOption(*mouse_event)) {
if (!option->IsDisabledFormControl()) {
#if defined(OS_MACOSX)
select_->UpdateSelectedState(option, mouse_event->metaKey(),
mouse_event->shiftKey());
UpdateSelectedState(option, mouse_event->metaKey(),
mouse_event->shiftKey());
#else
select_->UpdateSelectedState(option, mouse_event->ctrlKey(),
mouse_event->shiftKey());
UpdateSelectedState(option, mouse_event->ctrlKey(),
mouse_event->shiftKey());
#endif
}
if (LocalFrame* frame = select_->GetDocument().GetFrame())
......@@ -927,10 +930,59 @@ HTMLOptionElement* ListBoxSelectType::NextSelectableOptionPageAway(
void ListBoxSelectType::ToggleSelection(HTMLOptionElement& option) {
select_->active_selection_state_ = !select_->active_selection_state_;
select_->UpdateSelectedState(&option, true /*multi*/, false /*shift*/);
UpdateSelectedState(&option, true /*multi*/, false /*shift*/);
select_->ListBoxOnChange();
}
void ListBoxSelectType::UpdateSelectedState(HTMLOptionElement* clicked_option,
bool multi,
bool shift) {
DCHECK(clicked_option);
// Save the selection so it can be compared to the new selection when
// dispatching change events during mouseup, or after autoscroll finishes.
select_->SaveLastSelection();
select_->active_selection_state_ = true;
bool shift_select = select_->is_multiple_ && shift;
bool multi_select = select_->is_multiple_ && multi && !shift;
// Keep track of whether an active selection (like during drag selection),
// should select or deselect.
if (clicked_option->Selected() && multi_select) {
select_->active_selection_state_ = false;
clicked_option->SetSelectedState(false);
clicked_option->SetDirty(true);
}
// If we're not in any special multiple selection mode, then deselect all
// other items, excluding the clicked option. If no option was clicked, then
// this will deselect all items in the list.
if (!shift_select && !multi_select)
select_->DeselectItemsWithoutValidation(clicked_option);
// If the anchor hasn't been set, and we're doing a single selection or a
// shift selection, then initialize the anchor to the first selected index.
if (!select_->active_selection_anchor_ && !multi_select)
select_->SetActiveSelectionAnchor(select_->SelectedOption());
// Set the selection state of the clicked option.
if (!clicked_option->IsDisabledFormControl()) {
clicked_option->SetSelectedState(true);
clicked_option->SetDirty(true);
}
// If there was no selectedIndex() for the previous initialization, or If
// we're doing a single selection, or a multiple selection (using cmd or
// ctrl), then initialize the anchor index to the listIndex that just got
// clicked.
if (!select_->active_selection_anchor_ || !shift_select)
select_->SetActiveSelectionAnchor(clicked_option);
select_->SetActiveSelectionEnd(clicked_option);
select_->UpdateListBoxSelection(!multi_select);
}
// ============================================================================
SelectType::SelectType(HTMLSelectElement& select) : select_(select) {}
......
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