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

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

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

Powered by Google App Engine
This is Rietveld 408576698