| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cocoa/tab_strip_controller.h" | 5 #import "chrome/browser/cocoa/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 | 10 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 - (void)addSubviewToPermanentList:(NSView*)aView; | 100 - (void)addSubviewToPermanentList:(NSView*)aView; |
| 101 - (void)regenerateSubviewList; | 101 - (void)regenerateSubviewList; |
| 102 - (NSInteger)indexForContentsView:(NSView*)view; | 102 - (NSInteger)indexForContentsView:(NSView*)view; |
| 103 - (void)updateFavIconForContents:(TabContents*)contents | 103 - (void)updateFavIconForContents:(TabContents*)contents |
| 104 atIndex:(NSInteger)index; | 104 atIndex:(NSInteger)index; |
| 105 - (void)layoutTabsWithAnimation:(BOOL)animate | 105 - (void)layoutTabsWithAnimation:(BOOL)animate |
| 106 regenerateSubviews:(BOOL)doUpdate; | 106 regenerateSubviews:(BOOL)doUpdate; |
| 107 - (void)animationDidStopForController:(TabController*)controller | 107 - (void)animationDidStopForController:(TabController*)controller |
| 108 finished:(BOOL)finished; | 108 finished:(BOOL)finished; |
| 109 - (NSInteger)indexFromModelIndex:(NSInteger)index; | 109 - (NSInteger)indexFromModelIndex:(NSInteger)index; |
| 110 - (void)mouseMoved:(NSEvent*)event; |
| 110 @end | 111 @end |
| 111 | 112 |
| 112 // A simple view class that prevents the Window Server from dragging the area | 113 // A simple view class that prevents the Window Server from dragging the area |
| 113 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also | 114 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also |
| 114 // falsely pick up clicks during rapid tab closure, so we have to account for | 115 // falsely pick up clicks during rapid tab closure, so we have to account for |
| 115 // that. | 116 // that. |
| 116 @interface TabStripControllerDragBlockingView : NSView { | 117 @interface TabStripControllerDragBlockingView : NSView { |
| 117 TabStripController* controller_; // weak; owns us | 118 TabStripController* controller_; // weak; owns us |
| 118 } | 119 } |
| 119 | 120 |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 // controller and remove the view from the strip. | 886 // controller and remove the view from the strip. |
| 886 - (void)removeTab:(TabController*)controller { | 887 - (void)removeTab:(TabController*)controller { |
| 887 NSUInteger index = [tabArray_ indexOfObject:controller]; | 888 NSUInteger index = [tabArray_ indexOfObject:controller]; |
| 888 | 889 |
| 889 // Release the tab contents controller so those views get destroyed. This | 890 // Release the tab contents controller so those views get destroyed. This |
| 890 // will remove all the tab content Cocoa views from the hierarchy. A | 891 // will remove all the tab content Cocoa views from the hierarchy. A |
| 891 // subsequent "select tab" notification will follow from the model. To | 892 // subsequent "select tab" notification will follow from the model. To |
| 892 // tell us what to swap in in its absence. | 893 // tell us what to swap in in its absence. |
| 893 [tabContentsArray_ removeObjectAtIndex:index]; | 894 [tabContentsArray_ removeObjectAtIndex:index]; |
| 894 | 895 |
| 896 NSView* tab = [controller view]; |
| 897 |
| 898 // Stop observing the tab's tracking areas. |
| 899 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 900 [defaultCenter removeObserver:self |
| 901 name:NSViewDidUpdateTrackingAreasNotification |
| 902 object:tab]; |
| 903 |
| 895 // Remove the view from the tab strip. | 904 // Remove the view from the tab strip. |
| 896 NSView* tab = [controller view]; | |
| 897 [tab removeFromSuperview]; | 905 [tab removeFromSuperview]; |
| 898 | 906 |
| 899 // Clear the tab controller's target. | 907 // Clear the tab controller's target. |
| 900 // TODO(viettrungluu): [crbug.com/23829] Find a better way to handle the tab | 908 // TODO(viettrungluu): [crbug.com/23829] Find a better way to handle the tab |
| 901 // controller's target. | 909 // controller's target. |
| 902 [controller setTarget:nil]; | 910 [controller setTarget:nil]; |
| 903 | 911 |
| 904 if ([hoveredTab_ isEqual:tab]) | 912 if ([hoveredTab_ isEqual:tab]) |
| 905 hoveredTab_ = nil; | 913 hoveredTab_ = nil; |
| 906 | 914 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 | 1184 |
| 1177 // Called when the tab strip view changes size. As we only registered for | 1185 // Called when the tab strip view changes size. As we only registered for |
| 1178 // changes on our view, we know it's only for our view. Layout w/out | 1186 // changes on our view, we know it's only for our view. Layout w/out |
| 1179 // animations since they are blocked by the resize nested runloop. We need | 1187 // animations since they are blocked by the resize nested runloop. We need |
| 1180 // the views to adjust immediately. Neither the tabs nor their z-order are | 1188 // the views to adjust immediately. Neither the tabs nor their z-order are |
| 1181 // changed, so we don't need to update the subviews. | 1189 // changed, so we don't need to update the subviews. |
| 1182 - (void)tabViewFrameChanged:(NSNotification*)info { | 1190 - (void)tabViewFrameChanged:(NSNotification*)info { |
| 1183 [self layoutTabsWithAnimation:NO regenerateSubviews:NO]; | 1191 [self layoutTabsWithAnimation:NO regenerateSubviews:NO]; |
| 1184 } | 1192 } |
| 1185 | 1193 |
| 1194 // Called when the tracking areas for any given tab are updated. This allows |
| 1195 // the individual tabs to update their hover states correctly. |
| 1196 // Only generates the event if the cursor is in the tab strip. |
| 1197 - (void)tabUpdateTracking:(NSNotification*)notification { |
| 1198 DCHECK([[notification object] isKindOfClass:[TabView class]]); |
| 1199 NSWindow* window = [tabView_ window]; |
| 1200 NSPoint location = [window mouseLocationOutsideOfEventStream]; |
| 1201 if (NSPointInRect(location, [tabView_ frame])) { |
| 1202 NSEvent* mouseEvent = [NSEvent mouseEventWithType:NSMouseMoved |
| 1203 location:location |
| 1204 modifierFlags:0 |
| 1205 timestamp:0 |
| 1206 windowNumber:[window windowNumber] |
| 1207 context:nil |
| 1208 eventNumber:0 |
| 1209 clickCount:0 |
| 1210 pressure:0]; |
| 1211 [self mouseMoved:mouseEvent]; |
| 1212 } |
| 1213 } |
| 1214 |
| 1186 - (BOOL)inRapidClosureMode { | 1215 - (BOOL)inRapidClosureMode { |
| 1187 return availableResizeWidth_ != kUseFullAvailableWidth; | 1216 return availableResizeWidth_ != kUseFullAvailableWidth; |
| 1188 } | 1217 } |
| 1189 | 1218 |
| 1190 // Disable tab dragging when there are any pending animations. | 1219 // Disable tab dragging when there are any pending animations. |
| 1191 - (BOOL)tabDraggingAllowed { | 1220 - (BOOL)tabDraggingAllowed { |
| 1192 return [closingControllers_ count] == 0; | 1221 return [closingControllers_ count] == 0; |
| 1193 } | 1222 } |
| 1194 | 1223 |
| 1195 - (void)mouseMoved:(NSEvent*)event { | 1224 - (void)mouseMoved:(NSEvent*)event { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 [permanentSubviews_ addObject:aView]; | 1274 [permanentSubviews_ addObject:aView]; |
| 1246 } | 1275 } |
| 1247 | 1276 |
| 1248 // Update the subviews, keeping the permanent ones (or, more correctly, putting | 1277 // Update the subviews, keeping the permanent ones (or, more correctly, putting |
| 1249 // in the ones listed in permanentSubviews_), and putting in the current tabs in | 1278 // in the ones listed in permanentSubviews_), and putting in the current tabs in |
| 1250 // the correct z-order. Any current subviews which is neither in the permanent | 1279 // the correct z-order. Any current subviews which is neither in the permanent |
| 1251 // list nor a (current) tab will be removed. So if you add such a subview, you | 1280 // list nor a (current) tab will be removed. So if you add such a subview, you |
| 1252 // should call |-addSubviewToPermanentList:| (or better yet, call that and then | 1281 // should call |-addSubviewToPermanentList:| (or better yet, call that and then |
| 1253 // |-regenerateSubviewList| to actually add it). | 1282 // |-regenerateSubviewList| to actually add it). |
| 1254 - (void)regenerateSubviewList { | 1283 - (void)regenerateSubviewList { |
| 1284 // Remove self as an observer from all the old tabs before a new set of |
| 1285 // potentially different tabs is put in place. |
| 1286 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 1287 for (NSView* view in [tabView_ subviews]) { |
| 1288 [defaultCenter removeObserver:self |
| 1289 name:NSViewDidUpdateTrackingAreasNotification |
| 1290 object:view]; |
| 1291 } |
| 1292 |
| 1255 // Subviews to put in (in bottom-to-top order), beginning with the permanent | 1293 // Subviews to put in (in bottom-to-top order), beginning with the permanent |
| 1256 // ones. | 1294 // ones. |
| 1257 NSMutableArray* subviews = [NSMutableArray arrayWithArray:permanentSubviews_]; | 1295 NSMutableArray* subviews = [NSMutableArray arrayWithArray:permanentSubviews_]; |
| 1258 | 1296 |
| 1259 NSView* selectedTabView = nil; | 1297 NSView* selectedTabView = nil; |
| 1260 // Go through tabs in reverse order, since |subviews| is bottom-to-top. | 1298 // Go through tabs in reverse order, since |subviews| is bottom-to-top. |
| 1261 for (TabController* tab in [tabArray_.get() reverseObjectEnumerator]) { | 1299 for (TabController* tab in [tabArray_.get() reverseObjectEnumerator]) { |
| 1300 NSView* tabView = [tab view]; |
| 1301 |
| 1302 // Set self up to observe tabs so hover states will be correct as tabs move. |
| 1303 [defaultCenter addObserver:self |
| 1304 selector:@selector(tabUpdateTracking:) |
| 1305 name:NSViewDidUpdateTrackingAreasNotification |
| 1306 object:tabView]; |
| 1307 |
| 1262 if ([tab selected]) { | 1308 if ([tab selected]) { |
| 1263 DCHECK(!selectedTabView); | 1309 DCHECK(!selectedTabView); |
| 1264 selectedTabView = [tab view]; | 1310 selectedTabView = tabView; |
| 1265 } else { | 1311 } else { |
| 1266 [subviews addObject:[tab view]]; | 1312 [subviews addObject:tabView]; |
| 1267 } | 1313 } |
| 1268 } | 1314 } |
| 1269 if (selectedTabView) | 1315 if (selectedTabView) |
| 1270 [subviews addObject:selectedTabView]; | 1316 [subviews addObject:selectedTabView]; |
| 1271 | 1317 |
| 1272 [tabView_ setSubviews:subviews]; | 1318 [tabView_ setSubviews:subviews]; |
| 1273 } | 1319 } |
| 1274 | 1320 |
| 1275 - (GTMWindowSheetController*)sheetController { | 1321 - (GTMWindowSheetController*)sheetController { |
| 1276 if (!sheetController_.get()) | 1322 if (!sheetController_.get()) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1378 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 1333 BrowserWindowController* controller = | 1379 BrowserWindowController* controller = |
| 1334 (BrowserWindowController*)[[switchView_ window] windowController]; | 1380 (BrowserWindowController*)[[switchView_ window] windowController]; |
| 1335 DCHECK(index >= 0); | 1381 DCHECK(index >= 0); |
| 1336 if (index >= 0) { | 1382 if (index >= 0) { |
| 1337 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; | 1383 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; |
| 1338 } | 1384 } |
| 1339 } | 1385 } |
| 1340 | 1386 |
| 1341 @end | 1387 @end |
| OLD | NEW |