| 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/common/shelf/shelf_button.h" | 5 #include "ash/common/shelf/shelf_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/common/ash_constants.h" | 9 #include "ash/common/ash_constants.h" |
| 10 #include "ash/common/material_design/material_design_controller.h" | |
| 11 #include "ash/common/shelf/ink_drop_button_listener.h" | 10 #include "ash/common/shelf/ink_drop_button_listener.h" |
| 12 #include "ash/common/shelf/shelf_constants.h" | 11 #include "ash/common/shelf/shelf_constants.h" |
| 13 #include "ash/common/shelf/shelf_view.h" | 12 #include "ash/common/shelf/shelf_view.h" |
| 14 #include "ash/common/shelf/wm_shelf.h" | 13 #include "ash/common/shelf/wm_shelf.h" |
| 15 #include "ash/resources/grit/ash_resources.h" | |
| 16 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 17 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 18 #include "skia/ext/image_operations.h" | 16 #include "skia/ext/image_operations.h" |
| 19 #include "ui/accessibility/ax_node_data.h" | 17 #include "ui/accessibility/ax_node_data.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | |
| 21 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 23 #include "ui/events/event_constants.h" | |
| 24 #include "ui/gfx/animation/animation_delegate.h" | 19 #include "ui/gfx/animation/animation_delegate.h" |
| 25 #include "ui/gfx/animation/throb_animation.h" | 20 #include "ui/gfx/animation/throb_animation.h" |
| 26 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 27 #include "ui/gfx/geometry/vector2d.h" | 22 #include "ui/gfx/geometry/vector2d.h" |
| 28 #include "ui/gfx/image/image.h" | |
| 29 #include "ui/gfx/image/image_skia_operations.h" | 23 #include "ui/gfx/image/image_skia_operations.h" |
| 30 #include "ui/gfx/skbitmap_operations.h" | 24 #include "ui/gfx/skbitmap_operations.h" |
| 31 #include "ui/views/animation/ink_drop_impl.h" | 25 #include "ui/views/animation/ink_drop_impl.h" |
| 32 #include "ui/views/animation/square_ink_drop_ripple.h" | 26 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 33 #include "ui/views/controls/image_view.h" | 27 #include "ui/views/controls/image_view.h" |
| 34 | 28 |
| 35 namespace { | 29 namespace { |
| 36 | 30 |
| 37 // Size of the bar. This is along the opposite axis of the shelf. For example, | 31 // Size of the bar. This is along the opposite axis of the shelf. For example, |
| 38 // if the shelf is aligned horizontally then this is the height of the bar. | 32 // if the shelf is aligned horizontally then this is the height of the bar. |
| 39 const int kBarSize = 3; | 33 const int kBarSize = 3; |
| 40 const int kIconSize = 32; | 34 const int kIconSize = 32; |
| 41 const int kAttentionThrobDurationMS = 800; | 35 const int kAttentionThrobDurationMS = 800; |
| 42 const int kMaxAnimationSeconds = 10; | 36 const int kMaxAnimationSeconds = 10; |
| 43 const int kIndicatorOffsetFromBottom = 2; | 37 const int kIndicatorOffsetFromBottom = 2; |
| 44 const int kIndicatorRadius = 2; | 38 const int kIndicatorRadius = 2; |
| 45 const SkColor kIndicatorColor = SK_ColorWHITE; | 39 const SkColor kIndicatorColor = SK_ColorWHITE; |
| 46 // Canvas scale to ensure that the activity indicator is not pixelated even at | 40 // Canvas scale to ensure that the activity indicator is not pixelated even at |
| 47 // the highest possible device scale factors. | 41 // the highest possible device scale factors. |
| 48 const int kIndicatorCanvasScale = 5; | 42 const int kIndicatorCanvasScale = 5; |
| 49 | 43 |
| 50 // Shelf item ripple constants. | 44 // Shelf item ripple constants. |
| 51 const int kInkDropSmallSize = 48; | 45 const int kInkDropSmallSize = 48; |
| 52 const int kInkDropLargeSize = 60; | 46 const int kInkDropLargeSize = 60; |
| 53 | 47 |
| 54 // Padding from the edge of the shelf to the application icon when the shelf | 48 // Padding from the edge of the shelf to the application icon when the shelf |
| 55 // is horizontally and vertically aligned, respectively. | 49 // is horizontally and vertically aligned, respectively. |
| 56 const int kIconPaddingHorizontal = 5; | 50 const int kIconPaddingHorizontal = 7; |
| 57 const int kIconPaddingHorizontalMD = 7; | 51 const int kIconPaddingVertical = 8; |
| 58 const int kIconPaddingVertical = 6; | |
| 59 const int kIconPaddingVerticalMD = 8; | |
| 60 | 52 |
| 61 // Paints an activity indicator on |canvas| whose |size| is specified in DIP. | 53 // Paints an activity indicator on |canvas| whose |size| is specified in DIP. |
| 62 void PaintIndicatorOnCanvas(gfx::Canvas* canvas, const gfx::Size& size) { | 54 void PaintIndicatorOnCanvas(gfx::Canvas* canvas, const gfx::Size& size) { |
| 63 cc::PaintFlags flags; | 55 cc::PaintFlags flags; |
| 64 flags.setColor(kIndicatorColor); | 56 flags.setColor(kIndicatorColor); |
| 65 flags.setFlags(cc::PaintFlags::kAntiAlias_Flag); | 57 flags.setFlags(cc::PaintFlags::kAntiAlias_Flag); |
| 66 canvas->DrawCircle( | 58 canvas->DrawCircle( |
| 67 gfx::Point(size.width() / 2, | 59 gfx::Point(size.width() / 2, |
| 68 size.height() - kIndicatorOffsetFromBottom - kIndicatorRadius), | 60 size.height() - kIndicatorOffsetFromBottom - kIndicatorRadius), |
| 69 kIndicatorRadius, flags); | 61 kIndicatorRadius, flags); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 242 |
| 251 ShelfButton::ShelfButton(InkDropButtonListener* listener, ShelfView* shelf_view) | 243 ShelfButton::ShelfButton(InkDropButtonListener* listener, ShelfView* shelf_view) |
| 252 : CustomButton(nullptr), | 244 : CustomButton(nullptr), |
| 253 listener_(listener), | 245 listener_(listener), |
| 254 shelf_view_(shelf_view), | 246 shelf_view_(shelf_view), |
| 255 icon_view_(new views::ImageView()), | 247 icon_view_(new views::ImageView()), |
| 256 bar_(new BarView(shelf_view->wm_shelf())), | 248 bar_(new BarView(shelf_view->wm_shelf())), |
| 257 state_(STATE_NORMAL), | 249 state_(STATE_NORMAL), |
| 258 destroyed_flag_(nullptr) { | 250 destroyed_flag_(nullptr) { |
| 259 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 251 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 260 if (ash::MaterialDesignController::IsShelfMaterial()) { | 252 SetInkDropMode(InkDropMode::ON); |
| 261 SetInkDropMode(InkDropMode::ON); | 253 set_ink_drop_base_color(kShelfInkDropBaseColor); |
| 262 set_ink_drop_base_color(kShelfInkDropBaseColor); | 254 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); |
| 263 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); | |
| 264 } | |
| 265 | 255 |
| 266 const gfx::ShadowValue kShadows[] = { | 256 const gfx::ShadowValue kShadows[] = { |
| 267 gfx::ShadowValue(gfx::Vector2d(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), | 257 gfx::ShadowValue(gfx::Vector2d(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), |
| 268 gfx::ShadowValue(gfx::Vector2d(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), | 258 gfx::ShadowValue(gfx::Vector2d(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), |
| 269 gfx::ShadowValue(gfx::Vector2d(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), | 259 gfx::ShadowValue(gfx::Vector2d(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), |
| 270 }; | 260 }; |
| 271 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows)); | 261 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows)); |
| 272 | 262 |
| 273 // TODO: refactor the layers so each button doesn't require 2. | 263 // TODO: refactor the layers so each button doesn't require 2. |
| 274 icon_view_->SetPaintToLayer(); | 264 icon_view_->SetPaintToLayer(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 386 |
| 397 void ShelfButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 387 void ShelfButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 398 node_data->role = ui::AX_ROLE_BUTTON; | 388 node_data->role = ui::AX_ROLE_BUTTON; |
| 399 node_data->SetName(shelf_view_->GetTitleForView(this)); | 389 node_data->SetName(shelf_view_->GetTitleForView(this)); |
| 400 } | 390 } |
| 401 | 391 |
| 402 void ShelfButton::Layout() { | 392 void ShelfButton::Layout() { |
| 403 const gfx::Rect button_bounds(GetContentsBounds()); | 393 const gfx::Rect button_bounds(GetContentsBounds()); |
| 404 WmShelf* wm_shelf = shelf_view_->wm_shelf(); | 394 WmShelf* wm_shelf = shelf_view_->wm_shelf(); |
| 405 const bool is_horizontal_shelf = wm_shelf->IsHorizontalAlignment(); | 395 const bool is_horizontal_shelf = wm_shelf->IsHorizontalAlignment(); |
| 406 const int icon_pad = ash::MaterialDesignController::IsShelfMaterial() | 396 const int icon_pad = |
| 407 ? (is_horizontal_shelf ? kIconPaddingHorizontalMD | 397 is_horizontal_shelf ? kIconPaddingHorizontal : kIconPaddingVertical; |
| 408 : kIconPaddingVerticalMD) | |
| 409 : (is_horizontal_shelf ? kIconPaddingHorizontal | |
| 410 : kIconPaddingVertical); | |
| 411 int x_offset = is_horizontal_shelf ? 0 : icon_pad; | 398 int x_offset = is_horizontal_shelf ? 0 : icon_pad; |
| 412 int y_offset = is_horizontal_shelf ? icon_pad : 0; | 399 int y_offset = is_horizontal_shelf ? icon_pad : 0; |
| 413 | 400 |
| 414 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); | 401 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); |
| 415 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); | 402 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); |
| 416 | 403 |
| 417 // If on the left or top 'invert' the inset so the constant gap is on | 404 // If on the left or top 'invert' the inset so the constant gap is on |
| 418 // the interior (towards the center of display) edge of the shelf. | 405 // the interior (towards the center of display) edge of the shelf. |
| 419 if (SHELF_ALIGNMENT_LEFT == wm_shelf->GetAlignment()) | 406 if (SHELF_ALIGNMENT_LEFT == wm_shelf->GetAlignment()) |
| 420 x_offset = button_bounds.width() - (kIconSize + icon_pad); | 407 x_offset = button_bounds.width() - (kIconSize + icon_pad); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 icon_view_->SetHorizontalAlignment(is_horizontal_shelf | 525 icon_view_->SetHorizontalAlignment(is_horizontal_shelf |
| 539 ? views::ImageView::CENTER | 526 ? views::ImageView::CENTER |
| 540 : views::ImageView::LEADING); | 527 : views::ImageView::LEADING); |
| 541 icon_view_->SetVerticalAlignment(is_horizontal_shelf | 528 icon_view_->SetVerticalAlignment(is_horizontal_shelf |
| 542 ? views::ImageView::LEADING | 529 ? views::ImageView::LEADING |
| 543 : views::ImageView::CENTER); | 530 : views::ImageView::CENTER); |
| 544 SchedulePaint(); | 531 SchedulePaint(); |
| 545 } | 532 } |
| 546 | 533 |
| 547 void ShelfButton::UpdateBar() { | 534 void ShelfButton::UpdateBar() { |
| 548 if (state_ & STATE_HIDDEN) { | 535 bool draw_bar = !(state_ & STATE_HIDDEN) && |
| 549 bar_->SetVisible(false); | 536 (state_ & STATE_ACTIVE || state_ & STATE_ATTENTION || |
| 550 return; | 537 state_ & STATE_RUNNING); |
| 551 } | |
| 552 | 538 |
| 553 int bar_id = 0; | 539 if (draw_bar) { |
| 554 if (state_ & (STATE_ACTIVE)) | |
| 555 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; | |
| 556 else if (state_ & STATE_ATTENTION) | |
| 557 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION; | |
| 558 else if (state_ & STATE_RUNNING) | |
| 559 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; | |
| 560 | |
| 561 if (bar_id != 0) { | |
| 562 WmShelf* wm_shelf = shelf_view_->wm_shelf(); | 540 WmShelf* wm_shelf = shelf_view_->wm_shelf(); |
| 563 gfx::ImageSkia image; | 541 gfx::ImageSkia image; |
| 564 if (ash::MaterialDesignController::IsShelfMaterial()) { | 542 if (wm_shelf->IsVisible()) { |
| 565 if (wm_shelf->IsVisible()) { | 543 gfx::Size size(kShelfButtonSize, GetShelfConstant(SHELF_SIZE)); |
| 566 gfx::Size size(GetShelfConstant(SHELF_BUTTON_SIZE), | 544 gfx::Canvas canvas(size, kIndicatorCanvasScale, true /* is_opaque */); |
| 567 GetShelfConstant(SHELF_SIZE)); | 545 PaintIndicatorOnCanvas(&canvas, size); |
| 568 gfx::Canvas canvas(size, kIndicatorCanvasScale, true /* is_opaque */); | 546 image = gfx::ImageSkia(canvas.ExtractImageRep()); |
| 569 PaintIndicatorOnCanvas(&canvas, size); | |
| 570 image = gfx::ImageSkia(canvas.ExtractImageRep()); | |
| 571 } | |
| 572 } else { | |
| 573 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); | |
| 574 image = *rb->GetImageNamed(bar_id).ToImageSkia(); | |
| 575 } | 547 } |
| 576 ShelfAlignment shelf_alignment = wm_shelf->GetAlignment(); | 548 ShelfAlignment shelf_alignment = wm_shelf->GetAlignment(); |
| 577 if (!wm_shelf->IsHorizontalAlignment()) { | 549 if (!wm_shelf->IsHorizontalAlignment()) { |
| 578 image = gfx::ImageSkiaOperations::CreateRotatedImage( | 550 image = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 579 image, shelf_alignment == SHELF_ALIGNMENT_LEFT | 551 image, shelf_alignment == SHELF_ALIGNMENT_LEFT |
| 580 ? SkBitmapOperations::ROTATION_90_CW | 552 ? SkBitmapOperations::ROTATION_90_CW |
| 581 : SkBitmapOperations::ROTATION_270_CW); | 553 : SkBitmapOperations::ROTATION_270_CW); |
| 582 } | 554 } |
| 583 bar_->SetImage(image); | 555 bar_->SetImage(image); |
| 584 switch (shelf_alignment) { | 556 switch (shelf_alignment) { |
| 585 case SHELF_ALIGNMENT_BOTTOM: | 557 case SHELF_ALIGNMENT_BOTTOM: |
| 586 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 558 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| 587 bar_->SetHorizontalAlignment(views::ImageView::CENTER); | 559 bar_->SetHorizontalAlignment(views::ImageView::CENTER); |
| 588 bar_->SetVerticalAlignment(views::ImageView::TRAILING); | 560 bar_->SetVerticalAlignment(views::ImageView::TRAILING); |
| 589 break; | 561 break; |
| 590 case SHELF_ALIGNMENT_LEFT: | 562 case SHELF_ALIGNMENT_LEFT: |
| 591 bar_->SetHorizontalAlignment(views::ImageView::LEADING); | 563 bar_->SetHorizontalAlignment(views::ImageView::LEADING); |
| 592 bar_->SetVerticalAlignment(views::ImageView::CENTER); | 564 bar_->SetVerticalAlignment(views::ImageView::CENTER); |
| 593 break; | 565 break; |
| 594 case SHELF_ALIGNMENT_RIGHT: | 566 case SHELF_ALIGNMENT_RIGHT: |
| 595 bar_->SetHorizontalAlignment(views::ImageView::TRAILING); | 567 bar_->SetHorizontalAlignment(views::ImageView::TRAILING); |
| 596 bar_->SetVerticalAlignment(views::ImageView::CENTER); | 568 bar_->SetVerticalAlignment(views::ImageView::CENTER); |
| 597 break; | 569 break; |
| 598 } | 570 } |
| 599 bar_->SchedulePaint(); | 571 bar_->SchedulePaint(); |
| 600 } | 572 } |
| 601 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); | 573 |
| 574 bar_->SetVisible(draw_bar); |
| 602 } | 575 } |
| 603 | 576 |
| 604 } // namespace ash | 577 } // namespace ash |
| OLD | NEW |