Commit bd3b5953 authored by Kevin Bailey's avatar Kevin Bailey Committed by Commit Bot

[omnibox] Move tab switch button handling to parent

It was suggested to make the parent OmniboxResultView the recipient
of button presses. This CL makes that change, and minor clean up to
privatize methods which no longer need to be public.

Bug: 780835
Change-Id: If124040f26a41839fad9518bac1be23c3f52cf88
Reviewed-on: https://chromium-review.googlesource.com/990788
Commit-Queue: Kevin Bailey <krb@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547971}
parent dd5a6422
...@@ -353,8 +353,13 @@ void OmniboxResultView::SetAnswerImage(const gfx::ImageSkia& image) { ...@@ -353,8 +353,13 @@ void OmniboxResultView::SetAnswerImage(const gfx::ImageSkia& image) {
SchedulePaint(); SchedulePaint();
} }
void OmniboxResultView::OpenMatch(WindowOpenDisposition disposition) { ////////////////////////////////////////////////////////////////////////////////
model_->OpenMatch(model_index_, disposition); // views::ButtonListener overrides:
// |button| is the tab switch button.
void OmniboxResultView::ButtonPressed(views::Button* button,
const ui::Event& event) {
OpenMatch(WindowOpenDisposition::SWITCH_TO_TAB);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -524,6 +529,10 @@ bool OmniboxResultView::IsSelected() const { ...@@ -524,6 +529,10 @@ bool OmniboxResultView::IsSelected() const {
return model_->IsSelectedIndex(model_index_); return model_->IsSelectedIndex(model_index_);
} }
void OmniboxResultView::OpenMatch(WindowOpenDisposition disposition) {
model_->OpenMatch(model_index_, disposition);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// OmniboxResultView, views::View overrides, private: // OmniboxResultView, views::View overrides, private:
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ui/gfx/animation/slide_animation.h" #include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -37,7 +38,8 @@ class OmniboxTabSwitchButton; ...@@ -37,7 +38,8 @@ class OmniboxTabSwitchButton;
class OmniboxTextView; class OmniboxTextView;
class OmniboxResultView : public views::View, class OmniboxResultView : public views::View,
private gfx::AnimationDelegate { private gfx::AnimationDelegate,
public views::ButtonListener {
public: public:
OmniboxResultView(OmniboxPopupContentsView* model, OmniboxResultView(OmniboxPopupContentsView* model,
int model_index, int model_index,
...@@ -68,8 +70,10 @@ class OmniboxResultView : public views::View, ...@@ -68,8 +70,10 @@ class OmniboxResultView : public views::View,
// Stores the image in a local data member and schedules a repaint. // Stores the image in a local data member and schedules a repaint.
void SetAnswerImage(const gfx::ImageSkia& image); void SetAnswerImage(const gfx::ImageSkia& image);
// Allow other classes to trigger navigation. // views::ButtonListener:
void OpenMatch(WindowOpenDisposition disposition);
// Called when tab switch button pressed, due to being a listener.
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::View: // views::View:
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
...@@ -103,6 +107,9 @@ class OmniboxResultView : public views::View, ...@@ -103,6 +107,9 @@ class OmniboxResultView : public views::View,
// Whether |this| matches the model's selected index. // Whether |this| matches the model's selected index.
bool IsSelected() const; bool IsSelected() const;
// Call model's OpenMatch() with the selected index and provided disposition.
void OpenMatch(WindowOpenDisposition disposition);
// views::View: // views::View:
void Layout() override; void Layout() override;
const char* GetClassName() const override; const char* GetClassName() const override;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
OmniboxTabSwitchButton::OmniboxTabSwitchButton(OmniboxResultView* result_view, OmniboxTabSwitchButton::OmniboxTabSwitchButton(OmniboxResultView* result_view,
int text_height) int text_height)
: MdTextButton(this, views::style::CONTEXT_BUTTON_MD), : MdTextButton(result_view, views::style::CONTEXT_BUTTON_MD),
text_height_(text_height), text_height_(text_height),
result_view_(result_view) { result_view_(result_view) {
// TODO(krb): SetTooltipText(text); // TODO(krb): SetTooltipText(text);
...@@ -44,14 +44,11 @@ void OmniboxTabSwitchButton::StateChanged(ButtonState old_state) { ...@@ -44,14 +44,11 @@ void OmniboxTabSwitchButton::StateChanged(ButtonState old_state) {
SetBgColorOverride(GetBackgroundColor()); SetBgColorOverride(GetBackgroundColor());
// If used to be pressed, transer ownership. // If used to be pressed, transer ownership.
if (old_state == STATE_PRESSED) if (old_state == STATE_PRESSED)
SetMouseHandler(result_view_); SetMouseHandler(parent());
} }
if (state() == STATE_HOVERED) { if (state() == STATE_HOVERED) {
if (old_state == STATE_NORMAL) { if (old_state == STATE_NORMAL) {
SetBgColorOverride(GetBackgroundColor()); SetBgColorOverride(GetBackgroundColor());
} else {
// The button was released.
result_view_->OpenMatch(WindowOpenDisposition::SWITCH_TO_TAB);
} }
} }
if (state() == STATE_PRESSED) if (state() == STATE_PRESSED)
......
...@@ -9,17 +9,13 @@ ...@@ -9,17 +9,13 @@
class OmniboxResultView; class OmniboxResultView;
class OmniboxTabSwitchButton : public views::MdTextButton, class OmniboxTabSwitchButton : public views::MdTextButton {
public views::ButtonListener {
public: public:
OmniboxTabSwitchButton(OmniboxResultView* result_view, int text_height); OmniboxTabSwitchButton(OmniboxResultView* result_view, int text_height);
// views::View // views::View
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
// views::ButtonListener
void ButtonPressed(Button* sender, const ui::Event& event) override {}
// views::Button // views::Button
void StateChanged(ButtonState old_state) override; void StateChanged(ButtonState old_state) override;
......
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