BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_bar_toolbar_view.mm
blob77d95d9031792e6e72a69ba6f130c6acceb16099
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;
23 @end
25 @implementation BookmarkBarToolbarView
27 - (BOOL)isOpaque {
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];
42   } else {
43     [self drawBackground:dirtyRect];
44   }
47 - (void)drawAsDetachedBubble:(NSRect)dirtyRect {
48   CGFloat morph = [controller_ detachedMorphProgress];
49   ThemeService* themeService = [controller_ themeService];
50   if (!themeService)
51     return;
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.
64   {
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);
72   }
74   // Bottom stroke.
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
81                                                        ofColor:strokeColor];
82     strokeColor = [strokeColor colorWithAlphaComponent:0.5];
83     [strokeColor set];
84     NSRectFillUsingOperation(NSIntersectionRect(strokeRect, dirtyRect),
85                              NSCompositeSourceOver);
86   }
89 @end  // @implementation BookmarkBarToolbarView