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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm

Issue 2336453002: BackgroundGradientView: -drawBackground: → -drawRect: (Closed)
Patch Set: Put this back. Created 4 years, 3 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 unified diff | Download patch
OLDNEW
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_toolbar_view.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h"
6 6
7 #include "chrome/browser/search/search.h" 7 #include "chrome/browser/search/search.h"
8 #include "chrome/browser/themes/theme_properties.h" 8 #include "chrome/browser/themes/theme_properties.h"
9 #include "chrome/browser/themes/theme_service.h" 9 #include "chrome/browser/themes/theme_service.h"
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h"
11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
13 #include "skia/ext/skia_utils_mac.h" 13 #include "skia/ext/skia_utils_mac.h"
14 #import "ui/base/cocoa/nsview_additions.h" 14 #import "ui/base/cocoa/nsview_additions.h"
15 #include "ui/base/theme_provider.h" 15 #include "ui/base/theme_provider.h"
16 #include "ui/gfx/canvas_skia_paint.h" 16 #include "ui/gfx/canvas_skia_paint.h"
17 #include "ui/gfx/geometry/rect.h" 17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 18 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
19 19
20 @interface BookmarkBarToolbarView (Private) 20 @interface BookmarkBarToolbarView (Private)
21 - (void)drawAsDetachedBubble:(NSRect)dirtyRect; 21 - (void)drawAsDetachedBubble:(NSRect)dirtyRect;
22 @end 22 @end
23 23
24 @implementation BookmarkBarToolbarView 24 @implementation BookmarkBarToolbarView
25 25
26 - (BOOL)isOpaque { 26 - (BOOL)isOpaque {
27 // -drawRect: calls -drawAsDetachedBubble: or -drawBackground:, both of which 27 // -drawRect: calls -drawAsDetachedBubble: or -[super drawRect:], both of
28 // fill the dirty rect with an opaque color. 28 // which fill the dirty rect with an opaque color.
29 return YES; 29 return YES;
30 } 30 }
31 31
32 - (void)resetCursorRects { 32 - (void)resetCursorRects {
33 NSCursor *arrow = [NSCursor arrowCursor]; 33 NSCursor *arrow = [NSCursor arrowCursor];
34 [self addCursorRect:[self visibleRect] cursor:arrow]; 34 [self addCursorRect:[self visibleRect] cursor:arrow];
35 [arrow setOnMouseEntered:YES]; 35 [arrow setOnMouseEntered:YES];
36 } 36 }
37 37
38 - (void)drawRect:(NSRect)dirtyRect { 38 - (void)drawRect:(NSRect)dirtyRect {
39 if ([controller_ isInState:BookmarkBar::DETACHED] || 39 if ([controller_ isInState:BookmarkBar::DETACHED] ||
40 [controller_ isAnimatingToState:BookmarkBar::DETACHED] || 40 [controller_ isAnimatingToState:BookmarkBar::DETACHED] ||
41 [controller_ isAnimatingFromState:BookmarkBar::DETACHED]) { 41 [controller_ isAnimatingFromState:BookmarkBar::DETACHED]) {
42 [self drawAsDetachedBubble:dirtyRect]; 42 [self drawAsDetachedBubble:dirtyRect];
43 } else { 43 } else {
44 [self drawBackground:dirtyRect]; 44 [super drawRect:dirtyRect];
45 } 45 }
46 } 46 }
47 47
48 - (void)drawAsDetachedBubble:(NSRect)dirtyRect { 48 - (void)drawAsDetachedBubble:(NSRect)dirtyRect {
49 CGFloat morph = [controller_ detachedMorphProgress]; 49 CGFloat morph = [controller_ detachedMorphProgress];
50 Profile* profile = [controller_ profile]; 50 Profile* profile = [controller_ profile];
51 if (!profile) 51 if (!profile)
52 return; 52 return;
53 53
54 [[NSColor whiteColor] set]; 54 [[NSColor whiteColor] set];
55 NSRectFill(dirtyRect); 55 NSRectFill(dirtyRect);
56 56
57 // Overlay with a lighter background color. 57 // Overlay with a lighter background color.
58 const ui::ThemeProvider& tp = 58 const ui::ThemeProvider& tp =
59 ThemeService::GetThemeProviderForProfile(profile); 59 ThemeService::GetThemeProviderForProfile(profile);
60 NSColor* toolbarColor = 60 NSColor* toolbarColor =
61 tp.GetNSColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND); 61 tp.GetNSColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND);
62 CGFloat alpha = morph * [toolbarColor alphaComponent]; 62 CGFloat alpha = morph * [toolbarColor alphaComponent];
63 [[toolbarColor colorWithAlphaComponent:alpha] set]; 63 [[toolbarColor colorWithAlphaComponent:alpha] set];
64 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); 64 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
65 65
66 // Fade in/out the background. 66 // Fade in/out the background.
67 { 67 {
68 gfx::ScopedNSGraphicsContextSaveGState bgScopedState; 68 gfx::ScopedNSGraphicsContextSaveGState bgScopedState;
69 NSGraphicsContext* context = [NSGraphicsContext currentContext]; 69 NSGraphicsContext* context = [NSGraphicsContext currentContext];
70 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]); 70 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]);
71 CGContextSetAlpha(cgContext, 1 - morph); 71 CGContextSetAlpha(cgContext, 1 - morph);
72 CGContextBeginTransparencyLayer(cgContext, NULL); 72 CGContextBeginTransparencyLayer(cgContext, NULL);
73 [self drawBackground:dirtyRect]; 73 [super drawRect:dirtyRect];
74 CGContextEndTransparencyLayer(cgContext); 74 CGContextEndTransparencyLayer(cgContext);
75 } 75 }
76 76
77 // Bottom stroke. 77 // Bottom stroke.
78 NSRect strokeRect = [self bounds]; 78 NSRect strokeRect = [self bounds];
79 strokeRect.size.height = [self cr_lineWidth]; 79 strokeRect.size.height = [self cr_lineWidth];
80 if (NSIntersectsRect(strokeRect, dirtyRect)) { 80 if (NSIntersectsRect(strokeRect, dirtyRect)) {
81 NSColor* strokeColor = 81 NSColor* strokeColor =
82 tp.GetNSColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR); 82 tp.GetNSColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR);
83 strokeColor = [[self strokeColor] blendedColorWithFraction:morph 83 strokeColor = [[self strokeColor] blendedColorWithFraction:morph
84 ofColor:strokeColor]; 84 ofColor:strokeColor];
85 strokeColor = [strokeColor colorWithAlphaComponent:0.5]; 85 strokeColor = [strokeColor colorWithAlphaComponent:0.5];
86 [strokeColor set]; 86 [strokeColor set];
87 NSRectFillUsingOperation(NSIntersectionRect(strokeRect, dirtyRect), 87 NSRectFillUsingOperation(NSIntersectionRect(strokeRect, dirtyRect),
88 NSCompositeSourceOver); 88 NSCompositeSourceOver);
89 } 89 }
90 } 90 }
91 91
92 @end // @implementation BookmarkBarToolbarView 92 @end // @implementation BookmarkBarToolbarView
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698