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

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

Issue 6927058: Merge 83125 - Add and use gfx::ScopedNSGraphicsContextState (ui/gfx/scoped_ns_graphics_context_st... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/742/src/
Patch Set: Created 9 years, 7 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 | Annotate | Revision Log
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/ntp_background_util.h" 7 #include "chrome/browser/ntp_background_util.h"
8 #include "chrome/browser/themes/theme_service.h" 8 #include "chrome/browser/themes/theme_service.h"
9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.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/browser_window_controller.h" 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
12 #import "chrome/browser/ui/cocoa/themed_window.h" 12 #import "chrome/browser/ui/cocoa/themed_window.h"
13 #include "ui/base/theme_provider.h" 13 #include "ui/base/theme_provider.h"
14 #include "ui/gfx/canvas_skia_paint.h" 14 #include "ui/gfx/canvas_skia_paint.h"
15 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
16 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
16 17
17 const CGFloat kBorderRadius = 3.0; 18 const CGFloat kBorderRadius = 3.0;
18 19
19 @interface BookmarkBarToolbarView (Private) 20 @interface BookmarkBarToolbarView (Private)
20 - (void)drawRectAsBubble:(NSRect)rect; 21 - (void)drawRectAsBubble:(NSRect)rect;
21 @end 22 @end
22 23
23 @implementation BookmarkBarToolbarView 24 @implementation BookmarkBarToolbarView
24 25
25 - (BOOL)isOpaque { 26 - (BOOL)isOpaque {
(...skipping 23 matching lines...) Expand all
49 // to morph the bubble to a regular bar (shape and colour). 50 // to morph the bubble to a regular bar (shape and colour).
50 CGFloat morph = [controller_ detachedMorphProgress]; 51 CGFloat morph = [controller_ detachedMorphProgress];
51 52
52 NSRect bounds = [self bounds]; 53 NSRect bounds = [self bounds];
53 54
54 ui::ThemeProvider* themeProvider = [controller_ themeProvider]; 55 ui::ThemeProvider* themeProvider = [controller_ themeProvider];
55 if (!themeProvider) 56 if (!themeProvider)
56 return; 57 return;
57 58
58 NSGraphicsContext* context = [NSGraphicsContext currentContext]; 59 NSGraphicsContext* context = [NSGraphicsContext currentContext];
59 [context saveGraphicsState]; 60 gfx::ScopedNSGraphicsContextSaveGState scopedGState(context);
60 61
61 // Draw the background. 62 // Draw the background.
62 { 63 {
63 // CanvasSkiaPaint draws to the NSGraphicsContext during its destructor, so 64 // CanvasSkiaPaint draws to the NSGraphicsContext during its destructor, so
64 // explicitly scope this. 65 // explicitly scope this.
65 // 66 //
66 // Paint the entire bookmark bar, even if the damage rect is much smaller 67 // Paint the entire bookmark bar, even if the damage rect is much smaller
67 // because PaintBackgroundDetachedMode() assumes that area's origin is 68 // because PaintBackgroundDetachedMode() assumes that area's origin is
68 // (0, 0) and that its size is the size of the bookmark bar. 69 // (0, 0) and that its size is the size of the bookmark bar.
69 // 70 //
(...skipping 24 matching lines...) Expand all
94 yRadius:(morph * kBorderRadius)]; 95 yRadius:(morph * kBorderRadius)];
95 96
96 // Draw the rounded rectangle. 97 // Draw the rounded rectangle.
97 NSColor* toolbarColor = 98 NSColor* toolbarColor =
98 themeProvider->GetNSColor(ThemeService::COLOR_TOOLBAR, true); 99 themeProvider->GetNSColor(ThemeService::COLOR_TOOLBAR, true);
99 CGFloat alpha = morph * [toolbarColor alphaComponent]; 100 CGFloat alpha = morph * [toolbarColor alphaComponent];
100 [[toolbarColor colorWithAlphaComponent:alpha] set]; // Set with opacity. 101 [[toolbarColor colorWithAlphaComponent:alpha] set]; // Set with opacity.
101 [border fill]; 102 [border fill];
102 103
103 // Fade in/out the background. 104 // Fade in/out the background.
104 [context saveGraphicsState]; 105 {
105 [border setClip]; 106 gfx::ScopedNSGraphicsContextSaveGState bgScopedState(context);
106 CGContextRef cgContext = (CGContextRef)[context graphicsPort]; 107 [border setClip];
107 CGContextBeginTransparencyLayer(cgContext, NULL); 108 CGContextRef cgContext = (CGContextRef)[context graphicsPort];
108 CGContextSetAlpha(cgContext, 1 - morph); 109 CGContextBeginTransparencyLayer(cgContext, NULL);
109 [context setPatternPhase:[[self window] themePatternPhase]]; 110 CGContextSetAlpha(cgContext, 1 - morph);
110 [self drawBackground]; 111 [context setPatternPhase:[[self window] themePatternPhase]];
111 CGContextEndTransparencyLayer(cgContext); 112 [self drawBackground];
112 [context restoreGraphicsState]; 113 CGContextEndTransparencyLayer(cgContext);
114 }
113 115
114 // Draw the border of the rounded rectangle. 116 // Draw the border of the rounded rectangle.
115 NSColor* borderColor = themeProvider->GetNSColor( 117 NSColor* borderColor = themeProvider->GetNSColor(
116 ThemeService::COLOR_TOOLBAR_BUTTON_STROKE, true); 118 ThemeService::COLOR_TOOLBAR_BUTTON_STROKE, true);
117 alpha = morph * [borderColor alphaComponent]; 119 alpha = morph * [borderColor alphaComponent];
118 [[borderColor colorWithAlphaComponent:alpha] set]; // Set with opacity. 120 [[borderColor colorWithAlphaComponent:alpha] set]; // Set with opacity.
119 [border stroke]; 121 [border stroke];
120 122
121 // Fade in/out the divider. 123 // Fade in/out the divider.
122 // TODO(viettrungluu): It's not obvious that this divider lines up exactly 124 // TODO(viettrungluu): It's not obvious that this divider lines up exactly
123 // with |BackgroundGradientView|'s (in fact, it probably doesn't). 125 // with |BackgroundGradientView|'s (in fact, it probably doesn't).
124 NSColor* strokeColor = [self strokeColor]; 126 NSColor* strokeColor = [self strokeColor];
125 alpha = (1 - morph) * [strokeColor alphaComponent]; 127 alpha = (1 - morph) * [strokeColor alphaComponent];
126 [[strokeColor colorWithAlphaComponent:alpha] set]; 128 [[strokeColor colorWithAlphaComponent:alpha] set];
127 NSBezierPath* divider = [NSBezierPath bezierPath]; 129 NSBezierPath* divider = [NSBezierPath bezierPath];
128 NSPoint dividerStart = 130 NSPoint dividerStart =
129 NSMakePoint(morph * bookmarks::kNTPBookmarkBarPadding + morph * 0.5, 131 NSMakePoint(morph * bookmarks::kNTPBookmarkBarPadding + morph * 0.5,
130 morph * bookmarks::kNTPBookmarkBarPadding + morph * 0.5); 132 morph * bookmarks::kNTPBookmarkBarPadding + morph * 0.5);
131 CGFloat dividerWidth = 133 CGFloat dividerWidth =
132 NSWidth(bounds) - 2 * morph * bookmarks::kNTPBookmarkBarPadding - 2 * 0.5; 134 NSWidth(bounds) - 2 * morph * bookmarks::kNTPBookmarkBarPadding - 2 * 0.5;
133 [divider moveToPoint:dividerStart]; 135 [divider moveToPoint:dividerStart];
134 [divider relativeLineToPoint:NSMakePoint(dividerWidth, 0)]; 136 [divider relativeLineToPoint:NSMakePoint(dividerWidth, 0)];
135 [divider stroke]; 137 [divider stroke];
136
137 // Restore the graphics context.
138 [context restoreGraphicsState];
139 } 138 }
140 139
141 @end // @implementation BookmarkBarToolbarView 140 @end // @implementation BookmarkBarToolbarView
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_mac.mm ('k') | chrome/browser/ui/cocoa/browser_window_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698