OLD | NEW |
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 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 // Loads are now complete, update the state if a task was scheduled. | 768 // Loads are now complete, update the state if a task was scheduled. |
769 LoadingAnimationCallback(); | 769 LoadingAnimationCallback(); |
770 } | 770 } |
771 } | 771 } |
772 } | 772 } |
773 | 773 |
774 void BrowserView::SetStarredState(bool is_starred) { | 774 void BrowserView::SetStarredState(bool is_starred) { |
775 GetLocationBarView()->SetStarToggled(is_starred); | 775 GetLocationBarView()->SetStarToggled(is_starred); |
776 } | 776 } |
777 | 777 |
| 778 void BrowserView::OnActiveTabChanged(content::WebContents* old_contents, |
| 779 content::WebContents* new_contents, |
| 780 int index, |
| 781 int reason) { |
| 782 DCHECK(new_contents); |
| 783 |
| 784 // If |contents_container_| already has the correct WebContents, we can save |
| 785 // some work. This also prevents extra events from being reported by the |
| 786 // Visibility API under Windows, as ChangeWebContents will briefly hide |
| 787 // the WebContents window. |
| 788 bool change_tab_contents = |
| 789 contents_web_view_->web_contents() != new_contents; |
| 790 |
| 791 // Update various elements that are interested in knowing the current |
| 792 // WebContents. |
| 793 |
| 794 // When we toggle the NTP floating bookmarks bar and/or the info bar, |
| 795 // we don't want any WebContents to be attached, so that we |
| 796 // avoid an unnecessary resize and re-layout of a WebContents. |
| 797 if (change_tab_contents) |
| 798 contents_web_view_->SetWebContents(NULL); |
| 799 infobar_container_->ChangeInfoBarService( |
| 800 InfoBarService::FromWebContents(new_contents)); |
| 801 if (bookmark_bar_view_.get()) { |
| 802 bookmark_bar_view_->SetBookmarkBarState( |
| 803 browser_->bookmark_bar_state(), |
| 804 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); |
| 805 } |
| 806 UpdateUIForContents(new_contents); |
| 807 |
| 808 // Layout for DevTools _before_ setting the main WebContents to avoid |
| 809 // toggling the size of the main WebContents. |
| 810 UpdateDevToolsForContents(new_contents); |
| 811 |
| 812 if (change_tab_contents) |
| 813 contents_web_view_->SetWebContents(new_contents); |
| 814 |
| 815 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && |
| 816 GetWidget()->IsVisible()) { |
| 817 // We only restore focus if our window is visible, to avoid invoking blur |
| 818 // handlers when we are eventually shown. |
| 819 new_contents->GetView()->RestoreFocus(); |
| 820 } |
| 821 |
| 822 // Update all the UI bits. |
| 823 UpdateTitleBar(); |
| 824 } |
| 825 |
778 void BrowserView::ZoomChangedForActiveTab(bool can_show_bubble) { | 826 void BrowserView::ZoomChangedForActiveTab(bool can_show_bubble) { |
779 GetLocationBarView()->ZoomChangedForActiveTab( | 827 GetLocationBarView()->ZoomChangedForActiveTab( |
780 can_show_bubble && !toolbar_->IsWrenchMenuShowing()); | 828 can_show_bubble && !toolbar_->IsWrenchMenuShowing()); |
781 } | 829 } |
782 | 830 |
783 gfx::Rect BrowserView::GetRestoredBounds() const { | 831 gfx::Rect BrowserView::GetRestoredBounds() const { |
784 return frame_->GetRestoredBounds(); | 832 return frame_->GetRestoredBounds(); |
785 } | 833 } |
786 | 834 |
787 ui::WindowShowState BrowserView::GetRestoredState() const { | 835 ui::WindowShowState BrowserView::GetRestoredState() const { |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1390 } | 1438 } |
1391 | 1439 |
1392 void BrowserView::TabDeactivated(WebContents* contents) { | 1440 void BrowserView::TabDeactivated(WebContents* contents) { |
1393 // We do not store the focus when closing the tab to work-around bug 4633. | 1441 // We do not store the focus when closing the tab to work-around bug 4633. |
1394 // Some reports seem to show that the focus manager and/or focused view can | 1442 // Some reports seem to show that the focus manager and/or focused view can |
1395 // be garbage at that point, it is not clear why. | 1443 // be garbage at that point, it is not clear why. |
1396 if (!contents->IsBeingDestroyed()) | 1444 if (!contents->IsBeingDestroyed()) |
1397 contents->GetView()->StoreFocus(); | 1445 contents->GetView()->StoreFocus(); |
1398 } | 1446 } |
1399 | 1447 |
1400 void BrowserView::ActiveTabChanged(content::WebContents* old_contents, | |
1401 content::WebContents* new_contents, | |
1402 int index, | |
1403 int reason) { | |
1404 DCHECK(new_contents); | |
1405 | |
1406 // If |contents_container_| already has the correct WebContents, we can save | |
1407 // some work. This also prevents extra events from being reported by the | |
1408 // Visibility API under Windows, as ChangeWebContents will briefly hide | |
1409 // the WebContents window. | |
1410 bool change_tab_contents = | |
1411 contents_web_view_->web_contents() != new_contents; | |
1412 | |
1413 // Update various elements that are interested in knowing the current | |
1414 // WebContents. | |
1415 | |
1416 // When we toggle the NTP floating bookmarks bar and/or the info bar, | |
1417 // we don't want any WebContents to be attached, so that we | |
1418 // avoid an unnecessary resize and re-layout of a WebContents. | |
1419 if (change_tab_contents) | |
1420 contents_web_view_->SetWebContents(NULL); | |
1421 infobar_container_->ChangeInfoBarService( | |
1422 InfoBarService::FromWebContents(new_contents)); | |
1423 if (bookmark_bar_view_.get()) { | |
1424 bookmark_bar_view_->SetBookmarkBarState( | |
1425 browser_->bookmark_bar_state(), | |
1426 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); | |
1427 } | |
1428 UpdateUIForContents(new_contents); | |
1429 | |
1430 // Layout for DevTools _before_ setting the main WebContents to avoid | |
1431 // toggling the size of the main WebContents. | |
1432 UpdateDevToolsForContents(new_contents); | |
1433 | |
1434 if (change_tab_contents) | |
1435 contents_web_view_->SetWebContents(new_contents); | |
1436 | |
1437 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && | |
1438 GetWidget()->IsVisible()) { | |
1439 // We only restore focus if our window is visible, to avoid invoking blur | |
1440 // handlers when we are eventually shown. | |
1441 new_contents->GetView()->RestoreFocus(); | |
1442 } | |
1443 | |
1444 // Update all the UI bits. | |
1445 UpdateTitleBar(); | |
1446 | |
1447 // No need to update Toolbar because it's already updated in | |
1448 // browser.cc. | |
1449 } | |
1450 | |
1451 void BrowserView::TabStripEmpty() { | 1448 void BrowserView::TabStripEmpty() { |
1452 // Make sure all optional UI is removed before we are destroyed, otherwise | 1449 // Make sure all optional UI is removed before we are destroyed, otherwise |
1453 // there will be consequences (since our view hierarchy will still have | 1450 // there will be consequences (since our view hierarchy will still have |
1454 // references to freed views). | 1451 // references to freed views). |
1455 UpdateUIForContents(NULL); | 1452 UpdateUIForContents(NULL); |
1456 } | 1453 } |
1457 | 1454 |
1458 /////////////////////////////////////////////////////////////////////////////// | 1455 /////////////////////////////////////////////////////////////////////////////// |
1459 // BrowserView, ui::AcceleratorProvider implementation: | 1456 // BrowserView, ui::AcceleratorProvider implementation: |
1460 | 1457 |
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2678 // The +1 in the next line creates a 1-px gap between icon and arrow tip. | 2675 // The +1 in the next line creates a 1-px gap between icon and arrow tip. |
2679 gfx::Point icon_bottom(0, location_icon_view->GetImageBounds().bottom() - | 2676 gfx::Point icon_bottom(0, location_icon_view->GetImageBounds().bottom() - |
2680 LocationBarView::kIconInternalPadding + 1); | 2677 LocationBarView::kIconInternalPadding + 1); |
2681 ConvertPointToTarget(location_icon_view, this, &icon_bottom); | 2678 ConvertPointToTarget(location_icon_view, this, &icon_bottom); |
2682 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); | 2679 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); |
2683 ConvertPointToTarget(infobar_container_, this, &infobar_top); | 2680 ConvertPointToTarget(infobar_container_, this, &infobar_top); |
2684 top_arrow_height = infobar_top.y() - icon_bottom.y(); | 2681 top_arrow_height = infobar_top.y() - icon_bottom.y(); |
2685 } | 2682 } |
2686 return top_arrow_height; | 2683 return top_arrow_height; |
2687 } | 2684 } |
OLD | NEW |