diff options
author | benwells <benwells@chromium.org> | 2015-06-02 22:02:53 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-03 05:03:28 +0000 |
commit | 90d364c5c2a956df4c3e6724699367ec1da3cec5 (patch) | |
tree | 318b63cd4537b3be00c5ddf57a1aee95aece8076 | |
parent | f0a364eade26aa3c977fc9ce94a738dd4796ac06 (diff) | |
download | chromium_src-90d364c5c2a956df4c3e6724699367ec1da3cec5.zip chromium_src-90d364c5c2a956df4c3e6724699367ec1da3cec5.tar.gz chromium_src-90d364c5c2a956df4c3e6724699367ec1da3cec5.tar.bz2 |
Remove code which makes app tabs always pinned.
The code which is being removed makes view source on a hosted / bookmark
app window always pinned and isn't used any more.
BUG=442624
Review URL: https://codereview.chromium.org/1150213003
Cr-Commit-Position: refs/heads/master@{#332555}
37 files changed, 534 insertions, 815 deletions
diff --git a/chrome/browser/profile_resetter/profile_resetter.cc b/chrome/browser/profile_resetter/profile_resetter.cc index ab2a026..ee0573f 100644 --- a/chrome/browser/profile_resetter/profile_resetter.cc +++ b/chrome/browser/profile_resetter/profile_resetter.cc @@ -288,7 +288,7 @@ void ProfileResetter::ResetPinnedTabs() { // If we unpin the tab, it can be moved to the right. Thus traversing in // reverse direction is correct. for (int i = tab_model->count() - 1; i >= 0; --i) { - if (tab_model->IsTabPinned(i) && !tab_model->IsAppTab(i)) + if (tab_model->IsTabPinned(i)) tab_model->SetTabPinned(i, false); } } diff --git a/chrome/browser/profile_resetter/profile_resetter_unittest.cc b/chrome/browser/profile_resetter/profile_resetter_unittest.cc index e8adc00..cb56e11 100644 --- a/chrome/browser/profile_resetter/profile_resetter_unittest.cc +++ b/chrome/browser/profile_resetter/profile_resetter_unittest.cc @@ -732,16 +732,7 @@ TEST_F(ProfileResetterTest, ResetStartPagePartially) { } TEST_F(PinnedTabsResetTest, ResetPinnedTabs) { - scoped_refptr<Extension> extension_app = CreateExtension( - base::ASCIIToUTF16("hello!"), - base::FilePath(FILE_PATH_LITERAL("//nonexistent")), - Manifest::INVALID_LOCATION, - extensions::Manifest::TYPE_HOSTED_APP, - false); scoped_ptr<content::WebContents> contents1(CreateWebContents()); - extensions::TabHelper::CreateForWebContents(contents1.get()); - extensions::TabHelper::FromWebContents(contents1.get())-> - SetExtensionApp(extension_app.get()); scoped_ptr<content::WebContents> contents2(CreateWebContents()); scoped_ptr<content::WebContents> contents3(CreateWebContents()); scoped_ptr<content::WebContents> contents4(CreateWebContents()); @@ -756,17 +747,17 @@ TEST_F(PinnedTabsResetTest, ResetPinnedTabs) { EXPECT_EQ(contents2, tab_strip_model->GetWebContentsAt(0)); EXPECT_EQ(contents1, tab_strip_model->GetWebContentsAt(1)); - EXPECT_EQ(contents3, tab_strip_model->GetWebContentsAt(2)); - EXPECT_EQ(contents4, tab_strip_model->GetWebContentsAt(3)); - EXPECT_EQ(3, tab_strip_model->IndexOfFirstNonMiniTab()); + EXPECT_EQ(contents4, tab_strip_model->GetWebContentsAt(2)); + EXPECT_EQ(contents3, tab_strip_model->GetWebContentsAt(3)); + EXPECT_EQ(2, tab_strip_model->IndexOfFirstNonPinnedTab()); ResetAndWait(ProfileResetter::PINNED_TABS); - EXPECT_EQ(contents1, tab_strip_model->GetWebContentsAt(0)); - EXPECT_EQ(contents2, tab_strip_model->GetWebContentsAt(1)); - EXPECT_EQ(contents3, tab_strip_model->GetWebContentsAt(2)); - EXPECT_EQ(contents4, tab_strip_model->GetWebContentsAt(3)); - EXPECT_EQ(1, tab_strip_model->IndexOfFirstNonMiniTab()); + EXPECT_EQ(contents2, tab_strip_model->GetWebContentsAt(0)); + EXPECT_EQ(contents1, tab_strip_model->GetWebContentsAt(1)); + EXPECT_EQ(contents4, tab_strip_model->GetWebContentsAt(2)); + EXPECT_EQ(contents3, tab_strip_model->GetWebContentsAt(3)); + EXPECT_EQ(0, tab_strip_model->IndexOfFirstNonPinnedTab()); } TEST_F(ProfileResetterTest, ResetShortcuts) { diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc index 99cdde0..d68d4516 100644 --- a/chrome/browser/ui/browser_browsertest.cc +++ b/chrome/browser/ui/browser_browsertest.cc @@ -1480,28 +1480,18 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) { IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { ASSERT_TRUE(test_server()->Start()); - // Add an pinned app tab. + // Add a pinned tab. host_resolver()->AddRule("www.example.com", "127.0.0.1"); GURL url(test_server()->GetURL("empty.html")); TabStripModel* model = browser()->tab_strip_model(); - ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); - const Extension* extension_app = GetExtension(); ui_test_utils::NavigateToURL(browser(), url); - WebContents* app_contents = WebContents::Create( - WebContents::CreateParams(browser()->profile())); - extensions::TabHelper::CreateForWebContents(app_contents); - extensions::TabHelper* extensions_tab_helper = - extensions::TabHelper::FromWebContents(app_contents); - extensions_tab_helper->SetExtensionApp(extension_app); - model->AddWebContents(app_contents, 0, ui::PageTransitionFromInt(0), - TabStripModel::ADD_NONE); model->SetTabPinned(0, true); - ui_test_utils::NavigateToURL(browser(), url); // Add a non pinned tab. chrome::NewTab(browser()); + ui_test_utils::NavigateToURL(browser(), url); - // Add a pinned non-app tab. + // Add another pinned tab. chrome::NewTab(browser()); ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); model->SetTabPinned(2, true); @@ -1537,20 +1527,12 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { // Make sure the state matches. TabStripModel* new_model = new_browser->tab_strip_model(); - EXPECT_TRUE(new_model->IsAppTab(0)); - EXPECT_FALSE(new_model->IsAppTab(1)); - EXPECT_FALSE(new_model->IsAppTab(2)); - EXPECT_TRUE(new_model->IsTabPinned(0)); EXPECT_TRUE(new_model->IsTabPinned(1)); EXPECT_FALSE(new_model->IsTabPinned(2)); EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), new_model->GetWebContentsAt(2)->GetURL()); - - EXPECT_TRUE( - extensions::TabHelper::FromWebContents( - new_model->GetWebContentsAt(0))->extension_app() == extension_app); } #endif // !defined(OS_CHROMEOS) diff --git a/chrome/browser/ui/browser_tabrestore.cc b/chrome/browser/ui/browser_tabrestore.cc index a90291e..c7fdf730 100644 --- a/chrome/browser/ui/browser_tabrestore.cc +++ b/chrome/browser/ui/browser_tabrestore.cc @@ -112,9 +112,8 @@ content::WebContents* AddRestoredTab( int add_types = select ? TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE; if (pin) { - int first_mini_tab_idx = - browser->tab_strip_model()->IndexOfFirstNonMiniTab(); - tab_index = std::min(tab_index, first_mini_tab_idx); + tab_index = std::min( + tab_index, browser->tab_strip_model()->IndexOfFirstNonPinnedTab()); add_types |= TabStripModel::ADD_PINNED; } browser->tab_strip_model()->InsertWebContentsAt(tab_index, web_contents, diff --git a/chrome/browser/ui/cocoa/tabs/tab_controller.h b/chrome/browser/ui/cocoa/tabs/tab_controller.h index 8456e6b..72bf49b 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_controller.h +++ b/chrome/browser/ui/cocoa/tabs/tab_controller.h @@ -50,8 +50,6 @@ class MenuDelegate; NSRect originalIconFrame_; // frame of iconView_ as loaded from nib BOOL isIconShowing_; // last state of iconView_ in updateVisibility - BOOL app_; - BOOL mini_; BOOL pinned_; BOOL active_; BOOL selected_; @@ -67,8 +65,6 @@ class MenuDelegate; @property(assign, nonatomic) TabLoadingState loadingState; @property(assign, nonatomic) SEL action; -@property(assign, nonatomic) BOOL app; -@property(assign, nonatomic) BOOL mini; @property(assign, nonatomic) BOOL pinned; @property(assign, nonatomic) NSString* toolTip; // Note that |-selected| will return YES if the controller is |-active|, too. @@ -91,8 +87,7 @@ class MenuDelegate; + (CGFloat)minTabWidth; + (CGFloat)maxTabWidth; + (CGFloat)minActiveTabWidth; -+ (CGFloat)miniTabWidth; -+ (CGFloat)appTabWidth; ++ (CGFloat)pinnedTabWidth; // The view associated with this controller, pre-casted as a TabView - (TabView*)tabView; diff --git a/chrome/browser/ui/cocoa/tabs/tab_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_controller.mm index cc7b8d8..c202120 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_controller.mm +++ b/chrome/browser/ui/cocoa/tabs/tab_controller.mm @@ -23,9 +23,7 @@ @implementation TabController @synthesize action = action_; -@synthesize app = app_; @synthesize loadingState = loadingState_; -@synthesize mini = mini_; @synthesize pinned = pinned_; @synthesize target = target_; @synthesize url = url_; @@ -74,8 +72,7 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate { + (CGFloat)minTabWidth { return 36; } + (CGFloat)minActiveTabWidth { return 52; } + (CGFloat)maxTabWidth { return 214; } -+ (CGFloat)miniTabWidth { return 58; } -+ (CGFloat)appTabWidth { return 66; } ++ (CGFloat)pinnedTabWidth { return 58; } - (TabView*)tabView { DCHECK([[self view] isKindOfClass:[TabView class]]); @@ -213,7 +210,7 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate { TabView* tabView = [self tabView]; [tabView setTitle:title]; - if ([self mini] && ![self active]) { + if ([self pinned] && ![self active]) { [tabView startAlert]; } [super setTitle:title]; @@ -299,21 +296,21 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate { - (BOOL)shouldShowIcon { return chrome::ShouldTabShowFavicon( - [self iconCapacity], [self mini], [self active], iconView_ != nil, + [self iconCapacity], [self pinned], [self active], iconView_ != nil, !mediaIndicatorButton_ ? TAB_MEDIA_STATE_NONE : [mediaIndicatorButton_ showingMediaState]); } - (BOOL)shouldShowMediaIndicator { return chrome::ShouldTabShowMediaIndicator( - [self iconCapacity], [self mini], [self active], iconView_ != nil, + [self iconCapacity], [self pinned], [self active], iconView_ != nil, !mediaIndicatorButton_ ? TAB_MEDIA_STATE_NONE : [mediaIndicatorButton_ showingMediaState]); } - (BOOL)shouldShowCloseButton { return chrome::ShouldTabShowCloseButton( - [self iconCapacity], [self mini], [self active]); + [self iconCapacity], [self pinned], [self active]); } - (void)setIconImage:(NSImage*)image { @@ -332,12 +329,11 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate { [iconView_ setImage:image withToastAnimation:animate]; - if ([self app] || [self mini]) { + if ([self pinned]) { NSRect appIconFrame = [iconView_ frame]; appIconFrame.origin = originalIconFrame_.origin; - const CGFloat tabWidth = [self app] ? [TabController appTabWidth] - : [TabController miniTabWidth]; + const CGFloat tabWidth = [TabController pinnedTabWidth]; // Center the icon. appIconFrame.origin.x = @@ -358,9 +354,9 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate { [iconView_ setHidden:!newShowIcon]; isIconShowing_ = newShowIcon; - // If the tab is a mini-tab, hide the title. + // If the tab is a pinned-tab, hide the title. TabView* tabView = [self tabView]; - [tabView setTitleHidden:[self mini]]; + [tabView setTitleHidden:[self pinned]]; BOOL newShowCloseButton = [self shouldShowCloseButton]; @@ -373,10 +369,9 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate { if (newShowMediaIndicator) { NSRect newFrame = [mediaIndicatorButton_ frame]; newFrame.size = [[mediaIndicatorButton_ image] size]; - if ([self app] || [self mini]) { + if ([self pinned]) { // Tab is pinned: Position the media indicator in the center. - const CGFloat tabWidth = [self app] ? - [TabController appTabWidth] : [TabController miniTabWidth]; + const CGFloat tabWidth = [TabController pinnedTabWidth]; newFrame.origin.x = std::floor((tabWidth - NSWidth(newFrame)) / 2); newFrame.origin.y = NSMinY(originalIconFrame_) - std::floor((NSHeight(newFrame) - NSHeight(originalIconFrame_)) / 2); diff --git a/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm b/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm index fe38b79..7b1909a 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm @@ -108,7 +108,7 @@ class TabControllerTest : public CocoaTest { // given Tab size and TabRendererData state. const TabMediaState indicatorState = [[controller mediaIndicatorButton] showingMediaState]; - if ([controller mini]) { + if ([controller pinned]) { EXPECT_EQ(1, [controller iconCapacity]); if (indicatorState != TAB_MEDIA_STATE_NONE) { EXPECT_FALSE([controller shouldShowIcon]); @@ -144,7 +144,7 @@ class TabControllerTest : public CocoaTest { EXPECT_FALSE([controller shouldShowMediaIndicator]); break; } - } else { // Tab not selected/active and not mini tab. + } else { // Tab not selected/active and not pinned tab. switch ([controller iconCapacity]) { case 0: EXPECT_FALSE([controller shouldShowCloseButton]); @@ -175,7 +175,7 @@ class TabControllerTest : public CocoaTest { // Make sure the NSView's "isHidden" state jives with the "shouldShowXXX." EXPECT_TRUE([controller shouldShowIcon] == (!![controller iconView] && ![[controller iconView] isHidden])); - EXPECT_TRUE([controller mini] == [[controller tabView] titleHidden]); + EXPECT_TRUE([controller pinned] == [[controller tabView] titleHidden]); EXPECT_TRUE([controller shouldShowMediaIndicator] == ![[controller mediaIndicatorButton] isHidden]); EXPECT_TRUE([controller shouldShowCloseButton] != @@ -502,7 +502,7 @@ TEST_F(TabControllerTest, DISABLED_LayoutAndVisibilityOfSubviews) { // Perform layout over all possible combinations, checking for correct // results. - for (int isMiniTab = 0; isMiniTab < 2; ++isMiniTab) { + for (int isPinnedTab = 0; isPinnedTab < 2; ++isPinnedTab) { for (int isActiveTab = 0; isActiveTab < 2; ++isActiveTab) { for (size_t mediaStateIndex = 0; mediaStateIndex < arraysize(kMediaStatesToTest); @@ -510,12 +510,12 @@ TEST_F(TabControllerTest, DISABLED_LayoutAndVisibilityOfSubviews) { const TabMediaState mediaState = kMediaStatesToTest[mediaStateIndex]; SCOPED_TRACE(::testing::Message() << (isActiveTab ? "Active" : "Inactive") << ' ' - << (isMiniTab ? "Mini " : "") + << (isPinnedTab ? "Pinned " : "") << "Tab with media indicator state " << mediaState); // Simulate what tab_strip_controller would do to set up the // TabController state. - [controller setMini:(isMiniTab ? YES : NO)]; + [controller setPinned:(isPinnedTab ? YES : NO)]; [controller setActive:(isActiveTab ? YES : NO)]; [controller setIconImage:favicon]; [controller setMediaState:mediaState]; @@ -524,8 +524,8 @@ TEST_F(TabControllerTest, DISABLED_LayoutAndVisibilityOfSubviews) { // Test layout for every width from maximum to minimum. NSRect tabFrame = [[controller view] frame]; int minWidth; - if (isMiniTab) { - tabFrame.size.width = minWidth = [TabController miniTabWidth]; + if (isPinnedTab) { + tabFrame.size.width = minWidth = [TabController pinnedTabWidth]; } else { tabFrame.size.width = [TabController maxTabWidth]; minWidth = isActiveTab ? [TabController minActiveTabWidth] : diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm index b4a33f5..49fd977 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm @@ -87,8 +87,8 @@ const CGFloat kUseFullAvailableWidth = -1.0; // on each throbber frame instead of one. const CGFloat kTabOverlap = 19.0; -// The amount by which mini tabs are separated from normal tabs. -const CGFloat kLastMiniTabSpacing = 2.0; +// The amount by which pinned tabs are separated from normal tabs. +const CGFloat kLastPinnedTabSpacing = 2.0; // The amount by which the new tab button is offset (from the tabs). const CGFloat kNewTabButtonOffset = 8.0; @@ -241,8 +241,8 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { - (NSInteger)indexFromModelIndex:(NSInteger)index; - (void)clickNewTabButton:(id)sender; - (NSInteger)numberOfOpenTabs; -- (NSInteger)numberOfOpenMiniTabs; -- (NSInteger)numberOfOpenNonMiniTabs; +- (NSInteger)numberOfOpenPinnedTabs; +- (NSInteger)numberOfOpenNonPinnedTabs; - (void)mouseMoved:(NSEvent*)event; - (void)setTabTrackingAreasEnabled:(BOOL)enabled; - (void)droppingURLsAt:(NSPoint)point @@ -683,17 +683,17 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { return static_cast<NSInteger>(tabStripModel_->count()); } -// (Private) Returns the number of open, mini-tabs. -- (NSInteger)numberOfOpenMiniTabs { - // Ask the model for the number of mini tabs. Note that tabs which are in +// (Private) Returns the number of open, pinned tabs. +- (NSInteger)numberOfOpenPinnedTabs { + // Ask the model for the number of pinned tabs. Note that tabs which are in // the process of closing (i.e., whose controllers are in // |closingControllers_|) have already been removed from the model. - return tabStripModel_->IndexOfFirstNonMiniTab(); + return tabStripModel_->IndexOfFirstNonPinnedTab(); } -// (Private) Returns the number of open, non-mini tabs. -- (NSInteger)numberOfOpenNonMiniTabs { - NSInteger number = [self numberOfOpenTabs] - [self numberOfOpenMiniTabs]; +// (Private) Returns the number of open, non-pinned tabs. +- (NSInteger)numberOfOpenNonPinnedTabs { + NSInteger number = [self numberOfOpenTabs] - [self numberOfOpenPinnedTabs]; DCHECK_GE(number, 0); return number; } @@ -951,8 +951,7 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { const CGFloat kMaxTabWidth = [TabController maxTabWidth]; const CGFloat kMinTabWidth = [TabController minTabWidth]; const CGFloat kMinActiveTabWidth = [TabController minActiveTabWidth]; - const CGFloat kMiniTabWidth = [TabController miniTabWidth]; - const CGFloat kAppTabWidth = [TabController appTabWidth]; + const CGFloat kPinnedTabWidth = [TabController pinnedTabWidth]; NSRect enclosingRect = NSZeroRect; ScopedNSAnimationContextGroup mainAnimationGroup(animate); @@ -963,7 +962,7 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { [self regenerateSubviewList]; // Compute the base width of tabs given how much room we're allowed. Note that - // mini-tabs have a fixed width. We may not be able to use the entire width + // pinned tabs have a fixed width. We may not be able to use the entire width // if the user is quickly closing tabs. This may be negative, but that's okay // (taken care of by |MAX()| when calculating tab sizes). CGFloat availableSpace = 0; @@ -987,32 +986,33 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { availableSpace -= [self leftIndentForControls]; // This may be negative, but that's okay (taken care of by |MAX()| when - // calculating tab sizes). "mini" tabs in horizontal mode just get a special + // calculating tab sizes). "pinned" tabs in horizontal mode just get a special // section, they don't change size. - CGFloat availableSpaceForNonMini = availableSpace; - if ([self numberOfOpenMiniTabs]) { - availableSpaceForNonMini -= - [self numberOfOpenMiniTabs] * (kMiniTabWidth - kTabOverlap); - availableSpaceForNonMini -= kLastMiniTabSpacing; + CGFloat availableSpaceForNonPinned = availableSpace; + if ([self numberOfOpenPinnedTabs]) { + availableSpaceForNonPinned -= + [self numberOfOpenPinnedTabs] * (kPinnedTabWidth - kTabOverlap); + availableSpaceForNonPinned -= kLastPinnedTabSpacing; } - // Initialize |nonMiniTabWidth| in case there aren't any non-mini-tabs; this - // value shouldn't actually be used. - CGFloat nonMiniTabWidth = kMaxTabWidth; - CGFloat nonMiniTabWidthFraction = 0; - NSInteger numberOfNonMiniTabs = MIN( - [self numberOfOpenNonMiniTabs], - (availableSpaceForNonMini - kTabOverlap) / (kMinTabWidth - kTabOverlap)); - - if (numberOfNonMiniTabs) { - // Find the width of a non-mini-tab. This only applies to horizontal + // Initialize |nonPinnedTabWidth| in case there aren't any non-pinned tabs; + // this value shouldn't actually be used. + CGFloat nonPinnedTabWidth = kMaxTabWidth; + CGFloat nonPinnedTabWidthFraction = 0; + NSInteger numberOfNonPinnedTabs = MIN( + [self numberOfOpenNonPinnedTabs], + (availableSpaceForNonPinned - kTabOverlap) / (kMinTabWidth - + kTabOverlap)); + + if (numberOfNonPinnedTabs) { + // Find the width of a non-pinned tab. This only applies to horizontal // mode. Add in the amount we "get back" from the tabs overlapping. - nonMiniTabWidth = - ((availableSpaceForNonMini - kTabOverlap) / numberOfNonMiniTabs) + + nonPinnedTabWidth = + ((availableSpaceForNonPinned - kTabOverlap) / numberOfNonPinnedTabs) + kTabOverlap; // Clamp the width between the max and min. - nonMiniTabWidth = MAX(MIN(nonMiniTabWidth, kMaxTabWidth), kMinTabWidth); + nonPinnedTabWidth = MAX(MIN(nonPinnedTabWidth, kMaxTabWidth), kMinTabWidth); // When there are multiple tabs, we'll have one active and some inactive // tabs. If the desired width was between the minimum sizes of these types, @@ -1023,33 +1023,33 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { // *selected_width = 4, which results in a total width of 11.5. Instead, we // want to set *unselected_width = 2, *selected_width = 4, for a total width // of 10. - if (numberOfNonMiniTabs > 1 && nonMiniTabWidth < kMinActiveTabWidth) { - nonMiniTabWidth = (availableSpaceForNonMini - kMinActiveTabWidth) / - (numberOfNonMiniTabs - 1) + + if (numberOfNonPinnedTabs > 1 && nonPinnedTabWidth < kMinActiveTabWidth) { + nonPinnedTabWidth = (availableSpaceForNonPinned - kMinActiveTabWidth) / + (numberOfNonPinnedTabs - 1) + kTabOverlap; - if (nonMiniTabWidth < kMinTabWidth) { + if (nonPinnedTabWidth < kMinTabWidth) { // The above adjustment caused the tabs to not fit, show 1 less tab. - --numberOfNonMiniTabs; - nonMiniTabWidth = - ((availableSpaceForNonMini - kTabOverlap) / numberOfNonMiniTabs) + - kTabOverlap; + --numberOfNonPinnedTabs; + nonPinnedTabWidth = ((availableSpaceForNonPinned - kTabOverlap) / + numberOfNonPinnedTabs) + + kTabOverlap; } } // Separate integral and fractional parts. - CGFloat integralPart = std::floor(nonMiniTabWidth); - nonMiniTabWidthFraction = nonMiniTabWidth - integralPart; - nonMiniTabWidth = integralPart; + CGFloat integralPart = std::floor(nonPinnedTabWidth); + nonPinnedTabWidthFraction = nonPinnedTabWidth - integralPart; + nonPinnedTabWidth = integralPart; } BOOL visible = [[tabStripView_ window] isVisible]; CGFloat offset = [self leftIndentForControls]; bool hasPlaceholderGap = false; - // Whether or not the last tab processed by the loop was a mini tab. - BOOL isLastTabMini = NO; + // Whether or not the last tab processed by the loop was a pinned tab. + BOOL isLastTabPinned = NO; CGFloat tabWidthAccumulatedFraction = 0; - NSInteger laidOutNonMiniTabs = 0; + NSInteger laidOutNonPinnedTabs = 0; for (TabController* tab in tabArray_.get()) { // Ignore a tab that is going through a close animation. @@ -1098,17 +1098,17 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { // Set the width. Selected tabs are slightly wider when things get really // small and thus we enforce a different minimum width. - BOOL isMini = [tab mini]; - if (isMini) { - tabFrame.size.width = [tab app] ? kAppTabWidth : kMiniTabWidth; + BOOL isPinned = [tab pinned]; + if (isPinned) { + tabFrame.size.width = kPinnedTabWidth; } else { // Tabs have non-integer widths. Assign the integer part to the tab, and // keep an accumulation of the fractional parts. When the fractional // accumulation gets to be more than one pixel, assign that to the current // tab being laid out. This is vaguely inspired by Bresenham's line // algorithm. - tabFrame.size.width = nonMiniTabWidth; - tabWidthAccumulatedFraction += nonMiniTabWidthFraction; + tabFrame.size.width = nonPinnedTabWidth; + tabWidthAccumulatedFraction += nonPinnedTabWidthFraction; if (tabWidthAccumulatedFraction >= 1.0) { ++tabFrame.size.width; @@ -1116,26 +1116,26 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { } // In case of rounding error, give any left over pixels to the last tab. - if (laidOutNonMiniTabs == numberOfNonMiniTabs - 1 && + if (laidOutNonPinnedTabs == numberOfNonPinnedTabs - 1 && tabWidthAccumulatedFraction > 0.5) { ++tabFrame.size.width; } - ++laidOutNonMiniTabs; + ++laidOutNonPinnedTabs; } if ([tab active]) tabFrame.size.width = MAX(tabFrame.size.width, kMinActiveTabWidth); - // If this is the first non-mini tab, then add a bit of spacing between this - // and the last mini tab. - if (!isMini && isLastTabMini) { - offset += kLastMiniTabSpacing; + // If this is the first non-pinned tab, then add a bit of spacing between + // this and the last pinned tab. + if (!isPinned && isLastTabPinned) { + offset += kLastPinnedTabSpacing; tabFrame.origin.x = offset; } - isLastTabMini = isMini; + isLastTabPinned = isPinned; - if (laidOutNonMiniTabs > numberOfNonMiniTabs) { + if (laidOutNonPinnedTabs > numberOfNonPinnedTabs) { // There is not enough space to fit this tab. tabFrame.size.width = 0; [self setFrame:tabFrame ofTabView:[tab view]]; @@ -1268,9 +1268,7 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { // Make a new tab and add it to the strip. Keep track of its controller. TabController* newController = [self newTab]; - [newController setMini:tabStripModel_->IsMiniTab(modelIndex)]; [newController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; - [newController setApp:tabStripModel_->IsAppTab(modelIndex)]; [newController setUrl:contents->GetURL()]; [tabArray_ insertObject:newController atIndex:index]; NSView* newView = [newController view]; @@ -1557,7 +1555,7 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { bool oldHasIcon = [tabController iconView] != nil; bool newHasIcon = favicon::ShouldDisplayFavicon(contents) || - tabStripModel_->IsMiniTab(modelIndex); // Always show icon if mini. + tabStripModel_->IsTabPinned(modelIndex); // Always show icon if pinned. TabLoadingState oldState = [tabController loadingState]; TabLoadingState newState = kTabDone; @@ -1654,15 +1652,15 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { [tabArray_ removeObjectAtIndex:from]; [tabArray_ insertObject:movedTabController.get() atIndex:to]; - // The tab moved, which means that the mini-tab state may have changed. - if (tabStripModel_->IsMiniTab(modelTo) != [movedTabController mini]) - [self tabMiniStateChangedWithContents:contents atIndex:modelTo]; + // The tab moved, which means that the pinned tab state may have changed. + if (tabStripModel_->IsTabPinned(modelTo) != [movedTabController pinned]) + [self tabPinnedStateChangedWithContents:contents atIndex:modelTo]; [self layoutTabs]; } // Called when a tab is pinned or unpinned without moving. -- (void)tabMiniStateChangedWithContents:(content::WebContents*)contents +- (void)tabPinnedStateChangedWithContents:(content::WebContents*)contents atIndex:(NSInteger)modelIndex { // Take closing tabs into account. NSInteger index = [self indexFromModelIndex:modelIndex]; @@ -1671,15 +1669,13 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { DCHECK([tabController isKindOfClass:[TabController class]]); // Don't do anything if the change was already picked up by the move event. - if (tabStripModel_->IsMiniTab(modelIndex) == [tabController mini]) + if (tabStripModel_->IsTabPinned(modelIndex) == [tabController pinned]) return; - [tabController setMini:tabStripModel_->IsMiniTab(modelIndex)]; [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; - [tabController setApp:tabStripModel_->IsAppTab(modelIndex)]; [tabController setUrl:contents->GetURL()]; [self updateIconsForContents:contents atIndex:modelIndex]; - // If the tab is being restored and it's pinned, the mini state is set after + // If the tab is being restored and it's pinned, the pinned state is set after // the tab has already been rendered, so re-layout the tabstrip. In all other // cases, the state is set before the tab is rendered so this isn't needed. [self layoutTabs]; @@ -1765,8 +1761,8 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { // represents where the user dropped the new tab so it can be animated into its // correct location when the tab is added to the model. If the tab was pinned in // its previous window, setting |pinned| to YES will propagate that state to the -// new window. Mini-tabs are either app or pinned tabs; the app state is stored -// by the |contents|, but the |pinned| state is the caller's responsibility. +// new window. Pinned tabs are pinned tabs; the |pinned| state is the caller's +// responsibility. - (void)dropWebContents:(WebContents*)contents atIndex:(int)modelIndex withFrame:(NSRect)frame @@ -2206,7 +2202,7 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { // Add the traffic light buttons. The horizontal layout was determined by // manual inspection on Yosemite. CGFloat closeButtonX = 11; - CGFloat miniButtonX = 31; + CGFloat pinnedButtonX = 31; CGFloat zoomButtonX = 51; NSUInteger styleMask = [[tabStripView_ window] styleMask]; @@ -2221,7 +2217,7 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { NSButton* miniaturizeButton = [NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:styleMask]; - [miniaturizeButton setFrameOrigin:NSMakePoint(miniButtonX, buttonY)]; + [miniaturizeButton setFrameOrigin:NSMakePoint(pinnedButtonX, buttonY)]; [miniaturizeButton setEnabled:NO]; [customWindowControls_ addSubview:miniaturizeButton]; diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h b/chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h index dd9e396..d524416 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h @@ -51,7 +51,8 @@ class TabStripModelObserverBridge : public TabStripModelObserver { content::WebContents* old_contents, content::WebContents* new_contents, int index) override; - void TabMiniStateChanged(content::WebContents* contents, int index) override; + void TabPinnedStateChanged(content::WebContents* contents, + int index) override; void TabStripEmpty() override; void TabStripModelDeleted() override; @@ -85,8 +86,8 @@ class TabStripModelObserverBridge : public TabStripModelObserver { - (void)tabReplacedWithContents:(content::WebContents*)newContents previousContents:(content::WebContents*)oldContents atIndex:(NSInteger)index; -- (void)tabMiniStateChangedWithContents:(content::WebContents*)contents - atIndex:(NSInteger)index; +- (void)tabPinnedStateChangedWithContents:(content::WebContents*)contents + atIndex:(NSInteger)index; - (void)tabStripEmpty; - (void)tabStripModelDeleted; - (void)tabSelectionChanged; diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.mm index 084a1d4..248862c 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.mm +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.mm @@ -112,12 +112,12 @@ void TabStripModelObserverBridge::TabReplacedAt(TabStripModel* tab_strip_model, } } -void TabStripModelObserverBridge::TabMiniStateChanged(WebContents* contents, - int index) { +void TabStripModelObserverBridge::TabPinnedStateChanged(WebContents* contents, + int index) { if ([controller_ respondsToSelector: - @selector(tabMiniStateChangedWithContents:atIndex:)]) { - [controller_ tabMiniStateChangedWithContents:contents - atIndex:index]; + @selector(tabPinnedStateChangedWithContents:atIndex:)]) { + [controller_ tabPinnedStateChangedWithContents:contents + atIndex:index]; } } diff --git a/chrome/browser/ui/startup/startup_browser_creator_impl.cc b/chrome/browser/ui/startup/startup_browser_creator_impl.cc index 355fbe3..f334df7 100644 --- a/chrome/browser/ui/startup/startup_browser_creator_impl.cc +++ b/chrome/browser/ui/startup/startup_browser_creator_impl.cc @@ -785,7 +785,6 @@ Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser( ui::PAGE_TRANSITION_AUTO_TOPLEVEL); params.disposition = first_tab ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; params.tabstrip_add_types = add_types; - params.extension_app_id = tabs[i].app_id; #if defined(ENABLE_RLZ) && !defined(OS_IOS) if (process_startup && google_util::IsGoogleHomePageUrl(tabs[i].url)) { diff --git a/chrome/browser/ui/startup/startup_tab.cc b/chrome/browser/ui/startup/startup_tab.cc index 0249ba30..cda2d94 100644 --- a/chrome/browser/ui/startup/startup_tab.cc +++ b/chrome/browser/ui/startup/startup_tab.cc @@ -5,8 +5,7 @@ #include "chrome/browser/ui/startup/startup_tab.h" StartupTab::StartupTab() - : is_app(false), - is_pinned(true) { + : is_pinned(true) { } StartupTab::~StartupTab() { diff --git a/chrome/browser/ui/startup/startup_tab.h b/chrome/browser/ui/startup/startup_tab.h index c948725..26bab7c 100644 --- a/chrome/browser/ui/startup/startup_tab.h +++ b/chrome/browser/ui/startup/startup_tab.h @@ -18,15 +18,8 @@ struct StartupTab { // The url to load. GURL url; - // If true, the tab corresponds to an app an |app_id| gives the id of the - // app. - bool is_app; - // True if the is tab pinned. bool is_pinned; - - // Id of the app. - std::string app_id; }; typedef std::vector<StartupTab> StartupTabs; diff --git a/chrome/browser/ui/tabs/pinned_tab_codec.cc b/chrome/browser/ui/tabs/pinned_tab_codec.cc index af46b1d..4141698 100644 --- a/chrome/browser/ui/tabs/pinned_tab_codec.cc +++ b/chrome/browser/ui/tabs/pinned_tab_codec.cc @@ -22,9 +22,6 @@ using content::NavigationEntry; -// Key used in dictionaries for the app id. -static const char kAppID[] = "app_id"; - // Key used in dictionaries for the url. static const char kURL[] = "url"; @@ -42,8 +39,6 @@ static bool HasPinnedTabs(Browser* browser) { static void EncodeTab(const StartupTab& tab, base::ListValue* values) { scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); value->SetString(kURL, tab.url.spec()); - if (tab.is_app) - value->SetString(kAppID, tab.app_id); values->Append(value.release()); } @@ -55,25 +50,12 @@ static void EncodePinnedTab(TabStripModel* model, scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); content::WebContents* web_contents = model->GetWebContentsAt(index); - if (model->IsAppTab(index)) { - const extensions::Extension* extension = - extensions::TabHelper::FromWebContents(web_contents)->extension_app(); - DCHECK(extension); - value->SetString(kAppID, extension->id()); - // For apps we use the launch url. We do this because the user is - // effectively restarting the app, so returning them to the app's launch - // page seems closest to what they expect. - value->SetString( - kURL, extensions::AppLaunchInfo::GetFullLaunchURL(extension).spec()); + NavigationEntry* entry = web_contents->GetController().GetActiveEntry(); + if (!entry && web_contents->GetController().GetEntryCount()) + entry = web_contents->GetController().GetEntryAtIndex(0); + if (entry) { + value->SetString(kURL, entry->GetURL().spec()); values->Append(value.release()); - } else { - NavigationEntry* entry = web_contents->GetController().GetActiveEntry(); - if (!entry && web_contents->GetController().GetEntryCount()) - entry = web_contents->GetController().GetEntryAtIndex(0); - if (entry) { - value->SetString(kURL, entry->GetURL().spec()); - values->Append(value.release()); - } } } @@ -87,16 +69,11 @@ static void EncodePinnedTabs(Browser* browser, base::ListValue* values) { // Decodes the previously written values in |value| to |tab|, returning true // on success. static bool DecodeTab(const base::DictionaryValue& value, StartupTab* tab) { - tab->is_app = false; - std::string url_string; if (!value.GetString(kURL, &url_string)) return false; tab->url = GURL(url_string); - if (value.GetString(kAppID, &(tab->app_id))) - tab->is_app = true; - return true; } diff --git a/chrome/browser/ui/tabs/pinned_tab_codec_unittest.cc b/chrome/browser/ui/tabs/pinned_tab_codec_unittest.cc index 39c28a9..3212c99 100644 --- a/chrome/browser/ui/tabs/pinned_tab_codec_unittest.cc +++ b/chrome/browser/ui/tabs/pinned_tab_codec_unittest.cc @@ -45,7 +45,7 @@ TEST_F(PinnedTabCodecTest, PinnedAndNonPinned) { StartupTabs pinned_tabs = PinnedTabCodec::ReadPinnedTabs(profile()); std::string result = PinnedTabTestUtils::TabsToString(pinned_tabs); - EXPECT_EQ("http://www.google.com/::pinned:", result); + EXPECT_EQ("http://www.google.com/:pinned", result); // Update pinned tabs and restore back the old value directly. browser()->tab_strip_model()->SetTabPinned(1, true); @@ -53,11 +53,11 @@ TEST_F(PinnedTabCodecTest, PinnedAndNonPinned) { PinnedTabCodec::WritePinnedTabs(profile()); result = PinnedTabTestUtils::TabsToString( PinnedTabCodec::ReadPinnedTabs(profile())); - EXPECT_EQ("http://www.google.com/::pinned: http://www.google.com/2::pinned:", + EXPECT_EQ("http://www.google.com/:pinned http://www.google.com/2:pinned", result); PinnedTabCodec::WritePinnedTabs(profile(), pinned_tabs); result = PinnedTabTestUtils::TabsToString( PinnedTabCodec::ReadPinnedTabs(profile())); - EXPECT_EQ("http://www.google.com/::pinned:", result); + EXPECT_EQ("http://www.google.com/:pinned", result); } diff --git a/chrome/browser/ui/tabs/pinned_tab_service_unittest.cc b/chrome/browser/ui/tabs/pinned_tab_service_unittest.cc index 00f4c16..29057b7 100644 --- a/chrome/browser/ui/tabs/pinned_tab_service_unittest.cc +++ b/chrome/browser/ui/tabs/pinned_tab_service_unittest.cc @@ -63,7 +63,7 @@ TEST_F(PinnedTabServiceTest, Popup) { std::string result = PinnedTabTestUtils::TabsToString( PinnedTabCodec::ReadPinnedTabs(profile())); - EXPECT_EQ("http://www.google.com/::pinned:", result); + EXPECT_EQ("http://www.google.com/:pinned", result); // Close the popup. This shouldn't reset the saved state. popup->tab_strip_model()->CloseAllTabs(); @@ -72,7 +72,7 @@ TEST_F(PinnedTabServiceTest, Popup) { // Check the state to make sure it hasn't changed. result = PinnedTabTestUtils::TabsToString( PinnedTabCodec::ReadPinnedTabs(profile())); - EXPECT_EQ("http://www.google.com/::pinned:", result); + EXPECT_EQ("http://www.google.com/:pinned", result); } } // namespace diff --git a/chrome/browser/ui/tabs/pinned_tab_test_utils.cc b/chrome/browser/ui/tabs/pinned_tab_test_utils.cc index 0a42256..7d407f5 100644 --- a/chrome/browser/ui/tabs/pinned_tab_test_utils.cc +++ b/chrome/browser/ui/tabs/pinned_tab_test_utils.cc @@ -7,8 +7,7 @@ namespace { std::string TabToString(const StartupTab& tab) { - return tab.url.spec() + ":" + (tab.is_app ? "app" : "") + ":" + - (tab.is_pinned ? "pinned" : "") + ":" + tab.app_id; + return tab.url.spec() + ":" + (tab.is_pinned ? "pinned" : ""); } } // namespace diff --git a/chrome/browser/ui/tabs/tab_strip_model.cc b/chrome/browser/ui/tabs/tab_strip_model.cc index 7a751ee..b309b7d 100644 --- a/chrome/browser/ui/tabs/tab_strip_model.cc +++ b/chrome/browser/ui/tabs/tab_strip_model.cc @@ -277,11 +277,8 @@ void TabStripModel::InsertWebContentsAt(int index, int add_types) { delegate_->WillAddWebContents(contents); - bool active = add_types & ADD_ACTIVE; - // Force app tabs to be pinned. - extensions::TabHelper* extensions_tab_helper = - extensions::TabHelper::FromWebContents(contents); - bool pin = extensions_tab_helper->is_app() || add_types & ADD_PINNED; + bool active = (add_types & ADD_ACTIVE) != 0; + bool pin = (add_types & ADD_PINNED) != 0; index = ConstrainInsertionIndex(index, pin); // In tab dragging situations, if the last tab in the window was detached @@ -466,11 +463,11 @@ void TabStripModel::MoveWebContentsAt(int index, if (index == to_position) return; - int first_non_mini_tab = IndexOfFirstNonMiniTab(); - if ((index < first_non_mini_tab && to_position >= first_non_mini_tab) || - (to_position < first_non_mini_tab && index >= first_non_mini_tab)) { - // This would result in mini tabs mixed with non-mini tabs. We don't allow - // that. + int first_non_pinned_tab = IndexOfFirstNonPinnedTab(); + if ((index < first_non_pinned_tab && to_position >= first_non_pinned_tab) || + (to_position < first_non_pinned_tab && index >= first_non_pinned_tab)) { + // This would result in pinned tabs mixed with non-pinned tabs. We don't + // allow that. return; } @@ -478,36 +475,36 @@ void TabStripModel::MoveWebContentsAt(int index, } void TabStripModel::MoveSelectedTabsTo(int index) { - int total_mini_count = IndexOfFirstNonMiniTab(); - int selected_mini_count = 0; + int total_pinned_count = IndexOfFirstNonPinnedTab(); + int selected_pinned_count = 0; int selected_count = static_cast<int>(selection_model_.selected_indices().size()); for (int i = 0; i < selected_count && - IsMiniTab(selection_model_.selected_indices()[i]); ++i) { - selected_mini_count++; + IsTabPinned(selection_model_.selected_indices()[i]); ++i) { + selected_pinned_count++; } - // To maintain that all mini-tabs occur before non-mini-tabs we move them + // To maintain that all pinned tabs occur before non-pinned tabs we move them // first. - if (selected_mini_count > 0) { + if (selected_pinned_count > 0) { MoveSelectedTabsToImpl( - std::min(total_mini_count - selected_mini_count, index), 0u, - selected_mini_count); - if (index > total_mini_count - selected_mini_count) { - // We're being told to drag mini-tabs to an invalid location. Adjust the - // index such that non-mini-tabs end up at a location as though we could - // move the mini-tabs to index. See description in header for more + std::min(total_pinned_count - selected_pinned_count, index), 0u, + selected_pinned_count); + if (index > total_pinned_count - selected_pinned_count) { + // We're being told to drag pinned tabs to an invalid location. Adjust the + // index such that non-pinned tabs end up at a location as though we could + // move the pinned tabs to index. See description in header for more // details. - index += selected_mini_count; + index += selected_pinned_count; } } - if (selected_mini_count == selected_count) + if (selected_pinned_count == selected_count) return; // Then move the non-pinned tabs. - MoveSelectedTabsToImpl(std::max(index, total_mini_count), - selected_mini_count, - selected_count - selected_mini_count); + MoveSelectedTabsToImpl(std::max(index, total_pinned_count), + selected_pinned_count, + selected_count - selected_pinned_count); } WebContents* TabStripModel::GetActiveWebContents() const { @@ -677,34 +674,17 @@ void TabStripModel::SetTabPinned(int index, bool pinned) { if (contents_data_[index]->pinned() == pinned) return; - if (IsAppTab(index)) { - if (!pinned) { - // App tabs should always be pinned. - NOTREACHED(); - return; - } - // Changing the pinned state of an app tab doesn't affect its mini-tab - // status. - contents_data_[index]->set_pinned(pinned); - } else { - // The tab is not an app tab, its position may have to change as the - // mini-tab state is changing. - int non_mini_tab_index = IndexOfFirstNonMiniTab(); - contents_data_[index]->set_pinned(pinned); - if (pinned && index != non_mini_tab_index) { - MoveWebContentsAtImpl(index, non_mini_tab_index, false); - index = non_mini_tab_index; - } else if (!pinned && index + 1 != non_mini_tab_index) { - MoveWebContentsAtImpl(index, non_mini_tab_index - 1, false); - index = non_mini_tab_index - 1; - } - - FOR_EACH_OBSERVER(TabStripModelObserver, observers_, - TabMiniStateChanged(contents_data_[index]->web_contents(), - index)); + // The tab's position may have to change as the pinned tab state is changing. + int non_pinned_tab_index = IndexOfFirstNonPinnedTab(); + contents_data_[index]->set_pinned(pinned); + if (pinned && index != non_pinned_tab_index) { + MoveWebContentsAtImpl(index, non_pinned_tab_index, false); + index = non_pinned_tab_index; + } else if (!pinned && index + 1 != non_pinned_tab_index) { + MoveWebContentsAtImpl(index, non_pinned_tab_index - 1, false); + index = non_pinned_tab_index - 1; } - // else: the tab was at the boundary and its position doesn't need to change. FOR_EACH_OBSERVER(TabStripModelObserver, observers_, TabPinnedStateChanged(contents_data_[index]->web_contents(), index)); @@ -715,15 +695,6 @@ bool TabStripModel::IsTabPinned(int index) const { return contents_data_[index]->pinned(); } -bool TabStripModel::IsMiniTab(int index) const { - return IsTabPinned(index) || IsAppTab(index); -} - -bool TabStripModel::IsAppTab(int index) const { - WebContents* contents = GetWebContentsAt(index); - return contents && extensions::TabHelper::FromWebContents(contents)->is_app(); -} - bool TabStripModel::IsTabBlocked(int index) const { return contents_data_[index]->blocked(); } @@ -732,18 +703,18 @@ bool TabStripModel::IsTabDiscarded(int index) const { return contents_data_[index]->discarded(); } -int TabStripModel::IndexOfFirstNonMiniTab() const { +int TabStripModel::IndexOfFirstNonPinnedTab() const { for (size_t i = 0; i < contents_data_.size(); ++i) { - if (!IsMiniTab(static_cast<int>(i))) + if (!IsTabPinned(static_cast<int>(i))) return static_cast<int>(i); } - // No mini-tabs. + // No pinned tabs. return count(); } -int TabStripModel::ConstrainInsertionIndex(int index, bool mini_tab) { - return mini_tab ? std::min(std::max(0, index), IndexOfFirstNonMiniTab()) : - std::min(count(), std::max(index, IndexOfFirstNonMiniTab())); +int TabStripModel::ConstrainInsertionIndex(int index, bool pinned_tab) { + return pinned_tab ? std::min(std::max(0, index), IndexOfFirstNonPinnedTab()) : + std::min(count(), std::max(index, IndexOfFirstNonPinnedTab())); } void TabStripModel::ExtendSelectionTo(int index) { @@ -924,15 +895,6 @@ bool TabStripModel::IsContextMenuCommandEnabled( return delegate_->GetRestoreTabType() != TabStripModelDelegate::RESTORE_NONE; - case CommandTogglePinned: { - std::vector<int> indices = GetIndicesForCommand(context_index); - for (size_t i = 0; i < indices.size(); ++i) { - if (!IsAppTab(indices[i])) - return true; - } - return false; - } - case CommandToggleTabAudioMuted: { std::vector<int> indices = GetIndicesForCommand(context_index); for (size_t i = 0; i < indices.size(); ++i) { @@ -946,6 +908,7 @@ bool TabStripModel::IsContextMenuCommandEnabled( return browser_defaults::bookmarks_enabled && delegate_->CanBookmarkAllTabs(); + case CommandTogglePinned: case CommandSelectByDomain: case CommandSelectByOpener: return true; @@ -1034,17 +997,13 @@ void TabStripModel::ExecuteContextMenuCommand( std::vector<int> indices = GetIndicesForCommand(context_index); bool pin = WillContextMenuPin(context_index); if (pin) { - for (size_t i = 0; i < indices.size(); ++i) { - if (!IsAppTab(indices[i])) - SetTabPinned(indices[i], true); - } + for (size_t i = 0; i < indices.size(); ++i) + SetTabPinned(indices[i], true); } else { // Unpin from the back so that the order is maintained (unpinning can // trigger moving a tab). - for (size_t i = indices.size(); i > 0; --i) { - if (!IsAppTab(indices[i - 1])) - SetTabPinned(indices[i - 1], false); - } + for (size_t i = indices.size(); i > 0; --i) + SetTabPinned(indices[i - 1], false); } break; } @@ -1112,7 +1071,7 @@ std::vector<int> TabStripModel::GetIndicesClosedByCommand( // NOTE: callers expect the vector to be sorted in descending order. std::vector<int> indices; for (int i = count() - 1; i >= start; --i) { - if (i != index && !IsMiniTab(i) && (!is_selected || !IsTabSelected(i))) + if (i != index && !IsTabPinned(i) && (!is_selected || !IsTabSelected(i))) indices.push_back(i); } return indices; @@ -1122,10 +1081,8 @@ bool TabStripModel::WillContextMenuPin(int index) { std::vector<int> indices = GetIndicesForCommand(index); // If all tabs are pinned, then we unpin, otherwise we pin. bool all_pinned = true; - for (size_t i = 0; i < indices.size() && all_pinned; ++i) { - if (!IsAppTab(index)) // We never change app tabs. - all_pinned = IsTabPinned(indices[i]); - } + for (size_t i = 0; i < indices.size() && all_pinned; ++i) + all_pinned = IsTabPinned(indices[i]); return !all_pinned; } diff --git a/chrome/browser/ui/tabs/tab_strip_model.h b/chrome/browser/ui/tabs/tab_strip_model.h index dd45922..9059f30 100644 --- a/chrome/browser/ui/tabs/tab_strip_model.h +++ b/chrome/browser/ui/tabs/tab_strip_model.h @@ -25,36 +25,28 @@ class WebContents; // // TabStripModel // -// A model & low level controller of a Browser Window tabstrip. Holds a vector -// of WebContentses, and provides an API for adding, removing and -// shuffling them, as well as a higher level API for doing specific Browser- -// related tasks like adding new Tabs from just a URL, etc. +// A model & low level controller of a Browser Window tabstrip. Holds a vector +// of WebContentses, and provides an API for adding, removing and +// shuffling them, as well as a higher level API for doing specific Browser- +// related tasks like adding new Tabs from just a URL, etc. // -// Each tab may be any one of the following states: -// . Mini-tab. Mini tabs are locked to the left side of the tab strip and -// rendered differently (small tabs with only a favicon). The model makes -// sure all mini-tabs are at the beginning of the tab strip. For example, -// if a non-mini tab is added it is forced to be with non-mini tabs. Requests -// to move tabs outside the range of the tab type are ignored. For example, -// a request to move a mini-tab after non-mini-tabs is ignored. -// You'll notice there is no explicit api for making a tab a mini-tab, rather -// there are two tab types that are implicitly mini-tabs: -// . App. Corresponds to an extension that wants an app tab. App tabs are -// identified by extensions::TabHelper::is_app(). -// App tabs are always pinned (you can't unpin them). -// . Pinned. Any tab can be pinned. Non-app tabs whose pinned state is changed -// are moved to be with other mini-tabs or non-mini tabs. +// Each tab may be pinned. Pinned tabs are locked to the left side of the tab +// strip and rendered differently (small tabs with only a favicon). The model +// makes sure all pinned tabs are at the beginning of the tab strip. For +// example, if a non-pinned tab is added it is forced to be with non-pinned +// tabs. Requests to move tabs outside the range of the tab type are ignored. +// For example, a request to move a pinned tab after non-pinned tabs is ignored. // -// A TabStripModel has one delegate that it relies on to perform certain tasks -// like creating new TabStripModels (probably hosted in Browser windows) when -// required. See TabStripDelegate above for more information. +// A TabStripModel has one delegate that it relies on to perform certain tasks +// like creating new TabStripModels (probably hosted in Browser windows) when +// required. See TabStripDelegate above for more information. // -// A TabStripModel also has N observers (see TabStripModelObserver above), -// which can be registered via Add/RemoveObserver. An Observer is notified of -// tab creations, removals, moves, and other interesting events. The -// TabStrip implements this interface to know when to create new tabs in -// the View, and the Browser object likewise implements to be able to update -// its bookkeeping when such events happen. +// A TabStripModel also has N observers (see TabStripModelObserver above), +// which can be registered via Add/RemoveObserver. An Observer is notified of +// tab creations, removals, moves, and other interesting events. The +// TabStrip implements this interface to know when to create new tabs in +// the View, and the Browser object likewise implements to be able to update +// its bookkeeping when such events happen. // //////////////////////////////////////////////////////////////////////////////// class TabStripModel { @@ -171,7 +163,7 @@ class TabStripModel { // NOTE: adding a tab using this method does NOT query the order controller, // as such the ADD_FORCE_INDEX AddTabTypes is meaningless here. The only time // the |index| is changed is if using the index would result in breaking the - // constraint that all mini-tabs occur before non-mini-tabs. + // constraint that all pinned tabs occur before non-pinned tabs. // See also AddWebContents. void InsertWebContentsAt(int index, content::WebContents* contents, @@ -220,26 +212,24 @@ class TabStripModel { // If |select_after_move| is false, whatever tab was selected before the move // will still be selected, but its index may have incremented or decremented // one slot. - // NOTE: This respects basic ordering constraints and thus does nothing if the - // move would result in app tabs and non-app tabs mixing. void MoveWebContentsAt(int index, int to_position, bool select_after_move); // Moves the selected tabs to |index|. |index| is treated as if the tab strip // did not contain any of the selected tabs. For example, if the tabstrip // contains [A b c D E f] (upper case selected) and this is invoked with 1 the // result is [b A D E c f]. - // This method maintains that all mini-tabs occur before non-mini-tabs. When - // mini-tabs are selected the move is processed in two chunks: first mini-tabs - // are moved, then non-mini-tabs are moved. If the index is after - // (mini-tab-count - selected-mini-tab-count), then the index the non-mini - // selected tabs are moved to is (index + selected-mini-tab-count). For - // example, if the model consists of [A b c D E f] (A b c are mini) and this - // is invoked with 2, the result is [b c A D E f]. In this example nothing - // special happened because the target index was <= (mini-tab-count - - // selected-mini-tab-count). If the target index were 3, then the result would - // be [b c A f D F]. A, being mini, can move no further than index 2. The - // non-mini-tabs are moved to the target index + selected-mini-tab-count (3 + - // 1) + // This method maintains that all pinned tabs occur before non-pinned tabs. + // When pinned tabs are selected the move is processed in two chunks: first + // pinned tabs are moved, then non-pinned tabs are moved. If the index is + // after (pinned-tab-count - selected-pinned-tab-count), then the index the + // non-pinned selected tabs are moved to is (index + + // selected-pinned-tab-count). For example, if the model consists of + // [A b c D E f] (A b c are pinned) and this is invoked with 2, the result is + // [b c A D E f]. In this example nothing special happened because the target + // index was <= (pinned-tab-count - selected-pinned-tab-count). If the target + // index were 3, then the result would be [b c A f D F]. A, being pinned, can + // move no further than index 2. The non-pinned tabs are moved to the target + // index + selected-pinned tab-count (3 + 1). void MoveSelectedTabsTo(int index); // Returns the currently active WebContents, or NULL if there is none. @@ -325,14 +315,6 @@ class TabStripModel { // See description above class for details on pinned tabs. bool IsTabPinned(int index) const; - // Is the tab a mini-tab? - // See description above class for details on this. - bool IsMiniTab(int index) const; - - // Is the tab at |index| an app? - // See description above class for details on app tabs. - bool IsAppTab(int index) const; - // Returns true if the tab at |index| is blocked by a tab modal dialog. bool IsTabBlocked(int index) const; @@ -340,17 +322,17 @@ class TabStripModel { // save memory. See DiscardWebContentsAt() for details. bool IsTabDiscarded(int index) const; - // Returns the index of the first tab that is not a mini-tab. This returns - // |count()| if all of the tabs are mini-tabs, and 0 if none of the tabs are - // mini-tabs. - int IndexOfFirstNonMiniTab() const; + // Returns the index of the first tab that is not a pinned tab. This returns + // |count()| if all of the tabs are pinned tabs, and 0 if none of the tabs are + // pinned tabs. + int IndexOfFirstNonPinnedTab() const; // Returns a valid index for inserting a new tab into this model. |index| is - // the proposed index and |mini_tab| is true if inserting a tab will become - // mini (pinned or app). If |mini_tab| is true, the returned index is between - // 0 and IndexOfFirstNonMiniTab. If |mini_tab| is false, the returned index - // is between IndexOfFirstNonMiniTab and count(). - int ConstrainInsertionIndex(int index, bool mini_tab); + // the proposed index and |pinned_tab| is true if inserting a tab will become + // pinned (pinned). If |pinned_tab| is true, the returned index is between 0 + // and IndexOfFirstNonPinnedTab. If |pinned_tab| is false, the returned index + // is between IndexOfFirstNonPinnedTab and count(). + int ConstrainInsertionIndex(int index, bool pinned_tab); // Extends the selection from the anchor to |index|. void ExtendSelectionTo(int index); diff --git a/chrome/browser/ui/tabs/tab_strip_model_observer.cc b/chrome/browser/ui/tabs/tab_strip_model_observer.cc index 6b3911b..9fdf1a1 100644 --- a/chrome/browser/ui/tabs/tab_strip_model_observer.cc +++ b/chrome/browser/ui/tabs/tab_strip_model_observer.cc @@ -54,10 +54,6 @@ void TabStripModelObserver::TabPinnedStateChanged(WebContents* contents, int index) { } -void TabStripModelObserver::TabMiniStateChanged(WebContents* contents, - int index) { -} - void TabStripModelObserver::TabBlockedStateChanged(WebContents* contents, int index) { } diff --git a/chrome/browser/ui/tabs/tab_strip_model_observer.h b/chrome/browser/ui/tabs/tab_strip_model_observer.h index 210a2c0..8f84fe5 100644 --- a/chrome/browser/ui/tabs/tab_strip_model_observer.h +++ b/chrome/browser/ui/tabs/tab_strip_model_observer.h @@ -125,16 +125,9 @@ class TabStripModelObserver { content::WebContents* new_contents, int index); - // Invoked when the pinned state of a tab changes. See note in - // TabMiniStateChanged as to how this relates to TabMiniStateChanged. + // Invoked when the pinned state of a tab changes. virtual void TabPinnedStateChanged(content::WebContents* contents, int index); - // Invoked if the mini state of a tab changes. - // NOTE: This is sent when the pinned state of a non-app tab changes and is - // sent in addition to TabPinnedStateChanged. UI code typically need not care - // about TabPinnedStateChanged, but instead this. - virtual void TabMiniStateChanged(content::WebContents* contents, int index); - // Invoked when the blocked state of a tab changes. // NOTE: This is invoked when a tab becomes blocked/unblocked by a tab modal // window. diff --git a/chrome/browser/ui/tabs/tab_strip_model_unittest.cc b/chrome/browser/ui/tabs/tab_strip_model_unittest.cc index da582a3..cc5323f 100644 --- a/chrome/browser/ui/tabs/tab_strip_model_unittest.cc +++ b/chrome/browser/ui/tabs/tab_strip_model_unittest.cc @@ -216,9 +216,6 @@ class TabStripModelTest : public ChromeRenderViewHostTestHarness { actual += base::IntToString(GetID(model.GetWebContentsAt(i))); - if (model.IsAppTab(i)) - actual += "a"; - if (model.IsTabPinned(i)) actual += "p"; } @@ -1911,138 +1908,6 @@ TEST_F(TabStripModelTest, MAYBE_FastShutdown) { } } -// Tests various permutations of apps. -TEST_F(TabStripModelTest, Apps) { - TabStripDummyDelegate delegate; - TabStripModel tabstrip(&delegate, profile()); - MockTabStripModelObserver observer(&tabstrip); - tabstrip.AddObserver(&observer); - - EXPECT_TRUE(tabstrip.empty()); - - typedef MockTabStripModelObserver::State State; - -#if defined(OS_WIN) - base::FilePath path(FILE_PATH_LITERAL("c:\\foo")); -#elif defined(OS_POSIX) - base::FilePath path(FILE_PATH_LITERAL("/foo")); -#endif - - base::DictionaryValue manifest; - manifest.SetString("name", "hi!"); - manifest.SetString("version", "1"); - manifest.SetString("app.launch.web_url", "http://www.google.com"); - std::string error; - scoped_refptr<Extension> extension_app( - Extension::Create(path, extensions::Manifest::INVALID_LOCATION, - manifest, Extension::NO_FLAGS, &error)); - WebContents* contents1 = CreateWebContentsWithID(1); - extensions::TabHelper::CreateForWebContents(contents1); - extensions::TabHelper::FromWebContents(contents1) - ->SetExtensionApp(extension_app.get()); - WebContents* contents2 = CreateWebContentsWithID(2); - extensions::TabHelper::CreateForWebContents(contents2); - extensions::TabHelper::FromWebContents(contents2) - ->SetExtensionApp(extension_app.get()); - WebContents* contents3 = CreateWebContentsWithID(3); - - // Note! The ordering of these tests is important, each subsequent test - // builds on the state established in the previous. This is important if you - // ever insert tests rather than append. - - // Initial state, tab3 only and selected. - tabstrip.AppendWebContents(contents3, true); - - observer.ClearStates(); - - // Attempt to insert tab1 (an app tab) at position 1. This isn't a legal - // position and tab1 should end up at position 0. - { - tabstrip.InsertWebContentsAt(1, contents1, TabStripModel::ADD_NONE); - - ASSERT_EQ(1, observer.GetStateCount()); - State state(contents1, 0, MockTabStripModelObserver::INSERT); - EXPECT_TRUE(observer.StateEquals(0, state)); - - // And verify the state. - EXPECT_EQ("1ap 3", GetTabStripStateString(tabstrip)); - - observer.ClearStates(); - } - - // Insert tab 2 at position 1. - { - tabstrip.InsertWebContentsAt(1, contents2, TabStripModel::ADD_NONE); - - ASSERT_EQ(1, observer.GetStateCount()); - State state(contents2, 1, MockTabStripModelObserver::INSERT); - EXPECT_TRUE(observer.StateEquals(0, state)); - - // And verify the state. - EXPECT_EQ("1ap 2ap 3", GetTabStripStateString(tabstrip)); - - observer.ClearStates(); - } - - // Try to move tab 3 to position 0. This isn't legal and should be ignored. - { - tabstrip.MoveWebContentsAt(2, 0, false); - - ASSERT_EQ(0, observer.GetStateCount()); - - // And verify the state didn't change. - EXPECT_EQ("1ap 2ap 3", GetTabStripStateString(tabstrip)); - - observer.ClearStates(); - } - - // Try to move tab 0 to position 3. This isn't legal and should be ignored. - { - tabstrip.MoveWebContentsAt(0, 2, false); - - ASSERT_EQ(0, observer.GetStateCount()); - - // And verify the state didn't change. - EXPECT_EQ("1ap 2ap 3", GetTabStripStateString(tabstrip)); - - observer.ClearStates(); - } - - // Try to move tab 0 to position 1. This is a legal move. - { - tabstrip.MoveWebContentsAt(0, 1, false); - - ASSERT_EQ(1, observer.GetStateCount()); - State state(contents1, 1, MockTabStripModelObserver::MOVE); - state.src_index = 0; - EXPECT_TRUE(observer.StateEquals(0, state)); - - // And verify the state didn't change. - EXPECT_EQ("2ap 1ap 3", GetTabStripStateString(tabstrip)); - - observer.ClearStates(); - } - - // Remove tab3 and insert at position 0. It should be forced to position 2. - { - tabstrip.DetachWebContentsAt(2); - observer.ClearStates(); - - tabstrip.InsertWebContentsAt(0, contents3, TabStripModel::ADD_NONE); - - ASSERT_EQ(1, observer.GetStateCount()); - State state(contents3, 2, MockTabStripModelObserver::INSERT); - EXPECT_TRUE(observer.StateEquals(0, state)); - - // And verify the state didn't change. - EXPECT_EQ("2ap 1ap 3", GetTabStripStateString(tabstrip)); - - observer.ClearStates(); - } - - tabstrip.CloseAllTabs(); -} - // Tests various permutations of pinning tabs. TEST_F(TabStripModelTest, Pinning) { TabStripDummyDelegate delegate; diff --git a/chrome/browser/ui/views/ash/tab_scrubber.cc b/chrome/browser/ui/views/ash/tab_scrubber.cc index 716e7cf..e26c5ab 100644 --- a/chrome/browser/ui/views/ash/tab_scrubber.cc +++ b/chrome/browser/ui/views/ash/tab_scrubber.cc @@ -39,7 +39,7 @@ gfx::Point TabScrubber::GetStartPoint( TabStrip* tab_strip, int index, TabScrubber::Direction direction) { - int initial_tab_offset = Tab::GetMiniWidth() / 2; + int initial_tab_offset = Tab::GetPinnedWidth() / 2; gfx::Rect tab_bounds = tab_strip->tab_at(index)->bounds(); float x = direction == LEFT ? tab_bounds.x() + initial_tab_offset : diff --git a/chrome/browser/ui/views/ash/tab_scrubber_browsertest.cc b/chrome/browser/ui/views/ash/tab_scrubber_browsertest.cc index 2290bd8..d48b57b 100644 --- a/chrome/browser/ui/views/ash/tab_scrubber_browsertest.cc +++ b/chrome/browser/ui/views/ash/tab_scrubber_browsertest.cc @@ -208,8 +208,6 @@ class TabScrubberTest : public InProcessBrowserTest, int index) override {} void TabPinnedStateChanged(content::WebContents* contents, int index) override {} - void TabMiniStateChanged(content::WebContents* contents, int index) override { - } void TabBlockedStateChanged(content::WebContents* contents, int index) override {} void TabStripEmpty() override {} diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc index 0e4bb70..961ebf4 100644 --- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc +++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc @@ -482,11 +482,6 @@ void BrowserTabStripController::TabReplacedAt(TabStripModel* tab_strip_model, void BrowserTabStripController::TabPinnedStateChanged(WebContents* contents, int model_index) { - // Currently none of the renderers render pinned state differently. -} - -void BrowserTabStripController::TabMiniStateChanged(WebContents* contents, - int model_index) { SetTabDataAt(contents, model_index); } @@ -510,8 +505,8 @@ void BrowserTabStripController::SetTabRendererDataFromModel( data->loading = contents->IsLoading(); data->crashed_status = contents->GetCrashedStatus(); data->incognito = contents->GetBrowserContext()->IsOffTheRecord(); - data->mini = model_->IsMiniTab(model_index); - data->show_icon = data->mini || favicon::ShouldDisplayFavicon(contents); + data->pinned = model_->IsTabPinned(model_index); + data->show_icon = data->pinned || favicon::ShouldDisplayFavicon(contents); data->blocked = model_->IsTabBlocked(model_index); data->app = extensions::TabHelper::FromWebContents(contents)->is_app(); data->media_state = chrome::GetTabMediaStateForContents(contents); diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h index 15d1621..db2f32d 100644 --- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h +++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h @@ -94,8 +94,6 @@ class BrowserTabStripController : public TabStripController, int model_index) override; void TabPinnedStateChanged(content::WebContents* contents, int model_index) override; - void TabMiniStateChanged(content::WebContents* contents, - int model_index) override; void TabBlockedStateChanged(content::WebContents* contents, int model_index) override; diff --git a/chrome/browser/ui/views/tabs/stacked_tab_strip_layout.cc b/chrome/browser/ui/views/tabs/stacked_tab_strip_layout.cc index 39da73e..150d403 100644 --- a/chrome/browser/ui/views/tabs/stacked_tab_strip_layout.cc +++ b/chrome/browser/ui/views/tabs/stacked_tab_strip_layout.cc @@ -24,8 +24,8 @@ StackedTabStripLayout::StackedTabStripLayout(const gfx::Size& size, view_model_(view_model), x_(0), width_(0), - mini_tab_count_(0), - mini_tab_to_non_mini_tab_(0), + pinned_tab_count_(0), + pinned_tab_to_non_pinned_tab_(0), active_index_(-1), first_tab_x_(0) { } @@ -33,17 +33,17 @@ StackedTabStripLayout::StackedTabStripLayout(const gfx::Size& size, StackedTabStripLayout::~StackedTabStripLayout() { } -void StackedTabStripLayout::SetXAndMiniCount(int x, int mini_tab_count) { +void StackedTabStripLayout::SetXAndPinnedCount(int x, int pinned_tab_count) { first_tab_x_ = x; x_ = x; - mini_tab_count_ = mini_tab_count; - mini_tab_to_non_mini_tab_ = 0; - if (!requires_stacking() || tab_count() == mini_tab_count) { + pinned_tab_count_ = pinned_tab_count; + pinned_tab_to_non_pinned_tab_ = 0; + if (!requires_stacking() || tab_count() == pinned_tab_count) { ResetToIdealState(); return; } - if (mini_tab_count > 0) { - mini_tab_to_non_mini_tab_ = x - ideal_x(mini_tab_count - 1); + if (pinned_tab_count > 0) { + pinned_tab_to_non_pinned_tab_ = x - ideal_x(pinned_tab_count - 1); first_tab_x_ = ideal_x(0); } SetIdealBoundsAt(active_index(), ConstrainActiveX(ideal_x(active_index()))); @@ -124,10 +124,10 @@ void StackedTabStripLayout::SizeToFit() { // to fill in space. int delta = ideal_x(0) - first_tab_x_; int i = 0; - for (; i < mini_tab_count_; ++i) { - gfx::Rect mini_bounds(view_model_->ideal_bounds(i)); - mini_bounds.set_x(ideal_x(i) - delta); - view_model_->set_ideal_bounds(i, mini_bounds); + for (; i < pinned_tab_count_; ++i) { + gfx::Rect pinned_bounds(view_model_->ideal_bounds(i)); + pinned_bounds.set_x(ideal_x(i) - delta); + view_model_->set_ideal_bounds(i, pinned_bounds); } for (; delta > 0 && i < tab_count() - 1; ++i) { const int exposed = tab_offset() - (ideal_x(i + 1) - ideal_x(i)); @@ -145,7 +145,7 @@ void StackedTabStripLayout::SizeToFit() { // Tabs have been dragged to the left. Pull in tabs from right to left to fill // in space. SetIdealBoundsAt(tab_count() - 1, max_x); - for (int i = tab_count() - 2; i > mini_tab_count_ && + for (int i = tab_count() - 2; i > pinned_tab_count_ && ideal_x(i + 1) - ideal_x(i) > tab_offset(); --i) { SetIdealBoundsAt(i, ideal_x(i + 1) - tab_offset()); } @@ -157,8 +157,8 @@ void StackedTabStripLayout::AddTab(int index, int add_types, int start_x) { active_index_ = index; else if (active_index_ >= index) active_index_++; - if (add_types & kAddTypeMini) - mini_tab_count_++; + if (add_types & kAddTypePinned) + pinned_tab_count_++; x_ = start_x; if (!requires_stacking() || normal_tab_count() <= 1) { ResetToIdealState(); @@ -180,10 +180,10 @@ void StackedTabStripLayout::RemoveTab(int index, int start_x, int old_x) { active_index_ = std::min(active_index_, tab_count() - 1); else if (index < active_index_) active_index_--; - bool removed_mini_tab = index < mini_tab_count_; - if (removed_mini_tab) { - mini_tab_count_--; - DCHECK_GE(mini_tab_count_, 0); + bool removed_pinned_tab = index < pinned_tab_count_; + if (removed_pinned_tab) { + pinned_tab_count_--; + DCHECK_GE(pinned_tab_count_, 0); } int delta = start_x - x_; x_ = start_x; @@ -191,8 +191,8 @@ void StackedTabStripLayout::RemoveTab(int index, int start_x, int old_x) { ResetToIdealState(); return; } - if (removed_mini_tab) { - for (int i = mini_tab_count_; i < tab_count(); ++i) + if (removed_pinned_tab) { + for (int i = pinned_tab_count_; i < tab_count(); ++i) SetIdealBoundsAt(i, ideal_x(i) + delta); } SetActiveBoundsAndLayoutFromActiveTab(); @@ -203,11 +203,11 @@ void StackedTabStripLayout::MoveTab(int from, int to, int new_active_index, int start_x, - int mini_tab_count) { + int pinned_tab_count) { x_ = start_x; - mini_tab_count_ = mini_tab_count; + pinned_tab_count_ = pinned_tab_count; active_index_ = new_active_index; - if (!requires_stacking() || tab_count() == mini_tab_count_) { + if (!requires_stacking() || tab_count() == pinned_tab_count_) { ResetToIdealState(); } else { SetIdealBoundsAt(active_index(), @@ -216,14 +216,14 @@ void StackedTabStripLayout::MoveTab(int from, LayoutByTabOffsetBefore(active_index()); AdjustStackedTabs(); } - mini_tab_to_non_mini_tab_ = mini_tab_count > 0 ? - start_x - ideal_x(mini_tab_count - 1) : 0; - first_tab_x_ = mini_tab_count > 0 ? ideal_x(0) : start_x; + pinned_tab_to_non_pinned_tab_ = pinned_tab_count > 0 ? + start_x - ideal_x(pinned_tab_count - 1) : 0; + first_tab_x_ = pinned_tab_count > 0 ? ideal_x(0) : start_x; } bool StackedTabStripLayout::IsStacked(int index) const { - if (index == active_index() || tab_count() == mini_tab_count_ || - index < mini_tab_count_) + if (index == active_index() || tab_count() == pinned_tab_count_ || + index < pinned_tab_count_) return false; if (index > active_index()) return ideal_x(index) != ideal_x(index - 1) + tab_offset(); @@ -235,7 +235,7 @@ void StackedTabStripLayout::SetActiveTabLocation(int x) { return; const int index = active_index(); - if (index <= mini_tab_count_) + if (index <= pinned_tab_count_) return; x = std::min(GetMaxX(index), std::max(x, GetMinX(index))); @@ -265,41 +265,41 @@ std::string StackedTabStripLayout::BoundsString() const { void StackedTabStripLayout::Reset(int x, int width, - int mini_tab_count, + int pinned_tab_count, int active_index) { x_ = x; width_ = width; - mini_tab_count_ = mini_tab_count; - mini_tab_to_non_mini_tab_ = mini_tab_count > 0 ? - x - ideal_x(mini_tab_count - 1) : 0; - first_tab_x_ = mini_tab_count > 0 ? ideal_x(0) : x; + pinned_tab_count_ = pinned_tab_count; + pinned_tab_to_non_pinned_tab_ = pinned_tab_count > 0 ? + x - ideal_x(pinned_tab_count - 1) : 0; + first_tab_x_ = pinned_tab_count > 0 ? ideal_x(0) : x; active_index_ = active_index; ResetToIdealState(); } void StackedTabStripLayout::ResetToIdealState() { - if (tab_count() == mini_tab_count_) + if (tab_count() == pinned_tab_count_) return; if (!requires_stacking()) { - SetIdealBoundsAt(mini_tab_count_, x_); - LayoutByTabOffsetAfter(mini_tab_count_); + SetIdealBoundsAt(pinned_tab_count_, x_); + LayoutByTabOffsetAfter(pinned_tab_count_); return; } if (normal_tab_count() == 1) { // TODO: might want to shrink the tab here. - SetIdealBoundsAt(mini_tab_count_, 0); + SetIdealBoundsAt(pinned_tab_count_, 0); return; } int available_width = width_ - x_; - int leading_count = active_index() - mini_tab_count_; + int leading_count = active_index() - pinned_tab_count_; int trailing_count = tab_count() - active_index(); if (width_for_count(leading_count + 1) + max_stacked_width() < available_width) { - SetIdealBoundsAt(mini_tab_count_, x_); - LayoutByTabOffsetAfter(mini_tab_count_); + SetIdealBoundsAt(pinned_tab_count_, x_); + LayoutByTabOffsetAfter(pinned_tab_count_); } else if (width_for_count(trailing_count) + max_stacked_width() < available_width) { SetIdealBoundsAt(tab_count() - 1, width_ - size_.width()); @@ -307,12 +307,13 @@ void StackedTabStripLayout::ResetToIdealState() { } else { int index = active_index(); do { - int stacked_padding = stacked_padding_for_count(index - mini_tab_count_); + int stacked_padding = + stacked_padding_for_count(index - pinned_tab_count_); SetIdealBoundsAt(index, x_ + stacked_padding); LayoutByTabOffsetAfter(index); LayoutByTabOffsetBefore(index); index--; - } while (index >= mini_tab_count_ && ideal_x(mini_tab_count_) != x_ && + } while (index >= pinned_tab_count_ && ideal_x(pinned_tab_count_) != x_ && ideal_x(tab_count() - 1) != width_ - size_.width()); } AdjustStackedTabs(); @@ -375,8 +376,8 @@ void StackedTabStripLayout::LayoutByTabOffsetAfter(int index) { } void StackedTabStripLayout::LayoutByTabOffsetBefore(int index) { - for (int i = index - 1; i >= mini_tab_count_; --i) { - int min_x = x_ + stacked_padding_for_count(i - mini_tab_count_); + for (int i = index - 1; i >= pinned_tab_count_; --i) { + int min_x = x_ + stacked_padding_for_count(i - pinned_tab_count_); int x = std::max(min_x, ideal_x(i + 1) - (tab_offset())); SetIdealBoundsAt(i, x); } @@ -393,9 +394,9 @@ void StackedTabStripLayout::LayoutUsingCurrentAfter(int index) { } void StackedTabStripLayout::LayoutUsingCurrentBefore(int index) { - for (int i = index - 1; i >= mini_tab_count_; --i) { - int max_x = x_ + width_for_count(i - mini_tab_count_); - if (i > mini_tab_count_) + for (int i = index - 1; i >= pinned_tab_count_; --i) { + int max_x = x_ + width_for_count(i - pinned_tab_count_); + if (i > pinned_tab_count_) max_x += padding_; max_x = std::min(max_x, ideal_x(i + 1) - stacked_padding_); SetIdealBoundsAt( @@ -410,7 +411,7 @@ void StackedTabStripLayout::PushTabsAfter(int index, int delta) { } void StackedTabStripLayout::PushTabsBefore(int index, int delta) { - for (int i = index - 1; i > mini_tab_count_; --i) + for (int i = index - 1; i > pinned_tab_count_; --i) SetIdealBoundsAt(i, std::max(ideal_x(i) - delta, GetMinDragX(i))); } @@ -424,30 +425,30 @@ void StackedTabStripLayout::LayoutForDragAfter(int index) { } void StackedTabStripLayout::LayoutForDragBefore(int index) { - for (int i = index - 1; i >= mini_tab_count_; --i) { + for (int i = index - 1; i >= pinned_tab_count_; --i) { const int max_x = ideal_x(i + 1) - stacked_padding_; const int min_x = ideal_x(i + 1) - tab_offset(); SetIdealBoundsAt( i, std::max(min_x, std::min(ideal_x(i), max_x))); } - if (mini_tab_count_ == 0) + if (pinned_tab_count_ == 0) return; - // Pull in the mini-tabs. - const int delta = (mini_tab_count_ > 1) ? ideal_x(1) - ideal_x(0) : 0; - for (int i = mini_tab_count_ - 1; i >= 0; --i) { - gfx::Rect mini_bounds(view_model_->ideal_bounds(i)); - if (i == mini_tab_count_ - 1) - mini_bounds.set_x(ideal_x(i + 1) - mini_tab_to_non_mini_tab_); + // Pull in the pinned tabs. + const int delta = (pinned_tab_count_ > 1) ? ideal_x(1) - ideal_x(0) : 0; + for (int i = pinned_tab_count_ - 1; i >= 0; --i) { + gfx::Rect pinned_bounds(view_model_->ideal_bounds(i)); + if (i == pinned_tab_count_ - 1) + pinned_bounds.set_x(ideal_x(i + 1) - pinned_tab_to_non_pinned_tab_); else - mini_bounds.set_x(ideal_x(i + 1) - delta); - view_model_->set_ideal_bounds(i, mini_bounds); + pinned_bounds.set_x(ideal_x(i + 1) - delta); + view_model_->set_ideal_bounds(i, pinned_bounds); } } void StackedTabStripLayout::ExpandTabsBefore(int index, int delta) { - for (int i = index - 1; i >= mini_tab_count_ && delta > 0; --i) { + for (int i = index - 1; i >= pinned_tab_count_ && delta > 0; --i) { const int max_x = ideal_x(active_index()) - stacked_padding_for_count(active_index() - i); int to_resize = std::min(delta, max_x - ideal_x(i)); @@ -477,7 +478,7 @@ void StackedTabStripLayout::ExpandTabsAfter(int index, int delta) { } void StackedTabStripLayout::AdjustStackedTabs() { - if (!requires_stacking() || tab_count() <= mini_tab_count_ + 1) + if (!requires_stacking() || tab_count() <= pinned_tab_count_ + 1) return; AdjustLeadingStackedTabs(); @@ -485,7 +486,7 @@ void StackedTabStripLayout::AdjustStackedTabs() { } void StackedTabStripLayout::AdjustLeadingStackedTabs() { - int index = mini_tab_count_ + 1; + int index = pinned_tab_count_ + 1; while (index < active_index() && ideal_x(index) - ideal_x(index - 1) <= stacked_padding_ && ideal_x(index) <= x_ + max_stacked_width()) { @@ -495,11 +496,11 @@ void StackedTabStripLayout::AdjustLeadingStackedTabs() { ideal_x(index) <= x_ + max_stacked_width()) { index++; } - if (index <= mini_tab_count_ + max_stacked_count_ - 1) + if (index <= pinned_tab_count_ + max_stacked_count_ - 1) return; int max_stacked = index; int x = x_; - index = mini_tab_count_; + index = pinned_tab_count_; for (; index < max_stacked - max_stacked_count_ - 1; ++index) SetIdealBoundsAt(index, x); for (; index < max_stacked; ++index, x += stacked_padding_) @@ -538,14 +539,14 @@ void StackedTabStripLayout::SetIdealBoundsAt(int index, int x) { } int StackedTabStripLayout::GetMinX(int index) const { - int leading_count = index - mini_tab_count_; + int leading_count = index - pinned_tab_count_; int trailing_count = tab_count() - index; return std::max(x_ + stacked_padding_for_count(leading_count), width_ - width_for_count(trailing_count)); } int StackedTabStripLayout::GetMaxX(int index) const { - int leading_count = index - mini_tab_count_; + int leading_count = index - pinned_tab_count_; int trailing_count = tab_count() - index - 1; int trailing_offset = stacked_padding_for_count(trailing_count); int leading_size = width_for_count(leading_count) + x_; @@ -555,7 +556,7 @@ int StackedTabStripLayout::GetMaxX(int index) const { } int StackedTabStripLayout::GetMinDragX(int index) const { - return x_ + stacked_padding_for_count(index - mini_tab_count_); + return x_ + stacked_padding_for_count(index - pinned_tab_count_); } int StackedTabStripLayout::GetMaxDragX(int index) const { diff --git a/chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h b/chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h index 8c99ace..d2103d5 100644 --- a/chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h +++ b/chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h @@ -18,11 +18,11 @@ class Tab; // tabs. StackedTabStripLayout differs from the normal layout in that it stacks // tabs. Stacked tabs are tabs placed nearly on top of each other, and if enough // consecutive stacked tabs exist they are placed on top of each other. Normally -// stacked tabs are placed after mini-tabs, or at the end of the tabstrip, but +// stacked tabs are placed after pinned tabs, or at the end of the tabstrip, but // during dragging tabs may be stacked before or after the active tab. class StackedTabStripLayout { public: - static const int kAddTypeMini = 1 << 0; + static const int kAddTypePinned = 1 << 0; static const int kAddTypeActive = 1 << 1; // |size| is the size for tabs, |padding| the padding between consecutive @@ -37,9 +37,9 @@ class StackedTabStripLayout { views::ViewModelBase* view_model); ~StackedTabStripLayout(); - // Sets the x-coordinate the normal tabs start at as well as the mini-tab - // count. This is only useful if the mini-tab count or x-coordinate change. - void SetXAndMiniCount(int x, int mini_tab_count); + // Sets the x-coordinate the normal tabs start at as well as the pinned tab + // count. This is only useful if the pinned tab count or x-coordinate change. + void SetXAndPinnedCount(int x, int pinned_tab_count); // Sets the width available for sizing the tabs to. void SetWidth(int width); @@ -57,7 +57,7 @@ class StackedTabStripLayout { void SizeToFit(); // Adds a new tab at the specified index. |add_types| is a bitmask of - // kAddType*. |start_x| is the new x-coordinate non-mini tabs start at. + // kAddType*. |start_x| is the new x-coordinate non-pinned tabs start at. void AddTab(int index, int add_types, int start_x); // Removes the tab at the specified index. |start_x| is the new x-coordinate @@ -71,16 +71,17 @@ class StackedTabStripLayout { int to, int new_active_index, int start_x, - int mini_tab_count); + int pinned_tab_count); // Returns the active index as used by this class. The active index dictates - // stacking and what tabs are visible. As mini-tabs are never stacked, + // stacking and what tabs are visible. As pinned tabs are never stacked, // StackedTabStripLayout forces the active index to be in the normal tabs. int active_index() const { - return active_index_ < mini_tab_count_ ? mini_tab_count_ : active_index_; + return active_index_ < pinned_tab_count_ ? pinned_tab_count_ + : active_index_; } - int mini_tab_count() const { return mini_tab_count_; } + int pinned_tab_count() const { return pinned_tab_count_; } // Returns true if the tab at index is stacked. bool IsStacked(int index) const; @@ -95,9 +96,9 @@ class StackedTabStripLayout { private: friend class StackedTabStripLayoutTest; - // Sets the x-coordinate normal tabs start at, width mini-tab count and + // Sets the x-coordinate normal tabs start at, width pinned tab count and // active index at once. - void Reset(int x, int width, int mini_tab_count, int active_index); + void Reset(int x, int width, int pinned_tab_count, int active_index); // Resets to an ideal layout state. void ResetToIdealState(); @@ -120,7 +121,7 @@ class StackedTabStripLayout { void LayoutByTabOffsetAfter(int index); // Same as LayoutByTabOffsetAfter(), but iterates toward - // |mini_tab_count_|. + // |pinned_tab_count_|. void LayoutByTabOffsetBefore(int index); // Similar to LayoutByTabOffsetAfter(), but uses the current x-coordinate @@ -189,15 +190,15 @@ class StackedTabStripLayout { // Returns true if some of the tabs need to be stacked. bool requires_stacking() const { - return tab_count() != mini_tab_count_ && - x_ + width_for_count(tab_count() - mini_tab_count_) > width_; + return tab_count() != pinned_tab_count_ && + x_ + width_for_count(tab_count() - pinned_tab_count_) > width_; } // Number of tabs. int tab_count() const { return view_model_->view_size(); } - // Number of normal (non-mini) tabs. - int normal_tab_count() const { return tab_count() - mini_tab_count_; } + // Number of normal (non-pinned) tabs. + int normal_tab_count() const { return tab_count() - pinned_tab_count_; } // Distance between one tab to the next. int tab_offset() const { return size_.width() + padding_; } @@ -225,17 +226,17 @@ class StackedTabStripLayout { // Available width. int width_; - // Number of mini-tabs. - int mini_tab_count_; + // Number of pinned tabs. + int pinned_tab_count_; - // Distance from the last mini-tab to the first non-mini-tab. - int mini_tab_to_non_mini_tab_; + // Distance from the last pinned tab to the first non-pinned tab. + int pinned_tab_to_non_pinned_tab_; // Index of the active tab. int active_index_; // X-coordinate of the first tab. This is either |x_| if there are no - // mini-tabs, or the x-coordinate of the first mini-tab. + // pinned tabs, or the x-coordinate of the first pinned tab. int first_tab_x_; DISALLOW_COPY_AND_ASSIGN(StackedTabStripLayout); diff --git a/chrome/browser/ui/views/tabs/stacked_tab_strip_layout_unittest.cc b/chrome/browser/ui/views/tabs/stacked_tab_strip_layout_unittest.cc index 7e62549..bf01fdd 100644 --- a/chrome/browser/ui/views/tabs/stacked_tab_strip_layout_unittest.cc +++ b/chrome/browser/ui/views/tabs/stacked_tab_strip_layout_unittest.cc @@ -21,7 +21,7 @@ struct CommonTestData { const int tab_size; const int tab_padding; const int stacked_offset; - const int mini_tab_count; + const int pinned_tab_count; const int active_index; const std::string start_bounds; const std::string expected_bounds; @@ -37,9 +37,9 @@ class StackedTabStripLayoutTest : public testing::Test { void Reset(StackedTabStripLayout* layout, int x, int width, - int mini_tab_count, + int pinned_tab_count, int active_index) { - layout->Reset(x, width, mini_tab_count, active_index); + layout->Reset(x, width, pinned_tab_count, active_index); } void CreateLayout(const CommonTestData& data) { @@ -52,11 +52,11 @@ class StackedTabStripLayoutTest : public testing::Test { data.stacked_offset, 4, &view_model_)); if (data.start_bounds.empty()) { PrepareChildViewsFromString(data.expected_bounds); - layout_->Reset(data.initial_x, data.width, data.mini_tab_count, + layout_->Reset(data.initial_x, data.width, data.pinned_tab_count, data.active_index); } else { ASSERT_NO_FATAL_FAILURE(SetBoundsFromString(data.start_bounds)); - layout_->Reset(data.initial_x, data.width, data.mini_tab_count, + layout_->Reset(data.initial_x, data.width, data.pinned_tab_count, data.active_index); ASSERT_NO_FATAL_FAILURE(SetBoundsFromString(data.start_bounds)); } @@ -185,7 +185,8 @@ TEST_F(StackedTabStripLayoutTest, DragActiveTabExisting) { // The following set of tests create 6 tabs, the first two are pinned and // the 2nd tab is selected. // - // 1 pixel to the right, should push only mini-tabs and first non-mini-tab. + // 1 pixel to the right, should push only pinned tabs and first non-pinned + // tab. { { 10, 240, 100, -10, 2, 2, 1, "0 5 10 100 138 140", "1 6 11 101 138 140" }, 1 }, // Push enough to collapse the 4th tab. @@ -293,7 +294,7 @@ TEST_F(StackedTabStripLayoutTest, AddTab) { CommonTestData common_data; int add_index; bool add_active; - bool add_mini; + bool add_pinned; } test_data[] = { // Adding a background tab test cases. { { 0, 300, 100, -10, 2, 0, 1, "0 90 180 198 200", "0 16 106 196 198 200"}, @@ -335,12 +336,12 @@ TEST_F(StackedTabStripLayoutTest, AddTab) { int add_types = 0; if (test_data[i].add_active) add_types |= StackedTabStripLayout::kAddTypeActive; - if (test_data[i].add_mini) - add_types |= StackedTabStripLayout::kAddTypeMini; + if (test_data[i].add_pinned) + add_types |= StackedTabStripLayout::kAddTypePinned; AddViewToViewModel(test_data[i].add_index); layout_->AddTab(test_data[i].add_index, add_types, test_data[i].common_data.initial_x + - (test_data[i].add_mini ? 4 : 0)); + (test_data[i].add_pinned ? 4 : 0)); EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << " at " << i; } @@ -348,7 +349,7 @@ TEST_F(StackedTabStripLayoutTest, AddTab) { // Assertions around removing tabs. TEST_F(StackedTabStripLayoutTest, RemoveTab) { - // TODO: add coverage of removing mini tabs! + // TODO: add coverage of removing pinned tabs! struct TestData { struct CommonTestData common_data; const int remove_index; @@ -367,7 +368,7 @@ TEST_F(StackedTabStripLayoutTest, RemoveTab) { "0 2 4 6 10 80 98 100" }, 4, 0 }, - // Mini-tabs. + // Pinned tabs. { { 8, 200, 100, -10, 2, 1, 0, "0 8 94 96 98 100", "0 86 88 90 100" }, 0, 0 }, { { 16, 200, 100, -10, 2, 2, 0, "0 8 16 94 96 98 100", "8 8 86 88 90 100" }, @@ -464,14 +465,14 @@ TEST_F(StackedTabStripLayoutTest, EmptyTest) { // Assertions around removing tabs. TEST_F(StackedTabStripLayoutTest, MoveTab) { - // TODO: add coverage of removing mini tabs! + // TODO: add coverage of removing pinned tabs! struct TestData { struct CommonTestData common_data; const int from; const int to; const int new_active_index; const int new_start_x; - const int new_mini_tab_count; + const int new_pinned_tab_count; } test_data[] = { // Moves and unpins. { { 10, 300, 100, -10, 2, 2, 0, "", "0 5 10 100 190 198 200" }, @@ -491,14 +492,14 @@ TEST_F(StackedTabStripLayoutTest, MoveTab) { for (size_t i = 0; i < arraysize(test_data); ++i) { CreateLayout(test_data[i].common_data); view_model_.MoveViewOnly(test_data[i].from, test_data[i].to); - for (int j = 0; j < test_data[i].new_mini_tab_count; ++j) { + for (int j = 0; j < test_data[i].new_pinned_tab_count; ++j) { gfx::Rect bounds; bounds.set_x(j * 5); view_model_.set_ideal_bounds(j, bounds); } layout_->MoveTab(test_data[i].from, test_data[i].to, test_data[i].new_active_index, test_data[i].new_start_x, - test_data[i].new_mini_tab_count); + test_data[i].new_pinned_tab_count); EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << " at " << i; } @@ -525,17 +526,17 @@ TEST_F(StackedTabStripLayoutTest, IsStacked) { EXPECT_TRUE(layout_->IsStacked(0)); } -// Assertions around SetXAndMiniCount. -TEST_F(StackedTabStripLayoutTest, SetXAndMiniCount) { - // Verifies we don't crash when transitioning to all mini-tabs. +// Assertions around SetXAndPinnedCount. +TEST_F(StackedTabStripLayoutTest, SetXAndPinnedCount) { + // Verifies we don't crash when transitioning to all pinned tabs. PrepareChildViews(1); layout_.reset(new StackedTabStripLayout( gfx::Size(100, 10), -10, 2, 4, &view_model_)); Reset(layout_.get(), 0, 400, 0, 0); - layout_->SetXAndMiniCount(0, 1); + layout_->SetXAndPinnedCount(0, 1); } -// Assertions around SetXAndMiniCount. +// Assertions around SetXAndPinnedCount. TEST_F(StackedTabStripLayoutTest, SetActiveTabLocation) { struct TestData { struct CommonTestData common_data; diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc index c246e05..bea6af3 100644 --- a/chrome/browser/ui/views/tabs/tab.cc +++ b/chrome/browser/ui/views/tabs/tab.cc @@ -78,14 +78,14 @@ static const int kFaviconTitleSpacing = 4; static const int kViewSpacing = 3; static const int kStandardTitleWidth = 175; -// Width of mini-tabs. -const int kMiniTabWidth = 64; +// Width of pinned-tabs. +const int kPinnedTabWidth = 64; -// When a non-mini-tab becomes a mini-tab the width of the tab animates. If -// the width of a mini-tab is >= kMiniTabRendererAsNormalTabWidth then the tab -// is rendered as a normal tab. This is done to avoid having the title -// immediately disappear when transitioning a tab from normal to mini-tab. -static const int kMiniTabRendererAsNormalTabWidth = kMiniTabWidth + 30; +// When a non-pinned tab becomes a pinned tab the width of the tab animates. If +// the width of a pinned tab is >= kPinnedTabRendererAsNormalTabWidth then the +// tab is rendered as a normal tab. This is done to avoid having the title +// immediately disappear when transitioning a tab from normal to pinned tab. +static const int kPinnedTabRendererAsNormalTabWidth = kPinnedTabWidth + 30; // How opaque to make the hover state (out of 1). static const double kHoverOpacity = 0.33; @@ -96,25 +96,26 @@ static const double kSelectedTabOpacity = .45; // Selected (but not active) tabs have their throb value scaled down by this. static const double kSelectedTabThrobScale = .5; -// Durations for the various parts of the mini tab title animation. -static const int kMiniTitleChangeAnimationDuration1MS = 1600; -static const int kMiniTitleChangeAnimationStart1MS = 0; -static const int kMiniTitleChangeAnimationEnd1MS = 1900; -static const int kMiniTitleChangeAnimationDuration2MS = 0; -static const int kMiniTitleChangeAnimationDuration3MS = 550; -static const int kMiniTitleChangeAnimationStart3MS = 150; -static const int kMiniTitleChangeAnimationEnd3MS = 800; -static const int kMiniTitleChangeAnimationIntervalMS = 40; - -// Offset from the right edge for the start of the mini title change animation. -static const int kMiniTitleChangeInitialXOffset = 6; - -// Radius of the radial gradient used for mini title change animation. -static const int kMiniTitleChangeGradientRadius = 20; - -// Colors of the gradient used during the mini title change animation. -static const SkColor kMiniTitleChangeGradientColor1 = SK_ColorWHITE; -static const SkColor kMiniTitleChangeGradientColor2 = +// Durations for the various parts of the pinned tab title animation. +static const int kPinnedTitleChangeAnimationDuration1MS = 1600; +static const int kPinnedTitleChangeAnimationStart1MS = 0; +static const int kPinnedTitleChangeAnimationEnd1MS = 1900; +static const int kPinnedTitleChangeAnimationDuration2MS = 0; +static const int kPinnedTitleChangeAnimationDuration3MS = 550; +static const int kPinnedTitleChangeAnimationStart3MS = 150; +static const int kPinnedTitleChangeAnimationEnd3MS = 800; +static const int kPinnedTitleChangeAnimationIntervalMS = 40; + +// Offset from the right edge for the start of the pinned title change +// animation. +static const int kPinnedTitleChangeInitialXOffset = 6; + +// Radius of the radial gradient used for pinned title change animation. +static const int kPinnedTitleChangeGradientRadius = 20; + +// Colors of the gradient used during the pinned title change animation. +static const SkColor kPinnedTitleChangeGradientColor1 = SK_ColorWHITE; +static const SkColor kPinnedTitleChangeGradientColor2 = SkColorSetARGB(0, 255, 255, 255); // Max number of images to cache. This has to be at least two since rounding @@ -521,8 +522,8 @@ void Tab::SetData(const TabRendererData& data) { if (data_.media_state != old.media_state) GetMediaIndicatorButton()->TransitionToMediaState(data_.media_state); - if (old.mini != data_.mini) { - StopAndDeleteAnimation(mini_title_change_animation_.Pass()); + if (old.pinned != data_.pinned) { + StopAndDeleteAnimation(pinned_title_change_animation_.Pass()); } DataChanged(old); @@ -556,36 +557,37 @@ void Tab::StopPulse() { StopAndDeleteAnimation(pulse_animation_.Pass()); } -void Tab::StartMiniTabTitleAnimation() { - if (!data().mini) +void Tab::StartPinnedTabTitleAnimation() { + if (!data().pinned) return; - if (!mini_title_change_animation_) { + if (!pinned_title_change_animation_) { gfx::MultiAnimation::Parts parts; parts.push_back( - gfx::MultiAnimation::Part(kMiniTitleChangeAnimationDuration1MS, + gfx::MultiAnimation::Part(kPinnedTitleChangeAnimationDuration1MS, gfx::Tween::EASE_OUT)); parts.push_back( - gfx::MultiAnimation::Part(kMiniTitleChangeAnimationDuration2MS, + gfx::MultiAnimation::Part(kPinnedTitleChangeAnimationDuration2MS, gfx::Tween::ZERO)); parts.push_back( - gfx::MultiAnimation::Part(kMiniTitleChangeAnimationDuration3MS, + gfx::MultiAnimation::Part(kPinnedTitleChangeAnimationDuration3MS, gfx::Tween::EASE_IN)); - parts[0].start_time_ms = kMiniTitleChangeAnimationStart1MS; - parts[0].end_time_ms = kMiniTitleChangeAnimationEnd1MS; - parts[2].start_time_ms = kMiniTitleChangeAnimationStart3MS; - parts[2].end_time_ms = kMiniTitleChangeAnimationEnd3MS; - base::TimeDelta timeout = - base::TimeDelta::FromMilliseconds(kMiniTitleChangeAnimationIntervalMS); - mini_title_change_animation_.reset(new gfx::MultiAnimation(parts, timeout)); + parts[0].start_time_ms = kPinnedTitleChangeAnimationStart1MS; + parts[0].end_time_ms = kPinnedTitleChangeAnimationEnd1MS; + parts[2].start_time_ms = kPinnedTitleChangeAnimationStart3MS; + parts[2].end_time_ms = kPinnedTitleChangeAnimationEnd3MS; + base::TimeDelta timeout = base::TimeDelta::FromMilliseconds( + kPinnedTitleChangeAnimationIntervalMS); + pinned_title_change_animation_.reset( + new gfx::MultiAnimation(parts, timeout)); if (animation_container_.get()) - mini_title_change_animation_->SetContainer(animation_container_.get()); - mini_title_change_animation_->set_delegate(this); + pinned_title_change_animation_->SetContainer(animation_container_.get()); + pinned_title_change_animation_->set_delegate(this); } - mini_title_change_animation_->Start(); + pinned_title_change_animation_->Start(); } -void Tab::StopMiniTabTitleAnimation() { - StopAndDeleteAnimation(mini_title_change_animation_.Pass()); +void Tab::StopPinnedTabTitleAnimation() { + StopAndDeleteAnimation(pinned_title_change_animation_.Pass()); } // static @@ -626,8 +628,8 @@ int Tab::GetTouchWidth() { } // static -int Tab::GetMiniWidth() { - return kMiniTabWidth; +int Tab::GetPinnedWidth() { + return kPinnedTabWidth; } // static @@ -724,7 +726,7 @@ bool Tab::GetHitTestMask(gfx::Path* mask) const { void Tab::OnPaint(gfx::Canvas* canvas) { // Don't paint if we're narrower than we can render correctly. (This should // only happen during animations). - if (width() < GetMinimumUnselectedSize().width() && !data().mini) + if (width() < GetMinimumUnselectedSize().width() && !data().pinned) return; gfx::Rect clip; @@ -755,7 +757,7 @@ void Tab::Layout() { if (showing_icon_) { favicon_bounds_.set_size(gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); favicon_bounds_.set_y(lb.y() + (lb.height() - gfx::kFaviconSize + 1) / 2); - MaybeAdjustLeftForMiniTab(&favicon_bounds_); + MaybeAdjustLeftForPinnedTab(&favicon_bounds_); } showing_close_button_ = ShouldShowCloseBox(); @@ -792,7 +794,7 @@ void Tab::Layout() { lb.y() + (lb.height() - image_size.height() + 1) / 2, image_size.width(), image_size.height()); - MaybeAdjustLeftForMiniTab(&bounds); + MaybeAdjustLeftForPinnedTab(&bounds); button->SetBoundsRect(bounds); button->SetVisible(true); } else if (media_indicator_button_) { @@ -800,7 +802,8 @@ void Tab::Layout() { } // Size the title to fill the remaining width and use all available height. - bool show_title = !data().mini || width() >= kMiniTabRendererAsNormalTabWidth; + bool show_title = + !data().pinned || width() >= kPinnedTabRendererAsNormalTabWidth; if (show_title) { int title_left = favicon_bounds_.right() + kFaviconTitleSpacing; int title_width = lb.width() - title_left; @@ -993,14 +996,15 @@ void Tab::GetAccessibleState(ui::AXViewState* state) { //////////////////////////////////////////////////////////////////////////////// // Tab, private -void Tab::MaybeAdjustLeftForMiniTab(gfx::Rect* bounds) const { - if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) +void Tab::MaybeAdjustLeftForPinnedTab(gfx::Rect* bounds) const { + if (!data().pinned || width() >= kPinnedTabRendererAsNormalTabWidth) return; - const int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth(); - const int ideal_delta = width() - GetMiniWidth(); - const int ideal_x = (GetMiniWidth() - bounds->width()) / 2; + const int pinned_delta = + kPinnedTabRendererAsNormalTabWidth - GetPinnedWidth(); + const int ideal_delta = width() - GetPinnedWidth(); + const int ideal_x = (GetPinnedWidth() - bounds->width()) / 2; bounds->set_x(bounds->x() + static_cast<int>( - (1 - static_cast<float>(ideal_delta) / static_cast<float>(mini_delta)) * + (1 - static_cast<float>(ideal_delta) / static_cast<float>(pinned_delta)) * (ideal_x - bounds->x()))); } @@ -1033,8 +1037,8 @@ void Tab::PaintTab(gfx::Canvas* canvas) { const SkColor title_color = GetThemeProvider()->GetColor(IsSelected() ? ThemeProperties::COLOR_TAB_TEXT : ThemeProperties::COLOR_BACKGROUND_TAB_TEXT); - title_->SetVisible(!data().mini || - width() > kMiniTabRendererAsNormalTabWidth); + title_->SetVisible(!data().pinned || + width() > kPinnedTabRendererAsNormalTabWidth); title_->SetEnabledColor(title_color); if (show_icon) @@ -1053,12 +1057,12 @@ void Tab::PaintTab(gfx::Canvas* canvas) { void Tab::PaintImmersiveTab(gfx::Canvas* canvas) { // Use transparency for the draw-attention animation. int alpha = 255; - if (pulse_animation_ && pulse_animation_->is_animating() && !data().mini) { + if (pulse_animation_ && pulse_animation_->is_animating() && !data().pinned) { alpha = pulse_animation_->CurrentValueBetween( 255, static_cast<int>(255 * kImmersiveTabMinThrobOpacity)); } - // Draw a gray rectangle to represent the tab. This works for mini-tabs as + // Draw a gray rectangle to represent the tab. This works for pinned tabs as // well as regular ones. The active tab has a brigher bar. SkColor color = IsActive() ? kImmersiveActiveTabColor : kImmersiveInactiveTabColor; @@ -1098,8 +1102,8 @@ void Tab::PaintTabBackground(gfx::Canvas* canvas) { if (IsActive()) { PaintActiveTabBackground(canvas); } else { - if (mini_title_change_animation_ && - mini_title_change_animation_->is_animating()) { + if (pinned_title_change_animation_ && + pinned_title_change_animation_->is_animating()) { PaintInactiveTabBackgroundWithTitleChange(canvas); } else { PaintInactiveTabBackground(canvas); @@ -1124,22 +1128,22 @@ void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) { // Draw a radial gradient to hover_canvas. gfx::Canvas hover_canvas(size(), canvas->image_scale(), false); - int radius = kMiniTitleChangeGradientRadius; - int x0 = width() + radius - kMiniTitleChangeInitialXOffset; + int radius = kPinnedTitleChangeGradientRadius; + int x0 = width() + radius - kPinnedTitleChangeInitialXOffset; int x1 = radius; int x2 = -radius; int x; - if (mini_title_change_animation_->current_part_index() == 0) { - x = mini_title_change_animation_->CurrentValueBetween(x0, x1); - } else if (mini_title_change_animation_->current_part_index() == 1) { + if (pinned_title_change_animation_->current_part_index() == 0) { + x = pinned_title_change_animation_->CurrentValueBetween(x0, x1); + } else if (pinned_title_change_animation_->current_part_index() == 1) { x = x1; } else { - x = mini_title_change_animation_->CurrentValueBetween(x1, x2); + x = pinned_title_change_animation_->CurrentValueBetween(x1, x2); } SkPoint center_point; center_point.iset(x, 0); - SkColor colors[2] = { kMiniTitleChangeGradientColor1, - kMiniTitleChangeGradientColor2 }; + SkColor colors[2] = { kPinnedTitleChangeGradientColor1, + kPinnedTitleChangeGradientColor2 }; skia::RefPtr<SkShader> shader = skia::AdoptRef( SkGradientShader::CreateRadial( center_point, SkIntToScalar(radius), colors, NULL, 2, @@ -1157,8 +1161,8 @@ void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) { canvas->DrawImageInt(background_image, 0, 0); // And then the gradient on top of that. - if (mini_title_change_animation_->current_part_index() == 2) { - uint8 alpha = mini_title_change_animation_->CurrentValueBetween(255, 0); + if (pinned_title_change_animation_->current_part_index() == 2) { + uint8 alpha = pinned_title_change_animation_->CurrentValueBetween(255, 0); canvas->DrawImageInt(hover_image, 0, 0, alpha); } else { canvas->DrawImageInt(hover_image, 0, 0); @@ -1408,14 +1412,14 @@ int Tab::IconCapacity() const { bool Tab::ShouldShowIcon() const { return chrome::ShouldTabShowFavicon( - IconCapacity(), data().mini, IsActive(), data().show_icon, + IconCapacity(), data().pinned, IsActive(), data().show_icon, media_indicator_button_ ? media_indicator_button_->showing_media_state() : data_.media_state); } bool Tab::ShouldShowMediaIndicator() const { return chrome::ShouldTabShowMediaIndicator( - IconCapacity(), data().mini, IsActive(), data().show_icon, + IconCapacity(), data().pinned, IsActive(), data().show_icon, media_indicator_button_ ? media_indicator_button_->showing_media_state() : data_.media_state); } @@ -1425,7 +1429,7 @@ bool Tab::ShouldShowCloseBox() const { return false; return chrome::ShouldTabShowCloseButton( - IconCapacity(), data().mini, IsActive()); + IconCapacity(), data().pinned, IsActive()); } double Tab::GetThrobValue() { @@ -1436,8 +1440,8 @@ double Tab::GetThrobValue() { // Showing both the pulse and title change animation at the same time is too // much. if (pulse_animation_ && pulse_animation_->is_animating() && - (!mini_title_change_animation_ || - !mini_title_change_animation_->is_animating())) { + (!pinned_title_change_animation_ || + !pinned_title_change_animation_->is_animating())) { return pulse_animation_->GetCurrentValue() * kHoverOpacity * scale + min; } diff --git a/chrome/browser/ui/views/tabs/tab.h b/chrome/browser/ui/views/tabs/tab.h index e406b7c..d332f06 100644 --- a/chrome/browser/ui/views/tabs/tab.h +++ b/chrome/browser/ui/views/tabs/tab.h @@ -89,9 +89,9 @@ class Tab : public gfx::AnimationDelegate, void StartPulse(); void StopPulse(); - // Start/stop the mini-tab title animation. - void StartMiniTabTitleAnimation(); - void StopMiniTabTitleAnimation(); + // Start/stop the pinned tab title animation. + void StartPinnedTabTitleAnimation(); + void StopPinnedTabTitleAnimation(); // Set the background offset used to match the image in the inactive tab // to the frame image. @@ -135,8 +135,8 @@ class Tab : public gfx::AnimationDelegate, // Returns the width for touch tabs. static int GetTouchWidth(); - // Returns the width for mini-tabs. Mini-tabs always have this width. - static int GetMiniWidth(); + // Returns the width for pinned tabs. Pinned tabs always have this width. + static int GetPinnedWidth(); // Returns the height for immersive mode tabs. static int GetImmersiveHeight(); @@ -208,8 +208,8 @@ class Tab : public gfx::AnimationDelegate, void OnGestureEvent(ui::GestureEvent* event) override; // Invoked from Layout to adjust the position of the favicon or media - // indicator for mini tabs. - void MaybeAdjustLeftForMiniTab(gfx::Rect* bounds) const; + // indicator for pinned tabs. + void MaybeAdjustLeftForPinnedTab(gfx::Rect* bounds) const; // Invoked from SetData after |data_| has been updated to the new data. void DataChanged(const TabRendererData& old); @@ -336,7 +336,7 @@ class Tab : public gfx::AnimationDelegate, // Whole-tab throbbing "pulse" animation. scoped_ptr<gfx::ThrobAnimation> pulse_animation_; - scoped_ptr<gfx::MultiAnimation> mini_title_change_animation_; + scoped_ptr<gfx::MultiAnimation> pinned_title_change_animation_; // Crash icon animation (in place of favicon). scoped_ptr<gfx::LinearAnimation> crash_icon_animation_; diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller.cc b/chrome/browser/ui/views/tabs/tab_drag_controller.cc index e3b07ec..53e78b4 100644 --- a/chrome/browser/ui/views/tabs/tab_drag_controller.cc +++ b/chrome/browser/ui/views/tabs/tab_drag_controller.cc @@ -676,7 +676,7 @@ void TabDragController::MoveAttachedToNextStackedIndex( void TabDragController::MoveAttachedToPreviousStackedIndex( const gfx::Point& point_in_screen) { int index = attached_tabstrip_->touch_layout_->active_index(); - if (index <= attached_tabstrip_->GetMiniTabCount()) + if (index <= attached_tabstrip_->GetPinnedTabCount()) return; GetModel(attached_tabstrip_)->MoveSelectedTabsTo(index - 1); @@ -1230,7 +1230,7 @@ bool TabDragController::ShouldDragToNextStackedTab( bool TabDragController::ShouldDragToPreviousStackedTab( const gfx::Rect& dragged_bounds, int index) const { - if (index - 1 < attached_tabstrip_->GetMiniTabCount() || + if (index - 1 < attached_tabstrip_->GetPinnedTabCount() || !attached_tabstrip_->touch_layout_->IsStacked(index - 1) || (mouse_move_direction_ & kMovedMouseLeft) == 0) return false; diff --git a/chrome/browser/ui/views/tabs/tab_renderer_data.cc b/chrome/browser/ui/views/tabs/tab_renderer_data.cc index 6057b32..19e6555 100644 --- a/chrome/browser/ui/views/tabs/tab_renderer_data.cc +++ b/chrome/browser/ui/views/tabs/tab_renderer_data.cc @@ -10,7 +10,7 @@ TabRendererData::TabRendererData() crashed_status(base::TERMINATION_STATUS_STILL_RUNNING), incognito(false), show_icon(true), - mini(false), + pinned(false), blocked(false), app(false), media_state(TAB_MEDIA_STATE_NONE) { @@ -28,7 +28,7 @@ bool TabRendererData::Equals(const TabRendererData& data) { crashed_status == data.crashed_status && incognito == data.incognito && show_icon == data.show_icon && - mini == data.mini && + pinned == data.pinned && blocked == data.blocked && app == data.app && media_state == data.media_state; diff --git a/chrome/browser/ui/views/tabs/tab_renderer_data.h b/chrome/browser/ui/views/tabs/tab_renderer_data.h index e977059..6ba2011 100644 --- a/chrome/browser/ui/views/tabs/tab_renderer_data.h +++ b/chrome/browser/ui/views/tabs/tab_renderer_data.h @@ -46,7 +46,7 @@ struct CHROME_VIEWS_EXPORT TabRendererData { base::TerminationStatus crashed_status; bool incognito; bool show_icon; - bool mini; + bool pinned; bool blocked; bool app; TabMediaState media_state; diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc index 10958ee..1cddc85 100644 --- a/chrome/browser/ui/views/tabs/tab_strip.cc +++ b/chrome/browser/ui/views/tabs/tab_strip.cc @@ -533,10 +533,10 @@ const int TabStrip::kNewTabButtonAssetWidth = 34; const int TabStrip::kNewTabButtonAssetHeight = 18; #if defined(OS_MACOSX) const int TabStrip::kNewTabButtonHorizontalOffset = -8; -const int TabStrip::kMiniToNonMiniGap = 2; +const int TabStrip::kPinnedToNonPinnedGap = 2; #else const int TabStrip::kNewTabButtonHorizontalOffset = -11; -const int TabStrip::kMiniToNonMiniGap = 3; +const int TabStrip::kPinnedToNonPinnedGap = 3; #endif TabStrip::TabStrip(TabStripController* controller) @@ -637,10 +637,10 @@ void TabStrip::AddTabAt(int model_index, AddChildView(tab); if (touch_layout_) { - GenerateIdealBoundsForMiniTabs(NULL); + GenerateIdealBoundsForPinnedTabs(NULL); int add_types = 0; - if (data.mini) - add_types |= StackedTabStripLayout::kAddTypeMini; + if (data.pinned) + add_types |= StackedTabStripLayout::kAddTypePinned; if (is_active) add_types |= StackedTabStripLayout::kAddTypeActive; touch_layout_->AddTab(model_index, add_types, GetStartXForNormalTabs()); @@ -681,11 +681,11 @@ void TabStrip::MoveTab(int from_model_index, tab_at(from_model_index)->SetData(data); if (touch_layout_) { tabs_.MoveViewOnly(from_model_index, to_model_index); - int mini_count = 0; - GenerateIdealBoundsForMiniTabs(&mini_count); + int pinned_count = 0; + GenerateIdealBoundsForPinnedTabs(&pinned_count); touch_layout_->MoveTab( from_model_index, to_model_index, controller_->GetActiveIndex(), - GetStartXForNormalTabs(), mini_count); + GetStartXForNormalTabs(), pinned_count); } else { tabs_.Move(from_model_index, to_model_index); } @@ -708,8 +708,8 @@ void TabStrip::RemoveTabAt(int model_index) { // We still need to paint the tab until we actually remove it. Put it in // tabs_closing_map_ so we can find it. RemoveTabFromViewModel(model_index); - touch_layout_->RemoveTab(model_index, GenerateIdealBoundsForMiniTabs(NULL), - old_x); + touch_layout_->RemoveTab(model_index, + GenerateIdealBoundsForPinnedTabs(NULL), old_x); ScheduleRemoveTabAnimation(tab); } else if (in_tab_close_ && model_index != GetModelCount()) { StartMouseInitiatedRemoveTabAnimation(model_index); @@ -724,17 +724,17 @@ void TabStrip::RemoveTabAt(int model_index) { void TabStrip::SetTabData(int model_index, const TabRendererData& data) { Tab* tab = tab_at(model_index); - bool mini_state_changed = tab->data().mini != data.mini; + bool pinned_state_changed = tab->data().pinned != data.pinned; tab->SetData(data); - if (mini_state_changed) { + if (pinned_state_changed) { if (touch_layout_) { - int mini_tab_count = 0; - int start_x = GenerateIdealBoundsForMiniTabs(&mini_tab_count); - touch_layout_->SetXAndMiniCount(start_x, mini_tab_count); + int pinned_tab_count = 0; + int start_x = GenerateIdealBoundsForPinnedTabs(&pinned_tab_count); + touch_layout_->SetXAndPinnedCount(start_x, pinned_tab_count); } if (GetWidget() && GetWidget()->IsVisible()) - StartMiniTabAnimation(); + StartPinnedTabAnimation(); else DoLayout(); } @@ -778,9 +778,9 @@ bool TabStrip::ShouldTabBeVisible(const Tab* tab) const { // become clipped if we changed the active tab, widening either this tab or // the tabstrip portion before it. - // Mini tabs don't change size when activated, so any tab in the mini tab + // Pinned tabs don't change size when activated, so any tab in the pinned tab // region is safe. - if (tab->data().mini) + if (tab->data().pinned) return true; // If the active tab is on or before this tab, we're safe. @@ -813,9 +813,9 @@ void TabStrip::PrepareForCloseAt(int model_index, CloseTabSource source) { Tab* tab_being_removed = tab_at(model_index); available_width_for_tabs_ = last_tab->x() + last_tab->width() - tab_being_removed->width() - kTabHorizontalOffset; - if (model_index == 0 && tab_being_removed->data().mini && - !tab_at(1)->data().mini) { - available_width_for_tabs_ -= kMiniToNonMiniGap; + if (model_index == 0 && tab_being_removed->data().pinned && + !tab_at(1)->data().pinned) { + available_width_for_tabs_ -= kPinnedToNonPinnedGap; } } @@ -861,9 +861,9 @@ void TabStrip::SetSelection(const ui::ListSelectionModel& old_selection, old_selection.selected_indices()); // Fire accessibility events that reflect the changes to selection, and - // stop the mini tab title animation on tabs no longer selected. + // stop the pinned tab title animation on tabs no longer selected. for (size_t i = 0; i < no_longer_selected.size(); ++i) { - tab_at(no_longer_selected[i])->StopMiniTabTitleAnimation(); + tab_at(no_longer_selected[i])->StopPinnedTabTitleAnimation(); tab_at(no_longer_selected[i])->NotifyAccessibilityEvent( ui::AX_EVENT_SELECTION_REMOVE, true); } @@ -877,8 +877,8 @@ void TabStrip::SetSelection(const ui::ListSelectionModel& old_selection, void TabStrip::TabTitleChangedNotLoading(int model_index) { Tab* tab = tab_at(model_index); - if (tab->data().mini && !tab->IsActive()) - tab->StartMiniTabTitleAnimation(); + if (tab->data().pinned && !tab->IsActive()) + tab->StartPinnedTabTitleAnimation(); } int TabStrip::GetModelIndexOfTab(const Tab* tab) const { @@ -1373,13 +1373,13 @@ gfx::Size TabStrip::GetPreferredSize() const { Tab::GetTouchWidth() + (2 * kStackedPadding * kMaxStackedCount); } else { // Otherwise the minimum width is based on the actual number of tabs. - const int mini_tab_count = GetMiniTabCount(); - needed_tab_width = mini_tab_count * Tab::GetMiniWidth(); - const int remaining_tab_count = tab_count() - mini_tab_count; + const int pinned_tab_count = GetPinnedTabCount(); + needed_tab_width = pinned_tab_count * Tab::GetPinnedWidth(); + const int remaining_tab_count = tab_count() - pinned_tab_count; const int min_selected_width = Tab::GetMinimumSelectedSize().width(); const int min_unselected_width = Tab::GetMinimumUnselectedSize().width(); if (remaining_tab_count > 0) { - needed_tab_width += kMiniToNonMiniGap + min_selected_width + + needed_tab_width += kPinnedToNonPinnedGap + min_selected_width + ((remaining_tab_count - 1) * min_unselected_width); } if (tab_count() > 1) @@ -1696,14 +1696,14 @@ void TabStrip::StackDraggedTabs(int delta) { new_bounds.set_x(std::max(min_x, new_bounds.x() - adjusted_delta)); tabs_.set_ideal_bounds(i, new_bounds); } - const bool is_active_mini = tab_at(active_index)->data().mini; + const bool is_active_pinned = tab_at(active_index)->data().pinned; const int active_width = ideal_bounds(active_index).width(); for (int i = active_index + 1; i < tab_count(); ++i) { const int max_x = ideal_bounds(active_index).x() + (kStackedPadding * std::min(i - active_index, kMaxStackedCount)); gfx::Rect new_bounds(ideal_bounds(i)); int new_x = std::max(new_bounds.x() + delta, max_x); - if (new_x == max_x && !tab_at(i)->data().mini && !is_active_mini && + if (new_x == max_x && !tab_at(i)->data().pinned && !is_active_pinned && new_bounds.width() != active_width) new_x += (active_width - new_bounds.width()); new_bounds.set_x(new_x); @@ -1730,7 +1730,7 @@ void TabStrip::StackDraggedTabs(int delta) { int new_x = std::min(max_x, new_bounds.x() + adjusted_delta); // Because of rounding not all tabs are the same width. Adjust the // position to accommodate this, otherwise the stacking is off. - if (new_x == max_x && !tab_at(i)->data().mini && + if (new_x == max_x && !tab_at(i)->data().pinned && new_bounds.width() != last_tab_width) new_x += (last_tab_width - new_bounds.width()); new_bounds.set_x(new_x); @@ -1795,8 +1795,8 @@ void TabStrip::CalculateBoundsForDraggedTabs(const Tabs& tabs, int x = 0; for (size_t i = 0; i < tabs.size(); ++i) { Tab* tab = tabs[i]; - if (i > 0 && tab->data().mini != tabs[i - 1]->data().mini) - x += kMiniToNonMiniGap; + if (i > 0 && tab->data().pinned != tabs[i - 1]->data().pinned) + x += kPinnedToNonPinnedGap; gfx::Rect new_bounds = tab->bounds(); new_bounds.set_origin(gfx::Point(x, 0)); bounds->push_back(new_bounds); @@ -1809,19 +1809,19 @@ int TabStrip::GetSizeNeededForTabs(const Tabs& tabs) { for (size_t i = 0; i < tabs.size(); ++i) { Tab* tab = tabs[i]; width += tab->width(); - if (i > 0 && tab->data().mini != tabs[i - 1]->data().mini) - width += kMiniToNonMiniGap; + if (i > 0 && tab->data().pinned != tabs[i - 1]->data().pinned) + width += kPinnedToNonPinnedGap; } if (tabs.size() > 0) width += kTabHorizontalOffset * static_cast<int>(tabs.size() - 1); return width; } -int TabStrip::GetMiniTabCount() const { - int mini_count = 0; - while (mini_count < tab_count() && tab_at(mini_count)->data().mini) - mini_count++; - return mini_count; +int TabStrip::GetPinnedTabCount() const { + int pinned_count = 0; + while (pinned_count < tab_count() && tab_at(pinned_count)->data().pinned) + pinned_count++; + return pinned_count; } const Tab* TabStrip::GetLastVisibleTab() const { @@ -2084,10 +2084,11 @@ void TabStrip::GetCurrentTabWidths(double* unselected_width, } void TabStrip::GetDesiredTabWidths(int tab_count, - int mini_tab_count, + int pinned_tab_count, double* unselected_width, double* selected_width) const { - DCHECK(tab_count >= 0 && mini_tab_count >= 0 && mini_tab_count <= tab_count); + DCHECK(tab_count >= 0 && pinned_tab_count >= 0 && + pinned_tab_count <= tab_count); const double min_unselected_width = Tab::GetMinimumUnselectedSize().width(); const double min_selected_width = Tab::GetMinimumSelectedSize().width(); @@ -2102,16 +2103,16 @@ void TabStrip::GetDesiredTabWidths(int tab_count, // Determine how much space we can actually allocate to tabs. int available_width = (available_width_for_tabs_ < 0) ? tab_area_width() : available_width_for_tabs_; - if (mini_tab_count > 0) { + if (pinned_tab_count > 0) { available_width -= - mini_tab_count * (Tab::GetMiniWidth() + kTabHorizontalOffset); - tab_count -= mini_tab_count; + pinned_tab_count * (Tab::GetPinnedWidth() + kTabHorizontalOffset); + tab_count -= pinned_tab_count; if (tab_count == 0) { *selected_width = *unselected_width = Tab::GetStandardSize().width(); return; } - // Account for gap between the last mini-tab and first non-mini-tab. - available_width -= kMiniToNonMiniGap; + // Account for gap between the last pinned tab and first non-pinned tab. + available_width -= kPinnedToNonPinnedGap; } // Calculate the desired tab widths by dividing the available space into equal @@ -2156,10 +2157,10 @@ void TabStrip::ResizeLayoutTabs() { in_tab_close_ = false; available_width_for_tabs_ = -1; - int mini_tab_count = GetMiniTabCount(); - if (mini_tab_count == tab_count()) { - // Only mini-tabs, we know the tab widths won't have changed (all - // mini-tabs have the same width), so there is nothing to do. + int pinned_tab_count = GetPinnedTabCount(); + if (pinned_tab_count == tab_count()) { + // Only pinned tabs, we know the tab widths won't have changed (all + // pinned tabs have the same width), so there is nothing to do. return; } // Don't try and avoid layout based on tab sizes. If tabs are small enough @@ -2250,8 +2251,8 @@ void TabStrip::UpdateDropIndex(const DropTargetEvent& event) { // coordinates since we calculate the drop index based on the // original (and therefore non-mirrored) positions of the tabs. const int x = GetMirroredXInView(event.x()); - // We don't allow replacing the urls of mini-tabs. - for (int i = GetMiniTabCount(); i < tab_count(); ++i) { + // We don't allow replacing the urls of pinned tabs. + for (int i = GetPinnedTabCount(); i < tab_count(); ++i) { Tab* tab = tab_at(i); const int tab_max_x = tab->x() + tab->width(); const int hot_width = tab->width() / kTabEdgeRatioInverse; @@ -2374,17 +2375,17 @@ void TabStrip::GenerateIdealBounds() { return; } - GetDesiredTabWidths(tab_count(), GetMiniTabCount(), + GetDesiredTabWidths(tab_count(), GetPinnedTabCount(), ¤t_unselected_width_, ¤t_selected_width_); // NOTE: This currently assumes a tab's height doesn't differ based on // selected state or the number of tabs in the strip! int tab_height = Tab::GetStandardSize().height(); - int first_non_mini_index = 0; - double tab_x = GenerateIdealBoundsForMiniTabs(&first_non_mini_index); - for (int i = first_non_mini_index; i < tab_count(); ++i) { + int first_non_pinned_index = 0; + double tab_x = GenerateIdealBoundsForPinnedTabs(&first_non_pinned_index); + for (int i = first_non_pinned_index; i < tab_count(); ++i) { Tab* tab = tab_at(i); - DCHECK(!tab->data().mini); + DCHECK(!tab->data().pinned); double tab_width = tab->IsActive() ? current_selected_width_ : current_unselected_width_; double end_of_tab = tab_x + tab_width; @@ -2411,19 +2412,20 @@ void TabStrip::GenerateIdealBounds() { newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, new_tab_y)); } -int TabStrip::GenerateIdealBoundsForMiniTabs(int* first_non_mini_index) { +int TabStrip::GenerateIdealBoundsForPinnedTabs(int* first_non_pinned_index) { int next_x = 0; - int mini_width = Tab::GetMiniWidth(); + int pinned_width = Tab::GetPinnedWidth(); int tab_height = Tab::GetStandardSize().height(); int index = 0; - for (; index < tab_count() && tab_at(index)->data().mini; ++index) { - tabs_.set_ideal_bounds(index, gfx::Rect(next_x, 0, mini_width, tab_height)); - next_x += mini_width + kTabHorizontalOffset; + for (; index < tab_count() && tab_at(index)->data().pinned; ++index) { + tabs_.set_ideal_bounds(index, + gfx::Rect(next_x, 0, pinned_width, tab_height)); + next_x += pinned_width + kTabHorizontalOffset; } if (index > 0 && index < tab_count()) - next_x += kMiniToNonMiniGap; - if (first_non_mini_index) - *first_non_mini_index = index; + next_x += kPinnedToNonPinnedGap; + if (first_non_pinned_index) + *first_non_pinned_index = index; return next_x; } @@ -2433,7 +2435,7 @@ void TabStrip::StartResizeLayoutAnimation() { AnimateToIdealBounds(); } -void TabStrip::StartMiniTabAnimation() { +void TabStrip::StartPinnedTabAnimation() { in_tab_close_ = false; available_width_for_tabs_ = -1; @@ -2448,11 +2450,11 @@ void TabStrip::StartMouseInitiatedRemoveTabAnimation(int model_index) { // existing tabs, so we manually shift ideal_bounds then animate. Tab* tab_closing = tab_at(model_index); int delta = tab_closing->width() + kTabHorizontalOffset; - // If the tab being closed is a mini-tab next to a non-mini-tab, be sure to - // add the extra padding. + // If the tab being closed is a pinned tab next to a non-pinned tab, be sure + // to add the extra padding. DCHECK_LT(model_index, tab_count() - 1); - if (tab_closing->data().mini && !tab_at(model_index + 1)->data().mini) - delta += kMiniToNonMiniGap; + if (tab_closing->data().pinned && !tab_at(model_index + 1)->data().pinned) + delta += kPinnedToNonPinnedGap; for (int i = model_index + 1; i < tab_count(); ++i) { gfx::Rect bounds = ideal_bounds(i); @@ -2497,11 +2499,11 @@ bool TabStrip::IsPointInTab(Tab* tab, } int TabStrip::GetStartXForNormalTabs() const { - int mini_tab_count = GetMiniTabCount(); - if (mini_tab_count == 0) + int pinned_tab_count = GetPinnedTabCount(); + if (pinned_tab_count == 0) return 0; - return mini_tab_count * (Tab::GetMiniWidth() + kTabHorizontalOffset) + - kMiniToNonMiniGap; + return pinned_tab_count * (Tab::GetPinnedWidth() + kTabHorizontalOffset) + + kPinnedToNonPinnedGap; } Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { @@ -2577,11 +2579,11 @@ void TabStrip::SwapLayoutIfNecessary() { &tabs_)); touch_layout_->SetWidth(tab_area_width()); // This has to be after SetWidth() as SetWidth() is going to reset the - // bounds of the mini-tabs (since StackedTabStripLayout doesn't yet know how - // many mini-tabs there are). - GenerateIdealBoundsForMiniTabs(NULL); - touch_layout_->SetXAndMiniCount(GetStartXForNormalTabs(), - GetMiniTabCount()); + // bounds of the pinned tabs (since StackedTabStripLayout doesn't yet know + // how many pinned tabs there are). + GenerateIdealBoundsForPinnedTabs(NULL); + touch_layout_->SetXAndPinnedCount(GetStartXForNormalTabs(), + GetPinnedTabCount()); touch_layout_->SetActiveIndex(controller_->GetActiveIndex()); content::RecordAction(UserMetricsAction("StackedTab_EnteredStackedLayout")); @@ -2598,9 +2600,9 @@ bool TabStrip::NeedsTouchLayout() const { if (!stacked_layout_) return false; - int mini_tab_count = GetMiniTabCount(); - int normal_count = tab_count() - mini_tab_count; - if (normal_count <= 1 || normal_count == mini_tab_count) + int pinned_tab_count = GetPinnedTabCount(); + int normal_count = tab_count() - pinned_tab_count; + if (normal_count <= 1 || normal_count == pinned_tab_count) return false; int x = GetStartXForNormalTabs(); int available_width = tab_area_width() - x; diff --git a/chrome/browser/ui/views/tabs/tab_strip.h b/chrome/browser/ui/views/tabs/tab_strip.h index 49eca4d..a8153da 100644 --- a/chrome/browser/ui/views/tabs/tab_strip.h +++ b/chrome/browser/ui/views/tabs/tab_strip.h @@ -310,8 +310,8 @@ class TabStrip : public views::View, DISALLOW_COPY_AND_ASSIGN(DropInfo); }; - // Horizontal gap between mini and non-mini-tabs. - static const int kMiniToNonMiniGap; + // Horizontal gap between pinned and non-pinned tabs. + static const int kPinnedToNonPinnedGap; void Init(); @@ -378,8 +378,8 @@ class TabStrip : public views::View, // and drop to calculate offsets and positioning. int GetSizeNeededForTabs(const Tabs& tabs); - // Returns the number of mini-tabs. - int GetMiniTabCount() const; + // Returns the number of pinned tabs. + int GetPinnedTabCount() const; // Returns the last tab in the strip that's actually visible. This will be // the actual last tab unless the strip is in the overflow state. @@ -448,10 +448,10 @@ class TabStrip : public views::View, // desired strip width and number of tabs. If // |width_of_tabs_for_mouse_close_| is nonnegative we use that value in // calculating the desired strip width; otherwise we use the current width. - // |mini_tab_count| gives the number of mini-tabs and |tab_count| the number - // of mini and non-mini-tabs. + // |pinned_tab_count| gives the number of pinned tabs and |tab_count| the + // number of pinned and non-pinned tabs. void GetDesiredTabWidths(int tab_count, - int mini_tab_count, + int pinned_tab_count, double* unselected_width, double* selected_width) const; @@ -503,10 +503,10 @@ class TabStrip : public views::View, // button. void GenerateIdealBounds(); - // Generates the ideal bounds for the mini tabs. Returns the index to position - // the first non-mini tab and sets |first_non_mini_index| to the index of the - // first non-mini tab. - int GenerateIdealBoundsForMiniTabs(int* first_non_mini_index); + // Generates the ideal bounds for the pinned tabs. Returns the index to + // position the first non-pinned tab and sets |first_non_pinned_index| to the + // index of the first non-pinned tab. + int GenerateIdealBoundsForPinnedTabs(int* first_non_pinned_index); // Returns the width needed for the new tab button (and padding). static int new_tab_button_width() { @@ -519,7 +519,7 @@ class TabStrip : public views::View, // Starts various types of TabStrip animations. void StartResizeLayoutAnimation(); - void StartMiniTabAnimation(); + void StartPinnedTabAnimation(); void StartMouseInitiatedRemoveTabAnimation(int model_index); // Returns true if the specified point in TabStrip coords is within the diff --git a/chrome/browser/ui/views/tabs/tab_unittest.cc b/chrome/browser/ui/views/tabs/tab_unittest.cc index 71aee7e..a54c2b1 100644 --- a/chrome/browser/ui/views/tabs/tab_unittest.cc +++ b/chrome/browser/ui/views/tabs/tab_unittest.cc @@ -96,7 +96,7 @@ class TabTest : public views::ViewsTestBase, static void CheckForExpectedLayoutAndVisibilityOfElements(const Tab& tab) { // Check whether elements are visible when they are supposed to be, given // Tab size and TabRendererData state. - if (tab.data_.mini) { + if (tab.data_.pinned) { EXPECT_EQ(1, tab.IconCapacity()); if (tab.data_.media_state != TAB_MEDIA_STATE_NONE) { EXPECT_FALSE(tab.ShouldShowIcon()); @@ -132,7 +132,7 @@ class TabTest : public views::ViewsTestBase, EXPECT_FALSE(tab.ShouldShowMediaIndicator()); break; } - } else { // Tab not active and not mini tab. + } else { // Tab not active and not pinned tab. switch (tab.IconCapacity()) { case 0: EXPECT_FALSE(tab.ShouldShowCloseBox()); @@ -271,7 +271,7 @@ TEST_P(TabTest, LayoutAndVisibilityOfElements) { // Perform layout over all possible combinations, checking for correct // results. - for (int is_mini_tab = 0; is_mini_tab < 2; ++is_mini_tab) { + for (int is_pinned_tab = 0; is_pinned_tab < 2; ++is_pinned_tab) { for (int is_active_tab = 0; is_active_tab < 2; ++is_active_tab) { for (size_t media_state_index = 0; media_state_index < arraysize(kMediaStatesToTest); @@ -279,10 +279,10 @@ TEST_P(TabTest, LayoutAndVisibilityOfElements) { const TabMediaState media_state = kMediaStatesToTest[media_state_index]; SCOPED_TRACE(::testing::Message() << (is_active_tab ? "Active" : "Inactive") << ' ' - << (is_mini_tab ? "Mini " : "") + << (is_pinned_tab ? "Pinned " : "") << "Tab with media indicator state " << media_state); - data.mini = !!is_mini_tab; + data.pinned = !!is_pinned_tab; controller.set_active_tab(!!is_active_tab); data.media_state = media_state; tab.SetData(data); @@ -290,9 +290,9 @@ TEST_P(TabTest, LayoutAndVisibilityOfElements) { // Test layout for every width from standard to minimum. gfx::Rect bounds(gfx::Point(0, 0), Tab::GetStandardSize()); int min_width; - if (is_mini_tab) { - bounds.set_width(Tab::GetMiniWidth()); - min_width = Tab::GetMiniWidth(); + if (is_pinned_tab) { + bounds.set_width(Tab::GetPinnedWidth()); + min_width = Tab::GetPinnedWidth(); } else { min_width = is_active_tab ? Tab::GetMinimumSelectedSize().width() : Tab::GetMinimumUnselectedSize().width(); |