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

Side by Side Diff: views/events/event.cc

Issue 6713027: Add GetCharacter() and GetUnmodifiedCharacter() methods to views::Event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comment. Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « views/events/event.h ('k') | views/events/event_gtk.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/events/event.h" 5 #include "views/events/event.h"
6 6
7 #include "views/view.h" 7 #include "views/view.h"
8 #include "views/widget/root_view.h" 8 #include "views/widget/root_view.h"
9 9
10 namespace views { 10 namespace views {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 //////////////////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////////////////
63 // KeyEvent, public: 63 // KeyEvent, public:
64 64
65 KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code, 65 KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code,
66 int event_flags) 66 int event_flags)
67 : Event(type, event_flags), 67 : Event(type, event_flags),
68 key_code_(key_code) { 68 key_code_(key_code) {
69 } 69 }
70 70
71 // KeyEvent, private: ---------------------------------------------------------
72
73 // static
74 uint16 KeyEvent::GetCharacterFromKeyCode(ui::KeyboardCode key_code, int flags) {
75 const bool ctrl = (flags & ui::EF_CONTROL_DOWN) != 0;
76 const bool shift = (flags & ui::EF_SHIFT_DOWN) != 0;
77 const bool upper = shift ^ ((flags & ui::EF_CAPS_LOCK_DOWN) != 0);
78
79 // Following Windows behavior to map ctrl-a ~ ctrl-z to \x01 ~ \x1A.
80 if (key_code >= ui::VKEY_A && key_code <= ui::VKEY_Z)
81 return key_code - ui::VKEY_A + (ctrl ? 1 : (upper ? 'A' : 'a'));
82
83 // Other ctrl characters
84 if (ctrl) {
85 if (shift) {
86 // following graphics chars require shift key to input.
87 switch (key_code) {
88 // ctrl-@ maps to \x00 (Null byte)
89 case ui::VKEY_2:
90 return 0;
91 // ctrl-^ maps to \x1E (Record separator, Information separator two)
92 case ui::VKEY_6:
93 return 0x1E;
94 // ctrl-_ maps to \x1F (Unit separator, Information separator one)
95 case ui::VKEY_OEM_MINUS:
96 return 0x1F;
97 // Returns 0 for all other keys to avoid inputting unexpected chars.
98 default:
99 return 0;
100 }
101 } else {
102 switch (key_code) {
103 // ctrl-[ maps to \x1B (Escape)
104 case ui::VKEY_OEM_4:
105 return 0x1B;
106 // ctrl-\ maps to \x1C (File separator, Information separator four)
107 case ui::VKEY_OEM_5:
108 return 0x1C;
109 // ctrl-] maps to \x1D (Group separator, Information separator three)
110 case ui::VKEY_OEM_6:
111 return 0x1D;
112 // ctrl-Enter maps to \x0A (Line feed)
113 case ui::VKEY_RETURN:
114 return 0x0A;
115 // Returns 0 for all other keys to avoid inputting unexpected chars.
116 default:
117 return 0;
118 }
119 }
120 }
121
122 // Normal characters
123 if (key_code >= ui::VKEY_0 && key_code <= ui::VKEY_9)
124 return shift ? ")!@#$%^&*("[key_code - ui::VKEY_0] : key_code;
125 else if (key_code >= ui::VKEY_NUMPAD0 && key_code <= ui::VKEY_NUMPAD9)
126 return key_code - ui::VKEY_NUMPAD0 + '0';
127
128 switch (key_code) {
129 case ui::VKEY_TAB:
130 return '\t';
131 case ui::VKEY_RETURN:
132 return '\r';
133 case ui::VKEY_MULTIPLY:
134 return '*';
135 case ui::VKEY_ADD:
136 return '+';
137 case ui::VKEY_SUBTRACT:
138 return '-';
139 case ui::VKEY_DECIMAL:
140 return '.';
141 case ui::VKEY_DIVIDE:
142 return '/';
143 case ui::VKEY_SPACE:
144 return ' ';
145 case ui::VKEY_OEM_1:
146 return shift ? ':' : ';';
147 case ui::VKEY_OEM_PLUS:
148 return shift ? '+' : '=';
149 case ui::VKEY_OEM_COMMA:
150 return shift ? '<' : ',';
151 case ui::VKEY_OEM_MINUS:
152 return shift ? '_' : '-';
153 case ui::VKEY_OEM_PERIOD:
154 return shift ? '>' : '.';
155 case ui::VKEY_OEM_2:
156 return shift ? '?' : '/';
157 case ui::VKEY_OEM_3:
158 return shift ? '~' : '`';
159 case ui::VKEY_OEM_4:
160 return shift ? '{' : '[';
161 case ui::VKEY_OEM_5:
162 return shift ? '|' : '\\';
163 case ui::VKEY_OEM_6:
164 return shift ? '}' : ']';
165 case ui::VKEY_OEM_7:
166 return shift ? '"' : '\'';
167 default:
168 return 0;
169 }
170 }
171
71 //////////////////////////////////////////////////////////////////////////////// 172 ////////////////////////////////////////////////////////////////////////////////
72 // MouseEvent, public: 173 // MouseEvent, public:
73 174
74 // TODO(msw): Kill this legacy constructor when we update uses. 175 // TODO(msw): Kill this legacy constructor when we update uses.
75 MouseEvent::MouseEvent(ui::EventType type, 176 MouseEvent::MouseEvent(ui::EventType type,
76 View* source, 177 View* source,
77 View* target, 178 View* target,
78 const gfx::Point &l, 179 const gfx::Point &l,
79 int flags) 180 int flags)
80 : LocatedEvent(MouseEvent(type, l.x(), l.y(), flags), source, target) { 181 : LocatedEvent(MouseEvent(type, l.x(), l.y(), flags), source, target) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 #endif 214 #endif
114 215
115 //////////////////////////////////////////////////////////////////////////////// 216 ////////////////////////////////////////////////////////////////////////////////
116 // MouseWheelEvent, public: 217 // MouseWheelEvent, public:
117 218
118 // This value matches windows WHEEL_DELTA. 219 // This value matches windows WHEEL_DELTA.
119 // static 220 // static
120 const int MouseWheelEvent::kWheelDelta = 120; 221 const int MouseWheelEvent::kWheelDelta = 120;
121 222
122 } // namespace views 223 } // namespace views
OLDNEW
« no previous file with comments | « views/events/event.h ('k') | views/events/event_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698