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