Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: chrome/browser/ui/views/frame/browser_view.cc

Issue 5606012: Streamline the layout of the BrowserView's children TabContents views.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #if defined(OS_LINUX) 7 #if defined(OS_LINUX)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
(...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 void BrowserView::ToggleTabStripMode() { 1345 void BrowserView::ToggleTabStripMode() {
1346 InitTabStrip(browser_->tabstrip_model()); 1346 InitTabStrip(browser_->tabstrip_model());
1347 frame_->TabStripDisplayModeChanged(); 1347 frame_->TabStripDisplayModeChanged();
1348 } 1348 }
1349 1349
1350 void BrowserView::PrepareForInstant() { 1350 void BrowserView::PrepareForInstant() {
1351 contents_->FadeActiveContents(); 1351 contents_->FadeActiveContents();
1352 } 1352 }
1353 1353
1354 void BrowserView::ShowInstant(TabContents* preview_contents) { 1354 void BrowserView::ShowInstant(TabContents* preview_contents) {
1355 if (!preview_container_) { 1355 if (!preview_container_)
1356 preview_container_ = new TabContentsContainer(); 1356 preview_container_ = new TabContentsContainer();
1357 preview_container_->set_reserved_area_delegate(this);
1358 }
1359 contents_->SetPreview(preview_container_, preview_contents); 1357 contents_->SetPreview(preview_container_, preview_contents);
1360 preview_container_->ChangeTabContents(preview_contents); 1358 preview_container_->ChangeTabContents(preview_contents);
1361 1359
1362 #if defined(OS_WIN) 1360 #if defined(OS_WIN)
1363 // Removing the fade is instant (on windows). We need to force the preview to 1361 // Removing the fade is instant (on windows). We need to force the preview to
1364 // draw, otherwise the current page flickers before the new page appears. 1362 // draw, otherwise the current page flickers before the new page appears.
1365 RedrawWindow(preview_contents->view()->GetContentNativeView(), NULL, NULL, 1363 RedrawWindow(preview_contents->view()->GetContentNativeView(), NULL, NULL,
1366 RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN); 1364 RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN);
1367 #endif 1365 #endif
1368 1366
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 } 1819 }
1822 1820
1823 AccessibilityTypes::Role BrowserView::GetAccessibleRole() { 1821 AccessibilityTypes::Role BrowserView::GetAccessibleRole() {
1824 return AccessibilityTypes::ROLE_CLIENT; 1822 return AccessibilityTypes::ROLE_CLIENT;
1825 } 1823 }
1826 1824
1827 void BrowserView::InfoBarSizeChanged(bool is_animating) { 1825 void BrowserView::InfoBarSizeChanged(bool is_animating) {
1828 SelectedTabToolbarSizeChanged(is_animating); 1826 SelectedTabToolbarSizeChanged(is_animating);
1829 } 1827 }
1830 1828
1831 void BrowserView::UpdateReservedContentsRect( 1829 bool BrowserView::SplitHandleMoved(views::SingleSplitView* view) {
1832 const TabContentsContainer* source) { 1830 for (int i = 0; i < view->GetChildViewCount(); ++i)
1833 RenderWidgetHostView* render_widget_host_view = 1831 view->GetChildViewAt(i)->InvalidateLayout();
1834 source->tab_contents() ? source->tab_contents()->GetRenderWidgetHostView() 1832 SchedulePaint();
1835 : NULL; 1833 Layout();
1836 if (!render_widget_host_view) 1834 return false;
1837 return;
1838
1839 gfx::Rect reserved_rect;
1840
1841 if (!frame_->GetWindow()->IsMaximized() &&
1842 !frame_->GetWindow()->IsFullscreen()) {
1843 gfx::Size resize_corner_size = ResizeCorner::GetSize();
1844 if (!resize_corner_size.IsEmpty()) {
1845 gfx::Point resize_corner_origin;
1846 gfx::Rect bounds = GetLocalBounds(false);
1847 resize_corner_origin.set_x(bounds.right() - resize_corner_size.width());
1848 resize_corner_origin.set_y(bounds.bottom() - resize_corner_size.height());
1849
1850 View::ConvertPointToView(this, source, &resize_corner_origin);
1851
1852 gfx::Size container_size = source->size();
1853
1854 if (resize_corner_origin.x() < container_size.width() &&
1855 resize_corner_origin.y() < container_size.height()) {
1856 reserved_rect = gfx::Rect(resize_corner_origin, resize_corner_size);
1857 }
1858 }
1859 }
1860
1861 // TODO(alekseys): for source == contents_container_, consult SidebarTabView
1862 // for the current size to reserve. Something like this:
1863 // reserved_rect = reserved_rect.Union(SidebarTabView::GetCurrentBounds());
1864
1865 render_widget_host_view->set_reserved_contents_rect(reserved_rect);
1866 } 1835 }
1867 1836
1868 views::LayoutManager* BrowserView::CreateLayoutManager() const { 1837 views::LayoutManager* BrowserView::CreateLayoutManager() const {
1869 return new BrowserViewLayout; 1838 return new BrowserViewLayout;
1870 } 1839 }
1871 1840
1872 void BrowserView::InitTabStrip(TabStripModel* model) { 1841 void BrowserView::InitTabStrip(TabStripModel* model) {
1873 // Throw away the existing tabstrip if we're switching display modes. 1842 // Throw away the existing tabstrip if we're switching display modes.
1874 scoped_ptr<BaseTabStrip> old_strip(tabstrip_); 1843 scoped_ptr<BaseTabStrip> old_strip(tabstrip_);
1875 if (tabstrip_) { 1844 if (tabstrip_) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 toolbar_ = new ToolbarView(browser_.get()); 1887 toolbar_ = new ToolbarView(browser_.get());
1919 AddChildView(toolbar_); 1888 AddChildView(toolbar_);
1920 toolbar_->Init(browser_->profile()); 1889 toolbar_->Init(browser_->profile());
1921 toolbar_->SetAccessibleName( 1890 toolbar_->SetAccessibleName(
1922 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLBAR))); 1891 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLBAR)));
1923 1892
1924 infobar_container_ = new InfoBarContainer(this); 1893 infobar_container_ = new InfoBarContainer(this);
1925 AddChildView(infobar_container_); 1894 AddChildView(infobar_container_);
1926 1895
1927 contents_container_ = new TabContentsContainer; 1896 contents_container_ = new TabContentsContainer;
1928 contents_container_->set_reserved_area_delegate(this);
1929 contents_ = new ContentsContainer(contents_container_); 1897 contents_ = new ContentsContainer(contents_container_);
1930 1898
1931 SkColor bg_color = GetWidget()->GetThemeProvider()-> 1899 SkColor bg_color = GetWidget()->GetThemeProvider()->
1932 GetColor(BrowserThemeProvider::COLOR_TOOLBAR); 1900 GetColor(BrowserThemeProvider::COLOR_TOOLBAR);
1933 1901
1934 bool sidebar_allowed = SidebarManager::IsSidebarAllowed(); 1902 bool sidebar_allowed = SidebarManager::IsSidebarAllowed();
1935 if (sidebar_allowed) { 1903 if (sidebar_allowed) {
1936 sidebar_container_ = new TabContentsContainer; 1904 sidebar_container_ = new TabContentsContainer;
1937 sidebar_container_->set_reserved_area_delegate(this);
1938 sidebar_container_->SetID(VIEW_ID_SIDE_BAR_CONTAINER); 1905 sidebar_container_->SetID(VIEW_ID_SIDE_BAR_CONTAINER);
1939 sidebar_container_->SetVisible(false); 1906 sidebar_container_->SetVisible(false);
1940 1907
1941 sidebar_split_ = new views::SingleSplitView( 1908 sidebar_split_ = new views::SingleSplitView(
1942 contents_, 1909 contents_,
1943 sidebar_container_, 1910 sidebar_container_,
1944 views::SingleSplitView::HORIZONTAL_SPLIT); 1911 views::SingleSplitView::HORIZONTAL_SPLIT,
1912 this);
1945 sidebar_split_->SetID(VIEW_ID_SIDE_BAR_SPLIT); 1913 sidebar_split_->SetID(VIEW_ID_SIDE_BAR_SPLIT);
1946 sidebar_split_->SetAccessibleName( 1914 sidebar_split_->SetAccessibleName(
1947 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_SIDE_BAR))); 1915 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_SIDE_BAR)));
1948 sidebar_split_->set_background( 1916 sidebar_split_->set_background(
1949 views::Background::CreateSolidBackground(bg_color)); 1917 views::Background::CreateSolidBackground(bg_color));
1950 } 1918 }
1951 1919
1952 devtools_container_ = new TabContentsContainer; 1920 devtools_container_ = new TabContentsContainer;
1953 devtools_container_->set_reserved_area_delegate(this);
1954 devtools_container_->SetID(VIEW_ID_DEV_TOOLS_DOCKED); 1921 devtools_container_->SetID(VIEW_ID_DEV_TOOLS_DOCKED);
1955 devtools_container_->SetVisible(false); 1922 devtools_container_->SetVisible(false);
1956 1923
1957 views::View* contents_view = contents_; 1924 views::View* contents_view = contents_;
1958 if (sidebar_allowed) 1925 if (sidebar_allowed)
1959 contents_view = sidebar_split_; 1926 contents_view = sidebar_split_;
1960 1927
1961 contents_split_ = new views::SingleSplitView( 1928 contents_split_ = new views::SingleSplitView(
1962 contents_view, 1929 contents_view,
1963 devtools_container_, 1930 devtools_container_,
1964 views::SingleSplitView::VERTICAL_SPLIT); 1931 views::SingleSplitView::VERTICAL_SPLIT,
1932 this);
1965 contents_split_->SetID(VIEW_ID_CONTENTS_SPLIT); 1933 contents_split_->SetID(VIEW_ID_CONTENTS_SPLIT);
1966 contents_split_->SetAccessibleName( 1934 contents_split_->SetAccessibleName(
1967 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_WEB_CONTENTS))); 1935 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_WEB_CONTENTS)));
1968 contents_split_->set_background( 1936 contents_split_->set_background(
1969 views::Background::CreateSolidBackground(bg_color)); 1937 views::Background::CreateSolidBackground(bg_color));
1970 AddChildView(contents_split_); 1938 AddChildView(contents_split_);
1971 set_contents_view(contents_split_); 1939 set_contents_view(contents_split_);
1972 1940
1973 status_bubble_.reset(new StatusBubbleViews(contents_)); 1941 status_bubble_.reset(new StatusBubbleViews(contents_));
1974 1942
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2098 } 2066 }
2099 // Make sure user can see both panes. 2067 // Make sure user can see both panes.
2100 int min_sidebar_width = sidebar_split_->GetMinimumSize().width(); 2068 int min_sidebar_width = sidebar_split_->GetMinimumSize().width();
2101 sidebar_width = std::min(sidebar_split_->width() - min_sidebar_width, 2069 sidebar_width = std::min(sidebar_split_->width() - min_sidebar_width,
2102 std::max(min_sidebar_width, sidebar_width)); 2070 std::max(min_sidebar_width, sidebar_width));
2103 2071
2104 sidebar_split_->set_divider_offset( 2072 sidebar_split_->set_divider_offset(
2105 sidebar_split_->width() - sidebar_width); 2073 sidebar_split_->width() - sidebar_width);
2106 2074
2107 sidebar_container_->SetVisible(true); 2075 sidebar_container_->SetVisible(true);
2108 sidebar_split_->Layout(); 2076 sidebar_split_->InvalidateLayout();
2077 Layout();
2109 } else if (should_hide) { 2078 } else if (should_hide) {
2110 // Store split offset when hiding sidebar only. 2079 // Store split offset when hiding sidebar only.
2111 g_browser_process->local_state()->SetInteger( 2080 g_browser_process->local_state()->SetInteger(
2112 prefs::kExtensionSidebarWidth, 2081 prefs::kExtensionSidebarWidth,
2113 sidebar_split_->width() - sidebar_split_->divider_offset()); 2082 sidebar_split_->width() - sidebar_split_->divider_offset());
2114 2083
2115 sidebar_container_->SetVisible(false); 2084 sidebar_container_->SetVisible(false);
2116 sidebar_split_->Layout(); 2085 sidebar_split_->InvalidateLayout();
2086 Layout();
2117 } 2087 }
2118 } 2088 }
2119 2089
2120 void BrowserView::UpdateDevToolsForContents(TabContentsWrapper* wrapper) { 2090 void BrowserView::UpdateDevToolsForContents(TabContentsWrapper* wrapper) {
2121 TabContents* tab_contents = wrapper ? wrapper->tab_contents() : NULL; 2091 TabContents* tab_contents = wrapper ? wrapper->tab_contents() : NULL;
2122 TabContents* devtools_contents = 2092 TabContents* devtools_contents =
2123 DevToolsWindow::GetDevToolsContents(tab_contents); 2093 DevToolsWindow::GetDevToolsContents(tab_contents);
2124 2094
2125 bool should_show = devtools_contents && !devtools_container_->IsVisible(); 2095 bool should_show = devtools_contents && !devtools_container_->IsVisible();
2126 bool should_hide = !devtools_contents && devtools_container_->IsVisible(); 2096 bool should_hide = !devtools_contents && devtools_container_->IsVisible();
(...skipping 16 matching lines...) Expand all
2143 // Initial load, set to default value. 2113 // Initial load, set to default value.
2144 split_offset = 2 * contents_split_->height() / 3; 2114 split_offset = 2 * contents_split_->height() / 3;
2145 } 2115 }
2146 // Make sure user can see both panes. 2116 // Make sure user can see both panes.
2147 int min_split_size = contents_split_->height() / 10; 2117 int min_split_size = contents_split_->height() / 10;
2148 split_offset = std::min(contents_split_->height() - min_split_size, 2118 split_offset = std::min(contents_split_->height() - min_split_size,
2149 std::max(min_split_size, split_offset)); 2119 std::max(min_split_size, split_offset));
2150 contents_split_->set_divider_offset(split_offset); 2120 contents_split_->set_divider_offset(split_offset);
2151 2121
2152 devtools_container_->SetVisible(true); 2122 devtools_container_->SetVisible(true);
2153 contents_split_->Layout(); 2123 contents_split_->InvalidateLayout();
2124 Layout();
2154 } else if (should_hide) { 2125 } else if (should_hide) {
2155 // Store split offset when hiding devtools window only. 2126 // Store split offset when hiding devtools window only.
2156 g_browser_process->local_state()->SetInteger( 2127 g_browser_process->local_state()->SetInteger(
2157 prefs::kDevToolsSplitLocation, contents_split_->divider_offset()); 2128 prefs::kDevToolsSplitLocation, contents_split_->divider_offset());
2158 2129
2159 // Restore focus to the last focused view when hiding devtools window. 2130 // Restore focus to the last focused view when hiding devtools window.
2160 devtools_focus_tracker_->FocusLastFocusedExternalView(); 2131 devtools_focus_tracker_->FocusLastFocusedExternalView();
2161 2132
2162 devtools_container_->SetVisible(false); 2133 devtools_container_->SetVisible(false);
2163 contents_split_->Layout(); 2134 contents_split_->InvalidateLayout();
2135 Layout();
2164 } 2136 }
2165 } 2137 }
2166 2138
2167 void BrowserView::UpdateUIForContents(TabContentsWrapper* contents) { 2139 void BrowserView::UpdateUIForContents(TabContentsWrapper* contents) {
2168 bool needs_layout = MaybeShowBookmarkBar(contents); 2140 bool needs_layout = MaybeShowBookmarkBar(contents);
2169 needs_layout |= MaybeShowInfoBar(contents); 2141 needs_layout |= MaybeShowInfoBar(contents);
2170 if (needs_layout) 2142 if (needs_layout)
2171 Layout(); 2143 Layout();
2172 } 2144 }
2173 2145
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 // handlers when we are eventually shown. 2535 // handlers when we are eventually shown.
2564 new_contents->view()->RestoreFocus(); 2536 new_contents->view()->RestoreFocus();
2565 } 2537 }
2566 2538
2567 // Update all the UI bits. 2539 // Update all the UI bits.
2568 UpdateTitleBar(); 2540 UpdateTitleBar();
2569 UpdateToolbar(new_contents, true); 2541 UpdateToolbar(new_contents, true);
2570 UpdateUIForContents(new_contents); 2542 UpdateUIForContents(new_contents);
2571 } 2543 }
2572 2544
2545 gfx::Size BrowserView::GetResizeCornerSize() const {
2546 return ResizeCorner::GetSize();
2547 }
2548
2573 #if !defined(OS_CHROMEOS) 2549 #if !defined(OS_CHROMEOS)
2574 // static 2550 // static
2575 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { 2551 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) {
2576 // Create the view and the frame. The frame will attach itself via the view 2552 // Create the view and the frame. The frame will attach itself via the view
2577 // so we don't need to do anything with the pointer. 2553 // so we don't need to do anything with the pointer.
2578 BrowserView* view = new BrowserView(browser); 2554 BrowserView* view = new BrowserView(browser);
2579 BrowserFrame::Create(view, browser->profile()); 2555 BrowserFrame::Create(view, browser->profile());
2580 2556
2581 view->GetWindow()->GetNonClientView()->SetAccessibleName( 2557 view->GetWindow()->GetNonClientView()->SetAccessibleName(
2582 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); 2558 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
2583 2559
2584 return view; 2560 return view;
2585 } 2561 }
2586 #endif 2562 #endif
2587 2563
2588 // static 2564 // static
2589 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { 2565 FindBar* BrowserWindow::CreateFindBar(Browser* browser) {
2590 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); 2566 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window()));
2591 } 2567 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view.h ('k') | chrome/browser/ui/views/frame/browser_view_layout.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698