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

Side by Side Diff: chrome/browser/ui/views/tabs/tab_strip.cc

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 (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 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 in_tab_close_(false), 682 in_tab_close_(false),
683 animation_container_(new gfx::AnimationContainer()), 683 animation_container_(new gfx::AnimationContainer()),
684 bounds_animator_(this), 684 bounds_animator_(this),
685 stacked_layout_(false), 685 stacked_layout_(false),
686 adjust_layout_(false), 686 adjust_layout_(false),
687 reset_to_shrink_on_exit_(false), 687 reset_to_shrink_on_exit_(false),
688 mouse_move_count_(0), 688 mouse_move_count_(0),
689 immersive_style_(false) { 689 immersive_style_(false) {
690 Init(); 690 Init();
691 SetEventTargeter( 691 SetEventTargeter(
692 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); 692 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
693 } 693 }
694 694
695 TabStrip::~TabStrip() { 695 TabStrip::~TabStrip() {
696 FOR_EACH_OBSERVER(TabStripObserver, observers_, 696 FOR_EACH_OBSERVER(TabStripObserver, observers_,
697 TabStripDeleted(this)); 697 TabStripDeleted(this));
698 698
699 // The animations may reference the tabs. Shut down the animation before we 699 // The animations may reference the tabs. Shut down the animation before we
700 // delete the tabs. 700 // delete the tabs.
701 StopAnimating(false); 701 StopAnimating(false);
702 702
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 1701
1702 newtab_button_bounds_.set_size(GetLayoutSize(NEW_TAB_BUTTON)); 1702 newtab_button_bounds_.set_size(GetLayoutSize(NEW_TAB_BUTTON));
1703 newtab_button_bounds_.Inset(0, 0, 0, -GetNewTabButtonTopOffset()); 1703 newtab_button_bounds_.Inset(0, 0, 0, -GetNewTabButtonTopOffset());
1704 newtab_button_ = new NewTabButton(this, this); 1704 newtab_button_ = new NewTabButton(this, this);
1705 newtab_button_->SetTooltipText( 1705 newtab_button_->SetTooltipText(
1706 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); 1706 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB));
1707 newtab_button_->SetAccessibleName( 1707 newtab_button_->SetAccessibleName(
1708 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); 1708 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB));
1709 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, 1709 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
1710 views::ImageButton::ALIGN_BOTTOM); 1710 views::ImageButton::ALIGN_BOTTOM);
1711 newtab_button_->SetEventTargeter( 1711 newtab_button_->SetEventTargeter(std::unique_ptr<views::ViewTargeter>(
1712 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(newtab_button_))); 1712 new views::ViewTargeter(newtab_button_)));
1713 AddChildView(newtab_button_); 1713 AddChildView(newtab_button_);
1714 1714
1715 if (drop_indicator_width == 0) { 1715 if (drop_indicator_width == 0) {
1716 // Direction doesn't matter, both images are the same size. 1716 // Direction doesn't matter, both images are the same size.
1717 gfx::ImageSkia* drop_image = GetDropArrowImage(true); 1717 gfx::ImageSkia* drop_image = GetDropArrowImage(true);
1718 drop_indicator_width = drop_image->width(); 1718 drop_indicator_width = drop_image->width();
1719 drop_indicator_height = drop_image->height(); 1719 drop_indicator_height = drop_image->height();
1720 } 1720 }
1721 } 1721 }
1722 1722
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 1763
1764 void TabStrip::ScheduleRemoveTabAnimation(Tab* tab) { 1764 void TabStrip::ScheduleRemoveTabAnimation(Tab* tab) {
1765 // Start an animation for the tabs. 1765 // Start an animation for the tabs.
1766 GenerateIdealBounds(); 1766 GenerateIdealBounds();
1767 AnimateToIdealBounds(); 1767 AnimateToIdealBounds();
1768 1768
1769 // Animate the tab being closed to zero width. 1769 // Animate the tab being closed to zero width.
1770 gfx::Rect tab_bounds = tab->bounds(); 1770 gfx::Rect tab_bounds = tab->bounds();
1771 tab_bounds.set_width(0); 1771 tab_bounds.set_width(0);
1772 bounds_animator_.AnimateViewTo(tab, tab_bounds); 1772 bounds_animator_.AnimateViewTo(tab, tab_bounds);
1773 bounds_animator_.SetAnimationDelegate( 1773 bounds_animator_.SetAnimationDelegate(tab,
1774 tab, 1774 std::unique_ptr<gfx::AnimationDelegate>(
1775 scoped_ptr<gfx::AnimationDelegate>(new RemoveTabDelegate(this, tab))); 1775 new RemoveTabDelegate(this, tab)));
1776 1776
1777 // Don't animate the new tab button when dragging tabs. Otherwise it looks 1777 // Don't animate the new tab button when dragging tabs. Otherwise it looks
1778 // like the new tab button magically appears from beyond the end of the tab 1778 // like the new tab button magically appears from beyond the end of the tab
1779 // strip. 1779 // strip.
1780 if (TabDragController::IsAttachedTo(this)) { 1780 if (TabDragController::IsAttachedTo(this)) {
1781 bounds_animator_.StopAnimatingView(newtab_button_); 1781 bounds_animator_.StopAnimatingView(newtab_button_);
1782 newtab_button_->SetBoundsRect(newtab_button_bounds_); 1782 newtab_button_->SetBoundsRect(newtab_button_bounds_);
1783 } 1783 }
1784 } 1784 }
1785 1785
1786 void TabStrip::AnimateToIdealBounds() { 1786 void TabStrip::AnimateToIdealBounds() {
1787 for (int i = 0; i < tab_count(); ++i) { 1787 for (int i = 0; i < tab_count(); ++i) {
1788 Tab* tab = tab_at(i); 1788 Tab* tab = tab_at(i);
1789 if (!tab->dragging()) { 1789 if (!tab->dragging()) {
1790 bounds_animator_.AnimateViewTo(tab, ideal_bounds(i)); 1790 bounds_animator_.AnimateViewTo(tab, ideal_bounds(i));
1791 bounds_animator_.SetAnimationDelegate( 1791 bounds_animator_.SetAnimationDelegate(
1792 tab, 1792 tab, std::unique_ptr<gfx::AnimationDelegate>(
1793 scoped_ptr<gfx::AnimationDelegate>( 1793 new TabAnimationDelegate(this, tab)));
1794 new TabAnimationDelegate(this, tab)));
1795 } 1794 }
1796 } 1795 }
1797 1796
1798 bounds_animator_.AnimateViewTo(newtab_button_, newtab_button_bounds_); 1797 bounds_animator_.AnimateViewTo(newtab_button_, newtab_button_bounds_);
1799 } 1798 }
1800 1799
1801 bool TabStrip::ShouldHighlightCloseButtonAfterRemove() { 1800 bool TabStrip::ShouldHighlightCloseButtonAfterRemove() {
1802 return in_tab_close_; 1801 return in_tab_close_;
1803 } 1802 }
1804 1803
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2023 2022
2024 void TabStrip::RemoveTabFromViewModel(int index) { 2023 void TabStrip::RemoveTabFromViewModel(int index) {
2025 // We still need to paint the tab until we actually remove it. Put it 2024 // We still need to paint the tab until we actually remove it. Put it
2026 // in tabs_closing_map_ so we can find it. 2025 // in tabs_closing_map_ so we can find it.
2027 tabs_closing_map_[index].push_back(tab_at(index)); 2026 tabs_closing_map_[index].push_back(tab_at(index));
2028 UpdateTabsClosingMap(index + 1, -1); 2027 UpdateTabsClosingMap(index + 1, -1);
2029 tabs_.Remove(index); 2028 tabs_.Remove(index);
2030 } 2029 }
2031 2030
2032 void TabStrip::RemoveAndDeleteTab(Tab* tab) { 2031 void TabStrip::RemoveAndDeleteTab(Tab* tab) {
2033 scoped_ptr<Tab> deleter(tab); 2032 std::unique_ptr<Tab> deleter(tab);
2034 FindClosingTabResult res(FindClosingTab(tab)); 2033 FindClosingTabResult res(FindClosingTab(tab));
2035 res.first->second.erase(res.second); 2034 res.first->second.erase(res.second);
2036 if (res.first->second.empty()) 2035 if (res.first->second.empty())
2037 tabs_closing_map_.erase(res.first); 2036 tabs_closing_map_.erase(res.first);
2038 } 2037 }
2039 2038
2040 void TabStrip::UpdateTabsClosingMap(int index, int delta) { 2039 void TabStrip::UpdateTabsClosingMap(int index, int delta) {
2041 if (tabs_closing_map_.empty()) 2040 if (tabs_closing_map_.empty())
2042 return; 2041 return;
2043 2042
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2131 PrepareForAnimation(); 2130 PrepareForAnimation();
2132 2131
2133 // Animate the view back to its correct position. 2132 // Animate the view back to its correct position.
2134 GenerateIdealBounds(); 2133 GenerateIdealBounds();
2135 AnimateToIdealBounds(); 2134 AnimateToIdealBounds();
2136 } 2135 }
2137 bounds_animator_.AnimateViewTo(tab, ideal_bounds(tab_data_index)); 2136 bounds_animator_.AnimateViewTo(tab, ideal_bounds(tab_data_index));
2138 // Install a delegate to reset the dragging state when done. We have to leave 2137 // Install a delegate to reset the dragging state when done. We have to leave
2139 // dragging true for the tab otherwise it'll draw beneath the new tab button. 2138 // dragging true for the tab otherwise it'll draw beneath the new tab button.
2140 bounds_animator_.SetAnimationDelegate( 2139 bounds_animator_.SetAnimationDelegate(
2141 tab, 2140 tab, std::unique_ptr<gfx::AnimationDelegate>(
2142 scoped_ptr<gfx::AnimationDelegate>( 2141 new ResetDraggingStateDelegate(this, tab)));
2143 new ResetDraggingStateDelegate(this, tab)));
2144 } 2142 }
2145 2143
2146 void TabStrip::OwnDragController(TabDragController* controller) { 2144 void TabStrip::OwnDragController(TabDragController* controller) {
2147 // Typically, ReleaseDragController() and OwnDragController() calls are paired 2145 // Typically, ReleaseDragController() and OwnDragController() calls are paired
2148 // via corresponding calls to TabDragController::Detach() and 2146 // via corresponding calls to TabDragController::Detach() and
2149 // TabDragController::Attach(). There is one exception to that rule: when a 2147 // TabDragController::Attach(). There is one exception to that rule: when a
2150 // drag might start, we create a TabDragController that is owned by the 2148 // drag might start, we create a TabDragController that is owned by the
2151 // potential source tabstrip in MaybeStartDrag(). If a drag actually starts, 2149 // potential source tabstrip in MaybeStartDrag(). If a drag actually starts,
2152 // we then call Attach() on the source tabstrip, but since the source tabstrip 2150 // we then call Attach() on the source tabstrip, but since the source tabstrip
2153 // already owns the TabDragController, so we don't need to do anything. 2151 // already owns the TabDragController, so we don't need to do anything.
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2585 2583
2586 AnimateToIdealBounds(); 2584 AnimateToIdealBounds();
2587 2585
2588 gfx::Rect tab_bounds = tab_closing->bounds(); 2586 gfx::Rect tab_bounds = tab_closing->bounds();
2589 tab_bounds.set_width(0); 2587 tab_bounds.set_width(0);
2590 bounds_animator_.AnimateViewTo(tab_closing, tab_bounds); 2588 bounds_animator_.AnimateViewTo(tab_closing, tab_bounds);
2591 2589
2592 // Register delegate to do cleanup when done, BoundsAnimator takes 2590 // Register delegate to do cleanup when done, BoundsAnimator takes
2593 // ownership of RemoveTabDelegate. 2591 // ownership of RemoveTabDelegate.
2594 bounds_animator_.SetAnimationDelegate( 2592 bounds_animator_.SetAnimationDelegate(
2595 tab_closing, 2593 tab_closing, std::unique_ptr<gfx::AnimationDelegate>(
2596 scoped_ptr<gfx::AnimationDelegate>( 2594 new RemoveTabDelegate(this, tab_closing)));
2597 new RemoveTabDelegate(this, tab_closing)));
2598 } 2595 }
2599 2596
2600 bool TabStrip::IsPointInTab(Tab* tab, 2597 bool TabStrip::IsPointInTab(Tab* tab,
2601 const gfx::Point& point_in_tabstrip_coords) { 2598 const gfx::Point& point_in_tabstrip_coords) {
2602 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); 2599 gfx::Point point_in_tab_coords(point_in_tabstrip_coords);
2603 View::ConvertPointToTarget(this, tab, &point_in_tab_coords); 2600 View::ConvertPointToTarget(this, tab, &point_in_tab_coords);
2604 return tab->HitTestPoint(point_in_tab_coords); 2601 return tab->HitTestPoint(point_in_tab_coords);
2605 } 2602 }
2606 2603
2607 int TabStrip::GetStartXForNormalTabs() const { 2604 int TabStrip::GetStartXForNormalTabs() const {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
2881 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); 2878 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point);
2882 if (view) 2879 if (view)
2883 return view; 2880 return view;
2884 } 2881 }
2885 Tab* tab = FindTabForEvent(point); 2882 Tab* tab = FindTabForEvent(point);
2886 if (tab) 2883 if (tab)
2887 return ConvertPointToViewAndGetEventHandler(this, tab, point); 2884 return ConvertPointToViewAndGetEventHandler(this, tab, point);
2888 } 2885 }
2889 return this; 2886 return this;
2890 } 2887 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip.h ('k') | chrome/browser/ui/views/tabs/tab_strip_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698