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

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

Issue 1378023003: Update Location Bar Bubbles Layout for Material Design (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
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/layout_constants.h" 8 #include "chrome/browser/ui/views/layout_constants.h"
9 #include "ui/base/resource/material_design/material_design_controller.h"
9 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/color_utils.h" 12 #include "ui/gfx/color_utils.h"
12 #include "ui/views/controls/image_view.h" 13 #include "ui/views/controls/image_view.h"
13 #include "ui/views/painter.h" 14 #include "ui/views/painter.h"
14 15
15 namespace { 16 namespace {
16 17
17 SkColor CalculateImageColor(gfx::ImageSkia* image) { 18 SkColor CalculateImageColor(gfx::ImageSkia* image) {
18 // We grab the color of the middle pixel of the image, which we treat as 19 // We grab the color of the middle pixel of the image, which we treat as
(...skipping 20 matching lines...) Expand all
39 image_->SetImage( 40 image_->SetImage(
40 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 41 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
41 contained_image)); 42 contained_image));
42 } 43 }
43 44
44 // Disable separate hit testing for |image_|. This prevents views treating 45 // Disable separate hit testing for |image_|. This prevents views treating
45 // |image_| as a separate mouse hover region from |this|. 46 // |image_| as a separate mouse hover region from |this|.
46 image_->set_interactive(false); 47 image_->set_interactive(false);
47 AddChildView(image_); 48 AddChildView(image_);
48 49
50 if (ui::MaterialDesignController::IsModeMaterial())
51 label_->SetAutoColorReadabilityEnabled(false);
Peter Kasting 2015/10/01 01:12:17 You shouldn't need to do this; if you do something
jonross 2015/10/01 15:46:50 Yeah it is rejecting White text on all three backg
49 label_->SetEnabledColor(text_color); 52 label_->SetEnabledColor(text_color);
50 53
51 if (elide_in_middle) 54 if (elide_in_middle)
52 label_->SetElideBehavior(gfx::ELIDE_MIDDLE); 55 label_->SetElideBehavior(gfx::ELIDE_MIDDLE);
53 AddChildView(label_); 56 AddChildView(label_);
54 } 57 }
55 58
56 IconLabelBubbleView::~IconLabelBubbleView() { 59 IconLabelBubbleView::~IconLabelBubbleView() {
57 } 60 }
58 61
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return 1.0; 97 return 1.0;
95 } 98 }
96 99
97 gfx::Size IconLabelBubbleView::GetPreferredSize() const { 100 gfx::Size IconLabelBubbleView::GetPreferredSize() const {
98 // Height will be ignored by the LocationBarView. 101 // Height will be ignored by the LocationBarView.
99 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); 102 return GetSizeForLabelWidth(label_->GetPreferredSize().width());
100 } 103 }
101 104
102 void IconLabelBubbleView::Layout() { 105 void IconLabelBubbleView::Layout() {
103 const int image_width = image()->GetPreferredSize().width(); 106 const int image_width = image()->GetPreferredSize().width();
104 image_->SetBounds(std::min((width() - image_width) / 2, 107 const int image_x = std::min((width() - image_width) / 2,
105 GetBubbleOuterPadding(!is_extension_icon_)), 108 GetBubbleOuterPadding(!is_extension_icon_));
106 0, image_->GetPreferredSize().width(), height()); 109 if (ui::MaterialDesignController::IsModeMaterial()) {
110 const int image_height = image()->GetPreferredSize().height();
111 const int image_veritcal_padding = (height() - image_height) / 2;
Peter Kasting 2015/10/01 01:12:17 Nit: vertical -- but I'd probably just inline this
112 image_->SetBounds(image_x, image_veritcal_padding, image_width,
113 image_height);
114 } else {
115 image_->SetBounds(image_x, 0, image_width, height());
116 }
107 117
108 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 118 const int padding = GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING);
109 int pre_label_width = 119 int pre_label_width =
110 GetBubbleOuterPadding(true) + (image_width ? (image_width + padding) : 0); 120 GetBubbleOuterPadding(true) + (image_width ? (image_width + padding) : 0);
111 label_->SetBounds(pre_label_width, 0, 121 label_->SetBounds(pre_label_width, 0,
112 width() - pre_label_width - GetBubbleOuterPadding(false), 122 width() - pre_label_width - GetBubbleOuterPadding(false),
113 height()); 123 height());
114 } 124 }
115 125
116 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int width) const { 126 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int width) const {
117 gfx::Size size(image_->GetPreferredSize()); 127 gfx::Size size(image_->GetPreferredSize());
118 if (ShouldShowBackground()) { 128 if (ShouldShowBackground()) {
119 const int image_width = image_->GetPreferredSize().width(); 129 const int image_width = image_->GetPreferredSize().width();
120 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 130 const int padding = GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING);
121 const int non_label_width = 131 const int non_label_width =
122 GetBubbleOuterPadding(true) + 132 GetBubbleOuterPadding(true) +
123 (image_width ? (image_width + padding) : 0) + 133 (image_width ? (image_width + padding) : 0) +
124 GetBubbleOuterPadding(false); 134 GetBubbleOuterPadding(false);
125 size = gfx::Size(WidthMultiplier() * (width + non_label_width), 0); 135 size = gfx::Size(WidthMultiplier() * (width + non_label_width), 0);
126 size.SetToMax(background_painter_->GetMinimumSize()); 136 size.SetToMax(background_painter_->GetMinimumSize());
127 } 137 }
128 138
129 return size; 139 return size;
130 } 140 }
(...skipping 21 matching lines...) Expand all
152 const char* IconLabelBubbleView::GetClassName() const { 162 const char* IconLabelBubbleView::GetClassName() const {
153 return "IconLabelBubbleView"; 163 return "IconLabelBubbleView";
154 } 164 }
155 165
156 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { 166 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) {
157 if (!ShouldShowBackground()) 167 if (!ShouldShowBackground())
158 return; 168 return;
159 if (background_painter_) 169 if (background_painter_)
160 background_painter_->Paint(canvas, size()); 170 background_painter_->Paint(canvas, size());
161 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698