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" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 case ET_TOUCH_CANCELLED: | 56 case ET_TOUCH_CANCELLED: |
57 event.reset(new TouchEvent(native_event)); | 57 event.reset(new TouchEvent(native_event)); |
58 break; | 58 break; |
59 | 59 |
60 default: | 60 default: |
61 break; | 61 break; |
62 } | 62 } |
63 return event.Pass(); | 63 return event.Pass(); |
64 } | 64 } |
65 | 65 |
66 // From third_party/WebKit/Source/web/gtk/WebInputEventFactory.cpp: | |
67 base::char16 GetControlCharacterForKeycode(int windows_key_code, bool shift) { | |
68 if (windows_key_code >= ui::VKEY_A && | |
69 windows_key_code <= ui::VKEY_Z) { | |
70 // ctrl-A ~ ctrl-Z map to \x01 ~ \x1A | |
71 return windows_key_code - ui::VKEY_A + 1; | |
72 } | |
73 if (shift) { | |
74 // following graphics chars require shift key to input. | |
75 switch (windows_key_code) { | |
76 // ctrl-@ maps to \x00 (Null byte) | |
77 case ui::VKEY_2: | |
78 return 0; | |
79 // ctrl-^ maps to \x1E (Record separator, Information separator two) | |
80 case ui::VKEY_6: | |
81 return 0x1E; | |
82 // ctrl-_ maps to \x1F (Unit separator, Information separator one) | |
83 case ui::VKEY_OEM_MINUS: | |
84 return 0x1F; | |
85 // Returns 0 for all other keys to avoid inputting unexpected chars. | |
86 default: | |
87 break; | |
88 } | |
89 } else { | |
90 switch (windows_key_code) { | |
91 // ctrl-[ maps to \x1B (Escape) | |
92 case ui::VKEY_OEM_4: | |
93 return 0x1B; | |
94 // ctrl-\ maps to \x1C (File separator, Information separator four) | |
95 case ui::VKEY_OEM_5: | |
96 return 0x1C; | |
97 // ctrl-] maps to \x1D (Group separator, Information separator three) | |
98 case ui::VKEY_OEM_6: | |
99 return 0x1D; | |
100 // ctrl-Enter maps to \x0A (Line feed) | |
101 case ui::VKEY_RETURN: | |
102 return 0x0A; | |
103 // Returns 0 for all other keys to avoid inputting unexpected chars. | |
104 default: | |
105 break; | |
106 } | |
107 } | |
108 return 0; | |
109 } | |
110 | |
111 int RegisterCustomEventType() { | 66 int RegisterCustomEventType() { |
112 return ++g_custom_event_types; | 67 return ++g_custom_event_types; |
113 } | 68 } |
114 | 69 |
115 base::TimeDelta EventTimeForNow() { | 70 base::TimeDelta EventTimeForNow() { |
116 return base::TimeDelta::FromInternalValue( | 71 return base::TimeDelta::FromInternalValue( |
117 base::TimeTicks::Now().ToInternalValue()); | 72 base::TimeTicks::Now().ToInternalValue()); |
118 } | 73 } |
119 | 74 |
120 bool ShouldDefaultToNaturalScroll() { | 75 bool ShouldDefaultToNaturalScroll() { |
121 return GetInternalDisplayTouchSupport() == | 76 return GetInternalDisplayTouchSupport() == |
122 gfx::Display::TOUCH_SUPPORT_AVAILABLE; | 77 gfx::Display::TOUCH_SUPPORT_AVAILABLE; |
123 } | 78 } |
124 | 79 |
125 gfx::Display::TouchSupport GetInternalDisplayTouchSupport() { | 80 gfx::Display::TouchSupport GetInternalDisplayTouchSupport() { |
126 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); | 81 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); |
127 // No screen in some unit tests. | 82 // No screen in some unit tests. |
128 if (!screen) | 83 if (!screen) |
129 return gfx::Display::TOUCH_SUPPORT_UNKNOWN; | 84 return gfx::Display::TOUCH_SUPPORT_UNKNOWN; |
130 const std::vector<gfx::Display>& displays = screen->GetAllDisplays(); | 85 const std::vector<gfx::Display>& displays = screen->GetAllDisplays(); |
131 for (std::vector<gfx::Display>::const_iterator it = displays.begin(); | 86 for (std::vector<gfx::Display>::const_iterator it = displays.begin(); |
132 it != displays.end(); ++it) { | 87 it != displays.end(); ++it) { |
133 if (it->IsInternal()) | 88 if (it->IsInternal()) |
134 return it->touch_support(); | 89 return it->touch_support(); |
135 } | 90 } |
136 return gfx::Display::TOUCH_SUPPORT_UNAVAILABLE; | 91 return gfx::Display::TOUCH_SUPPORT_UNAVAILABLE; |
137 } | 92 } |
138 | 93 |
139 } // namespace ui | 94 } // namespace ui |
OLD | NEW |