| 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 236 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 | 247 // occur for "browser-fullscreen" and not for "tab-fullscreen" (which has a URL |
| 248 // for the tab entering fullscreen). | 248 // for the tab entering fullscreen). |
| 249 bool UseImmersiveFullscreenForUrl(const GURL& url) { | 249 bool UseImmersiveFullscreenForUrl(const GURL& url) { |
| 250 bool is_browser_fullscreen = url.is_empty(); | 250 bool is_browser_fullscreen = url.is_empty(); |
| 251 return is_browser_fullscreen && chrome::UseImmersiveFullscreen(); | 251 return is_browser_fullscreen && chrome::UseImmersiveFullscreen(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 } // namespace | 254 } // namespace |
| 255 | 255 |
| 256 /////////////////////////////////////////////////////////////////////////////// | 256 /////////////////////////////////////////////////////////////////////////////// |
| 257 |
| 258 // Delegate implementation for BrowserViewLayout. Usually just forwards calls |
| 259 // into BrowserView. |
| 260 class BrowserViewLayoutDelegateImpl : public BrowserViewLayoutDelegate { |
| 261 public: |
| 262 explicit BrowserViewLayoutDelegateImpl(BrowserView* browser_view) |
| 263 : browser_view_(browser_view) {} |
| 264 virtual ~BrowserViewLayoutDelegateImpl() {} |
| 265 |
| 266 // BrowserViewLayoutDelegate overrides: |
| 267 virtual bool DownloadShelfNeedsLayout() const OVERRIDE { |
| 268 DownloadShelfView* download_shelf = browser_view_->download_shelf_.get(); |
| 269 // Re-layout the shelf either if it is visible or if its close animation |
| 270 // is currently running. |
| 271 return download_shelf && |
| 272 (download_shelf->IsShowing() || download_shelf->IsClosing()); |
| 273 } |
| 274 |
| 275 virtual bool IsTabStripVisible() const OVERRIDE { |
| 276 return browser_view_->IsTabStripVisible(); |
| 277 } |
| 278 |
| 279 virtual gfx::Rect GetBoundsForTabStrip( |
| 280 views::View* tab_strip) const OVERRIDE { |
| 281 return browser_view_->frame()->GetBoundsForTabStrip(tab_strip); |
| 282 } |
| 283 |
| 284 virtual bool IsToolbarVisible() const OVERRIDE { |
| 285 return browser_view_->IsToolbarVisible(); |
| 286 } |
| 287 |
| 288 virtual bool IsBookmarkBarVisible() const OVERRIDE { |
| 289 return browser_view_->IsBookmarkBarVisible(); |
| 290 } |
| 291 |
| 292 private: |
| 293 BrowserView* browser_view_; |
| 294 |
| 295 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayoutDelegateImpl); |
| 296 }; |
| 297 |
| 298 /////////////////////////////////////////////////////////////////////////////// |
| 257 // BookmarkExtensionBackground, private: | 299 // BookmarkExtensionBackground, private: |
| 258 // This object serves as the views::Background object which is used to layout | 300 // This object serves as the views::Background object which is used to layout |
| 259 // and paint the bookmark bar. | 301 // and paint the bookmark bar. |
| 260 class BookmarkExtensionBackground : public views::Background { | 302 class BookmarkExtensionBackground : public views::Background { |
| 261 public: | 303 public: |
| 262 BookmarkExtensionBackground(BrowserView* browser_view, | 304 BookmarkExtensionBackground(BrowserView* browser_view, |
| 263 DetachableToolbarView* host_view, | 305 DetachableToolbarView* host_view, |
| 264 Browser* browser); | 306 Browser* browser); |
| 265 | 307 |
| 266 // View methods overridden from views:Background. | 308 // View methods overridden from views:Background. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 423 } |
| 382 | 424 |
| 383 /////////////////////////////////////////////////////////////////////////////// | 425 /////////////////////////////////////////////////////////////////////////////// |
| 384 // BrowserView, public: | 426 // BrowserView, public: |
| 385 | 427 |
| 386 BrowserView::BrowserView() | 428 BrowserView::BrowserView() |
| 387 : views::ClientView(NULL, NULL), | 429 : views::ClientView(NULL, NULL), |
| 388 last_focused_view_storage_id_( | 430 last_focused_view_storage_id_( |
| 389 views::ViewStorage::GetInstance()->CreateStorageID()), | 431 views::ViewStorage::GetInstance()->CreateStorageID()), |
| 390 frame_(NULL), | 432 frame_(NULL), |
| 433 layout_delegate_(new BrowserViewLayoutDelegateImpl(this)), |
| 391 top_container_(NULL), | 434 top_container_(NULL), |
| 392 tabstrip_(NULL), | 435 tabstrip_(NULL), |
| 393 toolbar_(NULL), | 436 toolbar_(NULL), |
| 394 window_switcher_button_(NULL), | 437 window_switcher_button_(NULL), |
| 395 infobar_container_(NULL), | 438 infobar_container_(NULL), |
| 396 contents_web_view_(NULL), | 439 contents_web_view_(NULL), |
| 397 devtools_container_(NULL), | 440 devtools_container_(NULL), |
| 398 contents_container_(NULL), | 441 contents_container_(NULL), |
| 399 overlay_container_(NULL), | 442 overlay_container_(NULL), |
| 400 contents_split_(NULL), | 443 contents_split_(NULL), |
| (...skipping 34 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 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1812 const char* BrowserView::GetClassName() const { | 1858 const char* BrowserView::GetClassName() const { |
| 1813 return kViewClassName; | 1859 return kViewClassName; |
| 1814 } | 1860 } |
| 1815 | 1861 |
| 1816 void BrowserView::Layout() { | 1862 void BrowserView::Layout() { |
| 1817 if (ignore_layout_) | 1863 if (ignore_layout_) |
| 1818 return; | 1864 return; |
| 1819 | 1865 |
| 1820 views::View::Layout(); | 1866 views::View::Layout(); |
| 1821 | 1867 |
| 1868 // TODO(jamescook): Why was this in the middle of layout code? |
| 1869 toolbar_->location_bar()->SetLocationEntryFocusable(IsToolbarVisible()); |
| 1870 |
| 1822 // The status bubble position requires that all other layout finish first. | 1871 // The status bubble position requires that all other layout finish first. |
| 1823 LayoutStatusBubble(); | 1872 LayoutStatusBubble(); |
| 1824 } | 1873 } |
| 1825 | 1874 |
| 1826 void BrowserView::PaintChildren(gfx::Canvas* canvas) { | 1875 void BrowserView::PaintChildren(gfx::Canvas* canvas) { |
| 1827 // Paint the |infobar_container_| last so that it may paint its | 1876 // Paint the |infobar_container_| last so that it may paint its |
| 1828 // overlapping tabs. | 1877 // overlapping tabs. |
| 1829 for (int i = 0; i < child_count(); ++i) { | 1878 for (int i = 0; i < child_count(); ++i) { |
| 1830 View* child = child_at(i); | 1879 View* child = child_at(i); |
| 1831 if (child != infobar_container_) | 1880 if (child != infobar_container_) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 accelerator_table_.find(accelerator); | 1920 accelerator_table_.find(accelerator); |
| 1872 DCHECK(iter != accelerator_table_.end()); | 1921 DCHECK(iter != accelerator_table_.end()); |
| 1873 int command_id = iter->second; | 1922 int command_id = iter->second; |
| 1874 | 1923 |
| 1875 chrome::BrowserCommandController* controller = browser_->command_controller(); | 1924 chrome::BrowserCommandController* controller = browser_->command_controller(); |
| 1876 if (!controller->block_command_execution()) | 1925 if (!controller->block_command_execution()) |
| 1877 UpdateAcceleratorMetrics(accelerator, command_id); | 1926 UpdateAcceleratorMetrics(accelerator, command_id); |
| 1878 return chrome::ExecuteCommand(browser_.get(), command_id); | 1927 return chrome::ExecuteCommand(browser_.get(), command_id); |
| 1879 } | 1928 } |
| 1880 | 1929 |
| 1881 /////////////////////////////////////////////////////////////////////////////// | |
| 1882 // BrowserView, private | |
| 1883 | |
| 1884 SkColor BrowserView::GetInfoBarSeparatorColor() const { | 1930 SkColor BrowserView::GetInfoBarSeparatorColor() const { |
| 1885 // NOTE: Keep this in sync with ToolbarView::OnPaint()! | 1931 // NOTE: Keep this in sync with ToolbarView::OnPaint()! |
| 1886 return (IsTabStripVisible() || !frame_->ShouldUseNativeFrame()) ? | 1932 return (IsTabStripVisible() || !frame_->ShouldUseNativeFrame()) ? |
| 1887 ThemeProperties::GetDefaultColor( | 1933 ThemeProperties::GetDefaultColor( |
| 1888 ThemeProperties::COLOR_TOOLBAR_SEPARATOR) : | 1934 ThemeProperties::COLOR_TOOLBAR_SEPARATOR) : |
| 1889 SK_ColorBLACK; | 1935 SK_ColorBLACK; |
| 1890 } | 1936 } |
| 1891 | 1937 |
| 1892 void BrowserView::InfoBarContainerStateChanged(bool is_animating) { | 1938 void BrowserView::InfoBarContainerStateChanged(bool is_animating) { |
| 1893 ToolbarSizeChanged(is_animating); | 1939 ToolbarSizeChanged(is_animating); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1991 | 2037 |
| 1992 overlay_container_ = new OverlayContainer(this); | 2038 overlay_container_ = new OverlayContainer(this); |
| 1993 overlay_container_->SetVisible(false); | 2039 overlay_container_->SetVisible(false); |
| 1994 AddChildView(overlay_container_); | 2040 AddChildView(overlay_container_); |
| 1995 | 2041 |
| 1996 overlay_controller_.reset( | 2042 overlay_controller_.reset( |
| 1997 new InstantOverlayControllerViews(browser(), overlay_container_)); | 2043 new InstantOverlayControllerViews(browser(), overlay_container_)); |
| 1998 | 2044 |
| 1999 BrowserViewLayout* browser_view_layout = new BrowserViewLayout; | 2045 BrowserViewLayout* browser_view_layout = new BrowserViewLayout; |
| 2000 browser_view_layout->Init(browser(), | 2046 browser_view_layout->Init(browser(), |
| 2047 layout_delegate_.get(), |
| 2001 this, | 2048 this, |
| 2049 top_container_, |
| 2050 tabstrip_, |
| 2051 toolbar_, |
| 2002 infobar_container_, | 2052 infobar_container_, |
| 2003 contents_split_, | 2053 contents_split_, |
| 2004 contents_container_, | 2054 contents_container_, |
| 2005 overlay_container_); | 2055 overlay_container_, |
| 2056 immersive_mode_controller_.get()); |
| 2006 SetLayoutManager(browser_view_layout); | 2057 SetLayoutManager(browser_view_layout); |
| 2007 | 2058 |
| 2008 #if defined(OS_WIN) && !defined(USE_AURA) | 2059 #if defined(OS_WIN) && !defined(USE_AURA) |
| 2009 // Create a custom JumpList and add it to an observer of TabRestoreService | 2060 // Create a custom JumpList and add it to an observer of TabRestoreService |
| 2010 // so we can update the custom JumpList when a tab is added or removed. | 2061 // so we can update the custom JumpList when a tab is added or removed. |
| 2011 if (JumpList::Enabled()) { | 2062 if (JumpList::Enabled()) { |
| 2012 load_complete_listener_.reset(new LoadCompleteListener(this)); | 2063 load_complete_listener_.reset(new LoadCompleteListener(this)); |
| 2013 } | 2064 } |
| 2014 #endif | 2065 #endif |
| 2015 | 2066 |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2682 // The +1 in the next line creates a 1-px gap between icon and arrow tip. | 2733 // The +1 in the next line creates a 1-px gap between icon and arrow tip. |
| 2683 gfx::Point icon_bottom(0, location_icon_view->GetImageBounds().bottom() - | 2734 gfx::Point icon_bottom(0, location_icon_view->GetImageBounds().bottom() - |
| 2684 LocationBarView::kIconInternalPadding + 1); | 2735 LocationBarView::kIconInternalPadding + 1); |
| 2685 ConvertPointToTarget(location_icon_view, this, &icon_bottom); | 2736 ConvertPointToTarget(location_icon_view, this, &icon_bottom); |
| 2686 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); | 2737 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); |
| 2687 ConvertPointToTarget(infobar_container_, this, &infobar_top); | 2738 ConvertPointToTarget(infobar_container_, this, &infobar_top); |
| 2688 top_arrow_height = infobar_top.y() - icon_bottom.y(); | 2739 top_arrow_height = infobar_top.y() - icon_bottom.y(); |
| 2689 } | 2740 } |
| 2690 return top_arrow_height; | 2741 return top_arrow_height; |
| 2691 } | 2742 } |
| OLD | NEW |