diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-27 22:19:13 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-27 22:19:13 +0000 |
commit | 85dca4cdd5d39d23bac09ed31417a0fe691aba2d (patch) | |
tree | 49857b6a51bebda5aac92c6c4a5ebdfc9d33f0b9 | |
parent | 43fe640e64aac277a5e0b28fe6b58d2973164df8 (diff) | |
download | chromium_src-85dca4cdd5d39d23bac09ed31417a0fe691aba2d.zip chromium_src-85dca4cdd5d39d23bac09ed31417a0fe691aba2d.tar.gz chromium_src-85dca4cdd5d39d23bac09ed31417a0fe691aba2d.tar.bz2 |
Alternate NTP Mac: Push down overlay in presentation mode
In presentation mode the browser toolbar and bookmark bar are in a
special floating view. This view obscures the instant overlay since
the overlay is at the top of the screen.
This CL pushes the overlay down so that it's not obscured when the
floating toolbar view is shown.
Test build: https://docs.google.com/file/d/0B0Odde3V7EhWTmtMTXBJYmtGS3M/edit?usp=sharing
BUG=167185
TEST=
Launched Chrome with instant extended enabled.
Enter presentation mode and type in the omnibox.
Verify that the omnibox popup is below the floating toolbar view.
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=190980
Review URL: https://chromiumcodereview.appspot.com/12594015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191048 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 125 insertions, 28 deletions
diff --git a/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm index 0127a5a..b27bc83 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm @@ -317,6 +317,29 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, VerifyZOrder(view_list); } +// Verify that in presentation mode, Instant search results are below the +// floating toolbar. +IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, + DISABLED_OverlayOffsetInstantPresentationMode) { + chrome::ToggleFullscreenMode(browser()); + ShowInstantResults(); + [controller() setFloatingBarShownFraction:0.0]; + EXPECT_EQ( + 0, [[controller() overlayableContentsController] overlayContentsOffset]); + EXPECT_EQ( + 0, [[controller() overlayableContentsController] activeContainerOffset]); + [controller() setFloatingBarShownFraction:1.0]; + + NSView* floating_bar = GetViewWithID(VIEW_ID_FULLSCREEN_FLOATING_BAR); + CGFloat floating_bar_height = NSHeight([floating_bar frame]); + EXPECT_EQ( + floating_bar_height, + [[controller() overlayableContentsController] overlayContentsOffset]); + EXPECT_EQ( + floating_bar_height, + [[controller() overlayableContentsController] activeContainerOffset]); +} + // Verify that if the fullscreen floating bar view is below the tab content area // then calling |updateSubviewZOrder:| will correctly move back above. IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, diff --git a/chrome/browser/ui/cocoa/browser_window_controller_private.mm b/chrome/browser/ui/cocoa/browser_window_controller_private.mm index 14788ab..d5f5d33 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller_private.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller_private.mm @@ -209,7 +209,7 @@ willPositionSheet:(NSWindow*)sheet CGFloat toolbarTopY = maxY; maxY = [self layoutToolbarAtMinX:minX maxY:maxY width:width]; - // If we're not displaying the bookmark bar below the infobar, then it goes + // If we're not displaying the bookmark bar below the info bar, then it goes // immediately below the toolbar. BOOL placeBookmarkBarBelowInfoBar = [self placeBookmarkBarBelowInfoBar]; if (!placeBookmarkBarBelowInfoBar) @@ -232,7 +232,7 @@ willPositionSheet:(NSWindow*)sheet if (inPresentationMode) maxY = NSMaxY(contentBounds); - // Also place the infobar container immediate below the toolbar, except in + // Also place the info bar container immediate below the toolbar, except in // presentation mode in which case it's at the top of the visual content area. maxY = [self layoutInfoBarAtMinX:minX maxY:maxY width:width]; @@ -244,19 +244,30 @@ willPositionSheet:(NSWindow*)sheet maxY = [self layoutBookmarkBarAtMinX:minX maxY:maxY width:width]; // In presentation mode the content area takes up all the remaining space - // (from the bottom of the infobar down). In normal mode the content area + // (from the bottom of the info bar down). In normal mode the content area // takes up the space between the bottom of the toolbar down. CGFloat contentAreaTop = 0; if (inPresentationMode) { - toolbarToWebContentsOffset_ = 0; + // The tabContentaArea starts at the bottom of the info bar (or top of the + // screen if there's no info bar). contentAreaTop = maxY; + CGFloat floatingBarHeight = + NSHeight(floatingBarBackingRect) * [self floatingBarShownFraction]; + // When an instant overlay is shown this is the amount it needs to be pushed + // down so that it doesn't get covered by the floating toolbar. + toolbarToWebContentsOffset_ = + floatingBarHeight - (NSMaxY(contentBounds) - maxY); } else { + // The tabContentArea view starts below the omnibox. CGFloat minToolbarHeight = 0; if ([self hasToolbar]) { minToolbarHeight = [toolbarController_ desiredHeightForCompression:bookmarks::kBookmarkBarOverlap]; } contentAreaTop = toolbarTopY - minToolbarHeight; + // This is the space between the bottom of the omnibox and the bottom of the + // last bar (info bar or bookmark bar or toolbar). This is used to push the + // tab web content down when no instant overlay is shown. toolbarToWebContentsOffset_ = contentAreaTop - maxY; } [self updateContentOffsets]; @@ -382,7 +393,7 @@ willPositionSheet:(NSWindow*)sheet - (BOOL)placeBookmarkBarBelowInfoBar { // If we are currently displaying the NTP detached bookmark bar or animating // to/from it (from/to anything else), we display the bookmark bar below the - // infobar. + // info bar. return [bookmarkBarController_ isInState:BookmarkBar::DETACHED] || [bookmarkBarController_ isAnimatingToState:BookmarkBar::DETACHED] || [bookmarkBarController_ isAnimatingFromState:BookmarkBar::DETACHED]; @@ -866,25 +877,53 @@ willPositionSheet:(NSWindow*)sheet } - (void)updateContentOffsets { - // Normally the tab contents sits below the bookmark bar. This is achieved by - // setting the offset to the height of the bookmark bar. The only exception - // is on the search results page where the Instant results are shown inside - // the page and not in the overlay contents as usual. - CGFloat tabContentsOffset = toolbarToWebContentsOffset_; - if ([self currentInstantUIState] == - browser_window_controller::kInstantUIFullPageResults) { - tabContentsOffset = 0; - } - [overlayableContentsController_ setActiveContainerOffset:tabContentsOffset]; - - // Prevent the fast resize view from drawing white over the bookmark bar. - [[self tabContentArea] setContentOffset:toolbarToWebContentsOffset_]; + if ([self inPresentationMode]) { + // In presentation mode the tabContentArea starts at the bottom of the info + // bar (or top of the screen if there's no info bar). + if ([self currentInstantUIState] != + browser_window_controller::kInstantUIFullPageResults) { + // Normal mode, keep the tab web contents at the top (below the info bar). + [overlayableContentsController_ setActiveContainerOffset:0]; + } else { + // Instant suggestions are displayed in the main tab contents so push that + // down so that the floating toolbar doesn't obscure it. + [overlayableContentsController_ + setActiveContainerOffset:toolbarToWebContentsOffset_]; + } + // Floating overlay (if any) should also be below the floating toolbar. + [overlayableContentsController_ + setOverlayContentsOffset:toolbarToWebContentsOffset_]; - // Prevent the dev tools splitter from overlapping the bookmark bar. - if ([self currentInstantUIState] != browser_window_controller::kInstantUINone) + [[self tabContentArea] setContentOffset:0]; [devToolsController_ setTopContentOffset:0]; - else - [devToolsController_ setTopContentOffset:toolbarToWebContentsOffset_]; + } else { + // In normal mode the tabContentArea starts just below the omnibox and the + // bookmark bar and info bar overlap it. + if ([self currentInstantUIState] != + browser_window_controller::kInstantUIFullPageResults) { + // Normal mode, push the tab web contents down so that it doesn't obscure + // the bookmark bar and info bar. + [overlayableContentsController_ + setActiveContainerOffset:toolbarToWebContentsOffset_]; + } else { + // Instant suggestions are displayed in the main tab contents so don't + // push it down (keep it next to the omnibox). + [overlayableContentsController_ setActiveContainerOffset:0]; + } + // Floating overlay (if any) should also be at the top (next to the + // omnibox). + [overlayableContentsController_ setOverlayContentsOffset:0]; + + // Prevent the fast resize view from drawing white over the bookmark bar. + [[self tabContentArea] setContentOffset:toolbarToWebContentsOffset_]; + // Prevent the dev tools splitter from overlapping the bookmark bar. + if ([self currentInstantUIState] != + browser_window_controller::kInstantUINone) { + [devToolsController_ setTopContentOffset:0]; + } else { + [devToolsController_ setTopContentOffset:toolbarToWebContentsOffset_]; + } + } } - (void)updateSubviewZOrder:(BOOL)inPresentationMode { @@ -898,7 +937,7 @@ willPositionSheet:(NSWindow*)sheet isPositioned:NSWindowAbove relativeTo:[self tabContentArea]]; } else { - // Toolbar is below tab contents so that the infobar arrow can appear above + // Toolbar is below tab contents so that the infob ar arrow can appear above // it. Unlike other views the toolbar never overlaps the actual web // content. [contentView cr_ensureSubview:toolbarView @@ -914,7 +953,7 @@ willPositionSheet:(NSWindow*)sheet relativeTo:toolbarView]; if (inPresentationMode) { - // In presentation mode the infobar is below all other views. + // In presentation mode the info bar is below all other views. [contentView cr_ensureSubview:[infoBarContainerController_ view] isPositioned:NSWindowBelow relativeTo:[self tabContentArea]]; diff --git a/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h index 769aea7..1e7c859 100644 --- a/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h +++ b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h @@ -63,12 +63,18 @@ class WebContents; // this is set to the height of the bookmark bar so that the bookmark bar is // not obscured. CGFloat activeContainerOffset_; + + // The vertical offset between the top of the view and the overlay. This is + // used in presentation mode to push the overlay below the floating toolbar + // view. + CGFloat overlayContentsOffset_; } @property(readonly, nonatomic) NSView* activeContainer; @property(readonly, nonatomic) NSView* dropShadowView; @property(readonly, nonatomic) BOOL drawDropShadow; @property(assign, nonatomic) CGFloat activeContainerOffset; +@property(assign, nonatomic) CGFloat overlayContentsOffset; // Initialization. - (id)initWithBrowser:(Browser*)browser diff --git a/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.mm b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.mm index 786b076..634f456 100644 --- a/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.mm +++ b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.mm @@ -22,6 +22,7 @@ @synthesize drawDropShadow = drawDropShadow_; @synthesize activeContainerOffset = activeContainerOffset_; +@synthesize overlayContentsOffset = overlayContentsOffset_; - (id)initWithBrowser:(Browser*)browser windowController:(BrowserWindowController*)windowController { @@ -145,6 +146,14 @@ [self layoutViews]; } +- (void)setOverlayContentsOffset:(CGFloat)overlayContentsOffset { + if (overlayContentsOffset_ == overlayContentsOffset) + return; + + overlayContentsOffset_ = overlayContentsOffset; + [self layoutViews]; +} + - (void)viewDidResize:(NSNotification*)note { [self layoutViews]; } @@ -165,8 +174,8 @@ if (overlayContents_) { NSRect overlayFrame = bounds; overlayFrame.size.height = [self overlayHeightInPixels]; - overlayFrame.origin.y = - NSMinY([topSeparatorView_ frame]) - NSHeight(overlayFrame); + overlayFrame.origin.y = NSMinY([topSeparatorView_ frame]) - + NSHeight(overlayFrame) - overlayContentsOffset_; [overlayContents_->GetView()->GetNativeView() setFrame:overlayFrame]; if (dropShadowView_) { @@ -192,8 +201,8 @@ } - (CGFloat)overlayHeightInPixels { - CGFloat height = - NSHeight([[self view] bounds]) - NSHeight([topSeparatorView_ frame]); + CGFloat height = NSHeight([[self view] bounds]) - + NSHeight([topSeparatorView_ frame]) - overlayContentsOffset_; switch (overlayHeightUnits_) { case INSTANT_SIZE_PERCENT: return std::min(height, (height * overlayHeight_) / 100); diff --git a/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm index cdbb80b..d2e115d 100644 --- a/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm +++ b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm @@ -172,3 +172,23 @@ IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HeightChangeNoHide) { instant_overlay_model_.SetOverlayState(mode, 11, INSTANT_SIZE_PERCENT); EXPECT_EQ(1, visibility_changed_count_); } + +IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, OverlayOffset) { + SearchMode mode; + mode.mode = SearchMode::MODE_NTP; + CGFloat expected_height = 10; + InstantSizeUnits units = INSTANT_SIZE_PIXELS; + instant_overlay_model_.SetOverlayState(mode, expected_height, units); + + CGFloat separator_height = [OverlayTopSeparatorView preferredHeight]; + NSView* overlay_view = web_contents_->GetView()->GetNativeView(); + EXPECT_EQ(separator_height, + NSMaxY([[overlay_view superview] frame]) - + NSMaxY([overlay_view frame])); + + CGFloat offset = 30; + [controller_ setOverlayContentsOffset:offset]; + EXPECT_EQ(separator_height + offset, + NSMaxY([[overlay_view superview] frame]) - + NSMaxY([overlay_view frame])); +} |