| 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/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/themes/theme_service.h" | 13 #include "chrome/browser/themes/theme_service.h" |
| 14 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 14 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 16 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 16 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 17 #include "chrome/browser/ui/views/constrained_window_frame_simple.h" | 17 #include "chrome/browser/ui/views/constrained_window_frame_simple.h" |
| 18 #include "chrome/browser/ui/views/frame/browser_view.h" | 18 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 19 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_contents_view.h" | 23 #include "content/public/browser/web_contents_view.h" |
| 24 #include "grit/chromium_strings.h" | 24 #include "grit/chromium_strings.h" |
| 25 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 26 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
| 27 #include "grit/ui_resources.h" | 27 #include "grit/ui_resources.h" |
| 28 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
| 29 #include "ui/aura/client/aura_constants.h" |
| 29 #include "ui/base/hit_test.h" | 30 #include "ui/base/hit_test.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/gfx/canvas.h" | 32 #include "ui/gfx/canvas.h" |
| 32 #include "ui/gfx/font.h" | 33 #include "ui/gfx/font.h" |
| 33 #include "ui/gfx/path.h" | 34 #include "ui/gfx/path.h" |
| 34 #include "ui/gfx/rect.h" | 35 #include "ui/gfx/rect.h" |
| 35 #include "ui/gfx/screen.h" | 36 #include "ui/gfx/screen.h" |
| 36 #include "ui/views/color_constants.h" | 37 #include "ui/views/color_constants.h" |
| 37 #include "ui/views/controls/button/image_button.h" | 38 #include "ui/views/controls/button/image_button.h" |
| 38 #include "ui/views/focus/focus_manager.h" | 39 #include "ui/views/focus/focus_manager.h" |
| 39 #include "ui/views/views_delegate.h" | 40 #include "ui/views/views_delegate.h" |
| 40 #include "ui/views/widget/widget.h" | 41 #include "ui/views/widget/widget.h" |
| 41 #include "ui/views/window/client_view.h" | 42 #include "ui/views/window/client_view.h" |
| 42 #include "ui/views/window/frame_background.h" | 43 #include "ui/views/window/frame_background.h" |
| 43 #include "ui/views/window/non_client_view.h" | 44 #include "ui/views/window/non_client_view.h" |
| 44 #include "ui/views/window/window_resources.h" | 45 #include "ui/views/window/window_resources.h" |
| 45 #include "ui/views/window/window_shape.h" | 46 #include "ui/views/window/window_shape.h" |
| 46 | 47 |
| 47 #if defined(OS_WIN) && !defined(USE_AURA) | 48 #if defined(OS_WIN) && !defined(USE_AURA) |
| 48 #include "ui/views/widget/native_widget_win.h" | 49 #include "ui/views/widget/native_widget_win.h" |
| 49 #endif | 50 #endif |
| 50 | 51 |
| 51 #if defined(USE_ASH) | 52 #if defined(USE_ASH) |
| 53 #include "ash/ash_constants.h" |
| 52 #include "ash/ash_switches.h" | 54 #include "ash/ash_switches.h" |
| 53 #include "ash/shell.h" | 55 #include "ash/shell.h" |
| 54 #include "ash/wm/custom_frame_view_ash.h" | 56 #include "ash/wm/custom_frame_view_ash.h" |
| 55 #include "ash/wm/visibility_controller.h" | 57 #include "ash/wm/visibility_controller.h" |
| 56 #include "ui/aura/window.h" | 58 #include "ui/aura/window.h" |
| 57 #endif | 59 #endif |
| 58 | 60 |
| 59 using base::TimeDelta; | 61 using base::TimeDelta; |
| 60 | 62 |
| 61 namespace views { | 63 namespace views { |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { | 581 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { |
| 580 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 582 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 581 params.delegate = widget_delegate; | 583 params.delegate = widget_delegate; |
| 582 params.native_widget = native_constrained_window_->AsNativeWidget(); | 584 params.native_widget = native_constrained_window_->AsNativeWidget(); |
| 583 params.child = true; | 585 params.child = true; |
| 584 params.parent = tab_contents->web_contents()->GetNativeView(); | 586 params.parent = tab_contents->web_contents()->GetNativeView(); |
| 585 #if defined(USE_ASH) | 587 #if defined(USE_ASH) |
| 586 // Ash window headers can be transparent. | 588 // Ash window headers can be transparent. |
| 587 params.transparent = true; | 589 params.transparent = true; |
| 588 ash::SetChildWindowVisibilityChangesAnimated(params.parent); | 590 ash::SetChildWindowVisibilityChangesAnimated(params.parent); |
| 591 // No animations should get performed on the window since that will re-order |
| 592 // the window stack which will then cause many problems. |
| 593 if (params.parent && params.parent->parent()) { |
| 594 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, |
| 595 true); |
| 596 } |
| 589 #endif | 597 #endif |
| 590 Init(params); | 598 Init(params); |
| 591 | 599 |
| 592 tab_contents_->constrained_window_tab_helper()->AddConstrainedDialog(this); | 600 tab_contents_->constrained_window_tab_helper()->AddConstrainedDialog(this); |
| 601 #if defined(USE_ASH) |
| 602 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); |
| 603 #endif |
| 593 } | 604 } |
| 594 | 605 |
| 595 ConstrainedWindowViews::~ConstrainedWindowViews() { | 606 ConstrainedWindowViews::~ConstrainedWindowViews() { |
| 596 } | 607 } |
| 597 | 608 |
| 598 //////////////////////////////////////////////////////////////////////////////// | 609 //////////////////////////////////////////////////////////////////////////////// |
| 599 // ConstrainedWindowViews, ConstrainedWindow implementation: | 610 // ConstrainedWindowViews, ConstrainedWindow implementation: |
| 600 | 611 |
| 601 void ConstrainedWindowViews::ShowConstrainedWindow() { | 612 void ConstrainedWindowViews::ShowConstrainedWindow() { |
| 602 ConstrainedWindowTabHelper* helper = | 613 ConstrainedWindowTabHelper* helper = |
| 603 tab_contents_->constrained_window_tab_helper(); | 614 tab_contents_->constrained_window_tab_helper(); |
| 604 if (helper && helper->delegate()) | 615 if (helper && helper->delegate()) |
| 605 helper->delegate()->WillShowConstrainedWindow(tab_contents_); | 616 helper->delegate()->WillShowConstrainedWindow(tab_contents_); |
| 606 Show(); | 617 Show(); |
| 607 FocusConstrainedWindow(); | 618 FocusConstrainedWindow(); |
| 608 } | 619 } |
| 609 | 620 |
| 610 void ConstrainedWindowViews::CloseConstrainedWindow() { | 621 void ConstrainedWindowViews::CloseConstrainedWindow() { |
| 622 #if defined(USE_ASH) |
| 623 gfx::NativeView view = tab_contents_->web_contents()->GetNativeView(); |
| 624 // Allow the parent to animate again. |
| 625 if (view && view->parent()) |
| 626 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); |
| 627 #endif |
| 611 tab_contents_->constrained_window_tab_helper()->WillClose(this); | 628 tab_contents_->constrained_window_tab_helper()->WillClose(this); |
| 612 Close(); | 629 Close(); |
| 613 } | 630 } |
| 614 | 631 |
| 615 void ConstrainedWindowViews::FocusConstrainedWindow() { | 632 void ConstrainedWindowViews::FocusConstrainedWindow() { |
| 616 ConstrainedWindowTabHelper* helper = | 633 ConstrainedWindowTabHelper* helper = |
| 617 tab_contents_->constrained_window_tab_helper(); | 634 tab_contents_->constrained_window_tab_helper(); |
| 618 if ((!helper->delegate() || | 635 if ((!helper->delegate() || |
| 619 helper->delegate()->ShouldFocusConstrainedWindow()) && | 636 helper->delegate()->ShouldFocusConstrainedWindow()) && |
| 620 widget_delegate() && | 637 widget_delegate() && |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 } | 674 } |
| 658 | 675 |
| 659 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { | 676 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { |
| 660 Activate(); | 677 Activate(); |
| 661 } | 678 } |
| 662 | 679 |
| 663 views::internal::NativeWidgetDelegate* | 680 views::internal::NativeWidgetDelegate* |
| 664 ConstrainedWindowViews::AsNativeWidgetDelegate() { | 681 ConstrainedWindowViews::AsNativeWidgetDelegate() { |
| 665 return this; | 682 return this; |
| 666 } | 683 } |
| 684 |
| 685 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) { |
| 686 // Prevent a constrained window to be moved by the user. |
| 687 return HTNOWHERE; |
| 688 } |
| OLD | NEW |