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 "win8/metro_driver/stdafx.h" | 5 #include "win8/metro_driver/stdafx.h" |
6 #include "win8/metro_driver/chrome_app_view_ash.h" | 6 #include "win8/metro_driver/chrome_app_view_ash.h" |
7 | 7 |
8 #include <corewindow.h> | 8 #include <corewindow.h> |
9 #include <windows.foundation.h> | 9 #include <windows.foundation.h> |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 winui::Core::CharacterReceivedEventArgs*> CharEventHandler; | 47 winui::Core::CharacterReceivedEventArgs*> CharEventHandler; |
48 | 48 |
49 typedef winfoundtn::ITypedEventHandler< | 49 typedef winfoundtn::ITypedEventHandler< |
50 winui::Core::CoreWindow*, | 50 winui::Core::CoreWindow*, |
51 winui::Core::VisibilityChangedEventArgs*> VisibilityChangedHandler; | 51 winui::Core::VisibilityChangedEventArgs*> VisibilityChangedHandler; |
52 | 52 |
53 typedef winfoundtn::ITypedEventHandler< | 53 typedef winfoundtn::ITypedEventHandler< |
54 winui::Core::CoreWindow*, | 54 winui::Core::CoreWindow*, |
55 winui::Core::WindowActivatedEventArgs*> WindowActivatedHandler; | 55 winui::Core::WindowActivatedEventArgs*> WindowActivatedHandler; |
56 | 56 |
57 typedef winfoundtn::ITypedEventHandler< | |
58 winui::Core::CoreWindow*, | |
59 winui::Core::WindowSizeChangedEventArgs*> SizeChangedHandler; | |
60 | |
57 // This function is exported by chrome.exe. | 61 // This function is exported by chrome.exe. |
58 typedef int (__cdecl *BreakpadExceptionHandler)(EXCEPTION_POINTERS* info); | 62 typedef int (__cdecl *BreakpadExceptionHandler)(EXCEPTION_POINTERS* info); |
59 | 63 |
60 // Global information used across the metro driver. | 64 // Global information used across the metro driver. |
61 struct Globals { | 65 struct Globals { |
62 winapp::Activation::ApplicationExecutionState previous_state; | 66 winapp::Activation::ApplicationExecutionState previous_state; |
63 winapp::Core::ICoreApplicationExit* app_exit; | 67 winapp::Core::ICoreApplicationExit* app_exit; |
64 BreakpadExceptionHandler breakpad_exception_handler; | 68 BreakpadExceptionHandler breakpad_exception_handler; |
65 } globals; | 69 } globals; |
66 | 70 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 window_ = window; | 314 window_ = window; |
311 DVLOG(1) << __FUNCTION__; | 315 DVLOG(1) << __FUNCTION__; |
312 | 316 |
313 // Retrieve the native window handle via the interop layer. | 317 // Retrieve the native window handle via the interop layer. |
314 mswr::ComPtr<ICoreWindowInterop> interop; | 318 mswr::ComPtr<ICoreWindowInterop> interop; |
315 HRESULT hr = window->QueryInterface(interop.GetAddressOf()); | 319 HRESULT hr = window->QueryInterface(interop.GetAddressOf()); |
316 CheckHR(hr); | 320 CheckHR(hr); |
317 hr = interop->get_WindowHandle(&core_window_hwnd_); | 321 hr = interop->get_WindowHandle(&core_window_hwnd_); |
318 CheckHR(hr); | 322 CheckHR(hr); |
319 | 323 |
324 hr = window_->add_SizeChanged(mswr::Callback<SizeChangedHandler>( | |
325 this, &ChromeAppViewAsh::OnSizeChanged).Get(), | |
326 &sizechange_token_); | |
327 CheckHR(hr); | |
328 | |
320 // Register for pointer and keyboard notifications. We forward | 329 // Register for pointer and keyboard notifications. We forward |
321 // them to the browser process via IPC. | 330 // them to the browser process via IPC. |
322 hr = window_->add_PointerMoved(mswr::Callback<PointerEventHandler>( | 331 hr = window_->add_PointerMoved(mswr::Callback<PointerEventHandler>( |
323 this, &ChromeAppViewAsh::OnPointerMoved).Get(), | 332 this, &ChromeAppViewAsh::OnPointerMoved).Get(), |
324 &pointermoved_token_); | 333 &pointermoved_token_); |
325 CheckHR(hr); | 334 CheckHR(hr); |
326 | 335 |
327 hr = window_->add_PointerPressed(mswr::Callback<PointerEventHandler>( | 336 hr = window_->add_PointerPressed(mswr::Callback<PointerEventHandler>( |
328 this, &ChromeAppViewAsh::OnPointerPressed).Get(), | 337 this, &ChromeAppViewAsh::OnPointerPressed).Get(), |
329 &pointerpressed_token_); | 338 &pointerpressed_token_); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 &ui_channel_listener, | 441 &ui_channel_listener, |
433 io_thread.message_loop_proxy()); | 442 io_thread.message_loop_proxy()); |
434 ui_channel_ = &ui_channel; | 443 ui_channel_ = &ui_channel; |
435 | 444 |
436 // Upon receipt of the MetroViewerHostMsg_SetTargetSurface message the | 445 // Upon receipt of the MetroViewerHostMsg_SetTargetSurface message the |
437 // browser will use D3D from the browser process to present to our Window. | 446 // browser will use D3D from the browser process to present to our Window. |
438 ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface( | 447 ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface( |
439 gfx::NativeViewId(core_window_hwnd_))); | 448 gfx::NativeViewId(core_window_hwnd_))); |
440 DVLOG(1) << "ICoreWindow sent " << core_window_hwnd_; | 449 DVLOG(1) << "ICoreWindow sent " << core_window_hwnd_; |
441 | 450 |
451 // Send an initial size message so that the Ash root window host gets sized | |
452 // correctly. | |
453 RECT rect = {0}; | |
454 ::GetWindowRect(core_window_hwnd_, &rect); | |
455 ui_channel_->Send( | |
456 new MetroViewerHostMsg_WindowSizeChanged(rect.right - rect.left, | |
457 rect.bottom - rect.top)); | |
458 | |
442 // And post the task that'll do the inner Metro message pumping to it. | 459 // And post the task that'll do the inner Metro message pumping to it. |
443 msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); | 460 msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); |
444 msg_loop.Run(); | 461 msg_loop.Run(); |
445 | 462 |
446 DVLOG(0) << "ProcessEvents done, hr=" << hr; | 463 DVLOG(0) << "ProcessEvents done, hr=" << hr; |
447 return hr; | 464 return hr; |
448 } | 465 } |
449 | 466 |
450 IFACEMETHODIMP | 467 IFACEMETHODIMP |
451 ChromeAppViewAsh::Uninitialize() { | 468 ChromeAppViewAsh::Uninitialize() { |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 winui::Core::CoreWindowActivationState state; | 818 winui::Core::CoreWindowActivationState state; |
802 HRESULT hr = args->get_WindowActivationState(&state); | 819 HRESULT hr = args->get_WindowActivationState(&state); |
803 if (FAILED(hr)) | 820 if (FAILED(hr)) |
804 return hr; | 821 return hr; |
805 DVLOG(1) << "Window activation state: " << state; | 822 DVLOG(1) << "Window activation state: " << state; |
806 ui_channel_->Send(new MetroViewerHostMsg_WindowActivated( | 823 ui_channel_->Send(new MetroViewerHostMsg_WindowActivated( |
807 state != winui::Core::CoreWindowActivationState_Deactivated)); | 824 state != winui::Core::CoreWindowActivationState_Deactivated)); |
808 return S_OK; | 825 return S_OK; |
809 } | 826 } |
810 | 827 |
828 HRESULT ChromeAppViewAsh::OnSizeChanged(winui::Core::ICoreWindow* sender, | |
829 winui::Core::IWindowSizeChangedEventArgs* args) { | |
830 if (!window_) { | |
831 return S_OK; | |
832 } | |
833 | |
834 winfoundtn::Size size; | |
835 args->get_Size(&size); | |
cpu_(ooo_6.6-7.5)
2013/05/21 20:36:12
check the error code of get_Size. I guess don't se
robertshield
2013/05/22 17:31:20
Done.
| |
836 | |
837 int32 cx = static_cast<int32>(size.Width); | |
838 int32 cy = static_cast<int32>(size.Height); | |
839 | |
840 DVLOG(1) << "Window size changed: width=" << cx << ", height=" << cy; | |
841 ui_channel_->Send(new MetroViewerHostMsg_WindowSizeChanged(cx, cy)); | |
842 return S_OK; | |
843 } | |
844 | |
811 | 845 |
812 /////////////////////////////////////////////////////////////////////////////// | 846 /////////////////////////////////////////////////////////////////////////////// |
813 | 847 |
814 ChromeAppViewFactory::ChromeAppViewFactory( | 848 ChromeAppViewFactory::ChromeAppViewFactory( |
815 winapp::Core::ICoreApplication* icore_app, | 849 winapp::Core::ICoreApplication* icore_app, |
816 LPTHREAD_START_ROUTINE host_main, | 850 LPTHREAD_START_ROUTINE host_main, |
817 void* host_context) { | 851 void* host_context) { |
818 mswr::ComPtr<winapp::Core::ICoreApplication> core_app(icore_app); | 852 mswr::ComPtr<winapp::Core::ICoreApplication> core_app(icore_app); |
819 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; | 853 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; |
820 CheckHR(core_app.As(&app_exit)); | 854 CheckHR(core_app.As(&app_exit)); |
821 globals.app_exit = app_exit.Detach(); | 855 globals.app_exit = app_exit.Detach(); |
822 } | 856 } |
823 | 857 |
824 IFACEMETHODIMP | 858 IFACEMETHODIMP |
825 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { | 859 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { |
826 *view = mswr::Make<ChromeAppViewAsh>().Detach(); | 860 *view = mswr::Make<ChromeAppViewAsh>().Detach(); |
827 return (*view) ? S_OK : E_OUTOFMEMORY; | 861 return (*view) ? S_OK : E_OUTOFMEMORY; |
828 } | 862 } |
OLD | NEW |