Chromium Code Reviews| Index: chrome/browser/ui/views/omnibox/omnibox_result_view.cc |
| diff --git a/chrome/browser/ui/views/omnibox/omnibox_result_view.cc b/chrome/browser/ui/views/omnibox/omnibox_result_view.cc |
| index 8c3f649a357369caae6dff9e05d9c330664ea351..c5ff3f68ce96c0f65029f57649230b9df6bf4bd6 100644 |
| --- a/chrome/browser/ui/views/omnibox/omnibox_result_view.cc |
| +++ b/chrome/browser/ui/views/omnibox/omnibox_result_view.cc |
| @@ -28,6 +28,14 @@ |
| #include "ui/gfx/color_utils.h" |
| #include "ui/gfx/render_text.h" |
| +#if defined(OS_WIN) |
| +#include "ui/base/native_theme/native_theme_win.h" |
| +#endif |
| + |
| +#if defined(USE_AURA) |
| +#include "ui/base/native_theme/native_theme_aura.h" |
| +#endif |
| + |
| namespace { |
| const char16 kEllipsis[] = { 0x2026, 0x0 }; |
| @@ -135,58 +143,42 @@ OmniboxResultView::~OmniboxResultView() { |
| } |
| // static |
| -SkColor OmniboxResultView::GetColor(ResultViewState state, ColorKind kind) { |
| - static bool initialized = false; |
| - static SkColor colors[NUM_STATES][NUM_KINDS]; |
| - if (!initialized) { |
| +SkColor OmniboxResultView::GetColor( |
| + const ui::NativeTheme* theme, |
| + ResultViewState state, |
| + ColorKind kind) { |
| #if defined(OS_WIN) |
| - colors[NORMAL][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW); |
| - colors[SELECTED][BACKGROUND] = color_utils::GetSysSkColor(COLOR_HIGHLIGHT); |
| - colors[NORMAL][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); |
| - colors[SELECTED][TEXT] = color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); |
| -#elif defined(USE_AURA) |
| - const ui::NativeTheme* theme = ui::NativeTheme::instance(); |
| - colors[SELECTED][BACKGROUND] = theme->GetSystemColor( |
| - ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); |
| - colors[NORMAL][BACKGROUND] = theme->GetSystemColor( |
| - ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| - colors[NORMAL][URL] = SkColorSetARGB(0xff, 0x00, 0x99, 0x33); |
| - colors[SELECTED][URL] = SkColorSetARGB(0xff, 0x00, 0x66, 0x22); |
| - colors[HOVERED][URL] = SkColorSetARGB(0xff, 0x00, 0x66, 0x22); |
| -#else |
| - // TODO(beng): source from theme provider. |
| - colors[NORMAL][BACKGROUND] = SK_ColorWHITE; |
| - colors[SELECTED][BACKGROUND] = SK_ColorBLUE; |
| - colors[NORMAL][TEXT] = SK_ColorBLACK; |
| - colors[SELECTED][TEXT] = SK_ColorWHITE; |
| -#endif |
| - colors[HOVERED][BACKGROUND] = |
| - color_utils::AlphaBlend(colors[SELECTED][BACKGROUND], |
| - colors[NORMAL][BACKGROUND], 64); |
| - colors[HOVERED][TEXT] = colors[NORMAL][TEXT]; |
| - for (int i = 0; i < NUM_STATES; ++i) { |
| -#if defined(USE_AURA) |
| - colors[i][TEXT] = |
| - color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xdd); |
| - colors[i][DIMMED_TEXT] = |
| - color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xbb); |
| -#else |
| - colors[i][DIMMED_TEXT] = |
| - color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 128); |
| - colors[i][URL] = color_utils::GetReadableColor(SkColorSetRGB(0, 128, 0), |
| - colors[i][BACKGROUND]); |
| + if (theme == ui::NativeThemeWin::instance()) { |
| + static bool initialized = false; |
| + static SkColor colors[NUM_STATES][NUM_KINDS]; |
| + if (!initialized) { |
| + colors[NORMAL][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW); |
| + colors[SELECTED][BACKGROUND] = |
| + color_utils::GetSysSkColor(COLOR_HIGHLIGHT); |
| + colors[NORMAL][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); |
| + colors[SELECTED][TEXT] = color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); |
| + CommonInitColors(theme, colors); |
| + initialized = true; |
| + } |
| + return colors[state][kind]; |
| + } |
| #endif |
| - |
| - // TODO(joi): Programmatically draw the dropdown border using |
| - // this color as well. (Right now it's drawn as black with 25% |
| - // alpha.) |
| - colors[i][DIVIDER] = |
| - color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 0x34); |
| + { |
|
sky
2012/11/08 02:04:24
I put this in a block so that there is no conflict
Peter Kasting
2012/11/08 18:55:47
Might be slightly clearer to add a qualifier to th
|
| + static bool initialized = false; |
| + static SkColor colors[NUM_STATES][NUM_KINDS]; |
| + if (!initialized) { |
| + colors[SELECTED][BACKGROUND] = theme->GetSystemColor( |
| + ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); |
| + colors[NORMAL][BACKGROUND] = theme->GetSystemColor( |
| + ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| + colors[NORMAL][URL] = SkColorSetARGB(0xff, 0x00, 0x99, 0x33); |
| + colors[SELECTED][URL] = SkColorSetARGB(0xff, 0x00, 0x66, 0x22); |
| + colors[HOVERED][URL] = SkColorSetARGB(0xff, 0x00, 0x66, 0x22); |
| + CommonInitColors(theme, colors); |
| + initialized = true; |
| } |
| - initialized = true; |
| + return colors[state][kind]; |
| } |
| - |
| - return colors[state][kind]; |
| } |
| void OmniboxResultView::SetMatch(const AutocompleteMatch& match) { |
| @@ -263,6 +255,39 @@ int OmniboxResultView::GetTextHeight() const { |
| } |
| // static |
| +void OmniboxResultView::CommonInitColors(const ui::NativeTheme* theme, |
| + SkColor colors[][NUM_KINDS]) { |
| + colors[HOVERED][BACKGROUND] = |
| + color_utils::AlphaBlend(colors[SELECTED][BACKGROUND], |
| + colors[NORMAL][BACKGROUND], 64); |
| + colors[HOVERED][TEXT] = colors[NORMAL][TEXT]; |
| +#if defined(USE_AURA) |
| + const bool is_aura = theme == ui::NativeThemeAura::instance(); |
| +#else |
| + const bool is_aura = false; |
| +#endif |
| + for (int i = 0; i < NUM_STATES; ++i) { |
| + if (is_aura) { |
| + colors[i][TEXT] = |
| + color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xdd); |
| + colors[i][DIMMED_TEXT] = |
| + color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xbb); |
| + } else { |
| + colors[i][DIMMED_TEXT] = |
| + color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 128); |
| + colors[i][URL] = color_utils::GetReadableColor(SkColorSetRGB(0, 128, 0), |
| + colors[i][BACKGROUND]); |
| + } |
| + |
| + // TODO(joi): Programmatically draw the dropdown border using |
| + // this color as well. (Right now it's drawn as black with 25% |
| + // alpha.) |
| + colors[i][DIVIDER] = |
| + color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 0x34); |
| + } |
| +} |
| + |
| +// static |
| bool OmniboxResultView::SortRunsLogically(const RunData& lhs, |
| const RunData& rhs) { |
| return lhs.run_start < rhs.run_start; |
| @@ -344,6 +369,7 @@ int OmniboxResultView::DrawString( |
| const int num_runs = bidi_line.CountRuns(); |
| ScopedVector<gfx::RenderText> render_texts; |
| Runs runs; |
| + const ui::NativeTheme* theme = GetNativeTheme(); |
| for (int run = 0; run < num_runs; ++run) { |
| int run_start_int = 0, run_length_int = 0; |
| // The index we pass to GetVisualRun corresponds to the position of the run |
| @@ -387,12 +413,14 @@ int OmniboxResultView::DrawString( |
| const bool use_bold_font = !!(style & ACMatchClassification::MATCH); |
| current_data->font = &(use_bold_font ? bold_font_ : normal_font_); |
| const ResultViewState state = GetState(); |
| - if (style & ACMatchClassification::URL) |
| - current_data->color = GetColor(state, URL); |
| - else if (style & ACMatchClassification::DIM) |
| - current_data->color = GetColor(state, DIMMED_TEXT); |
| - else |
| - current_data->color = GetColor(state, force_dim ? DIMMED_TEXT : TEXT); |
| + if (style & ACMatchClassification::URL) { |
| + current_data->color = GetColor(theme, state, URL); |
| + } else if (style & ACMatchClassification::DIM) { |
| + current_data->color = GetColor(theme, state, DIMMED_TEXT); |
| + } else { |
| + current_data->color = GetColor(theme, state, |
| + force_dim ? DIMMED_TEXT : TEXT); |
| + } |
| render_texts.push_back(gfx::RenderText::CreateInstance()); |
| current_data->render_text = render_texts.back(); |
| @@ -599,7 +627,7 @@ void OmniboxResultView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| void OmniboxResultView::OnPaint(gfx::Canvas* canvas) { |
| const ResultViewState state = GetState(); |
| if (state != NORMAL) |
| - canvas->DrawColor(GetColor(state, BACKGROUND)); |
| + canvas->DrawColor(GetColor(GetNativeTheme(), state, BACKGROUND)); |
| if (!match_.associated_keyword.get() || |
| keyword_icon_->x() > icon_bounds_.right()) { |