Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller_private.mm

Issue 12594015: Alternate NTP Mac: Push down overlay in presentation mode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #import "base/memory/scoped_nsobject.h" 10 #import "base/memory/scoped_nsobject.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 202 }
203 203
204 // Sanity-check |maxY|. 204 // Sanity-check |maxY|.
205 DCHECK_GE(maxY, minY); 205 DCHECK_GE(maxY, minY);
206 DCHECK_LE(maxY, NSMaxY(contentBounds) + yOffset); 206 DCHECK_LE(maxY, NSMaxY(contentBounds) + yOffset);
207 207
208 // Place the toolbar at the top of the reserved area. 208 // Place the toolbar at the top of the reserved area.
209 CGFloat toolbarTopY = maxY; 209 CGFloat toolbarTopY = maxY;
210 maxY = [self layoutToolbarAtMinX:minX maxY:maxY width:width]; 210 maxY = [self layoutToolbarAtMinX:minX maxY:maxY width:width];
211 211
212 // If we're not displaying the bookmark bar below the infobar, then it goes 212 // If we're not displaying the bookmark bar below the info bar, then it goes
213 // immediately below the toolbar. 213 // immediately below the toolbar.
214 BOOL placeBookmarkBarBelowInfoBar = [self placeBookmarkBarBelowInfoBar]; 214 BOOL placeBookmarkBarBelowInfoBar = [self placeBookmarkBarBelowInfoBar];
215 if (!placeBookmarkBarBelowInfoBar) 215 if (!placeBookmarkBarBelowInfoBar)
216 maxY = [self layoutBookmarkBarAtMinX:minX maxY:maxY width:width]; 216 maxY = [self layoutBookmarkBarAtMinX:minX maxY:maxY width:width];
217 217
218 // The floating bar backing view doesn't actually add any height. 218 // The floating bar backing view doesn't actually add any height.
219 NSRect floatingBarBackingRect = 219 NSRect floatingBarBackingRect =
220 NSMakeRect(minX, maxY, width, floatingBarHeight); 220 NSMakeRect(minX, maxY, width, floatingBarHeight);
221 [self layoutFloatingBarBackingView:floatingBarBackingRect 221 [self layoutFloatingBarBackingView:floatingBarBackingRect
222 presentationMode:inPresentationMode]; 222 presentationMode:inPresentationMode];
223 223
224 // Place the find bar immediately below the toolbar/attached bookmark bar. In 224 // Place the find bar immediately below the toolbar/attached bookmark bar. In
225 // presentation mode, it hangs off the top of the screen when the bar is 225 // presentation mode, it hangs off the top of the screen when the bar is
226 // hidden. The find bar is unaffected by the side tab positioning. 226 // hidden. The find bar is unaffected by the side tab positioning.
227 [findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:width]; 227 [findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:width];
228 [fullscreenExitBubbleController_ positionInWindowAtTop:maxY width:width]; 228 [fullscreenExitBubbleController_ positionInWindowAtTop:maxY width:width];
229 229
230 // If in presentation mode, reset |maxY| to top of screen, so that the 230 // If in presentation mode, reset |maxY| to top of screen, so that the
231 // floating bar slides over the things which appear to be in the content area. 231 // floating bar slides over the things which appear to be in the content area.
232 if (inPresentationMode) 232 if (inPresentationMode)
233 maxY = NSMaxY(contentBounds); 233 maxY = NSMaxY(contentBounds);
234 234
235 // Also place the infobar container immediate below the toolbar, except in 235 // Also place the info bar container immediate below the toolbar, except in
236 // presentation mode in which case it's at the top of the visual content area. 236 // presentation mode in which case it's at the top of the visual content area.
237 maxY = [self layoutInfoBarAtMinX:minX maxY:maxY width:width]; 237 maxY = [self layoutInfoBarAtMinX:minX maxY:maxY width:width];
238 238
239 // Place the download shelf, if any, at the bottom of the view. 239 // Place the download shelf, if any, at the bottom of the view.
240 minY = [self layoutDownloadShelfAtMinX:minX minY:minY width:width]; 240 minY = [self layoutDownloadShelfAtMinX:minX minY:minY width:width];
241 241
242 // Place the bookmark bar. 242 // Place the bookmark bar.
243 if (placeBookmarkBarBelowInfoBar) 243 if (placeBookmarkBarBelowInfoBar)
244 maxY = [self layoutBookmarkBarAtMinX:minX maxY:maxY width:width]; 244 maxY = [self layoutBookmarkBarAtMinX:minX maxY:maxY width:width];
245 245
246 // In presentation mode the content area takes up all the remaining space 246 // In presentation mode the content area takes up all the remaining space
247 // (from the bottom of the infobar down). In normal mode the content area 247 // (from the bottom of the info bar down). In normal mode the content area
248 // takes up the space between the bottom of the toolbar down. 248 // takes up the space between the bottom of the toolbar down.
249 CGFloat contentAreaTop = 0; 249 CGFloat contentAreaTop = 0;
250 if (inPresentationMode) { 250 if (inPresentationMode) {
251 toolbarToWebContentsOffset_ = 0; 251 // The tabContentaArea starts at the bottom of the info bar (or top of the
252 // screen if there's no info bar).
252 contentAreaTop = maxY; 253 contentAreaTop = maxY;
254 CGFloat floatingBarHeight =
255 NSHeight(floatingBarBackingRect) * [self floatingBarShownFraction];
256 // When an instant overlay is shown this is the amount it needs to be pushed
257 // down so that it doesn't get covered by the floating toolbar.
258 toolbarToWebContentsOffset_ =
259 floatingBarHeight - (NSMaxY(contentBounds) - maxY);
253 } else { 260 } else {
261 // The tabContentArea view starts below the omnibox.
254 CGFloat minToolbarHeight = 0; 262 CGFloat minToolbarHeight = 0;
255 if ([self hasToolbar]) { 263 if ([self hasToolbar]) {
256 minToolbarHeight = [toolbarController_ 264 minToolbarHeight = [toolbarController_
257 desiredHeightForCompression:bookmarks::kBookmarkBarOverlap]; 265 desiredHeightForCompression:bookmarks::kBookmarkBarOverlap];
258 } 266 }
259 contentAreaTop = toolbarTopY - minToolbarHeight; 267 contentAreaTop = toolbarTopY - minToolbarHeight;
268 // This is the space between the bottom of the omnibox and the bottom of the
269 // last bar (info bar or bookmark bar or toolbar). This is used to push the
270 // tab web content down when no instant overlay is shown.
260 toolbarToWebContentsOffset_ = contentAreaTop - maxY; 271 toolbarToWebContentsOffset_ = contentAreaTop - maxY;
261 } 272 }
262 [self updateContentOffsets]; 273 [self updateContentOffsets];
263 274
264 NSRect contentAreaRect = NSMakeRect(minX, minY, width, contentAreaTop - minY); 275 NSRect contentAreaRect = NSMakeRect(minX, minY, width, contentAreaTop - minY);
265 [self layoutTabContentArea:contentAreaRect]; 276 [self layoutTabContentArea:contentAreaRect];
266 277
267 // Normally, we don't need to tell the toolbar whether or not to show the 278 // Normally, we don't need to tell the toolbar whether or not to show the
268 // divider, but things break down during animation. 279 // divider, but things break down during animation.
269 [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]]; 280 [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]];
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 DCHECK([toolbarView isHidden]); 386 DCHECK([toolbarView isHidden]);
376 } 387 }
377 } 388 }
378 [toolbarView setFrame:toolbarFrame]; 389 [toolbarView setFrame:toolbarFrame];
379 return maxY; 390 return maxY;
380 } 391 }
381 392
382 - (BOOL)placeBookmarkBarBelowInfoBar { 393 - (BOOL)placeBookmarkBarBelowInfoBar {
383 // If we are currently displaying the NTP detached bookmark bar or animating 394 // If we are currently displaying the NTP detached bookmark bar or animating
384 // to/from it (from/to anything else), we display the bookmark bar below the 395 // to/from it (from/to anything else), we display the bookmark bar below the
385 // infobar. 396 // info bar.
386 return [bookmarkBarController_ isInState:BookmarkBar::DETACHED] || 397 return [bookmarkBarController_ isInState:BookmarkBar::DETACHED] ||
387 [bookmarkBarController_ isAnimatingToState:BookmarkBar::DETACHED] || 398 [bookmarkBarController_ isAnimatingToState:BookmarkBar::DETACHED] ||
388 [bookmarkBarController_ isAnimatingFromState:BookmarkBar::DETACHED]; 399 [bookmarkBarController_ isAnimatingFromState:BookmarkBar::DETACHED];
389 } 400 }
390 401
391 - (CGFloat)layoutBookmarkBarAtMinX:(CGFloat)minX 402 - (CGFloat)layoutBookmarkBarAtMinX:(CGFloat)minX
392 maxY:(CGFloat)maxY 403 maxY:(CGFloat)maxY
393 width:(CGFloat)width { 404 width:(CGFloat)width {
394 [bookmarkBarController_ updateHiddenState]; 405 [bookmarkBarController_ updateHiddenState];
395 406
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 if ([overlayableContentsController_ isShowingOverlay]) 870 if ([overlayableContentsController_ isShowingOverlay])
860 return browser_window_controller::kInstantUIOverlay; 871 return browser_window_controller::kInstantUIOverlay;
861 872
862 if (browser_->search_model()->top_bars_visible()) 873 if (browser_->search_model()->top_bars_visible())
863 return browser_window_controller::kInstantUINone; 874 return browser_window_controller::kInstantUINone;
864 875
865 return browser_window_controller::kInstantUIFullPageResults; 876 return browser_window_controller::kInstantUIFullPageResults;
866 } 877 }
867 878
868 - (void)updateContentOffsets { 879 - (void)updateContentOffsets {
869 // Normally the tab contents sits below the bookmark bar. This is achieved by 880 if ([self inPresentationMode]) {
870 // setting the offset to the height of the bookmark bar. The only exception 881 // In presentation mode the tabContentArea starts at the bottom of the info
871 // is on the search results page where the Instant results are shown inside 882 // bar (or top of the screen if there's no info bar).
872 // the page and not in the overlay contents as usual. 883 if ([self currentInstantUIState] !=
873 CGFloat tabContentsOffset = toolbarToWebContentsOffset_; 884 browser_window_controller::kInstantUIFullPageResults) {
874 if ([self currentInstantUIState] == 885 // Normal mode, keep the tab web contents at the top (below the info bar).
875 browser_window_controller::kInstantUIFullPageResults) { 886 [overlayableContentsController_ setActiveContainerOffset:0];
876 tabContentsOffset = 0; 887 } else {
888 // Instant suggestions are displayed in the main tab contents so push that
889 // down so that the floating toolbar doesn't obscure it.
890 [overlayableContentsController_
891 setActiveContainerOffset:toolbarToWebContentsOffset_];
892 }
893 // Floating overlay (if any) should also be below the floating toolbar.
894 [overlayableContentsController_
895 setOverlayContentsOffset:toolbarToWebContentsOffset_];
896
897 [[self tabContentArea] setContentOffset:0];
898 [devToolsController_ setTopContentOffset:0];
899 } else {
900 // In normal mode the tabContentArea starts just below the omnibox and the
901 // bookmark bar and info bar overlap it.
902 if ([self currentInstantUIState] !=
903 browser_window_controller::kInstantUIFullPageResults) {
904 // Normal mode, push the tab web contents down so that it doesn't obscure
905 // the bookmark bar and info bar.
906 [overlayableContentsController_
907 setActiveContainerOffset:toolbarToWebContentsOffset_];
908 } else {
909 // Instant suggestions are displayed in the main tab contents so don't
910 // push it down (keep it next to the omnibox).
911 [overlayableContentsController_ setActiveContainerOffset:0];
912 }
913 // Floating overlay (if any) should also be at the top (next to the
914 // omnibox).
915 [overlayableContentsController_ setOverlayContentsOffset:0];
916
917 // Prevent the fast resize view from drawing white over the bookmark bar.
918 [[self tabContentArea] setContentOffset:toolbarToWebContentsOffset_];
919 // Prevent the dev tools splitter from overlapping the bookmark bar.
920 if ([self currentInstantUIState] !=
921 browser_window_controller::kInstantUINone) {
922 [devToolsController_ setTopContentOffset:0];
923 } else {
924 [devToolsController_ setTopContentOffset:toolbarToWebContentsOffset_];
925 }
877 } 926 }
878 [overlayableContentsController_ setActiveContainerOffset:tabContentsOffset];
879
880 // Prevent the fast resize view from drawing white over the bookmark bar.
881 [[self tabContentArea] setContentOffset:toolbarToWebContentsOffset_];
882
883 // Prevent the dev tools splitter from overlapping the bookmark bar.
884 if ([self currentInstantUIState] != browser_window_controller::kInstantUINone)
885 [devToolsController_ setTopContentOffset:0];
886 else
887 [devToolsController_ setTopContentOffset:toolbarToWebContentsOffset_];
888 } 927 }
889 928
890 - (void)updateSubviewZOrder:(BOOL)inPresentationMode { 929 - (void)updateSubviewZOrder:(BOOL)inPresentationMode {
891 NSView* contentView = [[self window] contentView]; 930 NSView* contentView = [[self window] contentView];
892 NSView* toolbarView = [toolbarController_ view]; 931 NSView* toolbarView = [toolbarController_ view];
893 932
894 if (inPresentationMode) { 933 if (inPresentationMode) {
895 // Toolbar is above tab contents so that it can slide down from top of 934 // Toolbar is above tab contents so that it can slide down from top of
896 // screen. 935 // screen.
897 [contentView cr_ensureSubview:toolbarView 936 [contentView cr_ensureSubview:toolbarView
898 isPositioned:NSWindowAbove 937 isPositioned:NSWindowAbove
899 relativeTo:[self tabContentArea]]; 938 relativeTo:[self tabContentArea]];
900 } else { 939 } else {
901 // Toolbar is below tab contents so that the infobar arrow can appear above 940 // Toolbar is below tab contents so that the infob ar arrow can appear above
902 // it. Unlike other views the toolbar never overlaps the actual web 941 // it. Unlike other views the toolbar never overlaps the actual web
903 // content. 942 // content.
904 [contentView cr_ensureSubview:toolbarView 943 [contentView cr_ensureSubview:toolbarView
905 isPositioned:NSWindowBelow 944 isPositioned:NSWindowBelow
906 relativeTo:[self tabContentArea]]; 945 relativeTo:[self tabContentArea]];
907 } 946 }
908 947
909 // The bookmark bar is always below the toolbar. In normal mode this means 948 // The bookmark bar is always below the toolbar. In normal mode this means
910 // that it is below tab contents. This allows Instant results to be above 949 // that it is below tab contents. This allows Instant results to be above
911 // the bookmark bar. 950 // the bookmark bar.
912 [contentView cr_ensureSubview:[bookmarkBarController_ view] 951 [contentView cr_ensureSubview:[bookmarkBarController_ view]
913 isPositioned:NSWindowBelow 952 isPositioned:NSWindowBelow
914 relativeTo:toolbarView]; 953 relativeTo:toolbarView];
915 954
916 if (inPresentationMode) { 955 if (inPresentationMode) {
917 // In presentation mode the infobar is below all other views. 956 // In presentation mode the info bar is below all other views.
918 [contentView cr_ensureSubview:[infoBarContainerController_ view] 957 [contentView cr_ensureSubview:[infoBarContainerController_ view]
919 isPositioned:NSWindowBelow 958 isPositioned:NSWindowBelow
920 relativeTo:[self tabContentArea]]; 959 relativeTo:[self tabContentArea]];
921 } else { 960 } else {
922 // Above the toolbar but still below tab contents. Similar to the bookmark 961 // Above the toolbar but still below tab contents. Similar to the bookmark
923 // bar, this allows Instant results to be above the info bar. 962 // bar, this allows Instant results to be above the info bar.
924 [contentView cr_ensureSubview:[infoBarContainerController_ view] 963 [contentView cr_ensureSubview:[infoBarContainerController_ view]
925 isPositioned:NSWindowAbove 964 isPositioned:NSWindowAbove
926 relativeTo:toolbarView]; 965 relativeTo:toolbarView];
927 } 966 }
(...skipping 23 matching lines...) Expand all
951 relativeTo:[bookmarkBarController_ view]]; 990 relativeTo:[bookmarkBarController_ view]];
952 } else { 991 } else {
953 [contentView cr_ensureSubview:floatingBarBackingView_ 992 [contentView cr_ensureSubview:floatingBarBackingView_
954 isPositioned:NSWindowBelow 993 isPositioned:NSWindowBelow
955 relativeTo:[bookmarkBarController_ view]]; 994 relativeTo:[bookmarkBarController_ view]];
956 } 995 }
957 } 996 }
958 } 997 }
959 998
960 @end // @implementation BrowserWindowController(Private) 999 @end // @implementation BrowserWindowController(Private)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698