Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/browser/ui/views/location_bar/keyword_hint_view.cc

Issue 10453101: Convert most of the rest of chrome to ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/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 "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 "third_party/skia/include/core/SkBitmap.h"
19 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/image/image_skia.h"
22 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
23 23
24 // 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.
25 static const int kTabImageYOffset = 4; 25 static const int kTabImageYOffset = 4;
26 26
27 // The tab key image. 27 // The tab key image.
28 static const SkBitmap* kTabButtonBitmap = NULL; 28 static const gfx::ImageSkia* kTabButtonImage = NULL;
29 29
30 KeywordHintView::KeywordHintView(Profile* profile) : profile_(profile) { 30 KeywordHintView::KeywordHintView(Profile* profile) : profile_(profile) {
31 leading_label_ = CreateLabel(); 31 leading_label_ = CreateLabel();
32 trailing_label_ = CreateLabel(); 32 trailing_label_ = CreateLabel();
33 33
34 if (!kTabButtonBitmap) { 34 if (!kTabButtonImage) {
35 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 35 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
36 kTabButtonBitmap = rb.GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); 36 kTabButtonImage = rb.GetImageSkiaNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB);
37 } 37 }
38 } 38 }
39 39
40 KeywordHintView::~KeywordHintView() { 40 KeywordHintView::~KeywordHintView() {
41 } 41 }
42 42
43 void KeywordHintView::SetFont(const gfx::Font& font) { 43 void KeywordHintView::SetFont(const gfx::Font& font) {
44 leading_label_->SetFont(font); 44 leading_label_->SetFont(font);
45 trailing_label_->SetFont(font); 45 trailing_label_->SetFont(font);
46 } 46 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 void KeywordHintView::OnPaint(gfx::Canvas* canvas) { 80 void KeywordHintView::OnPaint(gfx::Canvas* canvas) {
81 int image_x = leading_label_->visible() ? leading_label_->width() : 0; 81 int image_x = leading_label_->visible() ? leading_label_->width() : 0;
82 82
83 // Since we paint the button image directly on the canvas (instead of using a 83 // Since we paint the button image directly on the canvas (instead of using a
84 // child view), we must mirror the button's position manually if the locale 84 // child view), we must mirror the button's position manually if the locale
85 // is right-to-left. 85 // is right-to-left.
86 gfx::Rect tab_button_bounds(image_x, 86 gfx::Rect tab_button_bounds(image_x,
87 kTabImageYOffset, 87 kTabImageYOffset,
88 kTabButtonBitmap->width(), 88 kTabButtonImage->width(),
89 kTabButtonBitmap->height()); 89 kTabButtonImage->height());
90 tab_button_bounds.set_x(GetMirroredXForRect(tab_button_bounds)); 90 tab_button_bounds.set_x(GetMirroredXForRect(tab_button_bounds));
91 canvas->DrawBitmapInt(*kTabButtonBitmap, 91 canvas->DrawBitmapInt(*kTabButtonImage,
92 tab_button_bounds.x(), 92 tab_button_bounds.x(),
93 tab_button_bounds.y()); 93 tab_button_bounds.y());
94 } 94 }
95 95
96 gfx::Size KeywordHintView::GetPreferredSize() { 96 gfx::Size KeywordHintView::GetPreferredSize() {
97 // TODO(sky): currently height doesn't matter, once baseline support is 97 // TODO(sky): currently height doesn't matter, once baseline support is
98 // added this should check baselines. 98 // added this should check baselines.
99 gfx::Size prefsize = leading_label_->GetPreferredSize(); 99 gfx::Size prefsize = leading_label_->GetPreferredSize();
100 int width = prefsize.width(); 100 int width = prefsize.width();
101 width += kTabButtonBitmap->width(); 101 width += kTabButtonImage->width();
102 prefsize = trailing_label_->GetPreferredSize(); 102 prefsize = trailing_label_->GetPreferredSize();
103 width += prefsize.width(); 103 width += prefsize.width();
104 return gfx::Size(width, prefsize.height()); 104 return gfx::Size(width, prefsize.height());
105 } 105 }
106 106
107 gfx::Size KeywordHintView::GetMinimumSize() { 107 gfx::Size KeywordHintView::GetMinimumSize() {
108 // TODO(sky): currently height doesn't matter, once baseline support is 108 // TODO(sky): currently height doesn't matter, once baseline support is
109 // added this should check baselines. 109 // added this should check baselines.
110 return gfx::Size(kTabButtonBitmap->width(), 0); 110 return gfx::Size(kTabButtonImage->width(), 0);
111 } 111 }
112 112
113 void KeywordHintView::Layout() { 113 void KeywordHintView::Layout() {
114 // TODO(sky): baseline layout. 114 // TODO(sky): baseline layout.
115 bool show_labels = (width() != kTabButtonBitmap->width()); 115 bool show_labels = (width() != kTabButtonImage->width());
116 116
117 leading_label_->SetVisible(show_labels); 117 leading_label_->SetVisible(show_labels);
118 trailing_label_->SetVisible(show_labels); 118 trailing_label_->SetVisible(show_labels);
119 int x = 0; 119 int x = 0;
120 gfx::Size pref; 120 gfx::Size pref;
121 121
122 if (show_labels) { 122 if (show_labels) {
123 pref = leading_label_->GetPreferredSize(); 123 pref = leading_label_->GetPreferredSize();
124 leading_label_->SetBounds(x, 0, pref.width(), height()); 124 leading_label_->SetBounds(x, 0, pref.width(), height());
125 125
126 x += pref.width() + kTabButtonBitmap->width(); 126 x += pref.width() + kTabButtonImage->width();
127 pref = trailing_label_->GetPreferredSize(); 127 pref = trailing_label_->GetPreferredSize();
128 trailing_label_->SetBounds(x, 0, pref.width(), height()); 128 trailing_label_->SetBounds(x, 0, pref.width(), height());
129 } 129 }
130 } 130 }
131 131
132 views::Label* KeywordHintView::CreateLabel() { 132 views::Label* KeywordHintView::CreateLabel() {
133 views::Label* label = new views::Label(); 133 views::Label* label = new views::Label();
134 label->SetBackgroundColor(LocationBarView::GetColor(ToolbarModel::NONE, 134 label->SetBackgroundColor(LocationBarView::GetColor(ToolbarModel::NONE,
135 LocationBarView::BACKGROUND)); 135 LocationBarView::BACKGROUND));
136 label->SetEnabledColor(LocationBarView::GetColor(ToolbarModel::NONE, 136 label->SetEnabledColor(LocationBarView::GetColor(ToolbarModel::NONE,
137 LocationBarView::DEEMPHASIZED_TEXT)); 137 LocationBarView::DEEMPHASIZED_TEXT));
138 AddChildView(label); 138 AddChildView(label);
139 return label; 139 return label;
140 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698