Commit e403fb86 authored by Orin Jaworski's avatar Orin Jaworski Committed by Commit Bot

[omnibox] Change popup handler API to pass Selection instead of line only

This CL starts preparing popup handlers for changes to either line
index or line state, instead of only considering line and assuming
the NORMAL state. The interface is changed, but not behavior.

Bug: 1046523
Change-Id: I1cdf5e288b6be2c488795be2bfba0b276327326e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132769Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Auto-Submit: Orin Jaworski <orinj@chromium.org>
Commit-Queue: Orin Jaworski <orinj@chromium.org>
Commit-Queue: Justin Donnelly <jdonnelly@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756122}
parent 7066ac32
...@@ -230,19 +230,20 @@ void OmniboxPopupContentsView::InvalidateLine(size_t line) { ...@@ -230,19 +230,20 @@ void OmniboxPopupContentsView::InvalidateLine(size_t line) {
OmniboxPopupModel::KEYWORD); OmniboxPopupModel::KEYWORD);
} }
void OmniboxPopupContentsView::OnSelectedLineChanged(size_t old_selected_line, void OmniboxPopupContentsView::OnSelectionChanged(
size_t new_selected_line) { OmniboxPopupModel::Selection old_selection,
OmniboxPopupModel::Selection new_selection) {
if (base::FeatureList::IsEnabled(omnibox::kWebUIOmniboxPopup)) { if (base::FeatureList::IsEnabled(omnibox::kWebUIOmniboxPopup)) {
webui_view_->GetWebUIHandler()->OnSelectedLineChanged(old_selected_line, webui_view_->GetWebUIHandler()->OnSelectedLineChanged(old_selection.line,
new_selected_line); new_selection.line);
return; return;
} }
if (old_selected_line != OmniboxPopupModel::kNoMatch) if (old_selection.line != OmniboxPopupModel::kNoMatch)
result_view_at(old_selected_line)->OnSelectionStateChanged(); result_view_at(old_selection.line)->OnSelectionStateChanged();
if (new_selected_line != OmniboxPopupModel::kNoMatch) if (new_selection.line != OmniboxPopupModel::kNoMatch)
result_view_at(new_selected_line)->OnSelectionStateChanged(); result_view_at(new_selection.line)->OnSelectionStateChanged();
} }
void OmniboxPopupContentsView::UpdatePopupAppearance() { void OmniboxPopupContentsView::UpdatePopupAppearance() {
......
...@@ -73,8 +73,8 @@ class OmniboxPopupContentsView : public views::View, ...@@ -73,8 +73,8 @@ class OmniboxPopupContentsView : public views::View,
// OmniboxPopupView: // OmniboxPopupView:
bool IsOpen() const override; bool IsOpen() const override;
void InvalidateLine(size_t line) override; void InvalidateLine(size_t line) override;
void OnSelectedLineChanged(size_t old_selected_line, void OnSelectionChanged(OmniboxPopupModel::Selection old_selection,
size_t new_selected_line) override; OmniboxPopupModel::Selection new_selection) override;
void UpdatePopupAppearance() override; void UpdatePopupAppearance() override;
void ProvideButtonFocusHint(size_t line) override; void ProvideButtonFocusHint(size_t line) override;
void OnMatchIconUpdated(size_t match_index) override; void OnMatchIconUpdated(size_t match_index) override;
......
...@@ -186,13 +186,13 @@ void OmniboxPopupModel::SetSelectedLine(size_t line, ...@@ -186,13 +186,13 @@ void OmniboxPopupModel::SetSelectedLine(size_t line,
return; // Nothing else to do. return; // Nothing else to do.
// We need to update selection before calling InvalidateLine(), since it will // We need to update selection before calling InvalidateLine(), since it will
// check them to determine how to draw. We also need to update // use selection to determine how to draw. We also need to update
// |selection_.line| before calling OnPopupDataChanged(), so that when the // |selection_.line| before calling OnPopupDataChanged(), so that when the
// edit notifies its controller that something has changed, the controller // edit notifies its controller that something has changed, the controller
// can get the correct updated data. // can get the correct updated data.
const size_t prev_selected_line = selected_line(); const Selection old_selection = selection_;
selection_ = Selection(line, NORMAL); selection_ = Selection(line, NORMAL);
view_->OnSelectedLineChanged(prev_selected_line, selected_line()); view_->OnSelectionChanged(old_selection, selection_);
if (line == kNoMatch) if (line == kNoMatch)
return; return;
......
...@@ -25,12 +25,10 @@ class OmniboxPopupView { ...@@ -25,12 +25,10 @@ class OmniboxPopupView {
// Invalidates one line of the autocomplete popup. // Invalidates one line of the autocomplete popup.
virtual void InvalidateLine(size_t line) = 0; virtual void InvalidateLine(size_t line) = 0;
// Invoked when the selected line changes. Either |old_selected_line| or // Invoked when the selection changes. The |line| field in either selection
// |new_selected_line| can be OmniboxPopupModel::kNoMatch. This method is // may be OmniboxPopupModel::kNoMatch. This method is invoked by the model.
// invoked by the model, and when it is, the view should consider the virtual void OnSelectionChanged(OmniboxPopupModel::Selection old_selection,
// LineState to have been reset to NORMAL. OmniboxPopupModel::Selection new_selection) {}
virtual void OnSelectedLineChanged(size_t old_selected_line,
size_t new_selected_line) {}
// Redraws the popup window to match any changes in the result set; this may // Redraws the popup window to match any changes in the result set; this may
// mean opening or closing the window. // mean opening or closing the window.
......
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
#include <memory> #include <memory>
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "components/omnibox/browser/omnibox_popup_model.h"
#include "components/omnibox/browser/omnibox_popup_view.h" #include "components/omnibox/browser/omnibox_popup_view.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.h" #import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.h"
#include "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_provider.h" #include "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_provider.h"
class OmniboxEditModel; class OmniboxEditModel;
@class OmniboxPopupMediator; @class OmniboxPopupMediator;
class OmniboxPopupModel;
class OmniboxPopupViewSuggestionsDelegate; class OmniboxPopupViewSuggestionsDelegate;
struct AutocompleteMatch; struct AutocompleteMatch;
......
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