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/platform_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/themes/theme_service.h" | 14 #include "chrome/browser/themes/theme_service.h" |
15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 16 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
18 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 18 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
19 #include "chrome/browser/ui/views/constrained_window_frame_simple.h" | 19 #include "chrome/browser/ui/views/constrained_window_frame_simple.h" |
20 #include "chrome/browser/ui/views/frame/browser_view.h" | 20 #include "chrome/browser/ui/views/frame/browser_view.h" |
21 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "content/public/browser/web_contents_view.h" | 25 #include "content/public/browser/web_contents_view.h" |
26 #include "content/public/browser/navigation_controller.h" | |
Peter Kasting
2012/10/15 21:46:54
Nit: Alphabetical order
please use gerrit instead
2012/10/16 00:12:23
Done.
| |
27 #include "content/public/browser/notification_service.h" | |
28 #include "content/public/browser/notification_source.h" | |
29 #include "content/public/browser/notification_types.h" | |
26 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
27 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
28 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
29 #include "grit/ui_resources.h" | 33 #include "grit/ui_resources.h" |
30 #include "net/base/net_util.h" | 34 #include "net/base/net_util.h" |
31 #include "ui/aura/client/aura_constants.h" | 35 #include "ui/aura/client/aura_constants.h" |
32 #include "ui/base/hit_test.h" | 36 #include "ui/base/hit_test.h" |
33 #include "ui/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
34 #include "ui/gfx/canvas.h" | 38 #include "ui/gfx/canvas.h" |
35 #include "ui/gfx/font.h" | 39 #include "ui/gfx/font.h" |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh); | 578 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh); |
575 }; | 579 }; |
576 #endif // defined(USE_ASH) | 580 #endif // defined(USE_ASH) |
577 | 581 |
578 //////////////////////////////////////////////////////////////////////////////// | 582 //////////////////////////////////////////////////////////////////////////////// |
579 // ConstrainedWindowViews, public: | 583 // ConstrainedWindowViews, public: |
580 | 584 |
581 ConstrainedWindowViews::ConstrainedWindowViews( | 585 ConstrainedWindowViews::ConstrainedWindowViews( |
582 content::WebContents* web_contents, | 586 content::WebContents* web_contents, |
583 views::WidgetDelegate* widget_delegate, | 587 views::WidgetDelegate* widget_delegate, |
584 bool enable_chrome_style) | 588 bool enable_chrome_style, |
589 const gfx::Insets& client_insets) | |
585 : WebContentsObserver(web_contents), | 590 : WebContentsObserver(web_contents), |
586 web_contents_(web_contents), | 591 web_contents_(web_contents), |
592 enable_chrome_style_(enable_chrome_style), | |
593 client_insets_(client_insets), | |
587 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( | 594 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( |
588 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))), | 595 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { |
589 enable_chrome_style_(enable_chrome_style) { | |
590 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 596 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
591 params.delegate = widget_delegate; | 597 params.delegate = widget_delegate; |
592 params.native_widget = native_constrained_window_->AsNativeWidget(); | 598 params.native_widget = native_constrained_window_->AsNativeWidget(); |
593 params.child = true; | 599 params.child = true; |
594 | 600 |
595 if (enable_chrome_style_) { | 601 if (enable_chrome_style_) { |
596 params.parent_widget = Widget::GetTopLevelWidgetForNativeView( | 602 params.parent_widget = Widget::GetTopLevelWidgetForNativeView( |
597 web_contents->GetView()->GetNativeView()); | 603 web_contents_->GetView()->GetNativeView()); |
598 } else { | 604 } else { |
599 params.parent = web_contents->GetNativeView(); | 605 params.parent = web_contents_->GetNativeView(); |
600 } | 606 } |
601 | 607 |
602 #if defined(USE_ASH) | 608 #if defined(USE_ASH) |
603 // Ash window headers can be transparent. | 609 // Ash window headers can be transparent. |
604 params.transparent = true; | 610 params.transparent = true; |
605 ash::SetChildWindowVisibilityChangesAnimated(params.GetParent()); | 611 ash::SetChildWindowVisibilityChangesAnimated(params.GetParent()); |
606 // No animations should get performed on the window since that will re-order | 612 // No animations should get performed on the window since that will re-order |
607 // the window stack which will then cause many problems. | 613 // the window stack which will then cause many problems. |
608 if (params.parent && params.parent->parent()) { | 614 if (params.parent && params.parent->parent()) { |
609 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, | 615 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, |
610 true); | 616 true); |
611 } | 617 } |
612 #endif | 618 #endif |
613 Init(params); | 619 Init(params); |
614 | 620 |
615 if (enable_chrome_style_) { | 621 if (enable_chrome_style_) { |
616 // Set the dialog background color. | 622 // Set the dialog background color. |
617 if (widget_delegate && widget_delegate->AsDialogDelegate()) { | 623 if (widget_delegate && widget_delegate->AsDialogDelegate()) { |
618 views::Background* background = views::Background::CreateSolidBackground( | 624 views::Background* background = views::Background::CreateSolidBackground( |
619 ConstrainedWindow::GetBackgroundColor()); | 625 ConstrainedWindow::GetBackgroundColor()); |
620 views::DialogClientView* dialog_client_view = | 626 views::DialogClientView* dialog_client_view = |
621 widget_delegate->AsDialogDelegate()->GetDialogClientView(); | 627 widget_delegate->AsDialogDelegate()->GetDialogClientView(); |
622 if (dialog_client_view) | 628 if (dialog_client_view) |
623 dialog_client_view->set_background(background); | 629 dialog_client_view->set_background(background); |
624 } | 630 } |
625 PositionChromeStyleWindow(); | 631 PositionChromeStyleWindow(GetRootView()->bounds().size()); |
632 registrar_.Add(this, | |
633 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | |
634 content::Source<content::WebContents>(web_contents)); | |
626 } | 635 } |
627 | 636 |
628 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 637 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
629 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 638 ConstrainedWindowTabHelper::FromWebContents(web_contents_); |
630 constrained_window_tab_helper->AddConstrainedDialog(this); | 639 constrained_window_tab_helper->AddConstrainedDialog(this); |
631 #if defined(USE_ASH) | 640 #if defined(USE_ASH) |
632 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); | 641 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); |
633 #endif | 642 #endif |
634 } | 643 } |
635 | 644 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 | 690 |
682 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 691 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
683 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 692 ConstrainedWindowTabHelper::FromWebContents(web_contents_); |
684 constrained_window_tab_helper->WillClose(this); | 693 constrained_window_tab_helper->WillClose(this); |
685 } | 694 } |
686 | 695 |
687 //////////////////////////////////////////////////////////////////////////////// | 696 //////////////////////////////////////////////////////////////////////////////// |
688 // ConstrainedWindowViews, views::Widget overrides: | 697 // ConstrainedWindowViews, views::Widget overrides: |
689 | 698 |
690 void ConstrainedWindowViews::CenterWindow(const gfx::Size& size) { | 699 void ConstrainedWindowViews::CenterWindow(const gfx::Size& size) { |
691 Widget::CenterWindow(size); | |
692 if (enable_chrome_style_) | 700 if (enable_chrome_style_) |
693 PositionChromeStyleWindow(); | 701 PositionChromeStyleWindow(size); |
702 else | |
703 Widget::CenterWindow(size); | |
694 } | 704 } |
695 | 705 |
696 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { | 706 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { |
697 if (enable_chrome_style_) { | 707 if (enable_chrome_style_) { |
698 return new ConstrainedWindowFrameSimple(this); | 708 ConstrainedWindowFrameSimple* frame = |
709 new ConstrainedWindowFrameSimple(this); | |
710 frame->set_border(views::Border::CreateEmptyBorder( | |
711 client_insets_.top(), | |
712 client_insets_.left(), | |
713 client_insets_.bottom(), | |
714 client_insets_.right())); | |
715 return frame; | |
699 } else { | 716 } else { |
Peter Kasting
2012/10/15 21:46:54
Nit: No else after return
please use gerrit instead
2012/10/16 00:12:23
Done.
| |
700 #if defined(USE_ASH) | 717 #if defined(USE_ASH) |
701 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 718 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
702 if (command_line->HasSwitch(ash::switches::kAuraGoogleDialogFrames)) | 719 if (command_line->HasSwitch(ash::switches::kAuraGoogleDialogFrames)) |
703 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(this); | 720 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(this); |
704 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh; | 721 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh; |
705 frame->Init(this); | 722 frame->Init(this); |
706 return frame; | 723 return frame; |
707 #endif | 724 #endif |
708 return new ConstrainedWindowFrameView(this); | 725 return new ConstrainedWindowFrameView(this); |
709 } | 726 } |
(...skipping 13 matching lines...) Expand all Loading... | |
723 views::internal::NativeWidgetDelegate* | 740 views::internal::NativeWidgetDelegate* |
724 ConstrainedWindowViews::AsNativeWidgetDelegate() { | 741 ConstrainedWindowViews::AsNativeWidgetDelegate() { |
725 return this; | 742 return this; |
726 } | 743 } |
727 | 744 |
728 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) { | 745 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) { |
729 // Prevent a constrained window to be moved by the user. | 746 // Prevent a constrained window to be moved by the user. |
730 return HTNOWHERE; | 747 return HTNOWHERE; |
731 } | 748 } |
732 | 749 |
733 void ConstrainedWindowViews::PositionChromeStyleWindow() { | 750 void ConstrainedWindowViews::PositionChromeStyleWindow(const gfx::Size& size) { |
734 DCHECK(enable_chrome_style_); | 751 DCHECK(enable_chrome_style_); |
735 gfx::Rect bounds = GetRootView()->bounds(); | 752 gfx::Rect bounds(GetRootView()->bounds()); |
753 bounds.set_size(size); | |
Peter Kasting
2012/10/15 21:46:54
Nit: How about:
gfx::rect bounds(GetRootView()-
please use gerrit instead
2012/10/16 00:12:23
That's a cool trick, thanks! Done.
| |
736 ConstrainedWindowTabHelperDelegate* tab_helper_delegate = | 754 ConstrainedWindowTabHelperDelegate* tab_helper_delegate = |
737 ConstrainedWindowTabHelper::FromWebContents(web_contents_)->delegate(); | 755 ConstrainedWindowTabHelper::FromWebContents(web_contents_)->delegate(); |
738 | |
739 BrowserWindow* browser_window = | 756 BrowserWindow* browser_window = |
740 tab_helper_delegate ? tab_helper_delegate->GetBrowserWindow() : NULL; | 757 tab_helper_delegate ? tab_helper_delegate->GetBrowserWindow() : NULL; |
741 int top_y; | 758 int top_y; |
Peter Kasting
2012/10/15 21:46:54
Nit: Declare this inside the conditional
please use gerrit instead
2012/10/16 00:12:23
Done.
| |
742 if (browser_window && browser_window->GetConstrainedWindowTopY(&top_y)) { | 759 if (browser_window) { |
743 bounds.set_y(top_y); | 760 bounds.set_x(browser_window->GetBounds().width() / 2 - bounds.width() / 2); |
744 bounds.set_x( | 761 if (browser_window->GetConstrainedWindowTopY(&top_y)) |
745 browser_window->GetBounds().width() / 2 - bounds.width() / 2); | 762 bounds.set_y(top_y); |
746 SetBounds(bounds); | |
747 } | 763 } |
764 SetBounds(bounds); | |
748 } | 765 } |
749 | 766 |
750 //////////////////////////////////////////////////////////////////////////////// | 767 //////////////////////////////////////////////////////////////////////////////// |
751 // ConstrainedWindowViews, content::WebContentsObserver implementation: | 768 // ConstrainedWindowViews, content::WebContentsObserver implementation: |
752 | 769 |
753 void ConstrainedWindowViews::WebContentsDestroyed( | 770 void ConstrainedWindowViews::WebContentsDestroyed( |
754 content::WebContents* web_contents) { | 771 content::WebContents* web_contents) { |
755 web_contents_ = NULL; | 772 web_contents_ = NULL; |
756 } | 773 } |
774 | |
775 //////////////////////////////////////////////////////////////////////////////// | |
776 // ConstrainedWindowViews, content::NotificationObserver implementation: | |
Peter Kasting
2012/10/15 21:46:54
Nit: This practice of separating each group of ove
please use gerrit instead
2012/10/16 00:12:23
Removed all //////////////. Done.
| |
777 | |
778 void ConstrainedWindowViews::Observe( | |
779 int type, | |
780 const content::NotificationSource& source, | |
781 const content::NotificationDetails& details) { | |
782 if (enable_chrome_style_ && | |
783 type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { | |
Peter Kasting
2012/10/15 21:46:54
Nit: DCHECK_EQ that |type| is this value atop the
please use gerrit instead
2012/10/16 00:12:23
I've added DCHECK(enable_chrome_style_) and DHCECK
| |
784 if (*content::Details<bool>(details).ptr()) | |
785 Show(); | |
786 else | |
787 Hide(); | |
788 } | |
789 } | |
OLD | NEW |