| OLD | NEW |
| 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/tabs/tab_strip.h" | 5 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 adjust_layout_(false), | 594 adjust_layout_(false), |
| 595 reset_to_shrink_on_exit_(false), | 595 reset_to_shrink_on_exit_(false), |
| 596 mouse_move_count_(0), | 596 mouse_move_count_(0), |
| 597 immersive_style_(false) { | 597 immersive_style_(false) { |
| 598 Init(); | 598 Init(); |
| 599 SetEventTargeter( | 599 SetEventTargeter( |
| 600 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 600 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 601 } | 601 } |
| 602 | 602 |
| 603 TabStrip::~TabStrip() { | 603 TabStrip::~TabStrip() { |
| 604 FOR_EACH_OBSERVER(TabStripObserver, observers_, | 604 for (TabStripObserver& observer : observers_) |
| 605 TabStripDeleted(this)); | 605 observer.TabStripDeleted(this); |
| 606 | 606 |
| 607 // The animations may reference the tabs. Shut down the animation before we | 607 // The animations may reference the tabs. Shut down the animation before we |
| 608 // delete the tabs. | 608 // delete the tabs. |
| 609 StopAnimating(false); | 609 StopAnimating(false); |
| 610 | 610 |
| 611 DestroyDragController(); | 611 DestroyDragController(); |
| 612 | 612 |
| 613 // Make sure we unhook ourselves as a message loop observer so that we don't | 613 // Make sure we unhook ourselves as a message loop observer so that we don't |
| 614 // crash in the case where the user closes the window after closing a tab | 614 // crash in the case where the user closes the window after closing a tab |
| 615 // but before moving the mouse. | 615 // but before moving the mouse. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 | 693 |
| 694 // Don't animate the first tab, it looks weird, and don't animate anything | 694 // Don't animate the first tab, it looks weird, and don't animate anything |
| 695 // if the containing window isn't visible yet. | 695 // if the containing window isn't visible yet. |
| 696 if (tab_count() > 1 && GetWidget() && GetWidget()->IsVisible()) | 696 if (tab_count() > 1 && GetWidget() && GetWidget()->IsVisible()) |
| 697 StartInsertTabAnimation(model_index); | 697 StartInsertTabAnimation(model_index); |
| 698 else | 698 else |
| 699 DoLayout(); | 699 DoLayout(); |
| 700 | 700 |
| 701 SwapLayoutIfNecessary(); | 701 SwapLayoutIfNecessary(); |
| 702 | 702 |
| 703 FOR_EACH_OBSERVER(TabStripObserver, observers_, | 703 for (TabStripObserver& observer : observers_) |
| 704 TabStripAddedTabAt(this, model_index)); | 704 observer.TabStripAddedTabAt(this, model_index); |
| 705 | 705 |
| 706 // Stop dragging when a new tab is added and dragging a window. Doing | 706 // Stop dragging when a new tab is added and dragging a window. Doing |
| 707 // otherwise results in a confusing state if the user attempts to reattach. We | 707 // otherwise results in a confusing state if the user attempts to reattach. We |
| 708 // could allow this and make TabDragController update itself during the add, | 708 // could allow this and make TabDragController update itself during the add, |
| 709 // but this comes up infrequently enough that it's not worth the complexity. | 709 // but this comes up infrequently enough that it's not worth the complexity. |
| 710 // | 710 // |
| 711 // At the start of AddTabAt() the model and tabs are out sync. Any queries to | 711 // At the start of AddTabAt() the model and tabs are out sync. Any queries to |
| 712 // find a tab given a model index can go off the end of |tabs_|. As such, it | 712 // find a tab given a model index can go off the end of |tabs_|. As such, it |
| 713 // is important that we complete the drag *after* adding the tab so that the | 713 // is important that we complete the drag *after* adding the tab so that the |
| 714 // model and tabstrip are in sync. | 714 // model and tabstrip are in sync. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 734 } else { | 734 } else { |
| 735 tabs_.Move(from_model_index, to_model_index); | 735 tabs_.Move(from_model_index, to_model_index); |
| 736 } | 736 } |
| 737 StartMoveTabAnimation(); | 737 StartMoveTabAnimation(); |
| 738 if (TabDragController::IsAttachedTo(this) && | 738 if (TabDragController::IsAttachedTo(this) && |
| 739 (last_tab != GetLastVisibleTab() || last_tab->dragging())) { | 739 (last_tab != GetLastVisibleTab() || last_tab->dragging())) { |
| 740 newtab_button_->SetVisible(false); | 740 newtab_button_->SetVisible(false); |
| 741 } | 741 } |
| 742 SwapLayoutIfNecessary(); | 742 SwapLayoutIfNecessary(); |
| 743 | 743 |
| 744 FOR_EACH_OBSERVER(TabStripObserver, observers_, | 744 for (TabStripObserver& observer : observers_) |
| 745 TabStripMovedTab(this, from_model_index, to_model_index)); | 745 observer.TabStripMovedTab(this, from_model_index, to_model_index); |
| 746 } | 746 } |
| 747 | 747 |
| 748 void TabStrip::RemoveTabAt(content::WebContents* contents, int model_index) { | 748 void TabStrip::RemoveTabAt(content::WebContents* contents, int model_index) { |
| 749 if (touch_layout_) { | 749 if (touch_layout_) { |
| 750 Tab* tab = tab_at(model_index); | 750 Tab* tab = tab_at(model_index); |
| 751 tab->set_closing(true); | 751 tab->set_closing(true); |
| 752 int old_x = tabs_.ideal_bounds(model_index).x(); | 752 int old_x = tabs_.ideal_bounds(model_index).x(); |
| 753 // We still need to paint the tab until we actually remove it. Put it in | 753 // We still need to paint the tab until we actually remove it. Put it in |
| 754 // tabs_closing_map_ so we can find it. | 754 // tabs_closing_map_ so we can find it. |
| 755 RemoveTabFromViewModel(model_index); | 755 RemoveTabFromViewModel(model_index); |
| 756 touch_layout_->RemoveTab(model_index, | 756 touch_layout_->RemoveTab(model_index, |
| 757 GenerateIdealBoundsForPinnedTabs(NULL), old_x); | 757 GenerateIdealBoundsForPinnedTabs(NULL), old_x); |
| 758 ScheduleRemoveTabAnimation(tab); | 758 ScheduleRemoveTabAnimation(tab); |
| 759 } else if (in_tab_close_ && model_index != GetModelCount()) { | 759 } else if (in_tab_close_ && model_index != GetModelCount()) { |
| 760 StartMouseInitiatedRemoveTabAnimation(model_index); | 760 StartMouseInitiatedRemoveTabAnimation(model_index); |
| 761 } else { | 761 } else { |
| 762 StartRemoveTabAnimation(model_index); | 762 StartRemoveTabAnimation(model_index); |
| 763 } | 763 } |
| 764 SwapLayoutIfNecessary(); | 764 SwapLayoutIfNecessary(); |
| 765 | 765 |
| 766 FOR_EACH_OBSERVER(TabStripObserver, observers_, | 766 for (TabStripObserver& observer : observers_) |
| 767 TabStripRemovedTabAt(this, model_index)); | 767 observer.TabStripRemovedTabAt(this, model_index); |
| 768 | 768 |
| 769 // Stop dragging when a new tab is removed and dragging a window. Doing | 769 // Stop dragging when a new tab is removed and dragging a window. Doing |
| 770 // otherwise results in a confusing state if the user attempts to reattach. We | 770 // otherwise results in a confusing state if the user attempts to reattach. We |
| 771 // could allow this and make TabDragController update itself during the | 771 // could allow this and make TabDragController update itself during the |
| 772 // remove operation, but this comes up infrequently enough that it's not worth | 772 // remove operation, but this comes up infrequently enough that it's not worth |
| 773 // the complexity. | 773 // the complexity. |
| 774 // | 774 // |
| 775 // At the start of RemoveTabAt() the model and tabs are out sync. Any queries | 775 // At the start of RemoveTabAt() the model and tabs are out sync. Any queries |
| 776 // to find a tab given a model index can go off the end of |tabs_|. As such, | 776 // to find a tab given a model index can go off the end of |tabs_|. As such, |
| 777 // it is important that we complete the drag *after* removing the tab so that | 777 // it is important that we complete the drag *after* removing the tab so that |
| (...skipping 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2421 | 2421 |
| 2422 const int max_new_tab_x = width() - newtab_button_bounds_.width(); | 2422 const int max_new_tab_x = width() - newtab_button_bounds_.width(); |
| 2423 // For non-stacked tabs the ideal bounds may go outside the bounds of the | 2423 // For non-stacked tabs the ideal bounds may go outside the bounds of the |
| 2424 // tabstrip. Constrain the x-coordinate of the new tab button so that it is | 2424 // tabstrip. Constrain the x-coordinate of the new tab button so that it is |
| 2425 // always visible. | 2425 // always visible. |
| 2426 const int new_tab_x = std::min( | 2426 const int new_tab_x = std::min( |
| 2427 max_new_tab_x, tabs_.ideal_bounds(tabs_.view_size() - 1).right() - | 2427 max_new_tab_x, tabs_.ideal_bounds(tabs_.view_size() - 1).right() - |
| 2428 GetLayoutConstant(TABSTRIP_NEW_TAB_BUTTON_OVERLAP)); | 2428 GetLayoutConstant(TABSTRIP_NEW_TAB_BUTTON_OVERLAP)); |
| 2429 const int old_max_x = newtab_button_bounds_.right(); | 2429 const int old_max_x = newtab_button_bounds_.right(); |
| 2430 newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, 0)); | 2430 newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, 0)); |
| 2431 if (newtab_button_bounds_.right() != old_max_x) | 2431 if (newtab_button_bounds_.right() != old_max_x) { |
| 2432 FOR_EACH_OBSERVER(TabStripObserver, observers_, TabStripMaxXChanged(this)); | 2432 for (TabStripObserver& observer : observers_) |
| 2433 observer.TabStripMaxXChanged(this); |
| 2434 } |
| 2433 } | 2435 } |
| 2434 | 2436 |
| 2435 int TabStrip::GenerateIdealBoundsForPinnedTabs(int* first_non_pinned_index) { | 2437 int TabStrip::GenerateIdealBoundsForPinnedTabs(int* first_non_pinned_index) { |
| 2436 const int num_pinned_tabs = GetPinnedTabCount(); | 2438 const int num_pinned_tabs = GetPinnedTabCount(); |
| 2437 | 2439 |
| 2438 if (first_non_pinned_index) | 2440 if (first_non_pinned_index) |
| 2439 *first_non_pinned_index = num_pinned_tabs; | 2441 *first_non_pinned_index = num_pinned_tabs; |
| 2440 | 2442 |
| 2441 if (num_pinned_tabs == 0) | 2443 if (num_pinned_tabs == 0) |
| 2442 return 0; | 2444 return 0; |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2802 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); | 2804 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); |
| 2803 if (view) | 2805 if (view) |
| 2804 return view; | 2806 return view; |
| 2805 } | 2807 } |
| 2806 Tab* tab = FindTabForEvent(point); | 2808 Tab* tab = FindTabForEvent(point); |
| 2807 if (tab) | 2809 if (tab) |
| 2808 return ConvertPointToViewAndGetEventHandler(this, tab, point); | 2810 return ConvertPointToViewAndGetEventHandler(this, tab, point); |
| 2809 } | 2811 } |
| 2810 return this; | 2812 return this; |
| 2811 } | 2813 } |
| OLD | NEW |