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

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

Issue 25039002: Always aligns text at vertically center (Textfield, Label). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced. Created 7 years, 1 month 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/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::FontList& font_list, 26 const gfx::FontList& font_list,
27 int font_y_offset,
28 SkColor text_color, 27 SkColor text_color,
29 SkColor background_color) 28 SkColor background_color)
30 : profile_(profile), 29 : profile_(profile),
31 tab_image_(new views::ImageView()) { 30 tab_image_(new views::ImageView()) {
32 leading_label_ = 31 leading_label_ =
33 CreateLabel(font_list, font_y_offset, text_color, background_color); 32 CreateLabel(font_list, text_color, background_color);
34 tab_image_->SetImage( 33 tab_image_->SetImage(
35 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 34 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
36 IDR_OMNIBOX_KEYWORD_HINT_TAB)); 35 IDR_OMNIBOX_KEYWORD_HINT_TAB));
37 AddChildView(tab_image_); 36 AddChildView(tab_image_);
38 trailing_label_ = 37 trailing_label_ =
39 CreateLabel(font_list, font_y_offset, text_color, background_color); 38 CreateLabel(font_list, text_color, background_color);
40 } 39 }
41 40
42 KeywordHintView::~KeywordHintView() { 41 KeywordHintView::~KeywordHintView() {
43 } 42 }
44 43
45 void KeywordHintView::SetKeyword(const string16& keyword) { 44 void KeywordHintView::SetKeyword(const string16& keyword) {
46 keyword_ = keyword; 45 keyword_ = keyword;
47 if (keyword_.empty()) 46 if (keyword_.empty())
48 return; 47 return;
49 DCHECK(profile_); 48 DCHECK(profile_);
(...skipping 27 matching lines...) Expand all
77 gfx::Size KeywordHintView::GetMinimumSize() { 76 gfx::Size KeywordHintView::GetMinimumSize() {
78 // Height will be ignored by the LocationBarView. 77 // Height will be ignored by the LocationBarView.
79 return tab_image_->GetPreferredSize(); 78 return tab_image_->GetPreferredSize();
80 } 79 }
81 80
82 void KeywordHintView::Layout() { 81 void KeywordHintView::Layout() {
83 int tab_width = tab_image_->GetPreferredSize().width(); 82 int tab_width = tab_image_->GetPreferredSize().width();
84 bool show_labels = (width() != tab_width); 83 bool show_labels = (width() != tab_width);
85 gfx::Size leading_size(leading_label_->GetPreferredSize()); 84 gfx::Size leading_size(leading_label_->GetPreferredSize());
86 leading_label_->SetBounds(0, 0, show_labels ? leading_size.width() : 0, 85 leading_label_->SetBounds(0, 0, show_labels ? leading_size.width() : 0,
87 leading_size.height()); 86 height());
88 tab_image_->SetBounds(leading_label_->bounds().right(), 0, tab_width, 87 tab_image_->SetBounds(leading_label_->bounds().right(), 0, tab_width,
89 height()); 88 height());
90 gfx::Size trailing_size(trailing_label_->GetPreferredSize()); 89 gfx::Size trailing_size(trailing_label_->GetPreferredSize());
91 trailing_label_->SetBounds(tab_image_->bounds().right(), 0, 90 trailing_label_->SetBounds(tab_image_->bounds().right(), 0,
92 show_labels ? trailing_size.width() : 0, 91 show_labels ? trailing_size.width() : 0,
93 trailing_size.height()); 92 height());
94 } 93 }
95 94
96 views::Label* KeywordHintView::CreateLabel(const gfx::FontList& font_list, 95 views::Label* KeywordHintView::CreateLabel(const gfx::FontList& font_list,
97 int font_y_offset,
98 SkColor text_color, 96 SkColor text_color,
99 SkColor background_color) { 97 SkColor background_color) {
100 views::Label* label = new views::Label(string16(), font_list); 98 views::Label* label = new views::Label(string16(), font_list);
101 label->set_border(views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0));
102 label->SetEnabledColor(text_color); 99 label->SetEnabledColor(text_color);
103 label->SetBackgroundColor(background_color); 100 label->SetBackgroundColor(background_color);
104 AddChildView(label); 101 AddChildView(label);
105 return label; 102 return label;
106 } 103 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/keyword_hint_view.h ('k') | chrome/browser/ui/views/location_bar/location_bar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698