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; |
(...skipping 11 matching lines...) Expand all Loading... |
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 HWND CreateMetroTopLevelWindow(const RECT& work_area) { |
47 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase); | 55 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase); |
48 WNDCLASSEXW wcex; | 56 WNDCLASSEXW wcex; |
49 wcex.cbSize = sizeof(wcex); | 57 wcex.cbSize = sizeof(wcex); |
50 wcex.style = CS_HREDRAW | CS_VREDRAW; | 58 wcex.style = CS_HREDRAW | CS_VREDRAW; |
51 wcex.lpfnWndProc = WndProc; | 59 wcex.lpfnWndProc = WndProc; |
52 wcex.cbClsExtra = 0; | 60 wcex.cbClsExtra = 0; |
53 wcex.cbWndExtra = 0; | 61 wcex.cbWndExtra = 0; |
54 wcex.hInstance = hInst; | 62 wcex.hInstance = hInst; |
55 wcex.hIcon = 0; | 63 wcex.hIcon = LoadIcon(::GetModuleHandle(NULL), L"IDR_MAINFRAME"); |
56 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); | 64 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); |
57 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1); | 65 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1); |
58 wcex.lpszMenuName = 0; | 66 wcex.lpszMenuName = 0; |
59 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow"; | 67 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow"; |
60 wcex.hIconSm = 0; | 68 wcex.hIconSm = LoadIcon(::GetModuleHandle(NULL), L"IDR_MAINFRAME"); |
| 69 |
| 70 |
61 | 71 |
62 HWND hwnd = ::CreateWindowExW(0, | 72 HWND hwnd = ::CreateWindowExW(0, |
63 MAKEINTATOM(::RegisterClassExW(&wcex)), | 73 MAKEINTATOM(::RegisterClassExW(&wcex)), |
64 L"metro_win7", | 74 L"metro_win7", |
65 WS_POPUP | WS_VISIBLE, | 75 WS_POPUP | WS_VISIBLE | WS_MINIMIZEBOX, |
66 0, 0, 1600, 900, | 76 work_area.top, work_area.left, |
| 77 work_area.right, work_area.bottom, |
67 NULL, NULL, hInst, NULL); | 78 NULL, NULL, hInst, NULL); |
68 return hwnd; | 79 return hwnd; |
69 } | 80 } |
70 | 81 |
71 typedef winfoundtn::ITypedEventHandler< | 82 typedef winfoundtn::ITypedEventHandler< |
72 winapp::Core::CoreApplicationView*, | 83 winapp::Core::CoreApplicationView*, |
73 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; | 84 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; |
74 | 85 |
75 typedef winfoundtn::ITypedEventHandler< | 86 typedef winfoundtn::ITypedEventHandler< |
76 winui::Core::CoreWindow*, | 87 winui::Core::CoreWindow*, |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 mouse_capture_lost_handler_(NULL), | 570 mouse_capture_lost_handler_(NULL), |
560 mouse_pressed_handler_(NULL), | 571 mouse_pressed_handler_(NULL), |
561 mouse_released_handler_(NULL), | 572 mouse_released_handler_(NULL), |
562 mouse_entered_handler_(NULL), | 573 mouse_entered_handler_(NULL), |
563 mouse_exited_handler_(NULL), | 574 mouse_exited_handler_(NULL), |
564 mouse_wheel_changed_handler_(NULL), | 575 mouse_wheel_changed_handler_(NULL), |
565 key_down_handler_(NULL), | 576 key_down_handler_(NULL), |
566 key_up_handler_(NULL), | 577 key_up_handler_(NULL), |
567 character_received_handler_(NULL) { | 578 character_received_handler_(NULL) { |
568 dispatcher_ = mswr::Make<CoreDispatcherEmulation>(this); | 579 dispatcher_ = mswr::Make<CoreDispatcherEmulation>(this); |
569 core_hwnd_ = CreateMetroTopLevelWindow(); | 580 |
| 581 // 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. |
| 583 ::SetCurrentProcessExplicitAppUserModelID(kAshWin7AppId); |
| 584 |
| 585 RECT work_area = {0}; |
| 586 ::SystemParametersInfo(SPI_GETWORKAREA, 0, &work_area, 0); |
| 587 if (::IsDebuggerPresent()) { |
| 588 work_area.top = 0; |
| 589 work_area.left = 0; |
| 590 work_area.right = 1600; |
| 591 work_area.bottom = 900; |
| 592 } |
| 593 |
| 594 core_hwnd_ = CreateMetroTopLevelWindow(work_area); |
570 } | 595 } |
571 | 596 |
572 ~CoreWindowEmulation() { | 597 ~CoreWindowEmulation() { |
573 if (core_hwnd_) | 598 if (core_hwnd_) |
574 ::DestroyWindow(core_hwnd_); | 599 ::DestroyWindow(core_hwnd_); |
575 } | 600 } |
576 | 601 |
577 // ICoreWindow implementation: | 602 // ICoreWindow implementation: |
578 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( | 603 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( |
579 IInspectable** value) { | 604 IInspectable** value) { |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 }; | 1200 }; |
1176 | 1201 |
1177 | 1202 |
1178 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { | 1203 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { |
1179 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); | 1204 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); |
1180 if (FAILED(hr)) | 1205 if (FAILED(hr)) |
1181 CHECK(false); | 1206 CHECK(false); |
1182 return mswr::Make<CoreApplicationWin7Emulation>(); | 1207 return mswr::Make<CoreApplicationWin7Emulation>(); |
1183 } | 1208 } |
1184 | 1209 |
OLD | NEW |