Commit 606166f0 authored by Ana Salazar's avatar Ana Salazar Committed by Commit Bot

Cros: Use floating values for obtaining icon bounds

Because we are scaling the icon bounds to animate long press gestures,
some values might be incorrectly rounded.
Change the method that calculates the bounds with scale to use floating
values and then Round the resulting rect to adapt to grid layer.
Also, include the icon shadows for scaling.

Bug: 1050730
Change-Id: Ief19fcf0d2894f570a77047f8209e53eeb461b73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2086317Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748337}
parent 9406a154
...@@ -609,21 +609,20 @@ bool ShelfAppButton::OnMouseDragged(const ui::MouseEvent& event) { ...@@ -609,21 +609,20 @@ bool ShelfAppButton::OnMouseDragged(const ui::MouseEvent& event) {
} }
gfx::Rect ShelfAppButton::GetIconViewBounds(float icon_scale) { gfx::Rect ShelfAppButton::GetIconViewBounds(float icon_scale) {
int icon_size = ShelfConfig::Get()->button_icon_size() * icon_scale; const float icon_size = ShelfConfig::Get()->button_icon_size() * icon_scale;
// TODO: Find out why there is an extra pixel of padding between each item const float icon_padding =
// and the inner side of the shelf. (ShelfConfig::Get()->hotseat_size() - icon_size) / 2;
// clang-format off
int icon_padding = (ShelfConfig::Get()->hotseat_size() - icon_size) / 2;
// clang-format on
const gfx::Rect button_bounds(GetContentsBounds()); const gfx::Rect button_bounds(GetContentsBounds());
Shelf* shelf = shelf_view_->shelf(); const Shelf* shelf = shelf_view_->shelf();
const bool is_horizontal_shelf = shelf->IsHorizontalAlignment(); const bool is_horizontal_shelf = shelf->IsHorizontalAlignment();
int x_offset = is_horizontal_shelf ? 0 : icon_padding; float x_offset = is_horizontal_shelf ? 0 : icon_padding;
int y_offset = is_horizontal_shelf ? icon_padding : 0; float y_offset = is_horizontal_shelf ? icon_padding : 0;
int icon_width = std::min(icon_size, button_bounds.width() - x_offset); const float icon_width =
int icon_height = std::min(icon_size, button_bounds.height() - y_offset); std::min(icon_size, button_bounds.width() - x_offset);
const float icon_height =
std::min(icon_size, button_bounds.height() - y_offset);
// If on the left or top 'invert' the inset so the constant gap is on // If on the left or top 'invert' the inset so the constant gap is on
// the interior (towards the center of display) edge of the shelf. // the interior (towards the center of display) edge of the shelf.
...@@ -632,21 +631,15 @@ gfx::Rect ShelfAppButton::GetIconViewBounds(float icon_scale) { ...@@ -632,21 +631,15 @@ gfx::Rect ShelfAppButton::GetIconViewBounds(float icon_scale) {
// Expand bounds to include shadows. // Expand bounds to include shadows.
gfx::Insets insets_shadows = gfx::ShadowValue::GetMargin(icon_shadows_); gfx::Insets insets_shadows = gfx::ShadowValue::GetMargin(icon_shadows_);
// insets_shadows = insets_shadows.Scale(icon_scale);
// Center icon with respect to the secondary axis. // Center icon with respect to the secondary axis.
if (is_horizontal_shelf) { if (is_horizontal_shelf)
x_offset = x_offset = std::max(0.0f, button_bounds.width() - icon_width + 1) / 2;
std::max(0, button_bounds.width() - icon_width + insets_shadows.left() - else
insets_shadows.right() + 1) / y_offset = std::max(0.0f, button_bounds.height() - icon_height) / 2;
2; gfx::RectF icon_view_bounds =
} else { gfx::RectF(button_bounds.x() + x_offset, button_bounds.y() + y_offset,
y_offset = icon_width, icon_height);
std::max(0, button_bounds.height() - icon_height +
insets_shadows.top() - insets_shadows.bottom() + 1) /
2;
}
gfx::Rect icon_view_bounds =
gfx::Rect(button_bounds.x() + x_offset, button_bounds.y() + y_offset,
icon_width, icon_height);
icon_view_bounds.Inset(insets_shadows); icon_view_bounds.Inset(insets_shadows);
// Icon size has been incorrect when running // Icon size has been incorrect when running
...@@ -654,7 +647,7 @@ gfx::Rect ShelfAppButton::GetIconViewBounds(float icon_scale) { ...@@ -654,7 +647,7 @@ gfx::Rect ShelfAppButton::GetIconViewBounds(float icon_scale) {
// http://crbug.com/234854. // http://crbug.com/234854.
DCHECK_LE(icon_width, icon_size); DCHECK_LE(icon_width, icon_size);
DCHECK_LE(icon_height, icon_size); DCHECK_LE(icon_height, icon_size);
return icon_view_bounds; return gfx::ToRoundedRect(icon_view_bounds);
} }
void ShelfAppButton::Layout() { void ShelfAppButton::Layout() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment