- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / autofill / autofill_section_view.mm
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.
4
5 #import "chrome/browser/ui/cocoa/autofill/autofill_section_view.h"
6
7 #import "chrome/browser/ui/chrome_style.h"
8 #include "skia/ext/skia_utils_mac.h"
9
10 namespace {
11
12 // Slight shading for mouse hover.
13 SkColor kShadingColor = 0x07000000;  // SkColorSetARGB(7, 0, 0, 0);
14
15 }  // namespace
16
17 @implementation AutofillSectionView
18
19 @synthesize clickTarget = clickTarget_;
20 @synthesize shouldHighlightOnHover = shouldHighlightOnHover_;
21 @synthesize isHighlighted = isHighlighted_;
22
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_];
30 }
31
32 - (void)drawRect:(NSRect)dirtyRect {
33   if (shouldHighlightOnHover_ && isHighlighted_) {
34     [[self hoverColor] set];
35     NSRectFill([self bounds]);
36   }
37 }
38
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];
46 }
47
48 - (void)setShouldHighlightOnHover:(BOOL)shouldHighlight {
49   if (shouldHighlight == shouldHighlightOnHover_)
50     return;
51   shouldHighlightOnHover_ = shouldHighlight;
52   [self setNeedsDisplay:YES];
53 }
54
55 - (void)setIsHighlighted:(BOOL)isHighlighted {
56   isHighlighted_ = isHighlighted;
57   if (shouldHighlightOnHover_)
58     [self setNeedsDisplay:YES];
59 }
60
61 @end