diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-16 21:36:10 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-16 21:36:10 +0000 |
commit | c47ee3fe8eb962680d1597bc1e63c666833f1a57 (patch) | |
tree | c6411a90be8806cd84f45edfbffe09a50056441d /chrome/browser/cocoa | |
parent | 56c4456f31726d89bcaba8471ff71e097066907d (diff) | |
download | chromium_src-c47ee3fe8eb962680d1597bc1e63c666833f1a57.zip chromium_src-c47ee3fe8eb962680d1597bc1e63c666833f1a57.tar.gz chromium_src-c47ee3fe8eb962680d1597bc1e63c666833f1a57.tar.bz2 |
Mac: fix/implement app windows (not app mode), popups, drawing; refactor code.
1. Properly display app windows, including Developer Tools window (no location bar). Also check using --app=http://foobar.com/.
2. Lay out popup windows (in particular, location bar) better. Check using, e.g., <http://www.quirksmode.org/js/popup.html>; make sure it looks good (with a variety of themes).
3. Properly draw border to Omnibox -- so that its border matches the surrounding buttons. Check (looking very closely/zooming) using various themes (Google and artist, light and dark).
4. Re-organize/refactor code in the BrowserWindowController (esp. the layout code). Check that (in a normal window) it still displays the toolbar, bookmark bar (normal and NTP), infobar, and download shelf correctly.
BUG=13148,20244,26757,29103
TEST=See above.
Review URL: http://codereview.chromium.org/495010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34757 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field_cell.mm | 42 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.mm | 6 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_cocoa.mm | 6 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.h | 29 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 425 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller_unittest.mm | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/chrome_browser_window.mm | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/chrome_browser_window_unittest.mm | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_item_cell.mm | 9 | ||||
-rw-r--r-- | chrome/browser/cocoa/gradient_button_cell.h | 1 | ||||
-rw-r--r-- | chrome/browser/cocoa/gradient_button_cell.mm | 14 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_window_controller.h | 7 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_window_controller.mm | 6 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.h | 13 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.mm | 25 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller_unittest.mm | 11 |
16 files changed, 384 insertions, 219 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.mm b/chrome/browser/cocoa/autocomplete_text_field_cell.mm index 5afcf10..1cb9d96 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_cell.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_cell.mm @@ -405,6 +405,48 @@ CGFloat WidthForKeyword(NSAttributedString* keywordString) { fraction:1.0]; } +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { + [NSGraphicsContext saveGraphicsState]; + + GTMTheme* theme = [controlView gtm_theme]; + + NSRect drawFrame = NSInsetRect(cellFrame, 0.5, 1.5); + // TODO(viettrungluu): It's hard to do pixel-perfect drawing in Cocoa 'cause + // rounding kills you (obviously, the constants below should be 0.5, but then + // it doesn't draw correctly). + NSRect innerFrame = NSInsetRect(drawFrame, 0.5001, 0.5001); + NSBezierPath* innerPath = [NSBezierPath bezierPathWithRect:drawFrame]; + + // Paint button background image if there is one (otherwise the border won't + // look right). + NSImage* backgroundImage = + [theme backgroundImageForStyle:GTMThemeStyleToolBarButton state:YES]; + if (backgroundImage) { + NSColor* patternColor = [NSColor colorWithPatternImage:backgroundImage]; + [patternColor set]; + // Set the phase to match window. + NSRect trueRect = [controlView convertRectToBase:cellFrame]; + [[NSGraphicsContext currentContext] + setPatternPhase:NSMakePoint(NSMinX(trueRect), NSMaxY(trueRect))]; + [innerPath fill]; + } + + // Draw the outer stroke (over the background). + [[theme strokeColorForStyle:GTMThemeStyleToolBarButton state:YES] setStroke]; + [innerPath setLineWidth:1]; + [innerPath stroke]; + + // Fill the inside if we're told to. + if ([self drawsBackground]) { + [[self backgroundColor] setFill]; + [NSBezierPath fillRect:innerFrame]; + } + + [NSGraphicsContext restoreGraphicsState]; + + [self drawInteriorWithFrame:cellFrame inView:controlView]; +} + - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { if (hintString_) { [self drawHintWithFrame:cellFrame inView:controlView]; diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm index 3f92b6e..a46584f 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller.mm @@ -452,8 +452,10 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; } - (void)setBookmarkBarEnabled:(BOOL)enabled { - barIsEnabled_ = enabled; - [self updateVisibility]; + if (enabled != barIsEnabled_) { + barIsEnabled_ = enabled; + [self updateVisibility]; + } } - (CGFloat)getDesiredToolbarHeightCompression { diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index dc7566b..3849510 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -197,7 +197,7 @@ void BrowserWindowCocoa::ConfirmAddSearchProvider( } LocationBar* BrowserWindowCocoa::GetLocationBar() const { - return [controller_ locationBar]; + return [controller_ locationBarBridge]; } void BrowserWindowCocoa::SetFocusToLocationBar() { @@ -223,8 +223,8 @@ bool BrowserWindowCocoa::IsBookmarkBarVisible() const { } bool BrowserWindowCocoa::IsToolbarVisible() const { - NOTIMPLEMENTED(); - return true; + return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || + browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR); } // This is called from Browser, which in turn is called directly from diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index 091babb..a273e8f 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -103,7 +103,7 @@ class TabStripModelObserverBridge; - (BrowserWindow*)browserWindow; // Access the C++ bridge object representing the location bar. -- (LocationBar*)locationBar; +- (LocationBar*)locationBarBridge; // Access the C++ bridge object representing the status bubble for the window. - (StatusBubbleMac*)statusBubble; @@ -131,6 +131,33 @@ class TabStripModelObserverBridge; // Make the location bar the first responder, if possible. - (void)focusLocationBar; +// Determines whether this controller's window supports a given feature (i.e., +// whether a given feature is or can be shown in the window). +// TODO(viettrungluu): |feature| is really should be |Browser::Feature|, but I +// don't want to include browser.h (and you can't forward declare enums). +- (BOOL)supportsWindowFeature:(int)feature; + +// Called to check whether or not this window has a normal title bar (YES if it +// does, NO otherwise). (E.g., normal browser windows do not, pop-ups do.) +- (BOOL)hasTitleBar; + +// Called to check whether or not this window has a toolbar (YES if it does, NO +// otherwise). (E.g., normal browser windows do, pop-ups do not.) +- (BOOL)hasToolbar; + +// Called to check whether or not this window has a location bar (YES if it +// does, NO otherwise). (E.g., normal browser windows do, pop-ups may or may +// not.) +- (BOOL)hasLocationBar; + +// Called to check whether or not this window can have bookmark bar (YES if it +// does, NO otherwise). (E.g., normal browser windows may, pop-ups may not.) +- (BOOL)supportsBookmarkBar; + +// Called to check if this controller's window is a normal window (e.g., not a +// pop-up window). Returns YES if it is, NO otherwise. +- (BOOL)isNormalWindow; + - (BOOL)isBookmarkBarVisible; // Called after bookmark bar visibility changes (due to pref change or change in diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 3af0816..0d13ce1 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -53,6 +53,25 @@ #include "grit/theme_resources.h" #import "third_party/GTM/AppKit/GTMTheme.h" +// ORGANIZATION: This is a big file. It is (in principle) organized as follows +// (in order): +// 1. Interfaces, including for our private methods. Very short, one-time-use +// classes may include an implementation immediately after their interface. +// 2. The general implementation section, ordered as follows: +// i. Public methods and overrides. +// ii. Overrides/implementations of undocumented methods. +// iii. Delegate methods for various protocols, formal and informal, to which +// |BrowserWindowController| conforms. +// 3. The private implementation section (|BrowserWindowController (Private)|). +// 4. Implementation for |GTMTheme (BrowserThemeProviderInitialization)|. +// +// Not all of the above guidelines are followed and more (re-)organization is +// needed. BUT PLEASE TRY TO KEEP THIS FILE ORGANIZED. I'd rather re-organize as +// little as possible, since doing so messes up the file's history. +// +// TODO(viettrungluu): (re-)organize some more, possibly split into separate +// files? + // Notes on self-inflicted (not user-inflicted) window resizing and moving: // // When the bookmark bar goes from hidden to shown (on a non-NTP) page, or when @@ -127,9 +146,42 @@ willPositionSheet:(NSWindow*)sheet // Assign a theme to the window. - (void)setTheme; -// Repositions the windows subviews. +// Repositions the window's subviews. From the top down: toolbar, normal +// bookmark bar (if shown), infobar, NTP detached bookmark bar (if shown), +// content area, download shelf (if any). - (void)layoutSubviews; +// Lays out the toolbar (or just location bar for popups) at the given maximum +// y-coordinate, with the given width; returns the new maximum y (below the +// toolbar). +- (CGFloat)layoutToolbarAtMaxY:(CGFloat)maxY width:(CGFloat)width; + +// Lays out the bookmark bar at the given maximum y-coordinate, with the given +// width; returns the new maximum y (below the bookmark bar). Note that one must +// call it with the appropriate |maxY| which depends on whether or not the +// bookmark bar is shown as the NTP bubble or not (use +// |-placeBookmarkBarBelowInfoBar|). +- (CGFloat)layoutBookmarkBarAtMaxY:(CGFloat)maxY width:(CGFloat)width; + +// Lays out the infobar at the given maximum y-coordinate, with the given width; +// returns the new maximum y (below the infobar). +- (CGFloat)layoutInfoBarAtMaxY:(CGFloat)maxY width:(CGFloat)width; + +// Returns YES if the bookmark bar should be placed below the infobar, NO +// otherwise. +- (BOOL)placeBookmarkBarBelowInfoBar; + +// Lays out the download shelf, if there is one, at the given minimum +// y-coordinate, with the given width; returns the new minimum y (above the +// download shelf). This is safe to call even if there is no download shelf. +- (CGFloat)layoutDownloadShelfAtMinY:(CGFloat)minY width:(CGFloat)width; + +// Lays out the tab content area between the given minimum and maximum +// y-coordinates, with the given width. +- (void)layoutTabContentAreaAtMinY:(CGFloat)minY + maxY:(CGFloat)maxY + width:(CGFloat)width; + // Should we show the normal bookmark bar? - (BOOL)shouldShowBookmarkBar; @@ -233,11 +285,8 @@ willPositionSheet:(NSWindow*)sheet profile:browser->profile() browser:browser resizeDelegate:self]); - // If we are a pop-up, we have a titlebar and no toolbar. - if (!browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) && - browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR)) { - [toolbarController_ setHasToolbar:NO]; - } + [toolbarController_ setHasToolbar:[self hasToolbar] + hasLocationBar:[self hasLocationBar]]; [[[self window] contentView] addSubview:[toolbarController_ view]]; // Create a sub-controller for the bookmark bar. @@ -248,18 +297,14 @@ willPositionSheet:(NSWindow*)sheet delegate:self resizeDelegate:self]); - // Add bookmark bar to the view hierarchy. This also triggers the - // nib load. The bookmark bar is defined (in the nib) to be - // bottom-aligned to it's parent view (among other things), so - // position and resize properties don't need to be set. + // 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]]; - - // Disable the bookmark bar if this window doesn't support them. - if (!browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { - [bookmarkBarController_ setBookmarkBarEnabled:NO]; - } + [bookmarkBarController_ setBookmarkBarEnabled:[self supportsBookmarkBar]]; // 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 @@ -752,7 +797,7 @@ willPositionSheet:(NSWindow*)sheet NSInteger tag = [item tag]; if (browser_->command_updater()->SupportsCommand(tag)) { // Generate return value (enabled state) - enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO; + enable = browser_->command_updater()->IsCommandEnabled(tag); switch (tag) { case IDC_CLOSE_TAB: // Disable "close tab" if we're not the key window or if there's only @@ -809,7 +854,7 @@ willPositionSheet:(NSWindow*)sheet // for Windows (ToolbarView::ButtonPressed()), this function handles // both reload button press event and Command+r press event. Thus the // 'isKindofClass' check is necessary. - [self locationBar]->Revert(); + [self locationBarBridge]->Revert(); } break; } @@ -841,8 +886,8 @@ willPositionSheet:(NSWindow*)sheet return [tabStripController_ sheetController]; } -- (LocationBar*)locationBar { - return [toolbarController_ locationBar]; +- (LocationBar*)locationBarBridge { + return [toolbarController_ locationBarBridge]; } - (StatusBubbleMac*)statusBubble { @@ -1116,9 +1161,7 @@ willPositionSheet:(NSWindow*)sheet } else { mac_util::ReleaseFullScreen(); [[[self window] contentView] addSubview:[toolbarController_ view]]; - if (browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { - [bookmarkBarController_ setBookmarkBarEnabled:YES]; - } + [bookmarkBarController_ setBookmarkBarEnabled:[self supportsBookmarkBar]]; } // Force a relayout. @@ -1187,11 +1230,34 @@ willPositionSheet:(NSWindow*)sheet return base::SysUTF16ToNSString(contents->GetTitle()); } -// TYPE_POPUP is not normal (e.g. no tab strip) +- (BOOL)supportsWindowFeature:(int)feature { + return browser_->SupportsWindowFeature( + static_cast<Browser::WindowFeature>(feature)); +} + +// (Override of |TabWindowController| method.) +- (BOOL)hasTabStrip { + return [self supportsWindowFeature:Browser::FEATURE_TABSTRIP]; +} + +- (BOOL)hasTitleBar { + return [self supportsWindowFeature:Browser::FEATURE_TITLEBAR]; +} + +- (BOOL)hasToolbar { + return [self supportsWindowFeature:Browser::FEATURE_TOOLBAR]; +} + +- (BOOL)hasLocationBar { + return [self supportsWindowFeature:Browser::FEATURE_LOCATIONBAR]; +} + +- (BOOL)supportsBookmarkBar { + return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; +} + - (BOOL)isNormalWindow { - if (browser_->type() == Browser::TYPE_NORMAL) - return YES; - return NO; + return browser_->type() == Browser::TYPE_NORMAL; } - (void)selectTabWithContents:(TabContents*)newContents @@ -1330,6 +1396,68 @@ willPositionSheet:(NSWindow*)sheet } } +// If the browser is in incognito mode, install the image view to decorate +// the window at the upper right. Use the same base y coordinate as the +// tab strip. +- (void)installIncognitoBadge { + if (!browser_->profile()->IsOffTheRecord()) + return; + // Don't install if we're not a normal browser (ie, a popup). + if (![self isNormalWindow]) + return; + + static const float kOffset = 4; + NSString* incognitoPath = [mac_util::MainAppBundle() + pathForResource:@"otr_icon" + ofType:@"pdf"]; + scoped_nsobject<NSImage> incognitoImage( + [[NSImage alloc] initWithContentsOfFile:incognitoPath]); + const NSSize imageSize = [incognitoImage size]; + NSRect tabFrame = [[self tabStripView] frame]; + NSRect incognitoFrame = tabFrame; + incognitoFrame.origin.x = NSMaxX(incognitoFrame) - imageSize.width - + kOffset; + incognitoFrame.size = imageSize; + scoped_nsobject<IncognitoImageView> incognitoView( + [[IncognitoImageView alloc] initWithFrame:incognitoFrame]); + [incognitoView setImage:incognitoImage.get()]; + [incognitoView setWantsLayer:YES]; + [incognitoView setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; + scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); + [shadow.get() setShadowColor:[NSColor colorWithCalibratedWhite:0.0 + alpha:0.5]]; + [shadow.get() setShadowOffset:NSMakeSize(0, -1)]; + [shadow setShadowBlurRadius:2.0]; + [incognitoView setShadow:shadow]; + + // Shrink the tab strip's width so there's no overlap and install the + // view. + tabFrame.size.width -= incognitoFrame.size.width + kOffset; + [[self tabStripView] setFrame:tabFrame]; + [[[[self window] contentView] superview] addSubview:incognitoView.get()]; +} + +// Undocumented method for multi-touch gestures in 10.5. Future OS's will +// likely add a public API, but the worst that will happen is that this will +// turn into dead code and just won't get called. +- (void)swipeWithEvent:(NSEvent*)event { + // Map forwards and backwards to history; left is positive, right is negative. + unsigned int command = 0; + if ([event deltaX] > 0.5) + command = IDC_BACK; + else if ([event deltaX] < -0.5) + command = IDC_FORWARD; + else if ([event deltaY] > 0.5) + ; // TODO(pinkerton): figure out page-up + else if ([event deltaY] < -0.5) + ; // TODO(pinkerton): figure out page-down + + // Ensure the command is valid first (ExecuteCommand() won't do that) and + // then make it so. + if (browser_->command_updater()->IsCommandEnabled(command)) + browser_->ExecuteCommand(command); +} + // Delegate method called when window is resized. - (void)windowDidResize:(NSNotification*)notification { // Resize (and possibly move) the status bubble. Note that we may get called @@ -1383,6 +1511,13 @@ willPositionSheet:(NSWindow*)sheet return frameSize; } +// Delegate method: see |NSWindowDelegate| protocol. +- (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj { + // Ask the toolbar controller if it wants to return a custom field editor + // for the specific object. + return [toolbarController_ customFieldEditorForObject:obj]; +} + // (Needed for |BookmarkBarControllerDelegate| protocol.) - (void)bookmarkBar:(BookmarkBarController*)controller didChangeFromState:(bookmarks::VisualState)oldState @@ -1428,47 +1563,6 @@ willAnimateFromState:(bookmarks::VisualState)oldState @implementation BrowserWindowController (Private) -// If the browser is in incognito mode, install the image view to decorate -// the window at the upper right. Use the same base y coordinate as the -// tab strip. -- (void)installIncognitoBadge { - if (!browser_->profile()->IsOffTheRecord()) - return; - // Don't install if we're not a normal browser (ie, a popup). - if (![self isNormalWindow]) - return; - - static const float kOffset = 4; - NSString* incognitoPath = [mac_util::MainAppBundle() - pathForResource:@"otr_icon" - ofType:@"pdf"]; - scoped_nsobject<NSImage> incognitoImage( - [[NSImage alloc] initWithContentsOfFile:incognitoPath]); - const NSSize imageSize = [incognitoImage size]; - NSRect tabFrame = [[self tabStripView] frame]; - NSRect incognitoFrame = tabFrame; - incognitoFrame.origin.x = NSMaxX(incognitoFrame) - imageSize.width - - kOffset; - incognitoFrame.size = imageSize; - scoped_nsobject<IncognitoImageView> incognitoView( - [[IncognitoImageView alloc] initWithFrame:incognitoFrame]); - [incognitoView setImage:incognitoImage.get()]; - [incognitoView setWantsLayer:YES]; - [incognitoView setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; - scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); - [shadow.get() setShadowColor:[NSColor colorWithCalibratedWhite:0.0 - alpha:0.5]]; - [shadow.get() setShadowOffset:NSMakeSize(0, -1)]; - [shadow setShadowBlurRadius:2.0]; - [incognitoView setShadow:shadow]; - - // Shrink the tab strip's width so there's no overlap and install the - // view. - tabFrame.size.width -= incognitoFrame.size.width + kOffset; - [[self tabStripView] setFrame:tabFrame]; - [[[[self window] contentView] superview] addSubview:incognitoView.get()]; -} - - (void)saveWindowPositionIfNeeded { if (browser_ != BrowserList::GetLastActive()) return; @@ -1537,33 +1631,6 @@ willPositionSheet:(NSWindow*)sheet return defaultSheetRect; } -// Undocumented method for multi-touch gestures in 10.5. Future OS's will -// likely add a public API, but the worst that will happen is that this will -// turn into dead code and just won't get called. -- (void)swipeWithEvent:(NSEvent*)event { - // Map forwards and backwards to history; left is positive, right is negative. - unsigned int command = 0; - if ([event deltaX] > 0.5) - command = IDC_BACK; - else if ([event deltaX] < -0.5) - command = IDC_FORWARD; - else if ([event deltaY] > 0.5) - ; // TODO(pinkerton): figure out page-up - else if ([event deltaY] < -0.5) - ; // TODO(pinkerton): figure out page-down - - // Ensure the command is valid first (ExecuteCommand() won't do that) and - // then make it so. - if (browser_->command_updater()->IsCommandEnabled(command)) - browser_->ExecuteCommand(command); -} - -- (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj { - // Ask the toolbar controller if it wants to return a custom field editor - // for the specific object. - return [toolbarController_ customFieldEditorForObject:obj]; -} - - (void)setTheme { ThemeProvider* theme_provider = browser_->profile()->GetThemeProvider(); BrowserThemeProvider* browser_theme_provider = @@ -1577,113 +1644,147 @@ willPositionSheet:(NSWindow*)sheet } } -// Private method to layout browser window subviews. Positions the toolbar and -// the infobar above the tab content area. Positions the download shelf below -// the tab content area. If the toolbar is not a child of the contentview, this -// method will not leave room for it. If we are currently running in fullscreen -// mode, or if the tabstrip is not a descendant of the window, this method fills -// the entire content area. Otherwise, this method places the topmost view -// directly beneath the tabstrip. - (void)layoutSubviews { NSWindow* window = [self window]; NSView* contentView = [window contentView]; NSRect contentFrame = [contentView frame]; - int maxY = NSMaxY(contentFrame); - int minY = NSMinY(contentFrame); - if (![self isFullscreen] && [self isNormalWindow]) { + CGFloat maxY = NSMaxY(contentFrame); + CGFloat minY = NSMinY(contentFrame); + CGFloat width = NSWidth(contentFrame); + if ([self hasTabStrip]) maxY = NSMinY([[self tabStripView] frame]); - } DCHECK_GE(maxY, minY); - // Suppress title drawing for normal windows (popups use normal - // window title bars). - if ([window respondsToSelector:@selector(setShouldHideTitle:)]) { - [(id)window setShouldHideTitle:[self isNormalWindow]]; - } + // Suppress title drawing if necessary. + if ([window respondsToSelector:@selector(setShouldHideTitle:)]) + [(id)window setShouldHideTitle:![self hasTitleBar]]; + + // Place the toolbar at the top of the reserved area. + maxY = [self layoutToolbarAtMaxY:maxY width:width]; + + // If we're not displaying the bookmark bar below the infobar, then it goes + // immediately below the toolbar. + BOOL placeBookmarkBarBelowInfoBar = [self placeBookmarkBarBelowInfoBar]; + if (!placeBookmarkBarBelowInfoBar) + maxY = [self layoutBookmarkBarAtMaxY:maxY width:width]; + + // Place the infobar container in place below the toolbar. + maxY = [self layoutInfoBarAtMaxY:maxY width:width]; + + // If the bookmark bar is detached, place it at the bottom of the stack. + if (placeBookmarkBarBelowInfoBar) + maxY = [self layoutBookmarkBarAtMaxY:maxY width:width]; + + // Place the download shelf, if any, at the bottom of the view. + minY = [self layoutDownloadShelfAtMinY:minY width:width]; - // Place the toolbar at the top of the reserved area, but only if we're not in - // fullscreen mode. + // Finally, the content area takes up all of the remaining space. + [self layoutTabContentAreaAtMinY:minY maxY:maxY width:width]; + + // Position the find bar relative to the infobar container. + [findBarCocoaController_ + positionFindBarView:[infoBarContainerController_ view]]; + + // Place the status bubble at the bottom of the content area. + verticalOffsetForStatusBubble_ = minY; + + // Normally, we don't need to tell the toolbar whether or not to show the + // divider, but things break down during animation. + [toolbarController_ + setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; +} + +- (CGFloat)layoutToolbarAtMaxY:(CGFloat)maxY width:(CGFloat)width { NSView* toolbarView = [toolbarController_ view]; NSRect toolbarFrame = [toolbarView frame]; - if (![self isFullscreen]) { + if ([self hasToolbar]) { // The toolbar is present in the window, so we make room for it. + DCHECK(![toolbarView isHidden]); toolbarFrame.origin.x = 0; toolbarFrame.origin.y = maxY - NSHeight(toolbarFrame); - toolbarFrame.size.width = NSWidth(contentFrame); + toolbarFrame.size.width = width; maxY -= NSHeight(toolbarFrame); + } else { + if ([self hasLocationBar]) { + // Location bar is present with no toolbar. Put a border of + // |kLocBar...Inset| pixels around the location bar. + // TODO(viettrungluu): This is moderately ridiculous. The toolbar should + // really be aware of what its height should be (the way the toolbar + // compression stuff is currently set up messes things up). + DCHECK(![toolbarView isHidden]); + // TODO(viettrungluu): We can argue about the "correct" insetting; I like + // the following best, though arguably 0 inset is better/more correct. + const CGFloat kLocBarLeftRightInset = 1; + const CGFloat kLocBarTopInset = 0; + const CGFloat kLocBarBottomInset = 1; + toolbarFrame.origin.x = kLocBarLeftRightInset; + toolbarFrame.origin.y = maxY - NSHeight(toolbarFrame) - kLocBarTopInset; + toolbarFrame.size.width = width - 2 * kLocBarLeftRightInset; + maxY -= kLocBarTopInset + NSHeight(toolbarFrame) + kLocBarBottomInset; + } else { + DCHECK([toolbarView isHidden]); + } } [toolbarView setFrame:toolbarFrame]; + return maxY; +} - // 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. - BOOL placeBookmarkBarBelowInfobar = - [bookmarkBarController_ isInState:bookmarks::kDetachedState] || - [bookmarkBarController_ isAnimatingToState:bookmarks::kDetachedState] || - [bookmarkBarController_ isAnimatingFromState:bookmarks::kDetachedState]; +- (CGFloat)layoutBookmarkBarAtMaxY:(CGFloat)maxY width:(CGFloat)width { + NSView* bookmarkBarView = [bookmarkBarController_ view]; + [bookmarkBarView setHidden:NO]; + NSRect bookmarkBarFrame = [bookmarkBarView frame]; + bookmarkBarFrame.origin.y = maxY - NSHeight(bookmarkBarFrame); + bookmarkBarFrame.size.width = width; + [bookmarkBarView setFrame:bookmarkBarFrame]; + maxY -= NSHeight(bookmarkBarFrame); - // If we're not displaying the bookmark bar below the infobar, then it goes - // immediately below the toolbar. - if (!placeBookmarkBarBelowInfobar) { - NSView* bookmarkBarView = [bookmarkBarController_ view]; - [bookmarkBarView setHidden:NO]; - NSRect bookmarkBarFrame = [bookmarkBarView frame]; - bookmarkBarFrame.origin.y = maxY - NSHeight(bookmarkBarFrame); - bookmarkBarFrame.size.width = NSWidth(contentFrame); - [bookmarkBarView setFrame:bookmarkBarFrame]; - maxY -= NSHeight(bookmarkBarFrame); - } + // TODO(viettrungluu): Does this really belong here? Calling it shouldn't be + // necessary in the non-NTP case. + [bookmarkBarController_ layoutSubviews]; - // Place the infobar container in place below the toolbar. + return maxY; +} + +- (CGFloat)layoutInfoBarAtMaxY:(CGFloat)maxY width:(CGFloat)width { NSView* infoBarView = [infoBarContainerController_ view]; NSRect infoBarFrame = [infoBarView frame]; infoBarFrame.origin.y = maxY - NSHeight(infoBarFrame); - infoBarFrame.size.width = NSWidth(contentFrame); + infoBarFrame.size.width = width; [infoBarView setFrame:infoBarFrame]; maxY -= NSHeight(infoBarFrame); + return maxY; +} - // If the bookmark bar is detached, place it at the bottom of the stack. - if (placeBookmarkBarBelowInfobar) { - NSView* bookmarkBarView = [bookmarkBarController_ view]; - [bookmarkBarView setHidden:NO]; - NSRect bookmarkBarFrame = [bookmarkBarView frame]; - bookmarkBarFrame.origin.y = maxY - NSHeight(bookmarkBarFrame); - bookmarkBarFrame.size.width = NSWidth(contentFrame); - [bookmarkBarView setFrame:bookmarkBarFrame]; - maxY -= NSHeight(bookmarkBarFrame); - - // TODO(viettrungluu): this really doesn't belong here. - [bookmarkBarController_ layoutSubviews]; - } +- (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. + return [bookmarkBarController_ isInState:bookmarks::kDetachedState] || + [bookmarkBarController_ isAnimatingToState:bookmarks::kDetachedState] || + [bookmarkBarController_ isAnimatingFromState:bookmarks::kDetachedState]; +} - // If there's a download shelf, place it at the bottom of the view. +- (CGFloat)layoutDownloadShelfAtMinY:(CGFloat)minY width:(CGFloat)width { if (downloadShelfController_.get()) { NSView* downloadView = [downloadShelfController_ view]; NSRect downloadFrame = [downloadView frame]; downloadFrame.origin.y = minY; - downloadFrame.size.width = NSWidth(contentFrame); + downloadFrame.size.width = width; [downloadView setFrame:downloadFrame]; minY += NSHeight(downloadFrame); } + return minY; +} - // Finally, the tabContentArea takes up all of the remaining space. +- (void)layoutTabContentAreaAtMinY:(CGFloat)minY + maxY:(CGFloat)maxY + width:(CGFloat)width { NSView* tabContentView = [self tabContentArea]; NSRect tabContentFrame = [tabContentView frame]; tabContentFrame.origin.y = minY; tabContentFrame.size.height = maxY - minY; - tabContentFrame.size.width = NSWidth(contentFrame); + tabContentFrame.size.width = width; [tabContentView setFrame:tabContentFrame]; - - // Position the find bar relative to the infobar container. - [findBarCocoaController_ - positionFindBarView:[infoBarContainerController_ view]]; - - verticalOffsetForStatusBubble_ = minY; - - // Normally, we don't need to tell the toolbar whether or not to show the - // divider, but things break down during animation. - [toolbarController_ - setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; } - (BOOL)shouldShowBookmarkBar { diff --git a/chrome/browser/cocoa/browser_window_controller_unittest.mm b/chrome/browser/cocoa/browser_window_controller_unittest.mm index 5ad4050..4c16404 100644 --- a/chrome/browser/cocoa/browser_window_controller_unittest.mm +++ b/chrome/browser/cocoa/browser_window_controller_unittest.mm @@ -104,6 +104,8 @@ TEST_F(BrowserWindowControllerTest, TestNormal) { // Make sure a normal BrowserWindowController is, uh, normal. EXPECT_TRUE([controller_ isNormalWindow]); + EXPECT_TRUE([controller_ hasTabStrip]); + EXPECT_FALSE([controller_ hasTitleBar]); EXPECT_TRUE([controller_ isBookmarkBarVisible]); // And make sure a controller for a pop-up window is not normal. @@ -114,6 +116,8 @@ TEST_F(BrowserWindowControllerTest, TestNormal) { static_cast<BrowserWindowController*>([cocoaWindow windowController]); ASSERT_TRUE([controller isKindOfClass:[BrowserWindowController class]]); EXPECT_FALSE([controller isNormalWindow]); + EXPECT_FALSE([controller hasTabStrip]); + EXPECT_TRUE([controller hasTitleBar]); EXPECT_FALSE([controller isBookmarkBarVisible]); [controller close]; } diff --git a/chrome/browser/cocoa/chrome_browser_window.mm b/chrome/browser/cocoa/chrome_browser_window.mm index c4b503b..1030bc8 100644 --- a/chrome/browser/cocoa/chrome_browser_window.mm +++ b/chrome/browser/cocoa/chrome_browser_window.mm @@ -112,7 +112,7 @@ namespace { closeButton_ = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:aStyle]; NSRect closeButtonFrame = [closeButton_ frame]; - CGFloat yOffset = [browserController isNormalWindow] ? + CGFloat yOffset = [browserController hasTabStrip] ? kChromeWindowButtonsWithTabStripOffsetFromTop : kChromeWindowButtonsWithoutTabStripOffsetFromTop; closeButtonFrame.origin = diff --git a/chrome/browser/cocoa/chrome_browser_window_unittest.mm b/chrome/browser/cocoa/chrome_browser_window_unittest.mm index 6ac0a8f..4ab4a2a 100644 --- a/chrome/browser/cocoa/chrome_browser_window_unittest.mm +++ b/chrome/browser/cocoa/chrome_browser_window_unittest.mm @@ -120,8 +120,11 @@ TEST_F(ChromeBrowserWindowTest, WindowWidgetLocation) { // Then with a tabstrip. id controller = [OCMockObject mockForClass:[BrowserWindowController class]]; BOOL yes = YES; + BOOL no = NO; [[[controller stub] andReturnValue:OCMOCK_VALUE(yes)] isKindOfClass:[BrowserWindowController class]]; + [[[controller expect] andReturnValue:OCMOCK_VALUE(yes)] hasTabStrip]; + [[[controller expect] andReturnValue:OCMOCK_VALUE(no)] hasTitleBar]; [[[controller expect] andReturnValue:OCMOCK_VALUE(yes)] isNormalWindow]; [window_ setWindowController:controller]; diff --git a/chrome/browser/cocoa/download_item_cell.mm b/chrome/browser/cocoa/download_item_cell.mm index 57d79e3..267fb0f 100644 --- a/chrome/browser/cocoa/download_item_cell.mm +++ b/chrome/browser/cocoa/download_item_cell.mm @@ -397,20 +397,12 @@ const int kCompleteAnimationDuration = 2.5; NSBezierPath* buttonInnerPath = [self leftRoundedPath:radius inRect:buttonDrawRect]; - NSBezierPath* buttonOuterPath = [self - leftRoundedPath:(radius + 1) - inRect:NSInsetRect(buttonDrawRect, -1, -1)]; - NSBezierPath* dropdownInnerPath = [self rightRoundedPath:radius inRect:dropdownDrawRect]; - NSBezierPath* dropdownOuterPath = [self - rightRoundedPath:(radius + 1) - inRect:NSInsetRect(dropdownDrawRect, -1, -1)]; // Stroke the borders and appropriate fill gradient. [self drawBorderAndFillForTheme:theme controlView:controlView - outerPath:buttonOuterPath innerPath:buttonInnerPath showClickedGradient:[self isButtonPartPressed] showHighlightGradient:[self isMouseOverButtonPart] @@ -421,7 +413,6 @@ const int kCompleteAnimationDuration = 2.5; [self drawBorderAndFillForTheme:theme controlView:controlView - outerPath:dropdownOuterPath innerPath:dropdownInnerPath showClickedGradient:[self isDropdownPartPressed] showHighlightGradient:[self isMouseOverDropdownPart] diff --git a/chrome/browser/cocoa/gradient_button_cell.h b/chrome/browser/cocoa/gradient_button_cell.h index e9d09bd..27909a0 100644 --- a/chrome/browser/cocoa/gradient_button_cell.h +++ b/chrome/browser/cocoa/gradient_button_cell.h @@ -45,7 +45,6 @@ typedef NSInteger ButtonType; - (void)drawBorderAndFillForTheme:(GTMTheme*)theme controlView:(NSView*)controlView - outerPath:(NSBezierPath*)outerPath innerPath:(NSBezierPath*)innerPath showClickedGradient:(BOOL)showClickedGradient showHighlightGradient:(BOOL)showHighlightGradient diff --git a/chrome/browser/cocoa/gradient_button_cell.mm b/chrome/browser/cocoa/gradient_button_cell.mm index 838397c8..43b865f 100644 --- a/chrome/browser/cocoa/gradient_button_cell.mm +++ b/chrome/browser/cocoa/gradient_button_cell.mm @@ -24,7 +24,6 @@ inView:(NSView*)controlView innerFrame:(NSRect*)returnInnerFrame innerPath:(NSBezierPath**)returnInnerPath - outerPath:(NSBezierPath**)returnOuterPath clipPath:(NSBezierPath**)returnClipPath; @end @@ -176,7 +175,6 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; // TODO(viettrungluu): clean up/reorganize. - (void)drawBorderAndFillForTheme:(GTMTheme*)theme controlView:(NSView*)controlView - outerPath:(NSBezierPath*)outerPath innerPath:(NSBezierPath*)innerPath showClickedGradient:(BOOL)showClickedGradient showHighlightGradient:(BOOL)showHighlightGradient @@ -279,7 +277,6 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; inView:(NSView*)controlView innerFrame:(NSRect*)returnInnerFrame innerPath:(NSBezierPath**)returnInnerPath - outerPath:(NSBezierPath**)returnOuterPath clipPath:(NSBezierPath**)returnClipPath { // Constants from Cole. Will kConstant them once the feedback loop // is complete. @@ -316,13 +313,6 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; xRadius:radius yRadius:radius]; } - if (returnOuterPath) { - DCHECK(*returnOuterPath == nil); - NSRect outerPathRect = NSInsetRect(drawFrame, -1, -1); - *returnOuterPath = [NSBezierPath bezierPathWithRoundedRect:outerPathRect - xRadius:radius + 1 - yRadius:radius + 1]; - } if (returnClipPath) { DCHECK(*returnClipPath == nil); NSRect clipPathRect = NSInsetRect(drawFrame, -0.5, -0.5); @@ -336,12 +326,10 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { NSRect innerFrame; NSBezierPath* innerPath = nil; - NSBezierPath* outerPath = nil; [self getDrawParamsForFrame:cellFrame inView:controlView innerFrame:&innerFrame innerPath:&innerPath - outerPath:&outerPath clipPath:NULL]; BOOL pressed = [self isHighlighted]; @@ -358,7 +346,6 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; [self drawBorderAndFillForTheme:theme controlView:controlView - outerPath:outerPath innerPath:innerPath showClickedGradient:pressed showHighlightGradient:[self isHighlighted] @@ -456,7 +443,6 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; inView:controlView innerFrame:NULL innerPath:NULL - outerPath:NULL clipPath:&boundingPath]; return boundingPath; } diff --git a/chrome/browser/cocoa/tab_window_controller.h b/chrome/browser/cocoa/tab_window_controller.h index c9c2589..850b203 100644 --- a/chrome/browser/cocoa/tab_window_controller.h +++ b/chrome/browser/cocoa/tab_window_controller.h @@ -115,10 +115,9 @@ // The title of the selected tab. - (NSString*)selectedTabTitle; -// Called to check if we are a normal window (e.g. not a pop-up) and -// want normal behavior (e.g. a tab strip). Return YES if so. The -// default implementation returns YES. -- (BOOL)isNormalWindow; +// Called to check whether or not this controller's window has a tab strip (YES +// if it does, NO otherwise). The default implementation returns YES. +- (BOOL)hasTabStrip; // Get/set whether a particular tab is draggable between windows. - (BOOL)isTabDraggable:(NSView*)tabView; diff --git a/chrome/browser/cocoa/tab_window_controller.mm b/chrome/browser/cocoa/tab_window_controller.mm index c8e881c..984ab35f 100644 --- a/chrome/browser/cocoa/tab_window_controller.mm +++ b/chrome/browser/cocoa/tab_window_controller.mm @@ -23,7 +23,7 @@ } - (void)windowDidLoad { - if ([self isNormalWindow]) { + if ([self hasTabStrip]) { // Place the tab bar above the content box and add it to the view hierarchy // as a sibling of the content view so it can overlap with the window frame. NSRect tabFrame = [tabContentArea_ frame]; @@ -199,8 +199,8 @@ return @""; } -- (BOOL)isNormalWindow { - // subclass must implement +- (BOOL)hasTabStrip { + // Subclasses should implement this. NOTIMPLEMENTED(); return YES; } diff --git a/chrome/browser/cocoa/toolbar_controller.h b/chrome/browser/cocoa/toolbar_controller.h index 0b96569..83a1b81 100644 --- a/chrome/browser/cocoa/toolbar_controller.h +++ b/chrome/browser/cocoa/toolbar_controller.h @@ -72,7 +72,8 @@ class ToolbarModel; scoped_ptr<BubblePositioner> bubblePositioner_; BooleanPrefMember showHomeButton_; BooleanPrefMember showPageOptionButtons_; - BOOL hasToolbar_; // if NO, we only have the location bar. + BOOL hasToolbar_; // If NO, we may have only the location bar. + BOOL hasLocationBar_; // If |hasToolbar_| is YES, this must also be YES. // We have an extra retain in the locationBar_. // See comments in awakeFromNib for more info. @@ -113,7 +114,7 @@ class ToolbarModel; resizeDelegate:(id<ViewResizer>)resizeDelegate; // Get the C++ bridge object representing the location bar for this tab. -- (LocationBar*)locationBar; +- (LocationBar*)locationBarBridge; // Called by the Window delegate so we can provide a custom field editor if // needed. @@ -138,10 +139,10 @@ class ToolbarModel; // state. - (void)setIsLoading:(BOOL)isLoading; -// Allow turning off the toolbar (but we keep the location bar -// around). This changes the behavior of other methods, like -// [self view]. -- (void)setHasToolbar:(BOOL)toolbar; +// Allow turning off the toolbar (but we may keep the location bar without a +// surrounding toolbar). If |toolbar| is YES, the value of |hasLocationBar| is +// ignored. This changes the behavior of other methods, like |-view|. +- (void)setHasToolbar:(BOOL)toolbar hasLocationBar:(BOOL)locBar; // The bookmark bubble (when you click the star) needs to know where to go. // Somewhere near the star button seems like a good start. diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm index 05a70b7..cb78971 100644 --- a/chrome/browser/cocoa/toolbar_controller.mm +++ b/chrome/browser/cocoa/toolbar_controller.mm @@ -149,6 +149,7 @@ class PrefObserverBridge : public NotificationObserver { browser_ = browser; resizeDelegate_ = resizeDelegate; hasToolbar_ = YES; + hasLocationBar_ = YES; // Register for notifications about state changes for the toolbar buttons commandObserver_.reset(new CommandObserverBridge(self, commands)); @@ -165,6 +166,7 @@ class PrefObserverBridge : public NotificationObserver { // Make sure any code in the base class which assumes [self view] is // the "parent" view continues to work. hasToolbar_ = YES; + hasLocationBar_ = YES; [[NSNotificationCenter defaultCenter] removeObserver:self]; @@ -293,7 +295,7 @@ class PrefObserverBridge : public NotificationObserver { [self mouseMoved:event]; } -- (LocationBar*)locationBar { +- (LocationBar*)locationBarBridge { return locationBarView_.get(); } @@ -377,15 +379,20 @@ class PrefObserverBridge : public NotificationObserver { [goButton_ setTag:tag]; } -- (void)setHasToolbar:(BOOL)toolbar { - [self view]; // force nib loading +- (void)setHasToolbar:(BOOL)toolbar hasLocationBar:(BOOL)locBar { + [self view]; // Force nib loading. + hasToolbar_ = toolbar; - // App mode allows turning off the location bar as well. - // TODO(???): add more code here when implementing app mode to allow - // turning off both toolbar AND location bar. + // If there's a toolbar, there must be a location bar. + DCHECK((toolbar && locBar) || !toolbar); + hasLocationBar_ = toolbar ? YES : locBar; + + // Decide whether to hide/show based on whether there's a location bar. + [[self view] setHidden:!hasLocationBar_]; // Make location bar not editable when in a pop-up. + // TODO(viettrungluu): is this right (all the time)? [locationBar_ setEditable:toolbar]; } @@ -582,7 +589,9 @@ class PrefObserverBridge : public NotificationObserver { } - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight { - return kBaseToolbarHeight - compressByHeight; + // With no toolbar, just ignore the compression. + return hasToolbar_ ? kBaseToolbarHeight - compressByHeight : + NSHeight([locationBar_ frame]); } - (void)setDividerOpacity:(CGFloat)opacity { @@ -613,7 +622,7 @@ class PrefObserverBridge : public NotificationObserver { // It is 'go', so see what it would do... // Fetch the EditView and EditModel - LocationBar* locationBar = [self locationBar]; + LocationBar* locationBar = [self locationBarBridge]; DCHECK(locationBar); AutocompleteEditView* editView = locationBar->location_entry(); DCHECK(editView); diff --git a/chrome/browser/cocoa/toolbar_controller_unittest.mm b/chrome/browser/cocoa/toolbar_controller_unittest.mm index f7a2310..5ce499b 100644 --- a/chrome/browser/cocoa/toolbar_controller_unittest.mm +++ b/chrome/browser/cocoa/toolbar_controller_unittest.mm @@ -95,11 +95,11 @@ TEST_F(ToolbarControllerTest, InitialState) { CompareState(updater, [bar_ toolbarViews]); } -// Make sure a "titlebar only" toolbar works +// Make sure a "titlebar only" toolbar with location bar works. TEST_F(ToolbarControllerTest, TitlebarOnly) { NSView* view = [bar_ view]; - [bar_ setHasToolbar:NO]; + [bar_ setHasToolbar:NO hasLocationBar:YES]; EXPECT_NE(view, [bar_ view]); // Simulate a popup going fullscreen and back. @@ -110,13 +110,14 @@ TEST_F(ToolbarControllerTest, TitlebarOnly) { [view removeFromSuperview]; [superview addSubview:view]; - [bar_ setHasToolbar:YES]; + [bar_ setHasToolbar:YES hasLocationBar:YES]; EXPECT_EQ(view, [bar_ view]); // Leave it off to make sure that's fine - [bar_ setHasToolbar:NO]; + [bar_ setHasToolbar:NO hasLocationBar:YES]; } +// TODO(viettrungluu): make a version of above without location bar. // Make some changes to the enabled state of a few of the buttons and ensure // that we're still in sync. @@ -208,7 +209,7 @@ TEST_F(ToolbarControllerTest, TogglePageWrench) { // having the full toolbar. Also ensure that the location bar doesn't change // size. TEST_F(ToolbarControllerTest, DontToggleWhenNoToolbar) { - [bar_ setHasToolbar:NO]; + [bar_ setHasToolbar:NO hasLocationBar:YES]; NSView* homeButton = [[bar_ toolbarViews] objectAtIndex:kHomeIndex]; NSView* pageButton = [[bar_ toolbarViews] objectAtIndex:kPageIndex]; NSView* wrenchButton = [[bar_ toolbarViews] objectAtIndex:kWrenchIndex]; |