Commit e179929c authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] Add some mouse hover handling to omnibox Views headers

This CL adds some mouse hover handling to the omnibox Views headers,
analogous to what OmniboxResultView already has.

The logic is slightly duplicative but I would hesitate to add any
abstraction at this point, given the experimental nature of the
feature, as well as the fact that it's just two locations.

Bug: 1052522
Change-Id: Ib0211c1e168bf17e0ff6ad487cc43c986801e064
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2145077Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758207}
parent 3b0db518
...@@ -146,6 +146,23 @@ OmniboxResultView::OmniboxResultView( ...@@ -146,6 +146,23 @@ OmniboxResultView::OmniboxResultView(
OmniboxResultView::~OmniboxResultView() {} OmniboxResultView::~OmniboxResultView() {}
// static
std::unique_ptr<views::Background> OmniboxResultView::GetPopupCellBackground(
views::View* view,
OmniboxPartState part_state) {
DCHECK(view);
bool high_contrast = view->GetNativeTheme() &&
view->GetNativeTheme()->UsesHighContrastColors();
// TODO(tapted): Consider using background()->SetNativeControlColor() and
// always have a background.
if ((part_state == OmniboxPartState::NORMAL && !high_contrast))
return nullptr;
return views::CreateSolidBackground(GetOmniboxColor(
view->GetThemeProvider(), OmniboxPart::RESULTS_BACKGROUND, part_state));
}
SkColor OmniboxResultView::GetColor(OmniboxPart part) const { SkColor OmniboxResultView::GetColor(OmniboxPart part) const {
return GetOmniboxColor(GetThemeProvider(), part, GetThemeState()); return GetOmniboxColor(GetThemeProvider(), part, GetThemeState());
} }
...@@ -203,14 +220,7 @@ void OmniboxResultView::ShowKeyword(bool show_keyword) { ...@@ -203,14 +220,7 @@ void OmniboxResultView::ShowKeyword(bool show_keyword) {
} }
void OmniboxResultView::ApplyThemeAndRefreshIcons(bool force_reapply_styles) { void OmniboxResultView::ApplyThemeAndRefreshIcons(bool force_reapply_styles) {
bool high_contrast = SetBackground(GetPopupCellBackground(this, GetThemeState()));
GetNativeTheme() && GetNativeTheme()->UsesHighContrastColors();
// TODO(tapted): Consider using background()->SetNativeControlColor() and
// always have a background.
SetBackground((GetThemeState() == OmniboxPartState::NORMAL && !high_contrast)
? nullptr
: views::CreateSolidBackground(
GetColor(OmniboxPart::RESULTS_BACKGROUND)));
// Reapply the dim color to account for the highlight state. // Reapply the dim color to account for the highlight state.
suggestion_view_->separator()->ApplyTextColor( suggestion_view_->separator()->ApplyTextColor(
...@@ -231,6 +241,8 @@ void OmniboxResultView::ApplyThemeAndRefreshIcons(bool force_reapply_styles) { ...@@ -231,6 +241,8 @@ void OmniboxResultView::ApplyThemeAndRefreshIcons(bool force_reapply_styles) {
omnibox::kKeywordSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE), omnibox::kKeywordSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE),
GetColor(OmniboxPart::RESULTS_ICON))); GetColor(OmniboxPart::RESULTS_ICON)));
bool high_contrast =
GetNativeTheme() && GetNativeTheme()->UsesHighContrastColors();
if (match_.answer) { if (match_.answer) {
suggestion_view_->content()->ApplyTextColor( suggestion_view_->content()->ApplyTextColor(
OmniboxPart::RESULTS_TEXT_DEFAULT); OmniboxPart::RESULTS_TEXT_DEFAULT);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#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/animation/animation_delegate_views.h" #include "ui/views/animation/animation_delegate_views.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
...@@ -48,6 +49,11 @@ class OmniboxResultView : public views::View, ...@@ -48,6 +49,11 @@ class OmniboxResultView : public views::View,
size_t model_index); size_t model_index);
~OmniboxResultView() override; ~OmniboxResultView() override;
// Static method to share logic about how to set backgrounds of popup cells.
static std::unique_ptr<views::Background> GetPopupCellBackground(
views::View* view,
OmniboxPartState part_state);
// Helper to get the color for |part| using the current state. // Helper to get the color for |part| using the current state.
SkColor GetColor(OmniboxPart part) const; SkColor GetColor(OmniboxPart part) const;
......
...@@ -29,6 +29,7 @@ class OmniboxRowView::HeaderView : public views::Label, ...@@ -29,6 +29,7 @@ class OmniboxRowView::HeaderView : public views::Label,
// TODO(tommycli): Add a focus ring. // TODO(tommycli): Add a focus ring.
hide_button_ = AddChildView(views::CreateVectorToggleImageButton(this)); hide_button_ = AddChildView(views::CreateVectorToggleImageButton(this));
views::InstallCircleHighlightPathGenerator(hide_button_); views::InstallCircleHighlightPathGenerator(hide_button_);
hide_button_->SetVisible(false);
} }
void SetHeader(int suggestion_group_id, const base::string16& header_text) { void SetHeader(int suggestion_group_id, const base::string16& header_text) {
...@@ -37,17 +38,24 @@ class OmniboxRowView::HeaderView : public views::Label, ...@@ -37,17 +38,24 @@ class OmniboxRowView::HeaderView : public views::Label,
} }
// views::View: // views::View:
gfx::Insets GetInsets() const override { return gfx::Insets(8, 16); }
void OnMouseEntered(const ui::MouseEvent& event) override {
UpdateUIForHoverState();
}
void OnMouseExited(const ui::MouseEvent& event) override {
UpdateUIForHoverState();
}
void OnThemeChanged() override { void OnThemeChanged() override {
views::View::OnThemeChanged(); views::View::OnThemeChanged();
int dip_size = GetLayoutConstant(LOCATION_BAR_ICON_SIZE); // Since the hide button is only visible when the part is hovered, base the
OmniboxPartState part_state = // icon color on the hover state.
IsMouseHovered() ? OmniboxPartState::HOVERED : OmniboxPartState::NORMAL; SkColor color =
GetOmniboxColor(GetThemeProvider(), OmniboxPart::RESULTS_ICON,
SkColor color = GetOmniboxColor(GetThemeProvider(), OmniboxPartState::HOVERED);
OmniboxPart::RESULTS_ICON, part_state);
hide_button_->set_ink_drop_base_color(color); hide_button_->set_ink_drop_base_color(color);
int dip_size = GetLayoutConstant(LOCATION_BAR_ICON_SIZE);
const gfx::ImageSkia arrow_down = const gfx::ImageSkia arrow_down =
gfx::CreateVectorIcon(omnibox::kChevronIcon, dip_size, color); gfx::CreateVectorIcon(omnibox::kChevronIcon, dip_size, color);
const gfx::ImageSkia arrow_up = const gfx::ImageSkia arrow_up =
...@@ -58,6 +66,9 @@ class OmniboxRowView::HeaderView : public views::Label, ...@@ -58,6 +66,9 @@ class OmniboxRowView::HeaderView : public views::Label,
// The "toggled" button state corresponds with the group being hidden. // The "toggled" button state corresponds with the group being hidden.
hide_button_->SetImage(views::Button::STATE_NORMAL, arrow_up); hide_button_->SetImage(views::Button::STATE_NORMAL, arrow_up);
hide_button_->SetToggledImage(views::Button::STATE_NORMAL, &arrow_down); hide_button_->SetToggledImage(views::Button::STATE_NORMAL, &arrow_down);
// When the theme is updated, also refresh the hover-specific UI.
UpdateUIForHoverState();
} }
// views::ButtonListener: // views::ButtonListener:
...@@ -68,6 +79,20 @@ class OmniboxRowView::HeaderView : public views::Label, ...@@ -68,6 +79,20 @@ class OmniboxRowView::HeaderView : public views::Label,
} }
private: private:
// Some UI changes on-hover, and this function effects those changes.
void UpdateUIForHoverState() {
bool is_hovered = IsMouseHovered();
hide_button_->SetVisible(is_hovered);
OmniboxPartState part_state =
is_hovered ? OmniboxPartState::HOVERED : OmniboxPartState::NORMAL;
// It's a little hokey that we're stealing the logic for the background
// color from OmniboxResultView. If we start doing this is more than just
// one place, we should introduce a more elegant abstraction here.
SetBackground(OmniboxResultView::GetPopupCellBackground(this, part_state));
}
// The Label containing the header text. This is never nullptr. // The Label containing the header text. This is never nullptr.
views::Label* header_text_; views::Label* header_text_;
......
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