OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #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 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
777 continue; | 777 continue; |
778 } else if ([current view] == view) { | 778 } else if ([current view] == view) { |
779 return index; | 779 return index; |
780 } | 780 } |
781 ++index; | 781 ++index; |
782 ++i; | 782 ++i; |
783 } | 783 } |
784 return -1; | 784 return -1; |
785 } | 785 } |
786 | 786 |
787 - (NSArray*)selectedViews { | |
Robert Sesek
2014/02/24 15:25:20
Header order should match declaration order.
Andre
2014/02/25 01:16:16
Done.
Robert Sesek
2014/02/25 21:06:47
Not yet. The order of the methods in the .h should
| |
788 NSMutableArray* views = [NSMutableArray arrayWithCapacity:[tabArray_ count]]; | |
789 for (TabController* tab in tabArray_.get()) { | |
790 if ([tab selected]) | |
791 [views addObject:[tab tabView]]; | |
792 } | |
793 return views; | |
794 } | |
787 | 795 |
788 // Returns the view at the given index, using the array of TabControllers to | 796 // Returns the view at the given index, using the array of TabControllers to |
789 // get the associated view. Returns nil if out of range. | 797 // get the associated view. Returns nil if out of range. |
790 - (NSView*)viewAtIndex:(NSUInteger)index { | 798 - (NSView*)viewAtIndex:(NSUInteger)index { |
791 if (index >= [tabArray_ count]) | 799 if (index >= [tabArray_ count]) |
792 return NULL; | 800 return NULL; |
793 return [[tabArray_ objectAtIndex:index] view]; | 801 return [[tabArray_ objectAtIndex:index] view]; |
794 } | 802 } |
795 | 803 |
796 - (NSUInteger)viewsCount { | 804 - (NSUInteger)viewsCount { |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1704 [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; | 1712 [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; |
1705 [tabController setApp:tabStripModel_->IsAppTab(modelIndex)]; | 1713 [tabController setApp:tabStripModel_->IsAppTab(modelIndex)]; |
1706 [tabController setUrl:contents->GetURL()]; | 1714 [tabController setUrl:contents->GetURL()]; |
1707 [self updateIconsForContents:contents atIndex:modelIndex]; | 1715 [self updateIconsForContents:contents atIndex:modelIndex]; |
1708 // If the tab is being restored and it's pinned, the mini state is set after | 1716 // If the tab is being restored and it's pinned, the mini state is set after |
1709 // the tab has already been rendered, so re-layout the tabstrip. In all other | 1717 // the tab has already been rendered, so re-layout the tabstrip. In all other |
1710 // cases, the state is set before the tab is rendered so this isn't needed. | 1718 // cases, the state is set before the tab is rendered so this isn't needed. |
1711 [self layoutTabs]; | 1719 [self layoutTabs]; |
1712 } | 1720 } |
1713 | 1721 |
1714 - (void)setFrameOfActiveTab:(NSRect)frame { | 1722 - (void)setFrame:(NSRect)frame ofTabView:(NSView*)view { |
1715 NSView* view = [self activeTabView]; | |
1716 NSValue* identifier = [NSValue valueWithPointer:view]; | 1723 NSValue* identifier = [NSValue valueWithPointer:view]; |
1717 [targetFrames_ setObject:[NSValue valueWithRect:frame] | 1724 [targetFrames_ setObject:[NSValue valueWithRect:frame] |
1718 forKey:identifier]; | 1725 forKey:identifier]; |
1719 [view setFrame:frame]; | 1726 [view setFrame:frame]; |
1720 } | 1727 } |
1721 | 1728 |
1722 - (TabStripModel*)tabStripModel { | 1729 - (TabStripModel*)tabStripModel { |
1723 return tabStripModel_; | 1730 return tabStripModel_; |
1724 } | 1731 } |
1725 | 1732 |
1733 - (NSArray*)tabViews { | |
1734 NSMutableArray* views = [NSMutableArray arrayWithCapacity:[tabArray_ count]]; | |
1735 for (TabController* tab in tabArray_.get()) { | |
1736 [views addObject:[tab tabView]]; | |
1737 } | |
1738 return views; | |
1739 } | |
1740 | |
1726 - (NSView*)activeTabView { | 1741 - (NSView*)activeTabView { |
1727 int activeIndex = tabStripModel_->active_index(); | 1742 int activeIndex = tabStripModel_->active_index(); |
1728 // Take closing tabs into account. They can't ever be selected. | 1743 // Take closing tabs into account. They can't ever be selected. |
1729 activeIndex = [self indexFromModelIndex:activeIndex]; | 1744 activeIndex = [self indexFromModelIndex:activeIndex]; |
1730 return [self viewAtIndex:activeIndex]; | 1745 return [self viewAtIndex:activeIndex]; |
1731 } | 1746 } |
1732 | 1747 |
1733 // Find the model index based on the x coordinate of the placeholder. If there | |
1734 // is no placeholder, this returns the end of the tab strip. Closing tabs are | |
1735 // not considered in computing the index. | |
1736 - (int)indexOfPlaceholder { | 1748 - (int)indexOfPlaceholder { |
1749 // Use |tabArray_| here instead of the tab strip count in order to get the | |
1750 // correct index when there are closing tabs to the left of the placeholder. | |
1751 const int count = [tabArray_ count]; | |
1752 | |
1753 // No placeholder, return the end of the strip. | |
1754 if (placeholderTab_ == nil) | |
1755 return count; | |
1756 | |
1737 double placeholderX = placeholderFrame_.origin.x; | 1757 double placeholderX = placeholderFrame_.origin.x; |
1738 int index = 0; | 1758 int index = 0; |
1739 int location = 0; | 1759 int location = 0; |
1740 // Use |tabArray_| here instead of the tab strip count in order to get the | |
1741 // correct index when there are closing tabs to the left of the placeholder. | |
1742 const int count = [tabArray_ count]; | |
1743 while (index < count) { | 1760 while (index < count) { |
1744 // Ignore closing tabs for simplicity. The only drawback of this is that | 1761 // Ignore closing tabs for simplicity. The only drawback of this is that |
1745 // if the placeholder is placed right before one or several contiguous | 1762 // if the placeholder is placed right before one or several contiguous |
1746 // currently closing tabs, the associated TabController will start at the | 1763 // currently closing tabs, the associated TabController will start at the |
1747 // end of the closing tabs. | 1764 // end of the closing tabs. |
1748 if ([closingControllers_ containsObject:[tabArray_ objectAtIndex:index]]) { | 1765 if ([closingControllers_ containsObject:[tabArray_ objectAtIndex:index]]) { |
1749 index++; | 1766 index++; |
1750 continue; | 1767 continue; |
1751 } | 1768 } |
1752 NSView* curr = [self viewAtIndex:index]; | 1769 NSView* curr = [self viewAtIndex:index]; |
(...skipping 25 matching lines...) Expand all Loading... | |
1778 // Drop a given WebContents at the location of the current placeholder. | 1795 // Drop a given WebContents at the location of the current placeholder. |
1779 // If there is no placeholder, it will go at the end. Used when dragging from | 1796 // If there is no placeholder, it will go at the end. Used when dragging from |
1780 // another window when we don't have access to the WebContents as part of our | 1797 // another window when we don't have access to the WebContents as part of our |
1781 // strip. |frame| is in the coordinate system of the tab strip view and | 1798 // strip. |frame| is in the coordinate system of the tab strip view and |
1782 // represents where the user dropped the new tab so it can be animated into its | 1799 // represents where the user dropped the new tab so it can be animated into its |
1783 // correct location when the tab is added to the model. If the tab was pinned in | 1800 // correct location when the tab is added to the model. If the tab was pinned in |
1784 // its previous window, setting |pinned| to YES will propagate that state to the | 1801 // its previous window, setting |pinned| to YES will propagate that state to the |
1785 // new window. Mini-tabs are either app or pinned tabs; the app state is stored | 1802 // new window. Mini-tabs are either app or pinned tabs; the app state is stored |
1786 // by the |contents|, but the |pinned| state is the caller's responsibility. | 1803 // by the |contents|, but the |pinned| state is the caller's responsibility. |
1787 - (void)dropWebContents:(WebContents*)contents | 1804 - (void)dropWebContents:(WebContents*)contents |
1805 atIndex:(int)modelIndex | |
1788 withFrame:(NSRect)frame | 1806 withFrame:(NSRect)frame |
1789 asPinnedTab:(BOOL)pinned { | 1807 asPinnedTab:(BOOL)pinned |
1790 int modelIndex = [self indexOfPlaceholder]; | 1808 activate:(BOOL)activate { |
1791 | |
1792 // Mark that the new tab being created should start at |frame|. It will be | 1809 // Mark that the new tab being created should start at |frame|. It will be |
1793 // reset as soon as the tab has been positioned. | 1810 // reset as soon as the tab has been positioned. |
1794 droppedTabFrame_ = frame; | 1811 droppedTabFrame_ = frame; |
1795 | 1812 |
1796 // Insert it into this tab strip. We want it in the foreground and to not | 1813 // Insert it into this tab strip. We want it in the foreground and to not |
1797 // inherit the current tab's group. | 1814 // inherit the current tab's group. |
1798 tabStripModel_->InsertWebContentsAt( | 1815 tabStripModel_->InsertWebContentsAt( |
1799 modelIndex, contents, | 1816 modelIndex, |
1800 TabStripModel::ADD_ACTIVE | (pinned ? TabStripModel::ADD_PINNED : 0)); | 1817 contents, |
1818 (activate ? TabStripModel::ADD_ACTIVE : 0) | | |
Robert Sesek
2014/02/24 15:25:20
Use ADD_NONE instead of 0, like you do in the othe
Andre
2014/02/25 01:16:16
Done.
| |
1819 (pinned ? TabStripModel::ADD_PINNED : 0)); | |
1801 } | 1820 } |
1802 | 1821 |
1803 // Called when the tab strip view changes size. As we only registered for | 1822 // Called when the tab strip view changes size. As we only registered for |
1804 // changes on our view, we know it's only for our view. Layout w/out | 1823 // changes on our view, we know it's only for our view. Layout w/out |
1805 // animations since they are blocked by the resize nested runloop. We need | 1824 // animations since they are blocked by the resize nested runloop. We need |
1806 // the views to adjust immediately. Neither the tabs nor their z-order are | 1825 // the views to adjust immediately. Neither the tabs nor their z-order are |
1807 // changed, so we don't need to update the subviews. | 1826 // changed, so we don't need to update the subviews. |
1808 - (void)tabViewFrameChanged:(NSNotification*)info { | 1827 - (void)tabViewFrameChanged:(NSNotification*)info { |
1809 [self layoutTabsWithAnimation:NO regenerateSubviews:NO]; | 1828 [self layoutTabsWithAnimation:NO regenerateSubviews:NO]; |
1810 } | 1829 } |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2225 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) { | 2244 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) { |
2226 // View hierarchy of the contents view: | 2245 // View hierarchy of the contents view: |
2227 // NSView -- switchView, same for all tabs | 2246 // NSView -- switchView, same for all tabs |
2228 // +- NSView -- TabContentsController's view | 2247 // +- NSView -- TabContentsController's view |
2229 // +- TabContentsViewCocoa | 2248 // +- TabContentsViewCocoa |
2230 // | 2249 // |
2231 // Changing it? Do not forget to modify | 2250 // Changing it? Do not forget to modify |
2232 // -[TabStripController swapInTabAtIndex:] too. | 2251 // -[TabStripController swapInTabAtIndex:] too. |
2233 return [web_contents->GetView()->GetNativeView() superview]; | 2252 return [web_contents->GetView()->GetNativeView() superview]; |
2234 } | 2253 } |
OLD | NEW |