Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: ui/arc/notification/arc_custom_notification_view.cc

Issue 2873553002: [Notifications] Fix swipe to close for ARC notifications. (Closed)
Patch Set: Address comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // ui::EventHandler 57 // ui::EventHandler
58 void OnEvent(ui::Event* event) override { 58 void OnEvent(ui::Event* event) override {
59 // Do not forward event targeted to the floating close button so that 59 // Do not forward event targeted to the floating close button so that
60 // keyboard press and tap are handled properly. 60 // keyboard press and tap are handled properly.
61 if (owner_->floating_control_buttons_widget_ && event->target() && 61 if (owner_->floating_control_buttons_widget_ && event->target() &&
62 owner_->floating_control_buttons_widget_->GetNativeWindow() == 62 owner_->floating_control_buttons_widget_->GetNativeWindow() ==
63 event->target()) { 63 event->target()) {
64 return; 64 return;
65 } 65 }
66 66
67 if (event->IsScrollEvent()) { 67 // TODO(yoshiki): Use a better tigger (eg. focusing EditText on
68 ForwardScrollEvent(event->AsScrollEvent()); 68 // notification) than clicking (crbug.com/697379).
69 } else if (event->IsMouseWheelEvent()) { 69 if (event->type() == ui::ET_MOUSE_PRESSED)
70 ForwardMouseWheelEvent(event->AsMouseWheelEvent()); 70 owner_->ActivateToast();
71 } else if (!event->IsTouchEvent() && event->type() != ui::ET_GESTURE_TAP) {
72 // TODO(yoshiki): Use a better tigger (eg. focusing EditText on
73 // notification) than clicking (crbug.com/697379).
74 if (event->type() == ui::ET_MOUSE_PRESSED)
75 owner_->ActivateToast();
76 71
77 // Forward the rest events to |owner_| except for:
78 // 1. Touches, because View should no longer receive touch events.
79 // See View::OnTouchEvent.
80 // 2. Tap gestures are handled on the Android side, so ignore them.
81 // See crbug.com/709911.
82 owner_->OnEvent(event);
83 }
84 }
85
86 void ForwardScrollEvent(ui::ScrollEvent* event) {
87 views::Widget* widget = owner_->GetWidget(); 72 views::Widget* widget = owner_->GetWidget();
88 if (!widget) 73 if (!widget)
89 return; 74 return;
90 75
91 event->target()->ConvertEventToTarget(widget->GetNativeWindow(), event); 76 // Forward the events to the containing widget, except for:
92 widget->OnScrollEvent(event); 77 // 1. Touches, because View should no longer receive touch events.
93 } 78 // See View::OnTouchEvent.
94 79 // 2. Tap gestures are handled on the Android side, so ignore them.
95 void ForwardMouseWheelEvent(ui::MouseWheelEvent* event) { 80 // See crbug.com/709911.
96 views::Widget* widget = owner_->GetWidget(); 81 // 3. Key events. These are already forwarded by NotificationSurface's
97 if (!widget) 82 // WindowDelegate.
98 return; 83 if (event->IsLocatedEvent()) {
99 84 ui::LocatedEvent* located_event = event->AsLocatedEvent();
100 event->target()->ConvertEventToTarget(widget->GetNativeWindow(), event); 85 located_event->target()->ConvertEventToTarget(widget->GetNativeWindow(),
101 widget->OnMouseEvent(event); 86 located_event);
87 if (located_event->type() == ui::ET_MOUSE_MOVED) {
88 widget->OnMouseEvent(located_event->AsMouseEvent());
89 } else if (located_event->IsScrollEvent()) {
90 widget->OnScrollEvent(located_event->AsScrollEvent());
91 } else if (located_event->IsGestureEvent() &&
92 event->type() != ui::ET_GESTURE_TAP) {
93 widget->OnGestureEvent(located_event->AsGestureEvent());
94 }
95 }
102 } 96 }
103 97
104 ArcCustomNotificationView* const owner_; 98 ArcCustomNotificationView* const owner_;
105 99
106 DISALLOW_COPY_AND_ASSIGN(EventForwarder); 100 DISALLOW_COPY_AND_ASSIGN(EventForwarder);
107 }; 101 };
108 102
109 class ArcCustomNotificationView::SlideHelper 103 class ArcCustomNotificationView::SlideHelper
110 : public ui::LayerAnimationObserver { 104 : public ui::LayerAnimationObserver {
111 public: 105 public:
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 void RequestFocusOnCloseButton() override { 189 void RequestFocusOnCloseButton() override {
196 if (owner_->close_button_) 190 if (owner_->close_button_)
197 owner_->close_button_->RequestFocus(); 191 owner_->close_button_->RequestFocus();
198 owner_->UpdateControlButtonsVisibility(); 192 owner_->UpdateControlButtonsVisibility();
199 } 193 }
200 194
201 void UpdateControlButtonsVisibility() override { 195 void UpdateControlButtonsVisibility() override {
202 owner_->UpdateControlButtonsVisibility(); 196 owner_->UpdateControlButtonsVisibility();
203 } 197 }
204 198
199 void OnSlideChanged() override {
200 if (owner_->slide_helper_)
201 owner_->slide_helper_->Update();
202 }
203
205 private: 204 private:
206 ArcCustomNotificationView* const owner_; 205 ArcCustomNotificationView* const owner_;
207 206
208 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); 207 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate);
209 }; 208 };
210 209
211 ArcCustomNotificationView::ControlButton::ControlButton( 210 ArcCustomNotificationView::ControlButton::ControlButton(
212 ArcCustomNotificationView* owner) 211 ArcCustomNotificationView* owner)
213 : message_center::PaddedButton(owner), owner_(owner) { 212 : message_center::PaddedButton(owner), owner_(owner) {
214 if (owner_->item_) { 213 if (owner_->item_) {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 // Bail if there is a |surface_| or no item or no snapshot image. 564 // Bail if there is a |surface_| or no item or no snapshot image.
566 if (surface_ || !item_ || item_->GetSnapshot().isNull()) 565 if (surface_ || !item_ || item_->GetSnapshot().isNull())
567 return; 566 return;
568 const gfx::Rect contents_bounds = GetContentsBounds(); 567 const gfx::Rect contents_bounds = GetContentsBounds();
569 canvas->DrawImageInt(item_->GetSnapshot(), 0, 0, item_->GetSnapshot().width(), 568 canvas->DrawImageInt(item_->GetSnapshot(), 0, 0, item_->GetSnapshot().width(),
570 item_->GetSnapshot().height(), contents_bounds.x(), 569 item_->GetSnapshot().height(), contents_bounds.x(),
571 contents_bounds.y(), contents_bounds.width(), 570 contents_bounds.y(), contents_bounds.width(),
572 contents_bounds.height(), false); 571 contents_bounds.height(), false);
573 } 572 }
574 573
575 void ArcCustomNotificationView::OnKeyEvent(ui::KeyEvent* event) {
576 // Forward to parent CustomNotificationView to handle keyboard dismissal.
577 parent()->OnKeyEvent(event);
578 }
579
580 void ArcCustomNotificationView::OnGestureEvent(ui::GestureEvent* event) {
581 // Forward to parent CustomNotificationView to handle sliding out.
582 parent()->OnGestureEvent(event);
583
584 // |slide_helper_| could be null before |surface_| is attached.
585 if (slide_helper_)
586 slide_helper_->Update();
587 }
588
589 void ArcCustomNotificationView::OnMouseEntered(const ui::MouseEvent&) { 574 void ArcCustomNotificationView::OnMouseEntered(const ui::MouseEvent&) {
590 UpdateControlButtonsVisibility(); 575 UpdateControlButtonsVisibility();
591 } 576 }
592 577
593 void ArcCustomNotificationView::OnMouseExited(const ui::MouseEvent&) { 578 void ArcCustomNotificationView::OnMouseExited(const ui::MouseEvent&) {
594 UpdateControlButtonsVisibility(); 579 UpdateControlButtonsVisibility();
595 } 580 }
596 581
597 void ArcCustomNotificationView::OnFocus() { 582 void ArcCustomNotificationView::OnFocus() {
598 CHECK_EQ(message_center::CustomNotificationView::kViewClassName, 583 CHECK_EQ(message_center::CustomNotificationView::kViewClassName,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 } 712 }
728 if (close_button_) { 713 if (close_button_) {
729 close_button_->set_background( 714 close_button_->set_background(
730 views::Background::CreateSolidBackground(current_color)); 715 views::Background::CreateSolidBackground(current_color));
731 close_button_->SchedulePaint(); 716 close_button_->SchedulePaint();
732 } 717 }
733 } 718 }
734 } 719 }
735 720
736 } // namespace arc 721 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698