| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 12 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 14 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 13 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 14 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" | 16 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" |
| 15 #include "chrome/browser/ui/window_sizer.h" | 17 #include "chrome/browser/ui/window_sizer.h" |
| 16 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
| 19 #include "content/browser/tab_contents/tab_contents_view.h" | 21 #include "content/browser/tab_contents/tab_contents_view.h" |
| 20 #include "content/common/notification_service.h" | 22 #include "content/common/notification_service.h" |
| 21 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 void PaintClientEdge(gfx::Canvas* canvas); | 206 void PaintClientEdge(gfx::Canvas* canvas); |
| 205 | 207 |
| 206 // Layout various sub-components of this view. | 208 // Layout various sub-components of this view. |
| 207 void LayoutWindowControls(); | 209 void LayoutWindowControls(); |
| 208 void LayoutTitleBar(); | 210 void LayoutTitleBar(); |
| 209 | 211 |
| 210 // Returns the bounds of the client area for the specified view size. | 212 // Returns the bounds of the client area for the specified view size. |
| 211 gfx::Rect CalculateClientAreaBounds(int width, int height) const; | 213 gfx::Rect CalculateClientAreaBounds(int width, int height) const; |
| 212 | 214 |
| 213 SkColor GetTitleColor() const { | 215 SkColor GetTitleColor() const { |
| 214 return container_->owner()->browser_context()->IsOffTheRecord() | 216 return container_->owner()->profile()->IsOffTheRecord() |
| 215 #if defined(OS_WIN) && !defined(USE_AURA) | 217 #if defined(OS_WIN) && !defined(USE_AURA) |
| 216 || !views::NativeWidgetWin::IsAeroGlassEnabled() | 218 || !views::NativeWidgetWin::IsAeroGlassEnabled() |
| 217 #endif | 219 #endif |
| 218 ? SK_ColorWHITE : SK_ColorBLACK; | 220 ? SK_ColorWHITE : SK_ColorBLACK; |
| 219 } | 221 } |
| 220 | 222 |
| 221 // Loads the appropriate set of WindowResources for the frame view. | 223 // Loads the appropriate set of WindowResources for the frame view. |
| 222 void InitWindowResources(); | 224 void InitWindowResources(); |
| 223 | 225 |
| 224 ConstrainedWindowViews* container_; | 226 ConstrainedWindowViews* container_; |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 title_font_ = &resources.GetFont(ResourceBundle::MediumFont); | 583 title_font_ = &resources.GetFont(ResourceBundle::MediumFont); |
| 582 #endif | 584 #endif |
| 583 initialized = true; | 585 initialized = true; |
| 584 } | 586 } |
| 585 } | 587 } |
| 586 | 588 |
| 587 //////////////////////////////////////////////////////////////////////////////// | 589 //////////////////////////////////////////////////////////////////////////////// |
| 588 // ConstrainedWindowViews, public: | 590 // ConstrainedWindowViews, public: |
| 589 | 591 |
| 590 ConstrainedWindowViews::ConstrainedWindowViews( | 592 ConstrainedWindowViews::ConstrainedWindowViews( |
| 591 TabContents* owner, | 593 TabContentsWrapper* wrapper, |
| 592 views::WidgetDelegate* widget_delegate) | 594 views::WidgetDelegate* widget_delegate) |
| 593 : owner_(owner), | 595 : wrapper_(wrapper), |
| 594 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( | 596 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( |
| 595 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { | 597 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { |
| 596 views::Widget::InitParams params; | 598 views::Widget::InitParams params; |
| 597 params.delegate = widget_delegate; | 599 params.delegate = widget_delegate; |
| 598 params.native_widget = native_constrained_window_->AsNativeWidget(); | 600 params.native_widget = native_constrained_window_->AsNativeWidget(); |
| 599 | 601 |
| 600 if (views::Widget::IsPureViews()) { | 602 if (views::Widget::IsPureViews()) { |
| 601 if (views::ViewsDelegate::views_delegate && | 603 if (views::ViewsDelegate::views_delegate && |
| 602 views::ViewsDelegate::views_delegate->GetDefaultParentView()) { | 604 views::ViewsDelegate::views_delegate->GetDefaultParentView()) { |
| 603 // Don't set parent so that constrained window is attached to | 605 // Don't set parent so that constrained window is attached to |
| 604 // desktop. This is necessary for key events to work under views desktop | 606 // desktop. This is necessary for key events to work under views desktop |
| 605 // because key events need to be sent to toplevel window | 607 // because key events need to be sent to toplevel window |
| 606 // which has an inputmethod object that knows where to forward | 608 // which has an inputmethod object that knows where to forward |
| 607 // event. | 609 // event. |
| 608 } else { | 610 } else { |
| 609 params.parent_widget = static_cast<TabContentsViewViews*>(owner->view()); | 611 params.parent_widget = |
| 612 static_cast<TabContentsViewViews*>(wrapper->view()); |
| 610 } | 613 } |
| 611 } else { | 614 } else { |
| 612 params.child = true; | 615 params.child = true; |
| 613 params.parent = owner->GetNativeView(); | 616 params.parent = wrapper->tab_contents()->GetNativeView(); |
| 614 } | 617 } |
| 615 | 618 |
| 616 Init(params); | 619 Init(params); |
| 617 owner->AddConstrainedDialog(this); | 620 |
| 621 wrapper_->constrained_window_tab_helper()->AddConstrainedDialog(this); |
| 618 } | 622 } |
| 619 | 623 |
| 620 ConstrainedWindowViews::~ConstrainedWindowViews() { | 624 ConstrainedWindowViews::~ConstrainedWindowViews() { |
| 621 } | 625 } |
| 622 | 626 |
| 623 //////////////////////////////////////////////////////////////////////////////// | 627 //////////////////////////////////////////////////////////////////////////////// |
| 624 // ConstrainedWindowViews, ConstrainedWindow implementation: | 628 // ConstrainedWindowViews, ConstrainedWindow implementation: |
| 625 | 629 |
| 626 void ConstrainedWindowViews::ShowConstrainedWindow() { | 630 void ConstrainedWindowViews::ShowConstrainedWindow() { |
| 627 // We marked the view as hidden during construction. Mark it as | 631 // We marked the view as hidden during construction. Mark it as |
| 628 // visible now so FocusManager will let us receive focus. | 632 // visible now so FocusManager will let us receive focus. |
| 629 non_client_view()->SetVisible(true); | 633 non_client_view()->SetVisible(true); |
| 630 if (owner_->delegate()) | 634 ConstrainedWindowTabHelper* helper = |
| 631 owner_->delegate()->WillShowConstrainedWindow(owner_); | 635 wrapper_->constrained_window_tab_helper(); |
| 636 if (helper && helper->delegate()) |
| 637 helper->delegate()->WillShowConstrainedWindow(wrapper_); |
| 632 Activate(); | 638 Activate(); |
| 633 FocusConstrainedWindow(); | 639 FocusConstrainedWindow(); |
| 634 } | 640 } |
| 635 | 641 |
| 636 void ConstrainedWindowViews::CloseConstrainedWindow() { | 642 void ConstrainedWindowViews::CloseConstrainedWindow() { |
| 637 owner_->WillClose(this); | 643 wrapper_->constrained_window_tab_helper()->WillClose(this); |
| 638 Close(); | 644 Close(); |
| 639 } | 645 } |
| 640 | 646 |
| 641 void ConstrainedWindowViews::FocusConstrainedWindow() { | 647 void ConstrainedWindowViews::FocusConstrainedWindow() { |
| 642 if ((!owner_->delegate() || | 648 ConstrainedWindowTabHelper* helper = |
| 643 owner_->delegate()->ShouldFocusConstrainedWindow()) && | 649 wrapper_->constrained_window_tab_helper(); |
| 650 if ((!helper->delegate() || |
| 651 helper->delegate()->ShouldFocusConstrainedWindow()) && |
| 644 widget_delegate() && | 652 widget_delegate() && |
| 645 widget_delegate()->GetInitiallyFocusedView()) { | 653 widget_delegate()->GetInitiallyFocusedView()) { |
| 646 widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); | 654 widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); |
| 647 } | 655 } |
| 648 } | 656 } |
| 649 | 657 |
| 650 //////////////////////////////////////////////////////////////////////////////// | 658 //////////////////////////////////////////////////////////////////////////////// |
| 651 // ConstrainedWindowViews, views::Window overrides: | 659 // ConstrainedWindowViews, views::Window overrides: |
| 652 | 660 |
| 653 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { | 661 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { |
| 654 return new ConstrainedWindowFrameView(this); | 662 return new ConstrainedWindowFrameView(this); |
| 655 } | 663 } |
| 656 | 664 |
| 657 //////////////////////////////////////////////////////////////////////////////// | 665 //////////////////////////////////////////////////////////////////////////////// |
| 658 // ConstrainedWindowViews, NativeConstrainedWindowDelegate implementation: | 666 // ConstrainedWindowViews, NativeConstrainedWindowDelegate implementation: |
| 659 | 667 |
| 660 void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() { | 668 void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() { |
| 661 // Tell our constraining TabContents that we've gone so it can update its | 669 wrapper_->constrained_window_tab_helper()->WillClose(this); |
| 662 // list. | |
| 663 owner_->WillClose(this); | |
| 664 } | 670 } |
| 665 | 671 |
| 666 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { | 672 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { |
| 667 Activate(); | 673 Activate(); |
| 668 } | 674 } |
| 669 | 675 |
| 670 views::internal::NativeWidgetDelegate* | 676 views::internal::NativeWidgetDelegate* |
| 671 ConstrainedWindowViews::AsNativeWidgetDelegate() { | 677 ConstrainedWindowViews::AsNativeWidgetDelegate() { |
| 672 return this; | 678 return this; |
| 673 } | 679 } |
| OLD | NEW |