OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <limits> | 9 #include <limits> |
10 #include <string> | 10 #include <string> |
11 | 11 |
(...skipping 18 matching lines...) Expand all Loading... | |
30 #import "chrome/browser/ui/cocoa/constrained_window_mac.h" | 30 #import "chrome/browser/ui/cocoa/constrained_window_mac.h" |
31 #import "chrome/browser/ui/cocoa/new_tab_button.h" | 31 #import "chrome/browser/ui/cocoa/new_tab_button.h" |
32 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 32 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
33 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" | 33 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" |
34 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 34 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
35 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 35 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
36 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" | 36 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" |
37 #import "chrome/browser/ui/cocoa/tracking_area.h" | 37 #import "chrome/browser/ui/cocoa/tracking_area.h" |
38 #include "chrome/browser/ui/find_bar/find_bar.h" | 38 #include "chrome/browser/ui/find_bar/find_bar.h" |
39 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 39 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
40 #include "chrome/browser/ui/title_prefix_matcher.h" | |
40 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 41 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
41 #include "content/browser/tab_contents/navigation_controller.h" | 42 #include "content/browser/tab_contents/navigation_controller.h" |
42 #include "content/browser/tab_contents/navigation_entry.h" | 43 #include "content/browser/tab_contents/navigation_entry.h" |
43 #include "content/browser/tab_contents/tab_contents.h" | 44 #include "content/browser/tab_contents/tab_contents.h" |
44 #include "content/browser/tab_contents/tab_contents_view.h" | 45 #include "content/browser/tab_contents/tab_contents_view.h" |
45 #include "grit/app_resources.h" | 46 #include "grit/app_resources.h" |
46 #include "grit/generated_resources.h" | 47 #include "grit/generated_resources.h" |
47 #include "grit/theme_resources.h" | 48 #include "grit/theme_resources.h" |
48 #include "skia/ext/skia_utils_mac.h" | 49 #include "skia/ext/skia_utils_mac.h" |
49 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 50 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 - (NSInteger)indexFromModelIndex:(NSInteger)index; | 137 - (NSInteger)indexFromModelIndex:(NSInteger)index; |
137 - (NSInteger)numberOfOpenTabs; | 138 - (NSInteger)numberOfOpenTabs; |
138 - (NSInteger)numberOfOpenMiniTabs; | 139 - (NSInteger)numberOfOpenMiniTabs; |
139 - (NSInteger)numberOfOpenNonMiniTabs; | 140 - (NSInteger)numberOfOpenNonMiniTabs; |
140 - (void)mouseMoved:(NSEvent*)event; | 141 - (void)mouseMoved:(NSEvent*)event; |
141 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; | 142 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; |
142 - (void)droppingURLsAt:(NSPoint)point | 143 - (void)droppingURLsAt:(NSPoint)point |
143 givesIndex:(NSInteger*)index | 144 givesIndex:(NSInteger*)index |
144 disposition:(WindowOpenDisposition*)disposition; | 145 disposition:(WindowOpenDisposition*)disposition; |
145 - (void)setNewTabButtonHoverState:(BOOL)showHover; | 146 - (void)setNewTabButtonHoverState:(BOOL)showHover; |
147 - (void)updateCommonTitlePrefix; | |
146 @end | 148 @end |
147 | 149 |
148 // A simple view class that prevents the Window Server from dragging the area | 150 // A simple view class that prevents the Window Server from dragging the area |
149 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also | 151 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also |
150 // falsely pick up clicks during rapid tab closure, so we have to account for | 152 // falsely pick up clicks during rapid tab closure, so we have to account for |
151 // that. | 153 // that. |
152 @interface TabStripControllerDragBlockingView : NSView { | 154 @interface TabStripControllerDragBlockingView : NSView { |
153 TabStripController* controller_; // weak; owns us | 155 TabStripController* controller_; // weak; owns us |
154 } | 156 } |
155 | 157 |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1016 [self layoutTabs]; | 1018 [self layoutTabs]; |
1017 } | 1019 } |
1018 | 1020 |
1019 // During normal loading, we won't yet have a favicon and we'll get | 1021 // During normal loading, we won't yet have a favicon and we'll get |
1020 // subsequent state change notifications to show the throbber, but when we're | 1022 // subsequent state change notifications to show the throbber, but when we're |
1021 // dragging a tab out into a new window, we have to put the tab's favicon | 1023 // dragging a tab out into a new window, we have to put the tab's favicon |
1022 // into the right state up front as we won't be told to do it from anywhere | 1024 // into the right state up front as we won't be told to do it from anywhere |
1023 // else. | 1025 // else. |
1024 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; | 1026 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; |
1025 | 1027 |
1028 [self updateCommonTitlePrefix]; | |
1029 | |
1026 // Send a broadcast that the number of tabs have changed. | 1030 // Send a broadcast that the number of tabs have changed. |
1027 [[NSNotificationCenter defaultCenter] | 1031 [[NSNotificationCenter defaultCenter] |
1028 postNotificationName:kTabStripNumberOfTabsChanged | 1032 postNotificationName:kTabStripNumberOfTabsChanged |
1029 object:self]; | 1033 object:self]; |
1030 } | 1034 } |
1031 | 1035 |
1032 // Called when a notification is received from the model to select a particular | 1036 // Called when a notification is received from the model to select a particular |
1033 // tab. Swaps in the toolbar and content area associated with |newContents|. | 1037 // tab. Swaps in the toolbar and content area associated with |newContents|. |
1034 - (void)selectTabWithContents:(TabContentsWrapper*)newContents | 1038 - (void)selectTabWithContents:(TabContentsWrapper*)newContents |
1035 previousContents:(TabContentsWrapper*)oldContents | 1039 previousContents:(TabContentsWrapper*)oldContents |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1135 [controller setTarget:nil]; | 1139 [controller setTarget:nil]; |
1136 | 1140 |
1137 if ([hoveredTab_ isEqual:tab]) | 1141 if ([hoveredTab_ isEqual:tab]) |
1138 hoveredTab_ = nil; | 1142 hoveredTab_ = nil; |
1139 | 1143 |
1140 NSValue* identifier = [NSValue valueWithPointer:tab]; | 1144 NSValue* identifier = [NSValue valueWithPointer:tab]; |
1141 [targetFrames_ removeObjectForKey:identifier]; | 1145 [targetFrames_ removeObjectForKey:identifier]; |
1142 | 1146 |
1143 // Once we're totally done with the tab, delete its controller | 1147 // Once we're totally done with the tab, delete its controller |
1144 [tabArray_ removeObjectAtIndex:index]; | 1148 [tabArray_ removeObjectAtIndex:index]; |
1149 | |
1150 [self updateCommonTitlePrefix]; | |
1145 } | 1151 } |
1146 | 1152 |
1147 // Called by the CAAnimation delegate when the tab completes the closing | 1153 // Called by the CAAnimation delegate when the tab completes the closing |
1148 // animation. | 1154 // animation. |
1149 - (void)animationDidStopForController:(TabController*)controller | 1155 - (void)animationDidStopForController:(TabController*)controller |
1150 finished:(BOOL)finished { | 1156 finished:(BOOL)finished { |
1151 [closingControllers_ removeObject:controller]; | 1157 [closingControllers_ removeObject:controller]; |
1152 [self removeTab:controller]; | 1158 [self removeTab:controller]; |
1153 } | 1159 } |
1154 | 1160 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1330 TabController* tabController = [tabArray_ objectAtIndex:index]; | 1336 TabController* tabController = [tabArray_ objectAtIndex:index]; |
1331 | 1337 |
1332 if (change != TabStripModelObserver::LOADING_ONLY) | 1338 if (change != TabStripModelObserver::LOADING_ONLY) |
1333 [self setTabTitle:tabController withContents:contents->tab_contents()]; | 1339 [self setTabTitle:tabController withContents:contents->tab_contents()]; |
1334 | 1340 |
1335 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; | 1341 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; |
1336 | 1342 |
1337 TabContentsController* updatedController = | 1343 TabContentsController* updatedController = |
1338 [tabContentsArray_ objectAtIndex:index]; | 1344 [tabContentsArray_ objectAtIndex:index]; |
1339 [updatedController tabDidChange:contents->tab_contents()]; | 1345 [updatedController tabDidChange:contents->tab_contents()]; |
1346 | |
1347 [self updateCommonTitlePrefix]; | |
1340 } | 1348 } |
1341 | 1349 |
1342 // Called when a tab is moved (usually by drag&drop). Keep our parallel arrays | 1350 // Called when a tab is moved (usually by drag&drop). Keep our parallel arrays |
1343 // in sync with the tab strip model. It can also be pinned/unpinned | 1351 // in sync with the tab strip model. It can also be pinned/unpinned |
1344 // simultaneously, so we need to take care of that. | 1352 // simultaneously, so we need to take care of that. |
1345 - (void)tabMovedWithContents:(TabContentsWrapper*)contents | 1353 - (void)tabMovedWithContents:(TabContentsWrapper*)contents |
1346 fromIndex:(NSInteger)modelFrom | 1354 fromIndex:(NSInteger)modelFrom |
1347 toIndex:(NSInteger)modelTo { | 1355 toIndex:(NSInteger)modelTo { |
1348 // Take closing tabs into account. | 1356 // Take closing tabs into account. |
1349 NSInteger from = [self indexFromModelIndex:modelFrom]; | 1357 NSInteger from = [self indexFromModelIndex:modelFrom]; |
(...skipping 11 matching lines...) Expand all Loading... | |
1361 [tabArray_ insertObject:movedTabController.get() atIndex:to]; | 1369 [tabArray_ insertObject:movedTabController.get() atIndex:to]; |
1362 | 1370 |
1363 // The tab moved, which means that the mini-tab state may have changed. | 1371 // The tab moved, which means that the mini-tab state may have changed. |
1364 if (tabStripModel_->IsMiniTab(modelTo) != [movedTabController mini]) | 1372 if (tabStripModel_->IsMiniTab(modelTo) != [movedTabController mini]) |
1365 [self tabMiniStateChangedWithContents:contents atIndex:modelTo]; | 1373 [self tabMiniStateChangedWithContents:contents atIndex:modelTo]; |
1366 | 1374 |
1367 [self layoutTabs]; | 1375 [self layoutTabs]; |
1368 } | 1376 } |
1369 | 1377 |
1370 // Called when a tab is pinned or unpinned without moving. | 1378 // Called when a tab is pinned or unpinned without moving. |
1371 - (void)tabMiniStateChangedWithContents:(TabContentsWrapper*)contents | 1379 - (void)tabMiniStateChangedWithContents:(TabContentsWrapper*)contents |
Robert Sesek
2011/03/21 19:09:14
If a tab is unpinned, do you need to call |-update
sail
2011/03/22 00:47:00
Done.
| |
1372 atIndex:(NSInteger)modelIndex { | 1380 atIndex:(NSInteger)modelIndex { |
1373 // Take closing tabs into account. | 1381 // Take closing tabs into account. |
1374 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1382 NSInteger index = [self indexFromModelIndex:modelIndex]; |
1375 | 1383 |
1376 TabController* tabController = [tabArray_ objectAtIndex:index]; | 1384 TabController* tabController = [tabArray_ objectAtIndex:index]; |
1377 DCHECK([tabController isKindOfClass:[TabController class]]); | 1385 DCHECK([tabController isKindOfClass:[TabController class]]); |
1378 | 1386 |
1379 // Don't do anything if the change was already picked up by the move event. | 1387 // Don't do anything if the change was already picked up by the move event. |
1380 if (tabStripModel_->IsMiniTab(modelIndex) == [tabController mini]) | 1388 if (tabStripModel_->IsMiniTab(modelIndex) == [tabController mini]) |
1381 return; | 1389 return; |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1899 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; | 1907 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; |
1900 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1908 NSInteger index = [self indexFromModelIndex:modelIndex]; |
1901 BrowserWindowController* controller = | 1909 BrowserWindowController* controller = |
1902 (BrowserWindowController*)[[switchView_ window] windowController]; | 1910 (BrowserWindowController*)[[switchView_ window] windowController]; |
1903 DCHECK(index >= 0); | 1911 DCHECK(index >= 0); |
1904 if (index >= 0) { | 1912 if (index >= 0) { |
1905 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; | 1913 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; |
1906 } | 1914 } |
1907 } | 1915 } |
1908 | 1916 |
1917 - (void)updateCommonTitlePrefix { | |
pink (ping after 24hrs)
2011/03/21 13:31:38
this method needs a comment
Robert Sesek
2011/03/21 19:09:14
+1. Each loop should probably have one, too.
sail
2011/03/22 00:47:00
Done.
sail
2011/03/22 00:47:00
Done.
| |
1918 std::vector<TitlePrefixMatcher::TitleInfo> tabTitleInfos; | |
1919 int tabIndex = 0; | |
1920 for (TabController* tabController in tabArray_.get()) { | |
1921 TabContentsController* tabContentsController = | |
1922 [tabContentsArray_ objectAtIndex:tabIndex]; | |
pink (ping after 24hrs)
2011/03/21 13:31:38
continuations indented 4 additional spaces.
sail
2011/03/22 00:47:00
Done.
| |
1923 TabContents* tabContents = [tabContentsController tabContents]; | |
1924 if (!tabContents->GetTitle().empty() && ![tabController mini]) { | |
1925 tabTitleInfos.push_back(TitlePrefixMatcher::TitleInfo( | |
1926 &(tabContents->GetTitle()), tabIndex)); | |
1927 } | |
1928 } | |
1929 TitlePrefixMatcher::CalculatePrefixLengths(&tabTitleInfos); | |
1930 | |
1931 for (size_t infoIndex = 0; infoIndex < tabTitleInfos.size(); infoIndex++) { | |
pink (ping after 24hrs)
2011/03/21 13:31:38
++infoIndex, not that it really matters.
sail
2011/03/22 00:47:00
Done.
| |
1932 tabIndex = tabTitleInfos[infoIndex].caller_value; | |
1933 TabController* tabController = [tabArray_ objectAtIndex:tabIndex]; | |
pink (ping after 24hrs)
2011/03/21 13:31:38
you should DCHECK tabIndex < array length to ensur
sail
2011/03/22 00:47:00
Done.
| |
1934 [tabController setTitleCommonPrefixLength: | |
1935 tabTitleInfos[infoIndex].prefix_length]; | |
1936 } | |
1937 } | |
1938 | |
1909 @end | 1939 @end |
OLD | NEW |