| 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 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 5 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/search_engines/template_url_service.h" | 13 #include "chrome/browser/search_engines/template_url_service.h" |
| 14 #include "chrome/browser/search_engines/template_url_service_factory.h" | 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 17 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 21 #include "ui/views/controls/image_view.h" | 21 #include "ui/views/controls/image_view.h" |
| 22 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
| 23 | 23 |
| 24 | 24 |
| 25 KeywordHintView::KeywordHintView(Profile* profile, | 25 KeywordHintView::KeywordHintView(Profile* profile, |
| 26 const gfx::Font& font, | 26 const gfx::FontList& font_list, |
| 27 int font_y_offset, | 27 int font_y_offset, |
| 28 SkColor text_color, | 28 SkColor text_color, |
| 29 SkColor background_color) | 29 SkColor background_color) |
| 30 : profile_(profile), | 30 : profile_(profile), |
| 31 tab_image_(new views::ImageView()) { | 31 tab_image_(new views::ImageView()) { |
| 32 leading_label_ = | 32 leading_label_ = |
| 33 CreateLabel(font, font_y_offset, text_color, background_color); | 33 CreateLabel(font_list, font_y_offset, text_color, background_color); |
| 34 tab_image_->SetImage( | 34 tab_image_->SetImage( |
| 35 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 35 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 36 IDR_OMNIBOX_KEYWORD_HINT_TAB)); | 36 IDR_OMNIBOX_KEYWORD_HINT_TAB)); |
| 37 AddChildView(tab_image_); | 37 AddChildView(tab_image_); |
| 38 trailing_label_ = | 38 trailing_label_ = |
| 39 CreateLabel(font, font_y_offset, text_color, background_color); | 39 CreateLabel(font_list, font_y_offset, text_color, background_color); |
| 40 } | 40 } |
| 41 | 41 |
| 42 KeywordHintView::~KeywordHintView() { | 42 KeywordHintView::~KeywordHintView() { |
| 43 } | 43 } |
| 44 | 44 |
| 45 void KeywordHintView::SetKeyword(const string16& keyword) { | 45 void KeywordHintView::SetKeyword(const string16& keyword) { |
| 46 keyword_ = keyword; | 46 keyword_ = keyword; |
| 47 if (keyword_.empty()) | 47 if (keyword_.empty()) |
| 48 return; | 48 return; |
| 49 DCHECK(profile_); | 49 DCHECK(profile_); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 leading_label_->SetBounds(0, 0, show_labels ? leading_size.width() : 0, | 86 leading_label_->SetBounds(0, 0, show_labels ? leading_size.width() : 0, |
| 87 leading_size.height()); | 87 leading_size.height()); |
| 88 tab_image_->SetBounds(leading_label_->bounds().right(), 0, tab_width, | 88 tab_image_->SetBounds(leading_label_->bounds().right(), 0, tab_width, |
| 89 height()); | 89 height()); |
| 90 gfx::Size trailing_size(trailing_label_->GetPreferredSize()); | 90 gfx::Size trailing_size(trailing_label_->GetPreferredSize()); |
| 91 trailing_label_->SetBounds(tab_image_->bounds().right(), 0, | 91 trailing_label_->SetBounds(tab_image_->bounds().right(), 0, |
| 92 show_labels ? trailing_size.width() : 0, | 92 show_labels ? trailing_size.width() : 0, |
| 93 trailing_size.height()); | 93 trailing_size.height()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 views::Label* KeywordHintView::CreateLabel(const gfx::Font& font, | 96 views::Label* KeywordHintView::CreateLabel(const gfx::FontList& font_list, |
| 97 int font_y_offset, | 97 int font_y_offset, |
| 98 SkColor text_color, | 98 SkColor text_color, |
| 99 SkColor background_color) { | 99 SkColor background_color) { |
| 100 views::Label* label = new views::Label(); | 100 views::Label* label = new views::Label(string16(), font_list); |
| 101 label->set_border(views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); | 101 label->set_border(views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); |
| 102 label->SetFont(font); | |
| 103 label->SetEnabledColor(text_color); | 102 label->SetEnabledColor(text_color); |
| 104 label->SetBackgroundColor(background_color); | 103 label->SetBackgroundColor(background_color); |
| 105 AddChildView(label); | 104 AddChildView(label); |
| 106 return label; | 105 return label; |
| 107 } | 106 } |
| OLD | NEW |