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