Bug 853105 - Allow double-click to minimize on windows with drawInTitlebar enabled. r=mstange, r=smichaud
authorJosiahOne <josiah@programmer.net>
Mon, 20 May 2013 17:38:54 -0400
changeset 145846 2464333908a77726cfd3b21aa22941584091fcfe
parent 145845 78214f394a9714bcc5876a62969f8959bb09ebc7
child 145847 cebcec9ca3c3dbd57fe037e1564b2218139d12e3
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, smichaud
bugs853105
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 853105 - Allow double-click to minimize on windows with drawInTitlebar enabled. r=mstange, r=smichaud
widget/cocoa/nsChildView.mm
widget/cocoa/nsCocoaWindow.mm
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -4086,17 +4086,28 @@ NSEvent* gLastDragMouseDownEvent = nil;
       cocoaEvent.data.mouse.deltaX = [theEvent deltaX];
       cocoaEvent.data.mouse.deltaY = [theEvent deltaY];
       cocoaEvent.data.mouse.deltaZ = [theEvent deltaZ];
       geckoEvent.pluginEvent = &cocoaEvent;
     }
   }
 
   // This might destroy our widget (and null out mGeckoChild).
-  mGeckoChild->DispatchWindowEvent(geckoEvent);
+  bool defaultPrevented = mGeckoChild->DispatchWindowEvent(geckoEvent);
+
+  // Check to see if we are double-clicking in the titlebar.
+  CGFloat locationInTitlebar = [[self window] frame].size.height - [theEvent locationInWindow].y;
+  if (!defaultPrevented && [theEvent clickCount] == 2 &&
+      [[self window] isMovableByWindowBackground] &&
+      [self shouldMinimizeOnTitlebarDoubleClick] &&
+      [[self window] isKindOfClass:[ToolbarWindow class]] &&
+      (locationInTitlebar < [(ToolbarWindow*)[self window] titlebarHeight] ||
+       locationInTitlebar < [(ToolbarWindow*)[self window] unifiedToolbarHeight])) {
+    [[self window] miniaturize:self];
+  }
 
   // If our mouse-up event's location is over some other object (as might
   // happen if it came at the end of a dragging operation), also send our
   // Gecko frame a mouse-exit event.
   if (mGeckoChild && mIsPluginView) {
     if (mPluginEventModel == NPEventModelCocoa) {
       if (ChildViewMouseTracker::ViewForEvent(theEvent) != self) {
         nsMouseEvent geckoExitEvent(true, NS_MOUSE_EXIT, mGeckoChild, nsMouseEvent::eReal);
@@ -4676,16 +4687,27 @@ static int32_t RoundUp(double aDouble)
 }
 
 - (BOOL) hasMarkedText
 {
   NS_ENSURE_TRUE(mTextInputHandler, NO);
   return mTextInputHandler->HasMarkedText();
 }
 
+- (BOOL)shouldMinimizeOnTitlebarDoubleClick
+{
+  NSString *MDAppleMiniaturizeOnDoubleClickKey =
+                                      @"AppleMiniaturizeOnDoubleClick";
+  NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
+  bool shouldMinimize = [[userDefaults
+          objectForKey:MDAppleMiniaturizeOnDoubleClickKey] boolValue];
+
+  return shouldMinimize;
+}
+
 - (NSInteger) conversationIdentifier
 {
   NS_ENSURE_TRUE(mTextInputHandler, reinterpret_cast<NSInteger>(self));
   return mTextInputHandler->ConversationIdentifier();
 }
 
 - (NSAttributedString *) attributedSubstringFromRange:(NSRange)theRange
 {
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -2941,33 +2941,34 @@ static const NSString* kStateShowsToolba
 // Returns the unified height of titlebar + toolbar.
 - (CGFloat)unifiedToolbarHeight
 {
   return mUnifiedToolbarHeight;
 }
 
 - (CGFloat)titlebarHeight
 {
+  // We use the original content rect here, not what we return from
+  // [self contentRectForFrameRect:], because that would give us a
+  // titlebarHeight of zero in drawsContentsIntoWindowFrame mode.
   NSRect frameRect = [self frame];
-  return frameRect.size.height - [self contentRectForFrameRect:frameRect].size.height;
+  NSRect originalContentRect = [NSWindow contentRectForFrameRect:frameRect styleMask:[self styleMask]];
+  return NSMaxY(frameRect) - NSMaxY(originalContentRect);
 }
 
 // Stores the complete height of titlebar + toolbar.
 - (void)setUnifiedToolbarHeight:(CGFloat)aHeight
 {
   if (aHeight == mUnifiedToolbarHeight)
     return;
 
   mUnifiedToolbarHeight = aHeight;
 
   // Update sheet positioning hint
-  NSRect frameRect = [self frame];
-  NSRect originalContentRect = [NSWindow contentRectForFrameRect:frameRect styleMask:[self styleMask]];
-  CGFloat originalTitlebarHeight = NSMaxY(frameRect) - NSMaxY(originalContentRect);
-  CGFloat topMargin = mUnifiedToolbarHeight - originalTitlebarHeight;
+  CGFloat topMargin = mUnifiedToolbarHeight - [self titlebarHeight];
   [self setContentBorderThickness:topMargin forEdge:NSMaxYEdge];
 
   // Redraw the title bar. If we're inside painting, we'll do it right now,
   // otherwise we'll just invalidate it.
   BOOL needSyncRedraw = ([NSView focusView] != nil);
   [self setTitlebarNeedsDisplayInRect:[self titlebarRect] sync:needSyncRedraw];
 }