| 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 10 matching lines...) Expand all Loading... |
| 21 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 22 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/native_theme/native_theme.h" | 24 #include "ui/base/native_theme/native_theme.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/base/text/text_elider.h" | 26 #include "ui/base/text/text_elider.h" |
| 27 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/color_utils.h" | 28 #include "ui/gfx/color_utils.h" |
| 29 #include "ui/gfx/render_text.h" | 29 #include "ui/gfx/render_text.h" |
| 30 | 30 |
| 31 #if defined(OS_WIN) |
| 32 #include "ui/base/native_theme/native_theme_win.h" |
| 33 #endif |
| 34 |
| 35 #if defined(USE_AURA) |
| 36 #include "ui/base/native_theme/native_theme_aura.h" |
| 37 #endif |
| 38 |
| 31 namespace { | 39 namespace { |
| 32 | 40 |
| 33 const char16 kEllipsis[] = { 0x2026, 0x0 }; | 41 const char16 kEllipsis[] = { 0x2026, 0x0 }; |
| 34 | 42 |
| 35 // The minimum distance between the top and bottom of the {icon|text} and the | 43 // The minimum distance between the top and bottom of the {icon|text} and the |
| 36 // top or bottom of the row. | 44 // top or bottom of the row. |
| 37 const int kMinimumIconVerticalPadding = 2; | 45 const int kMinimumIconVerticalPadding = 2; |
| 38 const int kMinimumTextVerticalPadding = 3; | 46 const int kMinimumTextVerticalPadding = 3; |
| 39 | 47 |
| 40 } // namespace | 48 } // namespace |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 135 } |
| 128 keyword_icon_->set_owned_by_client(); | 136 keyword_icon_->set_owned_by_client(); |
| 129 keyword_icon_->EnableCanvasFlippingForRTLUI(true); | 137 keyword_icon_->EnableCanvasFlippingForRTLUI(true); |
| 130 keyword_icon_->SetImage(GetKeywordIcon()); | 138 keyword_icon_->SetImage(GetKeywordIcon()); |
| 131 keyword_icon_->SizeToPreferredSize(); | 139 keyword_icon_->SizeToPreferredSize(); |
| 132 } | 140 } |
| 133 | 141 |
| 134 OmniboxResultView::~OmniboxResultView() { | 142 OmniboxResultView::~OmniboxResultView() { |
| 135 } | 143 } |
| 136 | 144 |
| 137 // static | 145 SkColor OmniboxResultView::GetColor( |
| 138 SkColor OmniboxResultView::GetColor(ResultViewState state, ColorKind kind) { | 146 ResultViewState state, |
| 147 ColorKind kind) const { |
| 148 const ui::NativeTheme* theme = GetNativeTheme(); |
| 149 #if defined(OS_WIN) |
| 150 if (theme == ui::NativeThemeWin::instance()) { |
| 151 static bool win_initialized = false; |
| 152 static SkColor win_colors[NUM_STATES][NUM_KINDS]; |
| 153 if (!win_initialized) { |
| 154 win_colors[NORMAL][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW); |
| 155 win_colors[SELECTED][BACKGROUND] = |
| 156 color_utils::GetSysSkColor(COLOR_HIGHLIGHT); |
| 157 win_colors[NORMAL][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); |
| 158 win_colors[SELECTED][TEXT] = |
| 159 color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); |
| 160 CommonInitColors(theme, win_colors); |
| 161 win_initialized = true; |
| 162 } |
| 163 return win_colors[state][kind]; |
| 164 } |
| 165 #endif |
| 139 static bool initialized = false; | 166 static bool initialized = false; |
| 140 static SkColor colors[NUM_STATES][NUM_KINDS]; | 167 static SkColor colors[NUM_STATES][NUM_KINDS]; |
| 141 if (!initialized) { | 168 if (!initialized) { |
| 142 #if defined(OS_WIN) | |
| 143 colors[NORMAL][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW); | |
| 144 colors[SELECTED][BACKGROUND] = color_utils::GetSysSkColor(COLOR_HIGHLIGHT); | |
| 145 colors[NORMAL][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); | |
| 146 colors[SELECTED][TEXT] = color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); | |
| 147 #elif defined(USE_AURA) | |
| 148 const ui::NativeTheme* theme = ui::NativeTheme::instance(); | |
| 149 colors[SELECTED][BACKGROUND] = theme->GetSystemColor( | 169 colors[SELECTED][BACKGROUND] = theme->GetSystemColor( |
| 150 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); | 170 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); |
| 151 colors[NORMAL][BACKGROUND] = theme->GetSystemColor( | 171 colors[NORMAL][BACKGROUND] = theme->GetSystemColor( |
| 152 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | 172 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| 153 colors[NORMAL][URL] = SkColorSetARGB(0xff, 0x00, 0x99, 0x33); | 173 colors[NORMAL][URL] = SkColorSetARGB(0xff, 0x00, 0x99, 0x33); |
| 154 colors[SELECTED][URL] = SkColorSetARGB(0xff, 0x00, 0x66, 0x22); | 174 colors[SELECTED][URL] = SkColorSetARGB(0xff, 0x00, 0x66, 0x22); |
| 155 colors[HOVERED][URL] = SkColorSetARGB(0xff, 0x00, 0x66, 0x22); | 175 colors[HOVERED][URL] = SkColorSetARGB(0xff, 0x00, 0x66, 0x22); |
| 156 #else | 176 CommonInitColors(theme, colors); |
| 157 // TODO(beng): source from theme provider. | |
| 158 colors[NORMAL][BACKGROUND] = SK_ColorWHITE; | |
| 159 colors[SELECTED][BACKGROUND] = SK_ColorBLUE; | |
| 160 colors[NORMAL][TEXT] = SK_ColorBLACK; | |
| 161 colors[SELECTED][TEXT] = SK_ColorWHITE; | |
| 162 #endif | |
| 163 colors[HOVERED][BACKGROUND] = | |
| 164 color_utils::AlphaBlend(colors[SELECTED][BACKGROUND], | |
| 165 colors[NORMAL][BACKGROUND], 64); | |
| 166 colors[HOVERED][TEXT] = colors[NORMAL][TEXT]; | |
| 167 for (int i = 0; i < NUM_STATES; ++i) { | |
| 168 #if defined(USE_AURA) | |
| 169 colors[i][TEXT] = | |
| 170 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xdd); | |
| 171 colors[i][DIMMED_TEXT] = | |
| 172 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xbb); | |
| 173 #else | |
| 174 colors[i][DIMMED_TEXT] = | |
| 175 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 128); | |
| 176 colors[i][URL] = color_utils::GetReadableColor(SkColorSetRGB(0, 128, 0), | |
| 177 colors[i][BACKGROUND]); | |
| 178 #endif | |
| 179 | |
| 180 // TODO(joi): Programmatically draw the dropdown border using | |
| 181 // this color as well. (Right now it's drawn as black with 25% | |
| 182 // alpha.) | |
| 183 colors[i][DIVIDER] = | |
| 184 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 0x34); | |
| 185 } | |
| 186 initialized = true; | 177 initialized = true; |
| 187 } | 178 } |
| 188 | |
| 189 return colors[state][kind]; | 179 return colors[state][kind]; |
| 190 } | 180 } |
| 191 | 181 |
| 192 void OmniboxResultView::SetMatch(const AutocompleteMatch& match) { | 182 void OmniboxResultView::SetMatch(const AutocompleteMatch& match) { |
| 193 match_ = match; | 183 match_ = match; |
| 194 animation_->Reset(); | 184 animation_->Reset(); |
| 195 | 185 |
| 196 if (match.associated_keyword.get()) { | 186 if (match.associated_keyword.get()) { |
| 197 keyword_icon_->SetImage(GetKeywordIcon()); | 187 keyword_icon_->SetImage(GetKeywordIcon()); |
| 198 | 188 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 DrawString(canvas, match.description, match.description_class, true, x, | 246 DrawString(canvas, match.description, match.description_class, true, x, |
| 257 text_bounds_.y()); | 247 text_bounds_.y()); |
| 258 } | 248 } |
| 259 } | 249 } |
| 260 | 250 |
| 261 int OmniboxResultView::GetTextHeight() const { | 251 int OmniboxResultView::GetTextHeight() const { |
| 262 return std::max(normal_font_.GetHeight(), bold_font_.GetHeight()); | 252 return std::max(normal_font_.GetHeight(), bold_font_.GetHeight()); |
| 263 } | 253 } |
| 264 | 254 |
| 265 // static | 255 // static |
| 256 void OmniboxResultView::CommonInitColors(const ui::NativeTheme* theme, |
| 257 SkColor colors[][NUM_KINDS]) { |
| 258 colors[HOVERED][BACKGROUND] = |
| 259 color_utils::AlphaBlend(colors[SELECTED][BACKGROUND], |
| 260 colors[NORMAL][BACKGROUND], 64); |
| 261 colors[HOVERED][TEXT] = colors[NORMAL][TEXT]; |
| 262 #if defined(USE_AURA) |
| 263 const bool is_aura = theme == ui::NativeThemeAura::instance(); |
| 264 #else |
| 265 const bool is_aura = false; |
| 266 #endif |
| 267 for (int i = 0; i < NUM_STATES; ++i) { |
| 268 if (is_aura) { |
| 269 colors[i][TEXT] = |
| 270 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xdd); |
| 271 colors[i][DIMMED_TEXT] = |
| 272 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xbb); |
| 273 } else { |
| 274 colors[i][DIMMED_TEXT] = |
| 275 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 128); |
| 276 colors[i][URL] = color_utils::GetReadableColor(SkColorSetRGB(0, 128, 0), |
| 277 colors[i][BACKGROUND]); |
| 278 } |
| 279 |
| 280 // TODO(joi): Programmatically draw the dropdown border using |
| 281 // this color as well. (Right now it's drawn as black with 25% |
| 282 // alpha.) |
| 283 colors[i][DIVIDER] = |
| 284 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 0x34); |
| 285 } |
| 286 } |
| 287 |
| 288 // static |
| 266 bool OmniboxResultView::SortRunsLogically(const RunData& lhs, | 289 bool OmniboxResultView::SortRunsLogically(const RunData& lhs, |
| 267 const RunData& rhs) { | 290 const RunData& rhs) { |
| 268 return lhs.run_start < rhs.run_start; | 291 return lhs.run_start < rhs.run_start; |
| 269 } | 292 } |
| 270 | 293 |
| 271 // static | 294 // static |
| 272 bool OmniboxResultView::SortRunsVisually(const RunData& lhs, | 295 bool OmniboxResultView::SortRunsVisually(const RunData& lhs, |
| 273 const RunData& rhs) { | 296 const RunData& rhs) { |
| 274 return lhs.visual_order < rhs.visual_order; | 297 return lhs.visual_order < rhs.visual_order; |
| 275 } | 298 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 int x = GetMirroredXForRect(keyword_text_bounds_); | 641 int x = GetMirroredXForRect(keyword_text_bounds_); |
| 619 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); | 642 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); |
| 620 PaintMatch(canvas, *match_.associated_keyword.get(), x); | 643 PaintMatch(canvas, *match_.associated_keyword.get(), x); |
| 621 } | 644 } |
| 622 } | 645 } |
| 623 | 646 |
| 624 void OmniboxResultView::AnimationProgressed(const ui::Animation* animation) { | 647 void OmniboxResultView::AnimationProgressed(const ui::Animation* animation) { |
| 625 Layout(); | 648 Layout(); |
| 626 SchedulePaint(); | 649 SchedulePaint(); |
| 627 } | 650 } |
| OLD | NEW |