| 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 |
| 53 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to |
| 54 // NativeTheme colors. |
| 55 struct TranslationTable { |
| 56 ui::NativeTheme::ColorId id; |
| 57 OmniboxResultView::ResultViewState state; |
| 58 OmniboxResultView::ColorKind kind; |
| 59 } static const kTranslationTable[] = { |
| 60 { NativeTheme::kColorId_ResultsTableNormalBackground, |
| 61 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND }, |
| 62 { NativeTheme::kColorId_ResultsTableHoveredBackground, |
| 63 OmniboxResultView::HOVERED, OmniboxResultView::BACKGROUND }, |
| 64 { NativeTheme::kColorId_ResultsTableSelectedBackground, |
| 65 OmniboxResultView::SELECTED, OmniboxResultView::BACKGROUND }, |
| 66 { NativeTheme::kColorId_ResultsTableNormalText, |
| 67 OmniboxResultView::NORMAL, OmniboxResultView::TEXT }, |
| 68 { NativeTheme::kColorId_ResultsTableHoveredText, |
| 69 OmniboxResultView::HOVERED, OmniboxResultView::TEXT }, |
| 70 { NativeTheme::kColorId_ResultsTableSelectedText, |
| 71 OmniboxResultView::SELECTED, OmniboxResultView::TEXT }, |
| 72 { NativeTheme::kColorId_ResultsTableNormalDimmedText, |
| 73 OmniboxResultView::NORMAL, OmniboxResultView::DIMMED_TEXT }, |
| 74 { NativeTheme::kColorId_ResultsTableHoveredDimmedText, |
| 75 OmniboxResultView::HOVERED, OmniboxResultView::DIMMED_TEXT }, |
| 76 { NativeTheme::kColorId_ResultsTableSelectedDimmedText, |
| 77 OmniboxResultView::SELECTED, OmniboxResultView::DIMMED_TEXT }, |
| 78 { NativeTheme::kColorId_ResultsTableNormalUrl, |
| 79 OmniboxResultView::NORMAL, OmniboxResultView::URL }, |
| 80 { NativeTheme::kColorId_ResultsTableHoveredUrl, |
| 81 OmniboxResultView::HOVERED, OmniboxResultView::URL }, |
| 82 { NativeTheme::kColorId_ResultsTableSelectedUrl, |
| 83 OmniboxResultView::SELECTED, OmniboxResultView::URL }, |
| 84 { NativeTheme::kColorId_ResultsTableNormalDivider, |
| 85 OmniboxResultView::NORMAL, OmniboxResultView::DIVIDER }, |
| 86 { NativeTheme::kColorId_ResultsTableHoveredDivider, |
| 87 OmniboxResultView::HOVERED, OmniboxResultView::DIVIDER }, |
| 88 { NativeTheme::kColorId_ResultsTableSelectedDivider, |
| 89 OmniboxResultView::SELECTED, OmniboxResultView::DIVIDER }, |
| 90 }; |
| 91 |
| 51 } // namespace | 92 } // namespace |
| 52 | 93 |
| 53 //////////////////////////////////////////////////////////////////////////////// | 94 //////////////////////////////////////////////////////////////////////////////// |
| 54 // OmniboxResultView, public: | 95 // OmniboxResultView, public: |
| 55 | 96 |
| 56 // This class is a utility class for calculations affected by whether the result | 97 // This class is a utility class for calculations affected by whether the result |
| 57 // view is horizontally mirrored. The drawing functions can be written as if | 98 // view is horizontally mirrored. The drawing functions can be written as if |
| 58 // all drawing occurs left-to-right, and then use this class to get the actual | 99 // all drawing occurs left-to-right, and then use this class to get the actual |
| 59 // coordinates to begin drawing onscreen. | 100 // coordinates to begin drawing onscreen. |
| 60 class OmniboxResultView::MirroringContext { | 101 class OmniboxResultView::MirroringContext { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 keyword_icon_->SetImage(GetKeywordIcon()); | 159 keyword_icon_->SetImage(GetKeywordIcon()); |
| 119 keyword_icon_->SizeToPreferredSize(); | 160 keyword_icon_->SizeToPreferredSize(); |
| 120 } | 161 } |
| 121 | 162 |
| 122 OmniboxResultView::~OmniboxResultView() { | 163 OmniboxResultView::~OmniboxResultView() { |
| 123 } | 164 } |
| 124 | 165 |
| 125 SkColor OmniboxResultView::GetColor( | 166 SkColor OmniboxResultView::GetColor( |
| 126 ResultViewState state, | 167 ResultViewState state, |
| 127 ColorKind kind) const { | 168 ColorKind kind) const { |
| 128 const ui::NativeTheme* theme = GetNativeTheme(); | 169 for (size_t i = 0; i < arraysize(kTranslationTable); ++i) { |
| 129 #if defined(OS_WIN) | 170 if (kTranslationTable[i].state == state && |
| 130 if (theme == ui::NativeThemeWin::instance()) { | 171 kTranslationTable[i].kind == kind) { |
| 131 static bool win_initialized = false; | 172 return GetNativeTheme()->GetSystemColor(kTranslationTable[i].id); |
| 132 static SkColor win_colors[NUM_STATES][NUM_KINDS]; | |
| 133 if (!win_initialized) { | |
| 134 win_colors[NORMAL][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW); | |
| 135 win_colors[SELECTED][BACKGROUND] = | |
| 136 color_utils::GetSysSkColor(COLOR_HIGHLIGHT); | |
| 137 win_colors[NORMAL][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); | |
| 138 win_colors[SELECTED][TEXT] = | |
| 139 color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); | |
| 140 CommonInitColors(theme, win_colors); | |
| 141 win_initialized = true; | |
| 142 } | 173 } |
| 143 return win_colors[state][kind]; | |
| 144 } | 174 } |
| 145 #endif | 175 |
| 146 static bool initialized = false; | 176 NOTREACHED(); |
| 147 static SkColor colors[NUM_STATES][NUM_KINDS]; | 177 return SK_ColorRED; |
| 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 } | 178 } |
| 165 | 179 |
| 166 void OmniboxResultView::SetMatch(const AutocompleteMatch& match) { | 180 void OmniboxResultView::SetMatch(const AutocompleteMatch& match) { |
| 167 match_ = match; | 181 match_ = match; |
| 168 ResetRenderTexts(); | 182 ResetRenderTexts(); |
| 169 animation_->Reset(); | 183 animation_->Reset(); |
| 170 | 184 |
| 171 AutocompleteMatch* associated_keyword_match = match_.associated_keyword.get(); | 185 AutocompleteMatch* associated_keyword_match = match_.associated_keyword.get(); |
| 172 if (associated_keyword_match) { | 186 if (associated_keyword_match) { |
| 173 keyword_icon_->SetImage(GetKeywordIcon()); | 187 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); | 422 input_render_text->GetGlyphBounds(contents_start_index); |
| 409 const int start_padding = is_match_contents_rtl ? | 423 const int start_padding = is_match_contents_rtl ? |
| 410 std::max(glyph_bounds.start(), glyph_bounds.end()) : | 424 std::max(glyph_bounds.start(), glyph_bounds.end()) : |
| 411 std::min(glyph_bounds.start(), glyph_bounds.end()); | 425 std::min(glyph_bounds.start(), glyph_bounds.end()); |
| 412 | 426 |
| 413 return is_ui_rtl ? | 427 return is_ui_rtl ? |
| 414 (input_render_text->GetContentWidth() - start_padding) : start_padding; | 428 (input_render_text->GetContentWidth() - start_padding) : start_padding; |
| 415 } | 429 } |
| 416 | 430 |
| 417 // static | 431 // 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; | 432 int OmniboxResultView::default_icon_size_ = 0; |
| 452 | 433 |
| 453 gfx::ImageSkia OmniboxResultView::GetIcon() const { | 434 gfx::ImageSkia OmniboxResultView::GetIcon() const { |
| 454 const gfx::Image image = model_->GetIconIfExtensionMatch(model_index_); | 435 const gfx::Image image = model_->GetIconIfExtensionMatch(model_index_); |
| 455 if (!image.IsEmpty()) | 436 if (!image.IsEmpty()) |
| 456 return image.AsImageSkia(); | 437 return image.AsImageSkia(); |
| 457 | 438 |
| 458 int icon = match_.starred ? | 439 int icon = match_.starred ? |
| 459 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); | 440 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); |
| 460 if (GetState() == SELECTED) { | 441 if (GetState() == SELECTED) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 } | 563 } |
| 583 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), | 564 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), |
| 584 keyword_description_rendertext_.get(), canvas, x); | 565 keyword_description_rendertext_.get(), canvas, x); |
| 585 } | 566 } |
| 586 } | 567 } |
| 587 | 568 |
| 588 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { | 569 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { |
| 589 Layout(); | 570 Layout(); |
| 590 SchedulePaint(); | 571 SchedulePaint(); |
| 591 } | 572 } |
| OLD | NEW |