OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/views/touchui/gesture_manager.h" | 5 #include "ui/views/touchui/gesture_manager.h" |
6 | 6 |
7 #ifndef NDEBUG | 7 #ifndef NDEBUG |
8 #include <ostream> | 8 #include <ostream> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "ui/views/events/event.h" | 12 #include "ui/views/events/event.h" |
13 #include "views/view.h" | 13 #include "views/view.h" |
14 #include "views/views_delegate.h" | |
15 #include "views/widget/widget.h" | 14 #include "views/widget/widget.h" |
16 | 15 |
17 namespace views { | 16 namespace views { |
18 | 17 |
19 GestureManager::~GestureManager() { | 18 GestureManager::~GestureManager() { |
20 } | 19 } |
21 | 20 |
22 GestureManager* GestureManager::GetInstance() { | 21 GestureManager* GestureManager::GetInstance() { |
23 return Singleton<GestureManager>::get(); | 22 return Singleton<GestureManager>::get(); |
24 } | 23 } |
25 | 24 |
26 bool GestureManager::ProcessTouchEventForGesture(const TouchEvent& event, | 25 bool GestureManager::ProcessTouchEventForGesture(const TouchEvent& event, |
27 View* source, | 26 View* source, |
28 ui::TouchStatus status) { | 27 ui::TouchStatus status) { |
29 if (status != ui::TOUCH_STATUS_UNKNOWN) | 28 if (status != ui::TOUCH_STATUS_UNKNOWN) |
30 return false; // The event was consumed by a touch sequence. | 29 return false; // The event was consumed by a touch sequence. |
31 | 30 |
32 // TODO(rjkroege): A realistic version of the GestureManager will | 31 // TODO(rjkroege): A realistic version of the GestureManager will |
33 // appear in a subsequent CL. This interim version permits verifying that the | 32 // appear in a subsequent CL. This interim version permits verifying that the |
34 // event distribution code works by turning all touch inputs into | 33 // event distribution code works by turning all touch inputs into |
35 // mouse approximations. | 34 // mouse approximations. |
36 | 35 |
37 // Conver the touch-event into a mouse-event. This mouse-event gets its | 36 // Conver the touch-event into a mouse-event. This mouse-event gets its |
38 // location information from the native-event, so it needs to convert the | 37 // location information from the native-event, so it needs to convert the |
39 // coordinate to the target widget. | 38 // coordinate to the target widget. |
40 MouseEvent mouseev(event); | 39 MouseEvent mouseev(event); |
41 if (ViewsDelegate::views_delegate->GetDefaultParentView()) { | 40 Widget* source_widget = source->GetWidget(); |
42 // TODO(oshima): We may need to send the event back through | 41 Widget* top_widget = source_widget->GetTopLevelWidget(); |
43 // window manager to handle mouse capture correctly. | 42 if (source_widget != top_widget && top_widget) { |
44 Widget* desktop = | 43 // This is necessary as TYPE_CHILD widget is still NativeWidgetGtk. |
45 ViewsDelegate::views_delegate->GetDefaultParentView()->GetWidget(); | 44 // Fix this once TYPE_CHILD is switched to NativeWidgetViews. |
46 Widget* source_widget = source->GetWidget(); | 45 MouseEvent converted(mouseev, |
47 MouseEvent converted( | 46 top_widget->GetRootView(), |
48 mouseev, desktop->GetRootView(), source_widget->GetRootView()); | 47 source_widget->GetRootView()); |
49 source_widget->OnMouseEvent(converted); | 48 source_widget->OnMouseEvent(mouseev); |
50 } else { | 49 } else { |
51 Widget* source_widget = source->GetWidget(); | 50 source_widget->OnMouseEvent(mouseev); |
52 Widget* top_widget = source_widget->GetTopLevelWidget(); | |
53 if (source_widget != top_widget && top_widget) { | |
54 // This is necessary as TYPE_CHILD widget is still NativeWidgetGtk. | |
55 // Fix this once TYPE_CHILD is switched to NativeWidgetViews. | |
56 MouseEvent converted(mouseev, | |
57 top_widget->GetRootView(), | |
58 source_widget->GetRootView()); | |
59 source_widget->OnMouseEvent(mouseev); | |
60 } else { | |
61 source_widget->OnMouseEvent(mouseev); | |
62 } | |
63 } | 51 } |
64 return true; | 52 return true; |
65 } | 53 } |
66 | 54 |
67 GestureManager::GestureManager() { | 55 GestureManager::GestureManager() { |
68 } | 56 } |
69 | 57 |
70 } // namespace views | 58 } // namespace views |
OLD | NEW |