| 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 "chrome/browser/first_run/try_chrome_dialog_view.h" | 5 #include "chrome/browser/first_run/try_chrome_dialog_view.h" |
| 6 | 6 |
| 7 #include <shellapi.h> | 7 #include <shellapi.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 272 |
| 273 // We resize the window according to the layout manager. This takes into | 273 // We resize the window according to the layout manager. This takes into |
| 274 // account the differences between XP and Vista fonts and buttons. | 274 // account the differences between XP and Vista fonts and buttons. |
| 275 layout->Layout(root_view); | 275 layout->Layout(root_view); |
| 276 gfx::Size preferred = layout->GetPreferredSize(root_view); | 276 gfx::Size preferred = layout->GetPreferredSize(root_view); |
| 277 if (separator) { | 277 if (separator) { |
| 278 int separator_height = separator->GetPreferredSize().height(); | 278 int separator_height = separator->GetPreferredSize().height(); |
| 279 separator->SetSize(gfx::Size(preferred.width(), separator_height)); | 279 separator->SetSize(gfx::Size(preferred.width(), separator_height)); |
| 280 } | 280 } |
| 281 | 281 |
| 282 gfx::Rect pos = ComputeWindowPosition(preferred.width(), preferred.height(), | 282 gfx::Rect pos = ComputeWindowPosition(preferred, base::i18n::IsRTL()); |
| 283 base::i18n::IsRTL()); | |
| 284 popup_->SetBounds(pos); | 283 popup_->SetBounds(pos); |
| 285 | 284 |
| 286 // Carve the toast shape into the window. | 285 // Carve the toast shape into the window. |
| 287 HWND toast_window; | 286 HWND toast_window; |
| 288 toast_window = popup_->GetNativeView()->GetHost()->GetAcceleratedWidget(); | 287 toast_window = popup_->GetNativeView()->GetHost()->GetAcceleratedWidget(); |
| 289 SetToastRegion(toast_window, preferred.width(), preferred.height()); | 288 SetToastRegion(toast_window, preferred.width(), preferred.height()); |
| 290 | 289 |
| 291 // Time to show the window in a modal loop. | 290 // Time to show the window in a modal loop. |
| 292 popup_->Show(); | 291 popup_->Show(); |
| 293 if (!listener.is_null()) | 292 if (!listener.is_null()) |
| 294 listener.Run(popup_->GetNativeView()); | 293 listener.Run(popup_->GetNativeView()); |
| 295 base::RunLoop().Run(); | 294 base::RunLoop().Run(); |
| 296 if (!listener.is_null()) | 295 if (!listener.is_null()) |
| 297 listener.Run(NULL); | 296 listener.Run(NULL); |
| 298 return result_; | 297 return result_; |
| 299 } | 298 } |
| 300 | 299 |
| 301 gfx::Rect TryChromeDialogView::ComputeWindowPosition(int width, | 300 gfx::Rect TryChromeDialogView::ComputeWindowPosition(gfx::Size size, |
| 302 int height, | |
| 303 bool is_RTL) { | 301 bool is_RTL) { |
| 304 // The 'Shell_TrayWnd' is the taskbar. We like to show our window in that | 302 // A best guess at a visible location in case all else fails. |
| 305 // monitor if we can. This code works even if such window is not found. | 303 gfx::Point origin(20, 20); |
| 306 HWND taskbar = ::FindWindowW(L"Shell_TrayWnd", NULL); | 304 |
| 307 HMONITOR monitor = ::MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY); | 305 // The taskbar (the 'Shell_TrayWnd' window) is always on the primary monitor. |
| 306 constexpr POINT kOrigin = {}; |
| 308 MONITORINFO info = {sizeof(info)}; | 307 MONITORINFO info = {sizeof(info)}; |
| 309 if (!GetMonitorInfoW(monitor, &info)) { | 308 if (::GetMonitorInfo(::MonitorFromPoint(kOrigin, MONITOR_DEFAULTTOPRIMARY), |
| 310 // Quite unexpected. Do a best guess at a visible rectangle. | 309 &info)) { |
| 311 return gfx::Rect(20, 20, width + 20, height + 20); | 310 // |rcWork| is the work area, accounting for the visible taskbars. |
| 311 origin.set_x(is_RTL ? info.rcWork.left : info.rcWork.right - size.width()); |
| 312 origin.set_y(info.rcWork.bottom - size.height()); |
| 312 } | 313 } |
| 313 // The |rcWork| is the work area. It should account for the taskbars that | 314 |
| 314 // are in the screen when we called the function. | 315 return gfx::Rect(origin, size); |
| 315 int left = is_RTL ? info.rcWork.left : info.rcWork.right - width; | |
| 316 int top = info.rcWork.bottom - height; | |
| 317 return gfx::Rect(left, top, width, height); | |
| 318 } | 316 } |
| 319 | 317 |
| 320 void TryChromeDialogView::SetToastRegion(HWND window, int w, int h) { | 318 void TryChromeDialogView::SetToastRegion(HWND window, int w, int h) { |
| 321 static const POINT polygon[] = { | 319 static const POINT polygon[] = { |
| 322 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side. | 320 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side. |
| 323 {w-4, 0}, {w-2, 1}, {w-1, 2}, {w, 4}, // Right side. | 321 {w-4, 0}, {w-2, 1}, {w-1, 2}, {w, 4}, // Right side. |
| 324 {w, h}, {0, h} | 322 {w, h}, {0, h} |
| 325 }; | 323 }; |
| 326 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING); | 324 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING); |
| 327 ::SetWindowRgn(window, region, FALSE); | 325 ::SetWindowRgn(window, region, FALSE); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 result_ = TRY_CHROME_AS_DEFAULT; | 362 result_ = TRY_CHROME_AS_DEFAULT; |
| 365 } | 363 } |
| 366 | 364 |
| 367 popup_->Close(); | 365 popup_->Close(); |
| 368 base::MessageLoop::current()->QuitWhenIdle(); | 366 base::MessageLoop::current()->QuitWhenIdle(); |
| 369 } | 367 } |
| 370 | 368 |
| 371 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { | 369 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { |
| 372 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); | 370 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); |
| 373 } | 371 } |
| OLD | NEW |