1 // Copyright 2013 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/autofill/autofill_section_view.h"
7 #import "chrome/browser/ui/chrome_style.h"
8 #include "skia/ext/skia_utils_mac.h"
12 // Slight shading for mouse hover.
13 SkColor kShadingColor = 0x07000000; // SkColorSetARGB(7, 0, 0, 0);
17 @implementation AutofillSectionView
19 @synthesize clickTarget = clickTarget_;
20 @synthesize shouldHighlightOnHover = shouldHighlightOnHover_;
21 @synthesize isHighlighted = isHighlighted_;
23 - (void)mouseEvent:(NSEvent*)event {
24 if ([event type] == NSMouseExited)
25 [self setIsHighlighted:NO];
26 else if ([event type] == NSMouseEntered)
27 [self setIsHighlighted:YES];
28 else if ([event type] == NSLeftMouseDown)
29 [clickTarget_ performClick:clickTarget_];
32 - (void)drawRect:(NSRect)dirtyRect {
33 if (shouldHighlightOnHover_ && isHighlighted_) {
34 [[self hoverColor] set];
35 NSRectFill([self bounds]);
39 - (NSColor*)hoverColor {
40 // Shading color is specified as a alpha component color, so premultiply.
41 NSColor* shadingColor = gfx::SkColorToCalibratedNSColor(kShadingColor);
42 NSColor* blendedColor = [[[self window] backgroundColor]
43 blendedColorWithFraction:[shadingColor alphaComponent]
44 ofColor:shadingColor];
45 return [blendedColor colorWithAlphaComponent:1.0];
48 - (void)setShouldHighlightOnHover:(BOOL)shouldHighlight {
49 if (shouldHighlight == shouldHighlightOnHover_)
51 shouldHighlightOnHover_ = shouldHighlight;
52 [self setNeedsDisplay:YES];
55 - (void)setIsHighlighted:(BOOL)isHighlighted {
56 isHighlighted_ = isHighlighted;
57 if (shouldHighlightOnHover_)
58 [self setNeedsDisplay:YES];