OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_EVENTS_PLATFORM_EVENT_PLATFORM_EVENT_BUILDER_H_ | |
6 #define UI_EVENTS_PLATFORM_EVENT_PLATFORM_EVENT_BUILDER_H_ | |
7 | |
8 #include "base/event_types.h" | |
9 #include "base/gtest_prod_util.h" | |
10 #include "base/macros.h" | |
11 | |
12 namespace ui { | |
13 | |
14 class Event; | |
15 class KeyEvent; | |
16 class LocatedEvent; | |
17 class MouseEvent; | |
18 class MouseWheelEvent; | |
19 class ScrollEvent; | |
20 class TouchEvent; | |
21 | |
22 // Builds ui::Events from native events. | |
23 // | |
24 // In chromium, this functionality was put inline on the individual Event | |
25 // subclasses. This was fine there since all chromium binaries included the | |
26 // system windowing system libraries. In mojo, we have small binaries which | |
27 // have want to have generic events while only the native viewport needs the | |
28 // capability to generate events from platform events. | |
29 class PlatformEventBuilder { | |
30 public: | |
31 static MouseEvent BuildMouseEvent(const base::NativeEvent& native_event); | |
32 static MouseWheelEvent BuildMouseWheelEvent( | |
33 const base::NativeEvent& native_event); | |
34 static TouchEvent BuildTouchEvent(const base::NativeEvent& native_event); | |
35 static KeyEvent BuildKeyEvent(const base::NativeEvent& native_event); | |
36 static ScrollEvent BuildScrollEvent(const base::NativeEvent& native_event); | |
37 | |
38 // Returns the repeat count based on the previous mouse click, if it is | |
39 // recent enough and within a small enough distance. Exposed for testing. | |
40 static int GetRepeatCount(const base::NativeEvent& native_event, | |
41 const MouseEvent& event); | |
42 | |
43 private: | |
44 FRIEND_TEST_ALL_PREFIXES(PlatformEventBuilderXTest, | |
45 DoubleClickRequiresRelease); | |
46 FRIEND_TEST_ALL_PREFIXES(PlatformEventBuilderXTest, SingleClickRightLeft); | |
47 | |
48 // Resets the last_click_event_ for unit tests. | |
49 static void ResetLastClickForTest(); | |
50 | |
51 // Takes data from |native_event| and fills the per class details on |event|. | |
52 static void FillEventFrom(const base::NativeEvent& native_event, | |
53 Event* event); | |
54 static void FillLocatedEventFrom(const base::NativeEvent& native_event, | |
55 LocatedEvent* located_event); | |
56 static void FillMouseEventFrom(const base::NativeEvent& native_event, | |
57 MouseEvent* mouse_event); | |
58 static void FillMouseWheelEventFrom(const base::NativeEvent& native_event, | |
59 MouseWheelEvent* mouse_wheel_event); | |
60 static void FillTouchEventFrom(const base::NativeEvent& native_event, | |
61 TouchEvent* touch_event); | |
62 static void FillKeyEventFrom(const base::NativeEvent& native_event, | |
63 KeyEvent* key_event); | |
64 static void FillScrollEventFrom(const base::NativeEvent& native_event, | |
65 ScrollEvent* scroll_event); | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(PlatformEventBuilder); | |
68 }; | |
69 | |
70 } // namespace ui | |
71 | |
72 #endif // UI_EVENTS_PLATFORM_EVENT_PLATFORM_EVENT_BUILDER_H_ | |
OLD | NEW |