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

Side by Side Diff: remoting/host/event_executor_win.cc

Issue 4726003: Implement InputStub in the host side for chromoting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 1 month 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "remoting/host/event_executor_win.h" 5 #include "remoting/host/event_executor_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8
8 #include "app/keyboard_codes.h" 9 #include "app/keyboard_codes.h"
9 #include "base/stl_util-inl.h" 10 #include "base/stl_util-inl.h"
11 #include "base/task.h"
10 #include "remoting/host/capturer.h" 12 #include "remoting/host/capturer.h"
11 // TODO(hclam): Should not include internal.pb.h here. 13 // TODO(hclam): Should not include internal.pb.h here.
12 #include "remoting/proto/internal.pb.h" 14 #include "remoting/proto/internal.pb.h"
13 15
14 namespace remoting { 16 namespace remoting {
15 17
16 EventExecutorWin::EventExecutorWin(Capturer* capturer) 18 EventExecutorWin::EventExecutorWin(Capturer* capturer)
17 : EventExecutor(capturer) { 19 : capturer_(capturer) {
18 } 20 }
19 21
20 EventExecutorWin::~EventExecutorWin() { 22 EventExecutorWin::~EventExecutorWin() {
21 } 23 }
22 24
23 void EventExecutorWin::HandleInputEvent(ChromotingClientMessage* msg) { 25 void EventExecutorMac::InjectKeyEvent(const KeyEvent* event, Task* done) {
awong 2010/11/10 19:36:54 You should talk to Dave about this. I would be ha
24 if (msg->has_mouse_set_position_event()) { 26 HandleKey(event->key(), event->pressed());
25 HandleMouseSetPosition(msg); 27 done->Run();
26 } else if (msg->has_mouse_move_event()) { 28 delete done;
27 HandleMouseMove(msg);
28 } else if (msg->has_mouse_wheel_event()) {
29 HandleMouseWheel(msg);
30 } else if (msg->has_mouse_down_event()) {
31 HandleMouseButtonDown(msg);
32 } else if (msg->has_mouse_up_event()) {
33 HandleMouseButtonUp(msg);
34 } else if (msg->has_key_event()) {
35 HandleKey(msg);
36 }
37 delete msg;
38 } 29 }
39 30
40 void EventExecutorWin::HandleMouseSetPosition(ChromotingClientMessage* msg) { 31 void EventExecutorMac::InjectMouseEvent(const MouseEvent* event, Task* done) {
41 int x = msg->mouse_set_position_event().x(); 32 if (event->has_mouse_x()) {
42 int y = msg->mouse_set_position_event().y(); 33 HandleMouseSetPosition(event->mouse_x(), event->mouse_y(),
43 int width = msg->mouse_set_position_event().width(); 34 event->mouse_width(), event->mouse_height());
44 int height = msg->mouse_set_position_event().height(); 35 } else if (event->has_wheel_offset_x()) {
36 HandleMouseWheel(event->wheel_offset_x(), event->wheel_offset_y());
37 } else if (event->has_button()) {
38 if (event->button_down())
39 HandleMouseButtonDown(event->button());
40 else
41 HandleMouseButtonUp(event->button());
42 }
43 done->Run();
44 delete done;
45 }
45 46
47 void EventExecutorWin::HandleMouseSetPosition(
48 int x, int y, int width, int height) {
46 // Get width and height from the capturer if they are missing from the 49 // Get width and height from the capturer if they are missing from the
47 // message. 50 // message.
48 if (width == 0 || height == 0) { 51 if (width == 0 || height == 0) {
49 width = capturer_->width(); 52 width = capturer_->width();
50 height = capturer_->height(); 53 height = capturer_->height();
51 } 54 }
52 if (width == 0 || height == 0) { 55 if (width == 0 || height == 0) {
53 return; 56 return;
54 } 57 }
55 58
56 INPUT input; 59 INPUT input;
57 input.type = INPUT_MOUSE; 60 input.type = INPUT_MOUSE;
58 input.mi.time = 0; 61 input.mi.time = 0;
59 input.mi.dx = static_cast<int>((x * 65535) / width); 62 input.mi.dx = static_cast<int>((x * 65535) / width);
60 input.mi.dy = static_cast<int>((y * 65535) / height); 63 input.mi.dy = static_cast<int>((y * 65535) / height);
61 input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; 64 input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
62 SendInput(1, &input, sizeof(INPUT)); 65 SendInput(1, &input, sizeof(INPUT));
63 } 66 }
64 67
65 void EventExecutorWin::HandleMouseMove(ChromotingClientMessage* msg) { 68 void EventExecutorWin::HandleMouseMove(int offset_x, int offset_y) {
66 INPUT input; 69 INPUT input;
67 input.type = INPUT_MOUSE; 70 input.type = INPUT_MOUSE;
68 input.mi.time = 0; 71 input.mi.time = 0;
69 input.mi.dx = msg->mouse_move_event().offset_x(); 72 input.mi.dx = offset_x;
70 input.mi.dy = msg->mouse_move_event().offset_y(); 73 input.mi.dy = offset_y;
71 input.mi.dwFlags = MOUSEEVENTF_MOVE; 74 input.mi.dwFlags = MOUSEEVENTF_MOVE;
72 SendInput(1, &input, sizeof(INPUT)); 75 SendInput(1, &input, sizeof(INPUT));
73 } 76 }
74 77
75 void EventExecutorWin::HandleMouseWheel(ChromotingClientMessage* msg) { 78 void EventExecutorWin::HandleMouseWheel(int offset_x, int offset_y) {
76 INPUT input; 79 INPUT input;
77 input.type = INPUT_MOUSE; 80 input.type = INPUT_MOUSE;
78 input.mi.time = 0; 81 input.mi.time = 0;
79 82
80 int dx = msg->mouse_wheel_event().offset_x(); 83 int dx = offset_x;
81 int dy = msg->mouse_wheel_event().offset_y(); 84 int dy = offset_y;
82 85
83 if (dx != 0) { 86 if (dx != 0) {
84 input.mi.mouseData = dx; 87 input.mi.mouseData = dx;
85 input.mi.dwFlags = MOUSEEVENTF_HWHEEL; 88 input.mi.dwFlags = MOUSEEVENTF_HWHEEL;
86 SendInput(1, &input, sizeof(INPUT)); 89 SendInput(1, &input, sizeof(INPUT));
87 } 90 }
88 if (dy != 0) { 91 if (dy != 0) {
89 input.mi.mouseData = dy; 92 input.mi.mouseData = dy;
90 input.mi.dwFlags = MOUSEEVENTF_WHEEL; 93 input.mi.dwFlags = MOUSEEVENTF_WHEEL;
91 SendInput(1, &input, sizeof(INPUT)); 94 SendInput(1, &input, sizeof(INPUT));
92 } 95 }
93 } 96 }
94 97
95 void EventExecutorWin::HandleMouseButtonDown(ChromotingClientMessage* msg) { 98 void EventExecutorWin::HandleMouseButtonDown(MouseButton button) {
96 INPUT input; 99 INPUT input;
97 input.type = INPUT_MOUSE; 100 input.type = INPUT_MOUSE;
98 input.mi.time = 0; 101 input.mi.time = 0;
99 input.mi.dx = 0; 102 input.mi.dx = 0;
100 input.mi.dy = 0; 103 input.mi.dy = 0;
101 104
102 MouseButton button = msg->mouse_down_event().button();
103 if (button == MouseButtonLeft) { 105 if (button == MouseButtonLeft) {
104 input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; 106 input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
105 } else if (button == MouseButtonMiddle) { 107 } else if (button == MouseButtonMiddle) {
106 input.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN; 108 input.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN;
107 } else if (button == MouseButtonRight) { 109 } else if (button == MouseButtonRight) {
108 input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN; 110 input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
109 } else { 111 } else {
110 input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; 112 input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
111 } 113 }
112 114
113 SendInput(1, &input, sizeof(INPUT)); 115 SendInput(1, &input, sizeof(INPUT));
114 } 116 }
115 117
116 void EventExecutorWin::HandleMouseButtonUp(ChromotingClientMessage* msg) { 118 void EventExecutorWin::HandleMouseButtonUp(MouseButtom button) {
117 INPUT input; 119 INPUT input;
118 input.type = INPUT_MOUSE; 120 input.type = INPUT_MOUSE;
119 input.mi.time = 0; 121 input.mi.time = 0;
120 input.mi.dx = 0; 122 input.mi.dx = 0;
121 input.mi.dy = 0; 123 input.mi.dy = 0;
122 124
123 MouseButton button = msg->mouse_down_event().button();
124 if (button == MouseButtonLeft) { 125 if (button == MouseButtonLeft) {
125 input.mi.dwFlags = MOUSEEVENTF_LEFTUP; 126 input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
126 } else if (button == MouseButtonMiddle) { 127 } else if (button == MouseButtonMiddle) {
127 input.mi.dwFlags = MOUSEEVENTF_MIDDLEUP; 128 input.mi.dwFlags = MOUSEEVENTF_MIDDLEUP;
128 } else if (button == MouseButtonRight) { 129 } else if (button == MouseButtonRight) {
129 input.mi.dwFlags = MOUSEEVENTF_RIGHTUP; 130 input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
130 } else { 131 } else {
131 input.mi.dwFlags = MOUSEEVENTF_LEFTUP; 132 input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
132 } 133 }
133 134
134 SendInput(1, &input, sizeof(INPUT)); 135 SendInput(1, &input, sizeof(INPUT));
135 } 136 }
136 137
137 void EventExecutorWin::HandleKey(ChromotingClientMessage* msg) { 138 void EventExecutorWin::HandleKey(int key, bool down) {
138 int key = msg->key_event().key();
139 bool down = msg->key_event().pressed();
140
141 // Calculate scan code from virtual key. 139 // Calculate scan code from virtual key.
142 HKL hkl = GetKeyboardLayout(0); 140 HKL hkl = GetKeyboardLayout(0);
143 int scan_code = MapVirtualKeyEx(key, MAPVK_VK_TO_VSC_EX, hkl); 141 int scan_code = MapVirtualKeyEx(key, MAPVK_VK_TO_VSC_EX, hkl);
144 142
145 INPUT input; 143 INPUT input;
146 input.type = INPUT_KEYBOARD; 144 input.type = INPUT_KEYBOARD;
147 input.ki.time = 0; 145 input.ki.time = 0;
148 input.ki.wVk = key; 146 input.ki.wVk = key;
149 input.ki.wScan = scan_code; 147 input.ki.wScan = scan_code;
150 148
151 // Flag to mark extended 'e0' key scancodes. Without this, the left and 149 // Flag to mark extended 'e0' key scancodes. Without this, the left and
152 // right windows keys will not be handled properly (on US keyboard). 150 // right windows keys will not be handled properly (on US keyboard).
153 if ((scan_code & 0xFF00) == 0xE000) { 151 if ((scan_code & 0xFF00) == 0xE000) {
154 input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; 152 input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
155 } 153 }
156 154
157 // Flag to mark keyup events. Default is keydown. 155 // Flag to mark keyup events. Default is keydown.
158 if (!down) { 156 if (!down) {
159 input.ki.dwFlags |= KEYEVENTF_KEYUP; 157 input.ki.dwFlags |= KEYEVENTF_KEYUP;
160 } 158 }
161 159
162 SendInput(1, &input, sizeof(INPUT)); 160 SendInput(1, &input, sizeof(INPUT));
163 } 161 }
164 162
165 } // namespace remoting 163 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698