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