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

Side by Side Diff: chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm

Issue 157403004: [mac] Implement dragging of multiple tabs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes for rsesek. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
6 6
7 #import <QuartzCore/QuartzCore.h> 7 #import <QuartzCore/QuartzCore.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <limits> 10 #include <limits>
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 continue; 781 continue;
782 } else if ([current view] == view) { 782 } else if ([current view] == view) {
783 return index; 783 return index;
784 } 784 }
785 ++index; 785 ++index;
786 ++i; 786 ++i;
787 } 787 }
788 return -1; 788 return -1;
789 } 789 }
790 790
791 - (NSArray*)selectedViews {
792 NSMutableArray* views = [NSMutableArray arrayWithCapacity:[tabArray_ count]];
793 for (TabController* tab in tabArray_.get()) {
794 if ([tab selected])
795 [views addObject:[tab tabView]];
796 }
797 return views;
798 }
791 799
792 // Returns the view at the given index, using the array of TabControllers to 800 // Returns the view at the given index, using the array of TabControllers to
793 // get the associated view. Returns nil if out of range. 801 // get the associated view. Returns nil if out of range.
794 - (NSView*)viewAtIndex:(NSUInteger)index { 802 - (NSView*)viewAtIndex:(NSUInteger)index {
795 if (index >= [tabArray_ count]) 803 if (index >= [tabArray_ count])
796 return NULL; 804 return NULL;
797 return [[tabArray_ objectAtIndex:index] view]; 805 return [[tabArray_ objectAtIndex:index] view];
798 } 806 }
799 807
800 - (NSUInteger)viewsCount { 808 - (NSUInteger)viewsCount {
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; 1716 [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)];
1709 [tabController setApp:tabStripModel_->IsAppTab(modelIndex)]; 1717 [tabController setApp:tabStripModel_->IsAppTab(modelIndex)];
1710 [tabController setUrl:contents->GetURL()]; 1718 [tabController setUrl:contents->GetURL()];
1711 [self updateIconsForContents:contents atIndex:modelIndex]; 1719 [self updateIconsForContents:contents atIndex:modelIndex];
1712 // If the tab is being restored and it's pinned, the mini state is set after 1720 // If the tab is being restored and it's pinned, the mini state is set after
1713 // the tab has already been rendered, so re-layout the tabstrip. In all other 1721 // the tab has already been rendered, so re-layout the tabstrip. In all other
1714 // cases, the state is set before the tab is rendered so this isn't needed. 1722 // cases, the state is set before the tab is rendered so this isn't needed.
1715 [self layoutTabs]; 1723 [self layoutTabs];
1716 } 1724 }
1717 1725
1718 - (void)setFrameOfActiveTab:(NSRect)frame { 1726 - (void)setFrame:(NSRect)frame ofTabView:(NSView*)view {
1719 NSView* view = [self activeTabView];
1720 NSValue* identifier = [NSValue valueWithPointer:view]; 1727 NSValue* identifier = [NSValue valueWithPointer:view];
1721 [targetFrames_ setObject:[NSValue valueWithRect:frame] 1728 [targetFrames_ setObject:[NSValue valueWithRect:frame]
1722 forKey:identifier]; 1729 forKey:identifier];
1723 [view setFrame:frame]; 1730 [view setFrame:frame];
1724 } 1731 }
1725 1732
1726 - (TabStripModel*)tabStripModel { 1733 - (TabStripModel*)tabStripModel {
1727 return tabStripModel_; 1734 return tabStripModel_;
1728 } 1735 }
1729 1736
1737 - (NSArray*)tabViews {
1738 NSMutableArray* views = [NSMutableArray arrayWithCapacity:[tabArray_ count]];
1739 for (TabController* tab in tabArray_.get()) {
1740 [views addObject:[tab tabView]];
1741 }
1742 return views;
1743 }
1744
1730 - (NSView*)activeTabView { 1745 - (NSView*)activeTabView {
1731 int activeIndex = tabStripModel_->active_index(); 1746 int activeIndex = tabStripModel_->active_index();
1732 // Take closing tabs into account. They can't ever be selected. 1747 // Take closing tabs into account. They can't ever be selected.
1733 activeIndex = [self indexFromModelIndex:activeIndex]; 1748 activeIndex = [self indexFromModelIndex:activeIndex];
1734 return [self viewAtIndex:activeIndex]; 1749 return [self viewAtIndex:activeIndex];
1735 } 1750 }
1736 1751
1737 // Find the model index based on the x coordinate of the placeholder. If there
1738 // is no placeholder, this returns the end of the tab strip. Closing tabs are
1739 // not considered in computing the index.
1740 - (int)indexOfPlaceholder { 1752 - (int)indexOfPlaceholder {
1753 // Use |tabArray_| here instead of the tab strip count in order to get the
1754 // correct index when there are closing tabs to the left of the placeholder.
1755 const int count = [tabArray_ count];
1756
1757 // No placeholder, return the end of the strip.
1758 if (placeholderTab_ == nil)
1759 return count;
1760
1741 double placeholderX = placeholderFrame_.origin.x; 1761 double placeholderX = placeholderFrame_.origin.x;
1742 int index = 0; 1762 int index = 0;
1743 int location = 0; 1763 int location = 0;
1744 // Use |tabArray_| here instead of the tab strip count in order to get the
1745 // correct index when there are closing tabs to the left of the placeholder.
1746 const int count = [tabArray_ count];
1747 while (index < count) { 1764 while (index < count) {
1748 // Ignore closing tabs for simplicity. The only drawback of this is that 1765 // Ignore closing tabs for simplicity. The only drawback of this is that
1749 // if the placeholder is placed right before one or several contiguous 1766 // if the placeholder is placed right before one or several contiguous
1750 // currently closing tabs, the associated TabController will start at the 1767 // currently closing tabs, the associated TabController will start at the
1751 // end of the closing tabs. 1768 // end of the closing tabs.
1752 if ([closingControllers_ containsObject:[tabArray_ objectAtIndex:index]]) { 1769 if ([closingControllers_ containsObject:[tabArray_ objectAtIndex:index]]) {
1753 index++; 1770 index++;
1754 continue; 1771 continue;
1755 } 1772 }
1756 NSView* curr = [self viewAtIndex:index]; 1773 NSView* curr = [self viewAtIndex:index];
(...skipping 25 matching lines...) Expand all
1782 // Drop a given WebContents at the location of the current placeholder. 1799 // Drop a given WebContents at the location of the current placeholder.
1783 // If there is no placeholder, it will go at the end. Used when dragging from 1800 // If there is no placeholder, it will go at the end. Used when dragging from
1784 // another window when we don't have access to the WebContents as part of our 1801 // another window when we don't have access to the WebContents as part of our
1785 // strip. |frame| is in the coordinate system of the tab strip view and 1802 // strip. |frame| is in the coordinate system of the tab strip view and
1786 // represents where the user dropped the new tab so it can be animated into its 1803 // represents where the user dropped the new tab so it can be animated into its
1787 // correct location when the tab is added to the model. If the tab was pinned in 1804 // correct location when the tab is added to the model. If the tab was pinned in
1788 // its previous window, setting |pinned| to YES will propagate that state to the 1805 // its previous window, setting |pinned| to YES will propagate that state to the
1789 // new window. Mini-tabs are either app or pinned tabs; the app state is stored 1806 // new window. Mini-tabs are either app or pinned tabs; the app state is stored
1790 // by the |contents|, but the |pinned| state is the caller's responsibility. 1807 // by the |contents|, but the |pinned| state is the caller's responsibility.
1791 - (void)dropWebContents:(WebContents*)contents 1808 - (void)dropWebContents:(WebContents*)contents
1809 atIndex:(int)modelIndex
1792 withFrame:(NSRect)frame 1810 withFrame:(NSRect)frame
1793 asPinnedTab:(BOOL)pinned { 1811 asPinnedTab:(BOOL)pinned
1794 int modelIndex = [self indexOfPlaceholder]; 1812 activate:(BOOL)activate {
1795
1796 // Mark that the new tab being created should start at |frame|. It will be 1813 // Mark that the new tab being created should start at |frame|. It will be
1797 // reset as soon as the tab has been positioned. 1814 // reset as soon as the tab has been positioned.
1798 droppedTabFrame_ = frame; 1815 droppedTabFrame_ = frame;
1799 1816
1800 // Insert it into this tab strip. We want it in the foreground and to not 1817 // Insert it into this tab strip. We want it in the foreground and to not
1801 // inherit the current tab's group. 1818 // inherit the current tab's group.
1802 tabStripModel_->InsertWebContentsAt( 1819 tabStripModel_->InsertWebContentsAt(
1803 modelIndex, contents, 1820 modelIndex,
1804 TabStripModel::ADD_ACTIVE | (pinned ? TabStripModel::ADD_PINNED : 0)); 1821 contents,
1822 (activate ? TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE) |
1823 (pinned ? TabStripModel::ADD_PINNED : TabStripModel::ADD_NONE));
1805 } 1824 }
1806 1825
1807 // Called when the tab strip view changes size. As we only registered for 1826 // Called when the tab strip view changes size. As we only registered for
1808 // changes on our view, we know it's only for our view. Layout w/out 1827 // changes on our view, we know it's only for our view. Layout w/out
1809 // animations since they are blocked by the resize nested runloop. We need 1828 // animations since they are blocked by the resize nested runloop. We need
1810 // the views to adjust immediately. Neither the tabs nor their z-order are 1829 // the views to adjust immediately. Neither the tabs nor their z-order are
1811 // changed, so we don't need to update the subviews. 1830 // changed, so we don't need to update the subviews.
1812 - (void)tabViewFrameChanged:(NSNotification*)info { 1831 - (void)tabViewFrameChanged:(NSNotification*)info {
1813 [self layoutTabsWithAnimation:NO regenerateSubviews:NO]; 1832 [self layoutTabsWithAnimation:NO regenerateSubviews:NO];
1814 } 1833 }
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
2229 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) { 2248 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) {
2230 // View hierarchy of the contents view: 2249 // View hierarchy of the contents view:
2231 // NSView -- switchView, same for all tabs 2250 // NSView -- switchView, same for all tabs
2232 // +- NSView -- TabContentsController's view 2251 // +- NSView -- TabContentsController's view
2233 // +- TabContentsViewCocoa 2252 // +- TabContentsViewCocoa
2234 // 2253 //
2235 // Changing it? Do not forget to modify 2254 // Changing it? Do not forget to modify
2236 // -[TabStripController swapInTabAtIndex:] too. 2255 // -[TabStripController swapInTabAtIndex:] too.
2237 return [web_contents->GetView()->GetNativeView() superview]; 2256 return [web_contents->GetView()->GetNativeView() superview];
2238 } 2257 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_strip_controller.h ('k') | chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698