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

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

Issue 1152613003: Implement sidebar support for extension action popups (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/profiles/avatar_menu.h" 27 #include "chrome/browser/profiles/avatar_menu.h"
28 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 29 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
30 #include "chrome/browser/profiles/profile_info_cache.h" 30 #include "chrome/browser/profiles/profile_info_cache.h"
31 #include "chrome/browser/profiles/profile_manager.h" 31 #include "chrome/browser/profiles/profile_manager.h"
32 #include "chrome/browser/profiles/profile_window.h" 32 #include "chrome/browser/profiles/profile_window.h"
33 #include "chrome/browser/profiles/profiles_state.h" 33 #include "chrome/browser/profiles/profiles_state.h"
34 #include "chrome/browser/search/search.h" 34 #include "chrome/browser/search/search.h"
35 #include "chrome/browser/sessions/tab_restore_service.h" 35 #include "chrome/browser/sessions/tab_restore_service.h"
36 #include "chrome/browser/sessions/tab_restore_service_factory.h" 36 #include "chrome/browser/sessions/tab_restore_service_factory.h"
37 #include "chrome/browser/sidebar/sidebar_container.h"
38 #include "chrome/browser/sidebar/sidebar_manager.h"
37 #include "chrome/browser/signin/signin_header_helper.h" 39 #include "chrome/browser/signin/signin_header_helper.h"
38 #include "chrome/browser/themes/theme_properties.h" 40 #include "chrome/browser/themes/theme_properties.h"
39 #include "chrome/browser/themes/theme_service_factory.h" 41 #include "chrome/browser/themes/theme_service_factory.h"
40 #include "chrome/browser/translate/chrome_translate_client.h" 42 #include "chrome/browser/translate/chrome_translate_client.h"
41 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" 43 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h"
42 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h" 44 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
43 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" 45 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h"
44 #include "chrome/browser/ui/browser.h" 46 #include "chrome/browser/ui/browser.h"
45 #include "chrome/browser/ui/browser_command_controller.h" 47 #include "chrome/browser/ui/browser_command_controller.h"
46 #include "chrome/browser/ui/browser_commands.h" 48 #include "chrome/browser/ui/browser_commands.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 #include "ui/base/resource/resource_bundle.h" 126 #include "ui/base/resource/resource_bundle.h"
125 #include "ui/base/theme_provider.h" 127 #include "ui/base/theme_provider.h"
126 #include "ui/content_accelerators/accelerator_util.h" 128 #include "ui/content_accelerators/accelerator_util.h"
127 #include "ui/events/event_utils.h" 129 #include "ui/events/event_utils.h"
128 #include "ui/gfx/canvas.h" 130 #include "ui/gfx/canvas.h"
129 #include "ui/gfx/color_utils.h" 131 #include "ui/gfx/color_utils.h"
130 #include "ui/gfx/geometry/rect_conversions.h" 132 #include "ui/gfx/geometry/rect_conversions.h"
131 #include "ui/gfx/screen.h" 133 #include "ui/gfx/screen.h"
132 #include "ui/strings/grit/ui_strings.h" 134 #include "ui/strings/grit/ui_strings.h"
133 #include "ui/views/controls/button/menu_button.h" 135 #include "ui/views/controls/button/menu_button.h"
136 #include "ui/views/controls/single_split_view.h"
137 #include "ui/views/controls/single_split_view_listener.h"
134 #include "ui/views/controls/textfield/textfield.h" 138 #include "ui/views/controls/textfield/textfield.h"
135 #include "ui/views/controls/webview/webview.h" 139 #include "ui/views/controls/webview/webview.h"
136 #include "ui/views/focus/external_focus_tracker.h" 140 #include "ui/views/focus/external_focus_tracker.h"
137 #include "ui/views/focus/view_storage.h" 141 #include "ui/views/focus/view_storage.h"
142 #include "ui/views/layout/box_layout.h"
138 #include "ui/views/layout/grid_layout.h" 143 #include "ui/views/layout/grid_layout.h"
139 #include "ui/views/widget/native_widget.h" 144 #include "ui/views/widget/native_widget.h"
140 #include "ui/views/widget/root_view.h" 145 #include "ui/views/widget/root_view.h"
141 #include "ui/views/widget/widget.h" 146 #include "ui/views/widget/widget.h"
142 #include "ui/views/window/dialog_delegate.h" 147 #include "ui/views/window/dialog_delegate.h"
143 148
144 #if defined(USE_AURA) 149 #if defined(USE_AURA)
145 #include "ui/aura/client/window_tree_client.h" 150 #include "ui/aura/client/window_tree_client.h"
146 #include "ui/aura/window.h" 151 #include "ui/aura/window.h"
147 #include "ui/aura/window_tree_host.h" 152 #include "ui/aura/window_tree_host.h"
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 contents_web_view_(nullptr), 461 contents_web_view_(nullptr),
457 contents_container_(nullptr), 462 contents_container_(nullptr),
458 initialized_(false), 463 initialized_(false),
459 in_process_fullscreen_(false), 464 in_process_fullscreen_(false),
460 #if defined(OS_WIN) 465 #if defined(OS_WIN)
461 hung_window_detector_(&hung_plugin_action_), 466 hung_window_detector_(&hung_plugin_action_),
462 ticker_(0), 467 ticker_(0),
463 #endif 468 #endif
464 force_location_bar_focus_(false), 469 force_location_bar_focus_(false),
465 activate_modal_dialog_factory_(this) { 470 activate_modal_dialog_factory_(this) {
471 registrar_.Add(
472 this, chrome::NOTIFICATION_SIDEBAR_CHANGED,
473 content::Source<SidebarManager>(SidebarManager::GetInstance()));
466 } 474 }
467 475
468 BrowserView::~BrowserView() { 476 BrowserView::~BrowserView() {
469 // All the tabs should have been destroyed already. If we were closed by the 477 // All the tabs should have been destroyed already. If we were closed by the
470 // OS with some tabs than the NativeBrowserFrame should have destroyed them. 478 // OS with some tabs than the NativeBrowserFrame should have destroyed them.
471 DCHECK_EQ(0, browser_->tab_strip_model()->count()); 479 DCHECK_EQ(0, browser_->tab_strip_model()->count());
472 480
473 // Immersive mode may need to reparent views before they are removed/deleted. 481 // Immersive mode may need to reparent views before they are removed/deleted.
474 immersive_mode_controller_.reset(); 482 immersive_mode_controller_.reset();
475 483
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 // static 541 // static
534 BrowserView* BrowserView::GetBrowserViewForBrowser(const Browser* browser) { 542 BrowserView* BrowserView::GetBrowserViewForBrowser(const Browser* browser) {
535 return static_cast<BrowserView*>(browser->window()); 543 return static_cast<BrowserView*>(browser->window());
536 } 544 }
537 545
538 void BrowserView::InitStatusBubble() { 546 void BrowserView::InitStatusBubble() {
539 status_bubble_.reset(new StatusBubbleViews(contents_web_view_)); 547 status_bubble_.reset(new StatusBubbleViews(contents_web_view_));
540 contents_web_view_->SetStatusBubble(status_bubble_.get()); 548 contents_web_view_->SetStatusBubble(status_bubble_.get());
541 } 549 }
542 550
551 bool BrowserView::SplitHandleMoved(views::SingleSplitView* sender) {
552 for (int i = 0; i < sender->child_count(); ++i)
553 sender->child_at(i)->InvalidateLayout();
554 SchedulePaint();
555 Layout();
556 return false;
557 }
558
543 gfx::Rect BrowserView::GetToolbarBounds() const { 559 gfx::Rect BrowserView::GetToolbarBounds() const {
544 gfx::Rect toolbar_bounds(toolbar_->bounds()); 560 gfx::Rect toolbar_bounds(toolbar_->bounds());
545 if (toolbar_bounds.IsEmpty()) 561 if (toolbar_bounds.IsEmpty())
546 return toolbar_bounds; 562 return toolbar_bounds;
547 // The apparent toolbar edges are outside the "real" toolbar edges. 563 // The apparent toolbar edges are outside the "real" toolbar edges.
548 toolbar_bounds.Inset(-views::NonClientFrameView::kClientEdgeThickness, 0); 564 toolbar_bounds.Inset(-views::NonClientFrameView::kClientEdgeThickness, 0);
549 return toolbar_bounds; 565 return toolbar_bounds;
550 } 566 }
551 567
552 gfx::Rect BrowserView::GetFindBarBoundingBox() const { 568 gfx::Rect BrowserView::GetFindBarBoundingBox() const {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 } 663 }
648 664
649 WebContents* BrowserView::GetActiveWebContents() const { 665 WebContents* BrowserView::GetActiveWebContents() const {
650 return browser_->tab_strip_model()->GetActiveWebContents(); 666 return browser_->tab_strip_model()->GetActiveWebContents();
651 } 667 }
652 668
653 gfx::ImageSkia BrowserView::GetOTRAvatarIcon() const { 669 gfx::ImageSkia BrowserView::GetOTRAvatarIcon() const {
654 return *GetThemeProvider()->GetImageSkiaNamed(IDR_OTR_ICON); 670 return *GetThemeProvider()->GetImageSkiaNamed(IDR_OTR_ICON);
655 } 671 }
656 672
673 void BrowserView::Observe(int type,
674 const content::NotificationSource& source,
675 const content::NotificationDetails& details) {
676 content::WebContents* target =
677 content::Details<SidebarContainer>(details)->web_contents();
678 switch (type) {
679 case chrome::NOTIFICATION_SIDEBAR_CHANGED:
680 if (GetActiveWebContents() == target)
681 UpdateSidebarForContents(target);
682 break;
683 default:
684 NOTREACHED(); // we don't ask for anything else!
685 break;
686 }
687 }
688
657 /////////////////////////////////////////////////////////////////////////////// 689 ///////////////////////////////////////////////////////////////////////////////
658 // BrowserView, BrowserWindow implementation: 690 // BrowserView, BrowserWindow implementation:
659 691
660 void BrowserView::Show() { 692 void BrowserView::Show() {
661 #if !defined(OS_WIN) 693 #if !defined(OS_WIN)
662 // The Browser associated with this browser window must become the active 694 // The Browser associated with this browser window must become the active
663 // browser at the time |Show()| is called. This is the natural behavior under 695 // browser at the time |Show()| is called. This is the natural behavior under
664 // Windows and Ash, but other platforms will not trigger 696 // Windows and Ash, but other platforms will not trigger
665 // OnWidgetActivationChanged() until we return to the runloop. Therefore any 697 // OnWidgetActivationChanged() until we return to the runloop. Therefore any
666 // calls to Browser::GetLastActive() will return the wrong result if we do not 698 // calls to Browser::GetLastActive() will return the wrong result if we do not
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 PermissionBubbleManager::FromWebContents(new_contents)->SetView( 908 PermissionBubbleManager::FromWebContents(new_contents)->SetView(
877 permission_bubble_.get()); 909 permission_bubble_.get());
878 } 910 }
879 911
880 UpdateUIForContents(new_contents); 912 UpdateUIForContents(new_contents);
881 913
882 // Layout for DevTools _before_ setting the both main and devtools WebContents 914 // Layout for DevTools _before_ setting the both main and devtools WebContents
883 // to avoid toggling the size of any of them. 915 // to avoid toggling the size of any of them.
884 UpdateDevToolsForContents(new_contents, !change_tab_contents); 916 UpdateDevToolsForContents(new_contents, !change_tab_contents);
885 917
918 UpdateSidebarForContents(new_contents);
886 if (change_tab_contents) { 919 if (change_tab_contents) {
887 web_contents_close_handler_->ActiveTabChanged(); 920 web_contents_close_handler_->ActiveTabChanged();
888 contents_web_view_->SetWebContents(new_contents); 921 contents_web_view_->SetWebContents(new_contents);
889 // The second layout update should be no-op. It will just set the 922 // The second layout update should be no-op. It will just set the
890 // DevTools WebContents. 923 // DevTools WebContents.
891 UpdateDevToolsForContents(new_contents, true); 924 UpdateDevToolsForContents(new_contents, true);
892 } 925 }
893 926
894 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && 927 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() &&
895 GetWidget()->IsVisible()) { 928 GetWidget()->IsVisible()) {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 anchor_view = toolbar_->app_menu(); 1337 anchor_view = toolbar_->app_menu();
1305 else 1338 else
1306 anchor_view = toolbar_->location_bar(); 1339 anchor_view = toolbar_->location_bar();
1307 1340
1308 OneClickSigninBubbleView::ShowBubble(type, email, error_message, 1341 OneClickSigninBubbleView::ShowBubble(type, email, error_message,
1309 delegate.Pass(), anchor_view, 1342 delegate.Pass(), anchor_view,
1310 start_sync_callback); 1343 start_sync_callback);
1311 } 1344 }
1312 #endif 1345 #endif
1313 1346
1347 int BrowserView::GetSidebarWidth() const {
1348 if (!sidebar_container_ || !sidebar_container_->visible())
1349 return 0;
1350 return sidebar_split_->divider_offset();
1351 }
1352
1314 void BrowserView::SetDownloadShelfVisible(bool visible) { 1353 void BrowserView::SetDownloadShelfVisible(bool visible) {
1315 // This can be called from the superclass destructor, when it destroys our 1354 // This can be called from the superclass destructor, when it destroys our
1316 // child views. At that point, browser_ is already gone. 1355 // child views. At that point, browser_ is already gone.
1317 if (!browser_) 1356 if (!browser_)
1318 return; 1357 return;
1319 1358
1320 if (visible && IsDownloadShelfVisible() != visible) { 1359 if (visible && IsDownloadShelfVisible() != visible) {
1321 // Invoke GetDownloadShelf to force the shelf to be created. 1360 // Invoke GetDownloadShelf to force the shelf to be created.
1322 GetDownloadShelf(); 1361 GetDownloadShelf();
1323 } 1362 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 // browser_->GetActiveWebContents() will return null or something else. 1596 // browser_->GetActiveWebContents() will return null or something else.
1558 if (index == browser_->tab_strip_model()->active_index()) { 1597 if (index == browser_->tab_strip_model()->active_index()) {
1559 // We need to reset the current tab contents to null before it gets 1598 // We need to reset the current tab contents to null before it gets
1560 // freed. This is because the focus manager performs some operations 1599 // freed. This is because the focus manager performs some operations
1561 // on the selected WebContents when it is removed. 1600 // on the selected WebContents when it is removed.
1562 web_contents_close_handler_->ActiveTabChanged(); 1601 web_contents_close_handler_->ActiveTabChanged();
1563 contents_web_view_->SetWebContents(nullptr); 1602 contents_web_view_->SetWebContents(nullptr);
1564 infobar_container_->ChangeInfoBarManager(nullptr); 1603 infobar_container_->ChangeInfoBarManager(nullptr);
1565 UpdateDevToolsForContents(nullptr, true); 1604 UpdateDevToolsForContents(nullptr, true);
1566 } 1605 }
1606 UpdateSidebarForContents(NULL);
1567 } 1607 }
1568 1608
1569 void BrowserView::TabDeactivated(WebContents* contents) { 1609 void BrowserView::TabDeactivated(WebContents* contents) {
1570 if (PermissionBubbleManager::FromWebContents(contents)) 1610 if (PermissionBubbleManager::FromWebContents(contents))
1571 PermissionBubbleManager::FromWebContents(contents)->SetView(nullptr); 1611 PermissionBubbleManager::FromWebContents(contents)->SetView(nullptr);
1572 1612
1573 // We do not store the focus when closing the tab to work-around bug 4633. 1613 // We do not store the focus when closing the tab to work-around bug 4633.
1574 // Some reports seem to show that the focus manager and/or focused view can 1614 // Some reports seem to show that the focus manager and/or focused view can
1575 // be garbage at that point, it is not clear why. 1615 // be garbage at that point, it is not clear why.
1576 if (!contents->IsBeingDestroyed()) 1616 if (!contents->IsBeingDestroyed())
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 devtools_web_view_->SetVisible(false); 2075 devtools_web_view_->SetVisible(false);
2036 2076
2037 contents_container_ = new views::View(); 2077 contents_container_ = new views::View();
2038 contents_container_->set_background(views::Background::CreateSolidBackground( 2078 contents_container_->set_background(views::Background::CreateSolidBackground(
2039 ThemeProperties::GetDefaultColor( 2079 ThemeProperties::GetDefaultColor(
2040 ThemeProperties::COLOR_CONTROL_BACKGROUND))); 2080 ThemeProperties::COLOR_CONTROL_BACKGROUND)));
2041 contents_container_->AddChildView(devtools_web_view_); 2081 contents_container_->AddChildView(devtools_web_view_);
2042 contents_container_->AddChildView(contents_web_view_); 2082 contents_container_->AddChildView(contents_web_view_);
2043 contents_container_->SetLayoutManager(new ContentsLayoutManager( 2083 contents_container_->SetLayoutManager(new ContentsLayoutManager(
2044 devtools_web_view_, contents_web_view_)); 2084 devtools_web_view_, contents_web_view_));
2045 AddChildView(contents_container_); 2085
2046 set_contents_view(contents_container_); 2086 sidebar_web_view_ = new views::WebView(browser_->profile());
2087 sidebar_web_view_->set_id(VIEW_ID_SIDE_BAR_VIEW);
2088 sidebar_web_view_->SetVisible(false);
2089
2090 sidebar_container_ = new views::View();
2091 sidebar_container_->AddChildView(sidebar_web_view_);
2092 sidebar_container_->set_id(VIEW_ID_SIDE_BAR_CONTAINER);
2093 sidebar_container_->SetVisible(false);
2094
2095 sidebar_split_ = new views::SingleSplitView(
2096 contents_container_, sidebar_container_,
2097 views::SingleSplitView::HORIZONTAL_SPLIT, this);
2098
2099 sidebar_split_->set_id(VIEW_ID_SIDE_BAR_SPLIT);
2100 sidebar_split_->set_background(views::Background::CreateSolidBackground(
2101 GetWidget()->GetThemeProvider()->GetColor(
2102 ThemeProperties::COLOR_TOOLBAR)));
2103 sidebar_split_->set_resize_leading_on_bounds_change(false);
2104 AddChildView(sidebar_split_);
2105 set_contents_view(sidebar_split_);
2047 2106
2048 // Top container holds tab strip and toolbar and lives at the front of the 2107 // Top container holds tab strip and toolbar and lives at the front of the
2049 // view hierarchy. 2108 // view hierarchy.
2050 top_container_ = new TopContainerView(this); 2109 top_container_ = new TopContainerView(this);
2051 AddChildView(top_container_); 2110 AddChildView(top_container_);
2052 2111
2053 // TabStrip takes ownership of the controller. 2112 // TabStrip takes ownership of the controller.
2054 BrowserTabStripController* tabstrip_controller = 2113 BrowserTabStripController* tabstrip_controller =
2055 new BrowserTabStripController(browser_.get(), 2114 new BrowserTabStripController(browser_.get(),
2056 browser_->tab_strip_model()); 2115 browser_->tab_strip_model());
2057 tabstrip_ = new TabStrip(tabstrip_controller); 2116 tabstrip_ = new TabStrip(tabstrip_controller);
2058 top_container_->AddChildView(tabstrip_); 2117 top_container_->AddChildView(tabstrip_);
2059 tabstrip_controller->InitFromModel(tabstrip_); 2118 tabstrip_controller->InitFromModel(tabstrip_);
2060 2119
2061 toolbar_ = new ToolbarView(browser_.get()); 2120 toolbar_ = new ToolbarView(browser_.get());
2062 top_container_->AddChildView(toolbar_); 2121 top_container_->AddChildView(toolbar_);
2063 toolbar_->Init(); 2122 toolbar_->Init();
2064 2123
2065 InitStatusBubble(); 2124 InitStatusBubble();
2066 2125
2067 // Create do-nothing view for the sake of controlling the z-order of the find 2126 // Create do-nothing view for the sake of controlling the z-order of the find
2068 // bar widget. 2127 // bar widget.
2069 find_bar_host_view_ = new View(); 2128 find_bar_host_view_ = new View();
2070 AddChildView(find_bar_host_view_); 2129 AddChildView(find_bar_host_view_);
2071 2130
2072 immersive_mode_controller_->Init(this); 2131 immersive_mode_controller_->Init(this);
2073 2132
2074 BrowserViewLayout* browser_view_layout = new BrowserViewLayout; 2133 BrowserViewLayout* browser_view_layout = new BrowserViewLayout;
2075 browser_view_layout->Init(new BrowserViewLayoutDelegateImpl(this), 2134 browser_view_layout->Init(
2076 browser(), 2135 new BrowserViewLayoutDelegateImpl(this), browser(), this, top_container_,
2077 this, 2136 tabstrip_, toolbar_, infobar_container_, sidebar_split_,
2078 top_container_, 2137 GetContentsLayoutManager(), immersive_mode_controller_.get());
2079 tabstrip_,
2080 toolbar_,
2081 infobar_container_,
2082 contents_container_,
2083 GetContentsLayoutManager(),
2084 immersive_mode_controller_.get());
2085 SetLayoutManager(browser_view_layout); 2138 SetLayoutManager(browser_view_layout);
2086 2139
2087 #if defined(OS_WIN) 2140 #if defined(OS_WIN)
2088 // Create a custom JumpList and add it to an observer of TabRestoreService 2141 // Create a custom JumpList and add it to an observer of TabRestoreService
2089 // so we can update the custom JumpList when a tab is added or removed. 2142 // so we can update the custom JumpList when a tab is added or removed.
2090 if (JumpList::Enabled()) { 2143 if (JumpList::Enabled()) {
2091 load_complete_listener_.reset(new LoadCompleteListener(this)); 2144 load_complete_listener_.reset(new LoadCompleteListener(this));
2092 } 2145 }
2093 #endif 2146 #endif
2094 2147
2095 GetLocationBar()->GetOmniboxView()->model()->popup_model()->AddObserver(this); 2148 GetLocationBar()->GetOmniboxView()->model()->popup_model()->AddObserver(this);
2096 } 2149 }
2097 2150
2151 void BrowserView::UpdateSidebarForContents(content::WebContents* new_contents) {
2152 if (!sidebar_container_)
2153 return; // Happens when sidebar is not allowed.
2154 if (!SidebarManager::GetInstance())
2155 return; // Happens only in tests.s
2156
2157 WebContents* sidebar_contents = NULL;
2158 if (new_contents) {
2159 SidebarContainer* client_host =
2160 SidebarManager::GetInstance()->GetActiveSidebarContainerFor(
2161 new_contents);
2162 if (client_host)
2163 sidebar_contents = client_host->host_contents();
2164 }
2165
2166 bool visible = NULL != sidebar_contents;
2167
2168 bool should_show = visible && !sidebar_container_->visible();
2169 bool should_hide = !visible && sidebar_container_->visible();
2170
2171 // Update sidebar content.
2172 WebContents* old_contents =
2173 static_cast<WebContents*>(sidebar_web_view_->web_contents());
2174
2175 sidebar_web_view_->SetWebContents(sidebar_contents);
2176
2177 SidebarManager::GetInstance()->NotifyStateChanges(old_contents,
2178 sidebar_contents);
2179
2180 // Update sidebar UI width.
2181 if (should_show) {
2182 // Restore split offset.
2183 int sidebar_width = g_browser_process->local_state()->GetInteger(
2184 prefs::kExtensionSidebarWidth);
2185 if (sidebar_width < 0) {
2186 // By default sidebar width is 1/7th of the current page content width.
2187 sidebar_width = sidebar_split_->width() / 7;
2188 }
2189 int min_sidebar_width = sidebar_split_->GetMinimumSize().width();
2190 // Not allowed to be wider than 50% of the split-view's frame
2191 sidebar_width = std::min(sidebar_split_->width() / 2 - min_sidebar_width,
2192 std::max(min_sidebar_width, sidebar_width));
2193 sidebar_split_->set_divider_offset(sidebar_split_->width() - sidebar_width);
2194
2195 sidebar_container_->SetVisible(true);
2196 sidebar_web_view_->SetVisible(true);
2197 sidebar_split_->InvalidateLayout();
2198 Layout();
2199
2200 } else if (should_hide) {
2201 // Store split offset when hiding sidebar only.
2202 g_browser_process->local_state()->SetInteger(
2203 prefs::kExtensionSidebarWidth,
2204 sidebar_split_->width() - sidebar_split_->divider_offset());
2205
2206 sidebar_container_->SetVisible(false);
2207 sidebar_split_->InvalidateLayout();
2208 Layout();
2209 }
2210 }
2211
2098 void BrowserView::LoadingAnimationCallback() { 2212 void BrowserView::LoadingAnimationCallback() {
2099 base::TimeTicks now = base::TimeTicks::Now(); 2213 base::TimeTicks now = base::TimeTicks::Now();
2100 if (!last_animation_time_.is_null()) { 2214 if (!last_animation_time_.is_null()) {
2101 UMA_HISTOGRAM_TIMES( 2215 UMA_HISTOGRAM_TIMES(
2102 "Tabs.LoadingAnimationTime", 2216 "Tabs.LoadingAnimationTime",
2103 now - last_animation_time_); 2217 now - last_animation_time_);
2104 } 2218 }
2105 last_animation_time_ = now; 2219 last_animation_time_ = now;
2106 if (browser_->is_type_tabbed()) { 2220 if (browser_->is_type_tabbed()) {
2107 // Loading animations are shown in the tab for tabbed windows. We check the 2221 // Loading animations are shown in the tab for tabbed windows. We check the
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
2615 return immersive_mode_controller()->IsEnabled(); 2729 return immersive_mode_controller()->IsEnabled();
2616 } 2730 }
2617 2731
2618 views::Widget* BrowserView::GetBubbleAssociatedWidget() { 2732 views::Widget* BrowserView::GetBubbleAssociatedWidget() {
2619 return GetWidget(); 2733 return GetWidget();
2620 } 2734 }
2621 2735
2622 gfx::Rect BrowserView::GetTopContainerBoundsInScreen() { 2736 gfx::Rect BrowserView::GetTopContainerBoundsInScreen() {
2623 return top_container_->GetBoundsInScreen(); 2737 return top_container_->GetBoundsInScreen();
2624 } 2738 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698