summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-23 20:56:09 +0000
committersail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-23 20:56:09 +0000
commitf2993654d80165413572a4b7a9f9aa8dd2cba9fe (patch)
treec9b503a0c96028f0dc7d45c0b233153de4b45259
parent098dff8adaddf498b929562fb1e1f7fa2fa5bb2f (diff)
downloadchromium_src-f2993654d80165413572a4b7a9f9aa8dd2cba9fe.zip
chromium_src-f2993654d80165413572a4b7a9f9aa8dd2cba9fe.tar.gz
chromium_src-f2993654d80165413572a4b7a9f9aa8dd2cba9fe.tar.bz2
Revert 178367
> Alternate NTP: Don't hide bookmark bar on instant > > Currently when typing in the omnibox the instant search results are shown next to omnibox by hiding the bookmark bar. > > This causes the web contents to jump up by 26 pixels. > > This CL works around this by changing the zorder such that the bookmark bar is under the web contents. With this approach there's no need to hide the bookmark bar and the web contents doesn't jump when typing. > > Screen recording: > New: https://docs.google.com/file/d/0B0Odde3V7EhWcnBBRVBxUXdnN2c/edit > New Infobar: https://docs.google.com/file/d/0B0Odde3V7EhWOG4wVWZ6WGp0aDQ/edit > Old: https://docs.google.com/file/d/0B0Odde3V7EhWOFYzeTlVbzRXX2s/edit > > Sample build: > https://docs.google.com/file/d/0B0Odde3V7EhWLXdnYVpHa0xEcFk/edit > > BUG=170835 > TBR=thakis@chromium.org > > Review URL: https://codereview.chromium.org/11876036 TBR=sail@chromium.org Review URL: https://codereview.chromium.org/12049047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178376 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/browser.cc14
-rw-r--r--chrome/browser/ui/browser.h3
-rw-r--r--chrome/browser/ui/cocoa/background_gradient_view.mm2
-rw-r--r--chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm7
-rw-r--r--chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_browsertest.mm143
-rw-r--r--chrome/browser/ui/cocoa/browser_window_cocoa.h8
-rw-r--r--chrome/browser/ui/cocoa/browser_window_cocoa.mm10
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller.h19
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller.mm46
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm348
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller_private.h14
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller_private.mm165
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller_unittest.mm2
-rw-r--r--chrome/browser/ui/cocoa/fast_resize_view.h6
-rw-r--r--chrome/browser/ui/cocoa/fast_resize_view.mm18
-rw-r--r--chrome/browser/ui/cocoa/nsview_additions.h11
-rw-r--r--chrome/browser/ui/cocoa/nsview_additions.mm34
-rw-r--r--chrome/browser/ui/cocoa/nsview_additions_unittest.mm98
-rw-r--r--chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.mm1
-rw-r--r--chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h18
-rw-r--r--chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.mm33
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/chrome_tests_unit.gypi1
23 files changed, 231 insertions, 771 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index cbd53a9..951fce5 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -1252,7 +1252,7 @@ void Browser::MaybeUpdateBookmarkBarStateForInstantPreview(
// bookmark bar.
if (mode.is_search_suggestions() &&
bookmark_bar_state_ == BookmarkBar::SHOW) {
- UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
+ UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INSTANT_PREVIEW_STATE);
}
}
@@ -2229,10 +2229,8 @@ void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) {
}
// Don't allow the bookmark bar to be shown in suggestions mode.
-#if !defined(OS_MACOSX)
if (search_model_->mode().is_search_suggestions())
state = BookmarkBar::HIDDEN;
-#endif
if (state == bookmark_bar_state_)
return;
@@ -2249,10 +2247,14 @@ void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) {
return;
}
- bool shouldAnimate = reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE;
- window_->BookmarkBarStateChanged(shouldAnimate ?
+ // Don't animate if mode is |NTP| because the bookmark is attached at top when
+ // pref is on and detached at bottom when off.
+ BookmarkBar::AnimateChangeType animate_type =
+ (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE ||
+ reason == BOOKMARK_BAR_STATE_CHANGE_INSTANT_PREVIEW_STATE) ?
BookmarkBar::ANIMATE_STATE_CHANGE :
- BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
+ BookmarkBar::DONT_ANIMATE_STATE_CHANGE;
+ window_->BookmarkBarStateChanged(animate_type);
}
bool Browser::ShouldHideUIForFullscreen() const {
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index ec797fc..9822e2b 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -525,6 +525,9 @@ class Browser : public TabStripModelObserver,
// Change is the result of window toggling in/out of fullscreen mode.
BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN,
+
+ // Change is the result of a state change in the instant preview.
+ BOOKMARK_BAR_STATE_CHANGE_INSTANT_PREVIEW_STATE,
};
// Overridden from content::WebContentsDelegate:
diff --git a/chrome/browser/ui/cocoa/background_gradient_view.mm b/chrome/browser/ui/cocoa/background_gradient_view.mm
index db2a3ec..aeaf21c 100644
--- a/chrome/browser/ui/cocoa/background_gradient_view.mm
+++ b/chrome/browser/ui/cocoa/background_gradient_view.mm
@@ -31,8 +31,6 @@
}
- (void)setShowsDivider:(BOOL)show {
- if (showsDivider_ == show)
- return;
showsDivider_ = show;
[self setNeedsDisplay:YES];
}
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm
index 8d89ca1..e5e3387 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm
@@ -257,7 +257,10 @@ void RecordAppLaunch(Profile* profile, GURL url) {
rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage());
innerContentAnimationsEnabled_ = YES;
- stateAnimationsEnabled_ = YES;
+ // Disable state animations (for example, showing or hiding the bookmark
+ // bar) if the detached bookmark bar will be shown at the bottom of the new
+ // tab page.
+ stateAnimationsEnabled_ = ![self shouldShowAtBottomWhenDetached];
// Register for theme changes, bookmark button pulsing, ...
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
@@ -2356,7 +2359,7 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) {
}
- (BOOL)shouldShowAtBottomWhenDetached {
- return NO;
+ return chrome::search::IsInstantExtendedAPIEnabled(browser_->profile());
}
#pragma mark BookmarkButtonDelegate Protocol
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_browsertest.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_browsertest.mm
new file mode 100644
index 0000000..9e34e00
--- /dev/null
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_browsertest.mm
@@ -0,0 +1,143 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
+
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/bookmarks/bookmark_model_factory.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
+#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view.h"
+#import "chrome/browser/ui/cocoa/browser_window_controller.h"
+#import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
+#include "chrome/browser/ui/search/search.h"
+#include "chrome/browser/ui/search/search_ui.h"
+#include "chrome/common/url_constants.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "content/public/test/test_utils.h"
+#include "googleurl/src/gurl.h"
+
+class BottomBookmarkBarControllerTest : public InProcessBrowserTest {
+ public:
+ BottomBookmarkBarControllerTest() {
+ chrome::search::EnableInstantExtendedAPIForTesting();
+ }
+
+ virtual void SetUpOnMainThread() OVERRIDE {
+ AddTabAtIndex(1,
+ GURL(chrome::kChromeUINewTabURL),
+ content::PAGE_TRANSITION_LINK);
+ EXPECT_TRUE([GetBookmarkBarController() shouldShowAtBottomWhenDetached]);
+ EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]);
+ }
+
+ BrowserWindowController* GetBrowserWindowController() const {
+ NSWindow* window = browser()->window()->GetNativeWindow();
+ return [BrowserWindowController browserWindowControllerForWindow:window];
+ }
+
+ BookmarkBarController* GetBookmarkBarController() const {
+ return [GetBrowserWindowController() bookmarkBarController];
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BottomBookmarkBarControllerTest);
+};
+
+// Verify that the bookmark bar is positioned correctly when detached and
+// attached.
+IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, Position) {
+ // Verify detached bookmark bar is at the bottom of content area.
+ NSRect bookmark_bar_frame = [[GetBookmarkBarController() view] frame];
+ EXPECT_EQ(0, NSMinY(bookmark_bar_frame));
+
+ // Attach the bookmark bar and verify it's above the content area.
+ browser()->window()->ToggleBookmarkBar();
+ content::RunAllPendingInMessageLoop();
+ NSRect content_frame = [[GetBrowserWindowController() tabContentArea] frame];
+ bookmark_bar_frame = [[GetBookmarkBarController() view] frame];
+ EXPECT_EQ(NSMinX(content_frame), NSMinX(bookmark_bar_frame));
+ EXPECT_EQ(NSMaxY(content_frame), NSMinY(bookmark_bar_frame));
+}
+
+// Test that detached bookmark bar is positioned correctly when the download
+// shelf is visible.
+IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, PositionWithDownloads) {
+ // Show the download shelf.
+ DownloadShelfController* download_shelf_controller =
+ [GetBrowserWindowController() downloadShelf];
+ [download_shelf_controller show:nil];
+ EXPECT_FALSE([[download_shelf_controller view] isHidden]);
+
+ // Verify that the bookmark bar is at the bottom of the content area but above
+ // the download shelf.
+ NSRect content_frame = [[GetBrowserWindowController() tabContentArea] frame];
+ NSRect bookmark_bar_frame = [[GetBookmarkBarController() view] frame];
+ EXPECT_EQ(NSMinY(content_frame), NSMinY(bookmark_bar_frame));
+ EXPECT_NE(0, NSMinY(bookmark_bar_frame));
+ EXPECT_EQ(NSMinY(content_frame), NSMinY(bookmark_bar_frame));
+}
+
+// Verify that the bookmark bar shrinks when the window is narrow.
+IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, NarrowWindow) {
+ NSWindow* window = browser()->window()->GetNativeWindow();
+ NSRect window_frame = [window frame];
+ CGFloat expected_width =
+ roundf(chrome::search::kMaxWidthForBottomBookmarkBar / 2.0);
+ window_frame.size.width = expected_width +
+ chrome::search::kHorizontalPaddingForBottomBookmarkBar * 2;
+ [window setFrame:window_frame display:YES];
+ EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]);
+
+ NSRect frame = [[GetBookmarkBarController() view] frame];
+ EXPECT_EQ(chrome::search::kHorizontalPaddingForBottomBookmarkBar,
+ NSMinX(frame));
+ EXPECT_EQ(expected_width, NSWidth(frame));
+}
+
+// Verify that the bookmark bar's width doesn't go above its maximum value.
+IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, WideWindow) {
+ NSWindow* window = browser()->window()->GetNativeWindow();
+ NSRect window_frame = [window frame];
+ window_frame.size.width = chrome::search::kMaxWidthForBottomBookmarkBar +
+ chrome::search::kHorizontalPaddingForBottomBookmarkBar * 2 + 100;
+ [window setFrame:window_frame display:YES];
+ EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]);
+
+ NSRect frame = [[GetBookmarkBarController() view] frame];
+ EXPECT_EQ(roundf((NSWidth(window_frame) - NSWidth(frame)) / 2.0),
+ NSMinX(frame));
+ EXPECT_EQ(chrome::search::kMaxWidthForBottomBookmarkBar, NSWidth(frame));
+}
+
+// Verify that the bookmark bar is hidden if the content area height falls
+// below a minimum value.
+IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, MinContentHeight) {
+ NSWindow* window = browser()->window()->GetNativeWindow();
+ NSRect window_frame = [window frame];
+ window_frame.size.height =
+ chrome::search::kMinContentHeightForBottomBookmarkBar;
+ [window setFrame:window_frame display:YES];
+ EXPECT_TRUE([[GetBookmarkBarController() view] isHidden]);
+}
+
+IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, NoItemContainer) {
+ EXPECT_TRUE([GetBookmarkBarController() isEmpty]);
+ BookmarkBarView* button_view = [GetBookmarkBarController() buttonView];
+ EXPECT_TRUE([[button_view noItemContainer] isHidden]);
+
+ // Add a bookmark.
+ BookmarkModel* model =
+ BookmarkModelFactory::GetForProfile(browser()->profile());
+ const BookmarkNode* node = model->bookmark_bar_node();
+ model->AddURL(node,
+ node->child_count(),
+ ASCIIToUTF16("title"),
+ GURL("http://www.google.com"));
+
+ // Item container should remain hidden.
+ EXPECT_FALSE([GetBookmarkBarController() isEmpty]);
+ EXPECT_TRUE([[button_view noItemContainer] isHidden]);
+}
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.h b/chrome/browser/ui/cocoa/browser_window_cocoa.h
index 285ed46..3ec1321 100644
--- a/chrome/browser/ui/cocoa/browser_window_cocoa.h
+++ b/chrome/browser/ui/cocoa/browser_window_cocoa.h
@@ -10,7 +10,6 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/extensions/extension_keybinding_registry.h"
#include "chrome/browser/ui/browser_window.h"
-#include "chrome/browser/ui/search/search_model_observer.h"
#include "ui/base/ui_base_types.h"
class Browser;
@@ -31,8 +30,7 @@ class Extension;
class BrowserWindowCocoa :
public BrowserWindow,
- public extensions::ExtensionKeybindingRegistry::Delegate,
- public chrome::search::SearchModelObserver {
+ public extensions::ExtensionKeybindingRegistry::Delegate {
public:
BrowserWindowCocoa(Browser* browser,
BrowserWindowController* controller);
@@ -152,10 +150,6 @@ class BrowserWindowCocoa :
virtual extensions::ActiveTabPermissionGranter*
GetActiveTabPermissionGranter() OVERRIDE;
- // Overridden from chrome::search::SearchModelObserver:
- virtual void ModeChanged(const chrome::search::Mode& old_mode,
- const chrome::search::Mode& new_mode) OVERRIDE;
-
// Adds the given FindBar cocoa controller to this browser window.
void AddFindBar(FindBarCocoaController* find_bar_cocoa_controller);
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
index dc62e7d..546e563 100644
--- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
@@ -43,7 +43,6 @@
#import "chrome/browser/ui/cocoa/web_dialog_window_controller.h"
#import "chrome/browser/ui/cocoa/website_settings_bubble_controller.h"
#include "chrome/browser/ui/page_info_bubble.h"
-#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/web_applications/web_app_ui.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_notification_types.h"
@@ -116,12 +115,9 @@ BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser,
chrome::GetSavedWindowBoundsAndShowState(browser_,
&bounds,
&initial_show_state_);
-
- browser_->search_model()->AddObserver(this);
}
BrowserWindowCocoa::~BrowserWindowCocoa() {
- browser_->search_model()->RemoveObserver(this);
}
void BrowserWindowCocoa::Show() {
@@ -652,12 +648,6 @@ extensions::ActiveTabPermissionGranter*
return tab_helper ? tab_helper->active_tab_permission_granter() : NULL;
}
-void BrowserWindowCocoa::ModeChanged(
- const chrome::search::Mode& old_mode,
- const chrome::search::Mode& new_mode) {
- [controller_ updateBookmarkBarStateForInstantPreview];
-}
-
void BrowserWindowCocoa::DestroyBrowser() {
[controller_ destroyBrowser];
diff --git a/chrome/browser/ui/cocoa/browser_window_controller.h b/chrome/browser/ui/cocoa/browser_window_controller.h
index 35921dc..9f8eda9 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller.h
+++ b/chrome/browser/ui/cocoa/browser_window_controller.h
@@ -113,6 +113,10 @@ class WebContents;
// nil for those which don't).
scoped_nsobject<NSView> floatingBarBackingView_;
+ // Tracks whether the floating bar is above or below the bookmark bar, in
+ // terms of z-order.
+ BOOL floatingBarAboveBookmarkBar_;
+
// The borderless window used in fullscreen mode. Lion reuses the original
// window in fullscreen mode, so this is always nil on Lion.
scoped_nsobject<NSWindow> fullscreenWindow_;
@@ -158,10 +162,6 @@ class WebContents;
// The Extension Command Registry used to determine which keyboard events to
// handle.
scoped_ptr<ExtensionKeybindingRegistryCocoa> extension_keybinding_registry_;
-
- // The offset between the bottom of the toolbar and web contents. This is used
- // to push the web contents below the bookmark bar.
- CGFloat toolbarToWebContentsOffset_;
}
// A convenience class method which gets the |BrowserWindowController| for a
@@ -201,9 +201,6 @@ class WebContents;
// Return a weak pointer to the tab strip controller.
- (TabStripController*)tabStripController;
-// Return a weak pointer to the find bar controller.
-- (FindBarCocoaController*)findBarCocoaController;
-
// Access the ObjC controller that contains the infobars.
- (InfoBarContainerController*)infoBarContainerController;
@@ -213,12 +210,6 @@ class WebContents;
// Access the C++ bridge object representing the location bar.
- (LocationBarViewMac*)locationBarBridge;
-// Returns a weak pointer to the floating bar backing view;
-- (NSView*)floatingBarBackingView;
-
-// Returns a weak pointer to the previewable contents controller.
-- (PreviewableContentsController*)previewableContentsController;
-
// Access the Profile object that backs this Browser.
- (Profile*)profile;
@@ -339,8 +330,6 @@ class WebContents;
returnCode:(NSInteger)code
context:(void*)context;
-- (void)updateBookmarkBarStateForInstantPreview;
-
@end // @interface BrowserWindowController
diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm
index 54dd72c..02f4220 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller.mm
@@ -67,8 +67,6 @@
#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
-#include "chrome/browser/ui/search/search.h"
-#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/tabs/dock_info.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
@@ -394,6 +392,7 @@ enum {
resizeDelegate:self]);
[toolbarController_ setHasToolbar:[self hasToolbar]
hasLocationBar:[self hasLocationBar]];
+ [[[self window] contentView] addSubview:[toolbarController_ view]];
// Create a sub-controller for the bookmark bar.
bookmarkBarController_.reset(
@@ -402,12 +401,21 @@ enum {
initialWidth:NSWidth([[[self window] contentView] frame])
delegate:self
resizeDelegate:self]);
+
+ // Add bookmark bar to the view hierarchy, which also triggers the nib load.
+ // The bookmark bar is defined (in the nib) to be bottom-aligned to its
+ // parent view (among other things), so position and resize properties don't
+ // need to be set.
+ [[[self window] contentView] addSubview:[bookmarkBarController_ view]
+ positioned:NSWindowBelow
+ relativeTo:[toolbarController_ view]];
[bookmarkBarController_ setBookmarkBarEnabled:[self supportsBookmarkBar]];
// Create the infobar container view, so we can pass it to the
// ToolbarController.
infoBarContainerController_.reset(
[[InfoBarContainerController alloc] initWithResizeDelegate:self]);
+ [[[self window] contentView] addSubview:[infoBarContainerController_ view]];
// We don't want to try and show the bar before it gets placed in its parent
// view, so this step shoudn't be inside the bookmark bar controller's
@@ -530,10 +538,6 @@ enum {
return tabStripController_.get();
}
-- (FindBarCocoaController*)findBarCocoaController {
- return findBarCocoaController_.get();
-}
-
- (InfoBarContainerController*)infoBarContainerController {
return infoBarContainerController_.get();
}
@@ -546,14 +550,6 @@ enum {
return [toolbarController_ locationBarBridge];
}
-- (NSView*)floatingBarBackingView {
- return floatingBarBackingView_;
-}
-
-- (PreviewableContentsController*)previewableContentsController {
- return previewableContentsController_;
-}
-
- (Profile*)profile {
return browser_->profile();
}
@@ -1532,7 +1528,13 @@ enum {
// Create a controller for the findbar.
findBarCocoaController_.reset([findBarCocoaController retain]);
- [self updateSubviewZOrder];
+ NSView* contentView = [[self window] contentView];
+ NSView* relativeView =
+ [self inPresentationMode] ? [toolbarController_ view] :
+ [infoBarContainerController_ view];
+ [contentView addSubview:[findBarCocoaController_ view]
+ positioned:NSWindowAbove
+ relativeTo:relativeView];
// Place the find bar immediately below the toolbar/attached bookmark bar. In
// presentation mode, it hangs off the top of the screen when the bar is
@@ -1540,7 +1542,7 @@ enum {
CGFloat maxY = [self placeBookmarkBarBelowInfoBar] ?
NSMinY([[toolbarController_ view] frame]) :
NSMinY([[bookmarkBarController_ view] frame]);
- CGFloat maxWidth = NSWidth([[[self window] contentView] frame]);
+ CGFloat maxWidth = NSWidth([contentView frame]);
[findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:maxWidth];
// This allows the FindBarCocoaController to call |layoutSubviews| and get
@@ -1907,7 +1909,8 @@ enum {
- (void)bookmarkBar:(BookmarkBarController*)controller
didChangeFromState:(BookmarkBar::State)oldState
toState:(BookmarkBar::State)newState {
- [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]];
+ [toolbarController_
+ setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]];
[self adjustToolbarAndBookmarkBarForCompression:
[controller getDesiredToolbarHeightCompression]];
}
@@ -1916,7 +1919,8 @@ enum {
- (void)bookmarkBar:(BookmarkBarController*)controller
willAnimateFromState:(BookmarkBar::State)oldState
toState:(BookmarkBar::State)newState {
- [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]];
+ [toolbarController_
+ setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]];
[self adjustToolbarAndBookmarkBarForCompression:
[controller getDesiredToolbarHeightCompression]];
}
@@ -1987,12 +1991,6 @@ willAnimateFromState:(BookmarkBar::State)oldState
[sheet orderOut:self];
}
-- (void)updateBookmarkBarStateForInstantPreview {
- [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]];
- [self updateContentOffsets];
- [self updateSubviewZOrder];
-}
-
@end // @implementation BrowserWindowController
diff --git a/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm
index 609f172..326665c 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm
@@ -7,28 +7,14 @@
#import "base/mac/mac_util.h"
#include "base/run_loop.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
-#include "chrome/browser/api/infobars/infobar_service.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
-#import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
#import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h"
-#import "chrome/browser/ui/cocoa/fast_resize_view.h"
-#import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
-#import "chrome/browser/ui/cocoa/nsview_additions.h"
-#import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h"
-#include "chrome/browser/ui/search/search.h"
-#include "chrome/browser/ui/search/search_model.h"
#include "chrome/test/base/in_process_browser_test.h"
-#include "content/public/browser/web_contents.h"
-#import "testing/gtest_mac.h"
-
-namespace {
#if !defined(MAC_OS_X_VERSION_10_7) || \
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
@@ -38,6 +24,8 @@ enum {
};
#endif // MAC_OS_X_VERSION_10_7
+typedef InProcessBrowserTest BrowserWindowControllerTest;
+
void CreateProfileCallback(const base::Closure& quit_closure,
Profile* profile,
Profile::CreateStatus status) {
@@ -49,149 +37,6 @@ void CreateProfileCallback(const base::Closure& quit_closure,
quit_closure.Run();
}
-enum ViewID {
- VIEW_ID_TOOLBAR,
- VIEW_ID_BOOKMARK_BAR,
- VIEW_ID_INFO_BAR,
- VIEW_ID_FIND_BAR,
- VIEW_ID_DOWNLOAD_SHELF,
- VIEW_ID_TAB_CONTENT_AREA,
- VIEW_ID_FULLSCREEN_FLOATING_BAR,
- VIEW_ID_COUNT,
-};
-
-// A very simple info bar implementation used to show an infobar on the browser
-// window.
-class DummyInfoBar : public ConfirmInfoBarDelegate {
- public:
- explicit DummyInfoBar(InfoBarService* service)
- : ConfirmInfoBarDelegate(service) {
- }
-
- virtual ~DummyInfoBar() {
- }
-
- virtual string16 GetMessageText() const OVERRIDE {
- return string16();
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(DummyInfoBar);
-};
-
-} // namespace
-
-class BrowserWindowControllerTest : public InProcessBrowserTest {
- public:
- BrowserWindowControllerTest() : InProcessBrowserTest() {
- }
-
- virtual void SetUpOnMainThread() OVERRIDE {
- [[controller() bookmarkBarController] setStateAnimationsEnabled:NO];
- [[controller() bookmarkBarController] setInnerContentAnimationsEnabled:NO];
- }
-
- virtual void CleanUpOnMainThread() OVERRIDE {
- if (web_contents_)
- browser()->search_model()->set_web_contents(NULL);
- web_contents_.reset();
- }
-
- BrowserWindowController* controller() const {
- return [BrowserWindowController browserWindowControllerForWindow:
- browser()->window()->GetNativeWindow()];
- }
-
- void ShowInstantResults() {
- chrome::search::EnableInstantExtendedAPIForTesting();
- web_contents_.reset(content::WebContents::Create(
- content::WebContents::CreateParams(browser()->profile())));
- browser()->search_model()->set_web_contents(web_contents_.get());
- chrome::search::Mode mode(chrome::search::Mode::MODE_SEARCH_SUGGESTIONS,
- chrome::search::Mode::ORIGIN_SEARCH);
- browser()->search_model()->SetMode(mode);
- EXPECT_TRUE(browser()->search_model()->mode().is_search_suggestions());
- EXPECT_TRUE([controller() isShowingInstantResults]);
- }
-
- void ShowInstantNTP() {
- chrome::search::EnableInstantExtendedAPIForTesting();
- web_contents_.reset(content::WebContents::Create(
- content::WebContents::CreateParams(browser()->profile())));
- browser()->search_model()->set_web_contents(web_contents_.get());
- chrome::search::Mode mode(chrome::search::Mode::MODE_NTP,
- chrome::search::Mode::ORIGIN_NTP);
- browser()->search_model()->SetMode(mode);
- EXPECT_TRUE(browser()->search_model()->mode().is_ntp());
- EXPECT_FALSE([controller() isShowingInstantResults]);
- }
-
- void ShowInfoBar() {
- content::WebContents* web_contents =
- chrome::GetActiveWebContents(browser());
- InfoBarService* service =
- InfoBarService::FromWebContents(web_contents);
- info_bar_delegate_.reset(new DummyInfoBar(service));
- [[controller() infoBarContainerController]
- addInfoBar:info_bar_delegate_->CreateInfoBar(service)
- animate:NO];
- }
-
- NSView* GetViewWithID(ViewID view_id) const {
- switch (view_id) {
- case VIEW_ID_FULLSCREEN_FLOATING_BAR:
- return [controller() floatingBarBackingView];
- case VIEW_ID_TOOLBAR:
- return [[controller() toolbarController] view];
- case VIEW_ID_BOOKMARK_BAR:
- return [[controller() bookmarkBarController] view];
- case VIEW_ID_INFO_BAR:
- return [[controller() infoBarContainerController] view];
- case VIEW_ID_FIND_BAR:
- return [[controller() findBarCocoaController] view];
- case VIEW_ID_DOWNLOAD_SHELF:
- return [[controller() downloadShelf] view];
- case VIEW_ID_TAB_CONTENT_AREA:
- return [controller() tabContentArea];
- default:
- NOTREACHED();
- return nil;
- }
- }
-
- void VerifyZOrder(const std::vector<ViewID>& view_list) const {
- for (size_t i = 0; i < view_list.size() - 1; ++i) {
- NSView* bottom_view = GetViewWithID(view_list[i]);
- NSView* top_view = GetViewWithID(view_list[i + 1]);
- EXPECT_NSEQ([bottom_view superview], [top_view superview]);
- EXPECT_TRUE([bottom_view cr_isBelowView:top_view]);
- }
-
- // Views not in |view_list| must either be nil or not parented.
- for (size_t i = 0; i < VIEW_ID_COUNT; ++i) {
- if (std::find(view_list.begin(), view_list.end(), i) == view_list.end()) {
- NSView* view = GetViewWithID(static_cast<ViewID>(i));
- EXPECT_TRUE(!view || ![view superview]);
- }
- }
- }
-
- CGFloat GetViewHeight(ViewID viewID) const {
- CGFloat height = NSHeight([GetViewWithID(viewID) frame]);
- if (viewID == VIEW_ID_INFO_BAR) {
- height -= [[controller() infoBarContainerController]
- overlappingTipHeight];
- }
- return height;
- }
-
- private:
- scoped_ptr<content::WebContents> web_contents_;
- scoped_ptr<InfoBarDelegate> info_bar_delegate_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserWindowControllerTest);
-};
-
// Tests that adding the first profile moves the Lion fullscreen button over
// correctly.
// DISABLED_ because it regularly times out: http://crbug.com/159002.
@@ -207,6 +52,9 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
NSWindow* window = browser()->window()->GetNativeWindow();
ASSERT_TRUE(window);
+ BrowserWindowController* controller =
+ static_cast<BrowserWindowCocoa*>(browser()->window())->cocoa_controller();
+
// With only one profile, the fullscreen button should be visible, but the
// avatar button should not.
EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles());
@@ -217,7 +65,7 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
EXPECT_FALSE([fullscreen_button isHidden]);
AvatarButtonController* avatar_controller =
- [controller() avatarButtonController];
+ [controller avatarButtonController];
NSView* avatar = [avatar_controller view];
EXPECT_TRUE(avatar);
EXPECT_TRUE([avatar isHidden]);
@@ -252,187 +100,3 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
EXPECT_LT(NSMinX(fullscreen_frame), NSMinX(avatar_frame));
EXPECT_LT(NSMaxX(fullscreen_frame), NSMinX(avatar_frame));
}
-
-// Verify that in non-instant normal mode that the find bar and download shelf
-// are above the content area. Everything else should be below it.
-IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormal) {
- browser()->GetFindBarController(); // add find bar
-
- std::vector<ViewID> view_list;
- view_list.push_back(VIEW_ID_BOOKMARK_BAR);
- view_list.push_back(VIEW_ID_TOOLBAR);
- view_list.push_back(VIEW_ID_INFO_BAR);
- view_list.push_back(VIEW_ID_TAB_CONTENT_AREA);
- view_list.push_back(VIEW_ID_FIND_BAR);
- view_list.push_back(VIEW_ID_DOWNLOAD_SHELF);
- VerifyZOrder(view_list);
-}
-
-// Verify that in non-instant presentation mode that the info bar is below the
-// content are and everything else is above it.
-IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderPresentationMode) {
- browser()->TogglePresentationMode();
- browser()->GetFindBarController(); // add find bar
-
- std::vector<ViewID> view_list;
- view_list.push_back(VIEW_ID_INFO_BAR);
- view_list.push_back(VIEW_ID_TAB_CONTENT_AREA);
- view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR);
- view_list.push_back(VIEW_ID_BOOKMARK_BAR);
- view_list.push_back(VIEW_ID_TOOLBAR);
- view_list.push_back(VIEW_ID_FIND_BAR);
- view_list.push_back(VIEW_ID_DOWNLOAD_SHELF);
- VerifyZOrder(view_list);
-}
-
-// Normal mode with instant results showing. Should be same z-order as normal
-// mode except find bar is below content area.
-IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormalInstant) {
- ShowInstantResults();
- browser()->GetFindBarController(); // add find bar
-
- std::vector<ViewID> view_list;
- view_list.push_back(VIEW_ID_BOOKMARK_BAR);
- view_list.push_back(VIEW_ID_TOOLBAR);
- view_list.push_back(VIEW_ID_INFO_BAR);
- view_list.push_back(VIEW_ID_FIND_BAR);
- view_list.push_back(VIEW_ID_TAB_CONTENT_AREA);
- view_list.push_back(VIEW_ID_DOWNLOAD_SHELF);
- VerifyZOrder(view_list);
-}
-
-// Presentation mode with instant results showing. Should be exact same as
-// non-instant presentation mode.
-IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
- ZOrderInstantPresentationMode) {
- browser()->TogglePresentationMode();
- ShowInstantResults();
- browser()->GetFindBarController(); // add find bar
-
- std::vector<ViewID> view_list;
- view_list.push_back(VIEW_ID_INFO_BAR);
- view_list.push_back(VIEW_ID_TAB_CONTENT_AREA);
- view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR);
- view_list.push_back(VIEW_ID_BOOKMARK_BAR);
- view_list.push_back(VIEW_ID_TOOLBAR);
- view_list.push_back(VIEW_ID_FIND_BAR);
- view_list.push_back(VIEW_ID_DOWNLOAD_SHELF);
- VerifyZOrder(view_list);
-}
-
-// Verify that in non-instant presentation mode the content area is beneath
-// the bookmark bar and info bar.
-IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffset) {
- PreviewableContentsController* preview =
- [controller() previewableContentsController];
-
- // Just toolbar.
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(0, [preview activeContainerOffset]);
-
- // Plus bookmark bar.
- browser()->window()->ToggleBookmarkBar();
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR),
- [preview activeContainerOffset]);
-
- // Plus info bar.
- ShowInfoBar();
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) +
- GetViewHeight(VIEW_ID_INFO_BAR),
- [preview activeContainerOffset]);
-
- // Minus bookmark bar.
- browser()->window()->ToggleBookmarkBar();
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]);
-}
-
-// Verify that in non-instant presentation mode the content area is beneath
-// the info bar.
-IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
- ContentOffsetPresentationMode) {
- browser()->TogglePresentationMode();
- PreviewableContentsController* preview =
- [controller() previewableContentsController];
-
- // Just toolbar.
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(0, [preview activeContainerOffset]);
-
- // Plus bookmark bar.
- browser()->window()->ToggleBookmarkBar();
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(0, [preview activeContainerOffset]);
-
- // Plus info bar.
- ShowInfoBar();
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(0, [preview activeContainerOffset]);
-
- // Minus bookmark bar.
- browser()->window()->ToggleBookmarkBar();
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(0, [preview activeContainerOffset]);
-}
-
-// Verify that when showing instant results the content area overlaps the
-// bookmark bar and info bar.
-IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstant) {
- ShowInstantResults();
- PreviewableContentsController* preview =
- [controller() previewableContentsController];
-
- // Just toolbar.
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(0, [preview activeContainerOffset]);
-
- // Plus bookmark bar.
- browser()->window()->ToggleBookmarkBar();
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(0, [preview activeContainerOffset]);
-
- // Plus info bar.
- ShowInfoBar();
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(0, [preview activeContainerOffset]);
-
- // Minus bookmark bar.
- browser()->window()->ToggleBookmarkBar();
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(0, [preview activeContainerOffset]);
-}
-
-// The instant NTP case is same as normal case except that the preview is
-// also shifted down.
-IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstantNPT) {
- ShowInstantNTP();
- PreviewableContentsController* preview =
- [controller() previewableContentsController];
-
- // Just toolbar.
- EXPECT_EQ(0, [preview previewOffset]);
- EXPECT_EQ(0, [preview activeContainerOffset]);
-
- // Plus bookmark bar.
- browser()->window()->ToggleBookmarkBar();
- EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR),
- [preview previewOffset]);
- EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR),
- [preview activeContainerOffset]);
-
- // Plus info bar.
- ShowInfoBar();
- EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) +
- GetViewHeight(VIEW_ID_INFO_BAR),
- [preview previewOffset]);
- EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) +
- GetViewHeight(VIEW_ID_INFO_BAR),
- [preview activeContainerOffset]);
-
- // Minus bookmark bar.
- browser()->window()->ToggleBookmarkBar();
- EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview previewOffset]);
- EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]);
-}
diff --git a/chrome/browser/ui/cocoa/browser_window_controller_private.h b/chrome/browser/ui/cocoa/browser_window_controller_private.h
index cfcea46..6423764 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller_private.h
+++ b/chrome/browser/ui/cocoa/browser_window_controller_private.h
@@ -144,20 +144,6 @@
- (void)enableBarVisibilityUpdates;
- (void)disableBarVisibilityUpdates;
-// The opacity for the toolbar divider; 0 means that it shouldn't be shown.
-- (CGFloat)toolbarDividerOpacity;
-
-// Returns YES if instant results are being shown under the omnibox.
-- (BOOL)isShowingInstantResults;
-
-// Updates the content offets of the tab strip controller and the previewable
-// contents controller. This is used to adjust the overlap between those views
-// and the bookmark bar.
-- (void)updateContentOffsets;
-
-// Ensures the z-order of subviews is correct.
-- (void)updateSubviewZOrder;
-
@end // @interface BrowserWindowController(Private)
#endif // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_CONTROLLER_PRIVATE_H_
diff --git a/chrome/browser/ui/cocoa/browser_window_controller_private.mm b/chrome/browser/ui/cocoa/browser_window_controller_private.mm
index 1232c9d..7d31c4e 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller_private.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller_private.mm
@@ -32,7 +32,6 @@
#import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
-#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/search/search_ui.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
@@ -177,9 +176,6 @@ willPositionSheet:(NSWindow*)sheet
if ([window respondsToSelector:@selector(setShouldHideTitle:)])
[(id)window setShouldHideTitle:![self hasTitleBar]];
- // Update z-order. The code below depends on this.
- [self updateSubviewZOrder];
-
BOOL inPresentationMode = [self inPresentationMode];
CGFloat floatingBarHeight = [self floatingBarHeight];
// In presentation mode, |yOffset| accounts for the sliding position of the
@@ -205,7 +201,6 @@ willPositionSheet:(NSWindow*)sheet
// Place the toolbar at the top of the reserved area.
maxY = [self layoutToolbarAtMinX:minX maxY:maxY width:width];
- CGFloat toolbarBottomY = maxY;
// If we're not displaying the bookmark bar below the infobar, then it goes
// immediately below the toolbar.
@@ -247,25 +242,14 @@ willPositionSheet:(NSWindow*)sheet
}
}
- // 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
- // takes up the space between the bottom of the toolbar down.
- CGFloat contentAreaTop = 0;
- if (inPresentationMode) {
- toolbarToWebContentsOffset_ = 0;
- contentAreaTop = maxY;
- } else {
- toolbarToWebContentsOffset_ = toolbarBottomY - maxY;
- contentAreaTop = toolbarBottomY;
- }
- [self updateContentOffsets];
-
- NSRect contentAreaRect = NSMakeRect(minX, minY, width, contentAreaTop - minY);
+ // Finally, the content area takes up all of the remaining space.
+ NSRect contentAreaRect = NSMakeRect(minX, minY, width, maxY - minY);
[self layoutTabContentArea:contentAreaRect];
// Normally, we don't need to tell the toolbar whether or not to show the
// divider, but things break down during animation.
- [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]];
+ [toolbarController_
+ setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]];
}
- (CGFloat)floatingBarHeight {
@@ -441,6 +425,22 @@ willPositionSheet:(NSWindow*)sheet
// window), there's no actual overlay. (Displaying one would result in an
// overly sliding in only under the menu, which gives an ugly effect.)
if (floatingBarBackingView_.get()) {
+ BOOL aboveBookmarkBar = [self placeBookmarkBarBelowInfoBar];
+
+ // Insert it into the view hierarchy if necessary.
+ if (![floatingBarBackingView_ superview] ||
+ aboveBookmarkBar != floatingBarAboveBookmarkBar_) {
+ NSView* contentView = [[self window] contentView];
+ // z-order gets messed up unless we explicitly remove the floatingbar
+ // view and re-add it.
+ [floatingBarBackingView_ removeFromSuperview];
+ [contentView addSubview:floatingBarBackingView_
+ positioned:(aboveBookmarkBar ?
+ NSWindowAbove : NSWindowBelow)
+ relativeTo:[bookmarkBarController_ view]];
+ floatingBarAboveBookmarkBar_ = aboveBookmarkBar;
+ }
+
// Set its frame.
[floatingBarBackingView_ setFrame:frame];
}
@@ -728,9 +728,15 @@ willPositionSheet:(NSWindow*)sheet
NSViewMinYMargin)];
}
- // Force the bookmark bar z-order to update.
- [[bookmarkBarController_ view] removeFromSuperview];
- [self updateSubviewZOrder];
+ // Adjust the infobar container. In fullscreen, it needs to be below all
+ // top chrome elements so it only sits atop the web contents. When in normal
+ // mode, it needs to draw over the bookmark bar and part of the toolbar.
+ [[infoBarContainerController_ view] removeFromSuperview];
+ NSView* infoBarDest = [[self window] contentView];
+ [infoBarDest addSubview:[infoBarContainerController_ view]
+ positioned:fullscreen ? NSWindowBelow : NSWindowAbove
+ relativeTo:fullscreen ? nil
+ : [toolbarController_ view]];
}
- (void)showFullscreenExitBubbleIfNecessary {
@@ -867,117 +873,4 @@ willPositionSheet:(NSWindow*)sheet
[presentationModeController_ cancelAnimationAndTimers];
}
-- (CGFloat)toolbarDividerOpacity {
- if ([self isShowingInstantResults])
- return 1;
- return [bookmarkBarController_ toolbarDividerOpacity];
-}
-
-- (BOOL)isShowingInstantResults {
- if (!browser_->search_model()->mode().is_search_suggestions())
- return NO;
-
- // If the search suggestions are already being displayed in the preview
- // contents then return YES.
- if ([previewableContentsController_ isShowingPreview])
- return YES;
-
- // Search suggestions might be shown directly in the web contents in some
- // cases.
- return browser_->search_model()->mode().origin ==
- chrome::search::Mode::ORIGIN_SEARCH;
-}
-
-- (void)updateContentOffsets {
- // Normally the preview contents is used to show instant results which must
- // obscure the bookmark bar. This is achieved by setting the offset to 0
- // so that it overlaps the bookmark bar. The only exception is when the
- // preview contents is showing the NTP which must sit below the bookmark bar.
- CGFloat previewOffset = 0;
- if (browser_->search_model()->mode().is_ntp())
- previewOffset = toolbarToWebContentsOffset_;
- [previewableContentsController_ setPreviewOffset:previewOffset];
-
- // 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 preview contents as usual.
- CGFloat tabContentsOffset = toolbarToWebContentsOffset_;
- if (browser_->search_model()->mode().is_search_suggestions() &&
- browser_->search_model()->mode().origin ==
- chrome::search::Mode::ORIGIN_SEARCH) {
- tabContentsOffset = 0;
- }
- [previewableContentsController_ setActiveContainerOffset:tabContentsOffset];
-
- // Prevent the fast resize view from drawing white over the bookmark bar.
- [[self tabContentArea] setContentOffset:toolbarToWebContentsOffset_];
-}
-
-- (void)updateSubviewZOrder {
- NSView* contentView = [[self window] contentView];
- NSView* toolbarView = [toolbarController_ view];
-
- if ([self inPresentationMode]) {
- // Toolbar is above tab contents so that it can slide down from top of
- // screen.
- [contentView cr_ensureSubview:toolbarView
- isPositioned:NSWindowAbove
- relativeTo:[self tabContentArea]];
- } else {
- // Toolbar is below tab contents so that the infobar arrow can appear above
- // it. Unlike other views the toolbar never overlaps the actual web
- // content.
- [contentView cr_ensureSubview:toolbarView
- isPositioned:NSWindowBelow
- relativeTo:[self tabContentArea]];
- }
-
- // The bookmark bar is always below the toolbar. In normal mode this means
- // that it is below tab contents. This allows instant results to be above
- // the bookmark bar.
- [contentView cr_ensureSubview:[bookmarkBarController_ view]
- isPositioned:NSWindowBelow
- relativeTo:toolbarView];
-
- if ([self inPresentationMode]) {
- // In presentation mode the infobar is below all other views.
- [contentView cr_ensureSubview:[infoBarContainerController_ view]
- isPositioned:NSWindowBelow
- relativeTo:[self tabContentArea]];
- } else {
- // Above the toolbar but still below tab contents. Similar to the bookmark
- // bar, this allows instant results to be above the info bar.
- [contentView cr_ensureSubview:[infoBarContainerController_ view]
- isPositioned:NSWindowAbove
- relativeTo:toolbarView];
- }
-
- // The find bar is above everything except instant search results.
- if (findBarCocoaController_) {
- NSView* relativeView = nil;
- if ([self inPresentationMode])
- relativeView = toolbarView;
- else if ([self isShowingInstantResults])
- relativeView = [infoBarContainerController_ view];
- else
- relativeView = [self tabContentArea];
- [contentView cr_ensureSubview:[findBarCocoaController_ view]
- isPositioned:NSWindowAbove
- relativeTo:relativeView];
- }
-
- if (floatingBarBackingView_) {
- if ([self placeBookmarkBarBelowInfoBar]) {
- [contentView cr_ensureSubview:floatingBarBackingView_
- isPositioned:NSWindowAbove
- relativeTo:[bookmarkBarController_ view]];
- } else {
- [contentView cr_ensureSubview:floatingBarBackingView_
- isPositioned:NSWindowBelow
- relativeTo:[bookmarkBarController_ view]];
- }
- }
-}
-
@end // @implementation BrowserWindowController(Private)
diff --git a/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm b/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm
index dad7acf..344a1f4 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm
@@ -267,7 +267,7 @@ void CheckViewPositions(BrowserWindowController* controller) {
EXPECT_EQ(NSMinY(contentView), NSMinY(download));
EXPECT_EQ(NSMaxY(download), NSMinY(contentArea));
- EXPECT_EQ(NSMaxY(contentArea), NSMinY(toolbar));
+ EXPECT_EQ(NSMaxY(contentArea), NSMinY(infobar));
// Bookmark bar frame is random memory when hidden.
if ([controller bookmarkBarVisible]) {
diff --git a/chrome/browser/ui/cocoa/fast_resize_view.h b/chrome/browser/ui/cocoa/fast_resize_view.h
index cdc9c7f..ba2c89f 100644
--- a/chrome/browser/ui/cocoa/fast_resize_view.h
+++ b/chrome/browser/ui/cocoa/fast_resize_view.h
@@ -16,14 +16,8 @@
@interface FastResizeView : NSView {
@private
BOOL fastResizeMode_;
-
- // Offset from the top of the view where the view's content starts. This is
- // used to prevent this view from drawing white on non-content area.
- CGFloat contentOffset_;
}
-@property(assign, nonatomic) CGFloat contentOffset;
-
// Turns fast resizing mode on or off, which determines how this view resizes
// its subviews. Turning fast resizing mode off has the effect of immediately
// resizing subviews to fit; callers do not need to explictly call |setFrame:|
diff --git a/chrome/browser/ui/cocoa/fast_resize_view.mm b/chrome/browser/ui/cocoa/fast_resize_view.mm
index 7d8a763..8755bc4 100644
--- a/chrome/browser/ui/cocoa/fast_resize_view.mm
+++ b/chrome/browser/ui/cocoa/fast_resize_view.mm
@@ -15,9 +15,6 @@
@end
@implementation FastResizeView
-
-@synthesize contentOffset = contentOffset_;
-
- (void)setFastResizeMode:(BOOL)fastResizeMode {
fastResizeMode_ = fastResizeMode;
@@ -34,18 +31,13 @@
// If we are in fast resize mode, our subviews may not completely cover our
// bounds, so we fill with white. If we are not in fast resize mode, we do
// not need to draw anything.
- if (!fastResizeMode_)
- return;
-
- // Don't draw on the non-content area.
- NSRect clipRect = [self bounds];
- clipRect.size.height -= contentOffset_;
- NSRectClip(clipRect);
-
- [[NSColor whiteColor] set];
- NSRectFill(dirtyRect);
+ if (fastResizeMode_) {
+ [[NSColor whiteColor] set];
+ NSRectFill(dirtyRect);
+ }
}
+
@end
@implementation FastResizeView (PrivateMethods)
diff --git a/chrome/browser/ui/cocoa/nsview_additions.h b/chrome/browser/ui/cocoa/nsview_additions.h
index 5bd7533..cd88787 100644
--- a/chrome/browser/ui/cocoa/nsview_additions.h
+++ b/chrome/browser/ui/cocoa/nsview_additions.h
@@ -15,17 +15,6 @@
// Checks if the mouse is currently in this view.
- (BOOL)cr_isMouseInView;
-// Returns YES if this view is below |otherView|.
-- (BOOL)cr_isBelowView:(NSView*)otherView;
-
-// Returns YES if this view is aobve |otherView|.
-- (BOOL)cr_isAboveView:(NSView*)otherView;
-
-// Ensures that the z-order of |subview| is correct relative to |otherView|.
-- (void)cr_ensureSubview:(NSView*)subview
- isPositioned:(NSWindowOrderingMode)place
- relativeTo:(NSView *)otherView;
-
@end
#endif // CHROME_BROWSER_UI_COCOA_NSVIEW_ADDITIONS_H_
diff --git a/chrome/browser/ui/cocoa/nsview_additions.mm b/chrome/browser/ui/cocoa/nsview_additions.mm
index 6352f08f9..9210330 100644
--- a/chrome/browser/ui/cocoa/nsview_additions.mm
+++ b/chrome/browser/ui/cocoa/nsview_additions.mm
@@ -4,8 +4,6 @@
#import "chrome/browser/ui/cocoa/nsview_additions.h"
-#include "base/logging.h"
-
#if !defined(MAC_OS_X_VERSION_10_7) || \
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
@@ -30,36 +28,4 @@
return [self hitTest:mouseLoc] == self;
}
-- (BOOL)cr_isBelowView:(NSView*)otherView {
- NSArray* subviews = [[self superview] subviews];
-
- NSUInteger selfIndex = [subviews indexOfObject:self];
- DCHECK_NE(NSNotFound, selfIndex);
-
- NSUInteger otherIndex = [subviews indexOfObject:otherView];
- DCHECK_NE(NSNotFound, otherIndex);
-
- return selfIndex < otherIndex;
-}
-
-- (BOOL)cr_isAboveView:(NSView*)otherView {
- return ![self cr_isBelowView:otherView];
-}
-
-- (void)cr_ensureSubview:(NSView*)subview
- isPositioned:(NSWindowOrderingMode)place
- relativeTo:(NSView *)otherView {
- DCHECK(place == NSWindowAbove || place == NSWindowBelow);
- BOOL isAbove = place == NSWindowAbove;
- if ([[subview superview] isEqual:self] &&
- [subview cr_isAboveView:otherView] == isAbove) {
- return;
- }
-
- [subview removeFromSuperview];
- [self addSubview:subview
- positioned:place
- relativeTo:otherView];
-}
-
@end
diff --git a/chrome/browser/ui/cocoa/nsview_additions_unittest.mm b/chrome/browser/ui/cocoa/nsview_additions_unittest.mm
deleted file mode 100644
index ffb7e0f..0000000
--- a/chrome/browser/ui/cocoa/nsview_additions_unittest.mm
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#import "chrome/browser/ui/cocoa/nsview_additions.h"
-
-#include "base/memory/scoped_nsobject.h"
-#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#import "testing/gtest_mac.h"
-
-typedef CocoaTest NSViewChromeAdditionsTest;
-
-@interface ParentView : NSView {
- @private
- int removeCount_;
- int addCount_;
-}
-
-@property(readonly, nonatomic) int removeCount;
-@property(readonly, nonatomic) int addCount;
-
-@end
-
-@implementation ParentView
-
-@synthesize removeCount = removeCount_;
-@synthesize addCount = addCount_;
-
-- (void)willRemoveSubview:(NSView*)view {
- ++removeCount_;
-}
-
-- (void)didAddSubview:(NSView*)view {
- ++addCount_;
-}
-
-@end
-
-TEST_F(NSViewChromeAdditionsTest, BelowAboveView) {
- scoped_nsobject<NSView> parent([[NSView alloc] initWithFrame:NSZeroRect]);
- scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]);
- scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]);
-
- [parent addSubview:child1];
- [parent addSubview:child2];
- EXPECT_TRUE([child1 cr_isBelowView:child2]);
- EXPECT_FALSE([child1 cr_isAboveView:child2]);
- EXPECT_FALSE([child2 cr_isBelowView:child1]);
- EXPECT_TRUE([child2 cr_isAboveView:child1]);
-
- [child1 removeFromSuperview];
- [child2 removeFromSuperview];
- [parent addSubview:child2];
- [parent addSubview:child1];
- EXPECT_FALSE([child1 cr_isBelowView:child2]);
- EXPECT_TRUE([child1 cr_isAboveView:child2]);
- EXPECT_TRUE([child2 cr_isBelowView:child1]);
- EXPECT_FALSE([child2 cr_isAboveView:child1]);
-}
-
-TEST_F(NSViewChromeAdditionsTest, EnsurePosition) {
- scoped_nsobject<NSView> parent([[NSView alloc] initWithFrame:NSZeroRect]);
- scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]);
- scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]);
-
- [parent addSubview:child1];
- [parent cr_ensureSubview:child2
- isPositioned:NSWindowAbove
- relativeTo:child1];
- EXPECT_NSEQ([[parent subviews] objectAtIndex:0], child1);
- EXPECT_NSEQ([[parent subviews] objectAtIndex:1], child2);
-
- [child2 removeFromSuperview];
- [parent cr_ensureSubview:child2
- isPositioned:NSWindowBelow
- relativeTo:child1];
- EXPECT_NSEQ([[parent subviews] objectAtIndex:0], child2);
- EXPECT_NSEQ([[parent subviews] objectAtIndex:1], child1);
-}
-
-// Verify that no view is removed or added when no change is needed.
-TEST_F(NSViewChromeAdditionsTest, EnsurePositionNoChange) {
- scoped_nsobject<ParentView> parent(
- [[ParentView alloc] initWithFrame:NSZeroRect]);
- scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]);
- scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]);
- [parent addSubview:child1];
- [parent addSubview:child2];
-
- EXPECT_EQ(0, [parent removeCount]);
- EXPECT_EQ(2, [parent addCount]);
- [parent cr_ensureSubview:child2
- isPositioned:NSWindowAbove
- relativeTo:child1];
- EXPECT_EQ(0, [parent removeCount]);
- EXPECT_EQ(2, [parent addCount]);
-}
diff --git a/chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.mm b/chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.mm
index 8a0d1df..410a77b 100644
--- a/chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.mm
+++ b/chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.mm
@@ -37,5 +37,4 @@ void InstantPreviewControllerMac::PreviewStateChanged(
[preview_ hidePreview];
}
browser_->MaybeUpdateBookmarkBarStateForInstantPreview(model.mode());
- [window_ updateBookmarkBarStateForInstantPreview];
}
diff --git a/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h b/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h
index a40053b..f08bd55 100644
--- a/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h
+++ b/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h
@@ -51,26 +51,11 @@ class WebContents;
// View responsible for drawing a drop shadow.
scoped_nsobject<NSView> dropShadowView_;
-
- BrowserWindowController* windowController_;
-
- // The vertical offset between the top of the view and the preview contents.
- // This is used to push the preview contents below the bookmark bar. Normally
- // this is 0 so that the preview contents obscures the bookmark bar.
- CGFloat previewOffset_;
-
- // The vertical offset between the top of the view and the active container.
- // This is used to push the active container below the bookmark bar. Normally
- // this is set to the height of the bookmark bar so that the bookmark bar is
- // not obscured.
- CGFloat activeContainerOffset_;
}
@property(readonly, nonatomic) NSView* activeContainer;
@property(readonly, nonatomic) NSView* dropShadowView;
@property(readonly, nonatomic) BOOL drawDropShadow;
-@property(assign, nonatomic) CGFloat previewOffset;
-@property(assign, nonatomic) CGFloat activeContainerOffset;
// Initialization.
- (id)initWithBrowser:(Browser*)browser
@@ -90,9 +75,6 @@ class WebContents;
// if it's the preview being activated (and adjust internal state accordingly).
- (void)onActivateTabWithContents:(content::WebContents*)contents;
-// Returns YES if the preview contents is currently showing.
-- (BOOL)isShowingPreview;
-
- (InstantPreviewControllerMac*)instantPreviewController;
@end
diff --git a/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.mm b/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.mm
index fc9fb75..a352362 100644
--- a/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.mm
+++ b/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.mm
@@ -5,7 +5,6 @@
#import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h"
#include "base/mac/bundle_locations.h"
-#include "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.h"
#include "chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h"
#include "content/public/browser/web_contents.h"
@@ -20,13 +19,10 @@
@implementation PreviewableContentsController
@synthesize drawDropShadow = drawDropShadow_;
-@synthesize previewOffset = previewOffset_;
-@synthesize activeContainerOffset = activeContainerOffset_;
- (id)initWithBrowser:(Browser*)browser
windowController:(BrowserWindowController*)windowController {
if ((self = [super init])) {
- windowController_ = windowController;
scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
[view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
[view setAutoresizesSubviews:NO];
@@ -123,10 +119,6 @@
}
}
-- (BOOL)isShowingPreview {
- return previewContents_ != nil;
-}
-
- (InstantPreviewControllerMac*)instantPreviewController {
return instantPreviewController_.get();
}
@@ -139,22 +131,6 @@
return dropShadowView_.get();
}
-- (void)setPreviewOffset:(CGFloat)previewOffset {
- if (previewOffset_ == previewOffset)
- return;
-
- previewOffset_ = previewOffset;
- [self layoutViews];
-}
-
-- (void)setActiveContainerOffset:(CGFloat)activeContainerOffset {
- if (activeContainerOffset_ == activeContainerOffset)
- return;
-
- activeContainerOffset_ = activeContainerOffset;
- [self layoutViews];
-}
-
- (void)viewDidResize:(NSNotification*)note {
[self layoutViews];
}
@@ -165,8 +141,7 @@
if (previewContents_) {
NSRect previewFrame = bounds;
previewFrame.size.height = [self previewHeightInPixels];
- previewFrame.origin.y =
- NSMaxY(bounds) - NSHeight(previewFrame) - previewOffset_;
+ previewFrame.origin.y = NSMaxY(bounds) - NSHeight(previewFrame);
[previewContents_->GetNativeView() setFrame:previewFrame];
if (dropShadowView_) {
@@ -178,13 +153,11 @@
}
}
- NSRect activeFrame = bounds;
- activeFrame.size.height -= activeContainerOffset_;
- [activeContainer_ setFrame:activeFrame];
+ [activeContainer_ setFrame:bounds];
}
- (CGFloat)previewHeightInPixels {
- CGFloat height = NSHeight([[self view] bounds]) - previewOffset_;
+ CGFloat height = NSHeight([[self view] bounds]);
switch (previewHeightUnits_) {
case INSTANT_SIZE_PERCENT:
return std::min(height, (height * previewHeight_) / 100);
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 5658079..1233979 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1220,6 +1220,7 @@
'browser/ui/cocoa/applescript/window_applescript_test.mm',
'browser/ui/cocoa/browser_window_cocoa_browsertest.mm',
'browser/ui/cocoa/browser_window_controller_browsertest.mm',
+ 'browser/ui/cocoa/bookmarks/bookmark_bar_controller_browsertest.mm',
'browser/ui/cocoa/constrained_window/constrained_window_mac_browsertest.mm',
'browser/ui/cocoa/content_settings/collected_cookies_mac_browsertest.mm',
'browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index c8c9a5e..e8e61e3 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1295,7 +1295,6 @@
'browser/ui/cocoa/notifications/balloon_controller_unittest.mm',
'browser/ui/cocoa/nsimage_cache_unittest.mm',
'browser/ui/cocoa/nsmenuitem_additions_unittest.mm',
- 'browser/ui/cocoa/nsview_additions_unittest.mm',
'browser/ui/cocoa/omnibox/omnibox_popup_view_mac_unittest.mm',
'browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm',
'browser/ui/cocoa/one_click_signin_bubble_controller_unittest.mm',