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

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

Issue 11364196: Remove TabContents from TabStripModelObserver::ActiveTabChanged. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month 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
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 frame_->UpdateWindowIcon(); 688 frame_->UpdateWindowIcon();
689 } 689 }
690 690
691 void BrowserView::BookmarkBarStateChanged( 691 void BrowserView::BookmarkBarStateChanged(
692 BookmarkBar::AnimateChangeType change_type) { 692 BookmarkBar::AnimateChangeType change_type) {
693 if (bookmark_bar_view_.get()) { 693 if (bookmark_bar_view_.get()) {
694 bookmark_bar_view_->SetBookmarkBarState( 694 bookmark_bar_view_->SetBookmarkBarState(
695 browser_->bookmark_bar_state(), change_type, 695 browser_->bookmark_bar_state(), change_type,
696 browser_->search_model()->mode()); 696 browser_->search_model()->mode());
697 } 697 }
698 if (MaybeShowBookmarkBar(GetActiveTabContents())) 698 if (MaybeShowBookmarkBar(GetActiveWebContents()))
699 Layout(); 699 Layout();
700 } 700 }
701 701
702 void BrowserView::UpdateDevTools() { 702 void BrowserView::UpdateDevTools() {
703 UpdateDevToolsForContents(GetActiveTabContents()); 703 UpdateDevToolsForContents(GetActiveWebContents());
704 Layout(); 704 Layout();
705 } 705 }
706 706
707 707
708 void BrowserView::UpdateLoadingAnimations(bool should_animate) { 708 void BrowserView::UpdateLoadingAnimations(bool should_animate) {
709 if (should_animate) { 709 if (should_animate) {
710 if (!loading_animation_timer_.IsRunning()) { 710 if (!loading_animation_timer_.IsRunning()) {
711 // Loads are happening, and the timer isn't running, so start it. 711 // Loads are happening, and the timer isn't running, so start it.
712 last_animation_time_ = base::TimeTicks::Now(); 712 last_animation_time_ = base::TimeTicks::Now();
713 loading_animation_timer_.Start(FROM_HERE, 713 loading_animation_timer_.Start(FROM_HERE,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 // early-return in this case because we need to layout again so the infobar 848 // early-return in this case because we need to layout again so the infobar
849 // container's bounds are set correctly. 849 // container's bounds are set correctly.
850 static CallState call_state = NORMAL; 850 static CallState call_state = NORMAL;
851 851
852 // A reentrant call can (and should) use the fast resize path unless both it 852 // A reentrant call can (and should) use the fast resize path unless both it
853 // and the normal call are both non-animating. 853 // and the normal call are both non-animating.
854 bool use_fast_resize = 854 bool use_fast_resize =
855 is_animating || (call_state == REENTRANT_FORCE_FAST_RESIZE); 855 is_animating || (call_state == REENTRANT_FORCE_FAST_RESIZE);
856 if (use_fast_resize) 856 if (use_fast_resize)
857 contents_container_->SetFastResize(true); 857 contents_container_->SetFastResize(true);
858 UpdateUIForContents(GetActiveTabContents()); 858 UpdateUIForContents(GetActiveWebContents());
859 if (use_fast_resize) 859 if (use_fast_resize)
860 contents_container_->SetFastResize(false); 860 contents_container_->SetFastResize(false);
861 861
862 // Inform the InfoBarContainer that the distance to the location icon may have 862 // Inform the InfoBarContainer that the distance to the location icon may have
863 // changed. We have to do this after the block above so that the toolbars are 863 // changed. We have to do this after the block above so that the toolbars are
864 // laid out correctly for calculating the maximum arrow height below. 864 // laid out correctly for calculating the maximum arrow height below.
865 { 865 {
866 int top_arrow_height = 0; 866 int top_arrow_height = 0;
867 // Hide the arrows on the Instant Extended NTP. 867 // Hide the arrows on the Instant Extended NTP.
868 if (!chrome::search::IsInstantExtendedAPIEnabled(browser()->profile()) || 868 if (!chrome::search::IsInstantExtendedAPIEnabled(browser()->profile()) ||
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 } 1416 }
1417 1417
1418 void BrowserView::TabDeactivated(WebContents* contents) { 1418 void BrowserView::TabDeactivated(WebContents* contents) {
1419 // We do not store the focus when closing the tab to work-around bug 4633. 1419 // We do not store the focus when closing the tab to work-around bug 4633.
1420 // Some reports seem to show that the focus manager and/or focused view can 1420 // Some reports seem to show that the focus manager and/or focused view can
1421 // be garbage at that point, it is not clear why. 1421 // be garbage at that point, it is not clear why.
1422 if (!contents->IsBeingDestroyed()) 1422 if (!contents->IsBeingDestroyed())
1423 contents->GetView()->StoreFocus(); 1423 contents->GetView()->StoreFocus();
1424 } 1424 }
1425 1425
1426 void BrowserView::ActiveTabChanged(TabContents* old_contents, 1426 void BrowserView::ActiveTabChanged(content::WebContents* old_contents,
1427 TabContents* new_contents, 1427 content::WebContents* new_contents,
1428 int index, 1428 int index,
1429 bool user_gesture) { 1429 bool user_gesture) {
1430 DCHECK(new_contents); 1430 DCHECK(new_contents);
1431 1431
1432 // See if the Instant preview is being activated (committed). 1432 // See if the Instant preview is being activated (committed).
1433 if (contents_->preview_web_contents() == new_contents->web_contents()) { 1433 if (contents_->preview_web_contents() == new_contents) {
1434 contents_->MakePreviewContentsActiveContents(); 1434 contents_->MakePreviewContentsActiveContents();
1435 views::WebView* old_container = contents_container_; 1435 views::WebView* old_container = contents_container_;
1436 contents_container_ = preview_controller_->release_preview_container(); 1436 contents_container_ = preview_controller_->release_preview_container();
1437 old_container->SetWebContents(NULL); 1437 old_container->SetWebContents(NULL);
1438 delete old_container; 1438 delete old_container;
1439 } 1439 }
1440 1440
1441 // If |contents_container_| already has the correct WebContents, we can save 1441 // If |contents_container_| already has the correct WebContents, we can save
1442 // some work. This also prevents extra events from being reported by the 1442 // some work. This also prevents extra events from being reported by the
1443 // Visibility API under Windows, as ChangeWebContents will briefly hide 1443 // Visibility API under Windows, as ChangeWebContents will briefly hide
1444 // the WebContents window. 1444 // the WebContents window.
1445 bool change_tab_contents = 1445 bool change_tab_contents =
1446 contents_container_->web_contents() != new_contents->web_contents(); 1446 contents_container_->web_contents() != new_contents;
1447 1447
1448 // Update various elements that are interested in knowing the current 1448 // Update various elements that are interested in knowing the current
1449 // WebContents. 1449 // WebContents.
1450 1450
1451 // When we toggle the NTP floating bookmarks bar and/or the info bar, 1451 // When we toggle the NTP floating bookmarks bar and/or the info bar,
1452 // we don't want any WebContents to be attached, so that we 1452 // we don't want any WebContents to be attached, so that we
1453 // avoid an unnecessary resize and re-layout of a WebContents. 1453 // avoid an unnecessary resize and re-layout of a WebContents.
1454 if (change_tab_contents) 1454 if (change_tab_contents)
1455 contents_container_->SetWebContents(NULL); 1455 contents_container_->SetWebContents(NULL);
1456 InfoBarTabHelper* new_infobar_tab_helper = 1456 InfoBarTabHelper* new_infobar_tab_helper =
1457 InfoBarTabHelper::FromWebContents(new_contents->web_contents()); 1457 InfoBarTabHelper::FromWebContents(new_contents);
1458 infobar_container_->ChangeTabContents(new_infobar_tab_helper); 1458 infobar_container_->ChangeTabContents(new_infobar_tab_helper);
1459 if (bookmark_bar_view_.get()) { 1459 if (bookmark_bar_view_.get()) {
1460 bookmark_bar_view_->SetBookmarkBarState( 1460 bookmark_bar_view_->SetBookmarkBarState(
1461 browser_->bookmark_bar_state(), 1461 browser_->bookmark_bar_state(),
1462 BookmarkBar::DONT_ANIMATE_STATE_CHANGE, 1462 BookmarkBar::DONT_ANIMATE_STATE_CHANGE,
1463 browser_->search_model()->mode()); 1463 browser_->search_model()->mode());
1464 } 1464 }
1465 UpdateUIForContents(new_contents); 1465 UpdateUIForContents(new_contents);
1466 1466
1467 // Layout for DevTools _before_ setting the main WebContents to avoid 1467 // Layout for DevTools _before_ setting the main WebContents to avoid
1468 // toggling the size of the main WebContents. 1468 // toggling the size of the main WebContents.
1469 UpdateDevToolsForContents(new_contents); 1469 UpdateDevToolsForContents(new_contents);
1470 1470
1471 if (change_tab_contents) { 1471 if (change_tab_contents) {
1472 contents_container_->SetWebContents(new_contents->web_contents()); 1472 contents_container_->SetWebContents(new_contents);
1473 #if defined(USE_AURA) 1473 #if defined(USE_AURA)
1474 // Put the Instant preview back on top in case it is showing custom new tab 1474 // Put the Instant preview back on top in case it is showing custom new tab
1475 // page content. 1475 // page content.
1476 if (contents_->preview_web_contents()) { 1476 if (contents_->preview_web_contents()) {
1477 ui::Layer* preview_layer = 1477 ui::Layer* preview_layer =
1478 contents_->preview_web_contents()->GetNativeView()->layer(); 1478 contents_->preview_web_contents()->GetNativeView()->layer();
1479 preview_layer->parent()->StackAtTop(preview_layer); 1479 preview_layer->parent()->StackAtTop(preview_layer);
1480 } 1480 }
1481 #endif 1481 #endif
1482 } 1482 }
1483 1483
1484 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && 1484 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() &&
1485 GetWidget()->IsVisible()) { 1485 GetWidget()->IsVisible()) {
1486 // We only restore focus if our window is visible, to avoid invoking blur 1486 // We only restore focus if our window is visible, to avoid invoking blur
1487 // handlers when we are eventually shown. 1487 // handlers when we are eventually shown.
1488 new_contents->web_contents()->GetView()->RestoreFocus(); 1488 new_contents->GetView()->RestoreFocus();
1489 } 1489 }
1490 1490
1491 // Update all the UI bits. 1491 // Update all the UI bits.
1492 UpdateTitleBar(); 1492 UpdateTitleBar();
1493 1493
1494 MaybeStackBookmarkBarAtTop(); 1494 MaybeStackBookmarkBarAtTop();
1495 1495
1496 // No need to update Toolbar because it's already updated in 1496 // No need to update Toolbar because it's already updated in
1497 // browser.cc. 1497 // browser.cc.
1498 } 1498 }
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
2061 #if !defined(USE_ASH) 2061 #if !defined(USE_ASH)
2062 overlap += 2062 overlap +=
2063 IsMaximized() ? 0 : views::NonClientFrameView::kClientEdgeThickness; 2063 IsMaximized() ? 0 : views::NonClientFrameView::kClientEdgeThickness;
2064 #endif 2064 #endif
2065 int height = status_bubble_->GetPreferredSize().height(); 2065 int height = status_bubble_->GetPreferredSize().height();
2066 int contents_height = status_bubble_->base_view()->bounds().height(); 2066 int contents_height = status_bubble_->base_view()->bounds().height();
2067 gfx::Point origin(-overlap, contents_height - height + overlap); 2067 gfx::Point origin(-overlap, contents_height - height + overlap);
2068 status_bubble_->SetBounds(origin.x(), origin.y(), width() / 3, height); 2068 status_bubble_->SetBounds(origin.x(), origin.y(), width() / 3, height);
2069 } 2069 }
2070 2070
2071 bool BrowserView::MaybeShowBookmarkBar(TabContents* contents) { 2071 bool BrowserView::MaybeShowBookmarkBar(WebContents* contents) {
2072 views::View* new_bookmark_bar_view = NULL; 2072 views::View* new_bookmark_bar_view = NULL;
2073 if (browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR) && 2073 if (browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR) &&
2074 contents) { 2074 contents) {
2075 if (!bookmark_bar_view_.get()) { 2075 if (!bookmark_bar_view_.get()) {
2076 bookmark_bar_view_.reset(new BookmarkBarView(browser_.get(), this)); 2076 bookmark_bar_view_.reset(new BookmarkBarView(browser_.get(), this));
2077 bookmark_bar_view_->set_owned_by_client(); 2077 bookmark_bar_view_->set_owned_by_client();
2078 bookmark_bar_view_->set_background( 2078 bookmark_bar_view_->set_background(
2079 new BookmarkExtensionBackground(this, bookmark_bar_view_.get(), 2079 new BookmarkExtensionBackground(this, bookmark_bar_view_.get(),
2080 browser_.get())); 2080 browser_.get()));
2081 bookmark_bar_view_->SetBookmarkBarState( 2081 bookmark_bar_view_->SetBookmarkBarState(
2082 browser_->bookmark_bar_state(), 2082 browser_->bookmark_bar_state(),
2083 BookmarkBar::DONT_ANIMATE_STATE_CHANGE, 2083 BookmarkBar::DONT_ANIMATE_STATE_CHANGE,
2084 browser_->search_model()->mode()); 2084 browser_->search_model()->mode());
2085 } 2085 }
2086 bookmark_bar_view_->SetPageNavigator(contents->web_contents()); 2086 bookmark_bar_view_->SetPageNavigator(contents);
2087 new_bookmark_bar_view = bookmark_bar_view_.get(); 2087 new_bookmark_bar_view = bookmark_bar_view_.get();
2088 } 2088 }
2089 return UpdateChildViewAndLayout(new_bookmark_bar_view, &active_bookmark_bar_); 2089 return UpdateChildViewAndLayout(new_bookmark_bar_view, &active_bookmark_bar_);
2090 } 2090 }
2091 2091
2092 bool BrowserView::MaybeShowInfoBar(TabContents* contents) { 2092 bool BrowserView::MaybeShowInfoBar(WebContents* contents) {
2093 // TODO(beng): Remove this function once the interface between 2093 // TODO(beng): Remove this function once the interface between
2094 // InfoBarContainer, DownloadShelfView and WebContents and this 2094 // InfoBarContainer, DownloadShelfView and WebContents and this
2095 // view is sorted out. 2095 // view is sorted out.
2096 return true; 2096 return true;
2097 } 2097 }
2098 2098
2099 void BrowserView::UpdateDevToolsForContents(TabContents* tab_contents) { 2099 void BrowserView::UpdateDevToolsForContents(WebContents* web_contents) {
2100 DevToolsWindow* new_devtools_window = tab_contents ? 2100 DevToolsWindow* new_devtools_window = web_contents ?
2101 DevToolsWindow::GetDockedInstanceForInspectedTab( 2101 DevToolsWindow::GetDockedInstanceForInspectedTab(web_contents) : NULL;
2102 tab_contents->web_contents()) : NULL;
2103 // Fast return in case of the same window having same orientation. 2102 // Fast return in case of the same window having same orientation.
2104 if (devtools_window_ == new_devtools_window) { 2103 if (devtools_window_ == new_devtools_window) {
2105 if (!new_devtools_window || 2104 if (!new_devtools_window ||
2106 (new_devtools_window->dock_side() == devtools_dock_side_)) { 2105 (new_devtools_window->dock_side() == devtools_dock_side_)) {
2107 return; 2106 return;
2108 } 2107 }
2109 } 2108 }
2110 2109
2111 // Replace tab contents. 2110 // Replace tab contents.
2112 if (devtools_window_ != new_devtools_window) { 2111 if (devtools_window_ != new_devtools_window) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2176 int split_offset = contents_split_->width() - 2175 int split_offset = contents_split_->width() -
2177 devtools_window_->GetWidth(contents_split_->width()); 2176 devtools_window_->GetWidth(contents_split_->width());
2178 contents_split_->set_divider_offset(split_offset); 2177 contents_split_->set_divider_offset(split_offset);
2179 } else { 2178 } else {
2180 int split_offset = contents_split_->height() - 2179 int split_offset = contents_split_->height() -
2181 devtools_window_->GetHeight(contents_split_->height()); 2180 devtools_window_->GetHeight(contents_split_->height());
2182 contents_split_->set_divider_offset(split_offset); 2181 contents_split_->set_divider_offset(split_offset);
2183 } 2182 }
2184 } 2183 }
2185 2184
2186 void BrowserView::UpdateUIForContents(TabContents* contents) { 2185 void BrowserView::UpdateUIForContents(WebContents* contents) {
2187 bool needs_layout = MaybeShowBookmarkBar(contents); 2186 bool needs_layout = MaybeShowBookmarkBar(contents);
2188 needs_layout |= MaybeShowInfoBar(contents); 2187 needs_layout |= MaybeShowInfoBar(contents);
2189 if (needs_layout) 2188 if (needs_layout)
2190 Layout(); 2189 Layout();
2191 } 2190 }
2192 2191
2193 bool BrowserView::UpdateChildViewAndLayout(views::View* new_view, 2192 bool BrowserView::UpdateChildViewAndLayout(views::View* new_view,
2194 views::View** old_view) { 2193 views::View** old_view) {
2195 DCHECK(old_view); 2194 DCHECK(old_view);
2196 if (*old_view == new_view) { 2195 if (*old_view == new_view) {
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 modal_browser->window()->Activate(); 2585 modal_browser->window()->Activate();
2587 } 2586 }
2588 2587
2589 AppModalDialogQueue::GetInstance()->ActivateModalDialog(); 2588 AppModalDialogQueue::GetInstance()->ActivateModalDialog();
2590 } 2589 }
2591 2590
2592 void BrowserView::MaybeStackBookmarkBarAtTop() { 2591 void BrowserView::MaybeStackBookmarkBarAtTop() {
2593 if (bookmark_bar_view_.get()) 2592 if (bookmark_bar_view_.get())
2594 bookmark_bar_view_->MaybeStackAtTop(); 2593 bookmark_bar_view_->MaybeStackAtTop();
2595 } 2594 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698