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

Side by Side Diff: win8/metro_driver/metro_driver_win7.cc

Issue 282953003: Support input events in Chrome ASH on Windows 7. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | « no previous file | no next file » | 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 "stdafx.h" 5 #include "stdafx.h"
6 #include <corewindow.h> 6 #include <corewindow.h>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "ui/gfx/win/msg_util.h"
9 10
10 EXTERN_C IMAGE_DOS_HEADER __ImageBase; 11 EXTERN_C IMAGE_DOS_HEADER __ImageBase;
11 int g_window_count = 0; 12 int g_window_count = 0;
12 13
13 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, 14 LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
14 WPARAM wparam, LPARAM lparam) { 15 WPARAM wparam, LPARAM lparam) {
15 PAINTSTRUCT ps; 16 PAINTSTRUCT ps;
16 HDC hdc; 17 HDC hdc;
17 switch (message) { 18 switch (message) {
18 case WM_CREATE: 19 case WM_CREATE:
19 ++g_window_count; 20 ++g_window_count;
20 break; 21 break;
21 case WM_PAINT: 22 case WM_PAINT:
22 hdc = ::BeginPaint(hwnd, &ps); 23 hdc = ::BeginPaint(hwnd, &ps);
23 ::EndPaint(hwnd, &ps); 24 ::EndPaint(hwnd, &ps);
24 break; 25 break;
25 case WM_LBUTTONUP:
26 // TODO(cpu): Remove this test code.
27 ::InvalidateRect(hwnd, NULL, TRUE);
28 break;
29 case WM_CLOSE: 26 case WM_CLOSE:
30 ::DestroyWindow(hwnd); 27 ::DestroyWindow(hwnd);
31 break; 28 break;
32 case WM_DESTROY: 29 case WM_DESTROY:
33 --g_window_count; 30 --g_window_count;
34 if (!g_window_count) 31 if (!g_window_count)
35 ::PostQuitMessage(0); 32 ::PostQuitMessage(0);
36 break; 33 break;
37 default: 34 default:
38 return ::DefWindowProc(hwnd, message, wparam, lparam); 35 return ::DefWindowProc(hwnd, message, wparam, lparam);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 winui::Core::TouchHitTestingEventArgs*> TouchHitTestHandler; 104 winui::Core::TouchHitTestingEventArgs*> TouchHitTestHandler;
108 105
109 typedef winfoundtn::ITypedEventHandler< 106 typedef winfoundtn::ITypedEventHandler<
110 winui::Core::CoreWindow*, 107 winui::Core::CoreWindow*,
111 winui::Core::VisibilityChangedEventArgs*> VisibilityChangedHandler; 108 winui::Core::VisibilityChangedEventArgs*> VisibilityChangedHandler;
112 109
113 typedef winfoundtn::ITypedEventHandler< 110 typedef winfoundtn::ITypedEventHandler<
114 winui::Core::CoreDispatcher*, 111 winui::Core::CoreDispatcher*,
115 winui::Core::AcceleratorKeyEventArgs*> AcceleratorKeyEventHandler; 112 winui::Core::AcceleratorKeyEventArgs*> AcceleratorKeyEventHandler;
116 113
114 // This interface is implemented by classes which handle mouse and keyboard
115 // input.
116 class InputHandler {
117 public:
118 InputHandler() {}
119 virtual ~InputHandler() {}
120
121 virtual bool HandleKeyboardMessage(const MSG& msg) = 0;
122 virtual bool HandleMouseMessage(const MSG& msg) = 0;
123
124 private:
125 DISALLOW_COPY_AND_ASSIGN(InputHandler);
126 };
127
128 // This class implements the winrt interfaces corresponding to mouse input.
129 class MouseEvent : public mswr::RuntimeClass<
130 winui::Core::IPointerEventArgs,
131 winui::Input::IPointerPoint,
132 winui::Input::IPointerPointProperties,
133 windevs::Input::IPointerDevice> {
134 public:
135 MouseEvent(const MSG& msg)
136 : msg_(msg) {
137 }
138
139 // IPointerEventArgs implementation.
140 virtual HRESULT STDMETHODCALLTYPE get_CurrentPoint(
141 winui::Input::IPointerPoint** point) {
142 return QueryInterface(winui::Input::IID_IPointerPoint,
143 reinterpret_cast<void**>(point));
144 }
145
146 virtual HRESULT STDMETHODCALLTYPE get_KeyModifiers(
147 winsys::VirtualKeyModifiers* modifiers) {
148 return E_NOTIMPL;
149 }
150
151 virtual HRESULT STDMETHODCALLTYPE GetIntermediatePoints(
152 __FIVector_1_Windows__CUI__CInput__CPointerPoint** points) {
cpu_(ooo_6.6-7.5) 2014/05/14 00:49:38 use the c++ type instead of the crazy C type.
ananta 2014/05/14 00:59:13 Done.
153 return E_NOTIMPL;
154 }
155
156 // IPointerPoint implementation.
157 virtual HRESULT STDMETHODCALLTYPE get_PointerDevice(
158 windevs::Input::IPointerDevice** pointer_device) {
159 return QueryInterface(windevs::Input::IID_IPointerDevice,
160 reinterpret_cast<void**>(pointer_device));
161 }
162
163 virtual HRESULT STDMETHODCALLTYPE get_Position(winfoundtn::Point* position) {
164 position->X = CR_GET_X_LPARAM(msg_.lParam);
165 position->Y = CR_GET_Y_LPARAM(msg_.lParam);
166 return S_OK;
167 }
168
169 virtual HRESULT STDMETHODCALLTYPE get_PointerId(uint32* pointer_id) {
170 // TODO(ananta)
171 // Implement this properly.
172 *pointer_id = 1;
173 return S_OK;
174 }
175
176 virtual HRESULT STDMETHODCALLTYPE get_Timestamp(uint64* timestamp) {
177 *timestamp = msg_.time;
178 return S_OK;
179 }
180
181 virtual HRESULT STDMETHODCALLTYPE get_Properties(
182 winui::Input::IPointerPointProperties** properties) {
183 return QueryInterface(winui::Input::IID_IPointerPointProperties,
184 reinterpret_cast<void**>(properties));
185 }
186
187 virtual HRESULT STDMETHODCALLTYPE get_RawPosition(
188 winfoundtn::Point* position) {
189 return E_NOTIMPL;
190 }
191
192 virtual HRESULT STDMETHODCALLTYPE get_FrameId(uint32* frame_id) {
193 return E_NOTIMPL;
194 }
195
196 virtual HRESULT STDMETHODCALLTYPE get_IsInContact(boolean* in_contact) {
197 return E_NOTIMPL;
198 }
199
200 // IPointerPointProperties implementation.
201 virtual HRESULT STDMETHODCALLTYPE get_PointerUpdateKind(
202 winui::Input::PointerUpdateKind* update_kind) {
203 // TODO(ananta)
204 // There is no WM_POINTERUPDATE equivalent on Windows 7. Look into
205 // equivalents.
206 if (msg_.message == WM_LBUTTONDOWN) {
207 *update_kind = winui::Input::PointerUpdateKind_LeftButtonPressed;
208 } else if (msg_.message == WM_RBUTTONDOWN) {
209 *update_kind = winui::Input::PointerUpdateKind_RightButtonPressed;
210 } else if (msg_.message == WM_MBUTTONDOWN) {
211 *update_kind = winui::Input::PointerUpdateKind_MiddleButtonPressed;
212 } else if (msg_.message == WM_LBUTTONUP) {
213 *update_kind = winui::Input::PointerUpdateKind_LeftButtonReleased;
214 } else if (msg_.message == WM_RBUTTONUP) {
215 *update_kind = winui::Input::PointerUpdateKind_RightButtonReleased;
216 } else if (msg_.message == WM_MBUTTONUP) {
217 *update_kind = winui::Input::PointerUpdateKind_MiddleButtonReleased;
218 }
219 return S_OK;
220 }
221
222 virtual HRESULT STDMETHODCALLTYPE get_IsLeftButtonPressed(
223 boolean* left_button_pressed) {
224 *left_button_pressed = msg_.wParam & MK_LBUTTON ? true : false;
225 return S_OK;
226 }
227
228 virtual HRESULT STDMETHODCALLTYPE get_IsRightButtonPressed(
229 boolean* right_button_pressed) {
230 *right_button_pressed = msg_.wParam & MK_RBUTTON ? true : false;
231 return S_OK;
232 }
233
234 virtual HRESULT STDMETHODCALLTYPE get_IsMiddleButtonPressed(
235 boolean* middle_button_pressed) {
236 *middle_button_pressed = msg_.wParam & MK_MBUTTON ? true : false;
237 return S_OK;
238 }
239
240 virtual HRESULT STDMETHODCALLTYPE get_IsHorizontalMouseWheel(
241 boolean* is_horizontal_mouse_wheel) {
242 *is_horizontal_mouse_wheel =
243 (msg_.message == WM_MOUSEHWHEEL) ? true : false;
244 return S_OK;
245 }
246
247 virtual HRESULT STDMETHODCALLTYPE get_MouseWheelDelta(int* delta) {
248 if (msg_.message == WM_MOUSEWHEEL || msg_.message == WM_MOUSEHWHEEL) {
249 *delta = GET_WHEEL_DELTA_WPARAM(msg_.wParam);
250 return S_OK;
251 } else {
252 return S_FALSE;
253 }
254 }
255
256 virtual HRESULT STDMETHODCALLTYPE get_Pressure(float* pressure) {
257 return E_NOTIMPL;
258 }
259
260 virtual HRESULT STDMETHODCALLTYPE get_IsInverted(boolean* inverted) {
261 return E_NOTIMPL;
262 }
263
264 virtual HRESULT STDMETHODCALLTYPE get_IsEraser(boolean* is_eraser) {
265 return E_NOTIMPL;
266 }
267
268 virtual HRESULT STDMETHODCALLTYPE get_Orientation(float* orientation) {
269 return E_NOTIMPL;
270 }
271
272 virtual HRESULT STDMETHODCALLTYPE get_XTilt(float* x_tilt) {
273 return E_NOTIMPL;
274 }
275
276 virtual HRESULT STDMETHODCALLTYPE get_YTilt(float* y_tilt) {
277 return E_NOTIMPL;
278 }
279
280 virtual HRESULT STDMETHODCALLTYPE get_Twist(float* twist) {
281 return E_NOTIMPL;
282 }
283
284 virtual HRESULT STDMETHODCALLTYPE get_ContactRect(winfoundtn::Rect* rect) {
285 return E_NOTIMPL;
286 }
287
288 virtual HRESULT STDMETHODCALLTYPE get_ContactRectRaw(winfoundtn::Rect* rect) {
289 return E_NOTIMPL;
290 }
291
292 virtual HRESULT STDMETHODCALLTYPE get_TouchConfidence(boolean* confidence) {
293 return E_NOTIMPL;
294 }
295
296 virtual HRESULT STDMETHODCALLTYPE get_IsPrimary(boolean* is_primary) {
297 return E_NOTIMPL;
298 }
299
300 virtual HRESULT STDMETHODCALLTYPE get_IsInRange(boolean* is_in_range) {
301 return E_NOTIMPL;
302 }
303
304 virtual HRESULT STDMETHODCALLTYPE get_IsCanceled(boolean* is_canceled) {
305 return E_NOTIMPL;
306 }
307
308 virtual HRESULT STDMETHODCALLTYPE get_IsBarrelButtonPressed(
309 boolean* is_barrel_button_pressed) {
310 return E_NOTIMPL;
311 }
312
313 virtual HRESULT STDMETHODCALLTYPE get_IsXButton1Pressed(
314 boolean* is_xbutton1_pressed) {
315 return E_NOTIMPL;
316 }
317
318 virtual HRESULT STDMETHODCALLTYPE get_IsXButton2Pressed(
319 boolean* is_xbutton2_pressed) {
320 return E_NOTIMPL;
321 }
322
323 virtual HRESULT STDMETHODCALLTYPE HasUsage(uint32 usage_page,
324 uint32 usage_id,
325 boolean* has_usage) {
326 return E_NOTIMPL;
327 }
328
329 virtual HRESULT STDMETHODCALLTYPE GetUsageValue(uint32 usage_page,
330 uint32 usage_id,
331 int32* usage_value) {
332 return E_NOTIMPL;
333 }
334
335 // IPointerDevice implementation.
336 virtual HRESULT STDMETHODCALLTYPE get_PointerDeviceType(
337 windevs::Input::PointerDeviceType* device_type) {
338 if (msg_.message == WM_TOUCH) {
339 *device_type = windevs::Input::PointerDeviceType_Touch;
340 } else {
341 *device_type = windevs::Input::PointerDeviceType_Mouse;
342 }
343 return S_OK;
344 }
345
346 virtual HRESULT STDMETHODCALLTYPE get_IsIntegrated(boolean* is_integrated) {
347 return E_NOTIMPL;
348 }
349
350 virtual HRESULT STDMETHODCALLTYPE get_MaxContacts(uint32* contacts) {
351 return E_NOTIMPL;
352 }
353
354 virtual HRESULT STDMETHODCALLTYPE get_PhysicalDeviceRect(
355 winfoundtn::Rect* rect) {
356 return E_NOTIMPL;
357 }
358
359 virtual HRESULT STDMETHODCALLTYPE get_ScreenRect(winfoundtn::Rect* rect) {
360 return E_NOTIMPL;
361 }
362
363 virtual HRESULT STDMETHODCALLTYPE get_SupportedUsages(
cpu_(ooo_6.6-7.5) 2014/05/14 00:49:38 same here about the type.
ananta 2014/05/14 00:59:13 Done.
364 __FIVectorView_1_Windows__CDevices__CInput__CPointerDeviceUsage** usages) {
cpu_(ooo_6.6-7.5) 2014/05/14 00:49:38 something weird about this line.
ananta 2014/05/14 00:59:13 Done.
365 return E_NOTIMPL;
366 }
367
368 private:
369 MSG msg_;
370
371 DISALLOW_COPY_AND_ASSIGN(MouseEvent);
372 };
373
374 // This class implements the winrt interfaces needed to support keyboard
375 // character and system character messages.
376 class KeyEvent : public mswr::RuntimeClass<
377 winui::Core::IKeyEventArgs,
378 winui::Core::ICharacterReceivedEventArgs,
379 winui::Core::IAcceleratorKeyEventArgs> {
380 public:
381 KeyEvent(const MSG& msg)
382 : msg_(msg) {}
383
384 // IKeyEventArgs implementation.
385 virtual HRESULT STDMETHODCALLTYPE get_VirtualKey(
386 winsys::VirtualKey* virtual_key) {
387 *virtual_key = static_cast<winsys::VirtualKey>(msg_.wParam);
388 return S_OK;
389 }
390
391 virtual HRESULT STDMETHODCALLTYPE get_KeyStatus(
392 winui::Core::CorePhysicalKeyStatus* key_status) {
393 // As per msdn documentation for the keyboard messages.
394 key_status->RepeatCount = msg_.lParam & 0x0000FFFF;
395 key_status->ScanCode = (msg_.lParam >> 16) & 0x00FF;
396 key_status->IsExtendedKey = (msg_.lParam & (1 << 24));
397 key_status->IsMenuKeyDown = (msg_.lParam & (1 << 29));
398 key_status->WasKeyDown = (msg_.lParam & (1 << 30));
399 key_status->IsKeyReleased = (msg_.lParam & (1 << 31));
400 return S_OK;
401 }
402
403 // ICharacterReceivedEventArgs implementation.
404 virtual HRESULT STDMETHODCALLTYPE get_KeyCode(uint32* key_code) {
405 *key_code = msg_.wParam;
406 return S_OK;
407 }
408
409 // IAcceleratorKeyEventArgs implementation.
410 virtual HRESULT STDMETHODCALLTYPE get_EventType(
411 winui::Core::CoreAcceleratorKeyEventType* event_type) {
412 if (msg_.message == WM_SYSKEYDOWN) {
413 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemKeyDown;
414 } else if (msg_.message == WM_SYSKEYUP) {
415 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemKeyUp;
416 } else if (msg_.message == WM_SYSCHAR) {
417 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemCharacter;
418 }
419 return S_OK;
420 }
421
422 private:
423 MSG msg_;
424 };
425
117 // The following classes are the emulation of the WinRT system as exposed 426 // The following classes are the emulation of the WinRT system as exposed
118 // to metro applications. There is one application (ICoreApplication) which 427 // to metro applications. There is one application (ICoreApplication) which
119 // contains a series of Views (ICoreApplicationView) each one of them 428 // contains a series of Views (ICoreApplicationView) each one of them
120 // containing a CoreWindow which represents a surface that can drawn to 429 // containing a CoreWindow which represents a surface that can drawn to
121 // and that receives events. 430 // and that receives events.
122 // 431 //
123 // Here is the general dependency hierachy in terms of interfaces: 432 // Here is the general dependency hierachy in terms of interfaces:
124 // 433 //
125 // IFrameworkViewSource --> IFrameworkView 434 // IFrameworkViewSource --> IFrameworkView
126 // ^ | 435 // ^ |
127 // | | metro app 436 // | | metro app
128 // --------------------------------------------------------------------- 437 // ---------------------------------------------------------------------
129 // | | winRT system 438 // | | winRT system
130 // | v 439 // | v
131 // ICoreApplication ICoreApplicationView 440 // ICoreApplication ICoreApplicationView
132 // | 441 // |
133 // v 442 // v
134 // ICoreWindow -----> ICoreWindowInterop 443 // ICoreWindow -----> ICoreWindowInterop
135 // | | 444 // | |
136 // | | 445 // | |
137 // v V 446 // v V
138 // ICoreDispatcher <==> real HWND 447 // ICoreDispatcher <==> real HWND
139 // 448 //
140 class CoreDispacherEmulation : 449 class CoreDispatcherEmulation :
141 public mswr::RuntimeClass< 450 public mswr::RuntimeClass<
142 winui::Core::ICoreDispatcher, 451 winui::Core::ICoreDispatcher,
143 winui::Core::ICoreAcceleratorKeys> { 452 winui::Core::ICoreAcceleratorKeys> {
144 public: 453 public:
454 CoreDispatcherEmulation(InputHandler* input_handler)
455 : input_handler_(input_handler),
456 accelerator_key_event_handler_(NULL) {}
457
145 // ICoreDispatcher implementation: 458 // ICoreDispatcher implementation:
146 virtual HRESULT STDMETHODCALLTYPE get_HasThreadAccess(boolean* value) { 459 virtual HRESULT STDMETHODCALLTYPE get_HasThreadAccess(boolean* value) {
147 return S_OK; 460 return S_OK;
148 } 461 }
149 462
150 virtual HRESULT STDMETHODCALLTYPE ProcessEvents( 463 virtual HRESULT STDMETHODCALLTYPE ProcessEvents(
151 winui::Core::CoreProcessEventsOption options) { 464 winui::Core::CoreProcessEventsOption options) {
152 // We don't support the other message pump modes. So we basically enter a 465 // We don't support the other message pump modes. So we basically enter a
153 // traditional message loop that we only exit a teardown. 466 // traditional message loop that we only exit a teardown.
154 if (options != winui::Core::CoreProcessEventsOption_ProcessUntilQuit) 467 if (options != winui::Core::CoreProcessEventsOption_ProcessUntilQuit)
155 return E_FAIL; 468 return E_FAIL;
156 469
157 MSG msg = {0}; 470 MSG msg = {0};
158 while((::GetMessage(&msg, NULL, 0, 0) != 0) && g_window_count > 0) { 471 while((::GetMessage(&msg, NULL, 0, 0) != 0) && g_window_count > 0) {
472 // Poor mans way of dispatching input events.
cpu_(ooo_6.6-7.5) 2014/05/14 00:49:38 man's
ananta 2014/05/14 00:59:13 Done.
473 if (input_handler_) {
474 if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) {
cpu_(ooo_6.6-7.5) 2014/05/14 00:49:38 can you put some ( ) around the tests, like ((m
ananta 2014/05/14 00:59:13 Done.
475 if (msg.message == WM_SYSKEYDOWN || msg.message == WM_SYSKEYUP ||
476 msg.message == WM_SYSCHAR) {
477 HandleSystemKeys(msg);
478 } else {
479 input_handler_->HandleKeyboardMessage(msg);
480 }
481 } else if (msg.message >= WM_MOUSEFIRST &&
482 msg.message <= WM_MOUSELAST) {
483 input_handler_->HandleMouseMessage(msg);
484 }
485 }
159 ::TranslateMessage(&msg); 486 ::TranslateMessage(&msg);
160 ::DispatchMessage(&msg); 487 ::DispatchMessage(&msg);
161 } 488 }
162 // TODO(cpu): figure what to do with msg.WParam which we would normally 489 // TODO(cpu): figure what to do with msg.WParam which we would normally
163 // return here. 490 // return here.
164 return S_OK; 491 return S_OK;
165 } 492 }
166 493
167 virtual HRESULT STDMETHODCALLTYPE RunAsync( 494 virtual HRESULT STDMETHODCALLTYPE RunAsync(
168 winui::Core::CoreDispatcherPriority priority, 495 winui::Core::CoreDispatcherPriority priority,
169 winui::Core::IDispatchedHandler *agileCallback, 496 winui::Core::IDispatchedHandler *agileCallback,
170 ABI::Windows::Foundation::IAsyncAction** asyncAction) { 497 ABI::Windows::Foundation::IAsyncAction** asyncAction) {
171 return S_OK; 498 return S_OK;
172 } 499 }
173 500
174 virtual HRESULT STDMETHODCALLTYPE RunIdleAsync( 501 virtual HRESULT STDMETHODCALLTYPE RunIdleAsync(
175 winui::Core::IIdleDispatchedHandler *agileCallback, 502 winui::Core::IIdleDispatchedHandler *agileCallback,
176 winfoundtn::IAsyncAction** asyncAction) { 503 winfoundtn::IAsyncAction** asyncAction) {
177 return S_OK; 504 return S_OK;
178 } 505 }
179 506
180 // ICoreAcceleratorKeys implementation: 507 // ICoreAcceleratorKeys implementation:
181 virtual HRESULT STDMETHODCALLTYPE add_AcceleratorKeyActivated( 508 virtual HRESULT STDMETHODCALLTYPE add_AcceleratorKeyActivated(
182 AcceleratorKeyEventHandler* handler, 509 AcceleratorKeyEventHandler* handler,
183 EventRegistrationToken *pCookie) { 510 EventRegistrationToken *pCookie) {
184 // TODO(cpu): implement this. 511 accelerator_key_event_handler_ = handler;
512 accelerator_key_event_handler_->AddRef();
185 return S_OK; 513 return S_OK;
186 } 514 }
187 515
188 virtual HRESULT STDMETHODCALLTYPE remove_AcceleratorKeyActivated( 516 virtual HRESULT STDMETHODCALLTYPE remove_AcceleratorKeyActivated(
189 EventRegistrationToken cookie) { 517 EventRegistrationToken cookie) {
518 accelerator_key_event_handler_->Release();
519 accelerator_key_event_handler_ = NULL;
190 return S_OK; 520 return S_OK;
191 } 521 }
192 522
523 private:
524 bool HandleSystemKeys(const MSG& msg) {
525 mswr::ComPtr<winui::Core::IAcceleratorKeyEventArgs> event_args;
526 event_args = mswr::Make<KeyEvent>(msg);
527 accelerator_key_event_handler_->Invoke(this, event_args.Get());
528 return true;
529 }
530
531 InputHandler* input_handler_;
532 AcceleratorKeyEventHandler* accelerator_key_event_handler_;
193 }; 533 };
194 534
195 class CoreWindowEmulation 535 class CoreWindowEmulation
196 : public mswr::RuntimeClass< 536 : public mswr::RuntimeClass<
197 mswr::RuntimeClassFlags<mswr::WinRtClassicComMix>, 537 mswr::RuntimeClassFlags<mswr::WinRtClassicComMix>,
198 winui::Core::ICoreWindow, ICoreWindowInterop> { 538 winui::Core::ICoreWindow, ICoreWindowInterop>,
539 public InputHandler {
199 public: 540 public:
200 CoreWindowEmulation() : core_hwnd_(NULL) { 541 CoreWindowEmulation()
201 dispatcher_ = mswr::Make<CoreDispacherEmulation>(); 542 : core_hwnd_(NULL),
543 mouse_moved_handler_(NULL),
544 mouse_capture_lost_handler_(NULL),
545 mouse_pressed_handler_(NULL),
546 mouse_released_handler_(NULL),
547 mouse_entered_handler_(NULL),
548 mouse_exited_handler_(NULL),
549 mouse_wheel_changed_handler_(NULL),
550 key_down_handler_(NULL),
551 key_up_handler_(NULL),
552 character_received_handler_(NULL) {
553 dispatcher_ = mswr::Make<CoreDispatcherEmulation>(this);
202 core_hwnd_ = CreateMetroTopLevelWindow(); 554 core_hwnd_ = CreateMetroTopLevelWindow();
203 } 555 }
204 556
205 ~CoreWindowEmulation() { 557 ~CoreWindowEmulation() {
206 if (core_hwnd_) 558 if (core_hwnd_)
207 ::DestroyWindow(core_hwnd_); 559 ::DestroyWindow(core_hwnd_);
208 } 560 }
209 561
210 // ICoreWindow implementation: 562 // ICoreWindow implementation:
211 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( 563 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 675 }
324 676
325 virtual HRESULT STDMETHODCALLTYPE remove_AutomationProviderRequested( 677 virtual HRESULT STDMETHODCALLTYPE remove_AutomationProviderRequested(
326 EventRegistrationToken cookie) { 678 EventRegistrationToken cookie) {
327 return S_OK; 679 return S_OK;
328 } 680 }
329 681
330 virtual HRESULT STDMETHODCALLTYPE add_CharacterReceived( 682 virtual HRESULT STDMETHODCALLTYPE add_CharacterReceived(
331 CharEventHandler* handler, 683 CharEventHandler* handler,
332 EventRegistrationToken* pCookie) { 684 EventRegistrationToken* pCookie) {
333 // TODO(cpu) : implement this. 685 character_received_handler_ = handler;
686 character_received_handler_->AddRef();
334 return S_OK; 687 return S_OK;
335 } 688 }
336 689
337 virtual HRESULT STDMETHODCALLTYPE remove_CharacterReceived( 690 virtual HRESULT STDMETHODCALLTYPE remove_CharacterReceived(
338 EventRegistrationToken cookie) { 691 EventRegistrationToken cookie) {
692 character_received_handler_->Release();
693 character_received_handler_ = NULL;
339 return S_OK; 694 return S_OK;
340 } 695 }
341 696
342 virtual HRESULT STDMETHODCALLTYPE add_Closed( 697 virtual HRESULT STDMETHODCALLTYPE add_Closed(
343 CoreWindowEventHandler* handler, 698 CoreWindowEventHandler* handler,
344 EventRegistrationToken* pCookie) { 699 EventRegistrationToken* pCookie) {
345 return S_OK; 700 return S_OK;
346 } 701 }
347 702
348 virtual HRESULT STDMETHODCALLTYPE remove_Closed( 703 virtual HRESULT STDMETHODCALLTYPE remove_Closed(
349 EventRegistrationToken cookie) { 704 EventRegistrationToken cookie) {
350 return S_OK; 705 return S_OK;
351 } 706 }
352 707
353 virtual HRESULT STDMETHODCALLTYPE add_InputEnabled( 708 virtual HRESULT STDMETHODCALLTYPE add_InputEnabled(
354 InputEnabledEventHandler* handler, 709 InputEnabledEventHandler* handler,
355 EventRegistrationToken* pCookie) { 710 EventRegistrationToken* pCookie) {
356 return S_OK; 711 return S_OK;
357 } 712 }
358 713
359 virtual HRESULT STDMETHODCALLTYPE remove_InputEnabled( 714 virtual HRESULT STDMETHODCALLTYPE remove_InputEnabled(
360 EventRegistrationToken cookie) { 715 EventRegistrationToken cookie) {
361 return S_OK; 716 return S_OK;
362 } 717 }
363 718
364 virtual HRESULT STDMETHODCALLTYPE add_KeyDown( 719 virtual HRESULT STDMETHODCALLTYPE add_KeyDown(
365 KeyEventHandler* handler, 720 KeyEventHandler* handler,
366 EventRegistrationToken* pCookie) { 721 EventRegistrationToken* pCookie) {
367 // TODO(cpu): implement this. 722 key_down_handler_ = handler;
cpu_(ooo_6.6-7.5) 2014/05/14 00:49:38 lets use mswr::ComPtr<> for key_down_handler_ so w
ananta 2014/05/14 00:59:13 We can't do that as we need to hold the reference
723 key_down_handler_->AddRef();
368 return S_OK; 724 return S_OK;
369 } 725 }
370 726
371 virtual HRESULT STDMETHODCALLTYPE remove_KeyDown( 727 virtual HRESULT STDMETHODCALLTYPE remove_KeyDown(
372 EventRegistrationToken cookie) { 728 EventRegistrationToken cookie) {
729 key_down_handler_->Release();
730 key_down_handler_ = NULL;
373 return S_OK; 731 return S_OK;
374 } 732 }
375 733
376 virtual HRESULT STDMETHODCALLTYPE add_KeyUp( 734 virtual HRESULT STDMETHODCALLTYPE add_KeyUp(
377 KeyEventHandler* handler, 735 KeyEventHandler* handler,
378 EventRegistrationToken* pCookie) { 736 EventRegistrationToken* pCookie) {
379 // TODO(cpu): implement this. 737 key_up_handler_ = handler;
738 key_up_handler_->AddRef();
380 return S_OK; 739 return S_OK;
381 } 740 }
382 741
383 virtual HRESULT STDMETHODCALLTYPE remove_KeyUp( 742 virtual HRESULT STDMETHODCALLTYPE remove_KeyUp(
384 EventRegistrationToken cookie) { 743 EventRegistrationToken cookie) {
744 key_up_handler_->Release();
745 key_up_handler_ = NULL;
385 return S_OK; 746 return S_OK;
386 } 747 }
387 748
388 virtual HRESULT STDMETHODCALLTYPE add_PointerCaptureLost( 749 virtual HRESULT STDMETHODCALLTYPE add_PointerCaptureLost(
389 PointerEventHandler* handler, 750 PointerEventHandler* handler,
390 EventRegistrationToken* cookie) { 751 EventRegistrationToken* cookie) {
752 mouse_capture_lost_handler_ = handler;
391 return S_OK; 753 return S_OK;
392 } 754 }
393 755
394 virtual HRESULT STDMETHODCALLTYPE remove_PointerCaptureLost( 756 virtual HRESULT STDMETHODCALLTYPE remove_PointerCaptureLost(
395 EventRegistrationToken cookie) { 757 EventRegistrationToken cookie) {
758 mouse_capture_lost_handler_ = NULL;
396 return S_OK; 759 return S_OK;
397 } 760 }
398 761
399 virtual HRESULT STDMETHODCALLTYPE add_PointerEntered( 762 virtual HRESULT STDMETHODCALLTYPE add_PointerEntered(
400 PointerEventHandler* handler, 763 PointerEventHandler* handler,
401 EventRegistrationToken* cookie) { 764 EventRegistrationToken* cookie) {
765 mouse_entered_handler_ = handler;
402 return S_OK; 766 return S_OK;
403 } 767 }
404 768
405 virtual HRESULT STDMETHODCALLTYPE remove_PointerEntered( 769 virtual HRESULT STDMETHODCALLTYPE remove_PointerEntered(
406 EventRegistrationToken cookie) { 770 EventRegistrationToken cookie) {
771 mouse_entered_handler_ = NULL;
407 return S_OK; 772 return S_OK;
408 } 773 }
409 774
410 virtual HRESULT STDMETHODCALLTYPE add_PointerExited( 775 virtual HRESULT STDMETHODCALLTYPE add_PointerExited(
411 PointerEventHandler* handler, 776 PointerEventHandler* handler,
412 EventRegistrationToken* cookie) { 777 EventRegistrationToken* cookie) {
778 mouse_exited_handler_ = handler;
413 return S_OK; 779 return S_OK;
414 } 780 }
415 781
416 virtual HRESULT STDMETHODCALLTYPE remove_PointerExited( 782 virtual HRESULT STDMETHODCALLTYPE remove_PointerExited(
417 EventRegistrationToken cookie) { 783 EventRegistrationToken cookie) {
784 mouse_exited_handler_ = NULL;
418 return S_OK; 785 return S_OK;
419 } 786 }
420 787
421 virtual HRESULT STDMETHODCALLTYPE add_PointerMoved( 788 virtual HRESULT STDMETHODCALLTYPE add_PointerMoved(
422 PointerEventHandler* handler, 789 PointerEventHandler* handler,
423 EventRegistrationToken* cookie) { 790 EventRegistrationToken* cookie) {
424 // TODO(cpu) : implement this. 791 mouse_moved_handler_ = handler;
792 mouse_moved_handler_->AddRef();
425 return S_OK; 793 return S_OK;
426 } 794 }
427 795
428 virtual HRESULT STDMETHODCALLTYPE remove_PointerMoved( 796 virtual HRESULT STDMETHODCALLTYPE remove_PointerMoved(
429 EventRegistrationToken cookie) { 797 EventRegistrationToken cookie) {
798 mouse_moved_handler_->Release();
799 mouse_moved_handler_ = NULL;
430 return S_OK; 800 return S_OK;
431 } 801 }
432 802
433 virtual HRESULT STDMETHODCALLTYPE add_PointerPressed( 803 virtual HRESULT STDMETHODCALLTYPE add_PointerPressed(
434 PointerEventHandler* handler, 804 PointerEventHandler* handler,
435 EventRegistrationToken* cookie) { 805 EventRegistrationToken* cookie) {
436 // TODO(cpu): implement this. 806 mouse_pressed_handler_ = handler;
807 mouse_pressed_handler_->AddRef();
437 return S_OK; 808 return S_OK;
438 } 809 }
439 810
440 virtual HRESULT STDMETHODCALLTYPE remove_PointerPressed( 811 virtual HRESULT STDMETHODCALLTYPE remove_PointerPressed(
441 EventRegistrationToken cookie) { 812 EventRegistrationToken cookie) {
813 mouse_pressed_handler_->Release();
814 mouse_pressed_handler_ = NULL;
442 return S_OK; 815 return S_OK;
443 } 816 }
444 817
445 virtual HRESULT STDMETHODCALLTYPE add_PointerReleased( 818 virtual HRESULT STDMETHODCALLTYPE add_PointerReleased(
446 PointerEventHandler* handler, 819 PointerEventHandler* handler,
447 EventRegistrationToken* cookie) { 820 EventRegistrationToken* cookie) {
448 // TODO(cpu): implement this. 821 mouse_released_handler_ = handler;
822 mouse_released_handler_->AddRef();
449 return S_OK; 823 return S_OK;
450 } 824 }
451 825
452 virtual HRESULT STDMETHODCALLTYPE remove_PointerReleased( 826 virtual HRESULT STDMETHODCALLTYPE remove_PointerReleased(
453 EventRegistrationToken cookie) { 827 EventRegistrationToken cookie) {
828 mouse_released_handler_->Release();
829 mouse_released_handler_ = NULL;
454 return S_OK; 830 return S_OK;
455 } 831 }
456 832
457 virtual HRESULT STDMETHODCALLTYPE add_TouchHitTesting( 833 virtual HRESULT STDMETHODCALLTYPE add_TouchHitTesting(
458 TouchHitTestHandler* handler, 834 TouchHitTestHandler* handler,
459 EventRegistrationToken* pCookie) { 835 EventRegistrationToken* pCookie) {
460 return S_OK; 836 return S_OK;
461 } 837 }
462 838
463 virtual HRESULT STDMETHODCALLTYPE remove_TouchHitTesting( 839 virtual HRESULT STDMETHODCALLTYPE remove_TouchHitTesting(
464 EventRegistrationToken cookie) { 840 EventRegistrationToken cookie) {
465 return S_OK; 841 return S_OK;
466 } 842 }
467 843
468 virtual HRESULT STDMETHODCALLTYPE add_PointerWheelChanged( 844 virtual HRESULT STDMETHODCALLTYPE add_PointerWheelChanged(
469 PointerEventHandler* handler, 845 PointerEventHandler* handler,
470 EventRegistrationToken* cookie) { 846 EventRegistrationToken* cookie) {
847 mouse_wheel_changed_handler_ = handler;
848 mouse_wheel_changed_handler_->AddRef();
471 return S_OK; 849 return S_OK;
472 } 850 }
473 851
474 virtual HRESULT STDMETHODCALLTYPE remove_PointerWheelChanged( 852 virtual HRESULT STDMETHODCALLTYPE remove_PointerWheelChanged(
475 EventRegistrationToken cookie) { 853 EventRegistrationToken cookie) {
854 mouse_wheel_changed_handler_->Release();
855 mouse_wheel_changed_handler_ = NULL;
476 return S_OK; 856 return S_OK;
477 } 857 }
478 858
479 virtual HRESULT STDMETHODCALLTYPE add_SizeChanged( 859 virtual HRESULT STDMETHODCALLTYPE add_SizeChanged(
480 SizeChangedHandler* handler, 860 SizeChangedHandler* handler,
481 EventRegistrationToken* pCookie) { 861 EventRegistrationToken* pCookie) {
482 // TODO(cpu): implement this. 862 // TODO(cpu): implement this.
483 return S_OK; 863 return S_OK;
484 } 864 }
485 865
(...skipping 19 matching lines...) Expand all
505 return E_FAIL; 885 return E_FAIL;
506 *hwnd = core_hwnd_; 886 *hwnd = core_hwnd_;
507 return S_OK; 887 return S_OK;
508 } 888 }
509 889
510 virtual HRESULT STDMETHODCALLTYPE put_MessageHandled( 890 virtual HRESULT STDMETHODCALLTYPE put_MessageHandled(
511 boolean value) { 891 boolean value) {
512 return S_OK; 892 return S_OK;
513 } 893 }
514 894
895 // InputHandler
896 virtual bool HandleKeyboardMessage(const MSG& msg) OVERRIDE {
897 switch (msg.message) {
898 case WM_KEYDOWN:
899 case WM_KEYUP: {
900 mswr::ComPtr<winui::Core::IKeyEventArgs> event_args;
901 event_args = mswr::Make<KeyEvent>(msg);
902 KeyEventHandler* handler = NULL;
903 if (msg.message == WM_KEYDOWN) {
904 handler = key_down_handler_;
905 } else {
906 handler = key_up_handler_;
907 }
908 handler->Invoke(this, event_args.Get());
909 break;
910 }
911
912 case WM_CHAR:
913 case WM_DEADCHAR:
914 case WM_UNICHAR: {
915 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> event_args;
916 event_args = mswr::Make<KeyEvent>(msg);
917 character_received_handler_->Invoke(this, event_args.Get());
918 break;
919 }
920
921 default:
922 return false;
923 }
924 return true;
925 }
926
927 virtual bool HandleMouseMessage(const MSG& msg) OVERRIDE {
928 PointerEventHandler* handler = NULL;
929 mswr::ComPtr<winui::Core::IPointerEventArgs> event_args;
930 event_args = mswr::Make<MouseEvent>(msg);
931 switch (msg.message) {
932 case WM_MOUSEMOVE: {
933 handler = mouse_moved_handler_;
934 break;
935 }
936 case WM_LBUTTONDOWN: {
937 case WM_RBUTTONDOWN:
938 case WM_MBUTTONDOWN:
939 handler = mouse_pressed_handler_;
940 break;
941 }
942
943 case WM_LBUTTONUP: {
944 case WM_RBUTTONUP:
945 case WM_MBUTTONUP:
946 handler = mouse_released_handler_;
947 break;
948 }
949
950 case WM_MOUSEWHEEL: {
951 case WM_MOUSEHWHEEL:
952 handler = mouse_wheel_changed_handler_;
953 break;
954 }
955
956 default:
957 return false;
958 }
959 DCHECK(handler);
960 handler->Invoke(this, event_args.Get());
961 return true;
962 }
963
515 private: 964 private:
965 PointerEventHandler* mouse_moved_handler_;
966 PointerEventHandler* mouse_capture_lost_handler_;
967 PointerEventHandler* mouse_pressed_handler_;
968 PointerEventHandler* mouse_released_handler_;
969 PointerEventHandler* mouse_entered_handler_;
970 PointerEventHandler* mouse_exited_handler_;
971 PointerEventHandler* mouse_wheel_changed_handler_;
972 KeyEventHandler* key_down_handler_;
973 KeyEventHandler* key_up_handler_;
974 CharEventHandler* character_received_handler_;
516 HWND core_hwnd_; 975 HWND core_hwnd_;
517 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher_; 976 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher_;
518 }; 977 };
519 978
520 class ActivatedEvent 979 class ActivatedEvent
521 : public mswr::RuntimeClass<winapp::Activation::IActivatedEventArgs> { 980 : public mswr::RuntimeClass<winapp::Activation::IActivatedEventArgs> {
522 public: 981 public:
523 ActivatedEvent(winapp::Activation::ActivationKind activation_kind) 982 ActivatedEvent(winapp::Activation::ActivationKind activation_kind)
524 : activation_kind_(activation_kind) { 983 : activation_kind_(activation_kind) {
525 } 984 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 }; 1160 };
702 1161
703 1162
704 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { 1163 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() {
705 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); 1164 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
706 if (FAILED(hr)) 1165 if (FAILED(hr))
707 CHECK(false); 1166 CHECK(false);
708 return mswr::Make<CoreApplicationWin7Emulation>(); 1167 return mswr::Make<CoreApplicationWin7Emulation>();
709 } 1168 }
710 1169
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698