Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: win8/metro_driver/metro_driver_win7.cc

Issue 546503002: Notify the Chrome browser process about the window being activated from the viewer process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review comments Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « win8/metro_driver/chrome_app_view_ash.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 if (core_hwnd_) {
573 ::RemoveProp(core_hwnd_, kAshWin7CoreWindowHandler);
599 ::DestroyWindow(core_hwnd_); 574 ::DestroyWindow(core_hwnd_);
575 }
600 } 576 }
601 577
602 // ICoreWindow implementation: 578 // ICoreWindow implementation:
603 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( 579 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider(
604 IInspectable** value) { 580 IInspectable** value) {
605 return S_OK; 581 return S_OK;
606 } 582 }
607 583
608 virtual HRESULT STDMETHODCALLTYPE get_Bounds( 584 virtual HRESULT STDMETHODCALLTYPE get_Bounds(
609 winfoundtn::Rect* value) { 585 winfoundtn::Rect* value) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 return S_OK; 668 return S_OK;
693 } 669 }
694 670
695 virtual HRESULT STDMETHODCALLTYPE SetPointerCapture(void) { 671 virtual HRESULT STDMETHODCALLTYPE SetPointerCapture(void) {
696 return S_OK; 672 return S_OK;
697 } 673 }
698 674
699 virtual HRESULT STDMETHODCALLTYPE add_Activated( 675 virtual HRESULT STDMETHODCALLTYPE add_Activated(
700 WindowActivatedHandler* handler, 676 WindowActivatedHandler* handler,
701 EventRegistrationToken* pCookie) { 677 EventRegistrationToken* pCookie) {
702 // TODO(cpu) implement this. 678 window_activated_handler_ = handler;
679 handler->AddRef();
703 return S_OK; 680 return S_OK;
704 } 681 }
705 682
706 virtual HRESULT STDMETHODCALLTYPE remove_Activated( 683 virtual HRESULT STDMETHODCALLTYPE remove_Activated(
707 EventRegistrationToken cookie) { 684 EventRegistrationToken cookie) {
685 window_activated_handler_->Release();
686 window_activated_handler_ = NULL;
708 return S_OK; 687 return S_OK;
709 } 688 }
710 689
711 virtual HRESULT STDMETHODCALLTYPE add_AutomationProviderRequested( 690 virtual HRESULT STDMETHODCALLTYPE add_AutomationProviderRequested(
712 AutomationProviderHandler* handler, 691 AutomationProviderHandler* handler,
713 EventRegistrationToken* cookie) { 692 EventRegistrationToken* cookie) {
714 return S_OK; 693 return S_OK;
715 } 694 }
716 695
717 virtual HRESULT STDMETHODCALLTYPE remove_AutomationProviderRequested( 696 virtual HRESULT STDMETHODCALLTYPE remove_AutomationProviderRequested(
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 } 973 }
995 974
996 default: 975 default:
997 return false; 976 return false;
998 } 977 }
999 DCHECK(handler); 978 DCHECK(handler);
1000 handler->Invoke(this, event_args.Get()); 979 handler->Invoke(this, event_args.Get());
1001 return true; 980 return true;
1002 } 981 }
1003 982
983 void OnWindowActivated() {
984 if (window_activated_handler_)
985 window_activated_handler_->Invoke(this, NULL);
986 }
987
1004 private: 988 private:
1005 PointerEventHandler* mouse_moved_handler_; 989 PointerEventHandler* mouse_moved_handler_;
1006 PointerEventHandler* mouse_capture_lost_handler_; 990 PointerEventHandler* mouse_capture_lost_handler_;
1007 PointerEventHandler* mouse_pressed_handler_; 991 PointerEventHandler* mouse_pressed_handler_;
1008 PointerEventHandler* mouse_released_handler_; 992 PointerEventHandler* mouse_released_handler_;
1009 PointerEventHandler* mouse_entered_handler_; 993 PointerEventHandler* mouse_entered_handler_;
1010 PointerEventHandler* mouse_exited_handler_; 994 PointerEventHandler* mouse_exited_handler_;
1011 PointerEventHandler* mouse_wheel_changed_handler_; 995 PointerEventHandler* mouse_wheel_changed_handler_;
1012 KeyEventHandler* key_down_handler_; 996 KeyEventHandler* key_down_handler_;
1013 KeyEventHandler* key_up_handler_; 997 KeyEventHandler* key_up_handler_;
1014 CharEventHandler* character_received_handler_; 998 CharEventHandler* character_received_handler_;
1015 HWND core_hwnd_; 999 HWND core_hwnd_;
1016 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher_; 1000 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher_;
1001 mswr::ComPtr<winapp::Core::IFrameworkView> app_view_;
1002 WindowActivatedHandler* window_activated_handler_;
1017 }; 1003 };
1018 1004
1005 LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
1006 WPARAM wparam, LPARAM lparam) {
1007 PAINTSTRUCT ps;
1008 HDC hdc;
1009 switch (message) {
1010 case WM_ACTIVATE: {
1011 // HIWORD(wparam) is 1 if the window is minimized.
1012 bool active = (LOWORD(wparam) != WA_INACTIVE) && !HIWORD(wparam);
1013 if (active) {
1014 CoreWindowEmulation* core_window_handler =
1015 reinterpret_cast<CoreWindowEmulation*>(
1016 ::GetProp(hwnd, kAshWin7CoreWindowHandler));
1017 if (core_window_handler)
1018 core_window_handler->OnWindowActivated();
1019 }
1020 return ::DefWindowProc(hwnd, message, wparam, lparam);
1021 }
1022 case WM_CREATE:
1023 ++g_window_count;
1024 break;
1025 case WM_PAINT:
1026 hdc = ::BeginPaint(hwnd, &ps);
1027 ::EndPaint(hwnd, &ps);
1028 break;
1029 case WM_CLOSE:
1030 ::DestroyWindow(hwnd);
1031 break;
1032 case WM_DESTROY:
1033 --g_window_count;
1034 if (!g_window_count)
1035 ::PostQuitMessage(0);
1036 break;
1037 // Always allow Chrome to set the cursor.
1038 case WM_SETCURSOR:
1039 return 1;
1040 default:
1041 return ::DefWindowProc(hwnd, message, wparam, lparam);
1042 }
1043 return 0;
1044 }
1045
1019 class ActivatedEvent 1046 class ActivatedEvent
1020 : public mswr::RuntimeClass<winapp::Activation::IActivatedEventArgs> { 1047 : public mswr::RuntimeClass<winapp::Activation::IActivatedEventArgs> {
1021 public: 1048 public:
1022 ActivatedEvent(winapp::Activation::ActivationKind activation_kind) 1049 ActivatedEvent(winapp::Activation::ActivationKind activation_kind)
1023 : activation_kind_(activation_kind) { 1050 : activation_kind_(activation_kind) {
1024 } 1051 }
1025 1052
1026 virtual HRESULT STDMETHODCALLTYPE get_Kind( 1053 virtual HRESULT STDMETHODCALLTYPE get_Kind(
1027 winapp::Activation::ActivationKind *value) { 1054 winapp::Activation::ActivationKind *value) {
1028 *value = activation_kind_; 1055 *value = activation_kind_;
(...skipping 11 matching lines...) Expand all
1040 return E_FAIL; 1067 return E_FAIL;
1041 } 1068 }
1042 1069
1043 private: 1070 private:
1044 winapp::Activation::ActivationKind activation_kind_; 1071 winapp::Activation::ActivationKind activation_kind_;
1045 }; 1072 };
1046 1073
1047 class CoreApplicationViewEmulation 1074 class CoreApplicationViewEmulation
1048 : public mswr::RuntimeClass<winapp::Core::ICoreApplicationView> { 1075 : public mswr::RuntimeClass<winapp::Core::ICoreApplicationView> {
1049 public: 1076 public:
1050 CoreApplicationViewEmulation() { 1077 CoreApplicationViewEmulation(winapp::Core::IFrameworkView* app_view) {
1051 core_window_ = mswr::Make<CoreWindowEmulation>(); 1078 core_window_ = mswr::Make<CoreWindowEmulation>(app_view);
1052 } 1079 }
1053 1080
1054 HRESULT Activate() { 1081 HRESULT Activate() {
1055 if (activated_handler_) { 1082 if (activated_handler_) {
1056 auto ae = mswr::Make<ActivatedEvent>( 1083 auto ae = mswr::Make<ActivatedEvent>(
1057 winapp::Activation::ActivationKind_File); 1084 winapp::Activation::ActivationKind_File);
1058 return activated_handler_->Invoke(this, ae.Get()); 1085 return activated_handler_->Invoke(this, ae.Get());
1059 } else { 1086 } else {
1060 return S_OK; 1087 return S_OK;
1061 } 1088 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 virtual HRESULT STDMETHODCALLTYPE GetCurrentView( 1172 virtual HRESULT STDMETHODCALLTYPE GetCurrentView(
1146 winapp::Core::ICoreApplicationView** value) { 1173 winapp::Core::ICoreApplicationView** value) {
1147 return S_OK; 1174 return S_OK;
1148 } 1175 }
1149 1176
1150 virtual HRESULT STDMETHODCALLTYPE Run( 1177 virtual HRESULT STDMETHODCALLTYPE Run(
1151 winapp::Core::IFrameworkViewSource* viewSource) { 1178 winapp::Core::IFrameworkViewSource* viewSource) {
1152 HRESULT hr = viewSource->CreateView(app_view_.GetAddressOf()); 1179 HRESULT hr = viewSource->CreateView(app_view_.GetAddressOf());
1153 if (FAILED(hr)) 1180 if (FAILED(hr))
1154 return hr; 1181 return hr;
1155 view_emulation_ = mswr::Make<CoreApplicationViewEmulation>(); 1182 view_emulation_ = mswr::Make<CoreApplicationViewEmulation>(
1183 app_view_.Get());
1156 hr = app_view_->Initialize(view_emulation_.Get()); 1184 hr = app_view_->Initialize(view_emulation_.Get());
1157 if (FAILED(hr)) 1185 if (FAILED(hr))
1158 return hr; 1186 return hr;
1159 mswr::ComPtr<winui::Core::ICoreWindow> core_window; 1187 mswr::ComPtr<winui::Core::ICoreWindow> core_window;
1160 hr = view_emulation_->get_CoreWindow(core_window.GetAddressOf()); 1188 hr = view_emulation_->get_CoreWindow(core_window.GetAddressOf());
1161 if (FAILED(hr)) 1189 if (FAILED(hr))
1162 return hr; 1190 return hr;
1163 hr = app_view_->SetWindow(core_window.Get()); 1191 hr = app_view_->SetWindow(core_window.Get());
1164 if (FAILED(hr)) 1192 if (FAILED(hr))
1165 return hr; 1193 return hr;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 }; 1228 };
1201 1229
1202 1230
1203 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { 1231 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() {
1204 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); 1232 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
1205 if (FAILED(hr)) 1233 if (FAILED(hr))
1206 CHECK(false); 1234 CHECK(false);
1207 return mswr::Make<CoreApplicationWin7Emulation>(); 1235 return mswr::Make<CoreApplicationWin7Emulation>();
1208 } 1236 }
1209 1237
OLDNEW
« no previous file with comments | « win8/metro_driver/chrome_app_view_ash.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698