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/browser_window_controller_private.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 willPositionSheet:(NSWindow*)sheet | 197 willPositionSheet:(NSWindow*)sheet |
198 usingRect:(NSRect)defaultSheetRect { | 198 usingRect:(NSRect)defaultSheetRect { |
199 // Position the sheet as follows: | 199 // Position the sheet as follows: |
200 // - If the bookmark bar is hidden or shown as a bubble (on the NTP when the | 200 // - If the bookmark bar is hidden or shown as a bubble (on the NTP when the |
201 // bookmark bar is disabled), position the sheet immediately below the | 201 // bookmark bar is disabled), position the sheet immediately below the |
202 // normal toolbar. | 202 // normal toolbar. |
203 // - If the bookmark bar is shown (attached to the normal toolbar), position | 203 // - If the bookmark bar is shown (attached to the normal toolbar), position |
204 // the sheet below the bookmark bar. | 204 // the sheet below the bookmark bar. |
205 // - If the bookmark bar is currently animating, position the sheet according | 205 // - If the bookmark bar is currently animating, position the sheet according |
206 // to where the bar will be when the animation ends. | 206 // to where the bar will be when the animation ends. |
207 CGFloat desiredY = defaultSheetRect.origin.y; | |
Robert Sesek
2014/10/27 15:41:22
naming: desiredY -> defaultSheetY
erikchen
2014/10/27 23:18:13
Done.
| |
207 switch ([bookmarkBarController_ currentState]) { | 208 switch ([bookmarkBarController_ currentState]) { |
208 case BookmarkBar::SHOW: { | 209 case BookmarkBar::SHOW: { |
209 NSRect bookmarkBarFrame = [[bookmarkBarController_ view] frame]; | 210 NSRect bookmarkBarFrame = [[bookmarkBarController_ view] frame]; |
210 defaultSheetRect.origin.y = bookmarkBarFrame.origin.y; | 211 desiredY = bookmarkBarFrame.origin.y; |
211 break; | 212 break; |
212 } | 213 } |
213 case BookmarkBar::HIDDEN: | 214 case BookmarkBar::HIDDEN: |
214 case BookmarkBar::DETACHED: { | 215 case BookmarkBar::DETACHED: { |
215 if ([self hasToolbar]) { | 216 if ([self hasToolbar]) { |
216 NSRect toolbarFrame = [[toolbarController_ view] frame]; | 217 NSRect toolbarFrame = [[toolbarController_ view] frame]; |
217 defaultSheetRect.origin.y = toolbarFrame.origin.y; | 218 desiredY = toolbarFrame.origin.y; |
218 } else { | 219 } else { |
219 // The toolbar is not shown in application mode. The sheet should be | 220 // The toolbar is not shown in application mode. The sheet should be |
220 // located at the top of the window, under the title of the window. | 221 // located at the top of the window, under the title of the window. |
221 defaultSheetRect.origin.y = NSHeight([[window contentView] frame]) - | 222 desiredY = NSHeight([[window contentView] frame]) - |
222 defaultSheetRect.size.height; | 223 defaultSheetRect.size.height; |
223 } | 224 } |
224 break; | 225 break; |
225 } | 226 } |
226 } | 227 } |
228 | |
229 // AppKit may shift the window up to fit the sheet on screen, but it will | |
230 // never adjust the height of the sheet, or the origin of the sheet relative | |
231 // to the window. Adjust the origin to prevent sheets from extending past the | |
232 // bottom of the screen. | |
233 | |
234 // Don't allow the sheet to extend past the bottom of the window. This logic | |
235 // intentionally ignores the size of the screens, since the window might span | |
236 // multiple screens, and AppKit may reposition the window. | |
237 CGFloat sheetHeight = NSHeight([sheet frame]); | |
238 desiredY = std::max(desiredY, sheetHeight); | |
239 | |
240 // It doesn't make sense to provide a Y higher than the height of the window. | |
241 CGFloat windowHeight = NSHeight([window frame]); | |
242 desiredY = std::min(desiredY, windowHeight); | |
243 | |
244 defaultSheetRect.origin.y = desiredY; | |
227 return defaultSheetRect; | 245 return defaultSheetRect; |
228 } | 246 } |
229 | 247 |
230 - (void)layoutSubviews { | 248 - (void)layoutSubviews { |
231 // Suppress title drawing if necessary. | 249 // Suppress title drawing if necessary. |
232 if ([self.window respondsToSelector:@selector(setShouldHideTitle:)]) | 250 if ([self.window respondsToSelector:@selector(setShouldHideTitle:)]) |
233 [(id)self.window setShouldHideTitle:![self hasTitleBar]]; | 251 [(id)self.window setShouldHideTitle:![self hasTitleBar]]; |
234 | 252 |
235 [bookmarkBarController_ updateHiddenState]; | 253 [bookmarkBarController_ updateHiddenState]; |
236 [self updateSubviewZOrder]; | 254 [self updateSubviewZOrder]; |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1043 | 1061 |
1044 [CATransaction commit]; | 1062 [CATransaction commit]; |
1045 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = YES; | 1063 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = YES; |
1046 } | 1064 } |
1047 } else { | 1065 } else { |
1048 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = NO; | 1066 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = NO; |
1049 } | 1067 } |
1050 } | 1068 } |
1051 | 1069 |
1052 @end // @implementation BrowserWindowController(Private) | 1070 @end // @implementation BrowserWindowController(Private) |
OLD | NEW |