OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // For WinDDK ATL compatibility, these ATL headers must come first. | 5 // For WinDDK ATL compatibility, these ATL headers must come first. |
6 #include "build/build_config.h" | 6 #include "build/build_config.h" |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <atlbase.h> // NOLINT | 8 #include <atlbase.h> // NOLINT |
9 #include <atlwin.h> // NOLINT | 9 #include <atlwin.h> // NOLINT |
10 #endif | 10 #endif |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "ui/native_theme/native_theme.h" | 34 #include "ui/native_theme/native_theme.h" |
35 | 35 |
36 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
37 #include "ui/native_theme/native_theme_win.h" | 37 #include "ui/native_theme/native_theme_win.h" |
38 #endif | 38 #endif |
39 | 39 |
40 #if defined(USE_AURA) | 40 #if defined(USE_AURA) |
41 #include "ui/native_theme/native_theme_aura.h" | 41 #include "ui/native_theme/native_theme_aura.h" |
42 #endif | 42 #endif |
43 | 43 |
44 using ui::NativeTheme; | |
45 | |
44 namespace { | 46 namespace { |
45 | 47 |
46 // The minimum distance between the top and bottom of the {icon|text} and the | 48 // The minimum distance between the top and bottom of the {icon|text} and the |
47 // top or bottom of the row. | 49 // top or bottom of the row. |
48 const int kMinimumIconVerticalPadding = 2; | 50 const int kMinimumIconVerticalPadding = 2; |
49 const int kMinimumTextVerticalPadding = 3; | 51 const int kMinimumTextVerticalPadding = 3; |
50 | 52 |
51 } // namespace | 53 } // namespace |
52 | 54 |
53 //////////////////////////////////////////////////////////////////////////////// | 55 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 keyword_icon_->SetImage(GetKeywordIcon()); | 120 keyword_icon_->SetImage(GetKeywordIcon()); |
119 keyword_icon_->SizeToPreferredSize(); | 121 keyword_icon_->SizeToPreferredSize(); |
120 } | 122 } |
121 | 123 |
122 OmniboxResultView::~OmniboxResultView() { | 124 OmniboxResultView::~OmniboxResultView() { |
123 } | 125 } |
124 | 126 |
125 SkColor OmniboxResultView::GetColor( | 127 SkColor OmniboxResultView::GetColor( |
126 ResultViewState state, | 128 ResultViewState state, |
127 ColorKind kind) const { | 129 ColorKind kind) const { |
128 const ui::NativeTheme* theme = GetNativeTheme(); | 130 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to |
129 #if defined(OS_WIN) | 131 // NativeTheme colors. |
130 if (theme == ui::NativeThemeWin::instance()) { | 132 struct TranslationTable { |
131 static bool win_initialized = false; | 133 OmniboxResultView::ResultViewState state; |
132 static SkColor win_colors[NUM_STATES][NUM_KINDS]; | 134 OmniboxResultView::ColorKind kind; |
133 if (!win_initialized) { | 135 ui::NativeTheme::ColorId id; |
134 win_colors[NORMAL][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW); | 136 } static const kTranslationTable[] = { |
135 win_colors[SELECTED][BACKGROUND] = | 137 { NORMAL, BACKGROUND, NativeTheme::kColorId_ResultsTableNormalBackground }, |
msw
2014/04/03 18:53:53
nit: swapping the order of state and kind would ma
Elliot Glaysher
2014/04/03 20:25:27
Done.
msw
2014/04/03 20:30:25
You didn't actually do what I asked, but I guess t
| |
136 color_utils::GetSysSkColor(COLOR_HIGHLIGHT); | 138 { HOVERED, BACKGROUND, |
137 win_colors[NORMAL][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); | 139 NativeTheme::kColorId_ResultsTableHoveredBackground }, |
138 win_colors[SELECTED][TEXT] = | 140 { SELECTED, BACKGROUND, |
139 color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); | 141 NativeTheme::kColorId_ResultsTableSelectedBackground }, |
140 CommonInitColors(theme, win_colors); | 142 { NORMAL, TEXT, NativeTheme::kColorId_ResultsTableNormalText }, |
141 win_initialized = true; | 143 { HOVERED, TEXT, NativeTheme::kColorId_ResultsTableHoveredText }, |
144 { SELECTED, TEXT, NativeTheme::kColorId_ResultsTableSelectedText }, | |
145 { NORMAL, DIMMED_TEXT, | |
146 NativeTheme::kColorId_ResultsTableNormalDimmedText }, | |
147 { HOVERED, DIMMED_TEXT, | |
148 NativeTheme::kColorId_ResultsTableHoveredDimmedText }, | |
149 { SELECTED, DIMMED_TEXT, | |
150 NativeTheme::kColorId_ResultsTableSelectedDimmedText }, | |
151 { NORMAL, URL, NativeTheme::kColorId_ResultsTableNormalUrl }, | |
152 { HOVERED, URL, NativeTheme::kColorId_ResultsTableHoveredUrl }, | |
153 { SELECTED, URL, NativeTheme::kColorId_ResultsTableSelectedUrl }, | |
154 { NORMAL, DIVIDER, NativeTheme::kColorId_ResultsTableNormalDivider }, | |
155 { HOVERED, DIVIDER, NativeTheme::kColorId_ResultsTableHoveredDivider }, | |
156 { SELECTED, DIVIDER, NativeTheme::kColorId_ResultsTableSelectedDivider }, | |
157 }; | |
158 | |
159 for (size_t i = 0; i < arraysize(kTranslationTable); ++i) { | |
160 if (kTranslationTable[i].state == state && | |
161 kTranslationTable[i].kind == kind) { | |
162 return GetNativeTheme()->GetSystemColor(kTranslationTable[i].id); | |
142 } | 163 } |
143 return win_colors[state][kind]; | |
144 } | 164 } |
145 #endif | 165 |
146 static bool initialized = false; | 166 NOTREACHED(); |
147 static SkColor colors[NUM_STATES][NUM_KINDS]; | 167 return SK_ColorRED; |
Elliot Glaysher
2014/04/03 18:14:58
It's wrong that the colors here are stored in a lo
| |
148 if (!initialized) { | |
149 colors[NORMAL][BACKGROUND] = theme->GetSystemColor( | |
150 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | |
151 colors[NORMAL][TEXT] = theme->GetSystemColor( | |
152 ui::NativeTheme::kColorId_TextfieldDefaultColor); | |
153 colors[NORMAL][URL] = SkColorSetARGB(0xff, 0x00, 0x99, 0x33); | |
154 colors[SELECTED][BACKGROUND] = theme->GetSystemColor( | |
155 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); | |
156 colors[SELECTED][TEXT] = theme->GetSystemColor( | |
157 ui::NativeTheme::kColorId_TextfieldSelectionColor); | |
158 colors[SELECTED][URL] = SkColorSetARGB(0xff, 0x00, 0x66, 0x22); | |
159 colors[HOVERED][URL] = SkColorSetARGB(0xff, 0x00, 0x66, 0x22); | |
160 CommonInitColors(theme, colors); | |
161 initialized = true; | |
162 } | |
163 return colors[state][kind]; | |
164 } | 168 } |
165 | 169 |
166 void OmniboxResultView::SetMatch(const AutocompleteMatch& match) { | 170 void OmniboxResultView::SetMatch(const AutocompleteMatch& match) { |
167 match_ = match; | 171 match_ = match; |
168 ResetRenderTexts(); | 172 ResetRenderTexts(); |
169 animation_->Reset(); | 173 animation_->Reset(); |
170 | 174 |
171 AutocompleteMatch* associated_keyword_match = match_.associated_keyword.get(); | 175 AutocompleteMatch* associated_keyword_match = match_.associated_keyword.get(); |
172 if (associated_keyword_match) { | 176 if (associated_keyword_match) { |
173 keyword_icon_->SetImage(GetKeywordIcon()); | 177 keyword_icon_->SetImage(GetKeywordIcon()); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 input_render_text->GetGlyphBounds(contents_start_index); | 412 input_render_text->GetGlyphBounds(contents_start_index); |
409 const int start_padding = is_match_contents_rtl ? | 413 const int start_padding = is_match_contents_rtl ? |
410 std::max(glyph_bounds.start(), glyph_bounds.end()) : | 414 std::max(glyph_bounds.start(), glyph_bounds.end()) : |
411 std::min(glyph_bounds.start(), glyph_bounds.end()); | 415 std::min(glyph_bounds.start(), glyph_bounds.end()); |
412 | 416 |
413 return is_ui_rtl ? | 417 return is_ui_rtl ? |
414 (input_render_text->GetContentWidth() - start_padding) : start_padding; | 418 (input_render_text->GetContentWidth() - start_padding) : start_padding; |
415 } | 419 } |
416 | 420 |
417 // static | 421 // static |
418 void OmniboxResultView::CommonInitColors(const ui::NativeTheme* theme, | |
419 SkColor colors[][NUM_KINDS]) { | |
420 colors[HOVERED][BACKGROUND] = | |
421 color_utils::AlphaBlend(colors[SELECTED][BACKGROUND], | |
422 colors[NORMAL][BACKGROUND], 64); | |
423 colors[HOVERED][TEXT] = colors[NORMAL][TEXT]; | |
424 #if defined(USE_AURA) | |
425 const bool is_aura = theme == ui::NativeThemeAura::instance(); | |
426 #else | |
427 const bool is_aura = false; | |
428 #endif | |
429 for (int i = 0; i < NUM_STATES; ++i) { | |
430 if (is_aura) { | |
431 colors[i][TEXT] = | |
432 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xdd); | |
433 colors[i][DIMMED_TEXT] = | |
434 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xbb); | |
435 } else { | |
436 colors[i][DIMMED_TEXT] = | |
437 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 128); | |
438 colors[i][URL] = color_utils::GetReadableColor(SkColorSetRGB(0, 128, 0), | |
439 colors[i][BACKGROUND]); | |
440 } | |
441 | |
442 // TODO(joi): Programmatically draw the dropdown border using | |
443 // this color as well. (Right now it's drawn as black with 25% | |
444 // alpha.) | |
445 colors[i][DIVIDER] = | |
446 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 0x34); | |
447 } | |
448 } | |
449 | |
450 // static | |
451 int OmniboxResultView::default_icon_size_ = 0; | 422 int OmniboxResultView::default_icon_size_ = 0; |
452 | 423 |
453 gfx::ImageSkia OmniboxResultView::GetIcon() const { | 424 gfx::ImageSkia OmniboxResultView::GetIcon() const { |
454 const gfx::Image image = model_->GetIconIfExtensionMatch(model_index_); | 425 const gfx::Image image = model_->GetIconIfExtensionMatch(model_index_); |
455 if (!image.IsEmpty()) | 426 if (!image.IsEmpty()) |
456 return image.AsImageSkia(); | 427 return image.AsImageSkia(); |
457 | 428 |
458 int icon = match_.starred ? | 429 int icon = match_.starred ? |
459 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); | 430 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); |
460 if (GetState() == SELECTED) { | 431 if (GetState() == SELECTED) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 } | 553 } |
583 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), | 554 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), |
584 keyword_description_rendertext_.get(), canvas, x); | 555 keyword_description_rendertext_.get(), canvas, x); |
585 } | 556 } |
586 } | 557 } |
587 | 558 |
588 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { | 559 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { |
589 Layout(); | 560 Layout(); |
590 SchedulePaint(); | 561 SchedulePaint(); |
591 } | 562 } |
OLD | NEW |