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.h" | 5 #include "chrome/browser/ui/views/frame/browser_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include "chrome/browser/ui/view_ids.h" | 54 #include "chrome/browser/ui/view_ids.h" |
55 #include "chrome/browser/ui/views/accelerator_table.h" | 55 #include "chrome/browser/ui/views/accelerator_table.h" |
56 #include "chrome/browser/ui/views/accessibility/invert_bubble_view.h" | 56 #include "chrome/browser/ui/views/accessibility/invert_bubble_view.h" |
57 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" | 57 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
58 #include "chrome/browser/ui/views/avatar_menu_button.h" | 58 #include "chrome/browser/ui/views/avatar_menu_button.h" |
59 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 59 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
60 #include "chrome/browser/ui/views/browser_dialogs.h" | 60 #include "chrome/browser/ui/views/browser_dialogs.h" |
61 #include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h" | 61 #include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h" |
62 #include "chrome/browser/ui/views/download/download_shelf_view.h" | 62 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
63 #include "chrome/browser/ui/views/frame/browser_view_layout.h" | 63 #include "chrome/browser/ui/views/frame/browser_view_layout.h" |
| 64 #include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h" |
64 #include "chrome/browser/ui/views/frame/contents_container.h" | 65 #include "chrome/browser/ui/views/frame/contents_container.h" |
65 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 66 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
66 #include "chrome/browser/ui/views/frame/instant_overlay_controller_views.h" | 67 #include "chrome/browser/ui/views/frame/instant_overlay_controller_views.h" |
67 #include "chrome/browser/ui/views/frame/overlay_container.h" | 68 #include "chrome/browser/ui/views/frame/overlay_container.h" |
68 #include "chrome/browser/ui/views/frame/top_container_view.h" | 69 #include "chrome/browser/ui/views/frame/top_container_view.h" |
69 #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" | 70 #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" |
70 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" | 71 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" |
71 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 72 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
72 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 73 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
73 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" | 74 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 // occur for "browser-fullscreen" and not for "tab-fullscreen" (which has a URL | 248 // occur for "browser-fullscreen" and not for "tab-fullscreen" (which has a URL |
248 // for the tab entering fullscreen). | 249 // for the tab entering fullscreen). |
249 bool UseImmersiveFullscreenForUrl(const GURL& url) { | 250 bool UseImmersiveFullscreenForUrl(const GURL& url) { |
250 bool is_browser_fullscreen = url.is_empty(); | 251 bool is_browser_fullscreen = url.is_empty(); |
251 return is_browser_fullscreen && chrome::UseImmersiveFullscreen(); | 252 return is_browser_fullscreen && chrome::UseImmersiveFullscreen(); |
252 } | 253 } |
253 | 254 |
254 } // namespace | 255 } // namespace |
255 | 256 |
256 /////////////////////////////////////////////////////////////////////////////// | 257 /////////////////////////////////////////////////////////////////////////////// |
| 258 |
| 259 // Delegate implementation for BrowserViewLayout. Usually just forwards calls |
| 260 // into BrowserView. |
| 261 class BrowserViewLayoutDelegateImpl : public BrowserViewLayoutDelegate { |
| 262 public: |
| 263 explicit BrowserViewLayoutDelegateImpl(BrowserView* browser_view) |
| 264 : browser_view_(browser_view) {} |
| 265 virtual ~BrowserViewLayoutDelegateImpl() {} |
| 266 |
| 267 // BrowserViewLayoutDelegate overrides: |
| 268 virtual bool DownloadShelfNeedsLayout() const OVERRIDE { |
| 269 DownloadShelfView* download_shelf = browser_view_->download_shelf_.get(); |
| 270 // Re-layout the shelf either if it is visible or if its close animation |
| 271 // is currently running. |
| 272 return download_shelf && |
| 273 (download_shelf->IsShowing() || download_shelf->IsClosing()); |
| 274 } |
| 275 |
| 276 virtual bool IsTabStripVisible() const OVERRIDE { |
| 277 return browser_view_->IsTabStripVisible(); |
| 278 } |
| 279 |
| 280 virtual gfx::Rect GetBoundsForTabStrip( |
| 281 views::View* tab_strip) const OVERRIDE { |
| 282 return browser_view_->frame()->GetBoundsForTabStrip(tab_strip); |
| 283 } |
| 284 |
| 285 virtual bool IsToolbarVisible() const OVERRIDE { |
| 286 return browser_view_->IsToolbarVisible(); |
| 287 } |
| 288 |
| 289 virtual bool IsBookmarkBarVisible() const OVERRIDE { |
| 290 return browser_view_->IsBookmarkBarVisible(); |
| 291 } |
| 292 |
| 293 private: |
| 294 BrowserView* browser_view_; |
| 295 |
| 296 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayoutDelegateImpl); |
| 297 }; |
| 298 |
| 299 /////////////////////////////////////////////////////////////////////////////// |
257 // BookmarkExtensionBackground, private: | 300 // BookmarkExtensionBackground, private: |
258 // This object serves as the views::Background object which is used to layout | 301 // This object serves as the views::Background object which is used to layout |
259 // and paint the bookmark bar. | 302 // and paint the bookmark bar. |
260 class BookmarkExtensionBackground : public views::Background { | 303 class BookmarkExtensionBackground : public views::Background { |
261 public: | 304 public: |
262 BookmarkExtensionBackground(BrowserView* browser_view, | 305 BookmarkExtensionBackground(BrowserView* browser_view, |
263 DetachableToolbarView* host_view, | 306 DetachableToolbarView* host_view, |
264 Browser* browser); | 307 Browser* browser); |
265 | 308 |
266 // View methods overridden from views:Background. | 309 // View methods overridden from views:Background. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 // destroyed. | 478 // destroyed. |
436 if (jumplist_) { | 479 if (jumplist_) { |
437 jumplist_->Terminate(); | 480 jumplist_->Terminate(); |
438 } | 481 } |
439 #endif | 482 #endif |
440 | 483 |
441 // We destroy the download shelf before |browser_| to remove its child | 484 // We destroy the download shelf before |browser_| to remove its child |
442 // download views from the set of download observers (since the observed | 485 // download views from the set of download observers (since the observed |
443 // downloads can be destroyed along with |browser_| and the observer | 486 // downloads can be destroyed along with |browser_| and the observer |
444 // notifications will call back into deleted objects). | 487 // notifications will call back into deleted objects). |
445 download_shelf_.reset(); | |
446 BrowserViewLayout* browser_view_layout = GetBrowserViewLayout(); | 488 BrowserViewLayout* browser_view_layout = GetBrowserViewLayout(); |
447 if (browser_view_layout) | 489 if (browser_view_layout) |
448 browser_view_layout->set_download_shelf(NULL); | 490 browser_view_layout->set_download_shelf(NULL); |
| 491 download_shelf_.reset(); |
449 | 492 |
450 // The TabStrip attaches a listener to the model. Make sure we shut down the | 493 // The TabStrip attaches a listener to the model. Make sure we shut down the |
451 // TabStrip first so that it can cleanly remove the listener. | 494 // TabStrip first so that it can cleanly remove the listener. |
452 if (tabstrip_) { | 495 if (tabstrip_) { |
453 tabstrip_->parent()->RemoveChildView(tabstrip_); | 496 tabstrip_->parent()->RemoveChildView(tabstrip_); |
| 497 if (browser_view_layout) |
| 498 browser_view_layout->set_tab_strip(NULL); |
454 delete tabstrip_; | 499 delete tabstrip_; |
455 tabstrip_ = NULL; | 500 tabstrip_ = NULL; |
456 } | 501 } |
457 // Child views maintain PrefMember attributes that point to | 502 // Child views maintain PrefMember attributes that point to |
458 // OffTheRecordProfile's PrefService which gets deleted by ~Browser. | 503 // OffTheRecordProfile's PrefService which gets deleted by ~Browser. |
459 RemoveAllChildViews(true); | 504 RemoveAllChildViews(true); |
460 | 505 |
461 // It is possible that we were forced-closed by the native view system and | 506 // It is possible that we were forced-closed by the native view system and |
462 // that tabs remain in the browser. Close any such remaining tabs. | 507 // that tabs remain in the browser. Close any such remaining tabs. |
463 while (browser_->tab_strip_model()->count()) | 508 while (browser_->tab_strip_model()->count()) |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 void BrowserView::RestoreFocus() { | 935 void BrowserView::RestoreFocus() { |
891 WebContents* selected_web_contents = GetActiveWebContents(); | 936 WebContents* selected_web_contents = GetActiveWebContents(); |
892 if (selected_web_contents) | 937 if (selected_web_contents) |
893 selected_web_contents->GetView()->RestoreFocus(); | 938 selected_web_contents->GetView()->RestoreFocus(); |
894 } | 939 } |
895 | 940 |
896 void BrowserView::SetWindowSwitcherButton(views::Button* button) { | 941 void BrowserView::SetWindowSwitcherButton(views::Button* button) { |
897 if (window_switcher_button_) | 942 if (window_switcher_button_) |
898 RemoveChildView(window_switcher_button_); | 943 RemoveChildView(window_switcher_button_); |
899 window_switcher_button_ = button; | 944 window_switcher_button_ = button; |
| 945 GetBrowserViewLayout()->set_window_switcher_button(button); |
900 AddChildView(button); | 946 AddChildView(button); |
901 } | 947 } |
902 | 948 |
903 void BrowserView::ToolbarSizeChanged(bool is_animating) { | 949 void BrowserView::ToolbarSizeChanged(bool is_animating) { |
904 // The call to InfoBarContainer::SetMaxTopArrowHeight() below can result in | 950 // The call to InfoBarContainer::SetMaxTopArrowHeight() below can result in |
905 // reentrancy; |call_state| tracks whether we're reentrant. We can't just | 951 // reentrancy; |call_state| tracks whether we're reentrant. We can't just |
906 // early-return in this case because we need to layout again so the infobar | 952 // early-return in this case because we need to layout again so the infobar |
907 // container's bounds are set correctly. | 953 // container's bounds are set correctly. |
908 static CallState call_state = NORMAL; | 954 static CallState call_state = NORMAL; |
909 | 955 |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 const char* BrowserView::GetClassName() const { | 1856 const char* BrowserView::GetClassName() const { |
1811 return kViewClassName; | 1857 return kViewClassName; |
1812 } | 1858 } |
1813 | 1859 |
1814 void BrowserView::Layout() { | 1860 void BrowserView::Layout() { |
1815 if (ignore_layout_) | 1861 if (ignore_layout_) |
1816 return; | 1862 return; |
1817 | 1863 |
1818 views::View::Layout(); | 1864 views::View::Layout(); |
1819 | 1865 |
| 1866 // TODO(jamescook): Why was this in the middle of layout code? |
| 1867 toolbar_->location_bar()->SetLocationEntryFocusable(IsToolbarVisible()); |
| 1868 |
1820 // The status bubble position requires that all other layout finish first. | 1869 // The status bubble position requires that all other layout finish first. |
1821 LayoutStatusBubble(); | 1870 LayoutStatusBubble(); |
1822 } | 1871 } |
1823 | 1872 |
1824 void BrowserView::PaintChildren(gfx::Canvas* canvas) { | 1873 void BrowserView::PaintChildren(gfx::Canvas* canvas) { |
1825 // Paint the |infobar_container_| last so that it may paint its | 1874 // Paint the |infobar_container_| last so that it may paint its |
1826 // overlapping tabs. | 1875 // overlapping tabs. |
1827 for (int i = 0; i < child_count(); ++i) { | 1876 for (int i = 0; i < child_count(); ++i) { |
1828 View* child = child_at(i); | 1877 View* child = child_at(i); |
1829 if (child != infobar_container_) | 1878 if (child != infobar_container_) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 accelerator_table_.find(accelerator); | 1918 accelerator_table_.find(accelerator); |
1870 DCHECK(iter != accelerator_table_.end()); | 1919 DCHECK(iter != accelerator_table_.end()); |
1871 int command_id = iter->second; | 1920 int command_id = iter->second; |
1872 | 1921 |
1873 chrome::BrowserCommandController* controller = browser_->command_controller(); | 1922 chrome::BrowserCommandController* controller = browser_->command_controller(); |
1874 if (!controller->block_command_execution()) | 1923 if (!controller->block_command_execution()) |
1875 UpdateAcceleratorMetrics(accelerator, command_id); | 1924 UpdateAcceleratorMetrics(accelerator, command_id); |
1876 return chrome::ExecuteCommand(browser_.get(), command_id); | 1925 return chrome::ExecuteCommand(browser_.get(), command_id); |
1877 } | 1926 } |
1878 | 1927 |
1879 /////////////////////////////////////////////////////////////////////////////// | |
1880 // BrowserView, private | |
1881 | |
1882 SkColor BrowserView::GetInfoBarSeparatorColor() const { | 1928 SkColor BrowserView::GetInfoBarSeparatorColor() const { |
1883 // NOTE: Keep this in sync with ToolbarView::OnPaint()! | 1929 // NOTE: Keep this in sync with ToolbarView::OnPaint()! |
1884 return (IsTabStripVisible() || !frame_->ShouldUseNativeFrame()) ? | 1930 return (IsTabStripVisible() || !frame_->ShouldUseNativeFrame()) ? |
1885 ThemeProperties::GetDefaultColor( | 1931 ThemeProperties::GetDefaultColor( |
1886 ThemeProperties::COLOR_TOOLBAR_SEPARATOR) : | 1932 ThemeProperties::COLOR_TOOLBAR_SEPARATOR) : |
1887 SK_ColorBLACK; | 1933 SK_ColorBLACK; |
1888 } | 1934 } |
1889 | 1935 |
1890 void BrowserView::InfoBarContainerStateChanged(bool is_animating) { | 1936 void BrowserView::InfoBarContainerStateChanged(bool is_animating) { |
1891 ToolbarSizeChanged(is_animating); | 1937 ToolbarSizeChanged(is_animating); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1988 toolbar_->Init(); | 2034 toolbar_->Init(); |
1989 | 2035 |
1990 overlay_container_ = new OverlayContainer(this); | 2036 overlay_container_ = new OverlayContainer(this); |
1991 overlay_container_->SetVisible(false); | 2037 overlay_container_->SetVisible(false); |
1992 AddChildView(overlay_container_); | 2038 AddChildView(overlay_container_); |
1993 | 2039 |
1994 overlay_controller_.reset( | 2040 overlay_controller_.reset( |
1995 new InstantOverlayControllerViews(browser(), overlay_container_)); | 2041 new InstantOverlayControllerViews(browser(), overlay_container_)); |
1996 | 2042 |
1997 BrowserViewLayout* browser_view_layout = new BrowserViewLayout; | 2043 BrowserViewLayout* browser_view_layout = new BrowserViewLayout; |
1998 browser_view_layout->Init(browser(), | 2044 browser_view_layout->Init(new BrowserViewLayoutDelegateImpl(this), |
| 2045 browser(), |
1999 this, | 2046 this, |
| 2047 top_container_, |
| 2048 tabstrip_, |
| 2049 toolbar_, |
2000 infobar_container_, | 2050 infobar_container_, |
2001 contents_split_, | 2051 contents_split_, |
2002 contents_container_, | 2052 contents_container_, |
2003 overlay_container_); | 2053 overlay_container_, |
| 2054 immersive_mode_controller_.get()); |
2004 SetLayoutManager(browser_view_layout); | 2055 SetLayoutManager(browser_view_layout); |
2005 | 2056 |
2006 #if defined(OS_WIN) && !defined(USE_AURA) | 2057 #if defined(OS_WIN) && !defined(USE_AURA) |
2007 // Create a custom JumpList and add it to an observer of TabRestoreService | 2058 // Create a custom JumpList and add it to an observer of TabRestoreService |
2008 // so we can update the custom JumpList when a tab is added or removed. | 2059 // so we can update the custom JumpList when a tab is added or removed. |
2009 if (JumpList::Enabled()) { | 2060 if (JumpList::Enabled()) { |
2010 load_complete_listener_.reset(new LoadCompleteListener(this)); | 2061 load_complete_listener_.reset(new LoadCompleteListener(this)); |
2011 } | 2062 } |
2012 #endif | 2063 #endif |
2013 | 2064 |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2680 // The +1 in the next line creates a 1-px gap between icon and arrow tip. | 2731 // The +1 in the next line creates a 1-px gap between icon and arrow tip. |
2681 gfx::Point icon_bottom(0, location_icon_view->GetImageBounds().bottom() - | 2732 gfx::Point icon_bottom(0, location_icon_view->GetImageBounds().bottom() - |
2682 LocationBarView::kIconInternalPadding + 1); | 2733 LocationBarView::kIconInternalPadding + 1); |
2683 ConvertPointToTarget(location_icon_view, this, &icon_bottom); | 2734 ConvertPointToTarget(location_icon_view, this, &icon_bottom); |
2684 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); | 2735 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); |
2685 ConvertPointToTarget(infobar_container_, this, &infobar_top); | 2736 ConvertPointToTarget(infobar_container_, this, &infobar_top); |
2686 top_arrow_height = infobar_top.y() - icon_bottom.y(); | 2737 top_arrow_height = infobar_top.y() - icon_bottom.y(); |
2687 } | 2738 } |
2688 return top_arrow_height; | 2739 return top_arrow_height; |
2689 } | 2740 } |
OLD | NEW |