Commit f80e654b authored by erikchen@chromium.org's avatar erikchen@chromium.org

mac: Toolbar renders incorrectly when downloads bar is open.

The toolbar's superview chromeContentView was incorrectly sized and was too
small. This happened because chromeContentView's layout was not being updated
in -[BrowserWindowController layoutSubviews].

I updated the unit tests in browser_window_controller_unittest.mm with 2 changes:
- All layout checking should use window coordinates, to ensure consistency.
- Layout checking should ensure that the frame of each view is within the
bounds of the superview.

BUG=396740

Review URL: https://codereview.chromium.org/419683008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285796 0039d316-1c4b-4281-b951-d872f2087c98
parent a9da7101
...@@ -185,6 +185,14 @@ willPositionSheet:(NSWindow*)sheet ...@@ -185,6 +185,14 @@ willPositionSheet:(NSWindow*)sheet
NSWindow* window = [self window]; NSWindow* window = [self window];
NSView* contentView = [window contentView]; NSView* contentView = [window contentView];
NSRect contentBounds = [contentView bounds]; NSRect contentBounds = [contentView bounds];
// Lay out the chromeContentView.
NSView* chromeContentView = [self chromeContentView];
BOOL autoresizesSubviews = [chromeContentView autoresizesSubviews];
[chromeContentView setAutoresizesSubviews:NO];
[chromeContentView setFrame:contentBounds];
[chromeContentView setAutoresizesSubviews:autoresizesSubviews];
CGFloat minX = NSMinX(contentBounds); CGFloat minX = NSMinX(contentBounds);
CGFloat minY = NSMinY(contentBounds); CGFloat minY = NSMinY(contentBounds);
CGFloat width = NSWidth(contentBounds); CGFloat width = NSWidth(contentBounds);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#import "chrome/browser/ui/cocoa/fast_resize_view.h"
#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#import "chrome/browser/ui/cocoa/nsview_additions.h" #import "chrome/browser/ui/cocoa/nsview_additions.h"
#include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
...@@ -242,19 +243,61 @@ TEST_F(BrowserWindowControllerTest, TestIncognitoWidthSpace) { ...@@ -242,19 +243,61 @@ TEST_F(BrowserWindowControllerTest, TestIncognitoWidthSpace) {
namespace { namespace {
// Returns the frame of the view in window coordinates.
NSRect FrameInWindowForView(NSView* view) {
return [[view superview] convertRect:[view frame] toView:nil];
}
// Whether the view's frame is within the bounds of the superview.
BOOL ViewContainmentValid(NSView* view) {
if (NSIsEmptyRect([view frame]))
return true;
return NSContainsRect([[view superview] bounds], [view frame]);
}
// Checks the view hierarchy rooted at |view| to ensure that each view is
// properly contained.
BOOL ViewHierarchyContainmentValid(NSView* view) {
// TODO(erikchen): Fix these views to have correct containment.
// http://crbug.com/397665.
if ([view isKindOfClass:NSClassFromString(@"DownloadShelfView")])
return YES;
if ([view isKindOfClass:NSClassFromString(@"BookmarkBarToolbarView")])
return YES;
if ([view isKindOfClass:NSClassFromString(@"BrowserActionsContainerView")])
return YES;
if (!ViewContainmentValid(view)) {
LOG(ERROR) << "View violates containment: " <<
[[view description] UTF8String];
return false;
}
for (NSView* subview in [view subviews]) {
BOOL result = ViewHierarchyContainmentValid(subview);
if (!result)
return false;
}
return true;
}
// Verifies that the toolbar, infobar, tab content area, and download shelf // Verifies that the toolbar, infobar, tab content area, and download shelf
// completely fill the area under the tabstrip. // completely fill the area under the tabstrip.
void CheckViewPositions(BrowserWindowController* controller) { void CheckViewPositions(BrowserWindowController* controller) {
NSRect contentView = [[[controller window] contentView] bounds]; EXPECT_TRUE(ViewHierarchyContainmentValid([[controller window] contentView]));
NSRect tabstrip = [[controller tabStripView] frame];
NSRect toolbar = [[controller toolbarView] frame]; NSRect contentView = FrameInWindowForView([[controller window] contentView]);
NSRect infobar = [[controller infoBarContainerView] frame]; NSRect tabstrip = FrameInWindowForView([controller tabStripView]);
NSRect contentArea = [[controller tabContentArea] frame]; NSRect toolbar = FrameInWindowForView([controller toolbarView]);
NSRect download = [[[controller downloadShelf] view] frame]; NSRect infobar = FrameInWindowForView([controller infoBarContainerView]);
NSRect tabContent = FrameInWindowForView([controller tabContentArea]);
NSRect download = FrameInWindowForView([[controller downloadShelf] view]);
EXPECT_EQ(NSMinY(contentView), NSMinY(download)); EXPECT_EQ(NSMinY(contentView), NSMinY(download));
EXPECT_EQ(NSMaxY(download), NSMinY(contentArea)); EXPECT_EQ(NSMaxY(download), NSMinY(tabContent));
EXPECT_EQ(NSMaxY(contentArea), NSMinY(infobar)); EXPECT_EQ(NSMaxY(tabContent), NSMinY(infobar));
// Bookmark bar frame is random memory when hidden. // Bookmark bar frame is random memory when hidden.
if ([controller bookmarkBarVisible]) { if ([controller bookmarkBarVisible]) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment