Commit 534d9c25 authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Encapsulate Omnibox NativeTheme usage to inside omnibox_theme.cc.

Bug: 801583
Change-Id: I59fbadf92ad7a30b0114370e305e938fe8e00b98
Reviewed-on: https://chromium-review.googlesource.com/958900
Commit-Queue: Trent Apted <tapted@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543602}
parent 85c977f5
...@@ -52,6 +52,33 @@ ui::NativeTheme::ColorId GetLegacyColorId(OmniboxPart part, ...@@ -52,6 +52,33 @@ ui::NativeTheme::ColorId GetLegacyColorId(OmniboxPart part,
state, NativeId::kColorId_ResultsTableNormalBackground, state, NativeId::kColorId_ResultsTableNormalBackground,
NativeId::kColorId_ResultsTableHoveredBackground, NativeId::kColorId_ResultsTableHoveredBackground,
NativeId::kColorId_ResultsTableSelectedBackground); NativeId::kColorId_ResultsTableSelectedBackground);
case OmniboxPart::TEXT_DEFAULT:
return NormalHoveredSelected(state,
NativeId::kColorId_ResultsTableNormalText,
NativeId::kColorId_ResultsTableHoveredText,
NativeId::kColorId_ResultsTableSelectedText);
case OmniboxPart::TEXT_DIMMED:
return NormalHoveredSelected(
state, NativeId::kColorId_ResultsTableNormalDimmedText,
NativeId::kColorId_ResultsTableHoveredDimmedText,
NativeId::kColorId_ResultsTableSelectedDimmedText);
case OmniboxPart::TEXT_NEGATIVE:
return NormalHoveredSelected(
state, NativeId::kColorId_ResultsTableNegativeText,
NativeId::kColorId_ResultsTableNegativeHoveredText,
NativeId::kColorId_ResultsTableNegativeSelectedText);
case OmniboxPart::TEXT_POSITIVE:
return NormalHoveredSelected(
state, NativeId::kColorId_ResultsTablePositiveText,
NativeId::kColorId_ResultsTablePositiveHoveredText,
NativeId::kColorId_ResultsTablePositiveSelectedText);
case OmniboxPart::TEXT_URL:
return NormalHoveredSelected(state,
NativeId::kColorId_ResultsTableNormalUrl,
NativeId::kColorId_ResultsTableHoveredUrl,
NativeId::kColorId_ResultsTableSelectedUrl);
case OmniboxPart::TEXT_INVISIBLE:
case OmniboxPart::RESULTS_SEPARATOR: case OmniboxPart::RESULTS_SEPARATOR:
NOTREACHED(); NOTREACHED();
break; break;
...@@ -62,6 +89,9 @@ ui::NativeTheme::ColorId GetLegacyColorId(OmniboxPart part, ...@@ -62,6 +89,9 @@ ui::NativeTheme::ColorId GetLegacyColorId(OmniboxPart part,
SkColor GetLegacyColor(OmniboxPart part, SkColor GetLegacyColor(OmniboxPart part,
OmniboxTint tint, OmniboxTint tint,
OmniboxPartState state) { OmniboxPartState state) {
if (part == OmniboxPart::TEXT_INVISIBLE)
return SK_ColorTRANSPARENT;
ui::NativeTheme* native_theme = nullptr; ui::NativeTheme* native_theme = nullptr;
#if defined(USE_AURA) #if defined(USE_AURA)
if (tint == OmniboxTint::DARK) if (tint == OmniboxTint::DARK)
...@@ -104,6 +134,15 @@ SkColor GetOmniboxColor(OmniboxPart part, ...@@ -104,6 +134,15 @@ SkColor GetOmniboxColor(OmniboxPart part,
// The dark base color doesn't appear in the MD2 spec, just Chrome's. // The dark base color doesn't appear in the MD2 spec, just Chrome's.
return dark ? SkColorSetARGB(0x6e, 0x16, 0x17, 0x1a) // 43% alpha. return dark ? SkColorSetARGB(0x6e, 0x16, 0x17, 0x1a) // 43% alpha.
: SkColorSetA(gfx::kGoogleGrey900, 0x24); // 14% alpha. : SkColorSetA(gfx::kGoogleGrey900, 0x24); // 14% alpha.
// TODO(tapted): Add these.
case OmniboxPart::TEXT_DEFAULT:
case OmniboxPart::TEXT_DIMMED:
case OmniboxPart::TEXT_INVISIBLE:
case OmniboxPart::TEXT_NEGATIVE:
case OmniboxPart::TEXT_POSITIVE:
case OmniboxPart::TEXT_URL:
return GetLegacyColor(part, tint, state);
} }
return gfx::kPlaceholderColor; return gfx::kPlaceholderColor;
} }
...@@ -11,6 +11,14 @@ ...@@ -11,6 +11,14 @@
enum class OmniboxPart { enum class OmniboxPart {
RESULTS_BACKGROUND, // Background of the results dropdown. RESULTS_BACKGROUND, // Background of the results dropdown.
RESULTS_SEPARATOR, // Separator between the input row and the results rows. RESULTS_SEPARATOR, // Separator between the input row and the results rows.
// Text styles.
TEXT_DEFAULT,
TEXT_DIMMED,
TEXT_INVISIBLE,
TEXT_NEGATIVE,
TEXT_POSITIVE,
TEXT_URL,
}; };
// The tint of the omnibox theme. E.g. Incognito may use a DARK tint. NATIVE is // The tint of the omnibox theme. E.g. Incognito may use a DARK tint. NATIVE is
......
...@@ -48,9 +48,6 @@ ...@@ -48,9 +48,6 @@
#include "ui/gfx/range/range.h" #include "ui/gfx/range/range.h"
#include "ui/gfx/render_text.h" #include "ui/gfx/render_text.h"
#include "ui/gfx/text_utils.h" #include "ui/gfx/text_utils.h"
#include "ui/native_theme/native_theme.h"
using ui::NativeTheme;
namespace { namespace {
...@@ -68,33 +65,6 @@ static const int kVerticalPadding = 4; ...@@ -68,33 +65,6 @@ static const int kVerticalPadding = 4;
// the additional padding here to zero). // the additional padding here to zero).
static const int kAnswerIconToTextPadding = 2; static const int kAnswerIconToTextPadding = 2;
// A mapping from OmniboxResultView's ResultViewState/ColorKind types to
// NativeTheme colors.
struct TranslationTable {
ui::NativeTheme::ColorId id;
OmniboxResultView::ResultViewState state;
OmniboxResultView::ColorKind kind;
} static const kTranslationTable[] = {
{ NativeTheme::kColorId_ResultsTableNormalText,
OmniboxResultView::NORMAL, OmniboxResultView::TEXT },
{ NativeTheme::kColorId_ResultsTableHoveredText,
OmniboxResultView::HOVERED, OmniboxResultView::TEXT },
{ NativeTheme::kColorId_ResultsTableSelectedText,
OmniboxResultView::SELECTED, OmniboxResultView::TEXT },
{ NativeTheme::kColorId_ResultsTableNormalDimmedText,
OmniboxResultView::NORMAL, OmniboxResultView::DIMMED_TEXT },
{ NativeTheme::kColorId_ResultsTableHoveredDimmedText,
OmniboxResultView::HOVERED, OmniboxResultView::DIMMED_TEXT },
{ NativeTheme::kColorId_ResultsTableSelectedDimmedText,
OmniboxResultView::SELECTED, OmniboxResultView::DIMMED_TEXT },
{ NativeTheme::kColorId_ResultsTableNormalUrl,
OmniboxResultView::NORMAL, OmniboxResultView::URL },
{ NativeTheme::kColorId_ResultsTableHoveredUrl,
OmniboxResultView::HOVERED, OmniboxResultView::URL },
{ NativeTheme::kColorId_ResultsTableSelectedUrl,
OmniboxResultView::SELECTED, OmniboxResultView::URL },
};
// Whether to use the two-line layout. // Whether to use the two-line layout.
bool IsTwoLineLayout() { bool IsTwoLineLayout() {
return base::FeatureList::IsEnabled(omnibox::kUIExperimentVerticalLayout) || return base::FeatureList::IsEnabled(omnibox::kUIExperimentVerticalLayout) ||
...@@ -171,20 +141,8 @@ OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model, ...@@ -171,20 +141,8 @@ OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model,
OmniboxResultView::~OmniboxResultView() {} OmniboxResultView::~OmniboxResultView() {}
SkColor OmniboxResultView::GetColor( SkColor OmniboxResultView::GetColor(OmniboxPart part) const {
ResultViewState state, return GetOmniboxColor(part, GetTint(), GetThemeState());
ColorKind kind) const {
if (kind == INVISIBLE_TEXT)
return SK_ColorTRANSPARENT;
for (size_t i = 0; i < arraysize(kTranslationTable); ++i) {
if (kTranslationTable[i].state == state &&
kTranslationTable[i].kind == kind) {
return GetNativeTheme()->GetSystemColor(kTranslationTable[i].id);
}
}
NOTREACHED();
return gfx::kPlaceholderColor;
} }
void OmniboxResultView::SetMatch(const AutocompleteMatch& match) { void OmniboxResultView::SetMatch(const AutocompleteMatch& match) {
...@@ -217,12 +175,12 @@ void OmniboxResultView::ShowKeyword(bool show_keyword) { ...@@ -217,12 +175,12 @@ void OmniboxResultView::ShowKeyword(bool show_keyword) {
} }
void OmniboxResultView::Invalidate() { void OmniboxResultView::Invalidate() {
const ResultViewState state = GetState(); // TODO(tapted): Consider using background()->SetNativeControlColor() and
if (state == NORMAL) { // always have a background.
if (GetThemeState() == OmniboxPartState::NORMAL) {
SetBackground(nullptr); SetBackground(nullptr);
} else { } else {
SkColor color = GetOmniboxColor(OmniboxPart::RESULTS_BACKGROUND, GetTint(), SkColor color = GetColor(OmniboxPart::RESULTS_BACKGROUND);
GetThemeState());
SetBackground(CreateBackgroundWithColor(color)); SetBackground(CreateBackgroundWithColor(color));
} }
...@@ -266,7 +224,7 @@ void OmniboxResultView::Invalidate() { ...@@ -266,7 +224,7 @@ void OmniboxResultView::Invalidate() {
} }
void OmniboxResultView::OnSelected() { void OmniboxResultView::OnSelected() {
DCHECK_EQ(SELECTED, GetState()); DCHECK(IsSelected());
// The text is also accessible via text/value change events in the omnibox but // The text is also accessible via text/value change events in the omnibox but
// this selection event allows the screen reader to get more details about the // this selection event allows the screen reader to get more details about the
...@@ -274,14 +232,8 @@ void OmniboxResultView::OnSelected() { ...@@ -274,14 +232,8 @@ void OmniboxResultView::OnSelected() {
NotifyAccessibilityEvent(ax::mojom::Event::kSelection, true); NotifyAccessibilityEvent(ax::mojom::Event::kSelection, true);
} }
OmniboxResultView::ResultViewState OmniboxResultView::GetState() const {
if (model_->IsSelectedIndex(model_index_))
return SELECTED;
return is_hovered_ ? HOVERED : NORMAL;
}
OmniboxPartState OmniboxResultView::GetThemeState() const { OmniboxPartState OmniboxResultView::GetThemeState() const {
if (model_->IsSelectedIndex(model_index_)) { if (IsSelected()) {
return is_hovered_ ? OmniboxPartState::HOVERED_AND_SELECTED return is_hovered_ ? OmniboxPartState::HOVERED_AND_SELECTED
: OmniboxPartState::SELECTED; : OmniboxPartState::SELECTED;
} }
...@@ -322,7 +274,7 @@ bool OmniboxResultView::OnMouseDragged(const ui::MouseEvent& event) { ...@@ -322,7 +274,7 @@ bool OmniboxResultView::OnMouseDragged(const ui::MouseEvent& event) {
// When the drag enters or remains within the bounds of this view, either // When the drag enters or remains within the bounds of this view, either
// set the state to be selected or hovered, depending on the mouse button. // set the state to be selected or hovered, depending on the mouse button.
if (event.IsOnlyLeftMouseButton()) { if (event.IsOnlyLeftMouseButton()) {
if (GetState() != SELECTED) if (!IsSelected())
model_->SetSelectedLine(model_index_); model_->SetSelectedLine(model_index_);
if (tab_switch_button_ && tab_switch_button_->parent()) { if (tab_switch_button_ && tab_switch_button_->parent()) {
gfx::Point point_in_child_coords(event.location()); gfx::Point point_in_child_coords(event.location());
...@@ -377,16 +329,10 @@ void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -377,16 +329,10 @@ void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
model_->child_count()); model_->child_count());
node_data->AddState(ax::mojom::State::kSelectable); node_data->AddState(ax::mojom::State::kSelectable);
switch (GetState()) { if (IsSelected())
case SELECTED: node_data->AddState(ax::mojom::State::kSelected);
node_data->AddState(ax::mojom::State::kSelected); if (is_hovered_)
break; node_data->AddState(ax::mojom::State::kHovered);
case HOVERED:
node_data->AddState(ax::mojom::State::kHovered);
break;
default:
break;
}
} }
gfx::Size OmniboxResultView::CalculatePreferredSize() const { gfx::Size OmniboxResultView::CalculatePreferredSize() const {
...@@ -429,8 +375,8 @@ gfx::Image OmniboxResultView::GetIcon() const { ...@@ -429,8 +375,8 @@ gfx::Image OmniboxResultView::GetIcon() const {
SkColor OmniboxResultView::GetVectorIconColor() const { SkColor OmniboxResultView::GetVectorIconColor() const {
// For selected rows, paint the icon the same color as the text. // For selected rows, paint the icon the same color as the text.
SkColor color = GetColor(GetState(), TEXT); SkColor color = GetColor(OmniboxPart::TEXT_DEFAULT);
if (GetState() != SELECTED) if (!IsSelected())
color = color_utils::DeriveDefaultIconColor(color); color = color_utils::DeriveDefaultIconColor(color);
return color; return color;
} }
...@@ -481,6 +427,10 @@ void OmniboxResultView::SetHovered(bool hovered) { ...@@ -481,6 +427,10 @@ void OmniboxResultView::SetHovered(bool hovered) {
} }
} }
bool OmniboxResultView::IsSelected() const {
return model_->IsSelectedIndex(model_index_);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// OmniboxResultView, views::View overrides, private: // OmniboxResultView, views::View overrides, private:
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ui/views/view.h" #include "ui/views/view.h"
class OmniboxPopupContentsView; class OmniboxPopupContentsView;
enum class OmniboxPart;
enum class OmniboxPartState; enum class OmniboxPartState;
enum class OmniboxTint; enum class OmniboxTint;
...@@ -36,30 +37,13 @@ class OmniboxTextView; ...@@ -36,30 +37,13 @@ class OmniboxTextView;
class OmniboxResultView : public views::View, class OmniboxResultView : public views::View,
private gfx::AnimationDelegate { private gfx::AnimationDelegate {
public: public:
// Keep these ordered from least dominant (normal) to most dominant
// (selected).
// TODO(tapted): Remove these: replace with OmniboxPartState.
enum ResultViewState {
NORMAL = 0,
HOVERED,
SELECTED,
NUM_STATES
};
enum ColorKind {
TEXT,
DIMMED_TEXT,
URL,
INVISIBLE_TEXT,
NUM_KINDS
};
OmniboxResultView(OmniboxPopupContentsView* model, OmniboxResultView(OmniboxPopupContentsView* model,
int model_index, int model_index,
const gfx::FontList& font_list); const gfx::FontList& font_list);
~OmniboxResultView() override; ~OmniboxResultView() override;
SkColor GetColor(ResultViewState state, ColorKind kind) const; // Helper to get the color for |part| using the current state and tint.
SkColor GetColor(OmniboxPart part) const;
// Updates the match used to paint the contents of this result view. We copy // Updates the match used to paint the contents of this result view. We copy
// the match so that we can continue to paint the last result even after the // the match so that we can continue to paint the last result even after the
...@@ -73,7 +57,6 @@ class OmniboxResultView : public views::View, ...@@ -73,7 +57,6 @@ class OmniboxResultView : public views::View,
// Invoked when this result view has been selected. // Invoked when this result view has been selected.
void OnSelected(); void OnSelected();
ResultViewState GetState() const;
OmniboxPartState GetThemeState() const; OmniboxPartState GetThemeState() const;
OmniboxTint GetTint() const; OmniboxTint GetTint() const;
...@@ -122,6 +105,9 @@ class OmniboxResultView : public views::View, ...@@ -122,6 +105,9 @@ class OmniboxResultView : public views::View,
// Sets the hovered state of this result. // Sets the hovered state of this result.
void SetHovered(bool hovered); void SetHovered(bool hovered);
// Whether |this| matches the model's selected index.
bool IsSelected() const;
// views::View: // views::View:
void Layout() override; void Layout() override;
const char* GetClassName() const override; const char* GetClassName() const override;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include "chrome/browser/ui/omnibox/omnibox_theme.h"
#include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h"
#include "components/omnibox/browser/omnibox_edit_model.h" #include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/browser/test_omnibox_client.h" #include "components/omnibox/browser/test_omnibox_client.h"
...@@ -98,107 +99,108 @@ class OmniboxResultViewTest : public views::ViewsTestBase { ...@@ -98,107 +99,108 @@ class OmniboxResultViewTest : public views::ViewsTestBase {
}; };
TEST_F(OmniboxResultViewTest, MousePressedWithLeftButtonSelectsThisResult) { TEST_F(OmniboxResultViewTest, MousePressedWithLeftButtonSelectsThisResult) {
EXPECT_NE(OmniboxResultView::SELECTED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::SELECTED, result_view()->GetThemeState());
EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex)); EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
// Right button press should not select. // Right button press should not select.
result_view()->OnMousePressed( result_view()->OnMousePressed(
CreateEvent(ui::ET_MOUSE_PRESSED, ui::EF_RIGHT_MOUSE_BUTTON)); CreateEvent(ui::ET_MOUSE_PRESSED, ui::EF_RIGHT_MOUSE_BUTTON));
EXPECT_NE(OmniboxResultView::SELECTED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::SELECTED, result_view()->GetThemeState());
EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex)); EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
// Middle button press should not select. // Middle button press should not select.
result_view()->OnMousePressed( result_view()->OnMousePressed(
CreateEvent(ui::ET_MOUSE_PRESSED, ui::EF_MIDDLE_MOUSE_BUTTON)); CreateEvent(ui::ET_MOUSE_PRESSED, ui::EF_MIDDLE_MOUSE_BUTTON));
EXPECT_NE(OmniboxResultView::SELECTED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::SELECTED, result_view()->GetThemeState());
EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex)); EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
// Multi-button press should not select. // Multi-button press should not select.
result_view()->OnMousePressed( result_view()->OnMousePressed(
CreateEvent(ui::ET_MOUSE_PRESSED, CreateEvent(ui::ET_MOUSE_PRESSED,
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON));
EXPECT_NE(OmniboxResultView::SELECTED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::SELECTED, result_view()->GetThemeState());
EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex)); EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
// Left button press should select. // Left button press should select.
result_view()->OnMousePressed( result_view()->OnMousePressed(
CreateEvent(ui::ET_MOUSE_PRESSED, ui::EF_LEFT_MOUSE_BUTTON)); CreateEvent(ui::ET_MOUSE_PRESSED, ui::EF_LEFT_MOUSE_BUTTON));
EXPECT_EQ(OmniboxResultView::SELECTED, result_view()->GetState()); EXPECT_EQ(OmniboxPartState::SELECTED, result_view()->GetThemeState());
EXPECT_TRUE(popup_view()->IsSelectedIndex(kTestResultViewIndex)); EXPECT_TRUE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
} }
TEST_F(OmniboxResultViewTest, MouseDragWithLeftButtonSelectsThisResult) { TEST_F(OmniboxResultViewTest, MouseDragWithLeftButtonSelectsThisResult) {
EXPECT_NE(OmniboxResultView::SELECTED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::SELECTED, result_view()->GetThemeState());
EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex)); EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
// Right button drag should not select. // Right button drag should not select.
result_view()->OnMouseDragged( result_view()->OnMouseDragged(
CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_RIGHT_MOUSE_BUTTON)); CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_RIGHT_MOUSE_BUTTON));
EXPECT_NE(OmniboxResultView::SELECTED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::SELECTED, result_view()->GetThemeState());
EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex)); EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
// Middle button drag should not select. // Middle button drag should not select.
result_view()->OnMouseDragged( result_view()->OnMouseDragged(
CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_MIDDLE_MOUSE_BUTTON)); CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_MIDDLE_MOUSE_BUTTON));
EXPECT_NE(OmniboxResultView::SELECTED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::SELECTED, result_view()->GetThemeState());
EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex)); EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
// Multi-button drag should not select. // Multi-button drag should not select.
result_view()->OnMouseDragged( result_view()->OnMouseDragged(
CreateEvent(ui::ET_MOUSE_DRAGGED, CreateEvent(ui::ET_MOUSE_DRAGGED,
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON));
EXPECT_NE(OmniboxResultView::SELECTED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::SELECTED, result_view()->GetThemeState());
EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex)); EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
// Left button drag should select. // Left button drag should select.
result_view()->OnMouseDragged( result_view()->OnMouseDragged(
CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_LEFT_MOUSE_BUTTON)); CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_LEFT_MOUSE_BUTTON));
EXPECT_EQ(OmniboxResultView::SELECTED, result_view()->GetState()); EXPECT_EQ(OmniboxPartState::HOVERED_AND_SELECTED,
result_view()->GetThemeState());
EXPECT_TRUE(popup_view()->IsSelectedIndex(kTestResultViewIndex)); EXPECT_TRUE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
} }
TEST_F(OmniboxResultViewTest, MouseDragWithNonLeftButtonSetsHoveredState) { TEST_F(OmniboxResultViewTest, MouseDragWithNonLeftButtonSetsHoveredState) {
EXPECT_NE(OmniboxResultView::HOVERED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::HOVERED, result_view()->GetThemeState());
// Right button drag should put the view in the HOVERED state. // Right button drag should put the view in the HOVERED state.
result_view()->OnMouseDragged( result_view()->OnMouseDragged(
CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_RIGHT_MOUSE_BUTTON)); CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_RIGHT_MOUSE_BUTTON));
EXPECT_EQ(OmniboxResultView::HOVERED, result_view()->GetState()); EXPECT_EQ(OmniboxPartState::HOVERED, result_view()->GetThemeState());
// Left button drag should take the view out of the HOVERED state. // Left button drag should take the view out of the HOVERED state.
result_view()->OnMouseDragged( result_view()->OnMouseDragged(
CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_LEFT_MOUSE_BUTTON)); CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_LEFT_MOUSE_BUTTON));
EXPECT_NE(OmniboxResultView::HOVERED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::HOVERED, result_view()->GetThemeState());
} }
TEST_F(OmniboxResultViewTest, MouseDragOutOfViewCancelsHoverState) { TEST_F(OmniboxResultViewTest, MouseDragOutOfViewCancelsHoverState) {
EXPECT_NE(OmniboxResultView::HOVERED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::HOVERED, result_view()->GetThemeState());
// Right button drag in the view should put the view in the HOVERED state. // Right button drag in the view should put the view in the HOVERED state.
result_view()->OnMouseDragged( result_view()->OnMouseDragged(
CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_RIGHT_MOUSE_BUTTON, 0, 0)); CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_RIGHT_MOUSE_BUTTON, 0, 0));
EXPECT_EQ(OmniboxResultView::HOVERED, result_view()->GetState()); EXPECT_EQ(OmniboxPartState::HOVERED, result_view()->GetThemeState());
// Right button drag outside of the view should revert the HOVERED state. // Right button drag outside of the view should revert the HOVERED state.
result_view()->OnMouseDragged( result_view()->OnMouseDragged(
CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_RIGHT_MOUSE_BUTTON, 200, 200)); CreateEvent(ui::ET_MOUSE_DRAGGED, ui::EF_RIGHT_MOUSE_BUTTON, 200, 200));
EXPECT_NE(OmniboxResultView::HOVERED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::HOVERED, result_view()->GetThemeState());
} }
TEST_F(OmniboxResultViewTest, MouseMoveAndExitSetsHoveredState) { TEST_F(OmniboxResultViewTest, MouseMoveAndExitSetsHoveredState) {
EXPECT_NE(OmniboxResultView::HOVERED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::HOVERED, result_view()->GetThemeState());
// Moving the mouse over the view should put the view in the HOVERED state. // Moving the mouse over the view should put the view in the HOVERED state.
result_view()->OnMouseMoved(CreateEvent(ui::ET_MOUSE_MOVED, 0)); result_view()->OnMouseMoved(CreateEvent(ui::ET_MOUSE_MOVED, 0));
EXPECT_EQ(OmniboxResultView::HOVERED, result_view()->GetState()); EXPECT_EQ(OmniboxPartState::HOVERED, result_view()->GetThemeState());
// Continuing to move over the view should not change the state. // Continuing to move over the view should not change the state.
result_view()->OnMouseMoved(CreateEvent(ui::ET_MOUSE_MOVED, 0)); result_view()->OnMouseMoved(CreateEvent(ui::ET_MOUSE_MOVED, 0));
EXPECT_EQ(OmniboxResultView::HOVERED, result_view()->GetState()); EXPECT_EQ(OmniboxPartState::HOVERED, result_view()->GetThemeState());
// But exiting should revert the HOVERED state. // But exiting should revert the HOVERED state.
result_view()->OnMouseExited(CreateEvent(ui::ET_MOUSE_MOVED, 0)); result_view()->OnMouseExited(CreateEvent(ui::ET_MOUSE_MOVED, 0));
EXPECT_NE(OmniboxResultView::HOVERED, result_view()->GetState()); EXPECT_NE(OmniboxPartState::HOVERED, result_view()->GetThemeState());
} }
TEST_F(OmniboxResultViewTest, AccessibleNodeData) { TEST_F(OmniboxResultViewTest, AccessibleNodeData) {
......
...@@ -12,21 +12,18 @@ ...@@ -12,21 +12,18 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/omnibox/omnibox_theme.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/range/range.h" #include "ui/gfx/range/range.h"
#include "ui/gfx/render_text.h" #include "ui/gfx/render_text.h"
#include "ui/native_theme/native_theme.h"
using ui::NativeTheme;
namespace { namespace {
struct TextStyle { struct TextStyle {
ui::ResourceBundle::FontStyle font; ui::ResourceBundle::FontStyle font;
ui::NativeTheme::ColorId OmniboxPart part;
colors[OmniboxResultView::ResultViewState::NUM_STATES];
gfx::BaselineStyle baseline; gfx::BaselineStyle baseline;
}; };
...@@ -46,59 +43,32 @@ struct TextStyle { ...@@ -46,59 +43,32 @@ struct TextStyle {
TextStyle GetTextStyle(int type) { TextStyle GetTextStyle(int type) {
switch (type) { switch (type) {
case SuggestionAnswer::TOP_ALIGNED: case SuggestionAnswer::TOP_ALIGNED:
return {ui::ResourceBundle::LargeFont, return {ui::ResourceBundle::LargeFont, OmniboxPart::TEXT_DIMMED,
{NativeTheme::kColorId_ResultsTableNormalDimmedText,
NativeTheme::kColorId_ResultsTableHoveredDimmedText,
NativeTheme::kColorId_ResultsTableSelectedDimmedText},
gfx::SUPERIOR}; gfx::SUPERIOR};
case SuggestionAnswer::DESCRIPTION_NEGATIVE: case SuggestionAnswer::DESCRIPTION_NEGATIVE:
return {ui::ResourceBundle::LargeFont, return {ui::ResourceBundle::LargeFont, OmniboxPart::TEXT_NEGATIVE,
{NativeTheme::kColorId_ResultsTableNegativeText,
NativeTheme::kColorId_ResultsTableNegativeHoveredText,
NativeTheme::kColorId_ResultsTableNegativeSelectedText},
gfx::INFERIOR}; gfx::INFERIOR};
case SuggestionAnswer::DESCRIPTION_POSITIVE: case SuggestionAnswer::DESCRIPTION_POSITIVE:
return {ui::ResourceBundle::LargeFont, return {ui::ResourceBundle::LargeFont, OmniboxPart::TEXT_POSITIVE,
{NativeTheme::kColorId_ResultsTablePositiveText,
NativeTheme::kColorId_ResultsTablePositiveHoveredText,
NativeTheme::kColorId_ResultsTablePositiveSelectedText},
gfx::INFERIOR}; gfx::INFERIOR};
case SuggestionAnswer::PERSONALIZED_SUGGESTION: case SuggestionAnswer::PERSONALIZED_SUGGESTION:
return {ui::ResourceBundle::BaseFont, return {ui::ResourceBundle::BaseFont, OmniboxPart::TEXT_DEFAULT,
{NativeTheme::kColorId_ResultsTableNormalText,
NativeTheme::kColorId_ResultsTableHoveredText,
NativeTheme::kColorId_ResultsTableSelectedText},
gfx::NORMAL_BASELINE}; gfx::NORMAL_BASELINE};
case SuggestionAnswer::ANSWER_TEXT_MEDIUM: case SuggestionAnswer::ANSWER_TEXT_MEDIUM:
return {ui::ResourceBundle::BaseFont, return {ui::ResourceBundle::BaseFont, OmniboxPart::TEXT_DIMMED,
{NativeTheme::kColorId_ResultsTableNormalDimmedText,
NativeTheme::kColorId_ResultsTableHoveredDimmedText,
NativeTheme::kColorId_ResultsTableSelectedDimmedText},
gfx::NORMAL_BASELINE}; gfx::NORMAL_BASELINE};
case SuggestionAnswer::ANSWER_TEXT_LARGE: case SuggestionAnswer::ANSWER_TEXT_LARGE:
return {ui::ResourceBundle::LargeFont, return {ui::ResourceBundle::LargeFont, OmniboxPart::TEXT_DIMMED,
{NativeTheme::kColorId_ResultsTableNormalDimmedText,
NativeTheme::kColorId_ResultsTableHoveredDimmedText,
NativeTheme::kColorId_ResultsTableSelectedDimmedText},
gfx::NORMAL_BASELINE}; gfx::NORMAL_BASELINE};
case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL: case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL:
return {ui::ResourceBundle::LargeFont, return {ui::ResourceBundle::LargeFont, OmniboxPart::TEXT_DIMMED,
{NativeTheme::kColorId_ResultsTableNormalDimmedText,
NativeTheme::kColorId_ResultsTableHoveredDimmedText,
NativeTheme::kColorId_ResultsTableSelectedDimmedText},
gfx::INFERIOR}; gfx::INFERIOR};
case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM: case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM:
return {ui::ResourceBundle::BaseFont, return {ui::ResourceBundle::BaseFont, OmniboxPart::TEXT_DIMMED,
{NativeTheme::kColorId_ResultsTableNormalDimmedText,
NativeTheme::kColorId_ResultsTableHoveredDimmedText,
NativeTheme::kColorId_ResultsTableSelectedDimmedText},
gfx::NORMAL_BASELINE}; gfx::NORMAL_BASELINE};
case SuggestionAnswer::SUGGESTION: // Fall through. case SuggestionAnswer::SUGGESTION: // Fall through.
default: default:
return {ui::ResourceBundle::BaseFont, return {ui::ResourceBundle::BaseFont, OmniboxPart::TEXT_DEFAULT,
{NativeTheme::kColorId_ResultsTableNormalText,
NativeTheme::kColorId_ResultsTableHoveredText,
NativeTheme::kColorId_ResultsTableSelectedText},
gfx::NORMAL_BASELINE}; gfx::NORMAL_BASELINE};
} }
} }
...@@ -168,18 +138,16 @@ std::unique_ptr<gfx::RenderText> OmniboxTextView::CreateClassifiedRenderText( ...@@ -168,18 +138,16 @@ std::unique_ptr<gfx::RenderText> OmniboxTextView::CreateClassifiedRenderText(
if (classifications[i].style & ACMatchClassification::MATCH) if (classifications[i].style & ACMatchClassification::MATCH)
render_text->ApplyWeight(gfx::Font::Weight::BOLD, current_range); render_text->ApplyWeight(gfx::Font::Weight::BOLD, current_range);
OmniboxResultView::ColorKind color_kind = OmniboxResultView::TEXT; OmniboxPart part = OmniboxPart::TEXT_DEFAULT;
if (classifications[i].style & ACMatchClassification::URL) { if (classifications[i].style & ACMatchClassification::URL) {
color_kind = OmniboxResultView::URL; part = OmniboxPart::TEXT_URL;
render_text->SetDirectionalityMode(gfx::DIRECTIONALITY_AS_URL); render_text->SetDirectionalityMode(gfx::DIRECTIONALITY_AS_URL);
} else if (classifications[i].style & ACMatchClassification::DIM) { } else if (classifications[i].style & ACMatchClassification::DIM) {
color_kind = OmniboxResultView::DIMMED_TEXT; part = OmniboxPart::TEXT_DIMMED;
} else if (classifications[i].style & ACMatchClassification::INVISIBLE) { } else if (classifications[i].style & ACMatchClassification::INVISIBLE) {
color_kind = OmniboxResultView::INVISIBLE_TEXT; part = OmniboxPart::TEXT_INVISIBLE;
} }
render_text->ApplyColor( render_text->ApplyColor(result_view_->GetColor(part), current_range);
result_view_->GetColor(result_view_->GetState(), color_kind),
current_range);
} }
return render_text; return render_text;
} }
...@@ -192,8 +160,7 @@ void OmniboxTextView::OnPaint(gfx::Canvas* canvas) { ...@@ -192,8 +160,7 @@ void OmniboxTextView::OnPaint(gfx::Canvas* canvas) {
} }
void OmniboxTextView::Dim() { void OmniboxTextView::Dim() {
render_text_->SetColor(result_view_->GetColor( render_text_->SetColor(result_view_->GetColor(OmniboxPart::TEXT_DIMMED));
result_view_->GetState(), OmniboxResultView::DIMMED_TEXT));
} }
void OmniboxTextView::SetText(const base::string16& text, void OmniboxTextView::SetText(const base::string16& text,
...@@ -294,9 +261,7 @@ void OmniboxTextView::AppendTextHelper(gfx::RenderText* destination, ...@@ -294,9 +261,7 @@ void OmniboxTextView::AppendTextHelper(gfx::RenderText* destination,
// one RenderText. Maybe with destination->SetFontList(...). // one RenderText. Maybe with destination->SetFontList(...).
destination->ApplyWeight( destination->ApplyWeight(
is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range);
destination->ApplyColor(GetNativeTheme()->GetSystemColor( destination->ApplyColor(result_view_->GetColor(text_style.part), range);
text_style.colors[result_view_->GetState()]),
range);
destination->ApplyBaselineStyle(text_style.baseline, range); destination->ApplyBaselineStyle(text_style.baseline, range);
} }
......
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