| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 #include "chrome/common/pref_names.h" | 59 #include "chrome/common/pref_names.h" |
| 60 #include "chrome/common/pref_service.h" | 60 #include "chrome/common/pref_service.h" |
| 61 #include "grit/app_resources.h" | 61 #include "grit/app_resources.h" |
| 62 #include "grit/chromium_strings.h" | 62 #include "grit/chromium_strings.h" |
| 63 #include "grit/generated_resources.h" | 63 #include "grit/generated_resources.h" |
| 64 #include "grit/theme_resources.h" | 64 #include "grit/theme_resources.h" |
| 65 #include "grit/webkit_resources.h" | 65 #include "grit/webkit_resources.h" |
| 66 #include "views/controls/single_split_view.h" | 66 #include "views/controls/single_split_view.h" |
| 67 #include "views/fill_layout.h" | 67 #include "views/fill_layout.h" |
| 68 #include "views/focus/external_focus_tracker.h" | 68 #include "views/focus/external_focus_tracker.h" |
| 69 #include "views/focus/view_storage.h" |
| 69 #include "views/grid_layout.h" | 70 #include "views/grid_layout.h" |
| 70 #include "views/view.h" | 71 #include "views/view.h" |
| 71 #include "views/widget/root_view.h" | 72 #include "views/widget/root_view.h" |
| 72 #include "views/window/dialog_delegate.h" | 73 #include "views/window/dialog_delegate.h" |
| 73 #include "views/window/non_client_view.h" | 74 #include "views/window/non_client_view.h" |
| 74 #include "views/window/window.h" | 75 #include "views/window/window.h" |
| 75 | 76 |
| 76 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
| 77 #include "app/win_util.h" | 78 #include "app/win_util.h" |
| 78 #include "chrome/browser/jumplist.h" | 79 #include "chrome/browser/jumplist.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 static const int kWindowBorderWidth = 5; | 118 static const int kWindowBorderWidth = 5; |
| 118 | 119 |
| 119 // If not -1, windows are shown with this state. | 120 // If not -1, windows are shown with this state. |
| 120 static int explicit_show_state = -1; | 121 static int explicit_show_state = -1; |
| 121 | 122 |
| 122 // How round the 'new tab' style bookmarks bar is. | 123 // How round the 'new tab' style bookmarks bar is. |
| 123 static const int kNewtabBarRoundness = 5; | 124 static const int kNewtabBarRoundness = 5; |
| 124 // ------------ | 125 // ------------ |
| 125 | 126 |
| 126 // Returned from BrowserView::GetClassName. | 127 // Returned from BrowserView::GetClassName. |
| 127 static const char kBrowserViewClassName[] = "browser/views/BrowserView"; | 128 const char BrowserView::kViewClassName[] = "browser/views/BrowserView"; |
| 128 | 129 |
| 129 /////////////////////////////////////////////////////////////////////////////// | 130 /////////////////////////////////////////////////////////////////////////////// |
| 130 // BookmarkExtensionBackground, private: | 131 // BookmarkExtensionBackground, private: |
| 131 // This object serves as the views::Background object which is used to layout | 132 // This object serves as the views::Background object which is used to layout |
| 132 // and paint the bookmark bar. | 133 // and paint the bookmark bar. |
| 133 class BookmarkExtensionBackground : public views::Background { | 134 class BookmarkExtensionBackground : public views::Background { |
| 134 public: | 135 public: |
| 135 explicit BookmarkExtensionBackground(BrowserView* browser_view, | 136 explicit BookmarkExtensionBackground(BrowserView* browser_view, |
| 136 DetachableToolbarView* host_view, | 137 DetachableToolbarView* host_view, |
| 137 Browser* browser); | 138 Browser* browser); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 find_bar_y_(0), | 406 find_bar_y_(0), |
| 406 contents_container_(NULL), | 407 contents_container_(NULL), |
| 407 devtools_container_(NULL), | 408 devtools_container_(NULL), |
| 408 contents_split_(NULL), | 409 contents_split_(NULL), |
| 409 initialized_(false), | 410 initialized_(false), |
| 410 ignore_layout_(false), | 411 ignore_layout_(false), |
| 411 #if defined(OS_WIN) | 412 #if defined(OS_WIN) |
| 412 hung_window_detector_(&hung_plugin_action_), | 413 hung_window_detector_(&hung_plugin_action_), |
| 413 ticker_(0), | 414 ticker_(0), |
| 414 #endif | 415 #endif |
| 415 extension_shelf_(NULL) { | 416 extension_shelf_(NULL), |
| 417 last_focused_view_storage_id_( |
| 418 views::ViewStorage::GetSharedInstance()->CreateStorageID()) { |
| 416 InitClass(); | 419 InitClass(); |
| 417 browser_->tabstrip_model()->AddObserver(this); | 420 browser_->tabstrip_model()->AddObserver(this); |
| 418 } | 421 } |
| 419 | 422 |
| 420 BrowserView::~BrowserView() { | 423 BrowserView::~BrowserView() { |
| 421 browser_->tabstrip_model()->RemoveObserver(this); | 424 browser_->tabstrip_model()->RemoveObserver(this); |
| 422 | 425 |
| 423 #if defined(OS_WIN) | 426 #if defined(OS_WIN) |
| 424 // Stop hung plugin monitoring. | 427 // Stop hung plugin monitoring. |
| 425 ticker_.Stop(); | 428 ticker_.Stop(); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 } | 652 } |
| 650 return otr_avatar_; | 653 return otr_avatar_; |
| 651 } | 654 } |
| 652 | 655 |
| 653 #if defined(OS_WIN) | 656 #if defined(OS_WIN) |
| 654 void BrowserView::PrepareToRunSystemMenu(HMENU menu) { | 657 void BrowserView::PrepareToRunSystemMenu(HMENU menu) { |
| 655 system_menu_->UpdateStates(); | 658 system_menu_->UpdateStates(); |
| 656 } | 659 } |
| 657 #endif | 660 #endif |
| 658 | 661 |
| 662 void BrowserView::TraverseNextAccessibleToolbar(bool forward) { |
| 663 // TODO(mohamed) This needs to be smart, that applies to all toolbars. |
| 664 // Currently it just traverses between bookmarks and toolbar. |
| 665 if (!forward && toolbar_->IsVisible() && toolbar_->IsEnabled()) { |
| 666 toolbar_->InitiateTraversal(last_focused_view_storage_id_); |
| 667 } else if (forward && bookmark_bar_view_->IsVisible() && |
| 668 bookmark_bar_view_->IsEnabled()) { |
| 669 bookmark_bar_view_->InitiateTraversal(last_focused_view_storage_id_); |
| 670 } |
| 671 } |
| 672 |
| 659 // static | 673 // static |
| 660 void BrowserView::RegisterBrowserViewPrefs(PrefService* prefs) { | 674 void BrowserView::RegisterBrowserViewPrefs(PrefService* prefs) { |
| 661 prefs->RegisterIntegerPref(prefs::kPluginMessageResponseTimeout, | 675 prefs->RegisterIntegerPref(prefs::kPluginMessageResponseTimeout, |
| 662 kDefaultPluginMessageResponseTimeout); | 676 kDefaultPluginMessageResponseTimeout); |
| 663 prefs->RegisterIntegerPref(prefs::kHungPluginDetectFrequency, | 677 prefs->RegisterIntegerPref(prefs::kHungPluginDetectFrequency, |
| 664 kDefaultHungPluginDetectFrequency); | 678 kDefaultHungPluginDetectFrequency); |
| 665 } | 679 } |
| 666 | 680 |
| 667 void BrowserView::AttachBrowserBubble(BrowserBubble* bubble) { | 681 void BrowserView::AttachBrowserBubble(BrowserBubble* bubble) { |
| 668 browser_bubbles_.insert(bubble); | 682 browser_bubbles_.insert(bubble); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 toolbar_->go_button()->ChangeMode( | 965 toolbar_->go_button()->ChangeMode( |
| 952 is_loading ? GoButton::MODE_STOP : GoButton::MODE_GO, force); | 966 is_loading ? GoButton::MODE_STOP : GoButton::MODE_GO, force); |
| 953 } | 967 } |
| 954 | 968 |
| 955 void BrowserView::UpdateToolbar(TabContents* contents, | 969 void BrowserView::UpdateToolbar(TabContents* contents, |
| 956 bool should_restore_state) { | 970 bool should_restore_state) { |
| 957 toolbar_->Update(contents, should_restore_state); | 971 toolbar_->Update(contents, should_restore_state); |
| 958 } | 972 } |
| 959 | 973 |
| 960 void BrowserView::FocusToolbar() { | 974 void BrowserView::FocusToolbar() { |
| 961 toolbar_->InitializeTraversal(); | 975 // Remove existing views in the storage, traversal should be restarted. |
| 976 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); |
| 977 if (view_storage->RetrieveView(last_focused_view_storage_id_)) |
| 978 view_storage->RemoveView(last_focused_view_storage_id_); |
| 979 |
| 980 // Store the last focused view into the storage, to handle existing traversal. |
| 981 view_storage->StoreView(last_focused_view_storage_id_, |
| 982 GetRootView()->GetFocusedView()); |
| 983 |
| 984 // Start the traversal within the main toolbar. |
| 985 toolbar_->InitiateTraversal(last_focused_view_storage_id_); |
| 962 } | 986 } |
| 963 | 987 |
| 964 void BrowserView::DestroyBrowser() { | 988 void BrowserView::DestroyBrowser() { |
| 965 // Explicitly delete the BookmarkBarView now. That way we don't have to | 989 // Explicitly delete the BookmarkBarView now. That way we don't have to |
| 966 // worry about the BookmarkBarView potentially outliving the Browser & | 990 // worry about the BookmarkBarView potentially outliving the Browser & |
| 967 // Profile. | 991 // Profile. |
| 968 bookmark_bar_view_.reset(); | 992 bookmark_bar_view_.reset(); |
| 969 browser_.reset(); | 993 browser_.reset(); |
| 970 } | 994 } |
| 971 | 995 |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1635 int widths[] = { tabstrip_size.width(), toolbar_size.width(), | 1659 int widths[] = { tabstrip_size.width(), toolbar_size.width(), |
| 1636 bookmark_bar_size.width(), contents_size.width() }; | 1660 bookmark_bar_size.width(), contents_size.width() }; |
| 1637 int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]); | 1661 int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]); |
| 1638 return gfx::Size(min_width, min_height); | 1662 return gfx::Size(min_width, min_height); |
| 1639 } | 1663 } |
| 1640 | 1664 |
| 1641 /////////////////////////////////////////////////////////////////////////////// | 1665 /////////////////////////////////////////////////////////////////////////////// |
| 1642 // BrowserView, views::View overrides: | 1666 // BrowserView, views::View overrides: |
| 1643 | 1667 |
| 1644 std::string BrowserView::GetClassName() const { | 1668 std::string BrowserView::GetClassName() const { |
| 1645 return kBrowserViewClassName; | 1669 return kViewClassName; |
| 1646 } | 1670 } |
| 1647 | 1671 |
| 1648 void BrowserView::Layout() { | 1672 void BrowserView::Layout() { |
| 1649 if (ignore_layout_) | 1673 if (ignore_layout_) |
| 1650 return; | 1674 return; |
| 1651 | 1675 |
| 1652 int top = LayoutTabStrip(); | 1676 int top = LayoutTabStrip(); |
| 1653 top = LayoutToolbar(top); | 1677 top = LayoutToolbar(top); |
| 1654 top = LayoutBookmarkAndInfoBars(top); | 1678 top = LayoutBookmarkAndInfoBars(top); |
| 1655 int bottom = LayoutExtensionAndDownloadShelves(); | 1679 int bottom = LayoutExtensionAndDownloadShelves(); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2067 } | 2091 } |
| 2068 bool changed = false; | 2092 bool changed = false; |
| 2069 if (new_height != current_height) { | 2093 if (new_height != current_height) { |
| 2070 changed = true; | 2094 changed = true; |
| 2071 } else if (new_view && *old_view) { | 2095 } else if (new_view && *old_view) { |
| 2072 // The view changed, but the new view wants the same size, give it the | 2096 // The view changed, but the new view wants the same size, give it the |
| 2073 // bounds of the last view and have it repaint. | 2097 // bounds of the last view and have it repaint. |
| 2074 new_view->SetBounds((*old_view)->bounds()); | 2098 new_view->SetBounds((*old_view)->bounds()); |
| 2075 new_view->SchedulePaint(); | 2099 new_view->SchedulePaint(); |
| 2076 } else if (new_view) { | 2100 } else if (new_view) { |
| 2077 DCHECK(new_height == 0); | 2101 DCHECK_EQ(0, new_height); |
| 2078 // The heights are the same, but the old view is null. This only happens | 2102 // The heights are the same, but the old view is null. This only happens |
| 2079 // when the height is zero. Zero out the bounds. | 2103 // when the height is zero. Zero out the bounds. |
| 2080 new_view->SetBounds(0, 0, 0, 0); | 2104 new_view->SetBounds(0, 0, 0, 0); |
| 2081 } | 2105 } |
| 2082 *old_view = new_view; | 2106 *old_view = new_view; |
| 2083 return changed; | 2107 return changed; |
| 2084 } | 2108 } |
| 2085 | 2109 |
| 2086 void BrowserView::LoadAccelerators() { | 2110 void BrowserView::LoadAccelerators() { |
| 2087 #if defined(OS_WIN) | 2111 #if defined(OS_WIN) |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2280 | 2304 |
| 2281 // static | 2305 // static |
| 2282 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { | 2306 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { |
| 2283 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); | 2307 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); |
| 2284 } | 2308 } |
| 2285 | 2309 |
| 2286 // static | 2310 // static |
| 2287 void BrowserList::AllBrowsersClosed() { | 2311 void BrowserList::AllBrowsersClosed() { |
| 2288 views::Window::CloseAllSecondaryWindows(); | 2312 views::Window::CloseAllSecondaryWindows(); |
| 2289 } | 2313 } |
| OLD | NEW |