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,
state, NativeId::kColorId_ResultsTableNormalBackground,
NativeId::kColorId_ResultsTableHoveredBackground,
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:
NOTREACHED();
break;
......@@ -62,6 +89,9 @@ ui::NativeTheme::ColorId GetLegacyColorId(OmniboxPart part,
SkColor GetLegacyColor(OmniboxPart part,
OmniboxTint tint,
OmniboxPartState state) {
if (part == OmniboxPart::TEXT_INVISIBLE)
return SK_ColorTRANSPARENT;
ui::NativeTheme* native_theme = nullptr;
#if defined(USE_AURA)
if (tint == OmniboxTint::DARK)
......@@ -104,6 +134,15 @@ SkColor GetOmniboxColor(OmniboxPart part,
// The dark base color doesn't appear in the MD2 spec, just Chrome's.
return dark ? SkColorSetARGB(0x6e, 0x16, 0x17, 0x1a) // 43% 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;
}
......@@ -11,6 +11,14 @@
enum class OmniboxPart {
RESULTS_BACKGROUND, // Background of the results dropdown.
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
......
......@@ -48,9 +48,6 @@
#include "ui/gfx/range/range.h"
#include "ui/gfx/render_text.h"
#include "ui/gfx/text_utils.h"
#include "ui/native_theme/native_theme.h"
using ui::NativeTheme;
namespace {
......@@ -68,33 +65,6 @@ static const int kVerticalPadding = 4;
// the additional padding here to zero).
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.
bool IsTwoLineLayout() {
return base::FeatureList::IsEnabled(omnibox::kUIExperimentVerticalLayout) ||
......@@ -171,20 +141,8 @@ OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model,
OmniboxResultView::~OmniboxResultView() {}
SkColor OmniboxResultView::GetColor(
ResultViewState state,
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;
SkColor OmniboxResultView::GetColor(OmniboxPart part) const {
return GetOmniboxColor(part, GetTint(), GetThemeState());
}
void OmniboxResultView::SetMatch(const AutocompleteMatch& match) {
......@@ -217,12 +175,12 @@ void OmniboxResultView::ShowKeyword(bool show_keyword) {
}
void OmniboxResultView::Invalidate() {
const ResultViewState state = GetState();
if (state == NORMAL) {
// TODO(tapted): Consider using background()->SetNativeControlColor() and
// always have a background.
if (GetThemeState() == OmniboxPartState::NORMAL) {
SetBackground(nullptr);
} else {
SkColor color = GetOmniboxColor(OmniboxPart::RESULTS_BACKGROUND, GetTint(),
GetThemeState());
SkColor color = GetColor(OmniboxPart::RESULTS_BACKGROUND);
SetBackground(CreateBackgroundWithColor(color));
}
......@@ -266,7 +224,7 @@ void OmniboxResultView::Invalidate() {
}
void OmniboxResultView::OnSelected() {
DCHECK_EQ(SELECTED, GetState());
DCHECK(IsSelected());
// 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
......@@ -274,14 +232,8 @@ void OmniboxResultView::OnSelected() {
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 {
if (model_->IsSelectedIndex(model_index_)) {
if (IsSelected()) {
return is_hovered_ ? OmniboxPartState::HOVERED_AND_SELECTED
: OmniboxPartState::SELECTED;
}
......@@ -322,7 +274,7 @@ bool OmniboxResultView::OnMouseDragged(const ui::MouseEvent& event) {
// 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.
if (event.IsOnlyLeftMouseButton()) {
if (GetState() != SELECTED)
if (!IsSelected())
model_->SetSelectedLine(model_index_);
if (tab_switch_button_ && tab_switch_button_->parent()) {
gfx::Point point_in_child_coords(event.location());
......@@ -377,16 +329,10 @@ void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
model_->child_count());
node_data->AddState(ax::mojom::State::kSelectable);
switch (GetState()) {
case SELECTED:
node_data->AddState(ax::mojom::State::kSelected);
break;
case HOVERED:
node_data->AddState(ax::mojom::State::kHovered);
break;
default:
break;
}
if (IsSelected())
node_data->AddState(ax::mojom::State::kSelected);
if (is_hovered_)
node_data->AddState(ax::mojom::State::kHovered);
}
gfx::Size OmniboxResultView::CalculatePreferredSize() const {
......@@ -429,8 +375,8 @@ gfx::Image OmniboxResultView::GetIcon() const {
SkColor OmniboxResultView::GetVectorIconColor() const {
// For selected rows, paint the icon the same color as the text.
SkColor color = GetColor(GetState(), TEXT);
if (GetState() != SELECTED)
SkColor color = GetColor(OmniboxPart::TEXT_DEFAULT);
if (!IsSelected())
color = color_utils::DeriveDefaultIconColor(color);
return color;
}
......@@ -481,6 +427,10 @@ void OmniboxResultView::SetHovered(bool hovered) {
}
}
bool OmniboxResultView::IsSelected() const {
return model_->IsSelectedIndex(model_index_);
}
////////////////////////////////////////////////////////////////////////////////
// OmniboxResultView, views::View overrides, private:
......
......@@ -22,6 +22,7 @@
#include "ui/views/view.h"
class OmniboxPopupContentsView;
enum class OmniboxPart;
enum class OmniboxPartState;
enum class OmniboxTint;
......@@ -36,30 +37,13 @@ class OmniboxTextView;
class OmniboxResultView : public views::View,
private gfx::AnimationDelegate {
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,
int model_index,
const gfx::FontList& font_list);
~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
// the match so that we can continue to paint the last result even after the
......@@ -73,7 +57,6 @@ class OmniboxResultView : public views::View,
// Invoked when this result view has been selected.
void OnSelected();
ResultViewState GetState() const;
OmniboxPartState GetThemeState() const;
OmniboxTint GetTint() const;
......@@ -122,6 +105,9 @@ class OmniboxResultView : public views::View,
// Sets the hovered state of this result.
void SetHovered(bool hovered);
// Whether |this| matches the model's selected index.
bool IsSelected() const;
// views::View:
void Layout() override;
const char* GetClassName() const override;
......
......@@ -6,6 +6,7 @@
#include <memory>
#include "chrome/browser/ui/omnibox/omnibox_theme.h"
#include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/browser/test_omnibox_client.h"
......@@ -98,107 +99,108 @@ class OmniboxResultViewTest : public views::ViewsTestBase {
};
TEST_F(OmniboxResultViewTest, MousePressedWithLeftButtonSelectsThisResult) {
EXPECT_NE(OmniboxResultView::SELECTED, result_view()->GetState());
EXPECT_NE(OmniboxPartState::SELECTED, result_view()->GetThemeState());
EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
// Right button press should not select.
result_view()->OnMousePressed(
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));
// Middle button press should not select.
result_view()->OnMousePressed(
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));
// Multi-button press should not select.
result_view()->OnMousePressed(
CreateEvent(ui::ET_MOUSE_PRESSED,
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));
// Left button press should select.
result_view()->OnMousePressed(
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));
}
TEST_F(OmniboxResultViewTest, MouseDragWithLeftButtonSelectsThisResult) {
EXPECT_NE(OmniboxResultView::SELECTED, result_view()->GetState());
EXPECT_NE(OmniboxPartState::SELECTED, result_view()->GetThemeState());
EXPECT_FALSE(popup_view()->IsSelectedIndex(kTestResultViewIndex));
// Right button drag should not select.
result_view()->OnMouseDragged(
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));
// Middle button drag should not select.
result_view()->OnMouseDragged(
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));
// Multi-button drag should not select.
result_view()->OnMouseDragged(
CreateEvent(ui::ET_MOUSE_DRAGGED,
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));
// Left button drag should select.
result_view()->OnMouseDragged(
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));
}
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.
result_view()->OnMouseDragged(
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.
result_view()->OnMouseDragged(
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) {
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.
result_view()->OnMouseDragged(
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.
result_view()->OnMouseDragged(
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) {
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.
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.
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.
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) {
......
......@@ -12,21 +12,18 @@
#include "base/macros.h"
#include "base/strings/string_util.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/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/range/range.h"
#include "ui/gfx/render_text.h"
#include "ui/native_theme/native_theme.h"
using ui::NativeTheme;
namespace {
struct TextStyle {
ui::ResourceBundle::FontStyle font;
ui::NativeTheme::ColorId
colors[OmniboxResultView::ResultViewState::NUM_STATES];
OmniboxPart part;
gfx::BaselineStyle baseline;
};
......@@ -46,59 +43,32 @@ struct TextStyle {
TextStyle GetTextStyle(int type) {
switch (type) {
case SuggestionAnswer::TOP_ALIGNED:
return {ui::ResourceBundle::LargeFont,
{NativeTheme::kColorId_ResultsTableNormalDimmedText,
NativeTheme::kColorId_ResultsTableHoveredDimmedText,
NativeTheme::kColorId_ResultsTableSelectedDimmedText},
return {ui::ResourceBundle::LargeFont, OmniboxPart::TEXT_DIMMED,
gfx::SUPERIOR};
case SuggestionAnswer::DESCRIPTION_NEGATIVE:
return {ui::ResourceBundle::LargeFont,
{NativeTheme::kColorId_ResultsTableNegativeText,
NativeTheme::kColorId_ResultsTableNegativeHoveredText,
NativeTheme::kColorId_ResultsTableNegativeSelectedText},
return {ui::ResourceBundle::LargeFont, OmniboxPart::TEXT_NEGATIVE,
gfx::INFERIOR};
case SuggestionAnswer::DESCRIPTION_POSITIVE:
return {ui::ResourceBundle::LargeFont,
{NativeTheme::kColorId_ResultsTablePositiveText,
NativeTheme::kColorId_ResultsTablePositiveHoveredText,
NativeTheme::kColorId_ResultsTablePositiveSelectedText},
return {ui::ResourceBundle::LargeFont, OmniboxPart::TEXT_POSITIVE,
gfx::INFERIOR};
case SuggestionAnswer::PERSONALIZED_SUGGESTION:
return {ui::ResourceBundle::BaseFont,
{NativeTheme::kColorId_ResultsTableNormalText,
NativeTheme::kColorId_ResultsTableHoveredText,
NativeTheme::kColorId_ResultsTableSelectedText},
return {ui::ResourceBundle::BaseFont, OmniboxPart::TEXT_DEFAULT,
gfx::NORMAL_BASELINE};
case SuggestionAnswer::ANSWER_TEXT_MEDIUM:
return {ui::ResourceBundle::BaseFont,
{NativeTheme::kColorId_ResultsTableNormalDimmedText,
NativeTheme::kColorId_ResultsTableHoveredDimmedText,
NativeTheme::kColorId_ResultsTableSelectedDimmedText},
return {ui::ResourceBundle::BaseFont, OmniboxPart::TEXT_DIMMED,
gfx::NORMAL_BASELINE};
case SuggestionAnswer::ANSWER_TEXT_LARGE:
return {ui::ResourceBundle::LargeFont,
{NativeTheme::kColorId_ResultsTableNormalDimmedText,
NativeTheme::kColorId_ResultsTableHoveredDimmedText,
NativeTheme::kColorId_ResultsTableSelectedDimmedText},
return {ui::ResourceBundle::LargeFont, OmniboxPart::TEXT_DIMMED,
gfx::NORMAL_BASELINE};
case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL:
return {ui::ResourceBundle::LargeFont,
{NativeTheme::kColorId_ResultsTableNormalDimmedText,
NativeTheme::kColorId_ResultsTableHoveredDimmedText,
NativeTheme::kColorId_ResultsTableSelectedDimmedText},
return {ui::ResourceBundle::LargeFont, OmniboxPart::TEXT_DIMMED,
gfx::INFERIOR};
case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM:
return {ui::ResourceBundle::BaseFont,
{NativeTheme::kColorId_ResultsTableNormalDimmedText,
NativeTheme::kColorId_ResultsTableHoveredDimmedText,
NativeTheme::kColorId_ResultsTableSelectedDimmedText},
return {ui::ResourceBundle::BaseFont, OmniboxPart::TEXT_DIMMED,
gfx::NORMAL_BASELINE};
case SuggestionAnswer::SUGGESTION: // Fall through.
default:
return {ui::ResourceBundle::BaseFont,
{NativeTheme::kColorId_ResultsTableNormalText,
NativeTheme::kColorId_ResultsTableHoveredText,
NativeTheme::kColorId_ResultsTableSelectedText},
return {ui::ResourceBundle::BaseFont, OmniboxPart::TEXT_DEFAULT,
gfx::NORMAL_BASELINE};
}
}
......@@ -168,18 +138,16 @@ std::unique_ptr<gfx::RenderText> OmniboxTextView::CreateClassifiedRenderText(
if (classifications[i].style & ACMatchClassification::MATCH)
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) {
color_kind = OmniboxResultView::URL;
part = OmniboxPart::TEXT_URL;
render_text->SetDirectionalityMode(gfx::DIRECTIONALITY_AS_URL);
} else if (classifications[i].style & ACMatchClassification::DIM) {
color_kind = OmniboxResultView::DIMMED_TEXT;
part = OmniboxPart::TEXT_DIMMED;
} else if (classifications[i].style & ACMatchClassification::INVISIBLE) {
color_kind = OmniboxResultView::INVISIBLE_TEXT;
part = OmniboxPart::TEXT_INVISIBLE;
}
render_text->ApplyColor(
result_view_->GetColor(result_view_->GetState(), color_kind),
current_range);
render_text->ApplyColor(result_view_->GetColor(part), current_range);
}
return render_text;
}
......@@ -192,8 +160,7 @@ void OmniboxTextView::OnPaint(gfx::Canvas* canvas) {
}
void OmniboxTextView::Dim() {
render_text_->SetColor(result_view_->GetColor(
result_view_->GetState(), OmniboxResultView::DIMMED_TEXT));
render_text_->SetColor(result_view_->GetColor(OmniboxPart::TEXT_DIMMED));
}
void OmniboxTextView::SetText(const base::string16& text,
......@@ -294,9 +261,7 @@ void OmniboxTextView::AppendTextHelper(gfx::RenderText* destination,
// one RenderText. Maybe with destination->SetFontList(...).
destination->ApplyWeight(
is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range);
destination->ApplyColor(GetNativeTheme()->GetSystemColor(
text_style.colors[result_view_->GetState()]),
range);
destination->ApplyColor(result_view_->GetColor(text_style.part), 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