[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_bar_toolbar_view.mm
blob2cdc5fde3ca80f75dd8a89b8a20b1268b9c4c11a
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 #import "chrome/browser/ui/cocoa/nsview_additions.h"
14 #import "chrome/browser/ui/cocoa/themed_window.h"
15 #include "chrome/browser/ui/ntp_background_util.h"
16 #include "chrome/browser/ui/search/search_ui.h"
17 #include "grit/theme_resources.h"
18 #include "skia/ext/skia_utils_mac.h"
19 #import "ui/base/cocoa/nsgraphics_context_additions.h"
20 #include "ui/base/theme_provider.h"
21 #include "ui/gfx/canvas_skia_paint.h"
22 #include "ui/gfx/rect.h"
23 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
25 @interface BookmarkBarToolbarView (Private)
26 - (void)drawAsDetachedBubble;
27 @end
29 @implementation BookmarkBarToolbarView
31 - (BOOL)isOpaque {
32   return [controller_ isInState:BookmarkBar::DETACHED];
35 - (void)resetCursorRects {
36   NSCursor *arrow = [NSCursor arrowCursor];
37   [self addCursorRect:[self visibleRect] cursor:arrow];
38   [arrow setOnMouseEntered:YES];
41 - (void)drawRect:(NSRect)rect {
42   if ([controller_ isInState:BookmarkBar::DETACHED] ||
43       [controller_ isAnimatingToState:BookmarkBar::DETACHED] ||
44       [controller_ isAnimatingFromState:BookmarkBar::DETACHED]) {
45     [self drawAsDetachedBubble];
46   } else {
47     NSPoint position = [[self window]
48         themeImagePositionForAlignment:THEME_IMAGE_ALIGN_WITH_TAB_STRIP];
49     [[NSGraphicsContext currentContext]
50         cr_setPatternPhase:position
51                    forView:[self cr_viewBeingDrawnTo]];
52     [self drawBackgroundWithOpaque:YES];
53   }
56 - (void)drawAsDetachedBubble {
57   CGFloat morph = [controller_ detachedMorphProgress];
58   NSRect bounds = [self bounds];
59   ThemeService* themeService = [controller_ themeService];
60   if (!themeService)
61     return;
63   [[NSColor whiteColor] set];
64   NSRectFill([self bounds]);
66   // Overlay with a lighter background color.
67   NSColor* toolbarColor = gfx::SkColorToCalibratedNSColor(
68         chrome::GetDetachedBookmarkBarBackgroundColor(themeService));
69   CGFloat alpha = morph * [toolbarColor alphaComponent];
70   [[toolbarColor colorWithAlphaComponent:alpha] set];
71   NSRectFillUsingOperation(bounds, NSCompositeSourceOver);
73   // Fade in/out the background.
74   {
75     gfx::ScopedNSGraphicsContextSaveGState bgScopedState;
76     NSGraphicsContext* context = [NSGraphicsContext currentContext];
77     CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]);
78     CGContextSetAlpha(cgContext, 1 - morph);
79     CGContextBeginTransparencyLayer(cgContext, NULL);
80     NSPoint position = [[self window]
81         themeImagePositionForAlignment:THEME_IMAGE_ALIGN_WITH_TAB_STRIP];
82     [context cr_setPatternPhase:position forView:[self cr_viewBeingDrawnTo]];
83     [self drawBackgroundWithOpaque:YES];
84     CGContextEndTransparencyLayer(cgContext);
85   }
87   // Bottom stroke.
88   NSColor* strokeColor = gfx::SkColorToCalibratedNSColor(
89         chrome::GetDetachedBookmarkBarSeparatorColor(themeService));
90   strokeColor = [[self strokeColor] blendedColorWithFraction:morph
91                                                      ofColor:strokeColor];
92   strokeColor = [strokeColor colorWithAlphaComponent:0.5];
93   [strokeColor set];
94   NSRect strokeRect = bounds;
95   strokeRect.size.height = [self cr_lineWidth];
96   NSRectFillUsingOperation(strokeRect, NSCompositeSourceOver);
99 @end  // @implementation BookmarkBarToolbarView