Chromium Code Reviews| 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/bind_objc_block.h" | 10 #include "base/mac/bind_objc_block.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 windowPreferences->SetBoolean("maximized", false); | 164 windowPreferences->SetBoolean("maximized", false); |
| 165 windowPreferences->SetBoolean("always_on_top", false); | 165 windowPreferences->SetBoolean("always_on_top", false); |
| 166 windowPreferences->SetInteger("work_area_left", workArea.x()); | 166 windowPreferences->SetInteger("work_area_left", workArea.x()); |
| 167 windowPreferences->SetInteger("work_area_top", workArea.y()); | 167 windowPreferences->SetInteger("work_area_top", workArea.y()); |
| 168 windowPreferences->SetInteger("work_area_right", workArea.right()); | 168 windowPreferences->SetInteger("work_area_right", workArea.right()); |
| 169 windowPreferences->SetInteger("work_area_bottom", workArea.bottom()); | 169 windowPreferences->SetInteger("work_area_bottom", workArea.bottom()); |
| 170 } | 170 } |
| 171 | 171 |
| 172 - (NSRect)window:(NSWindow*)window | 172 - (NSRect)window:(NSWindow*)window |
| 173 willPositionSheet:(NSWindow*)sheet | 173 willPositionSheet:(NSWindow*)sheet |
| 174 usingRect:(NSRect)defaultSheetRect { | 174 usingRect:(NSRect)defaultSheetLocation { |
| 175 // Position the sheet as follows: | 175 // Position the sheet as follows: |
| 176 // - If the bookmark bar is shown (attached to the normal toolbar), position | |
| 177 // the sheet below the bookmark bar. | |
| 176 // - If the bookmark bar is hidden or shown as a bubble (on the NTP when the | 178 // - If the bookmark bar is hidden or shown as a bubble (on the NTP when the |
| 177 // bookmark bar is disabled), position the sheet immediately below the | 179 // bookmark bar is disabled), position the sheet immediately below the |
| 178 // normal toolbar. | 180 // normal toolbar. |
| 179 // - If the bookmark bar is shown (attached to the normal toolbar), position | |
| 180 // the sheet below the bookmark bar. | |
| 181 // - If the bookmark bar is currently animating, position the sheet according | 181 // - If the bookmark bar is currently animating, position the sheet according |
| 182 // to where the bar will be when the animation ends. | 182 // to where the bar will be when the animation ends. |
| 183 CGFloat defaultSheetY = defaultSheetRect.origin.y; | 183 CGFloat defaultSheetY = defaultSheetLocation.origin.y; |
| 184 switch ([bookmarkBarController_ currentState]) { | 184 if ([self supportsBookmarkBar] && |
|
Andre
2015/01/06 20:55:33
This was the missing check that caused the sheet t
| |
| 185 case BookmarkBar::SHOW: { | 185 [bookmarkBarController_ currentState] == BookmarkBar::SHOW) { |
| 186 NSRect bookmarkBarFrame = [[bookmarkBarController_ view] frame]; | 186 defaultSheetY = NSMinY([[bookmarkBarController_ view] frame]); |
| 187 defaultSheetY = bookmarkBarFrame.origin.y; | 187 } else if ([self hasToolbar]) { |
| 188 break; | 188 defaultSheetY = NSMinY([[toolbarController_ view] frame]); |
| 189 } | 189 } else { |
| 190 case BookmarkBar::HIDDEN: | 190 // The toolbar is not shown in popup and application modes. The sheet |
| 191 case BookmarkBar::DETACHED: { | 191 // should be located at the top of the window, under the title of the |
| 192 if ([self hasToolbar]) { | 192 // window. |
| 193 NSRect toolbarFrame = [[toolbarController_ view] frame]; | 193 defaultSheetY = NSMaxY([[window contentView] frame]); |
| 194 defaultSheetY = toolbarFrame.origin.y; | |
| 195 } else { | |
| 196 // The toolbar is not shown in application mode. The sheet should be | |
| 197 // located at the top of the window, under the title of the window. | |
| 198 defaultSheetY = NSHeight([[window contentView] frame]) - | |
| 199 defaultSheetRect.size.height; | |
|
Andre
2015/01/06 20:55:33
This height has no meaning according to AppKit doc
| |
| 200 } | |
| 201 break; | |
| 202 } | |
| 203 } | 194 } |
| 204 | 195 |
| 205 // AppKit may shift the window up to fit the sheet on screen, but it will | 196 // AppKit may shift the window up to fit the sheet on screen, but it will |
| 206 // never adjust the height of the sheet, or the origin of the sheet relative | 197 // never adjust the height of the sheet, or the origin of the sheet relative |
| 207 // to the window. Adjust the origin to prevent sheets from extending past the | 198 // to the window. Adjust the origin to prevent sheets from extending past the |
| 208 // bottom of the screen. | 199 // bottom of the screen. |
| 209 | 200 |
| 210 // Don't allow the sheet to extend past the bottom of the window. This logic | 201 // Don't allow the sheet to extend past the bottom of the window. This logic |
| 211 // intentionally ignores the size of the screens, since the window might span | 202 // intentionally ignores the size of the screens, since the window might span |
| 212 // multiple screens, and AppKit may reposition the window. | 203 // multiple screens, and AppKit may reposition the window. |
| 213 CGFloat sheetHeight = NSHeight([sheet frame]); | 204 CGFloat sheetHeight = NSHeight([sheet frame]); |
| 214 defaultSheetY = std::max(defaultSheetY, sheetHeight); | 205 defaultSheetY = std::max(defaultSheetY, sheetHeight); |
| 215 | 206 |
| 216 // It doesn't make sense to provide a Y higher than the height of the window. | 207 // It doesn't make sense to provide a Y higher than the height of the window. |
| 217 CGFloat windowHeight = NSHeight([window frame]); | 208 CGFloat windowHeight = NSHeight([window frame]); |
| 218 defaultSheetY = std::min(defaultSheetY, windowHeight); | 209 defaultSheetY = std::min(defaultSheetY, windowHeight); |
| 219 | 210 |
| 220 defaultSheetRect.origin.y = defaultSheetY; | 211 defaultSheetLocation.origin.y = defaultSheetY; |
| 221 return defaultSheetRect; | 212 return defaultSheetLocation; |
| 222 } | 213 } |
| 223 | 214 |
| 224 - (void)layoutSubviews { | 215 - (void)layoutSubviews { |
| 225 // Suppress title drawing if necessary. | 216 // Suppress title drawing if necessary. |
| 226 if ([self.window respondsToSelector:@selector(setShouldHideTitle:)]) | 217 if ([self.window respondsToSelector:@selector(setShouldHideTitle:)]) |
| 227 [(id)self.window setShouldHideTitle:![self hasTitleBar]]; | 218 [(id)self.window setShouldHideTitle:![self hasTitleBar]]; |
| 228 | 219 |
| 229 [bookmarkBarController_ updateHiddenState]; | 220 [bookmarkBarController_ updateHiddenState]; |
| 230 [self updateSubviewZOrder]; | 221 [self updateSubviewZOrder]; |
| 231 | 222 |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1020 } | 1011 } |
| 1021 if (!enteringAppKitFullscreen_) | 1012 if (!enteringAppKitFullscreen_) |
| 1022 return NO; | 1013 return NO; |
| 1023 if (enteringAppKitFullscreenOnPrimaryScreen_) | 1014 if (enteringAppKitFullscreenOnPrimaryScreen_) |
| 1024 return NO; | 1015 return NO; |
| 1025 | 1016 |
| 1026 return YES; | 1017 return YES; |
| 1027 } | 1018 } |
| 1028 | 1019 |
| 1029 @end // @implementation BrowserWindowController(Private) | 1020 @end // @implementation BrowserWindowController(Private) |
| OLD | NEW |