| 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 2252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2263 if (modelIndex < 0) | 2263 if (modelIndex < 0) |
| 2264 return nil; | 2264 return nil; |
| 2265 NSInteger index = [self indexFromModelIndex:modelIndex]; | 2265 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 2266 if (index < 0 || | 2266 if (index < 0 || |
| 2267 index >= (NSInteger)[tabContentsArray_ count]) | 2267 index >= (NSInteger)[tabContentsArray_ count]) |
| 2268 return nil; | 2268 return nil; |
| 2269 return [tabContentsArray_ objectAtIndex:index]; | 2269 return [tabContentsArray_ objectAtIndex:index]; |
| 2270 } | 2270 } |
| 2271 | 2271 |
| 2272 - (void)addCustomWindowControls { | 2272 - (void)addCustomWindowControls { |
| 2273 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); | 2273 BOOL shouldFlipWindowControls = |
| 2274 cocoa_l10n_util::ShouldFlipWindowControlsInRTL(); |
| 2274 if (!customWindowControls_) { | 2275 if (!customWindowControls_) { |
| 2275 // Make the container view. | 2276 // Make the container view. |
| 2276 CGFloat height = NSHeight([tabStripView_ frame]); | 2277 CGFloat height = NSHeight([tabStripView_ frame]); |
| 2277 CGFloat width = [self leadingIndentForControls]; | 2278 CGFloat width = [self leadingIndentForControls]; |
| 2278 CGFloat xOrigin = isRTL ? NSWidth([tabStripView_ frame]) - width : 0; | 2279 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout() && |
| 2280 !shouldFlipWindowControls) |
| 2281 // The trailing indent is correct in this case, since the controls should |
| 2282 // stay on the left. |
| 2283 width = [self trailingIndentForControls]; |
| 2284 CGFloat xOrigin = |
| 2285 shouldFlipWindowControls ? NSWidth([tabStripView_ frame]) - width : 0; |
| 2279 NSRect frame = NSMakeRect(xOrigin, 0, width, height); | 2286 NSRect frame = NSMakeRect(xOrigin, 0, width, height); |
| 2280 customWindowControls_.reset( | 2287 customWindowControls_.reset( |
| 2281 [[CustomWindowControlsView alloc] initWithFrame:frame]); | 2288 [[CustomWindowControlsView alloc] initWithFrame:frame]); |
| 2282 [customWindowControls_ | 2289 [customWindowControls_ |
| 2283 setAutoresizingMask:isRTL ? NSViewMinXMargin | NSViewHeightSizable | 2290 setAutoresizingMask:shouldFlipWindowControls |
| 2284 : NSViewMaxXMargin | NSViewHeightSizable]; | 2291 ? NSViewMinXMargin | NSViewHeightSizable |
| 2292 : NSViewMaxXMargin | NSViewHeightSizable]; |
| 2285 | 2293 |
| 2286 // Add the traffic light buttons. The horizontal layout was determined by | 2294 // Add the traffic light buttons. The horizontal layout was determined by |
| 2287 // manual inspection on Yosemite. | 2295 // manual inspection on Yosemite. |
| 2288 CGFloat closeButtonX = 11; | 2296 CGFloat closeButtonX = 11; |
| 2289 CGFloat pinnedButtonX = 31; | 2297 CGFloat pinnedButtonX = 31; |
| 2290 CGFloat zoomButtonX = 51; | 2298 CGFloat zoomButtonX = 51; |
| 2291 if (isRTL) | 2299 if (shouldFlipWindowControls) |
| 2292 std::swap(closeButtonX, zoomButtonX); | 2300 std::swap(closeButtonX, zoomButtonX); |
| 2293 | 2301 |
| 2294 NSUInteger styleMask = [[tabStripView_ window] styleMask]; | 2302 NSUInteger styleMask = [[tabStripView_ window] styleMask]; |
| 2295 NSButton* closeButton = [NSWindow standardWindowButton:NSWindowCloseButton | 2303 NSButton* closeButton = [NSWindow standardWindowButton:NSWindowCloseButton |
| 2296 forStyleMask:styleMask]; | 2304 forStyleMask:styleMask]; |
| 2297 | 2305 |
| 2298 // Vertically center the buttons in the tab strip. | 2306 // Vertically center the buttons in the tab strip. |
| 2299 CGFloat buttonY = floor((height - NSHeight([closeButton bounds])) / 2); | 2307 CGFloat buttonY = floor((height - NSHeight([closeButton bounds])) / 2); |
| 2300 [closeButton setFrameOrigin:NSMakePoint(closeButtonX, buttonY)]; | 2308 [closeButton setFrameOrigin:NSMakePoint(closeButtonX, buttonY)]; |
| 2301 [customWindowControls_ addSubview:closeButton]; | 2309 [customWindowControls_ addSubview:closeButton]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2314 [zoomButton setFrameOrigin:NSMakePoint(zoomButtonX, buttonY)]; | 2322 [zoomButton setFrameOrigin:NSMakePoint(zoomButtonX, buttonY)]; |
| 2315 | 2323 |
| 2316 customWindowControlsTrackingArea_.reset([[CrTrackingArea alloc] | 2324 customWindowControlsTrackingArea_.reset([[CrTrackingArea alloc] |
| 2317 initWithRect:[customWindowControls_ bounds] | 2325 initWithRect:[customWindowControls_ bounds] |
| 2318 options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) | 2326 options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) |
| 2319 owner:self | 2327 owner:self |
| 2320 userInfo:nil]); | 2328 userInfo:nil]); |
| 2321 [customWindowControls_ | 2329 [customWindowControls_ |
| 2322 addTrackingArea:customWindowControlsTrackingArea_.get()]; | 2330 addTrackingArea:customWindowControlsTrackingArea_.get()]; |
| 2323 } | 2331 } |
| 2324 if (isRTL && | 2332 if (shouldFlipWindowControls && |
| 2325 NSMaxX([customWindowControls_ frame]) != NSMaxX([tabStripView_ frame])) { | 2333 NSMaxX([customWindowControls_ frame]) != NSMaxX([tabStripView_ frame])) { |
| 2326 NSRect frame = [customWindowControls_ frame]; | 2334 NSRect frame = [customWindowControls_ frame]; |
| 2327 frame.origin.x = | 2335 frame.origin.x = |
| 2328 NSMaxX([tabStripView_ frame]) - [self leadingIndentForControls]; | 2336 NSMaxX([tabStripView_ frame]) - [self leadingIndentForControls]; |
| 2329 [customWindowControls_ setFrame:frame]; | 2337 [customWindowControls_ setFrame:frame]; |
| 2330 } | 2338 } |
| 2331 if (![permanentSubviews_ containsObject:customWindowControls_]) { | 2339 if (![permanentSubviews_ containsObject:customWindowControls_]) { |
| 2332 [self addSubviewToPermanentList:customWindowControls_]; | 2340 [self addSubviewToPermanentList:customWindowControls_]; |
| 2333 [self regenerateSubviewList]; | 2341 [self regenerateSubviewList]; |
| 2334 } | 2342 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2400 for (int i = 0; i < tabStripModel_->count(); i++) { | 2408 for (int i = 0; i < tabStripModel_->count(); i++) { |
| 2401 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; | 2409 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; |
| 2402 } | 2410 } |
| 2403 } | 2411 } |
| 2404 | 2412 |
| 2405 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { | 2413 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { |
| 2406 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; | 2414 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; |
| 2407 } | 2415 } |
| 2408 | 2416 |
| 2409 @end | 2417 @end |
| OLD | NEW |