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 2154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2165 int modelIndex = tabStripModel_->active_index(); | 2165 int modelIndex = tabStripModel_->active_index(); |
2166 if (modelIndex < 0) | 2166 if (modelIndex < 0) |
2167 return nil; | 2167 return nil; |
2168 NSInteger index = [self indexFromModelIndex:modelIndex]; | 2168 NSInteger index = [self indexFromModelIndex:modelIndex]; |
2169 if (index < 0 || | 2169 if (index < 0 || |
2170 index >= (NSInteger)[tabContentsArray_ count]) | 2170 index >= (NSInteger)[tabContentsArray_ count]) |
2171 return nil; | 2171 return nil; |
2172 return [tabContentsArray_ objectAtIndex:index]; | 2172 return [tabContentsArray_ objectAtIndex:index]; |
2173 } | 2173 } |
2174 | 2174 |
| 2175 - (void)addWindowControls { |
| 2176 if (!fullscreenWindowControls_) { |
| 2177 // Make the container view. |
| 2178 CGFloat height = NSHeight([tabStripView_ frame]); |
| 2179 NSRect frame = NSMakeRect(0, 0, [self leftIndentForControls], height); |
| 2180 fullscreenWindowControls_.reset([[NSView alloc] initWithFrame:frame]); |
| 2181 [fullscreenWindowControls_ |
| 2182 setAutoresizingMask:NSViewMaxXMargin | NSViewHeightSizable]; |
| 2183 |
| 2184 // Add the traffic light buttons. The horizontal layout was determined by |
| 2185 // manual inspection on Yosemite. |
| 2186 CGFloat closeButtonX = 11; |
| 2187 CGFloat miniButtonX = 31; |
| 2188 CGFloat zoomButtonX = 51; |
| 2189 |
| 2190 NSUInteger styleMask = [[tabStripView_ window] styleMask]; |
| 2191 NSButton* closeButton = [NSWindow standardWindowButton:NSWindowCloseButton |
| 2192 forStyleMask:styleMask]; |
| 2193 |
| 2194 // Vertically center the buttons in the tab strip. |
| 2195 CGFloat buttonY = floor((height - NSHeight([closeButton bounds])) / 2); |
| 2196 [closeButton setFrameOrigin:NSMakePoint(closeButtonX, buttonY)]; |
| 2197 [fullscreenWindowControls_ addSubview:closeButton]; |
| 2198 |
| 2199 NSButton* miniaturizeButton = |
| 2200 [NSWindow standardWindowButton:NSWindowMiniaturizeButton |
| 2201 forStyleMask:styleMask]; |
| 2202 [miniaturizeButton setFrameOrigin:NSMakePoint(miniButtonX, buttonY)]; |
| 2203 [miniaturizeButton setEnabled:NO]; |
| 2204 [fullscreenWindowControls_ addSubview:miniaturizeButton]; |
| 2205 |
| 2206 NSButton* zoomButton = |
| 2207 [NSWindow standardWindowButton:NSWindowZoomButton |
| 2208 forStyleMask:styleMask]; |
| 2209 [fullscreenWindowControls_ addSubview:zoomButton]; |
| 2210 [zoomButton setFrameOrigin:NSMakePoint(zoomButtonX, buttonY)]; |
| 2211 } |
| 2212 |
| 2213 if (![permanentSubviews_ containsObject:fullscreenWindowControls_]) { |
| 2214 [self addSubviewToPermanentList:fullscreenWindowControls_]; |
| 2215 [self regenerateSubviewList]; |
| 2216 } |
| 2217 } |
| 2218 |
| 2219 - (void)removeWindowControls { |
| 2220 if (fullscreenWindowControls_) |
| 2221 [permanentSubviews_ removeObject:fullscreenWindowControls_]; |
| 2222 [self regenerateSubviewList]; |
| 2223 } |
| 2224 |
2175 - (void)themeDidChangeNotification:(NSNotification*)notification { | 2225 - (void)themeDidChangeNotification:(NSNotification*)notification { |
2176 [self setNewTabImages]; | 2226 [self setNewTabImages]; |
2177 } | 2227 } |
2178 | 2228 |
2179 - (void)setNewTabImages { | 2229 - (void)setNewTabImages { |
2180 ThemeService *theme = | 2230 ThemeService *theme = |
2181 static_cast<ThemeService*>([[tabStripView_ window] themeProvider]); | 2231 static_cast<ThemeService*>([[tabStripView_ window] themeProvider]); |
2182 if (!theme) | 2232 if (!theme) |
2183 return; | 2233 return; |
2184 | 2234 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2229 } | 2279 } |
2230 | 2280 |
2231 NSRect GetSheetParentBoundsForParentView(NSView* view) { | 2281 NSRect GetSheetParentBoundsForParentView(NSView* view) { |
2232 // If the devtools view is open, it shrinks the size of the WebContents, so go | 2282 // If the devtools view is open, it shrinks the size of the WebContents, so go |
2233 // up the hierarchy to the devtools container view to avoid that. Note that | 2283 // up the hierarchy to the devtools container view to avoid that. Note that |
2234 // the devtools view is always in the hierarchy even if it is not open or it | 2284 // the devtools view is always in the hierarchy even if it is not open or it |
2235 // is detached. | 2285 // is detached. |
2236 NSView* devtools_view = [[[view superview] superview] superview]; | 2286 NSView* devtools_view = [[[view superview] superview] superview]; |
2237 return [devtools_view convertRect:[devtools_view bounds] toView:nil]; | 2287 return [devtools_view convertRect:[devtools_view bounds] toView:nil]; |
2238 } | 2288 } |
OLD | NEW |