Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / autofill / autofill_section_view.mm
blobe10435a276ad23f1446c4977823d59ab0e878545
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"
10 namespace {
12 // Slight shading for mouse hover.
13 SkColor kShadingColor = 0x07000000;  // SkColorSetARGB(7, 0, 0, 0);
15 }  // namespace
17 @implementation AutofillSectionView
19 @synthesize clickTarget = clickTarget_;
20 @synthesize shouldHighlightOnHover = shouldHighlightOnHover_;
21 @synthesize isHighlighted = isHighlighted_;
23 - (void)updateHoverState {
24   NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream];
25   mouseLoc = [self convertPoint:mouseLoc fromView:nil];
26   [self setIsHighlighted:NSPointInRect(mouseLoc, [self bounds])];
29 - (void)mouseEvent:(NSEvent*)event {
30   if ([event type] == NSMouseExited)
31     [self setIsHighlighted:NO];
32   else if ([event type] == NSMouseEntered)
33     [self setIsHighlighted:YES];
34   else if ([event type] == NSLeftMouseDown)
35     [clickTarget_ performClick:clickTarget_];
38 - (void)drawRect:(NSRect)dirtyRect {
39   if (shouldHighlightOnHover_ && isHighlighted_) {
40     [[self hoverColor] set];
41     NSRectFill([self bounds]);
42   }
45 - (NSColor*)hoverColor {
46   // Shading color is specified as a alpha component color, so premultiply.
47   NSColor* shadingColor = gfx::SkColorToCalibratedNSColor(kShadingColor);
48   NSColor* blendedColor = [[[self window] backgroundColor]
49       blendedColorWithFraction:[shadingColor alphaComponent]
50                        ofColor:shadingColor];
51   return [blendedColor colorWithAlphaComponent:1.0];
54 - (void)setShouldHighlightOnHover:(BOOL)shouldHighlight {
55   if (shouldHighlight == shouldHighlightOnHover_)
56     return;
57   shouldHighlightOnHover_ = shouldHighlight;
58   [self setNeedsDisplay:YES];
61 - (void)setIsHighlighted:(BOOL)isHighlighted {
62   isHighlighted_ = isHighlighted;
63   if (shouldHighlightOnHover_)
64     [self setNeedsDisplay:YES];
67 @end