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

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

Issue 384100: Revert 31814 - Testing to see if it caused performance problems.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/cocoa/tab_view.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
111 @end 110 @end
112 111
113 // A simple view class that prevents the Window Server from dragging the area 112 // A simple view class that prevents the Window Server from dragging the area
114 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also 113 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also
115 // falsely pick up clicks during rapid tab closure, so we have to account for 114 // falsely pick up clicks during rapid tab closure, so we have to account for
116 // that. 115 // that.
117 @interface TabStripControllerDragBlockingView : NSView { 116 @interface TabStripControllerDragBlockingView : NSView {
118 TabStripController* controller_; // weak; owns us 117 TabStripController* controller_; // weak; owns us
119 } 118 }
120 119
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 // controller and remove the view from the strip. 885 // controller and remove the view from the strip.
887 - (void)removeTab:(TabController*)controller { 886 - (void)removeTab:(TabController*)controller {
888 NSUInteger index = [tabArray_ indexOfObject:controller]; 887 NSUInteger index = [tabArray_ indexOfObject:controller];
889 888
890 // Release the tab contents controller so those views get destroyed. This 889 // Release the tab contents controller so those views get destroyed. This
891 // will remove all the tab content Cocoa views from the hierarchy. A 890 // will remove all the tab content Cocoa views from the hierarchy. A
892 // subsequent "select tab" notification will follow from the model. To 891 // subsequent "select tab" notification will follow from the model. To
893 // tell us what to swap in in its absence. 892 // tell us what to swap in in its absence.
894 [tabContentsArray_ removeObjectAtIndex:index]; 893 [tabContentsArray_ removeObjectAtIndex:index];
895 894
895 // Remove the view from the tab strip.
896 NSView* tab = [controller view]; 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
904 // Remove the view from the tab strip.
905 [tab removeFromSuperview]; 897 [tab removeFromSuperview];
906 898
907 // Clear the tab controller's target. 899 // Clear the tab controller's target.
908 // TODO(viettrungluu): [crbug.com/23829] Find a better way to handle the tab 900 // TODO(viettrungluu): [crbug.com/23829] Find a better way to handle the tab
909 // controller's target. 901 // controller's target.
910 [controller setTarget:nil]; 902 [controller setTarget:nil];
911 903
912 if ([hoveredTab_ isEqual:tab]) 904 if ([hoveredTab_ isEqual:tab])
913 hoveredTab_ = nil; 905 hoveredTab_ = nil;
914 906
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 1176
1185 // Called when the tab strip view changes size. As we only registered for 1177 // Called when the tab strip view changes size. As we only registered for
1186 // changes on our view, we know it's only for our view. Layout w/out 1178 // changes on our view, we know it's only for our view. Layout w/out
1187 // animations since they are blocked by the resize nested runloop. We need 1179 // animations since they are blocked by the resize nested runloop. We need
1188 // the views to adjust immediately. Neither the tabs nor their z-order are 1180 // the views to adjust immediately. Neither the tabs nor their z-order are
1189 // changed, so we don't need to update the subviews. 1181 // changed, so we don't need to update the subviews.
1190 - (void)tabViewFrameChanged:(NSNotification*)info { 1182 - (void)tabViewFrameChanged:(NSNotification*)info {
1191 [self layoutTabsWithAnimation:NO regenerateSubviews:NO]; 1183 [self layoutTabsWithAnimation:NO regenerateSubviews:NO];
1192 } 1184 }
1193 1185
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
1215 - (BOOL)inRapidClosureMode { 1186 - (BOOL)inRapidClosureMode {
1216 return availableResizeWidth_ != kUseFullAvailableWidth; 1187 return availableResizeWidth_ != kUseFullAvailableWidth;
1217 } 1188 }
1218 1189
1219 // Disable tab dragging when there are any pending animations. 1190 // Disable tab dragging when there are any pending animations.
1220 - (BOOL)tabDraggingAllowed { 1191 - (BOOL)tabDraggingAllowed {
1221 return [closingControllers_ count] == 0; 1192 return [closingControllers_ count] == 0;
1222 } 1193 }
1223 1194
1224 - (void)mouseMoved:(NSEvent*)event { 1195 - (void)mouseMoved:(NSEvent*)event {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 [permanentSubviews_ addObject:aView]; 1245 [permanentSubviews_ addObject:aView];
1275 } 1246 }
1276 1247
1277 // Update the subviews, keeping the permanent ones (or, more correctly, putting 1248 // Update the subviews, keeping the permanent ones (or, more correctly, putting
1278 // in the ones listed in permanentSubviews_), and putting in the current tabs in 1249 // in the ones listed in permanentSubviews_), and putting in the current tabs in
1279 // the correct z-order. Any current subviews which is neither in the permanent 1250 // the correct z-order. Any current subviews which is neither in the permanent
1280 // list nor a (current) tab will be removed. So if you add such a subview, you 1251 // list nor a (current) tab will be removed. So if you add such a subview, you
1281 // should call |-addSubviewToPermanentList:| (or better yet, call that and then 1252 // should call |-addSubviewToPermanentList:| (or better yet, call that and then
1282 // |-regenerateSubviewList| to actually add it). 1253 // |-regenerateSubviewList| to actually add it).
1283 - (void)regenerateSubviewList { 1254 - (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
1293 // Subviews to put in (in bottom-to-top order), beginning with the permanent 1255 // Subviews to put in (in bottom-to-top order), beginning with the permanent
1294 // ones. 1256 // ones.
1295 NSMutableArray* subviews = [NSMutableArray arrayWithArray:permanentSubviews_]; 1257 NSMutableArray* subviews = [NSMutableArray arrayWithArray:permanentSubviews_];
1296 1258
1297 NSView* selectedTabView = nil; 1259 NSView* selectedTabView = nil;
1298 // Go through tabs in reverse order, since |subviews| is bottom-to-top. 1260 // Go through tabs in reverse order, since |subviews| is bottom-to-top.
1299 for (TabController* tab in [tabArray_.get() reverseObjectEnumerator]) { 1261 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
1308 if ([tab selected]) { 1262 if ([tab selected]) {
1309 DCHECK(!selectedTabView); 1263 DCHECK(!selectedTabView);
1310 selectedTabView = tabView; 1264 selectedTabView = [tab view];
1311 } else { 1265 } else {
1312 [subviews addObject:tabView]; 1266 [subviews addObject:[tab view]];
1313 } 1267 }
1314 } 1268 }
1315 if (selectedTabView) 1269 if (selectedTabView)
1316 [subviews addObject:selectedTabView]; 1270 [subviews addObject:selectedTabView];
1317 1271
1318 [tabView_ setSubviews:subviews]; 1272 [tabView_ setSubviews:subviews];
1319 } 1273 }
1320 1274
1321 - (GTMWindowSheetController*)sheetController { 1275 - (GTMWindowSheetController*)sheetController {
1322 if (!sheetController_.get()) 1276 if (!sheetController_.get())
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 NSInteger index = [self indexFromModelIndex:modelIndex]; 1332 NSInteger index = [self indexFromModelIndex:modelIndex];
1379 BrowserWindowController* controller = 1333 BrowserWindowController* controller =
1380 (BrowserWindowController*)[[switchView_ window] windowController]; 1334 (BrowserWindowController*)[[switchView_ window] windowController];
1381 DCHECK(index >= 0); 1335 DCHECK(index >= 0);
1382 if (index >= 0) { 1336 if (index >= 0) {
1383 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; 1337 [controller setTab:[self viewAtIndex:index] isDraggable:YES];
1384 } 1338 }
1385 } 1339 }
1386 1340
1387 @end 1341 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/cocoa/tab_view.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698