OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/frame/browser_view.h" | 5 #include "chrome/browser/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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // The number of milliseconds between loading animation frames. | 93 // The number of milliseconds between loading animation frames. |
94 static const int kLoadingAnimationFrameTimeMs = 30; | 94 static const int kLoadingAnimationFrameTimeMs = 30; |
95 // The amount of space we expect the window border to take up. | 95 // The amount of space we expect the window border to take up. |
96 static const int kWindowBorderWidth = 5; | 96 static const int kWindowBorderWidth = 5; |
97 | 97 |
98 // If not -1, windows are shown with this state. | 98 // If not -1, windows are shown with this state. |
99 static int explicit_show_state = -1; | 99 static int explicit_show_state = -1; |
100 | 100 |
101 // How round the 'new tab' style bookmarks bar is. | 101 // How round the 'new tab' style bookmarks bar is. |
102 static const int kNewtabBarRoundness = 5; | 102 static const int kNewtabBarRoundness = 5; |
103 | |
104 // The maximum width of the big title shown for extension app windows. | |
105 static const int kExtensionAppTitleMaxWidth = 150; | |
106 | |
107 // ------------ | 103 // ------------ |
108 | 104 |
109 // Returned from BrowserView::GetClassName. | 105 // Returned from BrowserView::GetClassName. |
110 const char BrowserView::kViewClassName[] = "browser/views/BrowserView"; | 106 const char BrowserView::kViewClassName[] = "browser/views/BrowserView"; |
111 | 107 |
112 #if defined(OS_CHROMEOS) | 108 #if defined(OS_CHROMEOS) |
113 // Get a normal browser window of given |profile| to use as dialog parent | 109 // Get a normal browser window of given |profile| to use as dialog parent |
114 // if given |browser| is not one. Otherwise, returns browser window of | 110 // if given |browser| is not one. Otherwise, returns browser window of |
115 // |browser|. If |profile| is NULL, |browser|'s profile is used to find the | 111 // |browser|. If |profile| is NULL, |browser|'s profile is used to find the |
116 // normal browser. | 112 // normal browser. |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 explicit_show_state = state; | 400 explicit_show_state = state; |
405 } | 401 } |
406 | 402 |
407 BrowserView::BrowserView(Browser* browser) | 403 BrowserView::BrowserView(Browser* browser) |
408 : views::ClientView(NULL, NULL), | 404 : views::ClientView(NULL, NULL), |
409 last_focused_view_storage_id_( | 405 last_focused_view_storage_id_( |
410 views::ViewStorage::GetSharedInstance()->CreateStorageID()), | 406 views::ViewStorage::GetSharedInstance()->CreateStorageID()), |
411 frame_(NULL), | 407 frame_(NULL), |
412 browser_(browser), | 408 browser_(browser), |
413 active_bookmark_bar_(NULL), | 409 active_bookmark_bar_(NULL), |
414 extension_app_icon_(NULL), | |
415 extension_app_title_(NULL), | |
416 tabstrip_(NULL), | 410 tabstrip_(NULL), |
417 toolbar_(NULL), | 411 toolbar_(NULL), |
418 infobar_container_(NULL), | 412 infobar_container_(NULL), |
419 contents_container_(NULL), | 413 contents_container_(NULL), |
420 devtools_container_(NULL), | 414 devtools_container_(NULL), |
421 contents_split_(NULL), | 415 contents_split_(NULL), |
422 initialized_(false), | 416 initialized_(false), |
423 ignore_layout_(true), | 417 ignore_layout_(true), |
424 #if defined(OS_WIN) | 418 #if defined(OS_WIN) |
425 hung_window_detector_(&hung_plugin_action_), | 419 hung_window_detector_(&hung_plugin_action_), |
426 ticker_(0), | 420 ticker_(0), |
427 #endif | 421 #endif |
428 extension_shelf_(NULL), | 422 extension_shelf_(NULL) { |
429 extension_app_icon_loader_(this) { | |
430 browser_->tabstrip_model()->AddObserver(this); | 423 browser_->tabstrip_model()->AddObserver(this); |
431 } | 424 } |
432 | 425 |
433 BrowserView::~BrowserView() { | 426 BrowserView::~BrowserView() { |
434 browser_->tabstrip_model()->RemoveObserver(this); | 427 browser_->tabstrip_model()->RemoveObserver(this); |
435 | 428 |
436 #if defined(OS_WIN) | 429 #if defined(OS_WIN) |
437 // Remove this observer. | 430 // Remove this observer. |
438 if (aeropeek_manager_.get()) | 431 if (aeropeek_manager_.get()) |
439 browser_->tabstrip_model()->RemoveObserver(aeropeek_manager_.get()); | 432 browser_->tabstrip_model()->RemoveObserver(aeropeek_manager_.get()); |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 ui_controls::SendKeyPress(GetNativeHandle(), base::VKEY_V, | 1278 ui_controls::SendKeyPress(GetNativeHandle(), base::VKEY_V, |
1286 false, false, false, true); | 1279 false, false, false, true); |
1287 } | 1280 } |
1288 #endif | 1281 #endif |
1289 | 1282 |
1290 void BrowserView::ToggleTabStripMode() { | 1283 void BrowserView::ToggleTabStripMode() { |
1291 InitTabStrip(browser_->tabstrip_model()); | 1284 InitTabStrip(browser_->tabstrip_model()); |
1292 frame_->TabStripDisplayModeChanged(); | 1285 frame_->TabStripDisplayModeChanged(); |
1293 } | 1286 } |
1294 | 1287 |
1295 void BrowserView::SetToolbarCollapsedMode(bool val) { | |
1296 toolbar_->SetCollapsed(val); | |
1297 Layout(); | |
1298 } | |
1299 | |
1300 /////////////////////////////////////////////////////////////////////////////// | 1288 /////////////////////////////////////////////////////////////////////////////// |
1301 // BrowserView, BrowserWindowTesting implementation: | 1289 // BrowserView, BrowserWindowTesting implementation: |
1302 | 1290 |
1303 BookmarkBarView* BrowserView::GetBookmarkBarView() const { | 1291 BookmarkBarView* BrowserView::GetBookmarkBarView() const { |
1304 return bookmark_bar_view_.get(); | 1292 return bookmark_bar_view_.get(); |
1305 } | 1293 } |
1306 | 1294 |
1307 LocationBarView* BrowserView::GetLocationBarView() const { | 1295 LocationBarView* BrowserView::GetLocationBarView() const { |
1308 return toolbar_->location_bar(); | 1296 return toolbar_->location_bar(); |
1309 } | 1297 } |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1711 | 1699 |
1712 BrowserTabStripController* tabstrip_controller = | 1700 BrowserTabStripController* tabstrip_controller = |
1713 new BrowserTabStripController(model); | 1701 new BrowserTabStripController(model); |
1714 | 1702 |
1715 if (UseVerticalTabs()) | 1703 if (UseVerticalTabs()) |
1716 tabstrip_ = new SideTabStrip(tabstrip_controller); | 1704 tabstrip_ = new SideTabStrip(tabstrip_controller); |
1717 else | 1705 else |
1718 tabstrip_ = new TabStrip(tabstrip_controller); | 1706 tabstrip_ = new TabStrip(tabstrip_controller); |
1719 | 1707 |
1720 tabstrip_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TABSTRIP)); | 1708 tabstrip_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TABSTRIP)); |
1721 if (browser_->extension_app() && tabstrip_->AsTabStrip()) | |
1722 tabstrip_->AsTabStrip()->set_new_tab_button_enabled(false); | |
1723 AddChildView(tabstrip_); | 1709 AddChildView(tabstrip_); |
1724 | 1710 |
1725 tabstrip_controller->InitFromModel(tabstrip_); | 1711 tabstrip_controller->InitFromModel(tabstrip_); |
1726 } | 1712 } |
1727 | 1713 |
1728 /////////////////////////////////////////////////////////////////////////////// | 1714 /////////////////////////////////////////////////////////////////////////////// |
1729 // BrowserView, private: | 1715 // BrowserView, private: |
1730 | 1716 |
1731 void BrowserView::Init() { | 1717 void BrowserView::Init() { |
1732 accessible_view_helper_.reset(new AccessibleViewHelper( | 1718 accessible_view_helper_.reset(new AccessibleViewHelper( |
(...skipping 12 matching lines...) Expand all Loading... |
1745 // Start a hung plugin window detector for this browser object (as long as | 1731 // Start a hung plugin window detector for this browser object (as long as |
1746 // hang detection is not disabled). | 1732 // hang detection is not disabled). |
1747 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 1733 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
1748 switches::kDisableHangMonitor)) { | 1734 switches::kDisableHangMonitor)) { |
1749 InitHangMonitor(); | 1735 InitHangMonitor(); |
1750 } | 1736 } |
1751 | 1737 |
1752 LoadAccelerators(); | 1738 LoadAccelerators(); |
1753 SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME)); | 1739 SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME)); |
1754 | 1740 |
1755 if (browser_->extension_app()) { | |
1756 extension_app_icon_ = new views::ImageView(); | |
1757 extension_app_icon_->SetID(VIEW_ID_EXTENSION_APP_ICON); | |
1758 AddChildView(extension_app_icon_); | |
1759 | |
1760 extension_app_title_ = new views::Label(); | |
1761 extension_app_title_->SetFont( | |
1762 extension_app_title_->font().DeriveFont(1, gfx::Font::BOLD)); | |
1763 extension_app_title_->SetColor(SK_ColorWHITE); | |
1764 extension_app_title_->SetID(VIEW_ID_EXTENSION_APP_TITLE); | |
1765 AddChildView(extension_app_title_); | |
1766 | |
1767 extension_app_icon_loader_.LoadImage( | |
1768 browser_->extension_app(), | |
1769 browser_->extension_app()->GetIconPath( | |
1770 Extension::EXTENSION_ICON_MEDIUM), | |
1771 gfx::Size(Extension::EXTENSION_ICON_SMALL, | |
1772 Extension::EXTENSION_ICON_SMALL), | |
1773 ImageLoadingTracker::CACHE); | |
1774 | |
1775 extension_app_title_->SetText( | |
1776 UTF8ToWide(browser_->extension_app()->name())); | |
1777 extension_app_title_->SizeToPreferredSize(); | |
1778 | |
1779 if (extension_app_title_->width() > kExtensionAppTitleMaxWidth) { | |
1780 extension_app_title_->SetBounds(extension_app_title_->x(), | |
1781 extension_app_title_->y(), | |
1782 kExtensionAppTitleMaxWidth, | |
1783 extension_app_title_->height()); | |
1784 } | |
1785 } | |
1786 | |
1787 InitTabStrip(browser_->tabstrip_model()); | 1741 InitTabStrip(browser_->tabstrip_model()); |
1788 | 1742 |
1789 toolbar_ = new ToolbarView(browser_.get()); | 1743 toolbar_ = new ToolbarView(browser_.get()); |
1790 AddChildView(toolbar_); | 1744 AddChildView(toolbar_); |
1791 toolbar_->Init(browser_->profile()); | 1745 toolbar_->Init(browser_->profile()); |
1792 toolbar_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TOOLBAR)); | 1746 toolbar_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TOOLBAR)); |
1793 if (browser_->type() == Browser::TYPE_EXTENSION_APP) | |
1794 toolbar_->SetCollapsed(true); | |
1795 | 1747 |
1796 infobar_container_ = new InfoBarContainer(this); | 1748 infobar_container_ = new InfoBarContainer(this); |
1797 AddChildView(infobar_container_); | 1749 AddChildView(infobar_container_); |
1798 | 1750 |
1799 contents_container_ = new TabContentsContainer; | 1751 contents_container_ = new TabContentsContainer; |
1800 devtools_container_ = new TabContentsContainer; | 1752 devtools_container_ = new TabContentsContainer; |
1801 devtools_container_->SetID(VIEW_ID_DEV_TOOLS_DOCKED); | 1753 devtools_container_->SetID(VIEW_ID_DEV_TOOLS_DOCKED); |
1802 devtools_container_->SetVisible(false); | 1754 devtools_container_->SetVisible(false); |
1803 contents_split_ = new views::SingleSplitView( | 1755 contents_split_ = new views::SingleSplitView( |
1804 contents_container_, | 1756 contents_container_, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1857 BuildSystemMenuForBrowserWindow(); | 1809 BuildSystemMenuForBrowserWindow(); |
1858 else | 1810 else |
1859 BuildSystemMenuForAppOrPopupWindow(browser_->type() == Browser::TYPE_APP); | 1811 BuildSystemMenuForAppOrPopupWindow(browser_->type() == Browser::TYPE_APP); |
1860 system_menu_.reset( | 1812 system_menu_.reset( |
1861 new views::NativeMenuWin(system_menu_contents_.get(), | 1813 new views::NativeMenuWin(system_menu_contents_.get(), |
1862 frame_->GetWindow()->GetNativeWindow())); | 1814 frame_->GetWindow()->GetNativeWindow())); |
1863 system_menu_->Rebuild(); | 1815 system_menu_->Rebuild(); |
1864 } | 1816 } |
1865 #endif | 1817 #endif |
1866 | 1818 |
1867 void BrowserView::OnImageLoaded(SkBitmap* image, ExtensionResource resource, | |
1868 int index) { | |
1869 if (image) | |
1870 extension_app_icon_->SetImage(*image); | |
1871 } | |
1872 | |
1873 BrowserViewLayout* BrowserView::GetBrowserViewLayout() const { | 1819 BrowserViewLayout* BrowserView::GetBrowserViewLayout() const { |
1874 return static_cast<BrowserViewLayout*>(GetLayoutManager()); | 1820 return static_cast<BrowserViewLayout*>(GetLayoutManager()); |
1875 } | 1821 } |
1876 | 1822 |
1877 void BrowserView::LayoutStatusBubble(int top) { | 1823 void BrowserView::LayoutStatusBubble(int top) { |
1878 // In restored mode, the client area has a client edge between it and the | 1824 // In restored mode, the client area has a client edge between it and the |
1879 // frame. | 1825 // frame. |
1880 int overlap = StatusBubbleViews::kShadowThickness + | 1826 int overlap = StatusBubbleViews::kShadowThickness + |
1881 (IsMaximized() ? 0 : views::NonClientFrameView::kClientEdgeThickness); | 1827 (IsMaximized() ? 0 : views::NonClientFrameView::kClientEdgeThickness); |
1882 int x = -overlap; | 1828 int x = -overlap; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2016 return changed; | 1962 return changed; |
2017 } | 1963 } |
2018 | 1964 |
2019 void BrowserView::ProcessFullscreen(bool fullscreen) { | 1965 void BrowserView::ProcessFullscreen(bool fullscreen) { |
2020 // Reduce jankiness during the following position changes by: | 1966 // Reduce jankiness during the following position changes by: |
2021 // * Hiding the window until it's in the final position | 1967 // * Hiding the window until it's in the final position |
2022 // * Ignoring all intervening Layout() calls, which resize the webpage and | 1968 // * Ignoring all intervening Layout() calls, which resize the webpage and |
2023 // thus are slow and look ugly | 1969 // thus are slow and look ugly |
2024 ignore_layout_ = true; | 1970 ignore_layout_ = true; |
2025 LocationBarView* location_bar = toolbar_->location_bar(); | 1971 LocationBarView* location_bar = toolbar_->location_bar(); |
| 1972 #if defined(OS_WIN) |
| 1973 AutocompleteEditViewWin* edit_view = |
| 1974 static_cast<AutocompleteEditViewWin*>(location_bar->location_entry()); |
| 1975 #endif |
2026 if (!fullscreen) { | 1976 if (!fullscreen) { |
2027 // Hide the fullscreen bubble as soon as possible, since the mode toggle can | 1977 // Hide the fullscreen bubble as soon as possible, since the mode toggle can |
2028 // take enough time for the user to notice. | 1978 // take enough time for the user to notice. |
2029 fullscreen_bubble_.reset(); | 1979 fullscreen_bubble_.reset(); |
2030 } else { | 1980 } else { |
2031 // Move focus out of the location bar if necessary. | 1981 // Move focus out of the location bar if necessary. |
2032 views::FocusManager* focus_manager = GetFocusManager(); | 1982 views::FocusManager* focus_manager = GetFocusManager(); |
2033 DCHECK(focus_manager); | 1983 DCHECK(focus_manager); |
2034 if (focus_manager->GetFocusedView() == location_bar) | 1984 if (focus_manager->GetFocusedView() == location_bar) |
2035 focus_manager->ClearFocus(); | 1985 focus_manager->ClearFocus(); |
2036 | 1986 |
| 1987 #if defined(OS_WIN) |
2037 // If we don't hide the edit and force it to not show until we come out of | 1988 // If we don't hide the edit and force it to not show until we come out of |
2038 // fullscreen, then if the user was on the New Tab Page, the edit contents | 1989 // fullscreen, then if the user was on the New Tab Page, the edit contents |
2039 // will appear atop the web contents once we go into fullscreen mode. This | 1990 // will appear atop the web contents once we go into fullscreen mode. This |
2040 // has something to do with how we move the main window while it's hidden; | 1991 // has something to do with how we move the main window while it's hidden; |
2041 // if we don't hide the main window below, we don't get this problem. | 1992 // if we don't hide the main window below, we don't get this problem. |
2042 location_bar->PushForceHidden(); | 1993 edit_view->set_force_hidden(true); |
| 1994 ShowWindow(edit_view->m_hWnd, SW_HIDE); |
| 1995 #endif |
2043 } | 1996 } |
2044 #if defined(OS_WIN) | 1997 #if defined(OS_WIN) |
2045 frame_->GetWindow()->PushForceHidden(); | 1998 frame_->GetWindow()->PushForceHidden(); |
2046 #endif | 1999 #endif |
2047 | 2000 |
2048 // Notify bookmark bar, so it can set itself to the appropriate drawing state. | 2001 // Notify bookmark bar, so it can set itself to the appropriate drawing state. |
2049 if (bookmark_bar_view_.get()) | 2002 if (bookmark_bar_view_.get()) |
2050 bookmark_bar_view_->OnFullscreenToggled(fullscreen); | 2003 bookmark_bar_view_->OnFullscreenToggled(fullscreen); |
2051 | 2004 |
2052 // Notify extension shelf, so it can set itself to the appropriate drawing | 2005 // Notify extension shelf, so it can set itself to the appropriate drawing |
(...skipping 16 matching lines...) Expand all Loading... |
2069 #endif | 2022 #endif |
2070 | 2023 |
2071 if (fullscreen) { | 2024 if (fullscreen) { |
2072 bool is_kiosk = | 2025 bool is_kiosk = |
2073 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); | 2026 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); |
2074 if (!is_kiosk) { | 2027 if (!is_kiosk) { |
2075 fullscreen_bubble_.reset(new FullscreenExitBubble(GetWidget(), | 2028 fullscreen_bubble_.reset(new FullscreenExitBubble(GetWidget(), |
2076 browser_.get())); | 2029 browser_.get())); |
2077 } | 2030 } |
2078 } else { | 2031 } else { |
| 2032 #if defined(OS_WIN) |
2079 // Show the edit again since we're no longer in fullscreen mode. | 2033 // Show the edit again since we're no longer in fullscreen mode. |
2080 location_bar->PopForceHidden(); | 2034 edit_view->set_force_hidden(false); |
| 2035 ShowWindow(edit_view->m_hWnd, SW_SHOW); |
| 2036 #endif |
2081 } | 2037 } |
2082 | 2038 |
2083 // Undo our anti-jankiness hacks and force the window to relayout now that | 2039 // Undo our anti-jankiness hacks and force the window to relayout now that |
2084 // it's in its final position. | 2040 // it's in its final position. |
2085 ignore_layout_ = false; | 2041 ignore_layout_ = false; |
2086 Layout(); | 2042 Layout(); |
2087 #if defined(OS_WIN) | 2043 #if defined(OS_WIN) |
2088 frame_->GetWindow()->PopForceHidden(); | 2044 frame_->GetWindow()->PopForceHidden(); |
2089 #endif | 2045 #endif |
2090 } | 2046 } |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2280 SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME)); | 2236 SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME)); |
2281 | 2237 |
2282 return view; | 2238 return view; |
2283 } | 2239 } |
2284 #endif | 2240 #endif |
2285 | 2241 |
2286 // static | 2242 // static |
2287 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { | 2243 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { |
2288 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); | 2244 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); |
2289 } | 2245 } |
OLD | NEW |