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 | 9 |
10 EXTERN_C IMAGE_DOS_HEADER __ImageBase; | 10 EXTERN_C IMAGE_DOS_HEADER __ImageBase; |
11 | 11 |
12 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, | 12 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, |
13 WPARAM wparam, LPARAM lparam) { | 13 WPARAM wparam, LPARAM lparam) { |
14 PAINTSTRUCT ps; | 14 PAINTSTRUCT ps; |
15 HDC hdc; | 15 HDC hdc; |
16 switch (message) { | 16 switch (message) { |
17 case WM_PAINT: | 17 case WM_PAINT: |
18 hdc = BeginPaint(hwnd, &ps); | 18 hdc = ::BeginPaint(hwnd, &ps); |
19 EndPaint(hwnd, &ps); | 19 EndPaint(hwnd, &ps); |
20 break; | 20 break; |
21 case WM_LBUTTONUP: | |
22 // TODO(cpu): Remove this test code. | |
23 ::InvalidateRect(hwnd, NULL, TRUE); | |
24 break; | |
21 case WM_DESTROY: | 25 case WM_DESTROY: |
22 PostQuitMessage(0); | 26 PostQuitMessage(0); |
23 break; | 27 break; |
24 default: | 28 default: |
25 return DefWindowProc(hwnd, message, wparam, lparam); | 29 return ::DefWindowProc(hwnd, message, wparam, lparam); |
26 } | 30 } |
27 return 0; | 31 return 0; |
28 } | 32 } |
29 | 33 |
30 HWND CreateMetroTopLevelWindow() { | 34 HWND CreateMetroTopLevelWindow() { |
31 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase); | 35 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase); |
32 WNDCLASSEXW wcex; | 36 WNDCLASSEXW wcex; |
33 wcex.cbSize = sizeof(wcex); | 37 wcex.cbSize = sizeof(wcex); |
34 wcex.style = CS_HREDRAW | CS_VREDRAW; | 38 wcex.style = CS_HREDRAW | CS_VREDRAW; |
35 wcex.lpfnWndProc = WndProc; | 39 wcex.lpfnWndProc = WndProc; |
36 wcex.cbClsExtra = 0; | 40 wcex.cbClsExtra = 0; |
37 wcex.cbWndExtra = 0; | 41 wcex.cbWndExtra = 0; |
38 wcex.hInstance = hInst; | 42 wcex.hInstance = hInst; |
39 wcex.hIcon = 0; | 43 wcex.hIcon = 0; |
40 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); | 44 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); |
41 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1); | 45 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1); |
42 wcex.lpszMenuName = 0; | 46 wcex.lpszMenuName = 0; |
43 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow"; | 47 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow"; |
44 wcex.hIconSm = 0; | 48 wcex.hIconSm = 0; |
45 | 49 |
46 HWND hwnd = ::CreateWindowExW(0, | 50 HWND hwnd = ::CreateWindowExW(0, |
47 MAKEINTATOM(::RegisterClassExW(&wcex)), | 51 MAKEINTATOM(::RegisterClassExW(&wcex)), |
48 L"metro_win7", | 52 L"metro_win7", |
49 WS_POPUP, | 53 WS_POPUP | WS_VISIBLE, |
50 0, 0, 0, 0, | 54 0, 0, 1024, 1024, |
51 NULL, NULL, hInst, NULL); | 55 NULL, NULL, hInst, NULL); |
52 return hwnd; | 56 return hwnd; |
53 } | 57 } |
54 | 58 |
55 typedef winfoundtn::ITypedEventHandler< | 59 typedef winfoundtn::ITypedEventHandler< |
56 winapp::Core::CoreApplicationView*, | 60 winapp::Core::CoreApplicationView*, |
57 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; | 61 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; |
58 | 62 |
59 typedef winfoundtn::ITypedEventHandler< | 63 typedef winfoundtn::ITypedEventHandler< |
60 winui::Core::CoreWindow*, | 64 winui::Core::CoreWindow*, |
(...skipping 29 matching lines...) Expand all Loading... | |
90 winui::Core::WindowSizeChangedEventArgs*> SizeChangedHandler; | 94 winui::Core::WindowSizeChangedEventArgs*> SizeChangedHandler; |
91 | 95 |
92 typedef winfoundtn::ITypedEventHandler< | 96 typedef winfoundtn::ITypedEventHandler< |
93 winui::Core::CoreWindow*, | 97 winui::Core::CoreWindow*, |
94 winui::Core::TouchHitTestingEventArgs*> TouchHitTestHandler; | 98 winui::Core::TouchHitTestingEventArgs*> TouchHitTestHandler; |
95 | 99 |
96 typedef winfoundtn::ITypedEventHandler< | 100 typedef winfoundtn::ITypedEventHandler< |
97 winui::Core::CoreWindow*, | 101 winui::Core::CoreWindow*, |
98 winui::Core::VisibilityChangedEventArgs*> VisibilityChangedHandler; | 102 winui::Core::VisibilityChangedEventArgs*> VisibilityChangedHandler; |
99 | 103 |
104 typedef winfoundtn::ITypedEventHandler< | |
105 winui::Core::CoreDispatcher*, | |
106 winui::Core::AcceleratorKeyEventArgs*> AcceleratorKeyEventHandler; | |
107 | |
100 // The following classes are the emulation of the WinRT system as exposed | 108 // The following classes are the emulation of the WinRT system as exposed |
101 // to metro applications. There is one application (ICoreApplication) which | 109 // to metro applications. There is one application (ICoreApplication) which |
102 // contains a series of Views (ICoreApplicationView) each one of them | 110 // contains a series of Views (ICoreApplicationView) each one of them |
103 // containing a CoreWindow which represents a surface that can drawn to | 111 // containing a CoreWindow which represents a surface that can drawn to |
104 // and that receives events. | 112 // and that receives events. |
105 // | 113 // |
106 // Here is the general dependency hierachy in terms of interfaces: | 114 // Here is the general dependency hierachy in terms of interfaces: |
107 // | 115 // |
108 // IFrameworkViewSource --> IFrameworkView | 116 // IFrameworkViewSource --> IFrameworkView |
109 // ^ | | 117 // ^ | |
110 // | | metro app | 118 // | | metro app |
111 // --------------------------------------------------------------------- | 119 // --------------------------------------------------------------------- |
112 // | | winRT system | 120 // | | winRT system |
113 // | v | 121 // | v |
114 // ICoreApplication ICoreApplicationView | 122 // ICoreApplication ICoreApplicationView |
zturner
2014/03/27 00:49:49
nit: Empty spaces at end of line.
| |
115 // | | 123 // | |
116 // v | 124 // v |
117 // ICoreWindow ----> ICoreWindowInterop | 125 // ICoreWindow -----> ICoreWindowInterop |
118 // | | 126 // | | |
119 // | | 127 // | | |
120 // V | 128 // v V |
121 // real HWND | 129 // ICoreDispatcher <==> real HWND |
122 // | 130 // |
131 class CoreDispacherEmulation : | |
132 public mswr::RuntimeClass< | |
133 winui::Core::ICoreDispatcher, | |
134 winui::Core::ICoreAcceleratorKeys> { | |
135 public: | |
136 // ICoreDispatcher implementation: | |
137 virtual HRESULT STDMETHODCALLTYPE get_HasThreadAccess(boolean* value) { | |
138 return S_OK; | |
139 } | |
140 | |
141 virtual HRESULT STDMETHODCALLTYPE ProcessEvents( | |
142 winui::Core::CoreProcessEventsOption options) { | |
143 // We don't support the other message pump modes. So we basically enter a | |
144 // traditional message loop that we only exit a teardown. | |
145 if (options != winui::Core::CoreProcessEventsOption_ProcessUntilQuit) | |
146 return E_FAIL; | |
147 | |
148 MSG msg = {0}; | |
149 while(::GetMessage(&msg, NULL, 0, 0) != 0) { | |
150 ::TranslateMessage(&msg); | |
151 ::DispatchMessage(&msg); | |
152 } | |
153 // TODO(cpu): figure what to do with msg.WParam which we would normally | |
154 // return here. | |
155 return S_OK; | |
156 } | |
157 | |
158 virtual HRESULT STDMETHODCALLTYPE RunAsync( | |
159 winui::Core::CoreDispatcherPriority priority, | |
160 winui::Core::IDispatchedHandler *agileCallback, | |
scottmg
2014/03/26 19:56:54
nit; random * bindings here
| |
161 ABI::Windows::Foundation::IAsyncAction** asyncAction) { | |
162 return S_OK; | |
163 } | |
164 | |
165 virtual HRESULT STDMETHODCALLTYPE RunIdleAsync( | |
166 winui::Core::IIdleDispatchedHandler *agileCallback, | |
167 winfoundtn::IAsyncAction** asyncAction) { | |
168 return S_OK; | |
169 } | |
170 | |
171 // ICoreAcceleratorKeys implementation: | |
172 virtual HRESULT STDMETHODCALLTYPE add_AcceleratorKeyActivated( | |
173 AcceleratorKeyEventHandler* handler, | |
174 EventRegistrationToken *pCookie) { | |
175 // TODO(cpu): implement this. | |
176 return S_OK; | |
177 } | |
178 | |
179 virtual HRESULT STDMETHODCALLTYPE remove_AcceleratorKeyActivated( | |
180 EventRegistrationToken cookie) { | |
181 return S_OK; | |
182 } | |
183 | |
184 }; | |
123 | 185 |
124 class CoreWindowEmulation | 186 class CoreWindowEmulation |
125 : public mswr::RuntimeClass< | 187 : public mswr::RuntimeClass< |
126 mswr::RuntimeClassFlags<mswr::WinRtClassicComMix>, | 188 mswr::RuntimeClassFlags<mswr::WinRtClassicComMix>, |
127 winui::Core::ICoreWindow, ICoreWindowInterop> { | 189 winui::Core::ICoreWindow, ICoreWindowInterop> { |
128 public: | 190 public: |
191 CoreWindowEmulation() : core_hwnd_(NULL) { | |
192 dispatcher_ = mswr::Make<CoreDispacherEmulation>(); | |
193 core_hwnd_ = CreateMetroTopLevelWindow(); | |
194 } | |
195 | |
196 ~CoreWindowEmulation() { | |
197 ::DestroyWindow(core_hwnd_); | |
198 } | |
199 | |
129 // ICoreWindow implementation: | 200 // ICoreWindow implementation: |
130 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( | 201 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( |
131 IInspectable **value) { | 202 IInspectable** value) { |
132 return S_OK; | 203 return S_OK; |
133 } | 204 } |
134 | 205 |
135 virtual HRESULT STDMETHODCALLTYPE get_Bounds( | 206 virtual HRESULT STDMETHODCALLTYPE get_Bounds( |
136 winfoundtn::Rect* value) { | 207 winfoundtn::Rect* value) { |
208 RECT rect; | |
209 if (!::GetClientRect(core_hwnd_, &rect)) | |
210 return E_FAIL; | |
211 value->Width = rect.right; | |
212 value->Height = rect.bottom; | |
137 return S_OK; | 213 return S_OK; |
138 } | 214 } |
139 | 215 |
140 virtual HRESULT STDMETHODCALLTYPE get_CustomProperties( | 216 virtual HRESULT STDMETHODCALLTYPE get_CustomProperties( |
141 winfoundtn::Collections::IPropertySet **value) { | 217 winfoundtn::Collections::IPropertySet** value) { |
142 return S_OK; | 218 return S_OK; |
143 } | 219 } |
144 | 220 |
145 virtual HRESULT STDMETHODCALLTYPE get_Dispatcher( | 221 virtual HRESULT STDMETHODCALLTYPE get_Dispatcher( |
146 winui::Core::ICoreDispatcher **value) { | 222 winui::Core::ICoreDispatcher** value) { |
147 return S_OK; | 223 return dispatcher_.CopyTo(value); |
148 } | 224 } |
149 | 225 |
150 virtual HRESULT STDMETHODCALLTYPE get_FlowDirection( | 226 virtual HRESULT STDMETHODCALLTYPE get_FlowDirection( |
151 winui::Core::CoreWindowFlowDirection* value) { | 227 winui::Core::CoreWindowFlowDirection* value) { |
152 return S_OK; | 228 return S_OK; |
153 } | 229 } |
154 | 230 |
155 virtual HRESULT STDMETHODCALLTYPE put_FlowDirection( | 231 virtual HRESULT STDMETHODCALLTYPE put_FlowDirection( |
156 winui::Core::CoreWindowFlowDirection value) { | 232 winui::Core::CoreWindowFlowDirection value) { |
157 return S_OK; | 233 return S_OK; |
158 } | 234 } |
159 | 235 |
160 virtual HRESULT STDMETHODCALLTYPE get_IsInputEnabled( | 236 virtual HRESULT STDMETHODCALLTYPE get_IsInputEnabled( |
161 boolean* value) { | 237 boolean* value) { |
162 return S_OK; | 238 return S_OK; |
163 } | 239 } |
164 | 240 |
165 virtual HRESULT STDMETHODCALLTYPE put_IsInputEnabled( | 241 virtual HRESULT STDMETHODCALLTYPE put_IsInputEnabled( |
166 boolean value) { | 242 boolean value) { |
167 return S_OK; | 243 return S_OK; |
168 } | 244 } |
169 | 245 |
170 virtual HRESULT STDMETHODCALLTYPE get_PointerCursor( | 246 virtual HRESULT STDMETHODCALLTYPE get_PointerCursor( |
171 winui::Core::ICoreCursor **value) { | 247 winui::Core::ICoreCursor** value) { |
172 return S_OK; | 248 return S_OK; |
173 } | 249 } |
174 | 250 |
175 virtual HRESULT STDMETHODCALLTYPE put_PointerCursor( | 251 virtual HRESULT STDMETHODCALLTYPE put_PointerCursor( |
176 winui::Core::ICoreCursor* value) { | 252 winui::Core::ICoreCursor* value) { |
177 return S_OK; | 253 return S_OK; |
178 } | 254 } |
179 | 255 |
180 virtual HRESULT STDMETHODCALLTYPE get_PointerPosition( | 256 virtual HRESULT STDMETHODCALLTYPE get_PointerPosition( |
181 winfoundtn::Point* value) { | 257 winfoundtn::Point* value) { |
182 return S_OK; | 258 return S_OK; |
183 } | 259 } |
184 | 260 |
185 virtual HRESULT STDMETHODCALLTYPE get_Visible( | 261 virtual HRESULT STDMETHODCALLTYPE get_Visible( |
186 boolean* value) { | 262 boolean* value) { |
187 return S_OK; | 263 return S_OK; |
188 } | 264 } |
189 | 265 |
190 virtual HRESULT STDMETHODCALLTYPE Activate(void) { | 266 virtual HRESULT STDMETHODCALLTYPE Activate(void) { |
267 // After we fire OnActivate on the View, Chrome calls us back here. | |
191 return S_OK; | 268 return S_OK; |
192 } | 269 } |
193 | 270 |
194 virtual HRESULT STDMETHODCALLTYPE Close(void) { | 271 virtual HRESULT STDMETHODCALLTYPE Close(void) { |
195 return S_OK; | 272 return S_OK; |
196 } | 273 } |
197 | 274 |
198 virtual HRESULT STDMETHODCALLTYPE GetAsyncKeyState( | 275 virtual HRESULT STDMETHODCALLTYPE GetAsyncKeyState( |
199 ABI::Windows::System::VirtualKey virtualKey, | 276 ABI::Windows::System::VirtualKey virtualKey, |
200 winui::Core::CoreVirtualKeyStates* KeyState) { | 277 winui::Core::CoreVirtualKeyStates* KeyState) { |
(...skipping 10 matching lines...) Expand all Loading... | |
211 return S_OK; | 288 return S_OK; |
212 } | 289 } |
213 | 290 |
214 virtual HRESULT STDMETHODCALLTYPE SetPointerCapture(void) { | 291 virtual HRESULT STDMETHODCALLTYPE SetPointerCapture(void) { |
215 return S_OK; | 292 return S_OK; |
216 } | 293 } |
217 | 294 |
218 virtual HRESULT STDMETHODCALLTYPE add_Activated( | 295 virtual HRESULT STDMETHODCALLTYPE add_Activated( |
219 WindowActivatedHandler* handler, | 296 WindowActivatedHandler* handler, |
220 EventRegistrationToken* pCookie) { | 297 EventRegistrationToken* pCookie) { |
298 // TODO(cpu) implement this. | |
221 return S_OK; | 299 return S_OK; |
222 } | 300 } |
223 | 301 |
224 virtual HRESULT STDMETHODCALLTYPE remove_Activated( | 302 virtual HRESULT STDMETHODCALLTYPE remove_Activated( |
225 EventRegistrationToken cookie) { | 303 EventRegistrationToken cookie) { |
226 return S_OK; | 304 return S_OK; |
227 } | 305 } |
228 | 306 |
229 virtual HRESULT STDMETHODCALLTYPE add_AutomationProviderRequested( | 307 virtual HRESULT STDMETHODCALLTYPE add_AutomationProviderRequested( |
230 AutomationProviderHandler* handler, | 308 AutomationProviderHandler* handler, |
231 EventRegistrationToken* cookie) { | 309 EventRegistrationToken* cookie) { |
232 return S_OK; | 310 return S_OK; |
233 } | 311 } |
234 | 312 |
235 virtual HRESULT STDMETHODCALLTYPE remove_AutomationProviderRequested( | 313 virtual HRESULT STDMETHODCALLTYPE remove_AutomationProviderRequested( |
236 EventRegistrationToken cookie) { | 314 EventRegistrationToken cookie) { |
237 return S_OK; | 315 return S_OK; |
238 } | 316 } |
239 | 317 |
240 virtual HRESULT STDMETHODCALLTYPE add_CharacterReceived( | 318 virtual HRESULT STDMETHODCALLTYPE add_CharacterReceived( |
241 CharEventHandler* handler, | 319 CharEventHandler* handler, |
242 EventRegistrationToken* pCookie) { | 320 EventRegistrationToken* pCookie) { |
321 // TODO(cpu) : implement this. | |
243 return S_OK; | 322 return S_OK; |
244 } | 323 } |
245 | 324 |
246 virtual HRESULT STDMETHODCALLTYPE remove_CharacterReceived( | 325 virtual HRESULT STDMETHODCALLTYPE remove_CharacterReceived( |
247 EventRegistrationToken cookie) { | 326 EventRegistrationToken cookie) { |
248 return S_OK; | 327 return S_OK; |
249 } | 328 } |
250 | 329 |
251 virtual HRESULT STDMETHODCALLTYPE add_Closed( | 330 virtual HRESULT STDMETHODCALLTYPE add_Closed( |
252 CoreWindowEventHandler* handler, | 331 CoreWindowEventHandler* handler, |
(...skipping 13 matching lines...) Expand all Loading... | |
266 } | 345 } |
267 | 346 |
268 virtual HRESULT STDMETHODCALLTYPE remove_InputEnabled( | 347 virtual HRESULT STDMETHODCALLTYPE remove_InputEnabled( |
269 EventRegistrationToken cookie) { | 348 EventRegistrationToken cookie) { |
270 return S_OK; | 349 return S_OK; |
271 } | 350 } |
272 | 351 |
273 virtual HRESULT STDMETHODCALLTYPE add_KeyDown( | 352 virtual HRESULT STDMETHODCALLTYPE add_KeyDown( |
274 KeyEventHandler* handler, | 353 KeyEventHandler* handler, |
275 EventRegistrationToken* pCookie) { | 354 EventRegistrationToken* pCookie) { |
355 // TODO(cpu): implement this. | |
276 return S_OK; | 356 return S_OK; |
277 } | 357 } |
278 | 358 |
279 virtual HRESULT STDMETHODCALLTYPE remove_KeyDown( | 359 virtual HRESULT STDMETHODCALLTYPE remove_KeyDown( |
280 EventRegistrationToken cookie) { | 360 EventRegistrationToken cookie) { |
281 return S_OK; | 361 return S_OK; |
282 } | 362 } |
283 | 363 |
284 virtual HRESULT STDMETHODCALLTYPE add_KeyUp( | 364 virtual HRESULT STDMETHODCALLTYPE add_KeyUp( |
285 KeyEventHandler* handler, | 365 KeyEventHandler* handler, |
286 EventRegistrationToken* pCookie) { | 366 EventRegistrationToken* pCookie) { |
367 // TODO(cpu): implement this. | |
287 return S_OK; | 368 return S_OK; |
288 } | 369 } |
289 | 370 |
290 virtual HRESULT STDMETHODCALLTYPE remove_KeyUp( | 371 virtual HRESULT STDMETHODCALLTYPE remove_KeyUp( |
291 EventRegistrationToken cookie) { | 372 EventRegistrationToken cookie) { |
292 return S_OK; | 373 return S_OK; |
293 } | 374 } |
294 | 375 |
295 virtual HRESULT STDMETHODCALLTYPE add_PointerCaptureLost( | 376 virtual HRESULT STDMETHODCALLTYPE add_PointerCaptureLost( |
296 PointerEventHandler* handler, | 377 PointerEventHandler* handler, |
(...skipping 24 matching lines...) Expand all Loading... | |
321 } | 402 } |
322 | 403 |
323 virtual HRESULT STDMETHODCALLTYPE remove_PointerExited( | 404 virtual HRESULT STDMETHODCALLTYPE remove_PointerExited( |
324 EventRegistrationToken cookie) { | 405 EventRegistrationToken cookie) { |
325 return S_OK; | 406 return S_OK; |
326 } | 407 } |
327 | 408 |
328 virtual HRESULT STDMETHODCALLTYPE add_PointerMoved( | 409 virtual HRESULT STDMETHODCALLTYPE add_PointerMoved( |
329 PointerEventHandler* handler, | 410 PointerEventHandler* handler, |
330 EventRegistrationToken* cookie) { | 411 EventRegistrationToken* cookie) { |
412 // TODO(cpu) : implement this. | |
331 return S_OK; | 413 return S_OK; |
332 } | 414 } |
333 | 415 |
334 virtual HRESULT STDMETHODCALLTYPE remove_PointerMoved( | 416 virtual HRESULT STDMETHODCALLTYPE remove_PointerMoved( |
335 EventRegistrationToken cookie) { | 417 EventRegistrationToken cookie) { |
336 return S_OK; | 418 return S_OK; |
337 } | 419 } |
338 | 420 |
339 virtual HRESULT STDMETHODCALLTYPE add_PointerPressed( | 421 virtual HRESULT STDMETHODCALLTYPE add_PointerPressed( |
340 PointerEventHandler* handler, | 422 PointerEventHandler* handler, |
341 EventRegistrationToken* cookie) { | 423 EventRegistrationToken* cookie) { |
424 // TODO(cpu): implement this. | |
342 return S_OK; | 425 return S_OK; |
343 } | 426 } |
344 | 427 |
345 virtual HRESULT STDMETHODCALLTYPE remove_PointerPressed( | 428 virtual HRESULT STDMETHODCALLTYPE remove_PointerPressed( |
346 EventRegistrationToken cookie) { | 429 EventRegistrationToken cookie) { |
347 return S_OK; | 430 return S_OK; |
348 } | 431 } |
349 | 432 |
350 virtual HRESULT STDMETHODCALLTYPE add_PointerReleased( | 433 virtual HRESULT STDMETHODCALLTYPE add_PointerReleased( |
351 PointerEventHandler* handler, | 434 PointerEventHandler* handler, |
352 EventRegistrationToken* cookie) { | 435 EventRegistrationToken* cookie) { |
436 // TODO(cpu): implement this. | |
353 return S_OK; | 437 return S_OK; |
354 } | 438 } |
355 | 439 |
356 virtual HRESULT STDMETHODCALLTYPE remove_PointerReleased( | 440 virtual HRESULT STDMETHODCALLTYPE remove_PointerReleased( |
357 EventRegistrationToken cookie) { | 441 EventRegistrationToken cookie) { |
358 return S_OK; | 442 return S_OK; |
359 } | 443 } |
360 | 444 |
361 virtual HRESULT STDMETHODCALLTYPE add_TouchHitTesting( | 445 virtual HRESULT STDMETHODCALLTYPE add_TouchHitTesting( |
362 TouchHitTestHandler* handler, | 446 TouchHitTestHandler* handler, |
(...skipping 13 matching lines...) Expand all Loading... | |
376 } | 460 } |
377 | 461 |
378 virtual HRESULT STDMETHODCALLTYPE remove_PointerWheelChanged( | 462 virtual HRESULT STDMETHODCALLTYPE remove_PointerWheelChanged( |
379 EventRegistrationToken cookie) { | 463 EventRegistrationToken cookie) { |
380 return S_OK; | 464 return S_OK; |
381 } | 465 } |
382 | 466 |
383 virtual HRESULT STDMETHODCALLTYPE add_SizeChanged( | 467 virtual HRESULT STDMETHODCALLTYPE add_SizeChanged( |
384 SizeChangedHandler* handler, | 468 SizeChangedHandler* handler, |
385 EventRegistrationToken* pCookie) { | 469 EventRegistrationToken* pCookie) { |
470 // TODO(cpu): implement this. | |
386 return S_OK; | 471 return S_OK; |
387 } | 472 } |
388 | 473 |
389 virtual HRESULT STDMETHODCALLTYPE remove_SizeChanged( | 474 virtual HRESULT STDMETHODCALLTYPE remove_SizeChanged( |
390 EventRegistrationToken cookie) { | 475 EventRegistrationToken cookie) { |
391 return S_OK; | 476 return S_OK; |
392 } | 477 } |
393 | 478 |
394 virtual HRESULT STDMETHODCALLTYPE add_VisibilityChanged( | 479 virtual HRESULT STDMETHODCALLTYPE add_VisibilityChanged( |
395 VisibilityChangedHandler* handler, | 480 VisibilityChangedHandler* handler, |
396 EventRegistrationToken* pCookie) { | 481 EventRegistrationToken* pCookie) { |
397 return S_OK; | 482 return S_OK; |
398 } | 483 } |
399 | 484 |
400 virtual HRESULT STDMETHODCALLTYPE remove_VisibilityChanged( | 485 virtual HRESULT STDMETHODCALLTYPE remove_VisibilityChanged( |
401 EventRegistrationToken cookie) { | 486 EventRegistrationToken cookie) { |
402 return S_OK; | 487 return S_OK; |
403 } | 488 } |
404 | 489 |
405 // ICoreWindowInterop implementation: | 490 // ICoreWindowInterop implementation: |
406 virtual HRESULT STDMETHODCALLTYPE get_WindowHandle( | 491 virtual HRESULT STDMETHODCALLTYPE get_WindowHandle(HWND* hwnd) { |
407 HWND *hwnd) { | 492 if (!core_hwnd_) |
493 return E_FAIL; | |
494 *hwnd = core_hwnd_; | |
408 return S_OK; | 495 return S_OK; |
409 } | 496 } |
410 | 497 |
411 virtual HRESULT STDMETHODCALLTYPE put_MessageHandled( | 498 virtual HRESULT STDMETHODCALLTYPE put_MessageHandled( |
412 boolean value) { | 499 boolean value) { |
413 return S_OK; | 500 return S_OK; |
414 } | 501 } |
415 | 502 |
503 private: | |
504 HWND core_hwnd_; | |
505 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher_; | |
506 }; | |
507 | |
508 class ActivatedEvent | |
509 : public mswr::RuntimeClass<winapp::Activation::IActivatedEventArgs> { | |
510 public: | |
511 ActivatedEvent(winapp::Activation::ActivationKind activation_kind) | |
512 : activation_kind_(activation_kind) { | |
513 } | |
514 | |
515 virtual HRESULT STDMETHODCALLTYPE get_Kind( | |
516 winapp::Activation::ActivationKind *value) { | |
517 *value = activation_kind_; | |
518 return S_OK; | |
519 } | |
520 | |
521 virtual HRESULT STDMETHODCALLTYPE get_PreviousExecutionState( | |
522 winapp::Activation::ApplicationExecutionState *value) { | |
523 *value = winapp::Activation::ApplicationExecutionState_ClosedByUser; | |
524 return S_OK; | |
525 } | |
526 | |
527 virtual HRESULT STDMETHODCALLTYPE get_SplashScreen( | |
528 winapp::Activation::ISplashScreen **value) { | |
529 return E_FAIL; | |
530 } | |
531 | |
532 private: | |
533 winapp::Activation::ActivationKind activation_kind_; | |
416 }; | 534 }; |
417 | 535 |
418 class CoreApplicationViewEmulation | 536 class CoreApplicationViewEmulation |
419 : public mswr::RuntimeClass<winapp::Core::ICoreApplicationView> { | 537 : public mswr::RuntimeClass<winapp::Core::ICoreApplicationView> { |
420 public: | 538 public: |
421 CoreApplicationViewEmulation() { | 539 CoreApplicationViewEmulation() { |
422 core_window_ = mswr::Make<CoreWindowEmulation>(); | 540 core_window_ = mswr::Make<CoreWindowEmulation>(); |
423 } | 541 } |
424 | 542 |
425 virtual HRESULT STDMETHODCALLTYPE get_CoreWindow( | 543 HRESULT Activate() { |
426 winui::Core::ICoreWindow **value) { | 544 if (activated_handler_) { |
427 if (!core_window_) | 545 auto ae = mswr::Make<ActivatedEvent>( |
428 return E_FAIL; | 546 winapp::Activation::ActivationKind_File); |
429 *value = core_window_.Get(); | 547 return activated_handler_->Invoke(this, ae.Get()); |
cpu_(ooo_6.6-7.5)
2014/03/26 19:22:53
this .Get() here was a bug, you need to up the ref
| |
430 return S_OK; | 548 } else { |
431 } | 549 return S_OK; |
550 } | |
551 } | |
552 | |
553 // ICoreApplicationView implementation: | |
554 virtual HRESULT STDMETHODCALLTYPE get_CoreWindow( | |
555 winui::Core::ICoreWindow** value) { | |
556 if (!core_window_) | |
557 return E_FAIL; | |
558 return core_window_.CopyTo(value); | |
559 } | |
432 | 560 |
433 virtual HRESULT STDMETHODCALLTYPE add_Activated( | 561 virtual HRESULT STDMETHODCALLTYPE add_Activated( |
434 ActivatedHandler* handler, | 562 ActivatedHandler* handler, |
435 EventRegistrationToken* token) { | 563 EventRegistrationToken* token) { |
564 // The real component supports multiple handles but we don't yet. | |
565 if (activated_handler_) | |
566 return E_FAIL; | |
567 activated_handler_ = handler; | |
436 return S_OK; | 568 return S_OK; |
437 } | 569 } |
438 | 570 |
439 virtual HRESULT STDMETHODCALLTYPE remove_Activated( | 571 virtual HRESULT STDMETHODCALLTYPE remove_Activated( |
440 EventRegistrationToken token) { | 572 EventRegistrationToken token) { |
573 // Chrome never unregisters handlers, so we don't care about it. | |
441 return S_OK; | 574 return S_OK; |
442 } | 575 } |
443 | 576 |
444 virtual HRESULT STDMETHODCALLTYPE get_IsMain( | 577 virtual HRESULT STDMETHODCALLTYPE get_IsMain( |
445 boolean* value) { | 578 boolean* value) { |
446 return S_OK; | 579 return S_OK; |
447 } | 580 } |
448 | 581 |
449 virtual HRESULT STDMETHODCALLTYPE get_IsHosted( | 582 virtual HRESULT STDMETHODCALLTYPE get_IsHosted( |
450 boolean* value) { | 583 boolean* value) { |
451 return S_OK; | 584 return S_OK; |
452 } | 585 } |
453 | 586 |
454 private: | 587 private: |
455 mswr::ComPtr<winui::Core::ICoreWindow> core_window_; | 588 mswr::ComPtr<winui::Core::ICoreWindow> core_window_; |
589 mswr::ComPtr<ActivatedHandler> activated_handler_; | |
456 }; | 590 }; |
457 | 591 |
458 class CoreApplicationWin7Emulation | 592 class CoreApplicationWin7Emulation |
459 : public mswr::RuntimeClass<winapp::Core::ICoreApplication, | 593 : public mswr::RuntimeClass<winapp::Core::ICoreApplication, |
460 winapp::Core::ICoreApplicationExit> { | 594 winapp::Core::ICoreApplicationExit> { |
461 public: | 595 public: |
462 // ICoreApplication implementation: | 596 // ICoreApplication implementation: |
463 | 597 |
464 virtual HRESULT STDMETHODCALLTYPE get_Id( | 598 virtual HRESULT STDMETHODCALLTYPE get_Id( |
465 HSTRING* value) { | 599 HSTRING* value) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 return hr; | 639 return hr; |
506 view_emulation_ = mswr::Make<CoreApplicationViewEmulation>(); | 640 view_emulation_ = mswr::Make<CoreApplicationViewEmulation>(); |
507 hr = app_view_->Initialize(view_emulation_.Get()); | 641 hr = app_view_->Initialize(view_emulation_.Get()); |
508 if (FAILED(hr)) | 642 if (FAILED(hr)) |
509 return hr; | 643 return hr; |
510 mswr::ComPtr<winui::Core::ICoreWindow> core_window; | 644 mswr::ComPtr<winui::Core::ICoreWindow> core_window; |
511 hr = view_emulation_->get_CoreWindow(core_window.GetAddressOf()); | 645 hr = view_emulation_->get_CoreWindow(core_window.GetAddressOf()); |
512 if (FAILED(hr)) | 646 if (FAILED(hr)) |
513 return hr; | 647 return hr; |
514 hr = app_view_->SetWindow(core_window.Get()); | 648 hr = app_view_->SetWindow(core_window.Get()); |
515 return hr; | 649 if (FAILED(hr)) |
650 return hr; | |
651 hr = app_view_->Load(NULL); | |
652 if (FAILED(hr)) | |
653 return hr; | |
654 hr = view_emulation_->Activate(); | |
655 if (FAILED(hr)) | |
656 return hr; | |
657 return app_view_->Run(); | |
516 } | 658 } |
517 | 659 |
518 virtual HRESULT STDMETHODCALLTYPE RunWithActivationFactories( | 660 virtual HRESULT STDMETHODCALLTYPE RunWithActivationFactories( |
519 winfoundtn::IGetActivationFactory* activationFactoryCallback) { | 661 winfoundtn::IGetActivationFactory* activationFactoryCallback) { |
520 return S_OK; | 662 return S_OK; |
521 } | 663 } |
522 | 664 |
523 // ICoreApplicationExit implementation: | 665 // ICoreApplicationExit implementation: |
524 | 666 |
525 virtual HRESULT STDMETHODCALLTYPE Exit(void) { | 667 virtual HRESULT STDMETHODCALLTYPE Exit(void) { |
526 return S_OK; | 668 return S_OK; |
527 } | 669 } |
528 | 670 |
529 virtual HRESULT STDMETHODCALLTYPE add_Exiting( | 671 virtual HRESULT STDMETHODCALLTYPE add_Exiting( |
530 winfoundtn::IEventHandler<IInspectable*>* handler, | 672 winfoundtn::IEventHandler<IInspectable*>* handler, |
531 EventRegistrationToken* token) { | 673 EventRegistrationToken* token) { |
532 return S_OK; | 674 return S_OK; |
533 } | 675 } |
534 | 676 |
535 virtual HRESULT STDMETHODCALLTYPE remove_Exiting( | 677 virtual HRESULT STDMETHODCALLTYPE remove_Exiting( |
536 EventRegistrationToken token) { | 678 EventRegistrationToken token) { |
537 return S_OK; | 679 return S_OK; |
538 } | 680 } |
539 | 681 |
540 private: | 682 private: |
541 mswr::ComPtr<winapp::Core::IFrameworkView> app_view_; | 683 mswr::ComPtr<winapp::Core::IFrameworkView> app_view_; |
542 mswr::ComPtr<winapp::Core::ICoreApplicationView> view_emulation_; | 684 mswr::ComPtr<CoreApplicationViewEmulation> view_emulation_; |
543 }; | 685 }; |
544 | 686 |
545 | 687 |
546 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { | 688 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { |
547 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); | 689 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); |
548 if (FAILED(hr)) | 690 if (FAILED(hr)) |
549 CHECK(false); | 691 CHECK(false); |
550 return mswr::Make<CoreApplicationWin7Emulation>(); | 692 return mswr::Make<CoreApplicationWin7Emulation>(); |
551 } | 693 } |
552 | 694 |
OLD | NEW |