| 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 "ash/pointer_watcher_delegate_aura.h" | 5 #include "ash/pointer_watcher_delegate_aura.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ui/aura/client/screen_position_client.h" | 8 #include "ui/aura/client/screen_position_client.h" |
| 9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| 11 #include "ui/events/event_constants.h" | 11 #include "ui/events/event_constants.h" |
| 12 #include "ui/gfx/geometry/point.h" | 12 #include "ui/gfx/geometry/point.h" |
| 13 #include "ui/views/pointer_watcher.h" | 13 #include "ui/views/pointer_watcher.h" |
| 14 #include "ui/views/widget/widget.h" |
| 14 | 15 |
| 15 namespace ash { | 16 namespace ash { |
| 16 | 17 |
| 17 PointerWatcherDelegateAura::PointerWatcherDelegateAura() { | 18 PointerWatcherDelegateAura::PointerWatcherDelegateAura() { |
| 18 Shell::GetInstance()->AddPreTargetHandler(this); | 19 Shell::GetInstance()->AddPreTargetHandler(this); |
| 19 } | 20 } |
| 20 | 21 |
| 21 PointerWatcherDelegateAura::~PointerWatcherDelegateAura() { | 22 PointerWatcherDelegateAura::~PointerWatcherDelegateAura() { |
| 22 Shell::GetInstance()->RemovePreTargetHandler(this); | 23 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 23 } | 24 } |
| 24 | 25 |
| 25 void PointerWatcherDelegateAura::AddPointerWatcher( | 26 void PointerWatcherDelegateAura::AddPointerWatcher( |
| 26 views::PointerWatcher* watcher) { | 27 views::PointerWatcher* watcher) { |
| 27 pointer_watchers_.AddObserver(watcher); | 28 pointer_watchers_.AddObserver(watcher); |
| 28 } | 29 } |
| 29 | 30 |
| 30 void PointerWatcherDelegateAura::RemovePointerWatcher( | 31 void PointerWatcherDelegateAura::RemovePointerWatcher( |
| 31 views::PointerWatcher* watcher) { | 32 views::PointerWatcher* watcher) { |
| 32 pointer_watchers_.RemoveObserver(watcher); | 33 pointer_watchers_.RemoveObserver(watcher); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void PointerWatcherDelegateAura::OnMouseEvent(ui::MouseEvent* event) { | 36 void PointerWatcherDelegateAura::OnMouseEvent(ui::MouseEvent* event) { |
| 36 if (event->type() == ui::ET_MOUSE_PRESSED) | 37 if (event->type() == ui::ET_MOUSE_PRESSED) |
| 37 FOR_EACH_OBSERVER(views::PointerWatcher, pointer_watchers_, | 38 FOR_EACH_OBSERVER(views::PointerWatcher, pointer_watchers_, |
| 38 OnMousePressed(*event, GetLocationInScreen(*event))); | 39 OnMousePressed(*event, GetLocationInScreen(*event), |
| 40 GetTargetWidget(*event))); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void PointerWatcherDelegateAura::OnTouchEvent(ui::TouchEvent* event) { | 43 void PointerWatcherDelegateAura::OnTouchEvent(ui::TouchEvent* event) { |
| 42 if (event->type() == ui::ET_TOUCH_PRESSED) | 44 if (event->type() == ui::ET_TOUCH_PRESSED) |
| 43 FOR_EACH_OBSERVER(views::PointerWatcher, pointer_watchers_, | 45 FOR_EACH_OBSERVER(views::PointerWatcher, pointer_watchers_, |
| 44 OnTouchPressed(*event, GetLocationInScreen(*event))); | 46 OnTouchPressed(*event, GetLocationInScreen(*event), |
| 47 GetTargetWidget(*event))); |
| 48 } |
| 49 |
| 50 views::Widget* PointerWatcherDelegateAura::GetTargetWidget( |
| 51 const ui::LocatedEvent& event) const { |
| 52 aura::Window* window = static_cast<aura::Window*>(event.target()); |
| 53 return views::Widget::GetTopLevelWidgetForNativeView(window); |
| 45 } | 54 } |
| 46 | 55 |
| 47 gfx::Point PointerWatcherDelegateAura::GetLocationInScreen( | 56 gfx::Point PointerWatcherDelegateAura::GetLocationInScreen( |
| 48 const ui::LocatedEvent& event) const { | 57 const ui::LocatedEvent& event) const { |
| 49 aura::Window* target = static_cast<aura::Window*>(event.target()); | 58 aura::Window* target = static_cast<aura::Window*>(event.target()); |
| 50 gfx::Point location_in_screen = event.location(); | 59 gfx::Point location_in_screen = event.location(); |
| 51 aura::client::GetScreenPositionClient(target->GetRootWindow()) | 60 aura::client::GetScreenPositionClient(target->GetRootWindow()) |
| 52 ->ConvertPointToScreen(target, &location_in_screen); | 61 ->ConvertPointToScreen(target, &location_in_screen); |
| 53 return location_in_screen; | 62 return location_in_screen; |
| 54 } | 63 } |
| 55 | 64 |
| 56 } // namespace ash | 65 } // namespace ash |
| OLD | NEW |