OLD | NEW |
---|---|
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 <iostream> | |
8 | |
7 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/layout_constants.h" | 10 #include "chrome/browser/ui/layout_constants.h" |
9 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" | 11 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
10 #include "ui/base/material_design/material_design_controller.h" | 12 #include "ui/base/material_design/material_design_controller.h" |
11 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/color_utils.h" | 15 #include "ui/gfx/color_utils.h" |
14 #include "ui/gfx/image/image_util.h" | 16 #include "ui/gfx/image/image_util.h" |
15 #include "ui/gfx/scoped_canvas.h" | 17 #include "ui/gfx/scoped_canvas.h" |
16 #include "ui/native_theme/native_theme.h" | 18 #include "ui/native_theme/native_theme.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 | 118 |
117 bool IconLabelBubbleView::IsShrinking() const { | 119 bool IconLabelBubbleView::IsShrinking() const { |
118 return false; | 120 return false; |
119 } | 121 } |
120 | 122 |
121 bool IconLabelBubbleView::OnActivate(const ui::Event& event) { | 123 bool IconLabelBubbleView::OnActivate(const ui::Event& event) { |
122 return false; | 124 return false; |
123 } | 125 } |
124 | 126 |
125 gfx::Size IconLabelBubbleView::GetPreferredSize() const { | 127 gfx::Size IconLabelBubbleView::GetPreferredSize() const { |
128 std::cout << "Icon::GetPreferredSize\n"; | |
Peter Kasting
2016/07/19 21:17:19
You may want to use the VLOG macro for this kind o
Kevin Bailey
2016/08/12 18:49:14
ack
| |
126 // Height will be ignored by the LocationBarView. | 129 // Height will be ignored by the LocationBarView. |
127 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); | 130 return GetSizeForLabelWidth(GetLabelPreferredWidth()); |
128 } | 131 } |
129 | 132 |
130 bool IconLabelBubbleView::OnKeyPressed(const ui::KeyEvent& event) { | 133 bool IconLabelBubbleView::OnKeyPressed(const ui::KeyEvent& event) { |
131 if (event.key_code() == ui::VKEY_RETURN) | 134 if (event.key_code() == ui::VKEY_RETURN) |
132 return OnActivate(event); | 135 return OnActivate(event); |
133 return false; | 136 return false; |
134 } | 137 } |
135 | 138 |
136 bool IconLabelBubbleView::OnKeyReleased(const ui::KeyEvent& event) { | 139 bool IconLabelBubbleView::OnKeyReleased(const ui::KeyEvent& event) { |
137 if (event.key_code() == ui::VKEY_SPACE) | 140 if (event.key_code() == ui::VKEY_SPACE) |
138 return OnActivate(event); | 141 return OnActivate(event); |
139 return false; | 142 return false; |
140 } | 143 } |
141 | 144 |
142 void IconLabelBubbleView::Layout() { | 145 void IconLabelBubbleView::Layout() { |
146 std::cout << "Icon::Layout " << (void*)this << "\n"; | |
143 // Compute the image bounds. In non-MD, the leading padding depends on | 147 // Compute the image bounds. In non-MD, the leading padding depends on |
144 // whether this is an extension icon, since extension icons and | 148 // whether this is an extension icon, since extension icons and |
145 // Chrome-provided icons are different sizes. In MD, these sizes are the | 149 // Chrome-provided icons are different sizes. In MD, these sizes are the |
146 // same, so it's not necessary to handle the two types differently. | 150 // same, so it's not necessary to handle the two types differently. |
147 const bool icon_has_enough_padding = | 151 const bool icon_has_enough_padding = |
148 !is_extension_icon_ || ui::MaterialDesignController::IsModeMaterial(); | 152 !is_extension_icon_ || ui::MaterialDesignController::IsModeMaterial(); |
149 int image_x = GetOuterPadding(icon_has_enough_padding); | 153 int image_x = GetOuterPadding(icon_has_enough_padding); |
150 int bubble_trailing_padding = GetOuterPadding(false); | 154 int bubble_trailing_padding = GetOuterPadding(false); |
151 | 155 |
152 // If ShouldShowBackground() is true, then either we show a background in the | 156 // If ShouldShowBackground() is true, then either we show a background in the |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 const int post_label_width = ui::MaterialDesignController::IsModeMaterial() | 247 const int post_label_width = ui::MaterialDesignController::IsModeMaterial() |
244 ? (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding()) | 248 ? (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding()) |
245 : GetOuterPadding(false); | 249 : GetOuterPadding(false); |
246 | 250 |
247 // |multiplier| grows from zero to one, stays equal to one and then shrinks | 251 // |multiplier| grows from zero to one, stays equal to one and then shrinks |
248 // to zero again. The view width should correspondingly grow from zero to | 252 // to zero again. The view width should correspondingly grow from zero to |
249 // fully showing both label and icon, stay there, then shrink to just large | 253 // fully showing both label and icon, stay there, then shrink to just large |
250 // enough to show the icon. We don't want to shrink all the way back to | 254 // enough to show the icon. We don't want to shrink all the way back to |
251 // zero, since this would mean the view would completely disappear and then | 255 // zero, since this would mean the view would completely disappear and then |
252 // pop back to an icon after the animation finishes. | 256 // pop back to an icon after the animation finishes. |
253 const int max_width = GetImageTrailingEdge() + GetInternalSpacing() + | 257 // Changed so that, while shrinking, |multiplier| only refers to the label, |
254 label_width + post_label_width; | 258 // separator and padding. |
Peter Kasting
2016/07/19 21:17:20
I'm not really sure why. You'll want to explain t
Kevin Bailey
2016/08/12 18:49:14
I integrated the comment better. Strictly speaking
| |
255 const int current_width = WidthMultiplier() * max_width; | 259 if (shrinking) { |
256 size.set_width(shrinking ? std::max(current_width, size.width()) | 260 const int current_width = GetImageTrailingEdge() + GetInternalSpacing() + |
257 : current_width); | 261 (label_width + post_label_width) * WidthMultiplier(); |
262 size.set_width(std::max(current_width, size.width())); | |
Peter Kasting
2016/07/19 21:17:20
Unless GetInternalSpacing() or WidthMultiplier() c
Kevin Bailey
2016/08/12 18:49:14
Done.
| |
263 } else { | |
264 const int max_width = GetImageTrailingEdge() + GetInternalSpacing() + | |
265 label_width + post_label_width; | |
266 const int current_width = WidthMultiplier() * max_width; | |
267 size.set_width(current_width); | |
268 } | |
258 } | 269 } |
259 return size; | 270 return size; |
260 } | 271 } |
261 | 272 |
262 int IconLabelBubbleView::MinimumWidthForImageWithBackgroundShown() const { | 273 int IconLabelBubbleView::MinimumWidthForImageWithBackgroundShown() const { |
263 return GetImageTrailingEdge() + GetOuterPadding(false); | 274 return GetImageTrailingEdge() + GetOuterPadding(false); |
264 } | 275 } |
265 | 276 |
277 int IconLabelBubbleView::GetLabelPreferredWidth() const { | |
278 return label_->GetPreferredSize().width(); | |
279 } | |
280 | |
266 void IconLabelBubbleView::SetLabelBackgroundColor( | 281 void IconLabelBubbleView::SetLabelBackgroundColor( |
267 SkColor chip_background_color) { | 282 SkColor chip_background_color) { |
268 // The background images are painted atop |parent_background_color_|. | 283 // The background images are painted atop |parent_background_color_|. |
269 // Alpha-blend |chip_background_color| with |parent_background_color_| to | 284 // Alpha-blend |chip_background_color| with |parent_background_color_| to |
270 // determine the actual color the label text will sit atop. | 285 // determine the actual color the label text will sit atop. |
271 // Tricky bit: We alpha blend an opaque version of |chip_background_color| | 286 // Tricky bit: We alpha blend an opaque version of |chip_background_color| |
272 // against |parent_background_color_| using the original image grid color's | 287 // against |parent_background_color_| using the original image grid color's |
273 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged | 288 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged |
274 // even if |a| is a color with non-255 alpha. | 289 // even if |a| is a color with non-255 alpha. |
275 label_->SetBackgroundColor(color_utils::AlphaBlend( | 290 label_->SetBackgroundColor(color_utils::AlphaBlend( |
(...skipping 24 matching lines...) Expand all Loading... | |
300 // The location bar will add LOCATION_BAR_HORIZONTAL_PADDING after us. | 315 // The location bar will add LOCATION_BAR_HORIZONTAL_PADDING after us. |
301 return kSpaceBesideSeparator - | 316 return kSpaceBesideSeparator - |
302 GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 317 GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
303 } | 318 } |
304 | 319 |
305 const char* IconLabelBubbleView::GetClassName() const { | 320 const char* IconLabelBubbleView::GetClassName() const { |
306 return "IconLabelBubbleView"; | 321 return "IconLabelBubbleView"; |
307 } | 322 } |
308 | 323 |
309 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { | 324 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { |
325 std::cout << "Icon::OnPaint\n"; | |
310 if (!ShouldShowBackground()) | 326 if (!ShouldShowBackground()) |
311 return; | 327 return; |
312 if (background_painter_) { | 328 if (background_painter_) { |
313 views::Painter::PaintPainterAt(canvas, background_painter_.get(), | 329 views::Painter::PaintPainterAt(canvas, background_painter_.get(), |
314 GetContentsBounds()); | 330 GetContentsBounds()); |
315 } | 331 } |
316 | 332 |
317 // In MD, draw a separator and not a background. | 333 // In MD, draw a separator and not a background. |
318 if (ui::MaterialDesignController::IsModeMaterial()) { | 334 if (ui::MaterialDesignController::IsModeMaterial()) { |
319 const SkColor plain_text_color = GetNativeTheme()->GetSystemColor( | 335 const SkColor plain_text_color = GetNativeTheme()->GetSystemColor( |
320 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 336 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
321 const SkColor separator_color = SkColorSetA( | 337 const SkColor separator_color = SkColorSetA( |
322 plain_text_color, color_utils::IsDark(plain_text_color) ? 0x59 : 0xCC); | 338 plain_text_color, color_utils::IsDark(plain_text_color) ? 0x59 : 0xCC); |
323 | 339 |
324 gfx::Rect bounds(GetLocalBounds()); | 340 if (!IsShrinking() || WidthMultiplier() > 0) { |
Peter Kasting
2016/07/19 21:17:19
This doesn't break the keyword search presentation
Kevin Bailey
2016/08/12 18:49:14
We don't shrink any more, so reverted.
| |
325 const int kSeparatorHeight = 16; | 341 gfx::Rect bounds(GetLocalBounds()); |
326 bounds.Inset(GetPostSeparatorPadding(), | 342 const int kSeparatorHeight = 16; |
327 (bounds.height() - kSeparatorHeight) / 2); | 343 bounds.Inset(GetPostSeparatorPadding(), |
344 (bounds.height() - kSeparatorHeight) / 2); | |
328 | 345 |
329 // Draw the 1 px separator. | 346 // Draw the 1 px separator. |
330 gfx::ScopedCanvas scoped_canvas(canvas); | 347 gfx::ScopedCanvas scoped_canvas(canvas); |
331 const float scale = canvas->UndoDeviceScaleFactor(); | 348 const float scale = canvas->UndoDeviceScaleFactor(); |
332 // Keep the separator aligned on a pixel center. | 349 // Keep the separator aligned on a pixel center. |
333 const gfx::RectF pixel_aligned_bounds = | 350 const gfx::RectF pixel_aligned_bounds = |
334 gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0); | 351 gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0); |
335 canvas->DrawLine(pixel_aligned_bounds.top_right(), | 352 canvas->DrawLine(pixel_aligned_bounds.top_right(), |
336 pixel_aligned_bounds.bottom_right(), separator_color); | 353 pixel_aligned_bounds.bottom_right(), separator_color); |
354 } | |
337 } | 355 } |
338 } | 356 } |
OLD | NEW |