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