| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/arc/notification/arc_custom_notification_view.h" | 5 #include "ui/arc/notification/arc_custom_notification_view.h" |
| 6 | 6 |
| 7 #include "ash/wm/window_util.h" | 7 #include "ash/wm/window_util.h" |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "components/exo/notification_surface.h" | 10 #include "components/exo/notification_surface.h" |
| 11 #include "components/exo/surface.h" | 11 #include "components/exo/surface.h" |
| 12 #include "ui/accessibility/ax_action_data.h" | 12 #include "ui/accessibility/ax_action_data.h" |
| 13 #include "ui/accessibility/ax_node_data.h" |
| 13 #include "ui/arc/notification/arc_notification_view.h" | 14 #include "ui/arc/notification/arc_notification_view.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/compositor/layer_animation_observer.h" | 17 #include "ui/compositor/layer_animation_observer.h" |
| 17 #include "ui/events/event_handler.h" | 18 #include "ui/events/event_handler.h" |
| 18 #include "ui/gfx/animation/linear_animation.h" | 19 #include "ui/gfx/animation/linear_animation.h" |
| 19 #include "ui/gfx/animation/tween.h" | 20 #include "ui/gfx/animation/tween.h" |
| 20 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
| 22 #include "ui/message_center/message_center_style.h" | 23 #include "ui/message_center/message_center_style.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 surface_manager->AddObserver(this); | 245 surface_manager->AddObserver(this); |
| 245 exo::NotificationSurface* surface = | 246 exo::NotificationSurface* surface = |
| 246 surface_manager->GetSurface(notification_key_); | 247 surface_manager->GetSurface(notification_key_); |
| 247 if (surface) | 248 if (surface) |
| 248 OnNotificationSurfaceAdded(surface); | 249 OnNotificationSurfaceAdded(surface); |
| 249 } | 250 } |
| 250 | 251 |
| 251 // Create a layer as an anchor to insert surface copy during a slide. | 252 // Create a layer as an anchor to insert surface copy during a slide. |
| 252 SetPaintToLayer(); | 253 SetPaintToLayer(); |
| 253 UpdatePreferredSize(); | 254 UpdatePreferredSize(); |
| 255 UpdateAccessibleName(); |
| 254 } | 256 } |
| 255 | 257 |
| 256 ArcCustomNotificationView::~ArcCustomNotificationView() { | 258 ArcCustomNotificationView::~ArcCustomNotificationView() { |
| 257 SetSurface(nullptr); | 259 SetSurface(nullptr); |
| 258 | 260 |
| 259 auto* surface_manager = ArcNotificationSurfaceManager::Get(); | 261 auto* surface_manager = ArcNotificationSurfaceManager::Get(); |
| 260 if (surface_manager) | 262 if (surface_manager) |
| 261 surface_manager->RemoveObserver(this); | 263 surface_manager->RemoveObserver(this); |
| 262 if (item_) { | 264 if (item_) { |
| 263 item_->RemoveObserver(this); | 265 item_->RemoveObserver(this); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 settings_button_->background()->get_color() != | 478 settings_button_->background()->get_color() != |
| 477 GetControlButtonBackgroundColor(item_->GetShownContents())) | 479 GetControlButtonBackgroundColor(item_->GetShownContents())) |
| 478 return true; | 480 return true; |
| 479 if (close_button_ && | 481 if (close_button_ && |
| 480 close_button_->background()->get_color() != | 482 close_button_->background()->get_color() != |
| 481 GetControlButtonBackgroundColor(item_->GetShownContents())) | 483 GetControlButtonBackgroundColor(item_->GetShownContents())) |
| 482 return true; | 484 return true; |
| 483 return false; | 485 return false; |
| 484 } | 486 } |
| 485 | 487 |
| 488 void ArcCustomNotificationView::UpdateAccessibleName() { |
| 489 // Don't update the accessible name when we are about to be destroyed. |
| 490 if (!item_) |
| 491 return; |
| 492 |
| 493 accessible_name_ = item_->GetAccessibleName(); |
| 494 } |
| 495 |
| 486 void ArcCustomNotificationView::ViewHierarchyChanged( | 496 void ArcCustomNotificationView::ViewHierarchyChanged( |
| 487 const views::View::ViewHierarchyChangedDetails& details) { | 497 const views::View::ViewHierarchyChangedDetails& details) { |
| 488 views::Widget* widget = GetWidget(); | 498 views::Widget* widget = GetWidget(); |
| 489 | 499 |
| 490 if (!details.is_add) { | 500 if (!details.is_add) { |
| 491 // Resets slide helper when this view is removed from its parent. | 501 // Resets slide helper when this view is removed from its parent. |
| 492 slide_helper_.reset(); | 502 slide_helper_.reset(); |
| 493 | 503 |
| 494 // Bail if this view is no longer attached to a widget or native_view() has | 504 // Bail if this view is no longer attached to a widget or native_view() has |
| 495 // attached to a different widget. | 505 // attached to a different widget. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 | 626 |
| 617 bool ArcCustomNotificationView::HandleAccessibleAction( | 627 bool ArcCustomNotificationView::HandleAccessibleAction( |
| 618 const ui::AXActionData& action_data) { | 628 const ui::AXActionData& action_data) { |
| 619 if (item_ && action_data.action == ui::AX_ACTION_DO_DEFAULT) { | 629 if (item_ && action_data.action == ui::AX_ACTION_DO_DEFAULT) { |
| 620 item_->ToggleExpansion(); | 630 item_->ToggleExpansion(); |
| 621 return true; | 631 return true; |
| 622 } | 632 } |
| 623 return false; | 633 return false; |
| 624 } | 634 } |
| 625 | 635 |
| 636 void ArcCustomNotificationView::GetAccessibleNodeData( |
| 637 ui::AXNodeData* node_data) { |
| 638 node_data->role = ui::AX_ROLE_BUTTON; |
| 639 node_data->SetName(accessible_name_); |
| 640 } |
| 641 |
| 626 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, | 642 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, |
| 627 const ui::Event& event) { | 643 const ui::Event& event) { |
| 628 if (item_ && !item_->GetPinned() && sender == close_button_.get()) { | 644 if (item_ && !item_->GetPinned() && sender == close_button_.get()) { |
| 629 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); | 645 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); |
| 630 static_cast<ArcNotificationView*>(parent())->OnCloseButtonPressed(); | 646 static_cast<ArcNotificationView*>(parent())->OnCloseButtonPressed(); |
| 631 } | 647 } |
| 632 if (item_ && settings_button_ && sender == settings_button_) { | 648 if (item_ && settings_button_ && sender == settings_button_) { |
| 633 item_->OpenSettings(); | 649 item_->OpenSettings(); |
| 634 } | 650 } |
| 635 } | 651 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 652 void ArcCustomNotificationView::OnItemDestroying() { | 668 void ArcCustomNotificationView::OnItemDestroying() { |
| 653 item_->RemoveObserver(this); | 669 item_->RemoveObserver(this); |
| 654 item_ = nullptr; | 670 item_ = nullptr; |
| 655 | 671 |
| 656 // Reset |surface_| with |item_| since no one is observing the |surface_| | 672 // Reset |surface_| with |item_| since no one is observing the |surface_| |
| 657 // after |item_| is gone and this view should be removed soon. | 673 // after |item_| is gone and this view should be removed soon. |
| 658 SetSurface(nullptr); | 674 SetSurface(nullptr); |
| 659 } | 675 } |
| 660 | 676 |
| 661 void ArcCustomNotificationView::OnItemUpdated() { | 677 void ArcCustomNotificationView::OnItemUpdated() { |
| 678 UpdateAccessibleName(); |
| 662 UpdatePinnedState(); | 679 UpdatePinnedState(); |
| 663 UpdateSnapshot(); | 680 UpdateSnapshot(); |
| 664 if (ShouldUpdateControlButtonsColor()) | 681 if (ShouldUpdateControlButtonsColor()) |
| 665 StartControlButtonsColorAnimation(); | 682 StartControlButtonsColorAnimation(); |
| 666 } | 683 } |
| 667 | 684 |
| 668 void ArcCustomNotificationView::OnNotificationSurfaceAdded( | 685 void ArcCustomNotificationView::OnNotificationSurfaceAdded( |
| 669 exo::NotificationSurface* surface) { | 686 exo::NotificationSurface* surface) { |
| 670 if (surface->notification_id() != notification_key_) | 687 if (surface->notification_id() != notification_key_) |
| 671 return; | 688 return; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 } | 724 } |
| 708 if (close_button_) { | 725 if (close_button_) { |
| 709 close_button_->set_background( | 726 close_button_->set_background( |
| 710 views::Background::CreateSolidBackground(current_color)); | 727 views::Background::CreateSolidBackground(current_color)); |
| 711 close_button_->SchedulePaint(); | 728 close_button_->SchedulePaint(); |
| 712 } | 729 } |
| 713 } | 730 } |
| 714 } | 731 } |
| 715 | 732 |
| 716 } // namespace arc | 733 } // namespace arc |
| OLD | NEW |