OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/common/shelf/app_list_button.h" | 5 #include "ash/common/shelf/app_list_button.h" |
6 | 6 |
7 #include "ash/common/ash_constants.h" | 7 #include "ash/common/ash_constants.h" |
8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
9 #include "ash/common/shelf/ink_drop_button_listener.h" | 9 #include "ash/common/shelf/ink_drop_button_listener.h" |
10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 } | 280 } |
281 | 281 |
282 void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) { | 282 void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) { |
283 if (draw_background_as_active_ == draw_background_as_active) | 283 if (draw_background_as_active_ == draw_background_as_active) |
284 return; | 284 return; |
285 draw_background_as_active_ = draw_background_as_active; | 285 draw_background_as_active_ = draw_background_as_active; |
286 SchedulePaint(); | 286 SchedulePaint(); |
287 } | 287 } |
288 | 288 |
289 gfx::Point AppListButton::GetCenterPoint() const { | 289 gfx::Point AppListButton::GetCenterPoint() const { |
290 // During shelf hide/show animations, width and height may not be equal. Take | 290 // For a bottom-aligned shelf, the button bounds could have a larger height |
291 // the greater of the two as the one that represents the normal size of the | 291 // than width (in the case of touch-dragging the shelf updwards) or a larger |
292 // button. | 292 // width than height (in the case of a shelf hide/show animation), so adjust |
293 int center = std::max(width(), height()) / 2.f; | 293 // the y-position of the circle's center to ensure correct layout. Similarly |
294 gfx::Point centroid(center, center); | 294 // adjust the x-position for a left- or right-aligned shelf. |
295 // For the left shelf alignment, we need to right-justify. For other shelf | 295 const int x_mid = width() / 2.f; |
296 // alignments, left/top justification (i.e. no adjustments are necessary). | 296 const int y_mid = height() / 2.f; |
297 if (SHELF_ALIGNMENT_LEFT == wm_shelf_->GetAlignment()) | 297 ShelfAlignment alignment = wm_shelf_->GetAlignment(); |
298 centroid.set_x(width() - center); | 298 if (alignment == SHELF_ALIGNMENT_BOTTOM) { |
299 return centroid; | 299 return gfx::Point(x_mid, x_mid); |
| 300 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { |
| 301 return gfx::Point(y_mid, y_mid); |
| 302 } else { |
| 303 DCHECK_EQ(alignment, SHELF_ALIGNMENT_LEFT); |
| 304 return gfx::Point(width() - y_mid, y_mid); |
| 305 } |
300 } | 306 } |
301 | 307 |
302 } // namespace ash | 308 } // namespace ash |
OLD | NEW |