diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-09 22:51:53 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-09 22:51:53 +0000 |
commit | cfee77b14ffaaa57961b19c293b8cfe0659b5386 (patch) | |
tree | 7b944b22877e65d92880ae1b9a1bcdf4a84ac5f5 /chrome/browser | |
parent | 5064ec7fdc132b608f1a96e7d8daeb9a4ccdc235 (diff) | |
download | chromium_src-cfee77b14ffaaa57961b19c293b8cfe0659b5386.zip chromium_src-cfee77b14ffaaa57961b19c293b8cfe0659b5386.tar.gz chromium_src-cfee77b14ffaaa57961b19c293b8cfe0659b5386.tar.bz2 |
Fix theming on popup windows (Mac).
BUG=http://crbug.com/37690
TEST=as in comment 3 on the bug
Review URL: http://codereview.chromium.org/729002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41084 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/cocoa/browser_frame_view.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_frame_view.mm | 71 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.h | 7 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 15 | ||||
-rw-r--r-- | chrome/browser/cocoa/chrome_browser_window.h | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/chrome_browser_window.mm | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/fullscreen_window.mm | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_window_controller.mm | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/themed_window.h | 11 | ||||
-rw-r--r-- | chrome/browser/cocoa/themed_window.mm | 4 |
10 files changed, 107 insertions, 20 deletions
diff --git a/chrome/browser/cocoa/browser_frame_view.h b/chrome/browser/cocoa/browser_frame_view.h index ebee82c..6505dfb 100644 --- a/chrome/browser/cocoa/browser_frame_view.h +++ b/chrome/browser/cocoa/browser_frame_view.h @@ -57,4 +57,7 @@ forView:(NSView*)view bounds:(NSRect)bounds; +// Gets the color to draw title text. ++ (NSColor*)titleColorForThemeView:(NSView*)view; + @end diff --git a/chrome/browser/cocoa/browser_frame_view.mm b/chrome/browser/cocoa/browser_frame_view.mm index 3189acf..01d2528 100644 --- a/chrome/browser/cocoa/browser_frame_view.mm +++ b/chrome/browser/cocoa/browser_frame_view.mm @@ -17,12 +17,23 @@ static const CGFloat kBrowserFrameViewPaintHeight = 60.0; static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 3 }; +static BOOL gCanDrawTitle = NO; + @interface NSView (Swizzles) - (void)drawRectOriginal:(NSRect)rect; - (BOOL)_mouseInGroup:(NSButton*)widget; - (void)updateTrackingAreas; @end +// Undocumented APIs. They are really on NSGrayFrame rather than +// BrowserFrameView, but we call them from methods swizzled onto NSGrayFrame. +@interface BrowserFrameView (UndocumentedAPI) + +- (CGRect)_titlebarTitleRect; +- (void)_drawTitleStringIn:(struct CGRect)arg1 withColor:(id)color; + +@end + @implementation BrowserFrameView + (void)load { @@ -76,6 +87,12 @@ static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 3 }; method_getTypeEncoding(m0)); DCHECK(didAdd); } + + gCanDrawTitle = + [grayFrameClass + instancesRespondToSelector:@selector(_titlebarTitleRect)] && + [grayFrameClass + instancesRespondToSelector:@selector(_drawTitleStringIn:withColor:)]; } - (id)initWithFrame:(NSRect)frame { @@ -128,6 +145,13 @@ static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 3 }; forView:self bounds:windowRect]; + // If the window needs a title and we painted over the title as drawn by the + // default window paint, paint it ourselves. + if (themed && gCanDrawTitle && ![[self window] _isTitleHidden]) { + [self _drawTitleStringIn:[self _titlebarTitleRect] + withColor:[BrowserFrameView titleColorForThemeView:self]]; + } + // Pinstripe the top. if (themed) { windowRect = [window frame]; @@ -151,17 +175,28 @@ static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 3 }; if (!themeProvider) return NO; + ThemedWindowStyle windowStyle = [[view window] themedWindowStyle]; + + // Devtools windows don't get themed. + if (windowStyle & THEMED_DEVTOOLS) + return NO; + BOOL active = [[view window] isMainWindow]; - BOOL incognito = [[view window] themeIsIncognito]; + BOOL incognito = windowStyle & THEMED_INCOGNITO; + BOOL popup = windowStyle & THEMED_POPUP; // Find a theme image. NSColor* themeImageColor = nil; int themeImageID; - if (active && incognito) + if (popup && active) + themeImageID = IDR_THEME_TOOLBAR; + else if (popup && !active) + themeImageID = IDR_THEME_TAB_BACKGROUND; + else if (!popup && active && incognito) themeImageID = IDR_THEME_FRAME_INCOGNITO; - else if (active && !incognito) + else if (!popup && active && !incognito) themeImageID = IDR_THEME_FRAME; - else if (!active && incognito) + else if (!popup && !active && incognito) themeImageID = IDR_THEME_FRAME_INCOGNITO_INACTIVE; else themeImageID = IDR_THEME_FRAME_INACTIVE; @@ -222,6 +257,34 @@ static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 3 }; return themed; } ++ (NSColor*)titleColorForThemeView:(NSView*)view { + ThemeProvider* themeProvider = [[view window] themeProvider]; + if (!themeProvider) + return [NSColor windowFrameTextColor]; + + ThemedWindowStyle windowStyle = [[view window] themedWindowStyle]; + BOOL active = [[view window] isMainWindow]; + BOOL incognito = windowStyle & THEMED_INCOGNITO; + BOOL popup = windowStyle & THEMED_POPUP; + + NSColor* titleColor = nil; + if (popup && active) { + titleColor = themeProvider->GetNSColor( + BrowserThemeProvider::COLOR_TAB_TEXT, false); + } else if (popup && !active) { + titleColor = themeProvider->GetNSColor( + BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT, false); + } + + if (titleColor) + return titleColor; + + if (incognito) + return [NSColor whiteColor]; + else + return [NSColor windowFrameTextColor]; +} + // Check to see if the mouse is currently in one of our window widgets. - (BOOL)_mouseInGroup:(NSButton*)widget { BOOL mouseInGroup = NO; diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index 64b9696..bbab2ee 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -14,10 +14,11 @@ #include "base/scoped_nsobject.h" #include "base/scoped_ptr.h" -#import "chrome/browser/cocoa/tab_window_controller.h" #import "chrome/browser/cocoa/bookmark_bar_controller.h" #import "chrome/browser/cocoa/bookmark_bubble_controller.h" #import "chrome/browser/cocoa/browser_command_executor.h" +#import "chrome/browser/cocoa/tab_window_controller.h" +#import "chrome/browser/cocoa/themed_window.h" #import "chrome/browser/cocoa/url_drop_target.h" #import "chrome/browser/cocoa/view_resizer.h" #include "chrome/browser/sync/sync_ui_util.h" @@ -236,8 +237,8 @@ class TabStripModelObserverBridge; // Gets the current theme provider. - (ThemeProvider*)themeProvider; -// Gets whether the current theme is incognito. -- (BOOL)themeIsIncognito; +// Gets the window style. +- (ThemedWindowStyle)themedWindowStyle; // Gets the pattern phase for the window. - (NSPoint)themePatternPhase; diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index de01113..ef46709 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -44,7 +44,6 @@ #import "chrome/browser/cocoa/tab_strip_controller.h" #import "chrome/browser/cocoa/tab_strip_view.h" #import "chrome/browser/cocoa/tab_view.h" -#import "chrome/browser/cocoa/themed_window.h" #import "chrome/browser/cocoa/toolbar_controller.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/sync/profile_sync_service.h" @@ -1313,8 +1312,18 @@ return browser_->profile()->GetThemeProvider(); } -- (BOOL)themeIsIncognito { - return browser_->profile()->IsOffTheRecord(); +- (ThemedWindowStyle)themedWindowStyle { + ThemedWindowStyle style = 0; + if (browser_->profile()->IsOffTheRecord()) + style |= THEMED_INCOGNITO; + + Browser::Type type = browser_->type(); + if (type == Browser::TYPE_POPUP) + style |= THEMED_POPUP; + else if (type == Browser::TYPE_DEVTOOLS) + style |= THEMED_DEVTOOLS; + + return style; } - (NSPoint)themePatternPhase { diff --git a/chrome/browser/cocoa/chrome_browser_window.h b/chrome/browser/cocoa/chrome_browser_window.h index 19a846f..ca2f439 100644 --- a/chrome/browser/cocoa/chrome_browser_window.h +++ b/chrome/browser/cocoa/chrome_browser_window.h @@ -51,7 +51,7 @@ const NSInteger kChromeWindowButtonsInterButtonSpacing = 7; @end -@interface ChromeBrowserWindow (UndocumentedAPI) +@interface NSWindow (UndocumentedAPI) // Undocumented Cocoa API to suppress drawing of the window's title. // -setTitle: still works, but the title set only applies to the diff --git a/chrome/browser/cocoa/chrome_browser_window.mm b/chrome/browser/cocoa/chrome_browser_window.mm index 7e22b5b..a09f884 100644 --- a/chrome/browser/cocoa/chrome_browser_window.mm +++ b/chrome/browser/cocoa/chrome_browser_window.mm @@ -347,8 +347,8 @@ namespace { return [[self windowController] themeProvider]; } -- (BOOL)themeIsIncognito { - return [[self windowController] themeIsIncognito]; +- (ThemedWindowStyle)themedWindowStyle { + return [[self windowController] themedWindowStyle]; } - (NSPoint)themePatternPhase { diff --git a/chrome/browser/cocoa/fullscreen_window.mm b/chrome/browser/cocoa/fullscreen_window.mm index cd0b656..bcc4d93 100644 --- a/chrome/browser/cocoa/fullscreen_window.mm +++ b/chrome/browser/cocoa/fullscreen_window.mm @@ -6,6 +6,7 @@ #include "base/mac_util.h" #include "chrome/browser/browser_theme_provider.h" +#import "chrome/browser/cocoa/themed_window.h" @implementation FullscreenWindow @@ -82,8 +83,8 @@ return [[self windowController] themeProvider]; } -- (BOOL)themeIsIncognito { - return [[self windowController] themeIsIncognito]; +- (ThemedWindowStyle)themedWindowStyle { + return [[self windowController] themedWindowStyle]; } - (NSPoint)themePatternPhase { diff --git a/chrome/browser/cocoa/tab_window_controller.mm b/chrome/browser/cocoa/tab_window_controller.mm index e2cd931..17fe56a 100644 --- a/chrome/browser/cocoa/tab_window_controller.mm +++ b/chrome/browser/cocoa/tab_window_controller.mm @@ -7,6 +7,7 @@ #include "app/theme_provider.h" #include "base/logging.h" #import "chrome/browser/cocoa/tab_strip_view.h" +#import "chrome/browser/cocoa/themed_window.h" @interface TabWindowController(PRIVATE) - (void)setUseOverlay:(BOOL)useOverlay; @@ -23,9 +24,9 @@ return NULL; } -- (BOOL)themeIsIncognito { +- (ThemedWindowStyle)themedWindowStyle { if ([self parentWindow]) - return [[[self parentWindow] windowController] themeIsIncognito]; + return [[[self parentWindow] windowController] themedWindowStyle]; return NO; } diff --git a/chrome/browser/cocoa/themed_window.h b/chrome/browser/cocoa/themed_window.h index affd452..c1b4a31 100644 --- a/chrome/browser/cocoa/themed_window.h +++ b/chrome/browser/cocoa/themed_window.h @@ -9,11 +9,20 @@ class ThemeProvider; +// Bit flags; mix-and-match as necessary. +enum { + THEMED_NORMAL = 0, + THEMED_INCOGNITO = 1 << 0, + THEMED_POPUP = 1 << 1, + THEMED_DEVTOOLS = 1 << 2 +}; +typedef NSUInteger ThemedWindowStyle; + // Implemented by windows that support theming. @interface NSWindow (ThemeProvider) - (ThemeProvider*)themeProvider; -- (BOOL)themeIsIncognito; +- (ThemedWindowStyle)themedWindowStyle; - (NSPoint)themePatternPhase; @end diff --git a/chrome/browser/cocoa/themed_window.mm b/chrome/browser/cocoa/themed_window.mm index 141f3e4..bde4057 100644 --- a/chrome/browser/cocoa/themed_window.mm +++ b/chrome/browser/cocoa/themed_window.mm @@ -12,8 +12,8 @@ return NULL; } -- (BOOL)themeIsIncognito { - return NO; +- (ThemedWindowStyle)themedWindowStyle { + return THEMED_NORMAL; } - (NSPoint)themePatternPhase { |