| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "chrome/browser/ui/browser_navigator.h" | 31 #include "chrome/browser/ui/browser_navigator.h" |
| 32 #include "chrome/browser/ui/find_bar/find_manager.h" | 32 #include "chrome/browser/ui/find_bar/find_manager.h" |
| 33 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 33 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 34 #import "chrome/browser/ui/cocoa/constrained_window_mac.h" | 34 #import "chrome/browser/ui/cocoa/constrained_window_mac.h" |
| 35 #import "chrome/browser/ui/cocoa/new_tab_button.h" | 35 #import "chrome/browser/ui/cocoa/new_tab_button.h" |
| 36 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 36 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
| 37 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" | 37 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" |
| 38 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 38 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 39 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 39 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 40 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" | 40 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" |
| 41 #import "chrome/browser/ui/cocoa/tracking_area.h" |
| 41 #include "chrome/browser/ui/find_bar/find_bar.h" | 42 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 42 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 43 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 43 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 44 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 44 #include "grit/app_resources.h" | 45 #include "grit/app_resources.h" |
| 45 #include "grit/generated_resources.h" | 46 #include "grit/generated_resources.h" |
| 46 #include "grit/theme_resources.h" | 47 #include "grit/theme_resources.h" |
| 47 #include "skia/ext/skia_utils_mac.h" | 48 #include "skia/ext/skia_utils_mac.h" |
| 48 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 49 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
| 49 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
| 50 #include "ui/base/resource/resource_bundle.h" | 51 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 116 } |
| 116 | 117 |
| 117 private: | 118 private: |
| 118 bool animate_; | 119 bool animate_; |
| 119 DISALLOW_COPY_AND_ASSIGN(ScopedNSAnimationContextGroup); | 120 DISALLOW_COPY_AND_ASSIGN(ScopedNSAnimationContextGroup); |
| 120 }; | 121 }; |
| 121 | 122 |
| 122 } // namespace | 123 } // namespace |
| 123 | 124 |
| 124 @interface TabStripController (Private) | 125 @interface TabStripController (Private) |
| 125 - (void)installTrackingArea; | |
| 126 - (void)addSubviewToPermanentList:(NSView*)aView; | 126 - (void)addSubviewToPermanentList:(NSView*)aView; |
| 127 - (void)regenerateSubviewList; | 127 - (void)regenerateSubviewList; |
| 128 - (NSInteger)indexForContentsView:(NSView*)view; | 128 - (NSInteger)indexForContentsView:(NSView*)view; |
| 129 - (void)updateFavIconForContents:(TabContents*)contents | 129 - (void)updateFavIconForContents:(TabContents*)contents |
| 130 atIndex:(NSInteger)modelIndex; | 130 atIndex:(NSInteger)modelIndex; |
| 131 - (void)layoutTabsWithAnimation:(BOOL)animate | 131 - (void)layoutTabsWithAnimation:(BOOL)animate |
| 132 regenerateSubviews:(BOOL)doUpdate; | 132 regenerateSubviews:(BOOL)doUpdate; |
| 133 - (void)animationDidStopForController:(TabController*)controller | 133 - (void)animationDidStopForController:(TabController*)controller |
| 134 finished:(BOOL)finished; | 134 finished:(BOOL)finished; |
| 135 - (NSInteger)indexFromModelIndex:(NSInteger)index; | 135 - (NSInteger)indexFromModelIndex:(NSInteger)index; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 DCHECK(view && switchView && browser && delegate); | 289 DCHECK(view && switchView && browser && delegate); |
| 290 if ((self = [super init])) { | 290 if ((self = [super init])) { |
| 291 tabStripView_.reset([view retain]); | 291 tabStripView_.reset([view retain]); |
| 292 switchView_ = switchView; | 292 switchView_ = switchView; |
| 293 browser_ = browser; | 293 browser_ = browser; |
| 294 tabStripModel_ = browser_->tabstrip_model(); | 294 tabStripModel_ = browser_->tabstrip_model(); |
| 295 delegate_ = delegate; | 295 delegate_ = delegate; |
| 296 bridge_.reset(new TabStripModelObserverBridge(tabStripModel_, self)); | 296 bridge_.reset(new TabStripModelObserverBridge(tabStripModel_, self)); |
| 297 tabContentsArray_.reset([[NSMutableArray alloc] init]); | 297 tabContentsArray_.reset([[NSMutableArray alloc] init]); |
| 298 tabArray_.reset([[NSMutableArray alloc] init]); | 298 tabArray_.reset([[NSMutableArray alloc] init]); |
| 299 NSWindow* browserWindow = [view window]; |
| 299 | 300 |
| 300 // Important note: any non-tab subviews not added to |permanentSubviews_| | 301 // Important note: any non-tab subviews not added to |permanentSubviews_| |
| 301 // (see |-addSubviewToPermanentList:|) will be wiped out. | 302 // (see |-addSubviewToPermanentList:|) will be wiped out. |
| 302 permanentSubviews_.reset([[NSMutableArray alloc] init]); | 303 permanentSubviews_.reset([[NSMutableArray alloc] init]); |
| 303 | 304 |
| 304 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 305 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 305 defaultFavIcon_.reset([rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON) retain]); | 306 defaultFavIcon_.reset([rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON) retain]); |
| 306 | 307 |
| 307 [self setIndentForControls:[[self class] defaultIndentForControls]]; | 308 [self setIndentForControls:[[self class] defaultIndentForControls]]; |
| 308 | 309 |
| 309 // TODO(viettrungluu): WTF? "For some reason, if the view is present in the | 310 // TODO(viettrungluu): WTF? "For some reason, if the view is present in the |
| 310 // nib a priori, it draws correctly. If we create it in code and add it to | 311 // nib a priori, it draws correctly. If we create it in code and add it to |
| 311 // the tab view, it draws with all sorts of crazy artifacts." | 312 // the tab view, it draws with all sorts of crazy artifacts." |
| 312 newTabButton_ = [view newTabButton]; | 313 newTabButton_ = [view newTabButton]; |
| 313 [self addSubviewToPermanentList:newTabButton_]; | 314 [self addSubviewToPermanentList:newTabButton_]; |
| 314 [newTabButton_ setTarget:nil]; | 315 [newTabButton_ setTarget:nil]; |
| 315 [newTabButton_ setAction:@selector(commandDispatch:)]; | 316 [newTabButton_ setAction:@selector(commandDispatch:)]; |
| 316 [newTabButton_ setTag:IDC_NEW_TAB]; | 317 [newTabButton_ setTag:IDC_NEW_TAB]; |
| 317 // Set the images from code because Cocoa fails to find them in our sub | 318 // Set the images from code because Cocoa fails to find them in our sub |
| 318 // bundle during tests. | 319 // bundle during tests. |
| 319 [newTabButton_ setImage:app::mac::GetCachedImageWithName(kNewTabImage)]; | 320 [newTabButton_ setImage:app::mac::GetCachedImageWithName(kNewTabImage)]; |
| 320 [newTabButton_ setAlternateImage: | 321 [newTabButton_ setAlternateImage: |
| 321 app::mac::GetCachedImageWithName(kNewTabPressedImage)]; | 322 app::mac::GetCachedImageWithName(kNewTabPressedImage)]; |
| 322 newTabButtonShowingHoverImage_ = NO; | 323 newTabButtonShowingHoverImage_ = NO; |
| 323 newTabTrackingArea_.reset( | 324 newTabTrackingArea_.reset( |
| 324 [[NSTrackingArea alloc] initWithRect:[newTabButton_ bounds] | 325 [[CrTrackingArea alloc] initWithRect:[newTabButton_ bounds] |
| 325 options:(NSTrackingMouseEnteredAndExited | | 326 options:(NSTrackingMouseEnteredAndExited | |
| 326 NSTrackingActiveAlways) | 327 NSTrackingActiveAlways) |
| 327 owner:self | 328 owner:self |
| 328 userInfo:nil]); | 329 userInfo:nil]); |
| 330 if (browserWindow) // Nil for Browsers without a tab strip (e.g. popups). |
| 331 [newTabTrackingArea_ clearOwnerWhenWindowWillClose:browserWindow]; |
| 329 [newTabButton_ addTrackingArea:newTabTrackingArea_.get()]; | 332 [newTabButton_ addTrackingArea:newTabTrackingArea_.get()]; |
| 330 targetFrames_.reset([[NSMutableDictionary alloc] init]); | 333 targetFrames_.reset([[NSMutableDictionary alloc] init]); |
| 331 | 334 |
| 332 dragBlockingView_.reset( | 335 dragBlockingView_.reset( |
| 333 [[TabStripControllerDragBlockingView alloc] initWithFrame:NSZeroRect | 336 [[TabStripControllerDragBlockingView alloc] initWithFrame:NSZeroRect |
| 334 controller:self]); | 337 controller:self]); |
| 335 [self addSubviewToPermanentList:dragBlockingView_]; | 338 [self addSubviewToPermanentList:dragBlockingView_]; |
| 336 | 339 |
| 337 newTabTargetFrame_ = NSMakeRect(0, 0, 0, 0); | 340 newTabTargetFrame_ = NSMakeRect(0, 0, 0, 0); |
| 338 availableResizeWidth_ = kUseFullAvailableWidth; | 341 availableResizeWidth_ = kUseFullAvailableWidth; |
| 339 | 342 |
| 340 closingControllers_.reset([[NSMutableSet alloc] init]); | 343 closingControllers_.reset([[NSMutableSet alloc] init]); |
| 341 | 344 |
| 342 // Install the permanent subviews. | 345 // Install the permanent subviews. |
| 343 [self regenerateSubviewList]; | 346 [self regenerateSubviewList]; |
| 344 | 347 |
| 345 // Watch for notifications that the tab strip view has changed size so | 348 // Watch for notifications that the tab strip view has changed size so |
| 346 // we can tell it to layout for the new size. | 349 // we can tell it to layout for the new size. |
| 347 [[NSNotificationCenter defaultCenter] | 350 [[NSNotificationCenter defaultCenter] |
| 348 addObserver:self | 351 addObserver:self |
| 349 selector:@selector(tabViewFrameChanged:) | 352 selector:@selector(tabViewFrameChanged:) |
| 350 name:NSViewFrameDidChangeNotification | 353 name:NSViewFrameDidChangeNotification |
| 351 object:tabStripView_]; | 354 object:tabStripView_]; |
| 352 | 355 |
| 353 trackingArea_.reset([[NSTrackingArea alloc] | 356 trackingArea_.reset([[CrTrackingArea alloc] |
| 354 initWithRect:NSZeroRect // Ignored by NSTrackingInVisibleRect | 357 initWithRect:NSZeroRect // Ignored by NSTrackingInVisibleRect |
| 355 options:NSTrackingMouseEnteredAndExited | | 358 options:NSTrackingMouseEnteredAndExited | |
| 356 NSTrackingMouseMoved | | 359 NSTrackingMouseMoved | |
| 357 NSTrackingActiveAlways | | 360 NSTrackingActiveAlways | |
| 358 NSTrackingInVisibleRect | 361 NSTrackingInVisibleRect |
| 359 owner:self | 362 owner:self |
| 360 userInfo:nil]); | 363 userInfo:nil]); |
| 364 if (browserWindow) // Nil for Browsers without a tab strip (e.g. popups). |
| 365 [trackingArea_ clearOwnerWhenWindowWillClose:browserWindow]; |
| 361 [tabStripView_ addTrackingArea:trackingArea_.get()]; | 366 [tabStripView_ addTrackingArea:trackingArea_.get()]; |
| 362 | 367 |
| 363 // Check to see if the mouse is currently in our bounds so we can | 368 // Check to see if the mouse is currently in our bounds so we can |
| 364 // enable the tracking areas. Otherwise we won't get hover states | 369 // enable the tracking areas. Otherwise we won't get hover states |
| 365 // or tab gradients if we load the window up under the mouse. | 370 // or tab gradients if we load the window up under the mouse. |
| 366 NSPoint mouseLoc = [[view window] mouseLocationOutsideOfEventStream]; | 371 NSPoint mouseLoc = [[view window] mouseLocationOutsideOfEventStream]; |
| 367 mouseLoc = [view convertPoint:mouseLoc fromView:nil]; | 372 mouseLoc = [view convertPoint:mouseLoc fromView:nil]; |
| 368 if (NSPointInRect(mouseLoc, [view bounds])) { | 373 if (NSPointInRect(mouseLoc, [view bounds])) { |
| 369 [self setTabTrackingAreasEnabled:YES]; | 374 [self setTabTrackingAreasEnabled:YES]; |
| 370 mouseInside_ = YES; | 375 mouseInside_ = YES; |
| (...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1894 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1899 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 1895 BrowserWindowController* controller = | 1900 BrowserWindowController* controller = |
| 1896 (BrowserWindowController*)[[switchView_ window] windowController]; | 1901 (BrowserWindowController*)[[switchView_ window] windowController]; |
| 1897 DCHECK(index >= 0); | 1902 DCHECK(index >= 0); |
| 1898 if (index >= 0) { | 1903 if (index >= 0) { |
| 1899 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; | 1904 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; |
| 1900 } | 1905 } |
| 1901 } | 1906 } |
| 1902 | 1907 |
| 1903 @end | 1908 @end |
| OLD | NEW |