Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: ui/events/event_utils.cc

Issue 1287103004: Sync ui/events to chromium @ https://codereview.chromium.org/1210203002 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/events/event_utils.h ('k') | ui/events/events_stub.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12
12 namespace ui { 13 namespace ui {
13 14
14 // From third_party/WebKit/Source/web/gtk/WebInputEventFactory.cpp: 15 namespace {
15 base::char16 GetControlCharacterForKeycode(int windows_key_code, bool shift) { 16 int g_custom_event_types = ET_LAST;
16 if (windows_key_code >= ui::VKEY_A && 17 } // namespace
17 windows_key_code <= ui::VKEY_Z) { 18
18 // ctrl-A ~ ctrl-Z map to \x01 ~ \x1A 19 scoped_ptr<Event> EventFromNative(const base::NativeEvent& native_event) {
19 return windows_key_code - ui::VKEY_A + 1; 20 scoped_ptr<Event> event;
21 EventType type = EventTypeFromNative(native_event);
22 switch(type) {
23 case ET_KEY_PRESSED:
24 case ET_KEY_RELEASED:
25 event.reset(new KeyEvent(native_event));
26 break;
27
28 case ET_MOUSE_PRESSED:
29 case ET_MOUSE_DRAGGED:
30 case ET_MOUSE_RELEASED:
31 case ET_MOUSE_MOVED:
32 case ET_MOUSE_ENTERED:
33 case ET_MOUSE_EXITED:
34 event.reset(new MouseEvent(native_event));
35 break;
36
37 case ET_MOUSEWHEEL:
38 event.reset(new MouseWheelEvent(native_event));
39 break;
40
41 case ET_SCROLL_FLING_START:
42 case ET_SCROLL_FLING_CANCEL:
43 case ET_SCROLL:
44 event.reset(new ScrollEvent(native_event));
45 break;
46
47 case ET_TOUCH_RELEASED:
48 case ET_TOUCH_PRESSED:
49 case ET_TOUCH_MOVED:
50 case ET_TOUCH_CANCELLED:
51 event.reset(new TouchEvent(native_event));
52 break;
53
54 default:
55 break;
20 } 56 }
21 if (shift) { 57 return event.Pass();
22 // following graphics chars require shift key to input. 58 }
23 switch (windows_key_code) { 59
24 // ctrl-@ maps to \x00 (Null byte) 60 int RegisterCustomEventType() {
25 case ui::VKEY_2: 61 return ++g_custom_event_types;
26 return 0;
27 // ctrl-^ maps to \x1E (Record separator, Information separator two)
28 case ui::VKEY_6:
29 return 0x1E;
30 // ctrl-_ maps to \x1F (Unit separator, Information separator one)
31 case ui::VKEY_OEM_MINUS:
32 return 0x1F;
33 // Returns 0 for all other keys to avoid inputting unexpected chars.
34 default:
35 break;
36 }
37 } else {
38 switch (windows_key_code) {
39 // ctrl-[ maps to \x1B (Escape)
40 case ui::VKEY_OEM_4:
41 return 0x1B;
42 // ctrl-\ maps to \x1C (File separator, Information separator four)
43 case ui::VKEY_OEM_5:
44 return 0x1C;
45 // ctrl-] maps to \x1D (Group separator, Information separator three)
46 case ui::VKEY_OEM_6:
47 return 0x1D;
48 // ctrl-Enter maps to \x0A (Line feed)
49 case ui::VKEY_RETURN:
50 return 0x0A;
51 // Returns 0 for all other keys to avoid inputting unexpected chars.
52 default:
53 break;
54 }
55 }
56 return 0;
57 } 62 }
58 63
59 base::TimeDelta EventTimeForNow() { 64 base::TimeDelta EventTimeForNow() {
60 return base::TimeDelta::FromInternalValue( 65 return base::TimeDelta::FromInternalValue(
61 base::TimeTicks::Now().ToInternalValue()); 66 base::TimeTicks::Now().ToInternalValue());
62 } 67 }
63 68
69 bool ShouldDefaultToNaturalScroll() {
70 return GetInternalDisplayTouchSupport() ==
71 gfx::Display::TOUCH_SUPPORT_AVAILABLE;
72 }
73
74 gfx::Display::TouchSupport GetInternalDisplayTouchSupport() {
75 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE);
76 // No screen in some unit tests.
77 if (!screen)
78 return gfx::Display::TOUCH_SUPPORT_UNKNOWN;
79 const std::vector<gfx::Display>& displays = screen->GetAllDisplays();
80 for (std::vector<gfx::Display>::const_iterator it = displays.begin();
81 it != displays.end(); ++it) {
82 if (it->IsInternal())
83 return it->touch_support();
84 }
85 return gfx::Display::TOUCH_SUPPORT_UNAVAILABLE;
86 }
87
64 } // namespace ui 88 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/event_utils.h ('k') | ui/events/events_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698