Chromium Code Reviews| 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" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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()); | |
|
xiyuan
2017/05/16 16:27:58
nit: wrap with {} for all branches
Eliot Courtney
2017/05/17 04:48:25
Done.
| |
| 94 } | |
| 102 } | 95 } |
| 103 | 96 |
| 104 ArcCustomNotificationView* const owner_; | 97 ArcCustomNotificationView* const owner_; |
| 105 | 98 |
| 106 DISALLOW_COPY_AND_ASSIGN(EventForwarder); | 99 DISALLOW_COPY_AND_ASSIGN(EventForwarder); |
| 107 }; | 100 }; |
| 108 | 101 |
| 109 class ArcCustomNotificationView::SlideHelper | 102 class ArcCustomNotificationView::SlideHelper |
| 110 : public ui::LayerAnimationObserver { | 103 : public ui::LayerAnimationObserver { |
| 111 public: | 104 public: |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 void RequestFocusOnCloseButton() override { | 188 void RequestFocusOnCloseButton() override { |
| 196 if (owner_->close_button_) | 189 if (owner_->close_button_) |
| 197 owner_->close_button_->RequestFocus(); | 190 owner_->close_button_->RequestFocus(); |
| 198 owner_->UpdateControlButtonsVisibility(); | 191 owner_->UpdateControlButtonsVisibility(); |
| 199 } | 192 } |
| 200 | 193 |
| 201 void UpdateControlButtonsVisibility() override { | 194 void UpdateControlButtonsVisibility() override { |
| 202 owner_->UpdateControlButtonsVisibility(); | 195 owner_->UpdateControlButtonsVisibility(); |
| 203 } | 196 } |
| 204 | 197 |
| 198 void OnSlideChanged() override { | |
| 199 if (owner_->slide_helper_) | |
| 200 owner_->slide_helper_->Update(); | |
| 201 } | |
| 202 | |
| 205 private: | 203 private: |
| 206 ArcCustomNotificationView* const owner_; | 204 ArcCustomNotificationView* const owner_; |
| 207 | 205 |
| 208 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); | 206 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); |
| 209 }; | 207 }; |
| 210 | 208 |
| 211 ArcCustomNotificationView::ControlButton::ControlButton( | 209 ArcCustomNotificationView::ControlButton::ControlButton( |
| 212 ArcCustomNotificationView* owner) | 210 ArcCustomNotificationView* owner) |
| 213 : message_center::PaddedButton(owner), owner_(owner) { | 211 : message_center::PaddedButton(owner), owner_(owner) { |
| 214 if (owner_->item_) { | 212 if (owner_->item_) { |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 // 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. |
| 566 if (surface_ || !item_ || item_->GetSnapshot().isNull()) | 564 if (surface_ || !item_ || item_->GetSnapshot().isNull()) |
| 567 return; | 565 return; |
| 568 const gfx::Rect contents_bounds = GetContentsBounds(); | 566 const gfx::Rect contents_bounds = GetContentsBounds(); |
| 569 canvas->DrawImageInt(item_->GetSnapshot(), 0, 0, item_->GetSnapshot().width(), | 567 canvas->DrawImageInt(item_->GetSnapshot(), 0, 0, item_->GetSnapshot().width(), |
| 570 item_->GetSnapshot().height(), contents_bounds.x(), | 568 item_->GetSnapshot().height(), contents_bounds.x(), |
| 571 contents_bounds.y(), contents_bounds.width(), | 569 contents_bounds.y(), contents_bounds.width(), |
| 572 contents_bounds.height(), false); | 570 contents_bounds.height(), false); |
| 573 } | 571 } |
| 574 | 572 |
| 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&) { | 573 void ArcCustomNotificationView::OnMouseEntered(const ui::MouseEvent&) { |
| 590 UpdateControlButtonsVisibility(); | 574 UpdateControlButtonsVisibility(); |
| 591 } | 575 } |
| 592 | 576 |
| 593 void ArcCustomNotificationView::OnMouseExited(const ui::MouseEvent&) { | 577 void ArcCustomNotificationView::OnMouseExited(const ui::MouseEvent&) { |
| 594 UpdateControlButtonsVisibility(); | 578 UpdateControlButtonsVisibility(); |
| 595 } | 579 } |
| 596 | 580 |
| 597 void ArcCustomNotificationView::OnFocus() { | 581 void ArcCustomNotificationView::OnFocus() { |
| 598 CHECK_EQ(message_center::CustomNotificationView::kViewClassName, | 582 CHECK_EQ(message_center::CustomNotificationView::kViewClassName, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 } | 711 } |
| 728 if (close_button_) { | 712 if (close_button_) { |
| 729 close_button_->set_background( | 713 close_button_->set_background( |
| 730 views::Background::CreateSolidBackground(current_color)); | 714 views::Background::CreateSolidBackground(current_color)); |
| 731 close_button_->SchedulePaint(); | 715 close_button_->SchedulePaint(); |
| 732 } | 716 } |
| 733 } | 717 } |
| 734 } | 718 } |
| 735 | 719 |
| 736 } // namespace arc | 720 } // namespace arc |
| OLD | NEW |