Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4604)

Unified Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.mm

Issue 2061353002: [Mac][Material Design] Fix regression with initial bookmark bar text. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initial changes Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.mm
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.mm
index eb1a0da06ebe12e0738607c2c49fab17830ed10d..fb1c88271cc29c748eb2a0c3f52102ce87ca26df 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.mm
@@ -17,14 +17,22 @@
#include "components/bookmarks/browser/bookmark_pasteboard_helper_mac.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "content/public/browser/user_metrics.h"
+#include "grit/theme_resources.h"
#import "third_party/mozilla/NSPasteboard+Utils.h"
#include "ui/base/clipboard/clipboard_util_mac.h"
+#import "ui/base/cocoa/nsgraphics_context_additions.h"
#import "ui/base/cocoa/nsview_additions.h"
using base::UserMetricsAction;
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
+@interface NSView (Private)
tapted 2016/06/15 02:09:04 nit: PrivateAPI? (Chrome has a few "Private" categ
+// Private Appkit API for hinting at the color appearing behind a transparent
+// view (allowing subpixel anti-aliasing to work correctly).
+- (void)setFontSmoothingBackgroundColor:(NSColor*)aColor;
+@end
+
@interface BookmarkBarView (Private)
- (void)themeDidChangeNotification:(NSNotification*)aNotification;
- (void)updateTheme:(const ui::ThemeProvider*)themeProvider;
@@ -99,12 +107,30 @@ using bookmarks::BookmarkNode;
// Adapt appearance to the current theme. Called after theme changes and before
// this is shown for the first time.
- (void)updateTheme:(const ui::ThemeProvider*)themeProvider {
+ // Undo any background color set for font smoothing.
+ if ([importBookmarksButton_ respondsToSelector:
+ @selector(setFontSmoothingBackgroundColor)]) {
tapted 2016/06/15 02:09:04 @selector(setFontSmoothingBackgroundColor:)? (miss
+ [importBookmarksButton_ setFontSmoothingBackgroundColor:nil];
+ [importBookmarksButton_ setNeedsDisplay:YES];
+ }
if (!themeProvider)
return;
NSColor* color =
themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
[noItemTextfield_ setTextColor:color];
+
+ // When not using a System theme, set the background color for font smoothing
+ // using a private API. The issue is that the |importBookmarksButton_|'s text
+ // is being drawn on a transparent background. Subpixel anti-aliasing needs
+ // to know the background color of the pixels the text is being drawn on top
+ // of - because the textfield is transparent, it can't know the color and so
+ // the anti-aliasing looks weird. This private API allows us to give the
+ // button a hint about the color of the background it will appear over.
+ if (!themeProvider->UsingSystemTheme()) {
+ [importBookmarksButton_ setFontSmoothingBackgroundColor:
tapted 2016/06/15 02:09:04 if (. respondsToSelector..)?
+ themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR)];
tapted 2016/06/15 02:09:04 I have no idea whether fontSmoothingBackgroundColo
+ }
}
// Mouse down events on the bookmark bar should not allow dragging the parent
@@ -297,6 +323,26 @@ using bookmarks::BookmarkNode;
return [barView_ menu];
}
+- (void)drawRect:(NSRect)dirtyRect {
+ const ui::ThemeProvider* themeProvider = [[self window] themeProvider];
+ // To allow subpixel anti-aliasing of the button's title to render correctly,
+ // draw the themed background before drawing the title.
+ if (themeProvider) {
+ bool active =
+ [[self window] isMainWindow] || !themeProvider->UsingSystemTheme();
+ int imageColorName = active ? IDR_THEME_TOOLBAR
+ : IDR_THEME_TOOLBAR_INACTIVE;
+ [themeProvider->GetNSImageColorNamed(imageColorName) set];
+ NSPoint position = [[self window]
+ themeImagePositionForAlignment:THEME_IMAGE_ALIGN_WITH_TAB_STRIP];
+ [[NSGraphicsContext currentContext] cr_setPatternPhase:position
+ forView:self];
+ NSRectFill(dirtyRect);
+ }
+
+ [super drawRect:dirtyRect];
+}
+
@end // @implementation BookmarkBarTextField
@implementation BookmarkBarItemContainer
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698