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 |
11 | 11 |
12 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" | 12 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" |
13 | 13 |
14 #include <algorithm> // NOLINT | 14 #include <algorithm> // NOLINT |
15 | 15 |
16 #include "base/i18n/bidi_line_iterator.h" | 16 #include "base/i18n/bidi_line_iterator.h" |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
18 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 18 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
19 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 19 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
20 #include "chrome/browser/ui/views/omnibox/omnibox_result_view_model.h" | 20 #include "chrome/browser/ui/views/omnibox/omnibox_result_view_model.h" |
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/resource/resource_bundle.h" | |
25 #include "ui/base/text/text_elider.h" | 24 #include "ui/base/text/text_elider.h" |
| 25 #include "ui/base/theme_provider.h" |
26 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/color_utils.h" | 27 #include "ui/gfx/color_utils.h" |
| 28 #include "ui/gfx/image/image.h" |
28 #include "ui/gfx/render_text.h" | 29 #include "ui/gfx/render_text.h" |
29 #include "ui/native_theme/native_theme.h" | 30 #include "ui/native_theme/native_theme.h" |
30 | 31 |
31 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
32 #include "ui/native_theme/native_theme_win.h" | 33 #include "ui/native_theme/native_theme_win.h" |
33 #endif | 34 #endif |
34 | 35 |
35 #if defined(USE_AURA) | 36 #if defined(USE_AURA) |
36 #include "ui/native_theme/native_theme_aura.h" | 37 #include "ui/native_theme/native_theme_aura.h" |
37 #endif | 38 #endif |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 private: | 99 private: |
99 int center_; | 100 int center_; |
100 int right_; | 101 int right_; |
101 | 102 |
102 DISALLOW_COPY_AND_ASSIGN(MirroringContext); | 103 DISALLOW_COPY_AND_ASSIGN(MirroringContext); |
103 }; | 104 }; |
104 | 105 |
105 OmniboxResultView::OmniboxResultView( | 106 OmniboxResultView::OmniboxResultView( |
106 OmniboxResultViewModel* model, | 107 OmniboxResultViewModel* model, |
107 int model_index, | 108 int model_index, |
| 109 views::View* location_bar, |
108 const gfx::Font& font) | 110 const gfx::Font& font) |
109 : edge_item_padding_(LocationBarView::GetItemPadding()), | 111 : edge_item_padding_(LocationBarView::GetItemPadding()), |
110 item_padding_(LocationBarView::GetItemPadding()), | 112 item_padding_(LocationBarView::GetItemPadding()), |
111 minimum_text_vertical_padding_(kMinimumTextVerticalPadding), | 113 minimum_text_vertical_padding_(kMinimumTextVerticalPadding), |
112 model_(model), | 114 model_(model), |
113 model_index_(model_index), | 115 model_index_(model_index), |
| 116 location_bar_(location_bar), |
114 font_(font), | 117 font_(font), |
115 font_height_(std::max(font.GetHeight(), | 118 font_height_(std::max(font.GetHeight(), |
116 font.DeriveFont(0, gfx::BOLD).GetHeight())), | 119 font.DeriveFont(0, gfx::BOLD).GetHeight())), |
117 ellipsis_width_(font.GetStringWidth(string16(kEllipsis))), | 120 ellipsis_width_(font.GetStringWidth(string16(kEllipsis))), |
118 mirroring_context_(new MirroringContext()), | 121 mirroring_context_(new MirroringContext()), |
119 keyword_icon_(new views::ImageView()), | 122 keyword_icon_(new views::ImageView()), |
120 ALLOW_THIS_IN_INITIALIZER_LIST( | 123 ALLOW_THIS_IN_INITIALIZER_LIST( |
121 animation_(new ui::SlideAnimation(this))) { | 124 animation_(new ui::SlideAnimation(this))) { |
122 CHECK_GE(model_index, 0); | 125 CHECK_GE(model_index, 0); |
123 if (default_icon_size_ == 0) { | 126 if (default_icon_size_ == 0) { |
124 default_icon_size_ = | 127 default_icon_size_ = |
125 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 128 location_bar_->GetThemeProvider()->GetImageSkiaNamed( |
126 AutocompleteMatch::TypeToIcon(AutocompleteMatch::URL_WHAT_YOU_TYPED))-> | 129 AutocompleteMatch::TypeToIcon(AutocompleteMatch::URL_WHAT_YOU_TYPED))-> |
127 width(); | 130 width(); |
128 } | 131 } |
129 keyword_icon_->set_owned_by_client(); | 132 keyword_icon_->set_owned_by_client(); |
130 keyword_icon_->EnableCanvasFlippingForRTLUI(true); | 133 keyword_icon_->EnableCanvasFlippingForRTLUI(true); |
131 keyword_icon_->SetImage(GetKeywordIcon()); | 134 keyword_icon_->SetImage(GetKeywordIcon()); |
132 keyword_icon_->SizeToPreferredSize(); | 135 keyword_icon_->SizeToPreferredSize(); |
133 } | 136 } |
134 | 137 |
135 OmniboxResultView::~OmniboxResultView() { | 138 OmniboxResultView::~OmniboxResultView() { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 icon = IDR_OMNIBOX_SEARCH_SELECTED; | 319 icon = IDR_OMNIBOX_SEARCH_SELECTED; |
317 break; | 320 break; |
318 case IDR_OMNIBOX_STAR: | 321 case IDR_OMNIBOX_STAR: |
319 icon = IDR_OMNIBOX_STAR_SELECTED; | 322 icon = IDR_OMNIBOX_STAR_SELECTED; |
320 break; | 323 break; |
321 default: | 324 default: |
322 NOTREACHED(); | 325 NOTREACHED(); |
323 break; | 326 break; |
324 } | 327 } |
325 } | 328 } |
326 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon); | 329 return *(location_bar_->GetThemeProvider()->GetImageSkiaNamed(icon)); |
327 } | 330 } |
328 | 331 |
329 const gfx::ImageSkia* OmniboxResultView::GetKeywordIcon() const { | 332 const gfx::ImageSkia* OmniboxResultView::GetKeywordIcon() const { |
330 // NOTE: If we ever begin returning icons of varying size, then callers need | 333 // NOTE: If we ever begin returning icons of varying size, then callers need |
331 // to ensure that |keyword_icon_| is resized each time its image is reset. | 334 // to ensure that |keyword_icon_| is resized each time its image is reset. |
332 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 335 return location_bar_->GetThemeProvider()->GetImageSkiaNamed( |
333 (GetState() == SELECTED) ? IDR_OMNIBOX_TTS_SELECTED : IDR_OMNIBOX_TTS); | 336 (GetState() == SELECTED) ? IDR_OMNIBOX_TTS_SELECTED : IDR_OMNIBOX_TTS); |
334 } | 337 } |
335 | 338 |
336 int OmniboxResultView::DrawString( | 339 int OmniboxResultView::DrawString( |
337 gfx::Canvas* canvas, | 340 gfx::Canvas* canvas, |
338 const string16& text, | 341 const string16& text, |
339 const ACMatchClassifications& classifications, | 342 const ACMatchClassifications& classifications, |
340 bool force_dim, | 343 bool force_dim, |
341 int x, | 344 int x, |
342 int y) { | 345 int y) { |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 int x = GetMirroredXForRect(keyword_text_bounds_); | 624 int x = GetMirroredXForRect(keyword_text_bounds_); |
622 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); | 625 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); |
623 PaintMatch(canvas, *match_.associated_keyword.get(), x); | 626 PaintMatch(canvas, *match_.associated_keyword.get(), x); |
624 } | 627 } |
625 } | 628 } |
626 | 629 |
627 void OmniboxResultView::AnimationProgressed(const ui::Animation* animation) { | 630 void OmniboxResultView::AnimationProgressed(const ui::Animation* animation) { |
628 Layout(); | 631 Layout(); |
629 SchedulePaint(); | 632 SchedulePaint(); |
630 } | 633 } |
OLD | NEW |