OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/events/event.h" | 5 #include "ui/views/events/event.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/base/keycodes/keyboard_code_conversion.h" | 8 #include "ui/base/keycodes/keyboard_code_conversion.h" |
9 #include "ui/views/view.h" | 9 #include "ui/views/view.h" |
10 #include "ui/views/widget/root_view.h" | 10 #include "ui/views/widget/root_view.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // MouseEvent, public: | 91 // MouseEvent, public: |
92 | 92 |
93 MouseEvent::MouseEvent(const NativeEvent& native_event) | 93 MouseEvent::MouseEvent(const NativeEvent& native_event) |
94 : LocatedEvent(native_event) { | 94 : LocatedEvent(native_event) { |
95 } | 95 } |
96 | 96 |
97 MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target) | 97 MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target) |
98 : LocatedEvent(model, source, target) { | 98 : LocatedEvent(model, source, target) { |
99 } | 99 } |
100 | 100 |
101 MouseEvent::MouseEvent(const TouchEvent& touch) | |
102 : LocatedEvent(touch.native_event()) { | |
103 // The location of the event is correctly extracted from the native event. But | |
104 // it is necessary to update the event type. | |
105 ui::EventType mtype = ui::ET_UNKNOWN; | |
106 switch (touch.type()) { | |
107 case ui::ET_TOUCH_RELEASED: | |
108 mtype = ui::ET_MOUSE_RELEASED; | |
109 break; | |
110 case ui::ET_TOUCH_PRESSED: | |
111 mtype = ui::ET_MOUSE_PRESSED; | |
112 break; | |
113 case ui::ET_TOUCH_MOVED: | |
114 mtype = ui::ET_MOUSE_MOVED; | |
115 break; | |
116 default: | |
117 NOTREACHED() << "Invalid mouse event."; | |
118 } | |
119 set_type(mtype); | |
120 | |
121 // It may not be possible to extract the button-information necessary for a | |
122 // MouseEvent from the native event for a TouchEvent, so the flags are | |
123 // explicitly updated as well. The button is approximated from the touchpoint | |
124 // identity. | |
125 int new_flags = flags() & ~(ui::EF_LEFT_MOUSE_BUTTON | | |
126 ui::EF_RIGHT_MOUSE_BUTTON | | |
127 ui::EF_MIDDLE_MOUSE_BUTTON); | |
128 int button = ui::EF_LEFT_MOUSE_BUTTON; | |
129 if (touch.identity() == 1) | |
130 button = ui::EF_RIGHT_MOUSE_BUTTON; | |
131 else if (touch.identity() == 2) | |
132 button = ui::EF_MIDDLE_MOUSE_BUTTON; | |
133 set_flags(new_flags | button); | |
134 } | |
135 | |
136 //////////////////////////////////////////////////////////////////////////////// | 101 //////////////////////////////////////////////////////////////////////////////// |
137 // MouseWheelEvent, public: | 102 // MouseWheelEvent, public: |
138 | 103 |
139 #if !defined(USE_AURA) | 104 #if !defined(USE_AURA) |
140 MouseWheelEvent::MouseWheelEvent(const NativeEvent& native_event) | 105 MouseWheelEvent::MouseWheelEvent(const NativeEvent& native_event) |
141 : MouseEvent(native_event), | 106 : MouseEvent(native_event), |
142 offset_(ui::GetMouseWheelOffset(native_event)) { | 107 offset_(ui::GetMouseWheelOffset(native_event)) { |
143 } | 108 } |
144 #endif | 109 #endif |
145 | 110 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 #endif | 231 #endif |
267 | 232 |
268 GestureEventForTest::GestureEventForTest(ui::EventType type, | 233 GestureEventForTest::GestureEventForTest(ui::EventType type, |
269 int x, | 234 int x, |
270 int y, | 235 int y, |
271 int flags) | 236 int flags) |
272 : GestureEvent(type, x, y, flags) { | 237 : GestureEvent(type, x, y, flags) { |
273 } | 238 } |
274 | 239 |
275 } // namespace views | 240 } // namespace views |
OLD | NEW |