diff options
author | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-13 16:33:35 +0000 |
---|---|---|
committer | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-13 16:33:35 +0000 |
commit | a457e8057cfb9b653b667799e078b814444a8af7 (patch) | |
tree | 90d01b9571cd79a4cd2f2f212b36db66ee397d98 /chrome/browser/cocoa | |
parent | cc0445fff1bc059231e7bd4772fe145105ea42cb (diff) | |
download | chromium_src-a457e8057cfb9b653b667799e078b814444a8af7.zip chromium_src-a457e8057cfb9b653b667799e078b814444a8af7.tar.gz chromium_src-a457e8057cfb9b653b667799e078b814444a8af7.tar.bz2 |
Fixes up drawing so that we don't have any transparent holes, and adds a
bit more of a guard around some private API calling.
Also moves the widgets up one pixel, and fixes drawing the widgets in windows
without tabstrips.
BUG=24539, 24693
TEST=Assign a window the Mark Ecko theme (https://tools.google.com/chrome/intl/en/themes/theme_at_mecko.html) and look for holes in the top of the window graphics. Click on this link (http://www.htmlcodetutorial.com/linking/popup_test_a.html) and make sure the popup windows widgets are in the right place.
Review URL: http://codereview.chromium.org/273031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/browser_frame_view.mm | 12 | ||||
-rw-r--r-- | chrome/browser/cocoa/chrome_browser_window.h | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/chrome_browser_window.mm | 74 | ||||
-rw-r--r-- | chrome/browser/cocoa/chrome_browser_window_unittest.mm | 6 |
4 files changed, 60 insertions, 40 deletions
diff --git a/chrome/browser/cocoa/browser_frame_view.mm b/chrome/browser/cocoa/browser_frame_view.mm index 3cc4ddc..3a02617 100644 --- a/chrome/browser/cocoa/browser_frame_view.mm +++ b/chrome/browser/cocoa/browser_frame_view.mm @@ -96,15 +96,11 @@ static const NSInteger kBrowserFrameViewPatternPhaseOffset = 2; - (void)drawRect:(NSRect)rect { // If this isn't the window class we expect, then pass it on to the // original implementation. + [self drawRectOriginal:rect]; if (![[self window] isKindOfClass:[ChromeBrowserWindow class]]) { - [self drawRectOriginal:rect]; return; } - // Clear out everything - [[NSColor clearColor] set]; - NSRectFill(rect); - // Set up our clip NSWindow* window = [self window]; NSRect windowRect = [window frame]; @@ -119,7 +115,7 @@ static const NSInteger kBrowserFrameViewPatternPhaseOffset = 2; GTMTheme* theme = [self gtm_theme]; GTMThemeState state = [window isMainWindow] ? GTMThemeStateActiveWindow : GTMThemeStateInactiveWindow; - NSColor* color = [theme backgroundPatternColorForStyle:GTMThemeStyleWindow + NSColor* color = [theme backgroundPatternColorForStyle:GTMThemeStyleWindow state:state]; if (color) { // If we have a theme pattern, draw it here. @@ -128,8 +124,6 @@ static const NSInteger kBrowserFrameViewPatternPhaseOffset = 2; [[NSGraphicsContext currentContext] setPatternPhase:phase]; [color set]; NSRectFill(rect); - } else { - [self drawRectOriginal:rect]; } // Check to see if we have an overlay image. @@ -157,7 +151,7 @@ static const NSInteger kBrowserFrameViewPatternPhaseOffset = 2; ChromeBrowserWindow* window = static_cast<ChromeBrowserWindow*>([self window]); mouseInGroup = [window mouseInGroup:widget]; - } else { + } else if ([super respondsToSelector:@selector(_mouseInGroup:)]) { mouseInGroup = [super _mouseInGroup:widget]; } return mouseInGroup; diff --git a/chrome/browser/cocoa/chrome_browser_window.h b/chrome/browser/cocoa/chrome_browser_window.h index c25b489..f69978c 100644 --- a/chrome/browser/cocoa/chrome_browser_window.h +++ b/chrome/browser/cocoa/chrome_browser_window.h @@ -10,8 +10,12 @@ #include "base/scoped_nsobject.h" // Offset from the top of the window frame to the top of the window controls -// (zoom, close, miniaturize). -const NSInteger kChromeWindowButtonsOffsetFromTop = 7; +// (zoom, close, miniaturize) for a window with a tabstrip. +const NSInteger kChromeWindowButtonsWithTabStripOffsetFromTop = 6; + +// Offset from the top of the window frame to the top of the window controls +// (zoom, close, miniaturize) for a window without a tabstrip. +const NSInteger kChromeWindowButtonsWithoutTabStripOffsetFromTop = 4; // Offset from the left of the window frame to the top of the window controls // (zoom, close, miniaturize). diff --git a/chrome/browser/cocoa/chrome_browser_window.mm b/chrome/browser/cocoa/chrome_browser_window.mm index 6786cda..fdc34de 100644 --- a/chrome/browser/cocoa/chrome_browser_window.mm +++ b/chrome/browser/cocoa/chrome_browser_window.mm @@ -27,14 +27,31 @@ typedef int (*KeyToCommandMapper)(bool, bool, bool, int); @implementation ChromeBrowserWindow -- (id)initWithContentRect:(NSRect)contentRect - styleMask:(NSUInteger)aStyle - backing:(NSBackingStoreType)bufferingType - defer:(BOOL)flag { - if ((self = [super initWithContentRect:contentRect - styleMask:aStyle - backing:bufferingType - defer:flag])) { +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; +} + +- (void)setWindowController:(NSWindowController*)controller { + if (controller == [self windowController]) { + return; + } + // Clean up our old stuff. + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; + [closeButton_ removeFromSuperview]; + closeButton_ = nil; + [miniaturizeButton_ removeFromSuperview]; + miniaturizeButton_ = nil; + [zoomButton_ removeFromSuperview]; + zoomButton_ = nil; + + [super setWindowController:controller]; + + BrowserWindowController* browserController + = static_cast<BrowserWindowController*>(controller); + if ([browserController isKindOfClass:[BrowserWindowController class]]) { NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; [defaultCenter addObserver:self selector:@selector(themeDidChangeNotification:) @@ -49,7 +66,6 @@ typedef int (*KeyToCommandMapper)(bool, bool, bool, int); selector:@selector(systemThemeDidChangeNotification:) name:@"AppleAquaColorVariantChanged" object:nil]; - [self setOpaque:NO]; // Set up our buttons how we like them. NSView* frameView = [self frameView]; NSRect frameViewBounds = [frameView bounds]; @@ -66,14 +82,18 @@ typedef int (*KeyToCommandMapper)(bool, bool, bool, int); [oldButton setHidden:YES]; // Create and position our new buttons. + NSUInteger aStyle = [self styleMask]; closeButton_ = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:aStyle]; NSRect closeButtonFrame = [closeButton_ frame]; + CGFloat yOffset = [browserController isNormalWindow] ? + kChromeWindowButtonsWithTabStripOffsetFromTop : + kChromeWindowButtonsWithoutTabStripOffsetFromTop; closeButtonFrame.origin = NSMakePoint(kChromeWindowButtonsOffsetFromLeft, (NSHeight(frameViewBounds) - - NSHeight(closeButtonFrame) - - kChromeWindowButtonsOffsetFromTop)); + NSHeight(closeButtonFrame) - yOffset)); + [closeButton_ setFrame:closeButtonFrame]; [closeButton_ setTarget:self]; [closeButton_ setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; @@ -106,15 +126,12 @@ typedef int (*KeyToCommandMapper)(bool, bool, bool, int); NSViewMinYMargin)]; [frameView addSubview:zoomButton_]; - [self updateTrackingAreas]; } - return self; -} -- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; + // Update our tracking areas. We want to update them even if we haven't + // added buttons above as we need to remove the old tracking area. If the + // buttons aren't to be shown, updateTrackingAreas won't add new ones. + [self updateTrackingAreas]; } - (NSView*)frameView { @@ -168,15 +185,18 @@ typedef int (*KeyToCommandMapper)(bool, bool, bool, int); if (widgetTrackingArea_) { [frameView removeTrackingArea:widgetTrackingArea_]; } - NSRect trackingRect = [closeButton_ frame]; - trackingRect.size.width = NSMaxX([zoomButton_ frame]) - NSMinX(trackingRect); - widgetTrackingArea_.reset( - [[NSTrackingArea alloc] initWithRect:trackingRect - options:(NSTrackingMouseEnteredAndExited | - NSTrackingActiveAlways) - owner:self - userInfo:nil]); - [frameView addTrackingArea:widgetTrackingArea_]; + if (closeButton_) { + NSRect trackingRect = [closeButton_ frame]; + trackingRect.size.width = NSMaxX([zoomButton_ frame]) - + NSMinX(trackingRect); + widgetTrackingArea_.reset( + [[NSTrackingArea alloc] initWithRect:trackingRect + options:(NSTrackingMouseEnteredAndExited | + NSTrackingActiveAlways) + owner:self + userInfo:nil]); + [frameView addTrackingArea:widgetTrackingArea_]; + } } - (void)windowMainStatusChanged { diff --git a/chrome/browser/cocoa/chrome_browser_window_unittest.mm b/chrome/browser/cocoa/chrome_browser_window_unittest.mm index 77986df..aa5e162 100644 --- a/chrome/browser/cocoa/chrome_browser_window_unittest.mm +++ b/chrome/browser/cocoa/chrome_browser_window_unittest.mm @@ -153,7 +153,8 @@ TEST_F(ChromeBrowserWindowTest, WindowWidgetLocation) { NSRect windowBounds = [window_ frame]; windowBounds.origin = NSZeroPoint; EXPECT_EQ(NSMaxY(closeBoxFrame), - NSMaxY(windowBounds) - kChromeWindowButtonsOffsetFromTop); + NSMaxY(windowBounds) - + kChromeWindowButtonsWithTabStripOffsetFromTop); EXPECT_EQ(NSMinX(closeBoxFrame), kChromeWindowButtonsOffsetFromLeft); NSCell* miniaturizeCell = [window_ accessibilityAttributeValue: @@ -162,7 +163,8 @@ TEST_F(ChromeBrowserWindowTest, WindowWidgetLocation) { EXPECT_TRUE(miniaturizeControl); NSRect miniaturizeFrame = [miniaturizeControl frame]; EXPECT_EQ(NSMaxY(miniaturizeFrame), - NSMaxY(windowBounds) - kChromeWindowButtonsOffsetFromTop); + NSMaxY(windowBounds) - + kChromeWindowButtonsWithTabStripOffsetFromTop); EXPECT_EQ(NSMinX(miniaturizeFrame), NSMaxX(closeBoxFrame) + kChromeWindowButtonsInterButtonSpacing); } |