Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #import "chrome/browser/themes/theme_properties.h" | 8 #import "chrome/browser/themes/theme_properties.h" |
| 9 #import "chrome/browser/themes/theme_service.h" | 9 #import "chrome/browser/themes/theme_service.h" |
| 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
| 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_context_menu_cocoa_controlle r.h" | 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_context_menu_cocoa_controlle r.h" |
| 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
| 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 15 #import "chrome/browser/ui/cocoa/themed_window.h" | 15 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 16 #import "chrome/browser/ui/cocoa/view_id_util.h" | 16 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 17 #include "components/bookmarks/browser/bookmark_pasteboard_helper_mac.h" | 17 #include "components/bookmarks/browser/bookmark_pasteboard_helper_mac.h" |
| 18 #include "components/bookmarks/browser/bookmark_utils.h" | 18 #include "components/bookmarks/browser/bookmark_utils.h" |
| 19 #include "content/public/browser/user_metrics.h" | 19 #include "content/public/browser/user_metrics.h" |
| 20 #include "grit/theme_resources.h" | |
| 20 #import "third_party/mozilla/NSPasteboard+Utils.h" | 21 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 21 #include "ui/base/clipboard/clipboard_util_mac.h" | 22 #include "ui/base/clipboard/clipboard_util_mac.h" |
| 23 #import "ui/base/cocoa/nsgraphics_context_additions.h" | |
| 22 #import "ui/base/cocoa/nsview_additions.h" | 24 #import "ui/base/cocoa/nsview_additions.h" |
| 23 | 25 |
| 24 using base::UserMetricsAction; | 26 using base::UserMetricsAction; |
| 25 using bookmarks::BookmarkModel; | 27 using bookmarks::BookmarkModel; |
| 26 using bookmarks::BookmarkNode; | 28 using bookmarks::BookmarkNode; |
| 27 | 29 |
| 30 @interface NSView (Private) | |
|
tapted
2016/06/15 02:09:04
nit: PrivateAPI? (Chrome has a few "Private" categ
| |
| 31 // Private Appkit API for hinting at the color appearing behind a transparent | |
| 32 // view (allowing subpixel anti-aliasing to work correctly). | |
| 33 - (void)setFontSmoothingBackgroundColor:(NSColor*)aColor; | |
| 34 @end | |
| 35 | |
| 28 @interface BookmarkBarView (Private) | 36 @interface BookmarkBarView (Private) |
| 29 - (void)themeDidChangeNotification:(NSNotification*)aNotification; | 37 - (void)themeDidChangeNotification:(NSNotification*)aNotification; |
| 30 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider; | 38 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider; |
| 31 | 39 |
| 32 // NSView override. | 40 // NSView override. |
| 33 - (void)setFrameSize:(NSSize)size; | 41 - (void)setFrameSize:(NSSize)size; |
| 34 @end | 42 @end |
| 35 | 43 |
| 36 @implementation BookmarkBarView | 44 @implementation BookmarkBarView |
| 37 | 45 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 } | 100 } |
| 93 | 101 |
| 94 // Called after a theme change took place, possibly for a different profile. | 102 // Called after a theme change took place, possibly for a different profile. |
| 95 - (void)themeDidChangeNotification:(NSNotification*)notification { | 103 - (void)themeDidChangeNotification:(NSNotification*)notification { |
| 96 [self updateTheme:[[self window] themeProvider]]; | 104 [self updateTheme:[[self window] themeProvider]]; |
| 97 } | 105 } |
| 98 | 106 |
| 99 // Adapt appearance to the current theme. Called after theme changes and before | 107 // Adapt appearance to the current theme. Called after theme changes and before |
| 100 // this is shown for the first time. | 108 // this is shown for the first time. |
| 101 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider { | 109 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider { |
| 110 // Undo any background color set for font smoothing. | |
| 111 if ([importBookmarksButton_ respondsToSelector: | |
| 112 @selector(setFontSmoothingBackgroundColor)]) { | |
|
tapted
2016/06/15 02:09:04
@selector(setFontSmoothingBackgroundColor:)? (miss
| |
| 113 [importBookmarksButton_ setFontSmoothingBackgroundColor:nil]; | |
| 114 [importBookmarksButton_ setNeedsDisplay:YES]; | |
| 115 } | |
| 102 if (!themeProvider) | 116 if (!themeProvider) |
| 103 return; | 117 return; |
| 104 | 118 |
| 105 NSColor* color = | 119 NSColor* color = |
| 106 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT); | 120 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT); |
| 107 [noItemTextfield_ setTextColor:color]; | 121 [noItemTextfield_ setTextColor:color]; |
| 122 | |
| 123 // When not using a System theme, set the background color for font smoothing | |
| 124 // using a private API. The issue is that the |importBookmarksButton_|'s text | |
| 125 // is being drawn on a transparent background. Subpixel anti-aliasing needs | |
| 126 // to know the background color of the pixels the text is being drawn on top | |
| 127 // of - because the textfield is transparent, it can't know the color and so | |
| 128 // the anti-aliasing looks weird. This private API allows us to give the | |
| 129 // button a hint about the color of the background it will appear over. | |
| 130 if (!themeProvider->UsingSystemTheme()) { | |
| 131 [importBookmarksButton_ setFontSmoothingBackgroundColor: | |
|
tapted
2016/06/15 02:09:04
if (. respondsToSelector..)?
| |
| 132 themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR)]; | |
|
tapted
2016/06/15 02:09:04
I have no idea whether fontSmoothingBackgroundColo
| |
| 133 } | |
| 108 } | 134 } |
| 109 | 135 |
| 110 // Mouse down events on the bookmark bar should not allow dragging the parent | 136 // Mouse down events on the bookmark bar should not allow dragging the parent |
| 111 // window around. | 137 // window around. |
| 112 - (BOOL)mouseDownCanMoveWindow { | 138 - (BOOL)mouseDownCanMoveWindow { |
| 113 return NO; | 139 return NO; |
| 114 } | 140 } |
| 115 | 141 |
| 116 - (BookmarkBarTextField*)noItemTextfield { | 142 - (BookmarkBarTextField*)noItemTextfield { |
| 117 return noItemTextfield_; | 143 return noItemTextfield_; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 } | 316 } |
| 291 | 317 |
| 292 @end // @implementation BookmarkBarView | 318 @end // @implementation BookmarkBarView |
| 293 | 319 |
| 294 @implementation BookmarkBarTextField | 320 @implementation BookmarkBarTextField |
| 295 | 321 |
| 296 - (NSMenu*)menu { | 322 - (NSMenu*)menu { |
| 297 return [barView_ menu]; | 323 return [barView_ menu]; |
| 298 } | 324 } |
| 299 | 325 |
| 326 - (void)drawRect:(NSRect)dirtyRect { | |
| 327 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; | |
| 328 // To allow subpixel anti-aliasing of the button's title to render correctly, | |
| 329 // draw the themed background before drawing the title. | |
| 330 if (themeProvider) { | |
| 331 bool active = | |
| 332 [[self window] isMainWindow] || !themeProvider->UsingSystemTheme(); | |
| 333 int imageColorName = active ? IDR_THEME_TOOLBAR | |
| 334 : IDR_THEME_TOOLBAR_INACTIVE; | |
| 335 [themeProvider->GetNSImageColorNamed(imageColorName) set]; | |
| 336 NSPoint position = [[self window] | |
| 337 themeImagePositionForAlignment:THEME_IMAGE_ALIGN_WITH_TAB_STRIP]; | |
| 338 [[NSGraphicsContext currentContext] cr_setPatternPhase:position | |
| 339 forView:self]; | |
| 340 NSRectFill(dirtyRect); | |
| 341 } | |
| 342 | |
| 343 [super drawRect:dirtyRect]; | |
| 344 } | |
| 345 | |
| 300 @end // @implementation BookmarkBarTextField | 346 @end // @implementation BookmarkBarTextField |
| 301 | 347 |
| 302 @implementation BookmarkBarItemContainer | 348 @implementation BookmarkBarItemContainer |
| 303 | 349 |
| 304 - (NSMenu*)menu { | 350 - (NSMenu*)menu { |
| 305 return [barView_ menu]; | 351 return [barView_ menu]; |
| 306 } | 352 } |
| 307 | 353 |
| 308 @end // @implementation BookmarkBarItemContainer | 354 @end // @implementation BookmarkBarItemContainer |
| OLD | NEW |