blob: b69ab99c66c8a1ca993c02bbdb619df7e5862a3e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/autofill/autofill_section_view.h"
#import "chrome/browser/ui/chrome_style.h"
#include "skia/ext/skia_utils_mac.h"
namespace {
// Slight shading for mouse hover.
SkColor kShadingColor = 0x07000000; // SkColorSetARGB(7, 0, 0, 0);
} // namespace
@implementation AutofillSectionView
@synthesize clickTarget = clickTarget_;
@synthesize shouldHighlightOnHover = shouldHighlightOnHover_;
@synthesize isHighlighted = isHighlighted_;
- (void)updateHoverState {
NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream];
mouseLoc = [self convertPoint:mouseLoc fromView:nil];
[self setIsHighlighted:NSPointInRect(mouseLoc, [self bounds])];
}
- (void)mouseEvent:(NSEvent*)event {
if ([event type] == NSMouseExited)
[self setIsHighlighted:NO];
else if ([event type] == NSMouseEntered)
[self setIsHighlighted:YES];
else if ([event type] == NSLeftMouseDown)
[clickTarget_ performClick:clickTarget_];
}
- (void)drawRect:(NSRect)dirtyRect {
if (shouldHighlightOnHover_ && isHighlighted_) {
[[self hoverColor] set];
NSRectFill([self bounds]);
}
}
- (NSColor*)hoverColor {
// Shading color is specified as a alpha component color, so premultiply.
NSColor* shadingColor = skia::SkColorToCalibratedNSColor(kShadingColor);
NSColor* blendedColor = [[[self window] backgroundColor]
blendedColorWithFraction:[shadingColor alphaComponent]
ofColor:shadingColor];
return [blendedColor colorWithAlphaComponent:1.0];
}
- (void)setShouldHighlightOnHover:(BOOL)shouldHighlight {
if (shouldHighlight == shouldHighlightOnHover_)
return;
shouldHighlightOnHover_ = shouldHighlight;
[self setNeedsDisplay:YES];
}
- (void)setIsHighlighted:(BOOL)isHighlighted {
isHighlighted_ = isHighlighted;
if (shouldHighlightOnHover_)
[self setNeedsDisplay:YES];
}
@end
|