Commit 70ef77ca authored by bruthig's avatar bruthig Committed by Commit bot

[ash-md] Fix layout of launcher and overflow buttons in Ash MD shelf

This CL ensures the correct layout of the launcher
button and the overflow button in the Ash MD shelf
when the shelf is being resized. This can occur in
two situations: when the shelf is being 'stretched'
toward the center of the screen by touch, or
during a shelf hide/show animation.

BUG=668230
TEST=manual

Review-Url: https://codereview.chromium.org/2598223002
Cr-Commit-Position: refs/heads/master@{#442031}
parent eb91daf3
......@@ -288,16 +288,23 @@ void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) {
}
gfx::Point AppListButton::GetCenterPoint() const {
// During shelf hide/show animations, width and height may not be equal. Take
// the greater of the two as the one that represents the normal size of the
// button.
int center = std::max(width(), height()) / 2.f;
gfx::Point centroid(center, center);
// For the left shelf alignment, we need to right-justify. For other shelf
// alignments, left/top justification (i.e. no adjustments are necessary).
if (SHELF_ALIGNMENT_LEFT == wm_shelf_->GetAlignment())
centroid.set_x(width() - center);
return centroid;
// For a bottom-aligned shelf, the button bounds could have a larger height
// than width (in the case of touch-dragging the shelf updwards) or a larger
// width than height (in the case of a shelf hide/show animation), so adjust
// the y-position of the circle's center to ensure correct layout. Similarly
// adjust the x-position for a left- or right-aligned shelf.
const int x_mid = width() / 2.f;
const int y_mid = height() / 2.f;
ShelfAlignment alignment = wm_shelf_->GetAlignment();
if (alignment == SHELF_ALIGNMENT_BOTTOM ||
alignment == SHELF_ALIGNMENT_BOTTOM_LOCKED) {
return gfx::Point(x_mid, x_mid);
} else if (alignment == SHELF_ALIGNMENT_RIGHT) {
return gfx::Point(y_mid, y_mid);
} else {
DCHECK_EQ(alignment, SHELF_ALIGNMENT_LEFT);
return gfx::Point(width() - y_mid, y_mid);
}
}
} // namespace ash
......@@ -172,18 +172,17 @@ int OverflowButton::NonMaterialBackgroundImageId() const {
gfx::Rect OverflowButton::CalculateButtonBounds() const {
ShelfAlignment alignment = wm_shelf_->GetAlignment();
gfx::Rect bounds(GetContentsBounds());
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
if (MaterialDesignController::IsShelfMaterial()) {
const int width_offset = (bounds.width() - kOverflowButtonSize) / 2;
const int height_offset = (bounds.height() - kOverflowButtonSize) / 2;
if (IsHorizontalAlignment(alignment)) {
bounds = gfx::Rect(bounds.x() + width_offset, bounds.y() + height_offset,
kOverflowButtonSize, kOverflowButtonSize);
} else {
bounds = gfx::Rect(bounds.x() + height_offset, bounds.y() + width_offset,
kOverflowButtonSize, kOverflowButtonSize);
}
// Align the button to the top of a bottom-aligned shelf, to the right edge
// a left-aligned shelf, and to the left edge of a right-aligned shelf.
const int inset = (GetShelfConstant(SHELF_SIZE) - kOverflowButtonSize) / 2;
const int x = alignment == SHELF_ALIGNMENT_LEFT
? bounds.right() - inset - kOverflowButtonSize
: bounds.x() + inset;
bounds = gfx::Rect(x, bounds.y() + inset, kOverflowButtonSize,
kOverflowButtonSize);
} else {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
const gfx::ImageSkia* background =
rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia();
if (alignment == SHELF_ALIGNMENT_LEFT) {
......
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