| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shelf/shelf_button.h" | 5 #include "ash/shelf/shelf_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
| 10 #include "ash/shelf/ink_drop_button_listener.h" | 10 #include "ash/shelf/ink_drop_button_listener.h" |
| 11 #include "ash/shelf/shelf.h" |
| 11 #include "ash/shelf/shelf_constants.h" | 12 #include "ash/shelf/shelf_constants.h" |
| 12 #include "ash/shelf/shelf_view.h" | 13 #include "ash/shelf/shelf_view.h" |
| 13 #include "ash/shelf/wm_shelf.h" | |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "skia/ext/image_operations.h" | 16 #include "skia/ext/image_operations.h" |
| 17 #include "ui/accessibility/ax_node_data.h" | 17 #include "ui/accessibility/ax_node_data.h" |
| 18 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
| 19 #include "ui/gfx/animation/animation_delegate.h" | 19 #include "ui/gfx/animation/animation_delegate.h" |
| 20 #include "ui/gfx/animation/throb_animation.h" | 20 #include "ui/gfx/animation/throb_animation.h" |
| 21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 22 #include "ui/gfx/geometry/vector2d.h" | 22 #include "ui/gfx/geometry/vector2d.h" |
| 23 #include "ui/gfx/image/image_skia_operations.h" | 23 #include "ui/gfx/image/image_skia_operations.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 return true; | 347 return true; |
| 348 } | 348 } |
| 349 | 349 |
| 350 void ShelfButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 350 void ShelfButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 351 node_data->role = ui::AX_ROLE_BUTTON; | 351 node_data->role = ui::AX_ROLE_BUTTON; |
| 352 node_data->SetName(shelf_view_->GetTitleForView(this)); | 352 node_data->SetName(shelf_view_->GetTitleForView(this)); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void ShelfButton::Layout() { | 355 void ShelfButton::Layout() { |
| 356 const gfx::Rect button_bounds(GetContentsBounds()); | 356 const gfx::Rect button_bounds(GetContentsBounds()); |
| 357 WmShelf* wm_shelf = shelf_view_->wm_shelf(); | 357 Shelf* shelf = shelf_view_->shelf(); |
| 358 const bool is_horizontal_shelf = wm_shelf->IsHorizontalAlignment(); | 358 const bool is_horizontal_shelf = shelf->IsHorizontalAlignment(); |
| 359 const int icon_pad = | 359 const int icon_pad = |
| 360 is_horizontal_shelf ? kIconPaddingHorizontal : kIconPaddingVertical; | 360 is_horizontal_shelf ? kIconPaddingHorizontal : kIconPaddingVertical; |
| 361 int x_offset = is_horizontal_shelf ? 0 : icon_pad; | 361 int x_offset = is_horizontal_shelf ? 0 : icon_pad; |
| 362 int y_offset = is_horizontal_shelf ? icon_pad : 0; | 362 int y_offset = is_horizontal_shelf ? icon_pad : 0; |
| 363 | 363 |
| 364 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); | 364 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); |
| 365 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); | 365 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); |
| 366 | 366 |
| 367 // If on the left or top 'invert' the inset so the constant gap is on | 367 // If on the left or top 'invert' the inset so the constant gap is on |
| 368 // the interior (towards the center of display) edge of the shelf. | 368 // the interior (towards the center of display) edge of the shelf. |
| 369 if (SHELF_ALIGNMENT_LEFT == wm_shelf->GetAlignment()) | 369 if (SHELF_ALIGNMENT_LEFT == shelf->alignment()) |
| 370 x_offset = button_bounds.width() - (kIconSize + icon_pad); | 370 x_offset = button_bounds.width() - (kIconSize + icon_pad); |
| 371 | 371 |
| 372 // Center icon with respect to the secondary axis. | 372 // Center icon with respect to the secondary axis. |
| 373 if (is_horizontal_shelf) | 373 if (is_horizontal_shelf) |
| 374 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; | 374 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; |
| 375 else | 375 else |
| 376 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; | 376 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; |
| 377 | 377 |
| 378 // Expand bounds to include shadows. | 378 // Expand bounds to include shadows. |
| 379 gfx::Insets insets_shadows = gfx::ShadowValue::GetMargin(icon_shadows_); | 379 gfx::Insets insets_shadows = gfx::ShadowValue::GetMargin(icon_shadows_); |
| 380 // Adjust offsets to center icon, not icon + shadow. | 380 // Adjust offsets to center icon, not icon + shadow. |
| 381 x_offset += (insets_shadows.left() - insets_shadows.right()) / 2; | 381 x_offset += (insets_shadows.left() - insets_shadows.right()) / 2; |
| 382 y_offset += (insets_shadows.top() - insets_shadows.bottom()) / 2; | 382 y_offset += (insets_shadows.top() - insets_shadows.bottom()) / 2; |
| 383 gfx::Rect icon_view_bounds = | 383 gfx::Rect icon_view_bounds = |
| 384 gfx::Rect(button_bounds.x() + x_offset, button_bounds.y() + y_offset, | 384 gfx::Rect(button_bounds.x() + x_offset, button_bounds.y() + y_offset, |
| 385 icon_width, icon_height); | 385 icon_width, icon_height); |
| 386 // The indicator should be aligned with the icon, not the icon + shadow. | 386 // The indicator should be aligned with the icon, not the icon + shadow. |
| 387 gfx::Point indicator_midpoint = icon_view_bounds.CenterPoint(); | 387 gfx::Point indicator_midpoint = icon_view_bounds.CenterPoint(); |
| 388 icon_view_bounds.Inset(insets_shadows); | 388 icon_view_bounds.Inset(insets_shadows); |
| 389 icon_view_bounds.AdjustToFit(gfx::Rect(size())); | 389 icon_view_bounds.AdjustToFit(gfx::Rect(size())); |
| 390 icon_view_->SetBoundsRect(icon_view_bounds); | 390 icon_view_->SetBoundsRect(icon_view_bounds); |
| 391 | 391 |
| 392 // Icon size has been incorrect when running | 392 // Icon size has been incorrect when running |
| 393 // PanelLayoutManagerTest.PanelAlignmentSecondDisplay on valgrind bot, see | 393 // PanelLayoutManagerTest.PanelAlignmentSecondDisplay on valgrind bot, see |
| 394 // http://crbug.com/234854. | 394 // http://crbug.com/234854. |
| 395 DCHECK_LE(icon_width, kIconSize); | 395 DCHECK_LE(icon_width, kIconSize); |
| 396 DCHECK_LE(icon_height, kIconSize); | 396 DCHECK_LE(icon_height, kIconSize); |
| 397 | 397 |
| 398 switch (wm_shelf->GetAlignment()) { | 398 switch (shelf->alignment()) { |
| 399 case SHELF_ALIGNMENT_BOTTOM: | 399 case SHELF_ALIGNMENT_BOTTOM: |
| 400 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 400 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| 401 indicator_midpoint.set_y(button_bounds.bottom() - kIndicatorRadiusDip - | 401 indicator_midpoint.set_y(button_bounds.bottom() - kIndicatorRadiusDip - |
| 402 kIndicatorOffsetFromBottom); | 402 kIndicatorOffsetFromBottom); |
| 403 break; | 403 break; |
| 404 case SHELF_ALIGNMENT_LEFT: | 404 case SHELF_ALIGNMENT_LEFT: |
| 405 indicator_midpoint.set_x(button_bounds.x() + kIndicatorRadiusDip + | 405 indicator_midpoint.set_x(button_bounds.x() + kIndicatorRadiusDip + |
| 406 kIndicatorOffsetFromBottom); | 406 kIndicatorOffsetFromBottom); |
| 407 break; | 407 break; |
| 408 case SHELF_ALIGNMENT_RIGHT: | 408 case SHELF_ALIGNMENT_RIGHT: |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 if (listener_) | 494 if (listener_) |
| 495 listener_->ButtonPressed(this, event, GetInkDrop()); | 495 listener_->ButtonPressed(this, event, GetInkDrop()); |
| 496 } | 496 } |
| 497 | 497 |
| 498 void ShelfButton::UpdateState() { | 498 void ShelfButton::UpdateState() { |
| 499 indicator_->SetVisible(!(state_ & STATE_HIDDEN) && | 499 indicator_->SetVisible(!(state_ & STATE_HIDDEN) && |
| 500 (state_ & STATE_ACTIVE || state_ & STATE_ATTENTION || | 500 (state_ & STATE_ACTIVE || state_ & STATE_ATTENTION || |
| 501 state_ & STATE_RUNNING)); | 501 state_ & STATE_RUNNING)); |
| 502 | 502 |
| 503 const bool is_horizontal_shelf = | 503 const bool is_horizontal_shelf = |
| 504 shelf_view_->wm_shelf()->IsHorizontalAlignment(); | 504 shelf_view_->shelf()->IsHorizontalAlignment(); |
| 505 icon_view_->SetHorizontalAlignment(is_horizontal_shelf | 505 icon_view_->SetHorizontalAlignment(is_horizontal_shelf |
| 506 ? views::ImageView::CENTER | 506 ? views::ImageView::CENTER |
| 507 : views::ImageView::LEADING); | 507 : views::ImageView::LEADING); |
| 508 icon_view_->SetVerticalAlignment(is_horizontal_shelf | 508 icon_view_->SetVerticalAlignment(is_horizontal_shelf |
| 509 ? views::ImageView::LEADING | 509 ? views::ImageView::LEADING |
| 510 : views::ImageView::CENTER); | 510 : views::ImageView::CENTER); |
| 511 SchedulePaint(); | 511 SchedulePaint(); |
| 512 } | 512 } |
| 513 | 513 |
| 514 } // namespace ash | 514 } // namespace ash |
| OLD | NEW |