Chromium Code Reviews| 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 #include <shobjidl.h> | 7 #include <shobjidl.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/gfx/geometry/safe_integer_conversions.h" | 10 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 11 #include "ui/gfx/win/msg_util.h" | 11 #include "ui/gfx/win/msg_util.h" |
| 12 | 12 |
| 13 #pragma comment(lib, "shell32.lib") | 13 #pragma comment(lib, "shell32.lib") |
| 14 | 14 |
| 15 EXTERN_C IMAGE_DOS_HEADER __ImageBase; | 15 EXTERN_C IMAGE_DOS_HEADER __ImageBase; |
| 16 // Even though we only create a single window, we need to keep this | 16 // Even though we only create a single window, we need to keep this |
| 17 // count because of the hidden window used by the UI message loop of | 17 // count because of the hidden window used by the UI message loop of |
| 18 // the metro viewer. | 18 // the metro viewer. |
| 19 int g_window_count = 0; | 19 int g_window_count = 0; |
| 20 | 20 |
| 21 const wchar_t kAshWin7AppId[] = L"Google.Chrome.AshWin7.1"; | 21 const wchar_t kAshWin7AppId[] = L"Google.Chrome.AshWin7.1"; |
| 22 | 22 const wchar_t kAshWin7CoreWindowHandler[] = L"CoreWindowHandler"; |
| 23 extern float GetModernUIScale(); | 23 extern float GetModernUIScale(); |
| 24 | 24 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, |
| 25 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, | 25 LPARAM lparam); |
| 26 WPARAM wparam, LPARAM lparam) { | |
| 27 PAINTSTRUCT ps; | |
| 28 HDC hdc; | |
| 29 switch (message) { | |
| 30 case WM_CREATE: | |
| 31 ++g_window_count; | |
| 32 break; | |
| 33 case WM_PAINT: | |
| 34 hdc = ::BeginPaint(hwnd, &ps); | |
| 35 ::EndPaint(hwnd, &ps); | |
| 36 break; | |
| 37 case WM_CLOSE: | |
| 38 ::DestroyWindow(hwnd); | |
| 39 break; | |
| 40 case WM_DESTROY: | |
| 41 --g_window_count; | |
| 42 if (!g_window_count) | |
| 43 ::PostQuitMessage(0); | |
| 44 break; | |
| 45 // Always allow Chrome to set the cursor. | |
| 46 case WM_SETCURSOR: | |
| 47 return 1; | |
| 48 default: | |
| 49 return ::DefWindowProc(hwnd, message, wparam, lparam); | |
| 50 } | |
| 51 return 0; | |
| 52 } | |
| 53 | 26 |
| 54 HWND CreateMetroTopLevelWindow(const RECT& work_area) { | 27 HWND CreateMetroTopLevelWindow(const RECT& work_area) { |
| 55 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase); | 28 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase); |
| 56 WNDCLASSEXW wcex; | 29 WNDCLASSEXW wcex; |
| 57 wcex.cbSize = sizeof(wcex); | 30 wcex.cbSize = sizeof(wcex); |
| 58 wcex.style = CS_HREDRAW | CS_VREDRAW; | 31 wcex.style = CS_HREDRAW | CS_VREDRAW; |
| 59 wcex.lpfnWndProc = WndProc; | 32 wcex.lpfnWndProc = WndProc; |
| 60 wcex.cbClsExtra = 0; | 33 wcex.cbClsExtra = 0; |
| 61 wcex.cbWndExtra = 0; | 34 wcex.cbWndExtra = 0; |
| 62 wcex.hInstance = hInst; | 35 wcex.hInstance = hInst; |
| 63 wcex.hIcon = LoadIcon(::GetModuleHandle(NULL), L"IDR_MAINFRAME"); | 36 wcex.hIcon = LoadIcon(::GetModuleHandle(NULL), L"IDR_MAINFRAME"); |
| 64 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); | 37 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 65 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1); | 38 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1); |
| 66 wcex.lpszMenuName = 0; | 39 wcex.lpszMenuName = 0; |
| 67 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow"; | 40 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow"; |
| 68 wcex.hIconSm = LoadIcon(::GetModuleHandle(NULL), L"IDR_MAINFRAME"); | 41 wcex.hIconSm = LoadIcon(::GetModuleHandle(NULL), L"IDR_MAINFRAME"); |
| 69 | 42 |
| 70 | |
| 71 | |
| 72 HWND hwnd = ::CreateWindowExW(0, | 43 HWND hwnd = ::CreateWindowExW(0, |
| 73 MAKEINTATOM(::RegisterClassExW(&wcex)), | 44 MAKEINTATOM(::RegisterClassExW(&wcex)), |
| 74 L"metro_win7", | 45 L"metro_win7", |
| 75 WS_POPUP | WS_VISIBLE | WS_MINIMIZEBOX, | 46 WS_POPUP | WS_VISIBLE | WS_MINIMIZEBOX, |
| 76 work_area.top, work_area.left, | 47 work_area.top, work_area.left, |
| 77 work_area.right, work_area.bottom, | 48 work_area.right, work_area.bottom, |
| 78 NULL, NULL, hInst, NULL); | 49 NULL, NULL, hInst, NULL); |
| 79 return hwnd; | 50 return hwnd; |
| 80 } | 51 } |
| 81 | 52 |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 InputHandler* input_handler_; | 528 InputHandler* input_handler_; |
| 558 AcceleratorKeyEventHandler* accelerator_key_event_handler_; | 529 AcceleratorKeyEventHandler* accelerator_key_event_handler_; |
| 559 }; | 530 }; |
| 560 | 531 |
| 561 class CoreWindowEmulation | 532 class CoreWindowEmulation |
| 562 : public mswr::RuntimeClass< | 533 : public mswr::RuntimeClass< |
| 563 mswr::RuntimeClassFlags<mswr::WinRtClassicComMix>, | 534 mswr::RuntimeClassFlags<mswr::WinRtClassicComMix>, |
| 564 winui::Core::ICoreWindow, ICoreWindowInterop>, | 535 winui::Core::ICoreWindow, ICoreWindowInterop>, |
| 565 public InputHandler { | 536 public InputHandler { |
| 566 public: | 537 public: |
| 567 CoreWindowEmulation() | 538 CoreWindowEmulation(winapp::Core::IFrameworkView* app_view) |
| 568 : core_hwnd_(NULL), | 539 : core_hwnd_(NULL), |
| 569 mouse_moved_handler_(NULL), | 540 mouse_moved_handler_(NULL), |
| 570 mouse_capture_lost_handler_(NULL), | 541 mouse_capture_lost_handler_(NULL), |
| 571 mouse_pressed_handler_(NULL), | 542 mouse_pressed_handler_(NULL), |
| 572 mouse_released_handler_(NULL), | 543 mouse_released_handler_(NULL), |
| 573 mouse_entered_handler_(NULL), | 544 mouse_entered_handler_(NULL), |
| 574 mouse_exited_handler_(NULL), | 545 mouse_exited_handler_(NULL), |
| 575 mouse_wheel_changed_handler_(NULL), | 546 mouse_wheel_changed_handler_(NULL), |
| 576 key_down_handler_(NULL), | 547 key_down_handler_(NULL), |
| 577 key_up_handler_(NULL), | 548 key_up_handler_(NULL), |
| 578 character_received_handler_(NULL) { | 549 character_received_handler_(NULL), |
| 550 app_view_(app_view), | |
| 551 window_activated_handler_(NULL) { | |
| 579 dispatcher_ = mswr::Make<CoreDispatcherEmulation>(this); | 552 dispatcher_ = mswr::Make<CoreDispatcherEmulation>(this); |
| 580 | 553 |
| 581 // Unless we select our own AppUserModelID the shell might confuse us | 554 // Unless we select our own AppUserModelID the shell might confuse us |
| 582 // with the app launcher one and we get the wrong taskbar button and icon. | 555 // with the app launcher one and we get the wrong taskbar button and icon. |
| 583 ::SetCurrentProcessExplicitAppUserModelID(kAshWin7AppId); | 556 ::SetCurrentProcessExplicitAppUserModelID(kAshWin7AppId); |
| 584 | 557 |
| 585 RECT work_area = {0}; | 558 RECT work_area = {0}; |
| 586 ::SystemParametersInfo(SPI_GETWORKAREA, 0, &work_area, 0); | 559 ::SystemParametersInfo(SPI_GETWORKAREA, 0, &work_area, 0); |
| 587 if (::IsDebuggerPresent()) { | 560 if (::IsDebuggerPresent()) { |
| 588 work_area.top = 0; | 561 work_area.top = 0; |
| 589 work_area.left = 0; | 562 work_area.left = 0; |
| 590 work_area.right = 1600; | 563 work_area.right = 1600; |
| 591 work_area.bottom = 900; | 564 work_area.bottom = 900; |
| 592 } | 565 } |
| 593 | 566 |
| 594 core_hwnd_ = CreateMetroTopLevelWindow(work_area); | 567 core_hwnd_ = CreateMetroTopLevelWindow(work_area); |
| 568 ::SetProp(core_hwnd_, kAshWin7CoreWindowHandler, this); | |
| 595 } | 569 } |
| 596 | 570 |
| 597 ~CoreWindowEmulation() { | 571 ~CoreWindowEmulation() { |
| 598 if (core_hwnd_) | 572 app_view_ = NULL; |
| 573 if (core_hwnd_) { | |
| 574 ::RemoveProp(core_hwnd_, kAshWin7CoreWindowHandler); | |
| 599 ::DestroyWindow(core_hwnd_); | 575 ::DestroyWindow(core_hwnd_); |
| 576 } | |
| 600 } | 577 } |
| 601 | 578 |
| 602 // ICoreWindow implementation: | 579 // ICoreWindow implementation: |
| 603 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( | 580 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( |
| 604 IInspectable** value) { | 581 IInspectable** value) { |
| 605 return S_OK; | 582 return S_OK; |
| 606 } | 583 } |
| 607 | 584 |
| 608 virtual HRESULT STDMETHODCALLTYPE get_Bounds( | 585 virtual HRESULT STDMETHODCALLTYPE get_Bounds( |
| 609 winfoundtn::Rect* value) { | 586 winfoundtn::Rect* value) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 return S_OK; | 669 return S_OK; |
| 693 } | 670 } |
| 694 | 671 |
| 695 virtual HRESULT STDMETHODCALLTYPE SetPointerCapture(void) { | 672 virtual HRESULT STDMETHODCALLTYPE SetPointerCapture(void) { |
| 696 return S_OK; | 673 return S_OK; |
| 697 } | 674 } |
| 698 | 675 |
| 699 virtual HRESULT STDMETHODCALLTYPE add_Activated( | 676 virtual HRESULT STDMETHODCALLTYPE add_Activated( |
| 700 WindowActivatedHandler* handler, | 677 WindowActivatedHandler* handler, |
| 701 EventRegistrationToken* pCookie) { | 678 EventRegistrationToken* pCookie) { |
| 702 // TODO(cpu) implement this. | 679 window_activated_handler_ = handler; |
| 680 handler->AddRef(); | |
| 703 return S_OK; | 681 return S_OK; |
| 704 } | 682 } |
| 705 | 683 |
| 706 virtual HRESULT STDMETHODCALLTYPE remove_Activated( | 684 virtual HRESULT STDMETHODCALLTYPE remove_Activated( |
| 707 EventRegistrationToken cookie) { | 685 EventRegistrationToken cookie) { |
| 686 window_activated_handler_->Release(); | |
| 687 window_activated_handler_ = NULL; | |
| 708 return S_OK; | 688 return S_OK; |
| 709 } | 689 } |
| 710 | 690 |
| 711 virtual HRESULT STDMETHODCALLTYPE add_AutomationProviderRequested( | 691 virtual HRESULT STDMETHODCALLTYPE add_AutomationProviderRequested( |
| 712 AutomationProviderHandler* handler, | 692 AutomationProviderHandler* handler, |
| 713 EventRegistrationToken* cookie) { | 693 EventRegistrationToken* cookie) { |
| 714 return S_OK; | 694 return S_OK; |
| 715 } | 695 } |
| 716 | 696 |
| 717 virtual HRESULT STDMETHODCALLTYPE remove_AutomationProviderRequested( | 697 virtual HRESULT STDMETHODCALLTYPE remove_AutomationProviderRequested( |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 994 } | 974 } |
| 995 | 975 |
| 996 default: | 976 default: |
| 997 return false; | 977 return false; |
| 998 } | 978 } |
| 999 DCHECK(handler); | 979 DCHECK(handler); |
| 1000 handler->Invoke(this, event_args.Get()); | 980 handler->Invoke(this, event_args.Get()); |
| 1001 return true; | 981 return true; |
| 1002 } | 982 } |
| 1003 | 983 |
| 984 void OnWindowActivated() { | |
| 985 if (window_activated_handler_) | |
| 986 window_activated_handler_->Invoke(this, NULL); | |
| 987 } | |
| 988 | |
| 1004 private: | 989 private: |
| 1005 PointerEventHandler* mouse_moved_handler_; | 990 PointerEventHandler* mouse_moved_handler_; |
| 1006 PointerEventHandler* mouse_capture_lost_handler_; | 991 PointerEventHandler* mouse_capture_lost_handler_; |
| 1007 PointerEventHandler* mouse_pressed_handler_; | 992 PointerEventHandler* mouse_pressed_handler_; |
| 1008 PointerEventHandler* mouse_released_handler_; | 993 PointerEventHandler* mouse_released_handler_; |
| 1009 PointerEventHandler* mouse_entered_handler_; | 994 PointerEventHandler* mouse_entered_handler_; |
| 1010 PointerEventHandler* mouse_exited_handler_; | 995 PointerEventHandler* mouse_exited_handler_; |
| 1011 PointerEventHandler* mouse_wheel_changed_handler_; | 996 PointerEventHandler* mouse_wheel_changed_handler_; |
| 1012 KeyEventHandler* key_down_handler_; | 997 KeyEventHandler* key_down_handler_; |
| 1013 KeyEventHandler* key_up_handler_; | 998 KeyEventHandler* key_up_handler_; |
| 1014 CharEventHandler* character_received_handler_; | 999 CharEventHandler* character_received_handler_; |
| 1015 HWND core_hwnd_; | 1000 HWND core_hwnd_; |
| 1016 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher_; | 1001 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher_; |
| 1002 winapp::Core::IFrameworkView* app_view_; | |
|
cpu_(ooo_6.6-7.5)
2014/09/04 19:13:21
CoreWindowEmulation is refcounted, it could outliv
ananta
2014/09/04 19:27:07
Made app_view a ComPtr.
| |
| 1003 WindowActivatedHandler* window_activated_handler_; | |
| 1017 }; | 1004 }; |
| 1018 | 1005 |
| 1006 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, | |
| 1007 WPARAM wparam, LPARAM lparam) { | |
| 1008 PAINTSTRUCT ps; | |
| 1009 HDC hdc; | |
| 1010 switch (message) { | |
| 1011 case WM_ACTIVATE: { | |
| 1012 // HIWORD(wparam) is 1 if the window is minimized. | |
| 1013 bool active = (LOWORD(wparam) != WA_INACTIVE) && !HIWORD(wparam); | |
| 1014 if (active) { | |
| 1015 CoreWindowEmulation* core_window_handler = | |
| 1016 reinterpret_cast<CoreWindowEmulation*>( | |
| 1017 ::GetProp(hwnd, kAshWin7CoreWindowHandler)); | |
| 1018 if (core_window_handler) | |
| 1019 core_window_handler->OnWindowActivated(); | |
| 1020 } | |
| 1021 return ::DefWindowProc(hwnd, message, wparam, lparam); | |
| 1022 } | |
| 1023 case WM_CREATE: | |
| 1024 ++g_window_count; | |
| 1025 break; | |
| 1026 case WM_PAINT: | |
| 1027 hdc = ::BeginPaint(hwnd, &ps); | |
| 1028 ::EndPaint(hwnd, &ps); | |
| 1029 break; | |
| 1030 case WM_CLOSE: | |
| 1031 ::DestroyWindow(hwnd); | |
| 1032 break; | |
| 1033 case WM_DESTROY: | |
| 1034 --g_window_count; | |
| 1035 if (!g_window_count) | |
| 1036 ::PostQuitMessage(0); | |
| 1037 break; | |
| 1038 // Always allow Chrome to set the cursor. | |
| 1039 case WM_SETCURSOR: | |
| 1040 return 1; | |
| 1041 default: | |
| 1042 return ::DefWindowProc(hwnd, message, wparam, lparam); | |
| 1043 } | |
| 1044 return 0; | |
| 1045 } | |
| 1046 | |
| 1019 class ActivatedEvent | 1047 class ActivatedEvent |
| 1020 : public mswr::RuntimeClass<winapp::Activation::IActivatedEventArgs> { | 1048 : public mswr::RuntimeClass<winapp::Activation::IActivatedEventArgs> { |
| 1021 public: | 1049 public: |
| 1022 ActivatedEvent(winapp::Activation::ActivationKind activation_kind) | 1050 ActivatedEvent(winapp::Activation::ActivationKind activation_kind) |
| 1023 : activation_kind_(activation_kind) { | 1051 : activation_kind_(activation_kind) { |
| 1024 } | 1052 } |
| 1025 | 1053 |
| 1026 virtual HRESULT STDMETHODCALLTYPE get_Kind( | 1054 virtual HRESULT STDMETHODCALLTYPE get_Kind( |
| 1027 winapp::Activation::ActivationKind *value) { | 1055 winapp::Activation::ActivationKind *value) { |
| 1028 *value = activation_kind_; | 1056 *value = activation_kind_; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1040 return E_FAIL; | 1068 return E_FAIL; |
| 1041 } | 1069 } |
| 1042 | 1070 |
| 1043 private: | 1071 private: |
| 1044 winapp::Activation::ActivationKind activation_kind_; | 1072 winapp::Activation::ActivationKind activation_kind_; |
| 1045 }; | 1073 }; |
| 1046 | 1074 |
| 1047 class CoreApplicationViewEmulation | 1075 class CoreApplicationViewEmulation |
| 1048 : public mswr::RuntimeClass<winapp::Core::ICoreApplicationView> { | 1076 : public mswr::RuntimeClass<winapp::Core::ICoreApplicationView> { |
| 1049 public: | 1077 public: |
| 1050 CoreApplicationViewEmulation() { | 1078 CoreApplicationViewEmulation(winapp::Core::IFrameworkView* app_view) { |
| 1051 core_window_ = mswr::Make<CoreWindowEmulation>(); | 1079 core_window_ = mswr::Make<CoreWindowEmulation>(app_view); |
| 1052 } | 1080 } |
| 1053 | 1081 |
| 1054 HRESULT Activate() { | 1082 HRESULT Activate() { |
| 1055 if (activated_handler_) { | 1083 if (activated_handler_) { |
| 1056 auto ae = mswr::Make<ActivatedEvent>( | 1084 auto ae = mswr::Make<ActivatedEvent>( |
| 1057 winapp::Activation::ActivationKind_File); | 1085 winapp::Activation::ActivationKind_File); |
| 1058 return activated_handler_->Invoke(this, ae.Get()); | 1086 return activated_handler_->Invoke(this, ae.Get()); |
| 1059 } else { | 1087 } else { |
| 1060 return S_OK; | 1088 return S_OK; |
| 1061 } | 1089 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1145 virtual HRESULT STDMETHODCALLTYPE GetCurrentView( | 1173 virtual HRESULT STDMETHODCALLTYPE GetCurrentView( |
| 1146 winapp::Core::ICoreApplicationView** value) { | 1174 winapp::Core::ICoreApplicationView** value) { |
| 1147 return S_OK; | 1175 return S_OK; |
| 1148 } | 1176 } |
| 1149 | 1177 |
| 1150 virtual HRESULT STDMETHODCALLTYPE Run( | 1178 virtual HRESULT STDMETHODCALLTYPE Run( |
| 1151 winapp::Core::IFrameworkViewSource* viewSource) { | 1179 winapp::Core::IFrameworkViewSource* viewSource) { |
| 1152 HRESULT hr = viewSource->CreateView(app_view_.GetAddressOf()); | 1180 HRESULT hr = viewSource->CreateView(app_view_.GetAddressOf()); |
| 1153 if (FAILED(hr)) | 1181 if (FAILED(hr)) |
| 1154 return hr; | 1182 return hr; |
| 1155 view_emulation_ = mswr::Make<CoreApplicationViewEmulation>(); | 1183 view_emulation_ = mswr::Make<CoreApplicationViewEmulation>( |
| 1184 app_view_.Get()); | |
| 1156 hr = app_view_->Initialize(view_emulation_.Get()); | 1185 hr = app_view_->Initialize(view_emulation_.Get()); |
| 1157 if (FAILED(hr)) | 1186 if (FAILED(hr)) |
| 1158 return hr; | 1187 return hr; |
| 1159 mswr::ComPtr<winui::Core::ICoreWindow> core_window; | 1188 mswr::ComPtr<winui::Core::ICoreWindow> core_window; |
| 1160 hr = view_emulation_->get_CoreWindow(core_window.GetAddressOf()); | 1189 hr = view_emulation_->get_CoreWindow(core_window.GetAddressOf()); |
| 1161 if (FAILED(hr)) | 1190 if (FAILED(hr)) |
| 1162 return hr; | 1191 return hr; |
| 1163 hr = app_view_->SetWindow(core_window.Get()); | 1192 hr = app_view_->SetWindow(core_window.Get()); |
| 1164 if (FAILED(hr)) | 1193 if (FAILED(hr)) |
| 1165 return hr; | 1194 return hr; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1200 }; | 1229 }; |
| 1201 | 1230 |
| 1202 | 1231 |
| 1203 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { | 1232 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { |
| 1204 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); | 1233 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); |
| 1205 if (FAILED(hr)) | 1234 if (FAILED(hr)) |
| 1206 CHECK(false); | 1235 CHECK(false); |
| 1207 return mswr::Make<CoreApplicationWin7Emulation>(); | 1236 return mswr::Make<CoreApplicationWin7Emulation>(); |
| 1208 } | 1237 } |
| 1209 | 1238 |
| OLD | NEW |