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

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

Issue 2555623002: Last round of cleaning up MD layout constants. (Closed)
Patch Set: pkasting review, remove debug code, rebase Created 4 years 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 "chrome/browser/ui/layout_constants.h" 7 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
8 #include "ui/accessibility/ax_node_data.h" 8 #include "ui/accessibility/ax_node_data.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/color_utils.h" 10 #include "ui/gfx/color_utils.h"
11 #include "ui/gfx/scoped_canvas.h" 11 #include "ui/gfx/scoped_canvas.h"
12 #include "ui/native_theme/native_theme.h" 12 #include "ui/native_theme/native_theme.h"
13 #include "ui/views/animation/ink_drop_highlight.h" 13 #include "ui/views/animation/ink_drop_highlight.h"
14 #include "ui/views/border.h" 14 #include "ui/views/border.h"
15 #include "ui/views/controls/image_view.h" 15 #include "ui/views/controls/image_view.h"
16 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
17 17
(...skipping 17 matching lines...) Expand all
35 35
36 if (elide_in_middle) 36 if (elide_in_middle)
37 label_->SetElideBehavior(gfx::ELIDE_MIDDLE); 37 label_->SetElideBehavior(gfx::ELIDE_MIDDLE);
38 AddChildView(label_); 38 AddChildView(label_);
39 39
40 // Bubbles are given the full internal height of the location bar so that all 40 // Bubbles are given the full internal height of the location bar so that all
41 // child views in the location bar have the same height. The visible height of 41 // child views in the location bar have the same height. The visible height of
42 // the bubble should be smaller, so use an empty border to shrink down the 42 // the bubble should be smaller, so use an empty border to shrink down the
43 // content bounds so the background gets painted correctly. 43 // content bounds so the background gets painted correctly.
44 SetBorder(views::CreateEmptyBorder( 44 SetBorder(views::CreateEmptyBorder(
45 gfx::Insets(GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING), 0))); 45 gfx::Insets(LocationBarView::kBubbleVerticalPadding, 0)));
46 46
47 // Flip the canvas in RTL so the separator is drawn on the correct side. 47 // Flip the canvas in RTL so the separator is drawn on the correct side.
48 EnableCanvasFlippingForRTLUI(true); 48 EnableCanvasFlippingForRTLUI(true);
49 } 49 }
50 50
51 IconLabelBubbleView::~IconLabelBubbleView() { 51 IconLabelBubbleView::~IconLabelBubbleView() {
52 } 52 }
53 53
54 void IconLabelBubbleView::SetLabel(const base::string16& label) { 54 void IconLabelBubbleView::SetLabel(const base::string16& label) {
55 label_->SetText(label); 55 label_->SetText(label);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 87 }
88 88
89 bool IconLabelBubbleView::OnKeyReleased(const ui::KeyEvent& event) { 89 bool IconLabelBubbleView::OnKeyReleased(const ui::KeyEvent& event) {
90 if (event.key_code() == ui::VKEY_SPACE) 90 if (event.key_code() == ui::VKEY_SPACE)
91 return OnActivate(event); 91 return OnActivate(event);
92 return false; 92 return false;
93 } 93 }
94 94
95 void IconLabelBubbleView::Layout() { 95 void IconLabelBubbleView::Layout() {
96 // Compute the image bounds. Leading and trailing padding are the same. 96 // Compute the image bounds. Leading and trailing padding are the same.
97 int image_x = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 97 int image_x = LocationBarView::kHorizontalPadding;
98 int bubble_trailing_padding = image_x; 98 int bubble_trailing_padding = image_x;
99 99
100 // If ShouldShowLabel() is true, then either we show a label in the 100 // If ShouldShowLabel() is true, then either we show a label in the
101 // steady state, or we're not yet in the last portion of the animation. In 101 // steady state, or we're not yet in the last portion of the animation. In
102 // these cases, we leave the leading and trailing padding alone. If this is 102 // these cases, we leave the leading and trailing padding alone. If this is
103 // false, however, then we're only showing the image, and either the view 103 // false, however, then we're only showing the image, and either the view
104 // width is the image width, or it's animating downwards and getting close to 104 // width is the image width, or it's animating downwards and getting close to
105 // it. In these cases, we want to shrink the trailing padding first, so the 105 // it. In these cases, we want to shrink the trailing padding first, so the
106 // image slides all the way to the trailing edge before slowing or stopping; 106 // image slides all the way to the trailing edge before slowing or stopping;
107 // then we want to shrink the leading padding down to zero. 107 // then we want to shrink the leading padding down to zero.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 const int separator_width = (GetScaleFactor() >= 2) ? 0 : 1; 185 const int separator_width = (GetScaleFactor() >= 2) ? 0 : 1;
186 const int post_label_width = 186 const int post_label_width =
187 (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding()); 187 (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding());
188 188
189 // |multiplier| grows from zero to one, stays equal to one and then shrinks 189 // |multiplier| grows from zero to one, stays equal to one and then shrinks
190 // to zero again. The view width should correspondingly grow from zero to 190 // to zero again. The view width should correspondingly grow from zero to
191 // fully showing both label and icon, stay there, then shrink to just large 191 // fully showing both label and icon, stay there, then shrink to just large
192 // enough to show the icon. We don't want to shrink all the way back to 192 // enough to show the icon. We don't want to shrink all the way back to
193 // zero, since this would mean the view would completely disappear and then 193 // zero, since this would mean the view would completely disappear and then
194 // pop back to an icon after the animation finishes. 194 // pop back to an icon after the animation finishes.
195 const int max_width = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + 195 const int max_width = LocationBarView::kHorizontalPadding +
196 image_->GetPreferredSize().width() + 196 image_->GetPreferredSize().width() +
197 GetInternalSpacing() + label_width + post_label_width; 197 GetInternalSpacing() + label_width + post_label_width;
198 const int current_width = WidthMultiplier() * max_width; 198 const int current_width = WidthMultiplier() * max_width;
199 size.set_width(shrinking ? std::max(current_width, size.width()) 199 size.set_width(shrinking ? std::max(current_width, size.width())
200 : current_width); 200 : current_width);
201 } 201 }
202 return size; 202 return size;
203 } 203 }
204 204
205 int IconLabelBubbleView::GetInternalSpacing() const { 205 int IconLabelBubbleView::GetInternalSpacing() const {
206 return image_->GetPreferredSize().IsEmpty() 206 return image_->GetPreferredSize().IsEmpty()
207 ? 0 207 ? 0
208 : GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 208 : LocationBarView::kHorizontalPadding;
209 } 209 }
210 210
211 int IconLabelBubbleView::GetPostSeparatorPadding() const { 211 int IconLabelBubbleView::GetPostSeparatorPadding() const {
212 // The location bar will add LOCATION_BAR_HORIZONTAL_PADDING after us. 212 // The location bar will add LocationBarView::kHorizontalPadding after us.
213 return kSpaceBesideSeparator - 213 return kSpaceBesideSeparator - LocationBarView::kHorizontalPadding;
214 GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
215 } 214 }
216 215
217 float IconLabelBubbleView::GetScaleFactor() const { 216 float IconLabelBubbleView::GetScaleFactor() const {
218 const views::Widget* widget = GetWidget(); 217 const views::Widget* widget = GetWidget();
219 // There may be no widget in tests, and in ash there may be no compositor if 218 // There may be no widget in tests, and in ash there may be no compositor if
220 // the native view of the Widget doesn't have a parent. 219 // the native view of the Widget doesn't have a parent.
221 const ui::Compositor* compositor = widget ? widget->GetCompositor() : nullptr; 220 const ui::Compositor* compositor = widget ? widget->GetCompositor() : nullptr;
222 return compositor ? compositor->device_scale_factor() : 1.0f; 221 return compositor ? compositor->device_scale_factor() : 1.0f;
223 } 222 }
224 223
(...skipping 17 matching lines...) Expand all
242 241
243 // Draw the 1 px separator. 242 // Draw the 1 px separator.
244 gfx::ScopedCanvas scoped_canvas(canvas); 243 gfx::ScopedCanvas scoped_canvas(canvas);
245 const float scale = canvas->UndoDeviceScaleFactor(); 244 const float scale = canvas->UndoDeviceScaleFactor();
246 // Keep the separator aligned on a pixel center. 245 // Keep the separator aligned on a pixel center.
247 const gfx::RectF pixel_aligned_bounds = 246 const gfx::RectF pixel_aligned_bounds =
248 gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0); 247 gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0);
249 canvas->DrawLine(pixel_aligned_bounds.top_right(), 248 canvas->DrawLine(pixel_aligned_bounds.top_right(),
250 pixel_aligned_bounds.bottom_right(), separator_color); 249 pixel_aligned_bounds.bottom_right(), separator_color);
251 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698