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