| 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/ui/views/try_chrome_dialog_view.h" | 5 #include "chrome/browser/ui/views/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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "chrome/browser/process_singleton.h" | 14 #include "chrome/browser/process_singleton.h" |
| 15 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" | 15 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
| 16 #include "chrome/grit/chromium_strings.h" | 16 #include "chrome/grit/chromium_strings.h" |
| 17 #include "chrome/grit/theme_resources.h" | 17 #include "chrome/grit/theme_resources.h" |
| 18 #include "chrome/install_static/install_util.h" | 18 #include "chrome/install_static/install_util.h" |
| 19 #include "chrome/installer/util/user_experiment.h" | 19 #include "chrome/installer/util/user_experiment.h" |
| 20 #include "components/strings/grit/components_strings.h" | 20 #include "components/strings/grit/components_strings.h" |
| 21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/display/screen.h" | 25 #include "ui/display/screen.h" |
| 26 #include "ui/display/win/screen_win.h" |
| 26 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
| 27 #include "ui/resources/grit/ui_resources.h" | 28 #include "ui/resources/grit/ui_resources.h" |
| 28 #include "ui/views/background.h" | 29 #include "ui/views/background.h" |
| 29 #include "ui/views/controls/button/checkbox.h" | 30 #include "ui/views/controls/button/checkbox.h" |
| 30 #include "ui/views/controls/button/image_button.h" | 31 #include "ui/views/controls/button/image_button.h" |
| 31 #include "ui/views/controls/button/md_text_button.h" | 32 #include "ui/views/controls/button/md_text_button.h" |
| 32 #include "ui/views/controls/button/radio_button.h" | 33 #include "ui/views/controls/button/radio_button.h" |
| 33 #include "ui/views/controls/image_view.h" | 34 #include "ui/views/controls/image_view.h" |
| 34 #include "ui/views/controls/link.h" | 35 #include "ui/views/controls/link.h" |
| 35 #include "ui/views/controls/separator.h" | 36 #include "ui/views/controls/separator.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 int separator_height = separator->GetPreferredSize().height(); | 287 int separator_height = separator->GetPreferredSize().height(); |
| 287 separator->SetSize(gfx::Size(preferred.width(), separator_height)); | 288 separator->SetSize(gfx::Size(preferred.width(), separator_height)); |
| 288 } | 289 } |
| 289 | 290 |
| 290 gfx::Rect pos = ComputeWindowPosition(preferred, base::i18n::IsRTL()); | 291 gfx::Rect pos = ComputeWindowPosition(preferred, base::i18n::IsRTL()); |
| 291 popup_->SetBounds(pos); | 292 popup_->SetBounds(pos); |
| 292 | 293 |
| 293 // Carve the toast shape into the window. | 294 // Carve the toast shape into the window. |
| 294 HWND toast_window; | 295 HWND toast_window; |
| 295 toast_window = popup_->GetNativeView()->GetHost()->GetAcceleratedWidget(); | 296 toast_window = popup_->GetNativeView()->GetHost()->GetAcceleratedWidget(); |
| 296 SetToastRegion(toast_window, preferred.width(), preferred.height()); | 297 |
| 298 gfx::Size size_in_pixels = display::win::ScreenWin::DIPToScreenSize( |
| 299 toast_window, preferred); |
| 300 SetToastRegion(toast_window, size_in_pixels.width(), |
| 301 size_in_pixels.height()); |
| 297 | 302 |
| 298 // Time to show the window in a modal loop. | 303 // Time to show the window in a modal loop. |
| 299 popup_->Show(); | 304 popup_->Show(); |
| 300 | 305 |
| 301 if (!listener.is_null()) | 306 if (!listener.is_null()) |
| 302 listener.Run(popup_->GetNativeView()); | 307 listener.Run(popup_->GetNativeView()); |
| 303 | 308 |
| 304 // If the dialog is not modal, we don't control when it is going to be | 309 // If the dialog is not modal, we don't control when it is going to be |
| 305 // dismissed and hence we cannot inform the listener about the dialog going | 310 // dismissed and hence we cannot inform the listener about the dialog going |
| 306 // away. | 311 // away. |
| 307 if (dialog_type == kDialogType::MODAL) { | 312 if (dialog_type == kDialogType::MODAL) { |
| 308 base::RunLoop().Run(); | 313 base::RunLoop().Run(); |
| 309 if (!listener.is_null()) | 314 if (!listener.is_null()) |
| 310 listener.Run(nullptr); | 315 listener.Run(nullptr); |
| 311 } | 316 } |
| 312 return result_; | 317 return result_; |
| 313 } | 318 } |
| 314 | 319 |
| 315 gfx::Rect TryChromeDialogView::ComputeWindowPosition(const gfx::Size& size, | 320 gfx::Rect TryChromeDialogView::ComputeWindowPosition(const gfx::Size& size, |
| 316 bool is_RTL) { | 321 bool is_RTL) { |
| 317 gfx::Point origin; | 322 gfx::Point origin; |
| 318 | 323 |
| 319 gfx::Rect work_area = popup_->GetWorkAreaBoundsInScreen(); | 324 gfx::Rect work_area = popup_->GetWorkAreaBoundsInScreen(); |
| 320 origin.set_x(is_RTL ? work_area.x() : work_area.right() - size.width()); | 325 origin.set_x(is_RTL ? work_area.x() : work_area.right() - size.width()); |
| 321 origin.set_y(work_area.bottom()- size.height()); | 326 origin.set_y(work_area.bottom()- size.height()); |
| 322 | 327 |
| 323 return display::Screen::GetScreen()->ScreenToDIPRectInWindow( | 328 return gfx::Rect(origin, size); |
| 324 popup_->GetNativeView(), gfx::Rect(origin, size)); | |
| 325 } | 329 } |
| 326 | 330 |
| 327 void TryChromeDialogView::SetToastRegion(HWND window, int w, int h) { | 331 void TryChromeDialogView::SetToastRegion(HWND window, int w, int h) { |
| 328 static const POINT polygon[] = { | 332 static const POINT polygon[] = { |
| 329 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side. | 333 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side. |
| 330 {w - 4, 0}, {w - 2, 1}, {w - 1, 2}, {w, 4}, // Right side. | 334 {w - 4, 0}, {w - 2, 1}, {w - 1, 2}, {w, 4}, // Right side. |
| 331 {w, h}, {0, h}}; | 335 {w, h}, {0, h}}; |
| 332 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING); | 336 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING); |
| 333 ::SetWindowRgn(window, region, FALSE); | 337 ::SetWindowRgn(window, region, FALSE); |
| 334 } | 338 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 result_ = TRY_CHROME_AS_DEFAULT; | 374 result_ = TRY_CHROME_AS_DEFAULT; |
| 371 } | 375 } |
| 372 | 376 |
| 373 popup_->Close(); | 377 popup_->Close(); |
| 374 base::MessageLoop::current()->QuitWhenIdle(); | 378 base::MessageLoop::current()->QuitWhenIdle(); |
| 375 } | 379 } |
| 376 | 380 |
| 377 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { | 381 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { |
| 378 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); | 382 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); |
| 379 } | 383 } |
| OLD | NEW |