<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -814,6 +814,12 @@ CPRunContinuesResponse  = -1002;
         return [_documentController openDocumentWithContentsOfURL:aFilename display:YES error:NULL];
 }
 
+- (void)_didResignActive
+{
+    if (self._activeMenu)
+        [self._activeMenu cancelTracking];
+}
+
 @end
 
 var _CPModalSessionMake = function(aWindow, aStopCode)</diff>
      <filename>AppKit/CPApplication.j</filename>
    </modified>
    <modified>
      <diff>@@ -30,6 +30,7 @@
 @import &quot;CPMenuItem.j&quot;
 @import &quot;CPPanel.j&quot;
 
+#include &quot;CoreGraphics/CGGeometry.h&quot;
 #include &quot;Platform/Platform.h&quot;
 
 
@@ -738,7 +739,21 @@ var _CPMenuBarVisible               = NO,
 */
 - (void)cancelTracking
 {
-    [_menuWindow cancelTracking];
+    [[CPRunLoop currentRunLoop] performSelector:@selector(_fireCancelTrackingEvent) target:self argument:nil order:0 modes:[CPDefaultRunLoopMode]];
+}
+
+- (void)_fireCancelTrackingEvent
+{
+    [CPApp sendEvent:[CPEvent
+        otherEventWithType:CPAppKitDefined
+                  location:_CGPointMakeZero()
+             modifierFlags:0
+                 timestamp:0
+              windowNumber:0
+                   context:0
+                   subtype:0
+                     data1:0
+                     data2:0]];
 }
 
 /* @ignore */
@@ -767,7 +782,7 @@ var _CPMenuBarVisible               = NO,
     {
         var item = _items[index],
             modifierMask = [item keyEquivalentModifierMask];
-        
+
         if ((modifierFlags &amp; (CPShiftKeyMask | CPAlternateKeyMask | CPCommandKeyMask | CPControlKeyMask)) == modifierMask &amp;&amp;
             [characters caseInsensitiveCompare:[item keyEquivalent]] == CPOrderedSame)
         {
@@ -928,7 +943,7 @@ var STICKY_TIME_INTERVAL        = 500,
 */
 @implementation _CPMenuWindow : CPWindow
 {
-    _CPMenuView         _menuView;    
+    _CPMenuView         _menuView;
     CPClipView          _menuClipView;
     CPView              _lastMouseOverMenuView;
     
@@ -1178,13 +1193,10 @@ var STICKY_TIME_INTERVAL        = 500,
     [_menuView scrollPoint:CGPointMake(0.0, [self convertBaseToGlobal:clipFrame.origin].y - menuViewOrigin.y)];
 }
 
-- (void)cancelTracking
-{
-    _trackingCanceled = YES;
-}
-
 - (void)beginTrackingWithEvent:(CPEvent)anEvent sessionDelegate:(id)aSessionDelegate didEndSelector:(SEL)aDidEndSelector
 {
+    CPApp._activeMenu = [_menuView menu];
+
     _startTime = [anEvent timestamp];//new Date();
     _scrollingState = _CPMenuWindowScrollingStateNone;
     _trackingCanceled = NO;
@@ -1198,7 +1210,41 @@ var STICKY_TIME_INTERVAL        = 500,
 - (void)trackEvent:(CPEvent)anEvent
 {
     var type = [anEvent type],
-        theWindow = [anEvent window],
+        menu = [_menuView menu];
+
+    // Close Menu Event.
+    if (type === CPAppKitDefined)
+    {
+        // Stop all periodic events at this point.
+        [CPEvent stopPeriodicEvents];
+
+        var highlightedItem = [[_menuView menu] highlightedItem];
+
+        [menu _highlightItemAtIndex:CPNotFound];
+
+        [self orderOut:self];
+
+        var delegate = [menu delegate];
+
+        if ([delegate respondsToSelector:@selector(menuDidClose:)])
+            [delegate menuDidClose:menu];
+
+        if (_sessionDelegate &amp;&amp; _didEndSelector)
+            objj_msgSend(_sessionDelegate, _didEndSelector, self, highlightedItem);
+
+        [[CPNotificationCenter defaultCenter]
+            postNotificationName:CPMenuDidEndTrackingNotification
+                          object:menu];
+
+        // Clear these now so its faster next time around.
+        [_menuView setMenu:nil];
+
+        CPApp._activeMenu = nil;
+
+        return;
+    }
+
+    var theWindow = [anEvent window],
         globalLocation = theWindow ? [theWindow convertBaseToGlobal:[anEvent locationInWindow]] : [anEvent locationInWindow];
 
     if (type === CPPeriodic)
@@ -1222,8 +1268,7 @@ var STICKY_TIME_INTERVAL        = 500,
 
     _lastGlobalLocation = globalLocation;
     
-    var menu = [_menuView menu],
-        menuLocation = [self convertGlobalToBase:globalLocation],
+    var menuLocation = [self convertGlobalToBase:globalLocation],
         activeItemIndex = [_menuView itemIndexAtPoint:[_menuView convertPoint:menuLocation fromView:nil]],
         mouseOverMenuView = [[menu itemAtIndex:activeItemIndex] view];
     
@@ -1279,47 +1324,11 @@ var STICKY_TIME_INTERVAL        = 500,
                 else if (oldScrollingState == _CPMenuWindowScrollingStateNone)
                     [CPEvent startPeriodicEventsAfterDelay:0.0 withPeriod:0.04];
         }
-        
         else if (type == CPLeftMouseUp &amp;&amp; ([anEvent timestamp] - _startTime &gt; STICKY_TIME_INTERVAL))
-        {
-            // Stop these if they're still goin'.
-            if (_scrollingState != _CPMenuWindowScrollingStateNone)
-                [CPEvent stopPeriodicEvents];
-    
-            [self cancelTracking];
-        }
+            [menu cancelTracking];
     }
-        
-    if (_trackingCanceled)
-    {
-        // Stop all periodic events at this point.
-        [CPEvent stopPeriodicEvents];
-        
-        var highlightedItem = [[_menuView menu] highlightedItem];
-        
-        [menu _highlightItemAtIndex:CPNotFound];
-        
-        [self orderOut:self];
 
-        var delegate = [menu delegate];
-        
-        if ([delegate respondsToSelector:@selector(menuDidClose:)])
-            [delegate menuDidClose:menu];
-
-        if (_sessionDelegate &amp;&amp; _didEndSelector)
-            objj_msgSend(_sessionDelegate, _didEndSelector, self, highlightedItem);
-
-        [[CPNotificationCenter defaultCenter]
-            postNotificationName:CPMenuDidEndTrackingNotification
-                          object:menu];
-
-        // Clear these now so its faster next time around.
-        [_menuView setMenu:nil];
-
-        return;
-    }
-            
-    [CPApp setTarget:self selector:@selector(trackEvent:) forNextEventMatchingMask:CPPeriodicMask | CPMouseMovedMask | CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
+    [CPApp setTarget:self selector:@selector(trackEvent:) forNextEventMatchingMask:CPPeriodicMask | CPMouseMovedMask | CPLeftMouseDraggedMask | CPLeftMouseUpMask | CPAppKitDefinedMask untilDate:nil inMode:nil dequeue:YES];
 }
 
 @end
@@ -1970,11 +1979,13 @@ var _CPMenuBarWindowBackgroundColor = nil,
     }
 }
 
-- (void)setFrame:(CGRect)aRect
+- (void)setFrame:(CGRect)aRect display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate
 {
-    var oldSize = CGSizeMakeCopy([self frame].size);
-    [super setFrame:aRect];
-    if (!CGSizeEqualToSize(oldSize, [self frame].size))
+    var size = [self frame].size;
+
+    [super setFrame:aRect display:shouldDisplay animate:shouldAnimate];
+
+    if (_CGSizeEqualToSize(size, aRect.size))
         [self tile];
 }
 </diff>
      <filename>AppKit/CPMenu.j</filename>
    </modified>
    <modified>
      <diff>@@ -338,6 +338,7 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop];
 
     if (![CPPlatform isBrowser])
     {
+        _DOMWindow.cpWindowNumber = [self._only windowNumber];
         _DOMWindow.cpSetFrame(_contentRect);
         _DOMWindow.cpSetLevel(_level);
         _DOMWindow.cpSetHasShadow(_hasShadow);</diff>
      <filename>AppKit/Platform/DOM/CPPlatformWindow+DOM.j</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>341eddb9f94ac33f5f33b1e70cbb959b133abf59</id>
    </parent>
  </parents>
  <author>
    <name>Francisco Ryan Tolmasky I</name>
    <email>francisco@280north.com</email>
  </author>
  <url>http://github.com/cacaodev/cappuccino/commit/0561f69c860ce820035a89220695d9ae81081530</url>
  <id>0561f69c860ce820035a89220695d9ae81081530</id>
  <committed-date>2009-10-22T19:58:34-07:00</committed-date>
  <authored-date>2009-10-22T19:58:34-07:00</authored-date>
  <message>Made cancelTracking send a close menu event so that it doesn't behave passively.

Reviewed by me.</message>
  <tree>672b71cd61c2f044e9f9568308e4bef5f4283112</tree>
  <committer>
    <name>Francisco Ryan Tolmasky I</name>
    <email>francisco@280north.com</email>
  </committer>
</commit>
