Chromium Code Reviews| 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/constrained_window_views.h" | 5 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/browser/platform_util.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/themes/theme_service.h" | 14 #include "chrome/browser/themes/theme_service.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | |
| 14 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 16 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 16 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 18 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 17 #include "chrome/browser/ui/views/constrained_window_frame_simple.h" | 19 #include "chrome/browser/ui/views/constrained_window_frame_simple.h" |
| 18 #include "chrome/browser/ui/views/frame/browser_view.h" | 20 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 19 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 22 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_contents_view.h" | 25 #include "content/public/browser/web_contents_view.h" |
| 24 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
| 25 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 26 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| 27 #include "grit/ui_resources.h" | 29 #include "grit/ui_resources.h" |
| 28 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
| 29 #include "ui/aura/client/aura_constants.h" | 31 #include "ui/aura/client/aura_constants.h" |
| 30 #include "ui/base/hit_test.h" | 32 #include "ui/base/hit_test.h" |
| 31 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 32 #include "ui/gfx/canvas.h" | 34 #include "ui/gfx/canvas.h" |
| 33 #include "ui/gfx/font.h" | 35 #include "ui/gfx/font.h" |
| 34 #include "ui/gfx/path.h" | 36 #include "ui/gfx/path.h" |
| 35 #include "ui/gfx/rect.h" | 37 #include "ui/gfx/rect.h" |
| 36 #include "ui/gfx/screen.h" | 38 #include "ui/gfx/screen.h" |
| 37 #include "ui/views/color_constants.h" | 39 #include "ui/views/color_constants.h" |
| 38 #include "ui/views/controls/button/image_button.h" | 40 #include "ui/views/controls/button/image_button.h" |
| 39 #include "ui/views/focus/focus_manager.h" | 41 #include "ui/views/focus/focus_manager.h" |
| 40 #include "ui/views/views_delegate.h" | 42 #include "ui/views/views_delegate.h" |
| 41 #include "ui/views/widget/widget.h" | 43 #include "ui/views/widget/widget.h" |
| 42 #include "ui/views/window/client_view.h" | 44 #include "ui/views/window/client_view.h" |
| 45 #include "ui/views/window/dialog_client_view.h" | |
| 46 #include "ui/views/window/dialog_delegate.h" | |
| 43 #include "ui/views/window/frame_background.h" | 47 #include "ui/views/window/frame_background.h" |
| 44 #include "ui/views/window/non_client_view.h" | 48 #include "ui/views/window/non_client_view.h" |
| 45 #include "ui/views/window/window_resources.h" | 49 #include "ui/views/window/window_resources.h" |
| 46 #include "ui/views/window/window_shape.h" | 50 #include "ui/views/window/window_shape.h" |
| 47 | 51 |
| 48 #if defined(OS_WIN) && !defined(USE_AURA) | 52 #if defined(OS_WIN) && !defined(USE_AURA) |
| 49 #include "ui/base/win/shell.h" | 53 #include "ui/base/win/shell.h" |
| 50 #include "ui/views/widget/native_widget_win.h" | 54 #include "ui/views/widget/native_widget_win.h" |
| 51 #endif | 55 #endif |
| 52 | 56 |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 ConstrainedWindowViews::ConstrainedWindowViews( | 581 ConstrainedWindowViews::ConstrainedWindowViews( |
| 578 TabContents* tab_contents, | 582 TabContents* tab_contents, |
| 579 views::WidgetDelegate* widget_delegate) | 583 views::WidgetDelegate* widget_delegate) |
| 580 : tab_contents_(tab_contents), | 584 : tab_contents_(tab_contents), |
| 581 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( | 585 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( |
| 582 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { | 586 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { |
| 583 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 587 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 584 params.delegate = widget_delegate; | 588 params.delegate = widget_delegate; |
| 585 params.native_widget = native_constrained_window_->AsNativeWidget(); | 589 params.native_widget = native_constrained_window_->AsNativeWidget(); |
| 586 params.child = true; | 590 params.child = true; |
| 587 params.parent = tab_contents->web_contents()->GetNativeView(); | 591 |
| 592 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 593 if (command_line->HasSwitch(switches::kEnableFramelessConstrainedDialogs)) { | |
| 594 content::WebContentsView* web_contents_view = | |
| 595 tab_contents->web_contents()->GetView(); | |
| 596 Widget* parent_widget = Widget::GetTopLevelWidgetForNativeView( | |
| 597 web_contents_view->GetNativeView()); | |
| 598 params.parent_widget = parent_widget; | |
| 599 } else { | |
| 600 params.parent = tab_contents->web_contents()->GetNativeView(); | |
| 601 } | |
| 602 | |
| 588 #if defined(USE_ASH) | 603 #if defined(USE_ASH) |
| 589 // Ash window headers can be transparent. | 604 // Ash window headers can be transparent. |
| 590 params.transparent = true; | 605 params.transparent = true; |
| 591 ash::SetChildWindowVisibilityChangesAnimated(params.parent); | 606 ash::SetChildWindowVisibilityChangesAnimated(params.parent); |
| 592 // No animations should get performed on the window since that will re-order | 607 // No animations should get performed on the window since that will re-order |
| 593 // the window stack which will then cause many problems. | 608 // the window stack which will then cause many problems. |
| 594 if (params.parent && params.parent->parent()) { | 609 if (params.parent && params.parent->parent()) { |
| 595 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, | 610 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, |
| 596 true); | 611 true); |
| 597 } | 612 } |
| 598 #endif | 613 #endif |
| 599 Init(params); | 614 Init(params); |
| 600 | 615 |
| 616 if (command_line->HasSwitch(switches::kEnableFramelessConstrainedDialogs)) { | |
| 617 // Set the dialog background color. | |
| 618 if (widget_delegate && widget_delegate->AsDialogDelegate()) { | |
| 619 views::Background* background = views::Background::CreateSolidBackground( | |
| 620 ConstrainedWindow::GetBackgroundColor()); | |
| 621 views::DialogClientView* dialog_client_view = | |
| 622 widget_delegate->AsDialogDelegate()->GetDialogClientView(); | |
| 623 if (dialog_client_view) | |
| 624 dialog_client_view->set_background(background); | |
| 625 } | |
| 626 | |
| 627 // Set the top of the now-centered window to overlap the browser chrome. | |
| 628 gfx::Rect bounds = GetRootView()->bounds(); | |
| 629 Widget::ConvertRect(this, params.parent_widget, &bounds); | |
| 630 ConstrainedWindowTabHelperDelegate* tab_helper_delegate = | |
| 631 tab_contents->constrained_window_tab_helper()->delegate(); | |
| 632 | |
| 633 BrowserWindow* browser_window = | |
| 634 tab_helper_delegate ? tab_helper_delegate->GetBrowserWindow() : NULL; | |
| 635 if (browser_window && browser_window->GetConstrainedWindowTopY() >= 0) { | |
| 636 bounds.set_y(browser_window->GetConstrainedWindowTopY()); | |
| 637 SetBounds(bounds); | |
|
Ben Goodger (Google)
2012/09/27 16:16:12
rather than creating at the wrong location the mov
Mike Wittman
2012/09/28 22:46:09
Not easily. The window centering logic lives with
Ben Goodger (Google)
2012/10/01 16:25:57
But you can construct correct bounds for params ea
Mike Wittman
2012/10/02 00:07:35
No, on further inspection I don't see a feasible w
| |
| 638 } | |
| 639 } | |
| 640 | |
| 601 tab_contents_->constrained_window_tab_helper()->AddConstrainedDialog(this); | 641 tab_contents_->constrained_window_tab_helper()->AddConstrainedDialog(this); |
| 602 #if defined(USE_ASH) | 642 #if defined(USE_ASH) |
| 603 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); | 643 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); |
| 604 #endif | 644 #endif |
| 605 } | 645 } |
| 606 | 646 |
| 607 ConstrainedWindowViews::~ConstrainedWindowViews() { | 647 ConstrainedWindowViews::~ConstrainedWindowViews() { |
| 608 } | 648 } |
| 609 | 649 |
| 610 //////////////////////////////////////////////////////////////////////////////// | 650 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 | 722 |
| 683 views::internal::NativeWidgetDelegate* | 723 views::internal::NativeWidgetDelegate* |
| 684 ConstrainedWindowViews::AsNativeWidgetDelegate() { | 724 ConstrainedWindowViews::AsNativeWidgetDelegate() { |
| 685 return this; | 725 return this; |
| 686 } | 726 } |
| 687 | 727 |
| 688 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) { | 728 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) { |
| 689 // Prevent a constrained window to be moved by the user. | 729 // Prevent a constrained window to be moved by the user. |
| 690 return HTNOWHERE; | 730 return HTNOWHERE; |
| 691 } | 731 } |
| OLD | NEW |