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

Side by Side Diff: chrome/browser/ui/views/location_bar/icon_label_bubble_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/icon_label_bubble_view.h" 5 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
9 #include "grit/theme_resources.h" 9 #include "grit/theme_resources.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/color_utils.h" 12 #include "ui/gfx/color_utils.h"
13 #include "ui/views/controls/image_view.h" 13 #include "ui/views/controls/image_view.h"
14 #include "ui/views/controls/label.h" 14 #include "ui/views/controls/label.h"
15 #include "ui/views/painter.h" 15 #include "ui/views/painter.h"
16 16
17 17
18 IconLabelBubbleView::IconLabelBubbleView(const int background_images[], 18 IconLabelBubbleView::IconLabelBubbleView(const int background_images[],
19 const int hover_background_images[], 19 const int hover_background_images[],
20 int contained_image, 20 int contained_image,
21 const gfx::FontList& font_list, 21 const gfx::FontList& font_list,
22 int font_y_offset,
23 SkColor text_color, 22 SkColor text_color,
24 SkColor parent_background_color, 23 SkColor parent_background_color,
25 bool elide_in_middle) 24 bool elide_in_middle)
26 : background_painter_( 25 : background_painter_(
27 views::Painter::CreateImageGridPainter(background_images)), 26 views::Painter::CreateImageGridPainter(background_images)),
28 image_(new views::ImageView()), 27 image_(new views::ImageView()),
29 label_(new views::Label(string16(), font_list)), 28 label_(new views::Label(string16(), font_list)),
30 is_extension_icon_(false), 29 is_extension_icon_(false),
31 in_hover_(false) { 30 in_hover_(false) {
32 image_->SetImage( 31 image_->SetImage(
33 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 32 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
34 contained_image)); 33 contained_image));
35 34
36 // Disable separate hit testing for |image_|. This prevents views treating 35 // Disable separate hit testing for |image_|. This prevents views treating
37 // |image_| as a separate mouse hover region from |this|. 36 // |image_| as a separate mouse hover region from |this|.
38 image_->set_interactive(false); 37 image_->set_interactive(false);
39 AddChildView(image_); 38 AddChildView(image_);
40 39
41 if (hover_background_images) { 40 if (hover_background_images) {
42 hover_background_painter_.reset( 41 hover_background_painter_.reset(
43 views::Painter::CreateImageGridPainter(hover_background_images)); 42 views::Painter::CreateImageGridPainter(hover_background_images));
44 } 43 }
45 44
46 label_->set_border(views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0));
47 label_->SetEnabledColor(text_color); 45 label_->SetEnabledColor(text_color);
48 // Calculate the actual background color for the label. The background images 46 // Calculate the actual background color for the label. The background images
49 // are painted atop |parent_background_color|. We grab the color of the 47 // are painted atop |parent_background_color|. We grab the color of the
50 // middle pixel of the middle image of the background, which we treat as the 48 // middle pixel of the middle image of the background, which we treat as the
51 // representative color of the entire background (reasonable, given the 49 // representative color of the entire background (reasonable, given the
52 // current appearance of these images). Then we alpha-blend it over the 50 // current appearance of these images). Then we alpha-blend it over the
53 // parent background color to determine the actual color the label text will 51 // parent background color to determine the actual color the label text will
54 // sit atop. 52 // sit atop.
55 const SkBitmap& bitmap( 53 const SkBitmap& bitmap(
56 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 54 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
(...skipping 29 matching lines...) Expand all
86 // Height will be ignored by the LocationBarView. 84 // Height will be ignored by the LocationBarView.
87 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); 85 return GetSizeForLabelWidth(label_->GetPreferredSize().width());
88 } 86 }
89 87
90 void IconLabelBubbleView::Layout() { 88 void IconLabelBubbleView::Layout() {
91 image_->SetBounds(GetBubbleOuterPadding(!is_extension_icon_), 0, 89 image_->SetBounds(GetBubbleOuterPadding(!is_extension_icon_), 0,
92 image_->GetPreferredSize().width(), height()); 90 image_->GetPreferredSize().width(), height());
93 const int pre_label_width = GetPreLabelWidth(); 91 const int pre_label_width = GetPreLabelWidth();
94 label_->SetBounds(pre_label_width, 0, 92 label_->SetBounds(pre_label_width, 0,
95 width() - pre_label_width - GetBubbleOuterPadding(false), 93 width() - pre_label_width - GetBubbleOuterPadding(false),
96 label_->GetPreferredSize().height()); 94 height());
97 } 95 }
98 96
99 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int width) const { 97 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int width) const {
100 gfx::Size size(GetPreLabelWidth() + width + GetBubbleOuterPadding(false), 0); 98 gfx::Size size(GetPreLabelWidth() + width + GetBubbleOuterPadding(false), 0);
101 size.SetToMax(background_painter_->GetMinimumSize()); 99 size.SetToMax(background_painter_->GetMinimumSize());
102 return size; 100 return size;
103 } 101 }
104 102
105 void IconLabelBubbleView::OnMouseEntered(const ui::MouseEvent& event) { 103 void IconLabelBubbleView::OnMouseEntered(const ui::MouseEvent& event) {
106 in_hover_ = true; 104 in_hover_ = true;
(...skipping 17 matching lines...) Expand all
124 views::Painter* painter = (in_hover_ && hover_background_painter_) ? 122 views::Painter* painter = (in_hover_ && hover_background_painter_) ?
125 hover_background_painter_.get() : background_painter_.get(); 123 hover_background_painter_.get() : background_painter_.get();
126 painter->Paint(canvas, size()); 124 painter->Paint(canvas, size());
127 } 125 }
128 126
129 int IconLabelBubbleView::GetPreLabelWidth() const { 127 int IconLabelBubbleView::GetPreLabelWidth() const {
130 const int image_width = image_->GetPreferredSize().width(); 128 const int image_width = image_->GetPreferredSize().width();
131 return GetBubbleOuterPadding(true) + 129 return GetBubbleOuterPadding(true) +
132 (image_width ? (image_width + LocationBarView::GetItemPadding()) : 0); 130 (image_width ? (image_width + LocationBarView::GetItemPadding()) : 0);
133 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698