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 | 8 |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "ui/gfx/geometry/safe_integer_conversions.h" | 10 #include "ui/gfx/geometry/safe_integer_conversions.h" |
10 #include "ui/gfx/win/msg_util.h" | 11 #include "ui/gfx/win/msg_util.h" |
11 | 12 |
13 #pragma comment(lib, "shell32.lib") | |
14 | |
12 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 | |
17 // count because of the hidden window used by the UI message loop of | |
18 // the metro viewer. | |
13 int g_window_count = 0; | 19 int g_window_count = 0; |
14 | 20 |
21 const wchar_t kAshWin7AppId[] = L"Google.Chrome.AshWin7.1"; | |
22 | |
15 extern float GetModernUIScale(); | 23 extern float GetModernUIScale(); |
16 | 24 |
17 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, | 25 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, |
18 WPARAM wparam, LPARAM lparam) { | 26 WPARAM wparam, LPARAM lparam) { |
19 PAINTSTRUCT ps; | 27 PAINTSTRUCT ps; |
20 HDC hdc; | 28 HDC hdc; |
21 switch (message) { | 29 switch (message) { |
22 case WM_CREATE: | 30 case WM_CREATE: |
23 ++g_window_count; | 31 ++g_window_count; |
24 break; | 32 break; |
ananta
2014/06/10 00:37:38
Are these alignment changes needed?
| |
25 case WM_PAINT: | 33 case WM_PAINT: |
26 hdc = ::BeginPaint(hwnd, &ps); | 34 hdc = ::BeginPaint(hwnd, &ps); |
27 ::EndPaint(hwnd, &ps); | 35 ::EndPaint(hwnd, &ps); |
28 break; | 36 break; |
29 case WM_CLOSE: | 37 case WM_CLOSE: |
30 ::DestroyWindow(hwnd); | 38 ::DestroyWindow(hwnd); |
31 break; | 39 break; |
32 case WM_DESTROY: | 40 case WM_DESTROY: |
33 --g_window_count; | 41 --g_window_count; |
34 if (!g_window_count) | 42 if (!g_window_count) |
35 ::PostQuitMessage(0); | 43 ::PostQuitMessage(0); |
36 break; | 44 break; |
37 // Always allow Chrome to set the cursor. | 45 // Always allow Chrome to set the cursor. |
38 case WM_SETCURSOR: | 46 case WM_SETCURSOR: |
39 return 1; | 47 return 1; |
40 default: | 48 default: |
41 return ::DefWindowProc(hwnd, message, wparam, lparam); | 49 return ::DefWindowProc(hwnd, message, wparam, lparam); |
42 } | 50 } |
43 return 0; | 51 return 0; |
44 } | 52 } |
45 | 53 |
46 HWND CreateMetroTopLevelWindow() { | 54 bool DeveloperModeLaunch() { |
ananta
2014/06/10 00:37:38
Instead of a keystate based check, how about IsDeb
| |
55 unsigned short key = ::GetAsyncKeyState(VK_SHIFT); | |
56 const unsigned short kPressedMask = 0x8000; | |
57 return (key & kPressedMask) != 0; | |
58 } | |
59 | |
60 HWND CreateMetroTopLevelWindow(const RECT& work_area) { | |
47 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase); | 61 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase); |
48 WNDCLASSEXW wcex; | 62 WNDCLASSEXW wcex; |
49 wcex.cbSize = sizeof(wcex); | 63 wcex.cbSize = sizeof(wcex); |
50 wcex.style = CS_HREDRAW | CS_VREDRAW; | 64 wcex.style = CS_HREDRAW | CS_VREDRAW; |
51 wcex.lpfnWndProc = WndProc; | 65 wcex.lpfnWndProc = WndProc; |
52 wcex.cbClsExtra = 0; | 66 wcex.cbClsExtra = 0; |
53 wcex.cbWndExtra = 0; | 67 wcex.cbWndExtra = 0; |
54 wcex.hInstance = hInst; | 68 wcex.hInstance = hInst; |
55 wcex.hIcon = 0; | 69 wcex.hIcon = LoadIcon(::GetModuleHandle(NULL), L"IDR_MAINFRAME"); |
56 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); | 70 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); |
57 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1); | 71 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1); |
58 wcex.lpszMenuName = 0; | 72 wcex.lpszMenuName = 0; |
59 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow"; | 73 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow"; |
60 wcex.hIconSm = 0; | 74 wcex.hIconSm = LoadIcon(::GetModuleHandle(NULL), L"IDR_MAINFRAME"); |
75 | |
76 | |
61 | 77 |
62 HWND hwnd = ::CreateWindowExW(0, | 78 HWND hwnd = ::CreateWindowExW(0, |
63 MAKEINTATOM(::RegisterClassExW(&wcex)), | 79 MAKEINTATOM(::RegisterClassExW(&wcex)), |
64 L"metro_win7", | 80 L"metro_win7", |
65 WS_POPUP | WS_VISIBLE, | 81 WS_POPUP | WS_VISIBLE | WS_MINIMIZEBOX, |
66 0, 0, 1600, 900, | 82 work_area.top, work_area.left, |
83 work_area.right, work_area.bottom, | |
67 NULL, NULL, hInst, NULL); | 84 NULL, NULL, hInst, NULL); |
68 return hwnd; | 85 return hwnd; |
69 } | 86 } |
70 | 87 |
71 typedef winfoundtn::ITypedEventHandler< | 88 typedef winfoundtn::ITypedEventHandler< |
72 winapp::Core::CoreApplicationView*, | 89 winapp::Core::CoreApplicationView*, |
73 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; | 90 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; |
74 | 91 |
75 typedef winfoundtn::ITypedEventHandler< | 92 typedef winfoundtn::ITypedEventHandler< |
76 winui::Core::CoreWindow*, | 93 winui::Core::CoreWindow*, |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 mouse_capture_lost_handler_(NULL), | 576 mouse_capture_lost_handler_(NULL), |
560 mouse_pressed_handler_(NULL), | 577 mouse_pressed_handler_(NULL), |
561 mouse_released_handler_(NULL), | 578 mouse_released_handler_(NULL), |
562 mouse_entered_handler_(NULL), | 579 mouse_entered_handler_(NULL), |
563 mouse_exited_handler_(NULL), | 580 mouse_exited_handler_(NULL), |
564 mouse_wheel_changed_handler_(NULL), | 581 mouse_wheel_changed_handler_(NULL), |
565 key_down_handler_(NULL), | 582 key_down_handler_(NULL), |
566 key_up_handler_(NULL), | 583 key_up_handler_(NULL), |
567 character_received_handler_(NULL) { | 584 character_received_handler_(NULL) { |
568 dispatcher_ = mswr::Make<CoreDispatcherEmulation>(this); | 585 dispatcher_ = mswr::Make<CoreDispatcherEmulation>(this); |
569 core_hwnd_ = CreateMetroTopLevelWindow(); | 586 |
587 // Unless we select our own AppUserModelID the shell might confuse us | |
588 // with the app launcher one and we get the wrong taskbar button and icon. | |
589 ::SetCurrentProcessExplicitAppUserModelID(kAshWin7AppId); | |
590 | |
591 RECT work_area = {0}; | |
592 ::SystemParametersInfo(SPI_GETWORKAREA, 0, &work_area, 0); | |
593 if (DeveloperModeLaunch()) { | |
594 work_area.top = 0; | |
595 work_area.left = 0; | |
596 work_area.right = 1600; | |
597 work_area.bottom = 900; | |
598 } | |
599 | |
600 core_hwnd_ = CreateMetroTopLevelWindow(work_area); | |
570 } | 601 } |
571 | 602 |
572 ~CoreWindowEmulation() { | 603 ~CoreWindowEmulation() { |
573 if (core_hwnd_) | 604 if (core_hwnd_) |
574 ::DestroyWindow(core_hwnd_); | 605 ::DestroyWindow(core_hwnd_); |
575 } | 606 } |
576 | 607 |
577 // ICoreWindow implementation: | 608 // ICoreWindow implementation: |
578 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( | 609 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( |
579 IInspectable** value) { | 610 IInspectable** value) { |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1175 }; | 1206 }; |
1176 | 1207 |
1177 | 1208 |
1178 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { | 1209 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { |
1179 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); | 1210 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); |
1180 if (FAILED(hr)) | 1211 if (FAILED(hr)) |
1181 CHECK(false); | 1212 CHECK(false); |
1182 return mswr::Make<CoreApplicationWin7Emulation>(); | 1213 return mswr::Make<CoreApplicationWin7Emulation>(); |
1183 } | 1214 } |
1184 | 1215 |
OLD | NEW |