| 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/constrained_window_tab_helper.h" | |
| 16 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 17 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 17 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" |
| 18 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
| 19 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/browser/web_contents_view.h" | 21 #include "content/public/browser/web_contents_view.h" |
| 22 #include "grit/chromium_strings.h" | 22 #include "grit/chromium_strings.h" |
| 23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 #include "grit/ui_resources.h" | 25 #include "grit/ui_resources.h" |
| 26 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| 27 #include "ui/aura/client/aura_constants.h" | 27 #include "ui/aura/client/aura_constants.h" |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); | 376 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void ConstrainedWindowFrameView::OnThemeChanged() { | 379 void ConstrainedWindowFrameView::OnThemeChanged() { |
| 380 InitWindowResources(); | 380 InitWindowResources(); |
| 381 } | 381 } |
| 382 | 382 |
| 383 void ConstrainedWindowFrameView::ButtonPressed( | 383 void ConstrainedWindowFrameView::ButtonPressed( |
| 384 views::Button* sender, const ui::Event& event) { | 384 views::Button* sender, const ui::Event& event) { |
| 385 if (sender == close_button_) | 385 if (sender == close_button_) |
| 386 container_->CloseConstrainedWindow(); | 386 container_->CloseWebContentsModalDialog(); |
| 387 } | 387 } |
| 388 | 388 |
| 389 int ConstrainedWindowFrameView::NonClientBorderThickness() const { | 389 int ConstrainedWindowFrameView::NonClientBorderThickness() const { |
| 390 return kFrameBorderThickness + kClientEdgeThickness; | 390 return kFrameBorderThickness + kClientEdgeThickness; |
| 391 } | 391 } |
| 392 | 392 |
| 393 int ConstrainedWindowFrameView::NonClientTopBorderHeight() const { | 393 int ConstrainedWindowFrameView::NonClientTopBorderHeight() const { |
| 394 return std::max(kFrameBorderThickness + IconSize(), | 394 return std::max(kFrameBorderThickness + IconSize(), |
| 395 kFrameShadowThickness + kCaptionButtonHeightWithPadding) + | 395 kFrameShadowThickness + kCaptionButtonHeightWithPadding) + |
| 396 TitlebarBottomThickness(); | 396 TitlebarBottomThickness(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 container_ = container; | 542 container_ = container; |
| 543 ash::CustomFrameViewAsh::Init(container); | 543 ash::CustomFrameViewAsh::Init(container); |
| 544 // Always use "active" look. | 544 // Always use "active" look. |
| 545 SetInactiveRenderingDisabled(true); | 545 SetInactiveRenderingDisabled(true); |
| 546 } | 546 } |
| 547 | 547 |
| 548 // views::ButtonListener overrides: | 548 // views::ButtonListener overrides: |
| 549 virtual void ButtonPressed(views::Button* sender, | 549 virtual void ButtonPressed(views::Button* sender, |
| 550 const ui::Event& event) OVERRIDE { | 550 const ui::Event& event) OVERRIDE { |
| 551 if (sender == close_button()) | 551 if (sender == close_button()) |
| 552 container_->CloseConstrainedWindow(); | 552 container_->CloseWebContentsModalDialog(); |
| 553 } | 553 } |
| 554 | 554 |
| 555 private: | 555 private: |
| 556 ConstrainedWindowViews* container_; // not owned | 556 ConstrainedWindowViews* container_; // not owned |
| 557 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh); | 557 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh); |
| 558 }; | 558 }; |
| 559 #endif // defined(USE_ASH) | 559 #endif // defined(USE_ASH) |
| 560 | 560 |
| 561 ConstrainedWindowViews::ConstrainedWindowViews( | 561 ConstrainedWindowViews::ConstrainedWindowViews( |
| 562 content::WebContents* web_contents, | 562 content::WebContents* web_contents, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 577 views::corewm::SetChildWindowVisibilityChangesAnimated(params.parent); | 577 views::corewm::SetChildWindowVisibilityChangesAnimated(params.parent); |
| 578 // No animations should get performed on the window since that will re-order | 578 // No animations should get performed on the window since that will re-order |
| 579 // the window stack which will then cause many problems. | 579 // the window stack which will then cause many problems. |
| 580 if (params.parent && params.parent->parent()) { | 580 if (params.parent && params.parent->parent()) { |
| 581 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, | 581 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, |
| 582 true); | 582 true); |
| 583 } | 583 } |
| 584 #endif | 584 #endif |
| 585 Init(params); | 585 Init(params); |
| 586 | 586 |
| 587 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 587 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 588 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 588 WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 589 constrained_window_tab_helper->AddConstrainedDialog(this); | 589 web_contents_modal_dialog_manager->AddDialog(this); |
| 590 #if defined(USE_ASH) | 590 #if defined(USE_ASH) |
| 591 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); | 591 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); |
| 592 views::corewm::SetModalParent(GetNativeWindow(), | 592 views::corewm::SetModalParent(GetNativeWindow(), |
| 593 web_contents_->GetView()->GetNativeView()); | 593 web_contents_->GetView()->GetNativeView()); |
| 594 #endif | 594 #endif |
| 595 } | 595 } |
| 596 | 596 |
| 597 ConstrainedWindowViews::~ConstrainedWindowViews() { | 597 ConstrainedWindowViews::~ConstrainedWindowViews() { |
| 598 } | 598 } |
| 599 | 599 |
| 600 void ConstrainedWindowViews::ShowConstrainedWindow() { | 600 void ConstrainedWindowViews::ShowWebContentsModalDialog() { |
| 601 Show(); | 601 Show(); |
| 602 FocusConstrainedWindow(); | 602 FocusWebContentsModalDialog(); |
| 603 } | 603 } |
| 604 | 604 |
| 605 void ConstrainedWindowViews::CloseConstrainedWindow() { | 605 void ConstrainedWindowViews::CloseWebContentsModalDialog() { |
| 606 #if defined(USE_ASH) | 606 #if defined(USE_ASH) |
| 607 gfx::NativeView view = web_contents_->GetNativeView(); | 607 gfx::NativeView view = web_contents_->GetNativeView(); |
| 608 // Allow the parent to animate again. | 608 // Allow the parent to animate again. |
| 609 if (view && view->parent()) | 609 if (view && view->parent()) |
| 610 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); | 610 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); |
| 611 #endif | 611 #endif |
| 612 NotifyTabHelperWillClose(); | 612 NotifyTabHelperWillClose(); |
| 613 Close(); | 613 Close(); |
| 614 } | 614 } |
| 615 | 615 |
| 616 void ConstrainedWindowViews::FocusConstrainedWindow() { | 616 void ConstrainedWindowViews::FocusWebContentsModalDialog() { |
| 617 ConstrainedWindowTabHelper* helper = | 617 WebContentsModalDialogManager* manager = |
| 618 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 618 WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 619 if ((!helper->delegate() || | 619 if ((!manager->delegate() || |
| 620 helper->delegate()->ShouldFocusConstrainedWindow()) && | 620 manager->delegate()->ShouldFocusWebContentsModalDialog()) && |
| 621 widget_delegate() && | 621 widget_delegate() && |
| 622 widget_delegate()->GetInitiallyFocusedView()) { | 622 widget_delegate()->GetInitiallyFocusedView()) { |
| 623 widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); | 623 widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); |
| 624 } | 624 } |
| 625 #if defined(USE_ASH) | 625 #if defined(USE_ASH) |
| 626 // We don't necessarily have a RootWindow yet. | 626 // We don't necessarily have a RootWindow yet. |
| 627 if (GetNativeView()->GetRootWindow()) | 627 if (GetNativeView()->GetRootWindow()) |
| 628 GetNativeView()->Focus(); | 628 GetNativeView()->Focus(); |
| 629 #endif | 629 #endif |
| 630 } | 630 } |
| 631 | 631 |
| 632 gfx::NativeWindow ConstrainedWindowViews::GetNativeWindow() { | 632 gfx::NativeWindow ConstrainedWindowViews::GetNativeWindow() { |
| 633 return Widget::GetNativeWindow(); | 633 return Widget::GetNativeWindow(); |
| 634 } | 634 } |
| 635 | 635 |
| 636 void ConstrainedWindowViews::NotifyTabHelperWillClose() { | 636 void ConstrainedWindowViews::NotifyTabHelperWillClose() { |
| 637 if (!web_contents_) | 637 if (!web_contents_) |
| 638 return; | 638 return; |
| 639 | 639 |
| 640 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 640 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 641 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 641 WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 642 constrained_window_tab_helper->WillClose(this); | 642 web_contents_modal_dialog_manager->WillClose(this); |
| 643 } | 643 } |
| 644 | 644 |
| 645 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { | 645 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { |
| 646 #if defined(USE_ASH) | 646 #if defined(USE_ASH) |
| 647 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 647 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 648 if (command_line->HasSwitch(switches::kEnableNewDialogStyle)) | 648 if (command_line->HasSwitch(switches::kEnableNewDialogStyle)) |
| 649 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(this); | 649 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(this); |
| 650 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh; | 650 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh; |
| 651 frame->Init(this); | 651 frame->Init(this); |
| 652 return frame; | 652 return frame; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 664 | 664 |
| 665 views::internal::NativeWidgetDelegate* | 665 views::internal::NativeWidgetDelegate* |
| 666 ConstrainedWindowViews::AsNativeWidgetDelegate() { | 666 ConstrainedWindowViews::AsNativeWidgetDelegate() { |
| 667 return this; | 667 return this; |
| 668 } | 668 } |
| 669 | 669 |
| 670 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) { | 670 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) { |
| 671 // Prevent a constrained window to be moved by the user. | 671 // Prevent a constrained window to be moved by the user. |
| 672 return HTNOWHERE; | 672 return HTNOWHERE; |
| 673 } | 673 } |
| OLD | NEW |