| 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_constants.h" | |
| 17 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 16 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 18 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 17 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 19 #include "chrome/browser/ui/views/constrained_window_frame_simple.h" | 18 #include "chrome/browser/ui/views/constrained_window_frame_simple.h" |
| 20 #include "chrome/browser/ui/views/frame/browser_view.h" | 19 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 21 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 24 #include "content/public/browser/navigation_controller.h" | |
| 25 #include "content/public/browser/notification_service.h" | |
| 26 #include "content/public/browser/notification_source.h" | |
| 27 #include "content/public/browser/notification_types.h" | |
| 28 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/browser/web_contents_view.h" | 24 #include "content/public/browser/web_contents_view.h" |
| 30 #include "grit/chromium_strings.h" | 25 #include "grit/chromium_strings.h" |
| 31 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 32 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
| 33 #include "grit/ui_resources.h" | 28 #include "grit/ui_resources.h" |
| 34 #include "net/base/net_util.h" | 29 #include "net/base/net_util.h" |
| 35 #include "ui/aura/client/aura_constants.h" | 30 #include "ui/aura/client/aura_constants.h" |
| 36 #include "ui/base/hit_test.h" | 31 #include "ui/base/hit_test.h" |
| 37 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 156 } |
| 162 | 157 |
| 163 static gfx::ImageSkia* images_[FRAME_PART_IMAGE_COUNT]; | 158 static gfx::ImageSkia* images_[FRAME_PART_IMAGE_COUNT]; |
| 164 | 159 |
| 165 DISALLOW_COPY_AND_ASSIGN(VistaWindowResources); | 160 DISALLOW_COPY_AND_ASSIGN(VistaWindowResources); |
| 166 }; | 161 }; |
| 167 | 162 |
| 168 gfx::ImageSkia* XPWindowResources::images_[]; | 163 gfx::ImageSkia* XPWindowResources::images_[]; |
| 169 gfx::ImageSkia* VistaWindowResources::images_[]; | 164 gfx::ImageSkia* VistaWindowResources::images_[]; |
| 170 | 165 |
| 166 //////////////////////////////////////////////////////////////////////////////// |
| 167 // ConstrainedWindowFrameView |
| 168 |
| 171 class ConstrainedWindowFrameView : public views::NonClientFrameView, | 169 class ConstrainedWindowFrameView : public views::NonClientFrameView, |
| 172 public views::ButtonListener { | 170 public views::ButtonListener { |
| 173 public: | 171 public: |
| 174 explicit ConstrainedWindowFrameView(ConstrainedWindowViews* container); | 172 explicit ConstrainedWindowFrameView(ConstrainedWindowViews* container); |
| 175 virtual ~ConstrainedWindowFrameView(); | 173 virtual ~ConstrainedWindowFrameView(); |
| 176 | 174 |
| 177 void UpdateWindowTitle(); | 175 void UpdateWindowTitle(); |
| 178 | 176 |
| 179 // Overridden from views::NonClientFrameView: | 177 // Overridden from views::NonClientFrameView: |
| 180 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; | 178 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 const int kIconMinimumSize = 16; | 278 const int kIconMinimumSize = 16; |
| 281 // The title text starts 2 px from the right edge of the left frame border. | 279 // The title text starts 2 px from the right edge of the left frame border. |
| 282 const int kTitleLeftSpacing = 2; | 280 const int kTitleLeftSpacing = 2; |
| 283 // There is a 5 px gap between the title text and the caption buttons. | 281 // There is a 5 px gap between the title text and the caption buttons. |
| 284 const int kTitleCaptionSpacing = 5; | 282 const int kTitleCaptionSpacing = 5; |
| 285 | 283 |
| 286 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0); | 284 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0); |
| 287 | 285 |
| 288 } // namespace | 286 } // namespace |
| 289 | 287 |
| 288 //////////////////////////////////////////////////////////////////////////////// |
| 289 // ConstrainedWindowFrameView, public: |
| 290 |
| 290 ConstrainedWindowFrameView::ConstrainedWindowFrameView( | 291 ConstrainedWindowFrameView::ConstrainedWindowFrameView( |
| 291 ConstrainedWindowViews* container) | 292 ConstrainedWindowViews* container) |
| 292 : NonClientFrameView(), | 293 : NonClientFrameView(), |
| 293 container_(container), | 294 container_(container), |
| 294 close_button_(new views::ImageButton(this)), | 295 close_button_(new views::ImageButton(this)), |
| 295 frame_background_(new views::FrameBackground()) { | 296 frame_background_(new views::FrameBackground()) { |
| 296 InitClass(); | 297 InitClass(); |
| 297 InitWindowResources(); | 298 InitWindowResources(); |
| 298 | 299 |
| 299 // Constrained windows always use the custom frame - they just have a | 300 // Constrained windows always use the custom frame - they just have a |
| (...skipping 12 matching lines...) Expand all Loading... |
| 312 AddChildView(close_button_); | 313 AddChildView(close_button_); |
| 313 } | 314 } |
| 314 | 315 |
| 315 ConstrainedWindowFrameView::~ConstrainedWindowFrameView() { | 316 ConstrainedWindowFrameView::~ConstrainedWindowFrameView() { |
| 316 } | 317 } |
| 317 | 318 |
| 318 void ConstrainedWindowFrameView::UpdateWindowTitle() { | 319 void ConstrainedWindowFrameView::UpdateWindowTitle() { |
| 319 SchedulePaintInRect(title_bounds_); | 320 SchedulePaintInRect(title_bounds_); |
| 320 } | 321 } |
| 321 | 322 |
| 323 //////////////////////////////////////////////////////////////////////////////// |
| 324 // ConstrainedWindowFrameView, views::NonClientFrameView implementation: |
| 325 |
| 322 gfx::Rect ConstrainedWindowFrameView::GetBoundsForClientView() const { | 326 gfx::Rect ConstrainedWindowFrameView::GetBoundsForClientView() const { |
| 323 return client_view_bounds_; | 327 return client_view_bounds_; |
| 324 } | 328 } |
| 325 | 329 |
| 326 gfx::Rect ConstrainedWindowFrameView::GetWindowBoundsForClientBounds( | 330 gfx::Rect ConstrainedWindowFrameView::GetWindowBoundsForClientBounds( |
| 327 const gfx::Rect& client_bounds) const { | 331 const gfx::Rect& client_bounds) const { |
| 328 int top_height = NonClientTopBorderHeight(); | 332 int top_height = NonClientTopBorderHeight(); |
| 329 int border_thickness = NonClientBorderThickness(); | 333 int border_thickness = NonClientBorderThickness(); |
| 330 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness), | 334 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness), |
| 331 std::max(0, client_bounds.y() - top_height), | 335 std::max(0, client_bounds.y() - top_height), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 360 // Fall back to the caption if no other component matches. | 364 // Fall back to the caption if no other component matches. |
| 361 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; | 365 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; |
| 362 } | 366 } |
| 363 | 367 |
| 364 void ConstrainedWindowFrameView::GetWindowMask(const gfx::Size& size, | 368 void ConstrainedWindowFrameView::GetWindowMask(const gfx::Size& size, |
| 365 gfx::Path* window_mask) { | 369 gfx::Path* window_mask) { |
| 366 DCHECK(window_mask); | 370 DCHECK(window_mask); |
| 367 views::GetDefaultWindowMask(size, window_mask); | 371 views::GetDefaultWindowMask(size, window_mask); |
| 368 } | 372 } |
| 369 | 373 |
| 374 //////////////////////////////////////////////////////////////////////////////// |
| 375 // ConstrainedWindowFrameView, views::View implementation: |
| 376 |
| 370 void ConstrainedWindowFrameView::OnPaint(gfx::Canvas* canvas) { | 377 void ConstrainedWindowFrameView::OnPaint(gfx::Canvas* canvas) { |
| 371 PaintFrameBorder(canvas); | 378 PaintFrameBorder(canvas); |
| 372 PaintTitleBar(canvas); | 379 PaintTitleBar(canvas); |
| 373 PaintClientEdge(canvas); | 380 PaintClientEdge(canvas); |
| 374 } | 381 } |
| 375 | 382 |
| 376 void ConstrainedWindowFrameView::Layout() { | 383 void ConstrainedWindowFrameView::Layout() { |
| 377 LayoutWindowControls(); | 384 LayoutWindowControls(); |
| 378 LayoutTitleBar(); | 385 LayoutTitleBar(); |
| 379 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); | 386 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); |
| 380 } | 387 } |
| 381 | 388 |
| 382 void ConstrainedWindowFrameView::OnThemeChanged() { | 389 void ConstrainedWindowFrameView::OnThemeChanged() { |
| 383 InitWindowResources(); | 390 InitWindowResources(); |
| 384 } | 391 } |
| 385 | 392 |
| 393 //////////////////////////////////////////////////////////////////////////////// |
| 394 // ConstrainedWindowFrameView, views::ButtonListener implementation: |
| 395 |
| 386 void ConstrainedWindowFrameView::ButtonPressed( | 396 void ConstrainedWindowFrameView::ButtonPressed( |
| 387 views::Button* sender, const ui::Event& event) { | 397 views::Button* sender, const ui::Event& event) { |
| 388 if (sender == close_button_) | 398 if (sender == close_button_) |
| 389 container_->CloseConstrainedWindow(); | 399 container_->CloseConstrainedWindow(); |
| 390 } | 400 } |
| 391 | 401 |
| 402 //////////////////////////////////////////////////////////////////////////////// |
| 403 // ConstrainedWindowFrameView, private: |
| 404 |
| 392 int ConstrainedWindowFrameView::NonClientBorderThickness() const { | 405 int ConstrainedWindowFrameView::NonClientBorderThickness() const { |
| 393 return kFrameBorderThickness + kClientEdgeThickness; | 406 return kFrameBorderThickness + kClientEdgeThickness; |
| 394 } | 407 } |
| 395 | 408 |
| 396 int ConstrainedWindowFrameView::NonClientTopBorderHeight() const { | 409 int ConstrainedWindowFrameView::NonClientTopBorderHeight() const { |
| 397 return std::max(kFrameBorderThickness + IconSize(), | 410 return std::max(kFrameBorderThickness + IconSize(), |
| 398 kFrameShadowThickness + kCaptionButtonHeightWithPadding) + | 411 kFrameShadowThickness + kCaptionButtonHeightWithPadding) + |
| 399 TitlebarBottomThickness(); | 412 TitlebarBottomThickness(); |
| 400 } | 413 } |
| 401 | 414 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 if (sender == close_button()) | 567 if (sender == close_button()) |
| 555 container_->CloseConstrainedWindow(); | 568 container_->CloseConstrainedWindow(); |
| 556 } | 569 } |
| 557 | 570 |
| 558 private: | 571 private: |
| 559 ConstrainedWindowViews* container_; // not owned | 572 ConstrainedWindowViews* container_; // not owned |
| 560 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh); | 573 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh); |
| 561 }; | 574 }; |
| 562 #endif // defined(USE_ASH) | 575 #endif // defined(USE_ASH) |
| 563 | 576 |
| 577 //////////////////////////////////////////////////////////////////////////////// |
| 578 // ConstrainedWindowViews, public: |
| 579 |
| 564 ConstrainedWindowViews::ConstrainedWindowViews( | 580 ConstrainedWindowViews::ConstrainedWindowViews( |
| 565 content::WebContents* web_contents, | 581 content::WebContents* web_contents, |
| 566 views::WidgetDelegate* widget_delegate, | 582 views::WidgetDelegate* widget_delegate, |
| 567 bool enable_chrome_style, | 583 bool enable_chrome_style) |
| 568 ChromeStyleClientInsets chrome_style_client_insets) | |
| 569 : WebContentsObserver(web_contents), | 584 : WebContentsObserver(web_contents), |
| 570 web_contents_(web_contents), | 585 web_contents_(web_contents), |
| 571 enable_chrome_style_(enable_chrome_style), | |
| 572 chrome_style_client_insets_(chrome_style_client_insets), | |
| 573 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( | 586 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( |
| 574 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { | 587 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))), |
| 588 enable_chrome_style_(enable_chrome_style) { |
| 575 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 589 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 576 params.delegate = widget_delegate; | 590 params.delegate = widget_delegate; |
| 577 params.native_widget = native_constrained_window_->AsNativeWidget(); | 591 params.native_widget = native_constrained_window_->AsNativeWidget(); |
| 578 params.child = true; | 592 params.child = true; |
| 579 ConstrainedWindowTabHelper::CreateForWebContents(web_contents); | 593 ConstrainedWindowTabHelper::CreateForWebContents(web_contents); |
| 580 | 594 |
| 581 if (enable_chrome_style_) { | 595 if (enable_chrome_style_) { |
| 582 params.parent_widget = Widget::GetTopLevelWidgetForNativeView( | 596 params.parent_widget = Widget::GetTopLevelWidgetForNativeView( |
| 583 web_contents_->GetView()->GetNativeView()); | 597 web_contents->GetView()->GetNativeView()); |
| 584 } else { | 598 } else { |
| 585 params.parent = web_contents_->GetNativeView(); | 599 params.parent = web_contents->GetNativeView(); |
| 586 } | 600 } |
| 587 | 601 |
| 588 #if defined(USE_ASH) | 602 #if defined(USE_ASH) |
| 589 // Ash window headers can be transparent. | 603 // Ash window headers can be transparent. |
| 590 params.transparent = true; | 604 params.transparent = true; |
| 591 ash::SetChildWindowVisibilityChangesAnimated(params.GetParent()); | 605 ash::SetChildWindowVisibilityChangesAnimated(params.GetParent()); |
| 592 // No animations should get performed on the window since that will re-order | 606 // No animations should get performed on the window since that will re-order |
| 593 // the window stack which will then cause many problems. | 607 // the window stack which will then cause many problems. |
| 594 if (params.parent && params.parent->parent()) { | 608 if (params.parent && params.parent->parent()) { |
| 595 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, | 609 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, |
| 596 true); | 610 true); |
| 597 } | 611 } |
| 598 #endif | 612 #endif |
| 599 Init(params); | 613 Init(params); |
| 600 | 614 |
| 601 if (enable_chrome_style_) { | 615 if (enable_chrome_style_) { |
| 602 // Set the dialog background color. | 616 // Set the dialog background color. |
| 603 if (widget_delegate && widget_delegate->AsDialogDelegate()) { | 617 if (widget_delegate && widget_delegate->AsDialogDelegate()) { |
| 604 views::Background* background = views::Background::CreateSolidBackground( | 618 views::Background* background = views::Background::CreateSolidBackground( |
| 605 ConstrainedWindow::GetBackgroundColor()); | 619 ConstrainedWindow::GetBackgroundColor()); |
| 606 views::DialogClientView* dialog_client_view = | 620 views::DialogClientView* dialog_client_view = |
| 607 widget_delegate->AsDialogDelegate()->GetDialogClientView(); | 621 widget_delegate->AsDialogDelegate()->GetDialogClientView(); |
| 608 if (dialog_client_view) | 622 if (dialog_client_view) |
| 609 dialog_client_view->set_background(background); | 623 dialog_client_view->set_background(background); |
| 610 } | 624 } |
| 611 PositionChromeStyleWindow(GetRootView()->bounds().size()); | 625 PositionChromeStyleWindow(); |
| 612 registrar_.Add(this, | |
| 613 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | |
| 614 content::Source<content::WebContents>(web_contents)); | |
| 615 } | 626 } |
| 616 | 627 |
| 617 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 628 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
| 618 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 629 ConstrainedWindowTabHelper::FromWebContents(web_contents_); |
| 619 constrained_window_tab_helper->AddConstrainedDialog(this); | 630 constrained_window_tab_helper->AddConstrainedDialog(this); |
| 620 #if defined(USE_ASH) | 631 #if defined(USE_ASH) |
| 621 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); | 632 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); |
| 622 #endif | 633 #endif |
| 623 } | 634 } |
| 624 | 635 |
| 625 ConstrainedWindowViews::~ConstrainedWindowViews() { | 636 ConstrainedWindowViews::~ConstrainedWindowViews() { |
| 626 } | 637 } |
| 627 | 638 |
| 639 //////////////////////////////////////////////////////////////////////////////// |
| 640 // ConstrainedWindowViews, ConstrainedWindow implementation: |
| 641 |
| 628 void ConstrainedWindowViews::ShowConstrainedWindow() { | 642 void ConstrainedWindowViews::ShowConstrainedWindow() { |
| 629 Show(); | 643 Show(); |
| 630 FocusConstrainedWindow(); | 644 FocusConstrainedWindow(); |
| 631 } | 645 } |
| 632 | 646 |
| 633 void ConstrainedWindowViews::CloseConstrainedWindow() { | 647 void ConstrainedWindowViews::CloseConstrainedWindow() { |
| 634 #if defined(USE_ASH) | 648 #if defined(USE_ASH) |
| 635 gfx::NativeView view = web_contents_->GetNativeView(); | 649 gfx::NativeView view = web_contents_->GetNativeView(); |
| 636 // Allow the parent to animate again. | 650 // Allow the parent to animate again. |
| 637 if (view && view->parent()) | 651 if (view && view->parent()) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 663 | 677 |
| 664 void ConstrainedWindowViews::NotifyTabHelperWillClose() { | 678 void ConstrainedWindowViews::NotifyTabHelperWillClose() { |
| 665 if (!web_contents_) | 679 if (!web_contents_) |
| 666 return; | 680 return; |
| 667 | 681 |
| 668 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 682 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
| 669 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 683 ConstrainedWindowTabHelper::FromWebContents(web_contents_); |
| 670 constrained_window_tab_helper->WillClose(this); | 684 constrained_window_tab_helper->WillClose(this); |
| 671 } | 685 } |
| 672 | 686 |
| 687 //////////////////////////////////////////////////////////////////////////////// |
| 688 // ConstrainedWindowViews, views::Widget overrides: |
| 689 |
| 673 void ConstrainedWindowViews::CenterWindow(const gfx::Size& size) { | 690 void ConstrainedWindowViews::CenterWindow(const gfx::Size& size) { |
| 691 Widget::CenterWindow(size); |
| 674 if (enable_chrome_style_) | 692 if (enable_chrome_style_) |
| 675 PositionChromeStyleWindow(size); | 693 PositionChromeStyleWindow(); |
| 676 else | |
| 677 Widget::CenterWindow(size); | |
| 678 } | 694 } |
| 679 | 695 |
| 680 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { | 696 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { |
| 681 if (enable_chrome_style_) | 697 if (enable_chrome_style_) { |
| 682 return new ConstrainedWindowFrameSimple(this, chrome_style_client_insets_); | 698 return new ConstrainedWindowFrameSimple(this); |
| 699 } else { |
| 683 #if defined(USE_ASH) | 700 #if defined(USE_ASH) |
| 684 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 701 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 685 if (command_line->HasSwitch(ash::switches::kAuraGoogleDialogFrames)) | 702 if (command_line->HasSwitch(ash::switches::kAuraGoogleDialogFrames)) |
| 686 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(this); | 703 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(this); |
| 687 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh; | 704 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh; |
| 688 frame->Init(this); | 705 frame->Init(this); |
| 689 return frame; | 706 return frame; |
| 690 #endif | 707 #endif |
| 691 return new ConstrainedWindowFrameView(this); | 708 return new ConstrainedWindowFrameView(this); |
| 709 } |
| 692 } | 710 } |
| 693 | 711 |
| 712 //////////////////////////////////////////////////////////////////////////////// |
| 713 // ConstrainedWindowViews, NativeConstrainedWindowDelegate implementation: |
| 714 |
| 694 void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() { | 715 void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() { |
| 695 NotifyTabHelperWillClose(); | 716 NotifyTabHelperWillClose(); |
| 696 } | 717 } |
| 697 | 718 |
| 698 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { | 719 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { |
| 699 Activate(); | 720 Activate(); |
| 700 } | 721 } |
| 701 | 722 |
| 702 views::internal::NativeWidgetDelegate* | 723 views::internal::NativeWidgetDelegate* |
| 703 ConstrainedWindowViews::AsNativeWidgetDelegate() { | 724 ConstrainedWindowViews::AsNativeWidgetDelegate() { |
| 704 return this; | 725 return this; |
| 705 } | 726 } |
| 706 | 727 |
| 707 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) { | 728 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) { |
| 708 // Prevent a constrained window to be moved by the user. | 729 // Prevent a constrained window to be moved by the user. |
| 709 return HTNOWHERE; | 730 return HTNOWHERE; |
| 710 } | 731 } |
| 711 | 732 |
| 733 void ConstrainedWindowViews::PositionChromeStyleWindow() { |
| 734 DCHECK(enable_chrome_style_); |
| 735 gfx::Rect bounds = GetRootView()->bounds(); |
| 736 ConstrainedWindowTabHelperDelegate* tab_helper_delegate = |
| 737 ConstrainedWindowTabHelper::FromWebContents(web_contents_)->delegate(); |
| 738 |
| 739 BrowserWindow* browser_window = |
| 740 tab_helper_delegate ? tab_helper_delegate->GetBrowserWindow() : NULL; |
| 741 int top_y; |
| 742 if (browser_window && browser_window->GetConstrainedWindowTopY(&top_y)) { |
| 743 bounds.set_y(top_y); |
| 744 bounds.set_x( |
| 745 browser_window->GetBounds().width() / 2 - bounds.width() / 2); |
| 746 SetBounds(bounds); |
| 747 } |
| 748 } |
| 749 |
| 750 //////////////////////////////////////////////////////////////////////////////// |
| 751 // ConstrainedWindowViews, content::WebContentsObserver implementation: |
| 752 |
| 712 void ConstrainedWindowViews::WebContentsDestroyed( | 753 void ConstrainedWindowViews::WebContentsDestroyed( |
| 713 content::WebContents* web_contents) { | 754 content::WebContents* web_contents) { |
| 714 web_contents_ = NULL; | 755 web_contents_ = NULL; |
| 715 } | 756 } |
| 716 | |
| 717 void ConstrainedWindowViews::Observe( | |
| 718 int type, | |
| 719 const content::NotificationSource& source, | |
| 720 const content::NotificationDetails& details) { | |
| 721 DCHECK(enable_chrome_style_); | |
| 722 DCHECK_EQ(type, content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED); | |
| 723 if (*content::Details<bool>(details).ptr()) | |
| 724 Show(); | |
| 725 else | |
| 726 Hide(); | |
| 727 } | |
| 728 | |
| 729 void ConstrainedWindowViews::PositionChromeStyleWindow(const gfx::Size& size) { | |
| 730 DCHECK(enable_chrome_style_); | |
| 731 gfx::Rect bounds(GetRootView()->bounds().origin(), size); | |
| 732 ConstrainedWindowTabHelperDelegate* tab_helper_delegate = | |
| 733 ConstrainedWindowTabHelper::FromWebContents(web_contents_)->delegate(); | |
| 734 BrowserWindow* browser_window = | |
| 735 tab_helper_delegate ? tab_helper_delegate->GetBrowserWindow() : NULL; | |
| 736 if (browser_window) { | |
| 737 bounds.set_x(browser_window->GetBounds().width() / 2 - bounds.width() / 2); | |
| 738 int top_y; | |
| 739 if (browser_window->GetConstrainedWindowTopY(&top_y)) | |
| 740 bounds.set_y(top_y); | |
| 741 } | |
| 742 SetBounds(bounds); | |
| 743 } | |
| OLD | NEW |