Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Unified Diff: ui/base/cocoa/hover_button.mm

Issue 16098012: [Mac] Reimplement HoverButton and HoverImageButton using NSButton.state. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nonatomic, assign Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/cocoa/hover_button.mm
diff --git a/ui/base/cocoa/hover_button.mm b/ui/base/cocoa/hover_button.mm
index a2348986560a4d0716477bcabe3e36fc80f33dab..74b6009748aaa6b3b9231ff1192fea4d8d2d1fb3 100644
--- a/ui/base/cocoa/hover_button.mm
+++ b/ui/base/cocoa/hover_button.mm
@@ -6,12 +6,11 @@
@implementation HoverButton
-@synthesize hoverState = hoverState_;
+@synthesize isMouseInside = isMouseInside_;
- (id)initWithFrame:(NSRect)frameRect {
if ((self = [super initWithFrame:frameRect])) {
[self setTrackingEnabled:YES];
- hoverState_ = kHoverStateNone;
[self updateTrackingAreas];
}
return self;
@@ -19,7 +18,6 @@
- (void)awakeFromNib {
[self setTrackingEnabled:YES];
- self.hoverState = kHoverStateNone;
[self updateTrackingAreas];
}
@@ -28,31 +26,27 @@
[super dealloc];
}
+- (void)setIsMouseInside:(BOOL)isInside {
+ isMouseInside_ = isInside;
+ [self setNeedsDisplay:YES];
+}
+
+- (HoverState)hoverState {
+ if (self.state == NSOnState)
+ return kHoverStateMouseDown;
+ if (self.isMouseInside)
+ return kHoverStateMouseOver;
+ return kHoverStateNone;
+}
+
- (void)mouseEntered:(NSEvent*)theEvent {
if (trackingArea_.get())
- self.hoverState = kHoverStateMouseOver;
+ self.isMouseInside = YES;
}
- (void)mouseExited:(NSEvent*)theEvent {
if (trackingArea_.get())
- self.hoverState = kHoverStateNone;
-}
-
-- (void)mouseDown:(NSEvent*)theEvent {
- self.hoverState = kHoverStateMouseDown;
- // The hover button needs to hold onto itself here for a bit. Otherwise,
- // it can be freed while |super mouseDown:| is in its loop, and the
- // |checkImageState| call will crash.
- // http://crbug.com/28220
- scoped_nsobject<HoverButton> myself([self retain]);
-
- [super mouseDown:theEvent];
- // We need to check the image state after the mouseDown event loop finishes.
- // It's possible that we won't get a mouseExited event if the button was
- // moved under the mouse during tab resize, instead of the mouse moving over
- // the button.
- // http://crbug.com/31279
- [self checkImageState];
+ self.isMouseInside = NO;
}
- (void)setTrackingEnabled:(BOOL)enabled {
@@ -96,13 +90,7 @@
// Update the button's state if the button has moved.
NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream];
mouseLoc = [self convertPoint:mouseLoc fromView:nil];
- self.hoverState = NSPointInRect(mouseLoc, [self bounds]) ?
- kHoverStateMouseOver : kHoverStateNone;
-}
-
-- (void)setHoverState:(HoverState)state {
- hoverState_ = state;
- [self setNeedsDisplay:YES];
+ self.isMouseInside = NSPointInRect(mouseLoc, [self bounds]);
}
@end

Powered by Google App Engine
This is Rietveld 408576698