diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-09 15:58:37 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-09 15:58:37 +0000 |
commit | ad54c1966904ed5b3d7e71c8f6caf4606c7e6a93 (patch) | |
tree | 9d444313041981d7fb10270c452bcc4f9f45c775 /chrome/browser | |
parent | 05dfe6a91f4670bfc442b3ab918e5092b3eff6cd (diff) | |
download | chromium_src-ad54c1966904ed5b3d7e71c8f6caf4606c7e6a93.zip chromium_src-ad54c1966904ed5b3d7e71c8f6caf4606c7e6a93.tar.gz chromium_src-ad54c1966904ed5b3d7e71c8f6caf4606c7e6a93.tar.bz2 |
Mac: incognito badge fixes.
1. Make the incognito badge appear in fullscreen mode.
2. Make the new tab button not run into the incognito badge.
BUG=37574, 37745
TEST=Make an incognito window and go to fullscreen mode; incognito badge should be visible in upper right. Make an incognito window with lots of tabs; new tab button (and tabs) shouldn't run into the badge; resize the window and make sure the badge stays in the right place.
Review URL: http://codereview.chromium.org/691003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41031 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
4 files changed, 46 insertions, 27 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index 9fd6c71..b6b95a9 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -32,6 +32,7 @@ class ConstrainedWindowMac; @class FindBarCocoaController; @class FullscreenController; @class GTMWindowSheetController; +@class IncognitoImageView; @class InfoBarContainerController; class LocationBar; class StatusBubbleMac; @@ -94,6 +95,10 @@ class TabStripModelObserverBridge; CGFloat totalMagnifyGestureAmount_; NSInteger currentZoomStepDelta_; + // The view which shows the incognito badge (NULL if not an incognito window). + // Needed to access the view to move it to/from the fullscreen window. + scoped_nsobject<IncognitoImageView> incognitoBadge_; + // Lazily created view which draws the background for the floating set of bars // in fullscreen mode. scoped_nsobject<NSView> floatingBarBackingView_; diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index f2daf7a..0e47bd1 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -222,9 +222,7 @@ windowShim_->SetBounds(windowRect, BrowserWindow::WINDOW_BOUNDS); - // Puts the incognito badge on the window frame, if necessary. Do this - // before creating the tab strip to avoid redundant tab layout. - // TODO(viettrungluu): fullscreen mode + // Puts the incognito badge on the window frame, if necessary. [self installIncognitoBadge]; // Create a controller for the tab strip, giving it the model object for @@ -1414,34 +1412,24 @@ if (!browser_->profile()->IsOffTheRecord() || ![self hasTabStrip]) return; - const CGFloat kOffset = 4; // Space between the badge and the right edge. + // Install the image into the badge view and size the view appropriately. + // Hide it for now; positioning and showing will be done by the layout code. NSImage* image = nsimage_cache::ImageNamed(@"otr_icon.pdf"); - - // Create the incognito badge view, with size that of the image, aligned with - // the bottom of the tab strip, and aligned at the right with a bit of space. - NSSize size = [image size]; - NSRect tabStripFrame = [[self tabStripView] frame]; - NSRect frame = NSMakeRect(NSMaxX(tabStripFrame) - size.width - kOffset, - tabStripFrame.origin.y, size.width, size.height); - scoped_nsobject<IncognitoImageView> incognitoView( - [[IncognitoImageView alloc] initWithFrame:frame]); - [incognitoView setImage:image]; - [incognitoView setWantsLayer:YES]; - [incognitoView setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; + incognitoBadge_.reset([[IncognitoImageView alloc] init]); + [incognitoBadge_ setImage:image]; + [incognitoBadge_ setFrameSize:[image size]]; + [incognitoBadge_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; + [incognitoBadge_ setHidden:YES]; // Give it a shadow. scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); - [shadow.get() setShadowColor:[NSColor colorWithCalibratedWhite:0.0 - alpha:0.5]]; - [shadow.get() setShadowOffset:NSMakeSize(0, -1)]; + [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.5]]; + [shadow setShadowOffset:NSMakeSize(0, -1)]; [shadow setShadowBlurRadius:2.0]; - [incognitoView setShadow:shadow]; + [incognitoBadge_ setShadow:shadow]; - // Shrink the tab strip's width so there's no overlap and install the view. - tabStripFrame.size.width -= NSWidth(frame) + kOffset; - DCHECK(NSWidth(tabStripFrame) > 0); - [[self tabStripView] setFrame:tabStripFrame]; - [[[[self window] contentView] superview] addSubview:incognitoView.get()]; + // Install the view. + [[[[self window] contentView] superview] addSubview:incognitoBadge_]; } // Documented in 10.6+, but present starting in 10.5. Called when we get a @@ -1682,8 +1670,15 @@ willAnimateFromState:(bookmarks::VisualState)oldState [contentView setAutoresizesSubviews:YES]; [destWindow setContentView:contentView]; - // Add the tabstrip after setting the content view, so that the tab strip will - // be on top (in the z-order). + // Move the incognito badge if present. + if (incognitoBadge_.get()) { + [incognitoBadge_ removeFromSuperview]; + [incognitoBadge_ setHidden:YES]; // Will be shown in layout. + [[[destWindow contentView] superview] addSubview:incognitoBadge_]; + } + + // Add the tab strip after setting the content view and moving the incognito + // badge (if any), so that the tab strip will be on top (in the z-order). if ([self hasTabStrip]) [[[destWindow contentView] superview] addSubview:tabStripView]; diff --git a/chrome/browser/cocoa/browser_window_controller_private.mm b/chrome/browser/cocoa/browser_window_controller_private.mm index e4ab513..5251112 100644 --- a/chrome/browser/cocoa/browser_window_controller_private.mm +++ b/chrome/browser/cocoa/browser_window_controller_private.mm @@ -27,6 +27,9 @@ namespace { +// Space between the incognito badge and the right edge of the window. +const CGFloat kIncognitoBadgeOffset = 4; + // Insets for the location bar, used when the full toolbar is hidden. // TODO(viettrungluu): We can argue about the "correct" insetting; I like the // following best, though arguably 0 inset is better/more correct. @@ -248,6 +251,15 @@ willPositionSheet:(NSWindow*)sheet // this? Moreover, |-layoutTabs| will try to animate.... [tabStripController_ layoutTabs]; + // Now lay out incognito badge together with the tab strip. + if (incognitoBadge_.get()) { + // Actually place the badge *above* |maxY|. + NSPoint origin = NSMakePoint(width - NSWidth([incognitoBadge_ frame]) - + kIncognitoBadgeOffset, maxY); + [incognitoBadge_ setFrameOrigin:origin]; + [incognitoBadge_ setHidden:NO]; // Make sure it's shown. + } + return maxY; } diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index 6fe0222..ef0bcfa 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -60,6 +60,10 @@ const CGFloat kTabOverlap = 20.0; // The amount by which the new tab button is offset (from the tabs). const CGFloat kNewTabButtonOffset = 8.0; +// The amount by which to shrink the tab strip (on the right) when the +// incognito badge is present. +const CGFloat kIncognitoBadgeTabStripShrink = 18; + // Time (in seconds) in which tabs animate to their final position. const NSTimeInterval kAnimationDuration = 0.2; @@ -668,7 +672,10 @@ private: availableWidth = availableResizeWidth_; } else { availableWidth = NSWidth([tabStripView_ frame]); + // Account for the new tab button and the incognito badge. availableWidth -= NSWidth([newTabButton_ frame]) + kNewTabButtonOffset; + if (browser_->profile()->IsOffTheRecord()) + availableWidth -= kIncognitoBadgeTabStripShrink; } availableWidth -= [self indentForControls]; |