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

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

Issue 6692001: Add in DOMBrowserView and Frame related classes (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Removed DOMBrowserFrame* classes and added changes in line with oshima's comments Created 9 years, 9 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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 #endif 465 #endif
466 466
467 // We destroy the download shelf before |browser_| to remove its child 467 // We destroy the download shelf before |browser_| to remove its child
468 // download views from the set of download observers (since the observed 468 // download views from the set of download observers (since the observed
469 // downloads can be destroyed along with |browser_| and the observer 469 // downloads can be destroyed along with |browser_| and the observer
470 // notifications will call back into deleted objects). 470 // notifications will call back into deleted objects).
471 download_shelf_.reset(); 471 download_shelf_.reset();
472 472
473 // The TabStrip attaches a listener to the model. Make sure we shut down the 473 // The TabStrip attaches a listener to the model. Make sure we shut down the
474 // TabStrip first so that it can cleanly remove the listener. 474 // TabStrip first so that it can cleanly remove the listener.
475 tabstrip_->parent()->RemoveChildView(tabstrip_); 475 if (tabstrip_) {
476 delete tabstrip_; 476 tabstrip_->parent()->RemoveChildView(tabstrip_);
477 tabstrip_ = NULL; 477 delete tabstrip_;
478 478 tabstrip_ = NULL;
479 }
479 // Child views maintain PrefMember attributes that point to 480 // Child views maintain PrefMember attributes that point to
480 // OffTheRecordProfile's PrefService which gets deleted by ~Browser. 481 // OffTheRecordProfile's PrefService which gets deleted by ~Browser.
481 RemoveAllChildViews(true); 482 RemoveAllChildViews(true);
482 // Explicitly set browser_ to NULL. 483 // Explicitly set browser_ to NULL.
483 browser_.reset(); 484 browser_.reset();
484 } 485 }
485 486
486 // static 487 // static
487 BrowserView* BrowserView::GetBrowserViewForNativeWindow( 488 BrowserView* BrowserView::GetBrowserViewForNativeWindow(
488 gfx::NativeWindow window) { 489 gfx::NativeWindow window) {
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 // Comment out for one cycle to see if this fixes dist tests. 1645 // Comment out for one cycle to see if this fixes dist tests.
1645 // tabstrip_->DestroyDragController(); 1646 // tabstrip_->DestroyDragController();
1646 1647
1647 status_bubble_->Reposition(); 1648 status_bubble_->Reposition();
1648 1649
1649 BrowserBubbleHost::WindowMoved(); 1650 BrowserBubbleHost::WindowMoved();
1650 1651
1651 browser::HideBookmarkBubbleView(); 1652 browser::HideBookmarkBubbleView();
1652 1653
1653 // Close the omnibox popup, if any. 1654 // Close the omnibox popup, if any.
1654 if (toolbar_->location_bar()) 1655 if (toolbar_ && toolbar_->location_bar())
1655 toolbar_->location_bar()->location_entry()->ClosePopup(); 1656 toolbar_->location_bar()->location_entry()->ClosePopup();
1656 } 1657 }
1657 1658
1658 /////////////////////////////////////////////////////////////////////////////// 1659 ///////////////////////////////////////////////////////////////////////////////
1659 // BrowserView, views::ClientView overrides: 1660 // BrowserView, views::ClientView overrides:
1660 1661
1661 bool BrowserView::CanClose() { 1662 bool BrowserView::CanClose() {
1662 // You cannot close a frame for which there is an active originating drag 1663 // You cannot close a frame for which there is an active originating drag
1663 // session. 1664 // session.
1664 if (!tabstrip_->IsTabStripCloseable()) 1665 if (tabstrip_ && !tabstrip_->IsTabStripCloseable())
1665 return false; 1666 return false;
1666 1667
1667 // Give beforeunload handlers the chance to cancel the close before we hide 1668 // Give beforeunload handlers the chance to cancel the close before we hide
1668 // the window below. 1669 // the window below.
1669 if (!browser_->ShouldCloseWindow()) 1670 if (!browser_->ShouldCloseWindow())
1670 return false; 1671 return false;
1671 1672
1672 if (!browser_->tabstrip_model()->empty()) { 1673 if (!browser_->tabstrip_model()->empty()) {
1673 // Tab strip isn't empty. Hide the frame (so it appears to have closed 1674 // Tab strip isn't empty. Hide the frame (so it appears to have closed
1674 // immediately) and close all the tabs, allowing the renderers to shut 1675 // immediately) and close all the tabs, allowing the renderers to shut
1675 // down. When the tab strip is empty we'll be called back again. 1676 // down. When the tab strip is empty we'll be called back again.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 void BrowserView::InitTabStrip(TabStripModel* model) { 1814 void BrowserView::InitTabStrip(TabStripModel* model) {
1814 // Throw away the existing tabstrip if we're switching display modes. 1815 // Throw away the existing tabstrip if we're switching display modes.
1815 scoped_ptr<AbstractTabStripView> old_strip(tabstrip_); 1816 scoped_ptr<AbstractTabStripView> old_strip(tabstrip_);
1816 if (tabstrip_) 1817 if (tabstrip_)
1817 tabstrip_->parent()->RemoveChildView(tabstrip_); 1818 tabstrip_->parent()->RemoveChildView(tabstrip_);
1818 1819
1819 tabstrip_ = CreateTabStrip(browser_.get(), model, UseVerticalTabs()); 1820 tabstrip_ = CreateTabStrip(browser_.get(), model, UseVerticalTabs());
1820 AddChildView(tabstrip_); 1821 AddChildView(tabstrip_);
1821 } 1822 }
1822 1823
1823 /////////////////////////////////////////////////////////////////////////////// 1824 ToolbarView* BrowserView::CreateToolbar() const {
1824 // BrowserView, private: 1825 return new ToolbarView(browser_.get());
1826 }
1825 1827
1826 void BrowserView::Init() { 1828 void BrowserView::Init() {
1827 SetLayoutManager(CreateLayoutManager()); 1829 SetLayoutManager(CreateLayoutManager());
1828 // Stow a pointer to this object onto the window handle so that we can get at 1830 // Stow a pointer to this object onto the window handle so that we can get at
1829 // it later when all we have is a native view. 1831 // it later when all we have is a native view.
1830 GetWidget()->native_widget()->SetNativeWindowProperty(kBrowserViewKey, this); 1832 GetWidget()->native_widget()->SetNativeWindowProperty(kBrowserViewKey, this);
1831 1833
1832 // Stow a pointer to the browser's profile onto the window handle so that we 1834 // Stow a pointer to the browser's profile onto the window handle so that we
1833 // can get it later when all we have is a native view. 1835 // can get it later when all we have is a native view.
1834 GetWidget()->native_widget()->SetNativeWindowProperty(Profile::kProfileKey, 1836 GetWidget()->native_widget()->SetNativeWindowProperty(Profile::kProfileKey,
1835 browser_->profile()); 1837 browser_->profile());
1836 1838
1837 // Start a hung plugin window detector for this browser object (as long as 1839 // Start a hung plugin window detector for this browser object (as long as
1838 // hang detection is not disabled). 1840 // hang detection is not disabled).
1839 if (!CommandLine::ForCurrentProcess()->HasSwitch( 1841 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1840 switches::kDisableHangMonitor)) { 1842 switches::kDisableHangMonitor)) {
1841 InitHangMonitor(); 1843 InitHangMonitor();
1842 } 1844 }
1843 1845
1844 LoadAccelerators(); 1846 LoadAccelerators();
1845 1847
1846 InitTabStrip(browser_->tabstrip_model()); 1848 InitTabStrip(browser_->tabstrip_model());
1847 1849
1848 toolbar_ = new ToolbarView(browser_.get()); 1850 SetToolbar(CreateToolbar());
1849 AddChildView(toolbar_);
1850 toolbar_->Init(browser_->profile());
1851 1851
1852 infobar_container_ = new InfoBarContainer(this); 1852 infobar_container_ = new InfoBarContainer(this);
1853 AddChildView(infobar_container_); 1853 AddChildView(infobar_container_);
1854 1854
1855 contents_container_ = new TabContentsContainer; 1855 contents_container_ = new TabContentsContainer;
1856 contents_ = new ContentsContainer(contents_container_); 1856 contents_ = new ContentsContainer(contents_container_);
1857 1857
1858 SkColor bg_color = GetWidget()->GetThemeProvider()-> 1858 SkColor bg_color = GetWidget()->GetThemeProvider()->
1859 GetColor(BrowserThemeProvider::COLOR_TOOLBAR); 1859 GetColor(BrowserThemeProvider::COLOR_TOOLBAR);
1860 1860
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 aeropeek_manager_.reset(new AeroPeekManager( 1913 aeropeek_manager_.reset(new AeroPeekManager(
1914 frame_->GetWindow()->GetNativeWindow())); 1914 frame_->GetWindow()->GetNativeWindow()));
1915 browser_->tabstrip_model()->AddObserver(aeropeek_manager_.get()); 1915 browser_->tabstrip_model()->AddObserver(aeropeek_manager_.get());
1916 } 1916 }
1917 #endif 1917 #endif
1918 1918
1919 // We're now initialized and ready to process Layout requests. 1919 // We're now initialized and ready to process Layout requests.
1920 ignore_layout_ = false; 1920 ignore_layout_ = false;
1921 } 1921 }
1922 1922
1923 void BrowserView::LoadingAnimationCallback() {
1924 base::TimeTicks now = base::TimeTicks::Now();
1925 if (!last_animation_time_.is_null()) {
1926 UMA_HISTOGRAM_TIMES(
1927 "Tabs.LoadingAnimationTime",
1928 now - last_animation_time_);
1929 }
1930 last_animation_time_ = now;
1931 if (browser_->type() == Browser::TYPE_NORMAL) {
1932 // Loading animations are shown in the tab for tabbed windows. We check the
1933 // browser type instead of calling IsTabStripVisible() because the latter
1934 // will return false for fullscreen windows, but we still need to update
1935 // their animations (so that when they come out of fullscreen mode they'll
1936 // be correct).
1937 tabstrip_->UpdateLoadingAnimations();
1938 } else if (ShouldShowWindowIcon()) {
1939 // ... or in the window icon area for popups and app windows.
1940 TabContents* tab_contents = browser_->GetSelectedTabContents();
1941 // GetSelectedTabContents can return NULL for example under Purify when
1942 // the animations are running slowly and this function is called on a timer
1943 // through LoadingAnimationCallback.
1944 frame_->UpdateThrobber(tab_contents && tab_contents->is_loading());
1945 }
1946 }
1947
1948 // BrowserView, private --------------------------------------------------------
1949
1923 #if defined(OS_WIN) 1950 #if defined(OS_WIN)
1924 void BrowserView::InitSystemMenu() { 1951 void BrowserView::InitSystemMenu() {
1925 system_menu_contents_.reset(new views::SystemMenuModel(this)); 1952 system_menu_contents_.reset(new views::SystemMenuModel(this));
1926 // We add the menu items in reverse order so that insertion_index never needs 1953 // We add the menu items in reverse order so that insertion_index never needs
1927 // to change. 1954 // to change.
1928 if (IsBrowserTypeNormal()) 1955 if (IsBrowserTypeNormal())
1929 BuildSystemMenuForBrowserWindow(); 1956 BuildSystemMenuForBrowserWindow();
1930 else 1957 else
1931 BuildSystemMenuForAppOrPopupWindow(browser_->type() == Browser::TYPE_APP); 1958 BuildSystemMenuForAppOrPopupWindow(browser_->type() == Browser::TYPE_APP);
1932 system_menu_.reset( 1959 system_menu_.reset(
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2364 case APPCOMMAND_REDO: 2391 case APPCOMMAND_REDO:
2365 case APPCOMMAND_SPELL_CHECK: 2392 case APPCOMMAND_SPELL_CHECK:
2366 default: return -1; 2393 default: return -1;
2367 } 2394 }
2368 #else 2395 #else
2369 // App commands are Windows-specific so there's nothing to do here. 2396 // App commands are Windows-specific so there's nothing to do here.
2370 return -1; 2397 return -1;
2371 #endif 2398 #endif
2372 } 2399 }
2373 2400
2374 void BrowserView::LoadingAnimationCallback() {
2375 base::TimeTicks now = base::TimeTicks::Now();
2376 if (!last_animation_time_.is_null()) {
2377 UMA_HISTOGRAM_TIMES(
2378 "Tabs.LoadingAnimationTime",
2379 now - last_animation_time_);
2380 }
2381 last_animation_time_ = now;
2382 if (browser_->type() == Browser::TYPE_NORMAL) {
2383 // Loading animations are shown in the tab for tabbed windows. We check the
2384 // browser type instead of calling IsTabStripVisible() because the latter
2385 // will return false for fullscreen windows, but we still need to update
2386 // their animations (so that when they come out of fullscreen mode they'll
2387 // be correct).
2388 tabstrip_->UpdateLoadingAnimations();
2389 } else if (ShouldShowWindowIcon()) {
2390 // ... or in the window icon area for popups and app windows.
2391 TabContents* tab_contents = browser_->GetSelectedTabContents();
2392 // GetSelectedTabContents can return NULL for example under Purify when
2393 // the animations are running slowly and this function is called on a timer
2394 // through LoadingAnimationCallback.
2395 frame_->UpdateThrobber(tab_contents && tab_contents->is_loading());
2396 }
2397 }
2398
2399 void BrowserView::InitHangMonitor() { 2401 void BrowserView::InitHangMonitor() {
2400 #if defined(OS_WIN) 2402 #if defined(OS_WIN)
2401 PrefService* pref_service = g_browser_process->local_state(); 2403 PrefService* pref_service = g_browser_process->local_state();
2402 if (!pref_service) 2404 if (!pref_service)
2403 return; 2405 return;
2404 2406
2405 int plugin_message_response_timeout = 2407 int plugin_message_response_timeout =
2406 pref_service->GetInteger(prefs::kPluginMessageResponseTimeout); 2408 pref_service->GetInteger(prefs::kPluginMessageResponseTimeout);
2407 int hung_plugin_detect_freq = 2409 int hung_plugin_detect_freq =
2408 pref_service->GetInteger(prefs::kHungPluginDetectFrequency); 2410 pref_service->GetInteger(prefs::kHungPluginDetectFrequency);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2514 // Update all the UI bits. 2516 // Update all the UI bits.
2515 UpdateTitleBar(); 2517 UpdateTitleBar();
2516 // No need to update Toolbar because it's already updated in 2518 // No need to update Toolbar because it's already updated in
2517 // browser.cc. 2519 // browser.cc.
2518 } 2520 }
2519 2521
2520 gfx::Size BrowserView::GetResizeCornerSize() const { 2522 gfx::Size BrowserView::GetResizeCornerSize() const {
2521 return ResizeCorner::GetSize(); 2523 return ResizeCorner::GetSize();
2522 } 2524 }
2523 2525
2526 void BrowserView::SetToolbar(ToolbarView* toolbar) {
2527 if (toolbar_) {
2528 RemoveChildView(toolbar_);
2529 delete toolbar_;
2530 }
2531 toolbar_ = toolbar;
2532 if (toolbar) {
2533 AddChildView(toolbar_);
2534 toolbar_->Init(browser_->profile());
2535 }
2536 }
2537
2524 #if !defined(OS_CHROMEOS) 2538 #if !defined(OS_CHROMEOS)
2525 // static 2539 // static
2526 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { 2540 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) {
2527 // Create the view and the frame. The frame will attach itself via the view 2541 // Create the view and the frame. The frame will attach itself via the view
2528 // so we don't need to do anything with the pointer. 2542 // so we don't need to do anything with the pointer.
2529 BrowserView* view = new BrowserView(browser); 2543 BrowserView* view = new BrowserView(browser);
2530 BrowserFrame::Create(view, browser->profile()); 2544 BrowserFrame::Create(view, browser->profile());
2531 2545
2532 view->GetWindow()->non_client_view()->SetAccessibleName( 2546 view->GetWindow()->non_client_view()->SetAccessibleName(
2533 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 2547 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
2534 2548
2535 return view; 2549 return view;
2536 } 2550 }
2537 #endif 2551 #endif
2538 2552
2539 // static 2553 // static
2540 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { 2554 FindBar* BrowserWindow::CreateFindBar(Browser* browser) {
2541 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); 2555 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window()));
2542 } 2556 }
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