summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/hover_button.mm
diff options
context:
space:
mode:
authorjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-30 16:13:33 +0000
committerjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-30 16:13:33 +0000
commit80bebf48af21c4470b0732919df363f5ba8e52ab (patch)
treef60c689efe6708b0df2e10acbde993b3f856916c /chrome/browser/cocoa/hover_button.mm
parent0638e0fe295a8e2ce7deb5d975351829a0aaadf2 (diff)
downloadchromium_src-80bebf48af21c4470b0732919df363f5ba8e52ab.zip
chromium_src-80bebf48af21c4470b0732919df363f5ba8e52ab.tar.gz
chromium_src-80bebf48af21c4470b0732919df363f5ba8e52ab.tar.bz2
Change mac notifications UI to match the new mocks. Introduce a new utility view which provides an image based button that changes on hover and press.
Refer to the bug for screenshots of the current and desired UI. Screenshot of what results from this patch is visible at http://www.corp.google.com/~johnnyg/49490patch.png XIB change: change height of title bar, change bindings of buttons. BUG=49190 TEST=notifications on the mac Review URL: http://codereview.chromium.org/3014004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54326 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/hover_button.mm')
-rw-r--r--chrome/browser/cocoa/hover_button.mm97
1 files changed, 97 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/hover_button.mm b/chrome/browser/cocoa/hover_button.mm
new file mode 100644
index 0000000..38874e3
--- /dev/null
+++ b/chrome/browser/cocoa/hover_button.mm
@@ -0,0 +1,97 @@
+// Copyright (c) 2010 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/cocoa/hover_button.h"
+
+@implementation HoverButton
+
+- (id)initWithFrame:(NSRect)frameRect {
+ if ((self = [super initWithFrame:frameRect])) {
+ [self setTrackingEnabled:YES];
+ hoverState_ = kHoverStateNone;
+ [self updateTrackingAreas];
+ }
+ return self;
+}
+
+- (void)awakeFromNib {
+ [self setTrackingEnabled:YES];
+ hoverState_ = kHoverStateNone;
+ [self updateTrackingAreas];
+}
+
+- (void)dealloc {
+ [self setTrackingEnabled:NO];
+ [super dealloc];
+}
+
+- (void)mouseEntered:(NSEvent*)theEvent {
+ hoverState_ = kHoverStateMouseOver;
+ [self setNeedsDisplay:YES];
+}
+
+- (void)mouseExited:(NSEvent*)theEvent {
+ hoverState_ = kHoverStateNone;
+ [self setNeedsDisplay:YES];
+}
+
+- (void)mouseDown:(NSEvent*)theEvent {
+ hoverState_ = kHoverStateMouseDown;
+ [self setNeedsDisplay:YES];
+ // The hover button needs to hold onto itself here for a bit. Otherwise,
+ // it can be freed while |super mouseDown:| is in it's 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];
+}
+
+- (void)setTrackingEnabled:(BOOL)enabled {
+ if (enabled) {
+ trackingArea_.reset(
+ [[NSTrackingArea alloc] initWithRect:[self bounds]
+ options:NSTrackingMouseEnteredAndExited |
+ NSTrackingActiveAlways
+ owner:self
+ userInfo:nil]);
+ [self addTrackingArea:trackingArea_.get()];
+
+ // If you have a separate window that overlaps the close button, and you
+ // move the mouse directly over the close button without entering another
+ // part of the tab strip, we don't get any mouseEntered event since the
+ // tracking area was disabled when we entered.
+ [self checkImageState];
+ } else {
+ if (trackingArea_.get()) {
+ [self removeTrackingArea:trackingArea_.get()];
+ trackingArea_.reset(nil);
+ }
+ }
+}
+
+- (void)updateTrackingAreas {
+ [super updateTrackingAreas];
+ [self checkImageState];
+}
+
+- (void)checkImageState {
+ if (!trackingArea_.get())
+ return;
+
+ // Update the button's state if the button has moved.
+ NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream];
+ mouseLoc = [self convertPoint:mouseLoc fromView:nil];
+ hoverState_ = NSPointInRect(mouseLoc, [self bounds]) ?
+ kHoverStateMouseOver : kHoverStateNone;
+ [self setNeedsDisplay:YES];
+}
+
+@end