OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 10 #include "base/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 "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
16 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
21 #include "views/controls/label.h" | 22 #include "views/controls/label.h" |
22 | 23 |
23 // Amount of space to offset the tab image from the top of the view by. | 24 // Amount of space to offset the tab image from the top of the view by. |
24 static const int kTabImageYOffset = 4; | 25 static const int kTabImageYOffset = 4; |
25 | 26 |
26 // The tab key image. | 27 // The tab key image. |
27 static const SkBitmap* kTabButtonBitmap = NULL; | 28 static const SkBitmap* kTabButtonBitmap = NULL; |
28 | 29 |
29 KeywordHintView::KeywordHintView(Profile* profile) : profile_(profile) { | 30 KeywordHintView::KeywordHintView(Profile* profile) : profile_(profile) { |
30 leading_label_ = new views::Label(); | 31 leading_label_ = CreateLabel(); |
31 trailing_label_ = new views::Label(); | 32 trailing_label_ = CreateLabel(); |
32 AddChildView(leading_label_); | |
33 AddChildView(trailing_label_); | |
34 | 33 |
35 if (!kTabButtonBitmap) { | 34 if (!kTabButtonBitmap) { |
36 kTabButtonBitmap = ResourceBundle::GetSharedInstance(). | 35 kTabButtonBitmap = ResourceBundle::GetSharedInstance(). |
37 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); | 36 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); |
38 } | 37 } |
39 } | 38 } |
40 | 39 |
41 KeywordHintView::~KeywordHintView() { | 40 KeywordHintView::~KeywordHintView() { |
42 } | 41 } |
43 | 42 |
44 void KeywordHintView::SetFont(const gfx::Font& font) { | 43 void KeywordHintView::SetFont(const gfx::Font& font) { |
45 leading_label_->SetFont(font); | 44 leading_label_->SetFont(font); |
46 trailing_label_->SetFont(font); | 45 trailing_label_->SetFont(font); |
47 } | 46 } |
48 | 47 |
49 void KeywordHintView::SetColor(const SkColor& color) { | |
50 leading_label_->SetColor(color); | |
51 trailing_label_->SetColor(color); | |
52 } | |
53 | |
54 void KeywordHintView::SetKeyword(const string16& keyword) { | 48 void KeywordHintView::SetKeyword(const string16& keyword) { |
55 keyword_ = keyword; | 49 keyword_ = keyword; |
56 if (keyword_.empty()) | 50 if (keyword_.empty()) |
57 return; | 51 return; |
58 DCHECK(profile_); | 52 DCHECK(profile_); |
59 TemplateURLService* url_service = | 53 TemplateURLService* url_service = |
60 TemplateURLServiceFactory::GetForProfile(profile_); | 54 TemplateURLServiceFactory::GetForProfile(profile_); |
61 if (!url_service) | 55 if (!url_service) |
62 return; | 56 return; |
63 | 57 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 121 |
128 if (show_labels) { | 122 if (show_labels) { |
129 pref = leading_label_->GetPreferredSize(); | 123 pref = leading_label_->GetPreferredSize(); |
130 leading_label_->SetBounds(x, 0, pref.width(), height()); | 124 leading_label_->SetBounds(x, 0, pref.width(), height()); |
131 | 125 |
132 x += pref.width() + kTabButtonBitmap->width(); | 126 x += pref.width() + kTabButtonBitmap->width(); |
133 pref = trailing_label_->GetPreferredSize(); | 127 pref = trailing_label_->GetPreferredSize(); |
134 trailing_label_->SetBounds(x, 0, pref.width(), height()); | 128 trailing_label_->SetBounds(x, 0, pref.width(), height()); |
135 } | 129 } |
136 } | 130 } |
| 131 |
| 132 views::Label* KeywordHintView::CreateLabel() { |
| 133 views::Label* label = new views::Label(); |
| 134 label->SetBackgroundColor(LocationBarView::GetColor(ToolbarModel::NONE, |
| 135 LocationBarView::BACKGROUND)); |
| 136 label->SetEnabledColor(LocationBarView::GetColor(ToolbarModel::NONE, |
| 137 LocationBarView::DEEMPHASIZED_TEXT)); |
| 138 AddChildView(label); |
| 139 return label; |
| 140 } |
OLD | NEW |