| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/frame/browser_view_layout.h" | 5 #include "chrome/browser/ui/views/frame/browser_view_layout.h" |
| 6 | 6 |
| 7 #include "base/observer_list.h" | 7 #include "base/observer_list.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 class BrowserViewLayout::WebContentsModalDialogHostViews | 61 class BrowserViewLayout::WebContentsModalDialogHostViews |
| 62 : public WebContentsModalDialogHost { | 62 : public WebContentsModalDialogHost { |
| 63 public: | 63 public: |
| 64 explicit WebContentsModalDialogHostViews( | 64 explicit WebContentsModalDialogHostViews( |
| 65 BrowserViewLayout* browser_view_layout) | 65 BrowserViewLayout* browser_view_layout) |
| 66 : browser_view_layout_(browser_view_layout) { | 66 : browser_view_layout_(browser_view_layout) { |
| 67 } | 67 } |
| 68 | 68 |
| 69 virtual ~WebContentsModalDialogHostViews() { | 69 virtual ~WebContentsModalDialogHostViews() { |
| 70 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, | 70 FOR_EACH_OBSERVER(ModalDialogHostObserver, |
| 71 observer_list_, | 71 observer_list_, |
| 72 OnHostDestroying()); | 72 OnHostDestroying()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void NotifyPositionRequiresUpdate() { | 75 void NotifyPositionRequiresUpdate() { |
| 76 FOR_EACH_OBSERVER(ModalDialogHostObserver, | 76 FOR_EACH_OBSERVER(ModalDialogHostObserver, |
| 77 observer_list_, | 77 observer_list_, |
| 78 OnPositionRequiresUpdate()); | 78 OnPositionRequiresUpdate()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Center horizontally over the content area, with the top overlapping the | |
| 82 // browser chrome. | |
| 83 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE { | 81 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE { |
| 84 int top_y = browser_view_layout_->web_contents_modal_dialog_top_y_; | 82 views::View* view = browser_view_layout_->delegate_->GetContentsWebView(); |
| 85 views::View* contents_container = | 83 gfx::Rect content_area = view->ConvertRectToWidget(view->GetLocalBounds()); |
| 86 browser_view_layout_->contents_container_; | 84 const int middle_x = content_area.x() + content_area.width() / 2; |
| 87 gfx::Rect contents_container_bounds_in_widget = | 85 const int top = browser_view_layout_->web_contents_modal_dialog_top_y_; |
| 88 contents_container->ConvertRectToWidget( | 86 return gfx::Point(middle_x - size.width() / 2, top); |
| 89 contents_container->GetLocalBounds()); | 87 } |
| 90 int middle_x = contents_container_bounds_in_widget.x() + | 88 |
| 91 contents_container_bounds_in_widget.width() / 2; | 89 virtual gfx::Size GetMaximumDialogSize() OVERRIDE { |
| 92 return gfx::Point(middle_x - size.width() / 2, top_y); | 90 views::View* view = browser_view_layout_->delegate_->GetContentsWebView(); |
| 91 gfx::Rect content_area = view->ConvertRectToWidget(view->GetLocalBounds()); |
| 92 const int top = browser_view_layout_->web_contents_modal_dialog_top_y_; |
| 93 return gfx::Size(content_area.width(), content_area.bottom() - top); |
| 93 } | 94 } |
| 94 | 95 |
| 95 private: | 96 private: |
| 96 virtual gfx::NativeView GetHostView() const OVERRIDE { | 97 virtual gfx::NativeView GetHostView() const OVERRIDE { |
| 97 gfx::NativeWindow native_window = | 98 gfx::NativeWindow window = |
| 98 browser_view_layout_->browser()->window()->GetNativeWindow(); | 99 browser_view_layout_->browser()->window()->GetNativeWindow(); |
| 99 return views::Widget::GetWidgetForNativeWindow(native_window)-> | 100 return views::Widget::GetWidgetForNativeWindow(window)->GetNativeView(); |
| 100 GetNativeView(); | |
| 101 } | |
| 102 | |
| 103 virtual gfx::Size GetMaximumDialogSize() OVERRIDE { | |
| 104 gfx::Rect content_area = | |
| 105 browser_view_layout_->contents_container_->ConvertRectToWidget( | |
| 106 browser_view_layout_->contents_container_->GetLocalBounds()); | |
| 107 | |
| 108 gfx::Size max_dialog_size = content_area.size(); | |
| 109 // Adjust for difference in alignment between the dialog top and the top of | |
| 110 // the content area. | |
| 111 int height_offset = content_area.y() - | |
| 112 browser_view_layout_->web_contents_modal_dialog_top_y_; | |
| 113 max_dialog_size.Enlarge(0, height_offset); | |
| 114 return max_dialog_size; | |
| 115 } | 101 } |
| 116 | 102 |
| 117 // Add/remove observer. | 103 // Add/remove observer. |
| 118 virtual void AddObserver( | 104 virtual void AddObserver(ModalDialogHostObserver* observer) OVERRIDE { |
| 119 ModalDialogHostObserver* observer) OVERRIDE { | |
| 120 observer_list_.AddObserver(observer); | 105 observer_list_.AddObserver(observer); |
| 121 } | 106 } |
| 122 virtual void RemoveObserver( | 107 virtual void RemoveObserver(ModalDialogHostObserver* observer) OVERRIDE { |
| 123 ModalDialogHostObserver* observer) OVERRIDE { | |
| 124 observer_list_.RemoveObserver(observer); | 108 observer_list_.RemoveObserver(observer); |
| 125 } | 109 } |
| 126 | 110 |
| 127 BrowserViewLayout* const browser_view_layout_; | 111 BrowserViewLayout* const browser_view_layout_; |
| 128 | 112 |
| 129 ObserverList<ModalDialogHostObserver> observer_list_; | 113 ObserverList<ModalDialogHostObserver> observer_list_; |
| 130 | 114 |
| 131 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogHostViews); | 115 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogHostViews); |
| 132 }; | 116 }; |
| 133 | 117 |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 365 } |
| 382 | 366 |
| 383 // Adjust the fullscreen exit bubble bounds for |top_container_|'s new bounds. | 367 // Adjust the fullscreen exit bubble bounds for |top_container_|'s new bounds. |
| 384 // This makes the fullscreen exit bubble look like it animates with | 368 // This makes the fullscreen exit bubble look like it animates with |
| 385 // |top_container_| in immersive fullscreen. | 369 // |top_container_| in immersive fullscreen. |
| 386 FullscreenExitBubbleViews* fullscreen_exit_bubble = | 370 FullscreenExitBubbleViews* fullscreen_exit_bubble = |
| 387 delegate_->GetFullscreenExitBubble(); | 371 delegate_->GetFullscreenExitBubble(); |
| 388 if (fullscreen_exit_bubble) | 372 if (fullscreen_exit_bubble) |
| 389 fullscreen_exit_bubble->RepositionIfVisible(); | 373 fullscreen_exit_bubble->RepositionIfVisible(); |
| 390 | 374 |
| 391 // Adjust any hosted dialogs if the browser's dialog positioning has changed. | 375 // Adjust any hosted dialogs if the browser's dialog hosting bounds changed. |
| 392 if (dialog_host_->GetDialogPosition(gfx::Size()) != latest_dialog_position_) { | 376 const gfx::Rect dialog_bounds(dialog_host_->GetDialogPosition(gfx::Size()), |
| 393 latest_dialog_position_ = dialog_host_->GetDialogPosition(gfx::Size()); | 377 dialog_host_->GetMaximumDialogSize()); |
| 378 if (latest_dialog_bounds_ != dialog_bounds) { |
| 379 latest_dialog_bounds_ = dialog_bounds; |
| 394 dialog_host_->NotifyPositionRequiresUpdate(); | 380 dialog_host_->NotifyPositionRequiresUpdate(); |
| 395 } | 381 } |
| 396 } | 382 } |
| 397 | 383 |
| 398 // Return the preferred size which is the size required to give each | 384 // Return the preferred size which is the size required to give each |
| 399 // children their respective preferred size. | 385 // children their respective preferred size. |
| 400 gfx::Size BrowserViewLayout::GetPreferredSize(views::View* host) { | 386 gfx::Size BrowserViewLayout::GetPreferredSize(views::View* host) { |
| 401 return gfx::Size(); | 387 return gfx::Size(); |
| 402 } | 388 } |
| 403 | 389 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 return bottom; | 565 return bottom; |
| 580 } | 566 } |
| 581 | 567 |
| 582 bool BrowserViewLayout::InfobarVisible() const { | 568 bool BrowserViewLayout::InfobarVisible() const { |
| 583 // Cast to a views::View to access GetPreferredSize(). | 569 // Cast to a views::View to access GetPreferredSize(). |
| 584 views::View* infobar_container = infobar_container_; | 570 views::View* infobar_container = infobar_container_; |
| 585 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 571 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
| 586 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 572 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
| 587 (infobar_container->GetPreferredSize().height() != 0); | 573 (infobar_container->GetPreferredSize().height() != 0); |
| 588 } | 574 } |
| OLD | NEW |