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/events/event_utils.h" | 5 #include "ui/events/event_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
10 #include "ui/gfx/display.h" | 10 #include "ui/gfx/display.h" |
11 #include "ui/gfx/screen.h" | 11 #include "ui/gfx/screen.h" |
12 | 12 |
13 namespace ui { | 13 namespace ui { |
14 | 14 |
15 namespace { | 15 namespace { |
16 int g_custom_event_types = ET_LAST; | 16 int g_custom_event_types = ET_LAST; |
17 } // namespace | 17 } // namespace |
18 | 18 |
| 19 Event* EventFromNative(const base::NativeEvent& native_event) { |
| 20 EventType type = EventTypeFromNative(native_event); |
| 21 switch(type) { |
| 22 case ET_KEY_PRESSED: |
| 23 case ET_KEY_RELEASED: |
| 24 return new KeyEvent(native_event, false); |
| 25 |
| 26 case ET_TRANSLATED_KEY_PRESS: |
| 27 case ET_TRANSLATED_KEY_RELEASE: |
| 28 return new TranslatedKeyEvent(native_event, false); |
| 29 |
| 30 case ET_MOUSE_PRESSED: |
| 31 case ET_MOUSE_DRAGGED: |
| 32 case ET_MOUSE_RELEASED: |
| 33 case ET_MOUSE_MOVED: |
| 34 case ET_MOUSE_ENTERED: |
| 35 case ET_MOUSE_EXITED: |
| 36 return new MouseEvent(native_event); |
| 37 |
| 38 case ET_MOUSEWHEEL: |
| 39 return new MouseWheelEvent(native_event); |
| 40 |
| 41 case ET_SCROLL_FLING_START: |
| 42 case ET_SCROLL_FLING_CANCEL: |
| 43 case ET_SCROLL: |
| 44 return new ScrollEvent(native_event); |
| 45 |
| 46 case ET_TOUCH_RELEASED: |
| 47 case ET_TOUCH_PRESSED: |
| 48 case ET_TOUCH_MOVED: |
| 49 case ET_TOUCH_CANCELLED: |
| 50 return new TouchEvent(native_event); |
| 51 |
| 52 default: |
| 53 return NULL; |
| 54 } |
| 55 } |
| 56 |
19 int RegisterCustomEventType() { | 57 int RegisterCustomEventType() { |
20 return ++g_custom_event_types; | 58 return ++g_custom_event_types; |
21 } | 59 } |
22 | 60 |
23 base::TimeDelta EventTimeForNow() { | 61 base::TimeDelta EventTimeForNow() { |
24 return base::TimeDelta::FromInternalValue( | 62 return base::TimeDelta::FromInternalValue( |
25 base::TimeTicks::Now().ToInternalValue()); | 63 base::TimeTicks::Now().ToInternalValue()); |
26 } | 64 } |
27 | 65 |
28 bool ShouldDefaultToNaturalScroll() { | 66 bool ShouldDefaultToNaturalScroll() { |
29 return GetInternalDisplayTouchSupport() == | 67 return GetInternalDisplayTouchSupport() == |
30 gfx::Display::TOUCH_SUPPORT_AVAILABLE; | 68 gfx::Display::TOUCH_SUPPORT_AVAILABLE; |
31 } | 69 } |
32 | 70 |
33 gfx::Display::TouchSupport GetInternalDisplayTouchSupport() { | 71 gfx::Display::TouchSupport GetInternalDisplayTouchSupport() { |
34 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); | 72 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); |
35 // No screen in some unit tests. | 73 // No screen in some unit tests. |
36 if (!screen) | 74 if (!screen) |
37 return gfx::Display::TOUCH_SUPPORT_UNKNOWN; | 75 return gfx::Display::TOUCH_SUPPORT_UNKNOWN; |
38 const std::vector<gfx::Display>& displays = screen->GetAllDisplays(); | 76 const std::vector<gfx::Display>& displays = screen->GetAllDisplays(); |
39 for (std::vector<gfx::Display>::const_iterator it = displays.begin(); | 77 for (std::vector<gfx::Display>::const_iterator it = displays.begin(); |
40 it != displays.end(); ++it) { | 78 it != displays.end(); ++it) { |
41 if (it->IsInternal()) | 79 if (it->IsInternal()) |
42 return it->touch_support(); | 80 return it->touch_support(); |
43 } | 81 } |
44 return gfx::Display::TOUCH_SUPPORT_UNAVAILABLE; | 82 return gfx::Display::TOUCH_SUPPORT_UNAVAILABLE; |
45 } | 83 } |
46 | 84 |
47 } // namespace ui | 85 } // namespace ui |
OLD | NEW |