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

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

Issue 227573007: Third part of porting Chrome Ash to Windows 7 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lf Created 6 years, 8 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
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 7
8 #include "base/command_line.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 10
10 EXTERN_C IMAGE_DOS_HEADER __ImageBase; 11 EXTERN_C IMAGE_DOS_HEADER __ImageBase;
12 int g_window_count = 0;
11 13
12 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, 14 LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
13 WPARAM wparam, LPARAM lparam) { 15 WPARAM wparam, LPARAM lparam) {
14 PAINTSTRUCT ps; 16 PAINTSTRUCT ps;
15 HDC hdc; 17 HDC hdc;
16 switch (message) { 18 switch (message) {
ananta 2014/04/11 02:25:24 Please add some comments here about why we need th
19 case WM_CREATE:
20 ++g_window_count;
21 break;
17 case WM_PAINT: 22 case WM_PAINT:
18 hdc = ::BeginPaint(hwnd, &ps); 23 hdc = ::BeginPaint(hwnd, &ps);
19 EndPaint(hwnd, &ps); 24 EndPaint(hwnd, &ps);
20 break; 25 break;
21 case WM_LBUTTONUP: 26 case WM_CLOSE:
22 // TODO(cpu): Remove this test code. 27 DestroyWindow(hwnd);
23 ::InvalidateRect(hwnd, NULL, TRUE);
24 break; 28 break;
25 case WM_DESTROY: 29 case WM_DESTROY:
26 PostQuitMessage(0); 30 --g_window_count;
31 if (!g_window_count)
32 PostQuitMessage(0);
27 break; 33 break;
28 default: 34 default:
29 return ::DefWindowProc(hwnd, message, wparam, lparam); 35 return ::DefWindowProc(hwnd, message, wparam, lparam);
30 } 36 }
31 return 0; 37 return 0;
32 } 38 }
33 39
34 HWND CreateMetroTopLevelWindow() { 40 HWND CreateMetroTopLevelWindow() {
35 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase); 41 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase);
36 WNDCLASSEXW wcex; 42 WNDCLASSEXW wcex;
37 wcex.cbSize = sizeof(wcex); 43 wcex.cbSize = sizeof(wcex);
38 wcex.style = CS_HREDRAW | CS_VREDRAW; 44 wcex.style = CS_HREDRAW | CS_VREDRAW;
39 wcex.lpfnWndProc = WndProc; 45 wcex.lpfnWndProc = WndProc;
40 wcex.cbClsExtra = 0; 46 wcex.cbClsExtra = 0;
41 wcex.cbWndExtra = 0; 47 wcex.cbWndExtra = 0;
42 wcex.hInstance = hInst; 48 wcex.hInstance = hInst;
43 wcex.hIcon = 0; 49 wcex.hIcon = 0;
44 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 50 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
45 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1); 51 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1);
46 wcex.lpszMenuName = 0; 52 wcex.lpszMenuName = 0;
47 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow"; 53 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow";
48 wcex.hIconSm = 0; 54 wcex.hIconSm = 0;
49 55
50 HWND hwnd = ::CreateWindowExW(0, 56 HWND hwnd = ::CreateWindowExW(0,
51 MAKEINTATOM(::RegisterClassExW(&wcex)), 57 MAKEINTATOM(::RegisterClassExW(&wcex)),
52 L"metro_win7", 58 L"metro_win7",
53 WS_POPUP | WS_VISIBLE, 59 WS_POPUP | WS_VISIBLE,
54 0, 0, 1024, 1024, 60 0, 0, 1600, 900,
55 NULL, NULL, hInst, NULL); 61 NULL, NULL, hInst, NULL);
56 return hwnd; 62 return hwnd;
57 } 63 }
58 64
59 typedef winfoundtn::ITypedEventHandler< 65 typedef winfoundtn::ITypedEventHandler<
60 winapp::Core::CoreApplicationView*, 66 winapp::Core::CoreApplicationView*,
61 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; 67 winapp::Activation::IActivatedEventArgs*> ActivatedHandler;
62 68
63 typedef winfoundtn::ITypedEventHandler< 69 typedef winfoundtn::ITypedEventHandler<
64 winui::Core::CoreWindow*, 70 winui::Core::CoreWindow*,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 145 }
140 146
141 virtual HRESULT STDMETHODCALLTYPE ProcessEvents( 147 virtual HRESULT STDMETHODCALLTYPE ProcessEvents(
142 winui::Core::CoreProcessEventsOption options) { 148 winui::Core::CoreProcessEventsOption options) {
143 // We don't support the other message pump modes. So we basically enter a 149 // We don't support the other message pump modes. So we basically enter a
144 // traditional message loop that we only exit a teardown. 150 // traditional message loop that we only exit a teardown.
145 if (options != winui::Core::CoreProcessEventsOption_ProcessUntilQuit) 151 if (options != winui::Core::CoreProcessEventsOption_ProcessUntilQuit)
146 return E_FAIL; 152 return E_FAIL;
147 153
148 MSG msg = {0}; 154 MSG msg = {0};
149 while(::GetMessage(&msg, NULL, 0, 0) != 0) { 155 while((::GetMessage(&msg, NULL, 0, 0) != 0) && g_window_count > 0) {
150 ::TranslateMessage(&msg); 156 ::TranslateMessage(&msg);
151 ::DispatchMessage(&msg); 157 ::DispatchMessage(&msg);
152 } 158 }
153 // TODO(cpu): figure what to do with msg.WParam which we would normally 159 // TODO(cpu): figure what to do with msg.WParam which we would normally
154 // return here. 160 // return here.
155 return S_OK; 161 return S_OK;
156 } 162 }
157 163
158 virtual HRESULT STDMETHODCALLTYPE RunAsync( 164 virtual HRESULT STDMETHODCALLTYPE RunAsync(
159 winui::Core::CoreDispatcherPriority priority, 165 winui::Core::CoreDispatcherPriority priority,
(...skipping 27 matching lines...) Expand all
187 : public mswr::RuntimeClass< 193 : public mswr::RuntimeClass<
188 mswr::RuntimeClassFlags<mswr::WinRtClassicComMix>, 194 mswr::RuntimeClassFlags<mswr::WinRtClassicComMix>,
189 winui::Core::ICoreWindow, ICoreWindowInterop> { 195 winui::Core::ICoreWindow, ICoreWindowInterop> {
190 public: 196 public:
191 CoreWindowEmulation() : core_hwnd_(NULL) { 197 CoreWindowEmulation() : core_hwnd_(NULL) {
192 dispatcher_ = mswr::Make<CoreDispacherEmulation>(); 198 dispatcher_ = mswr::Make<CoreDispacherEmulation>();
193 core_hwnd_ = CreateMetroTopLevelWindow(); 199 core_hwnd_ = CreateMetroTopLevelWindow();
194 } 200 }
195 201
196 ~CoreWindowEmulation() { 202 ~CoreWindowEmulation() {
197 ::DestroyWindow(core_hwnd_); 203 if (core_hwnd_)
204 ::DestroyWindow(core_hwnd_);
198 } 205 }
199 206
200 // ICoreWindow implementation: 207 // ICoreWindow implementation:
201 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( 208 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider(
202 IInspectable** value) { 209 IInspectable** value) {
203 return S_OK; 210 return S_OK;
204 } 211 }
205 212
206 virtual HRESULT STDMETHODCALLTYPE get_Bounds( 213 virtual HRESULT STDMETHODCALLTYPE get_Bounds(
207 winfoundtn::Rect* value) { 214 winfoundtn::Rect* value) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 boolean* value) { 269 boolean* value) {
263 return S_OK; 270 return S_OK;
264 } 271 }
265 272
266 virtual HRESULT STDMETHODCALLTYPE Activate(void) { 273 virtual HRESULT STDMETHODCALLTYPE Activate(void) {
267 // After we fire OnActivate on the View, Chrome calls us back here. 274 // After we fire OnActivate on the View, Chrome calls us back here.
268 return S_OK; 275 return S_OK;
269 } 276 }
270 277
271 virtual HRESULT STDMETHODCALLTYPE Close(void) { 278 virtual HRESULT STDMETHODCALLTYPE Close(void) {
279 ::PostMessage(core_hwnd_, WM_CLOSE, 0, 0);
280 core_hwnd_ = NULL;
272 return S_OK; 281 return S_OK;
273 } 282 }
274 283
275 virtual HRESULT STDMETHODCALLTYPE GetAsyncKeyState( 284 virtual HRESULT STDMETHODCALLTYPE GetAsyncKeyState(
276 ABI::Windows::System::VirtualKey virtualKey, 285 ABI::Windows::System::VirtualKey virtualKey,
277 winui::Core::CoreVirtualKeyStates* KeyState) { 286 winui::Core::CoreVirtualKeyStates* KeyState) {
278 return S_OK; 287 return S_OK;
279 } 288 }
280 289
281 virtual HRESULT STDMETHODCALLTYPE GetKeyState( 290 virtual HRESULT STDMETHODCALLTYPE GetKeyState(
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 544
536 class CoreApplicationViewEmulation 545 class CoreApplicationViewEmulation
537 : public mswr::RuntimeClass<winapp::Core::ICoreApplicationView> { 546 : public mswr::RuntimeClass<winapp::Core::ICoreApplicationView> {
538 public: 547 public:
539 CoreApplicationViewEmulation() { 548 CoreApplicationViewEmulation() {
540 core_window_ = mswr::Make<CoreWindowEmulation>(); 549 core_window_ = mswr::Make<CoreWindowEmulation>();
541 } 550 }
542 551
543 HRESULT Activate() { 552 HRESULT Activate() {
544 if (activated_handler_) { 553 if (activated_handler_) {
554 // This form means chrome or a test has launched the viewer.
555 if (CommandLine::ForCurrentProcess()->HasSwitch("connect"))
556 return activated_handler_->Invoke(this, nullptr);
557 // This form used to reach other integration code paths.
545 auto ae = mswr::Make<ActivatedEvent>( 558 auto ae = mswr::Make<ActivatedEvent>(
546 winapp::Activation::ActivationKind_File); 559 winapp::Activation::ActivationKind_File);
547 return activated_handler_->Invoke(this, ae.Get()); 560 return activated_handler_->Invoke(this, ae.Get());
548 } else { 561 } else {
549 return S_OK; 562 return S_OK;
550 } 563 }
551 } 564 }
552 565
566 HRESULT Close() {
567 return core_window_->Close();
568 }
569
553 // ICoreApplicationView implementation: 570 // ICoreApplicationView implementation:
554 virtual HRESULT STDMETHODCALLTYPE get_CoreWindow( 571 virtual HRESULT STDMETHODCALLTYPE get_CoreWindow(
555 winui::Core::ICoreWindow** value) { 572 winui::Core::ICoreWindow** value) {
556 if (!core_window_) 573 if (!core_window_)
557 return E_FAIL; 574 return E_FAIL;
558 return core_window_.CopyTo(value); 575 return core_window_.CopyTo(value);
559 } 576 }
560 577
561 virtual HRESULT STDMETHODCALLTYPE add_Activated( 578 virtual HRESULT STDMETHODCALLTYPE add_Activated(
562 ActivatedHandler* handler, 579 ActivatedHandler* handler,
(...skipping 15 matching lines...) Expand all
578 boolean* value) { 595 boolean* value) {
579 return S_OK; 596 return S_OK;
580 } 597 }
581 598
582 virtual HRESULT STDMETHODCALLTYPE get_IsHosted( 599 virtual HRESULT STDMETHODCALLTYPE get_IsHosted(
583 boolean* value) { 600 boolean* value) {
584 return S_OK; 601 return S_OK;
585 } 602 }
586 603
587 private: 604 private:
588 mswr::ComPtr<winui::Core::ICoreWindow> core_window_; 605 mswr::ComPtr<CoreWindowEmulation> core_window_;
589 mswr::ComPtr<ActivatedHandler> activated_handler_; 606 mswr::ComPtr<ActivatedHandler> activated_handler_;
590 }; 607 };
591 608
592 class CoreApplicationWin7Emulation 609 class CoreApplicationWin7Emulation
593 : public mswr::RuntimeClass<winapp::Core::ICoreApplication, 610 : public mswr::RuntimeClass<winapp::Core::ICoreApplication,
594 winapp::Core::ICoreApplicationExit> { 611 winapp::Core::ICoreApplicationExit> {
595 public: 612 public:
596 // ICoreApplication implementation: 613 // ICoreApplication implementation:
597 614
598 virtual HRESULT STDMETHODCALLTYPE get_Id( 615 virtual HRESULT STDMETHODCALLTYPE get_Id(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 return app_view_->Run(); 674 return app_view_->Run();
658 } 675 }
659 676
660 virtual HRESULT STDMETHODCALLTYPE RunWithActivationFactories( 677 virtual HRESULT STDMETHODCALLTYPE RunWithActivationFactories(
661 winfoundtn::IGetActivationFactory* activationFactoryCallback) { 678 winfoundtn::IGetActivationFactory* activationFactoryCallback) {
662 return S_OK; 679 return S_OK;
663 } 680 }
664 681
665 // ICoreApplicationExit implementation: 682 // ICoreApplicationExit implementation:
666 683
667 virtual HRESULT STDMETHODCALLTYPE Exit(void) { 684 virtual HRESULT STDMETHODCALLTYPE Exit() {
668 return S_OK; 685 return view_emulation_->Close();
669 } 686 }
670 687
671 virtual HRESULT STDMETHODCALLTYPE add_Exiting( 688 virtual HRESULT STDMETHODCALLTYPE add_Exiting(
672 winfoundtn::IEventHandler<IInspectable*>* handler, 689 winfoundtn::IEventHandler<IInspectable*>* handler,
673 EventRegistrationToken* token) { 690 EventRegistrationToken* token) {
674 return S_OK; 691 return S_OK;
675 } 692 }
676 693
677 virtual HRESULT STDMETHODCALLTYPE remove_Exiting( 694 virtual HRESULT STDMETHODCALLTYPE remove_Exiting(
678 EventRegistrationToken token) { 695 EventRegistrationToken token) {
679 return S_OK; 696 return S_OK;
680 } 697 }
681 698
682 private: 699 private:
683 mswr::ComPtr<winapp::Core::IFrameworkView> app_view_; 700 mswr::ComPtr<winapp::Core::IFrameworkView> app_view_;
684 mswr::ComPtr<CoreApplicationViewEmulation> view_emulation_; 701 mswr::ComPtr<CoreApplicationViewEmulation> view_emulation_;
685 }; 702 };
686 703
687 704
688 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { 705 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() {
689 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); 706 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
690 if (FAILED(hr)) 707 if (FAILED(hr))
691 CHECK(false); 708 CHECK(false);
692 return mswr::Make<CoreApplicationWin7Emulation>(); 709 return mswr::Make<CoreApplicationWin7Emulation>();
693 } 710 }
694 711
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698