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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h"
7 #include "chrome/browser/search/search.h"
8 #include "chrome/browser/themes/theme_properties.h"
9 #include "chrome/browser/themes/theme_service.h"
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h"
11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
12 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
13 #include "chrome/browser/ui/search/search_ui.h"
14 #include "skia/ext/skia_utils_mac.h"
15 #import "ui/base/cocoa/nsview_additions.h"
16 #include "ui/base/theme_provider.h"
17 #include "ui/gfx/canvas_skia_paint.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
21 @interface BookmarkBarToolbarView (Private)
22 - (void)drawAsDetachedBubble:(NSRect)dirtyRect;
25 @implementation BookmarkBarToolbarView
28 return [controller_ isInState:BookmarkBar::DETACHED];
31 - (void)resetCursorRects {
32 NSCursor *arrow = [NSCursor arrowCursor];
33 [self addCursorRect:[self visibleRect] cursor:arrow];
34 [arrow setOnMouseEntered:YES];
37 - (void)drawRect:(NSRect)dirtyRect {
38 if ([controller_ isInState:BookmarkBar::DETACHED] ||
39 [controller_ isAnimatingToState:BookmarkBar::DETACHED] ||
40 [controller_ isAnimatingFromState:BookmarkBar::DETACHED]) {
41 [self drawAsDetachedBubble:dirtyRect];
43 [self drawBackground:dirtyRect];
47 - (void)drawAsDetachedBubble:(NSRect)dirtyRect {
48 CGFloat morph = [controller_ detachedMorphProgress];
49 ThemeService* themeService = [controller_ themeService];
53 [[NSColor whiteColor] set];
54 NSRectFill(dirtyRect);
56 // Overlay with a lighter background color.
57 NSColor* toolbarColor = gfx::SkColorToCalibratedNSColor(
58 chrome::GetDetachedBookmarkBarBackgroundColor(themeService));
59 CGFloat alpha = morph * [toolbarColor alphaComponent];
60 [[toolbarColor colorWithAlphaComponent:alpha] set];
61 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
63 // Fade in/out the background.
65 gfx::ScopedNSGraphicsContextSaveGState bgScopedState;
66 NSGraphicsContext* context = [NSGraphicsContext currentContext];
67 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]);
68 CGContextSetAlpha(cgContext, 1 - morph);
69 CGContextBeginTransparencyLayer(cgContext, NULL);
70 [self drawBackground:dirtyRect];
71 CGContextEndTransparencyLayer(cgContext);
75 NSRect strokeRect = [self bounds];
76 strokeRect.size.height = [self cr_lineWidth];
77 if (NSIntersectsRect(strokeRect, dirtyRect)) {
78 NSColor* strokeColor = gfx::SkColorToCalibratedNSColor(
79 chrome::GetDetachedBookmarkBarSeparatorColor(themeService));
80 strokeColor = [[self strokeColor] blendedColorWithFraction:morph
82 strokeColor = [strokeColor colorWithAlphaComponent:0.5];
84 NSRectFillUsingOperation(NSIntersectionRect(strokeRect, dirtyRect),
85 NSCompositeSourceOver);
89 @end // @implementation BookmarkBarToolbarView