| 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_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/common/ash_constants.h" | 10 #include "ash/common/ash_constants.h" |
| 11 #include "ash/common/material_design/material_design_controller.h" | 11 #include "ash/common/material_design/material_design_controller.h" |
| 12 #include "ash/common/shelf/shelf_constants.h" | 12 #include "ash/common/shelf/shelf_constants.h" |
| 13 #include "ash/shelf/ink_drop_button_listener.h" |
| 13 #include "ash/shelf/shelf.h" | 14 #include "ash/shelf/shelf.h" |
| 14 #include "ash/shelf/shelf_view.h" | 15 #include "ash/shelf/shelf_view.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "grit/ash_resources.h" | 17 #include "grit/ash_resources.h" |
| 17 #include "skia/ext/image_operations.h" | 18 #include "skia/ext/image_operations.h" |
| 18 #include "third_party/skia/include/core/SkPaint.h" | 19 #include "third_party/skia/include/core/SkPaint.h" |
| 19 #include "ui/accessibility/ax_view_state.h" | 20 #include "ui/accessibility/ax_view_state.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/compositor/layer.h" | 22 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 23 #include "ui/events/event_constants.h" | 24 #include "ui/events/event_constants.h" |
| 24 #include "ui/gfx/animation/animation_delegate.h" | 25 #include "ui/gfx/animation/animation_delegate.h" |
| 25 #include "ui/gfx/animation/throb_animation.h" | 26 #include "ui/gfx/animation/throb_animation.h" |
| 26 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
| 27 #include "ui/gfx/geometry/vector2d.h" | 28 #include "ui/gfx/geometry/vector2d.h" |
| 28 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
| 29 #include "ui/gfx/image/image_skia_operations.h" | 30 #include "ui/gfx/image/image_skia_operations.h" |
| 30 #include "ui/gfx/skbitmap_operations.h" | 31 #include "ui/gfx/skbitmap_operations.h" |
| 32 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 31 #include "ui/views/controls/image_view.h" | 33 #include "ui/views/controls/image_view.h" |
| 32 | 34 |
| 33 namespace { | 35 namespace { |
| 34 | 36 |
| 35 // Size of the bar. This is along the opposite axis of the shelf. For example, | 37 // Size of the bar. This is along the opposite axis of the shelf. For example, |
| 36 // if the shelf is aligned horizontally then this is the height of the bar. | 38 // if the shelf is aligned horizontally then this is the height of the bar. |
| 37 const int kBarSize = 3; | 39 const int kBarSize = 3; |
| 38 const int kIconSize = 32; | 40 const int kIconSize = 32; |
| 39 const int kIconPad = 5; | 41 const int kIconPad = 5; |
| 40 const int kIconPadVertical = 6; | 42 const int kIconPadVertical = 6; |
| 41 const int kAttentionThrobDurationMS = 800; | 43 const int kAttentionThrobDurationMS = 800; |
| 42 const int kMaxAnimationSeconds = 10; | 44 const int kMaxAnimationSeconds = 10; |
| 43 const int kIndicatorOffsetFromBottom = 2; | 45 const int kIndicatorOffsetFromBottom = 2; |
| 44 const int kIndicatorRadius = 2; | 46 const int kIndicatorRadius = 2; |
| 45 const SkColor kIndicatorColor = SK_ColorWHITE; | 47 const SkColor kIndicatorColor = SK_ColorWHITE; |
| 46 | 48 |
| 47 // Canvas scale to ensure that the activity indicator is not pixelated even at | 49 // Canvas scale to ensure that the activity indicator is not pixelated even at |
| 48 // the highest possible device scale factors. | 50 // the highest possible device scale factors. |
| 49 const int kIndicatorCanvasScale = 5; | 51 const int kIndicatorCanvasScale = 5; |
| 50 | 52 |
| 53 // Shelf item ripple constants. |
| 54 const int kInkDropSmallSize = 48; |
| 55 const int kInkDropLargeSize = 60; |
| 56 const int kInkDropLargeCornerRadius = 4; |
| 57 const SkColor kInkDropBaseColor = SK_ColorWHITE; |
| 58 |
| 51 // Paints an activity indicator on |canvas| whose |size| is specified in DIP. | 59 // Paints an activity indicator on |canvas| whose |size| is specified in DIP. |
| 52 void PaintIndicatorOnCanvas(gfx::Canvas* canvas, const gfx::Size& size) { | 60 void PaintIndicatorOnCanvas(gfx::Canvas* canvas, const gfx::Size& size) { |
| 53 SkPaint paint; | 61 SkPaint paint; |
| 54 paint.setColor(kIndicatorColor); | 62 paint.setColor(kIndicatorColor); |
| 55 paint.setFlags(SkPaint::kAntiAlias_Flag); | 63 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 56 canvas->DrawCircle( | 64 canvas->DrawCircle( |
| 57 gfx::Point(size.width() / 2, | 65 gfx::Point(size.width() / 2, |
| 58 size.height() - kIndicatorOffsetFromBottom - kIndicatorRadius), | 66 size.height() - kIndicatorOffsetFromBottom - kIndicatorRadius), |
| 59 kIndicatorRadius, paint); | 67 kIndicatorRadius, paint); |
| 60 } | 68 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 243 |
| 236 DISALLOW_COPY_AND_ASSIGN(BarView); | 244 DISALLOW_COPY_AND_ASSIGN(BarView); |
| 237 }; | 245 }; |
| 238 | 246 |
| 239 //////////////////////////////////////////////////////////////////////////////// | 247 //////////////////////////////////////////////////////////////////////////////// |
| 240 // ShelfButton | 248 // ShelfButton |
| 241 | 249 |
| 242 // static | 250 // static |
| 243 const char ShelfButton::kViewClassName[] = "ash/ShelfButton"; | 251 const char ShelfButton::kViewClassName[] = "ash/ShelfButton"; |
| 244 | 252 |
| 245 ShelfButton::ShelfButton(ShelfView* shelf_view) | 253 ShelfButton::ShelfButton(InkDropButtonListener* listener, ShelfView* shelf_view) |
| 246 : CustomButton(shelf_view), | 254 : CustomButton(nullptr), |
| 255 listener_(listener), |
| 247 shelf_view_(shelf_view), | 256 shelf_view_(shelf_view), |
| 248 icon_view_(new views::ImageView()), | 257 icon_view_(new views::ImageView()), |
| 249 bar_(new BarView(shelf_view->shelf())), | 258 bar_(new BarView(shelf_view->shelf())), |
| 250 state_(STATE_NORMAL), | 259 state_(STATE_NORMAL), |
| 251 destroyed_flag_(nullptr) { | 260 destroyed_flag_(nullptr) { |
| 252 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 261 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 262 if (ash::MaterialDesignController::IsShelfMaterial()) { |
| 263 SetHasInkDrop(true); |
| 264 set_ink_drop_base_color(kInkDropBaseColor); |
| 265 } |
| 253 | 266 |
| 254 const gfx::ShadowValue kShadows[] = { | 267 const gfx::ShadowValue kShadows[] = { |
| 255 gfx::ShadowValue(gfx::Vector2d(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), | 268 gfx::ShadowValue(gfx::Vector2d(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), |
| 256 gfx::ShadowValue(gfx::Vector2d(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), | 269 gfx::ShadowValue(gfx::Vector2d(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), |
| 257 gfx::ShadowValue(gfx::Vector2d(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), | 270 gfx::ShadowValue(gfx::Vector2d(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), |
| 258 }; | 271 }; |
| 259 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows)); | 272 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows)); |
| 260 | 273 |
| 261 // TODO: refactor the layers so each button doesn't require 2. | 274 // TODO: refactor the layers so each button doesn't require 2. |
| 262 icon_view_->SetPaintToLayer(true); | 275 icon_view_->SetPaintToLayer(true); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 Layout(); | 338 Layout(); |
| 326 if (state & STATE_ATTENTION) | 339 if (state & STATE_ATTENTION) |
| 327 bar_->ShowAttention(false); | 340 bar_->ShowAttention(false); |
| 328 } | 341 } |
| 329 } | 342 } |
| 330 | 343 |
| 331 gfx::Rect ShelfButton::GetIconBounds() const { | 344 gfx::Rect ShelfButton::GetIconBounds() const { |
| 332 return icon_view_->bounds(); | 345 return icon_view_->bounds(); |
| 333 } | 346 } |
| 334 | 347 |
| 348 void ShelfButton::OnDragStarted() { |
| 349 AnimateInkDrop(views::InkDropState::HIDDEN); |
| 350 } |
| 351 |
| 335 void ShelfButton::ShowContextMenu(const gfx::Point& p, | 352 void ShelfButton::ShowContextMenu(const gfx::Point& p, |
| 336 ui::MenuSourceType source_type) { | 353 ui::MenuSourceType source_type) { |
| 337 if (!context_menu_controller()) | 354 if (!context_menu_controller()) |
| 338 return; | 355 return; |
| 339 | 356 |
| 340 bool destroyed = false; | 357 bool destroyed = false; |
| 341 destroyed_flag_ = &destroyed; | 358 destroyed_flag_ = &destroyed; |
| 342 | 359 |
| 343 CustomButton::ShowContextMenu(p, source_type); | 360 CustomButton::ShowContextMenu(p, source_type); |
| 344 | 361 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 case ui::ET_GESTURE_SCROLL_END: | 491 case ui::ET_GESTURE_SCROLL_END: |
| 475 case ui::ET_SCROLL_FLING_START: | 492 case ui::ET_SCROLL_FLING_START: |
| 476 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false); | 493 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false); |
| 477 event->SetHandled(); | 494 event->SetHandled(); |
| 478 return; | 495 return; |
| 479 default: | 496 default: |
| 480 return CustomButton::OnGestureEvent(event); | 497 return CustomButton::OnGestureEvent(event); |
| 481 } | 498 } |
| 482 } | 499 } |
| 483 | 500 |
| 501 std::unique_ptr<views::InkDropRipple> ShelfButton::CreateInkDropRipple() const { |
| 502 return base::WrapUnique(new views::SquareInkDropRipple( |
| 503 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), |
| 504 kInkDropLargeCornerRadius, |
| 505 gfx::Size(kInkDropSmallSize, kInkDropSmallSize), |
| 506 kInkDropSmallCornerRadius, GetInkDropCenter(), GetInkDropBaseColor())); |
| 507 } |
| 508 |
| 509 bool ShelfButton::ShouldEnterPushedState(const ui::Event& event) { |
| 510 if (!shelf_view_->ShouldEventActivateButton(this, event)) |
| 511 return false; |
| 512 |
| 513 return CustomButton::ShouldEnterPushedState(event); |
| 514 } |
| 515 |
| 516 bool ShelfButton::ShouldShowInkDropHighlight() const { |
| 517 return false; |
| 518 } |
| 519 |
| 520 void ShelfButton::NotifyClick(const ui::Event& event) { |
| 521 CustomButton::NotifyClick(event); |
| 522 if (listener_) |
| 523 listener_->ButtonPressed(this, event, ink_drop()); |
| 524 } |
| 525 |
| 484 void ShelfButton::UpdateState() { | 526 void ShelfButton::UpdateState() { |
| 485 UpdateBar(); | 527 UpdateBar(); |
| 486 Shelf* shelf = shelf_view_->shelf(); | 528 Shelf* shelf = shelf_view_->shelf(); |
| 487 icon_view_->SetHorizontalAlignment(shelf->PrimaryAxisValue( | 529 icon_view_->SetHorizontalAlignment(shelf->PrimaryAxisValue( |
| 488 views::ImageView::CENTER, views::ImageView::LEADING)); | 530 views::ImageView::CENTER, views::ImageView::LEADING)); |
| 489 icon_view_->SetVerticalAlignment(shelf->PrimaryAxisValue( | 531 icon_view_->SetVerticalAlignment(shelf->PrimaryAxisValue( |
| 490 views::ImageView::LEADING, views::ImageView::CENTER)); | 532 views::ImageView::LEADING, views::ImageView::CENTER)); |
| 491 SchedulePaint(); | 533 SchedulePaint(); |
| 492 } | 534 } |
| 493 | 535 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 views::ImageView::TRAILING)); | 572 views::ImageView::TRAILING)); |
| 531 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( | 573 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( |
| 532 views::ImageView::TRAILING, views::ImageView::CENTER, | 574 views::ImageView::TRAILING, views::ImageView::CENTER, |
| 533 views::ImageView::CENTER)); | 575 views::ImageView::CENTER)); |
| 534 bar_->SchedulePaint(); | 576 bar_->SchedulePaint(); |
| 535 } | 577 } |
| 536 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); | 578 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); |
| 537 } | 579 } |
| 538 | 580 |
| 539 } // namespace ash | 581 } // namespace ash |
| OLD | NEW |