summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authordimich@chromium.org <dimich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 00:16:21 +0000
committerdimich@chromium.org <dimich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 00:16:21 +0000
commitf5a49f47ee2fcf48b3b420e3bc94eec893be92f2 (patch)
tree9320b20e6de4d3b5584fcd77b0f5ed36e9a5b9e3 /chrome/browser
parentcd2ec4bce32b559b5daa47de815a31fc6d469517 (diff)
downloadchromium_src-f5a49f47ee2fcf48b3b420e3bc94eec893be92f2.zip
chromium_src-f5a49f47ee2fcf48b3b420e3bc94eec893be92f2.tar.gz
chromium_src-f5a49f47ee2fcf48b3b420e3bc94eec893be92f2.tar.bz2
Prevent Notifications on Mac from bringing main browser window to the top when clicked.
The only relevant Notification.xib change: added a custom transparent view backed by BalloonOverlayViewCocoa class on top of the whole Notification balloon, so it gets first crack at mouse messages. The view is using springs to autoresize in both dimensions. BUG=68589 TEST=none Review URL: http://codereview.chromium.org/6105001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70562 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/ui/cocoa/notifications/balloon_controller.h6
-rw-r--r--chrome/browser/ui/cocoa/notifications/balloon_controller.mm33
-rw-r--r--chrome/browser/ui/cocoa/notifications/balloon_view.h7
-rw-r--r--chrome/browser/ui/cocoa/notifications/balloon_view.mm28
4 files changed, 25 insertions, 49 deletions
diff --git a/chrome/browser/ui/cocoa/notifications/balloon_controller.h b/chrome/browser/ui/cocoa/notifications/balloon_controller.h
index 61376b4..fadd35a 100644
--- a/chrome/browser/ui/cocoa/notifications/balloon_controller.h
+++ b/chrome/browser/ui/cocoa/notifications/balloon_controller.h
@@ -52,9 +52,6 @@ class NotificationOptionsMenuModel;
// The host for the renderer of the HTML contents.
scoped_ptr<BalloonViewHost> htmlContents_;
-
- // The psn of the front application process.
- ProcessSerialNumber frontProcessNum_;
}
// Initialize with a balloon object containing the notification data.
@@ -86,9 +83,6 @@ class NotificationOptionsMenuModel;
// The BalloonHost
- (BalloonViewHost*)getHost;
-
-// Handle the event if it is for the balloon.
-- (BOOL)handleEvent:(NSEvent*)event;
@end
@interface BalloonController (UnitTesting)
diff --git a/chrome/browser/ui/cocoa/notifications/balloon_controller.mm b/chrome/browser/ui/cocoa/notifications/balloon_controller.mm
index b7daca6f..6fca0a1 100644
--- a/chrome/browser/ui/cocoa/notifications/balloon_controller.mm
+++ b/chrome/browser/ui/cocoa/notifications/balloon_controller.mm
@@ -113,45 +113,12 @@ const int kRightMargin = 2;
assumeInside:NO];
}
-- (BOOL)handleEvent:(NSEvent*)event {
- BOOL eventHandled = NO;
- if ([event type] == NSLeftMouseDown) {
- NSPoint mouse = [shelf_ convertPoint:[event locationInWindow]
- fromView:nil];
- if (NSPointInRect(mouse, [closeButton_ frame])) {
- [closeButton_ mouseDown:event];
-
- // Bring back the front process that is deactivated when we click the
- // close button.
- if (frontProcessNum_.highLongOfPSN || frontProcessNum_.lowLongOfPSN) {
- SetFrontProcessWithOptions(&frontProcessNum_,
- kSetFrontProcessFrontWindowOnly);
- frontProcessNum_.highLongOfPSN = 0;
- frontProcessNum_.lowLongOfPSN = 0;
- }
-
- eventHandled = YES;
- } else if (NSPointInRect(mouse, [optionsButton_ frame])) {
- [optionsButton_ mouseDown:event];
- eventHandled = YES;
- }
- }
- return eventHandled;
-}
-
- (void) mouseEntered:(NSEvent*)event {
[[closeButton_ cell] setHighlighted:YES];
-
- // Remember the current front process so that we can bring it back later.
- if (!frontProcessNum_.highLongOfPSN && !frontProcessNum_.lowLongOfPSN)
- GetFrontProcess(&frontProcessNum_);
}
- (void) mouseExited:(NSEvent*)event {
[[closeButton_ cell] setHighlighted:NO];
-
- frontProcessNum_.highLongOfPSN = 0;
- frontProcessNum_.lowLongOfPSN = 0;
}
- (IBAction)optionsButtonPressed:(id)sender {
diff --git a/chrome/browser/ui/cocoa/notifications/balloon_view.h b/chrome/browser/ui/cocoa/notifications/balloon_view.h
index b742eaf..916bcec 100644
--- a/chrome/browser/ui/cocoa/notifications/balloon_view.h
+++ b/chrome/browser/ui/cocoa/notifications/balloon_view.h
@@ -24,5 +24,12 @@
}
@end
+// This view overlays the notification balloon on top. It is used to intercept
+// mouse input to prevent reordering of the other browser windows when clicking
+// on the notification balloon.
+@interface BalloonOverlayViewCocoa : NSView {
+}
+@end
+
#endif // CHROME_BROWSER_UI_COCOA_NOTIFICATIONS_BALLOON_VIEW_H_
diff --git a/chrome/browser/ui/cocoa/notifications/balloon_view.mm b/chrome/browser/ui/cocoa/notifications/balloon_view.mm
index e88331a..aa78be6 100644
--- a/chrome/browser/ui/cocoa/notifications/balloon_view.mm
+++ b/chrome/browser/ui/cocoa/notifications/balloon_view.mm
@@ -37,16 +37,6 @@ const int kRoundedCornerSize = 6;
- (BOOL)canBecomeMainWindow {
return NO;
}
-
-- (void)sendEvent:(NSEvent*)event {
- // We do not want to bring chrome window to foreground when we click on close
- // or option button. To do this, we have to intercept the event.
- BalloonController* delegate =
- static_cast<BalloonController*>([self delegate]);
- if (![delegate handleEvent:event]) {
- [super sendEvent:event];
- }
-}
@end
@implementation BalloonShelfViewCocoa
@@ -82,3 +72,21 @@ const int kRoundedCornerSize = 6;
[path stroke];
}
@end
+
+@implementation BalloonOverlayViewCocoa
+
+// We do not want to bring chrome window to foreground when we click on any
+// part of the notification balloon. To do this, we first postpone the window
+// reorder here (shouldDelayWindowOrderingForEvent is called during mouseDown)
+// and then complete canceling the reorder by [NSApp preventWindowOrdering] in
+// mouseDown handler of this view.
+- (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent*)theEvent {
+ return YES;
+}
+
+- (void)mouseDown:(NSEvent*)event {
+ [NSApp preventWindowOrdering];
+ // Continue bubbling the event up the chain of responders.
+ [super mouseDown:event];
+}
+@end