diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 2382f5efb3..cd2637470f 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -98,9 +98,6 @@ var CPViewFlags = { }, CPViewHasCustomDrawRect = 1 << 0, CPViewHasCustomLayoutSubviews = 1 << 1; -var CPCurrentToolTip, - CPCurrentToolTipTimer, - CPToolTipDelay = 1.0; /*! @ingroup appkit @@ -246,8 +243,8 @@ var CPCurrentToolTip, - (void)_setupToolTipHandlers { _toolTipInstalled = NO; - _toolTipFunctionIn = function(e) { [self _fireToolTip]; } - _toolTipFunctionOut = function(e) { [self _invalidateToolTip]; }; + _toolTipFunctionIn = function(e) { [_CPToolTip scheduleToolTipForView:self]; } + _toolTipFunctionOut = function(e) { [_CPToolTip invalidateCurrentToolTipIfNeeded]; }; } + (CPSet)keyPathsForValuesAffectingFrame @@ -398,54 +395,6 @@ var CPCurrentToolTip, _toolTipInstalled = NO; } -/*! @ignore - Starts the tooltip timer. -*/ -- (void)_fireToolTip -{ - if (CPCurrentToolTipTimer) - { - [CPCurrentToolTipTimer invalidate]; - - if (CPCurrentToolTip) - [CPCurrentToolTip close]; - - CPCurrentToolTip = nil; - } - - if (_toolTip) - CPCurrentToolTipTimer = [CPTimer scheduledTimerWithTimeInterval:CPToolTipDelay target:self selector:@selector(_showToolTip:) userInfo:nil repeats:NO]; -} - -/*! @ignore - Stop the tooltip timer if any -*/ -- (void)_invalidateToolTip -{ - if (CPCurrentToolTipTimer) - { - [CPCurrentToolTipTimer invalidate]; - CPCurrentToolTipTimer = nil; - } - - if (CPCurrentToolTip) - { - [CPCurrentToolTip close]; - CPCurrentToolTip = nil; - } -} - -/*! @ignore - Actually shows the tooltip if any -*/ -- (void)_showToolTip:(CPTimer)aTimer -{ - if (CPCurrentToolTip) - [CPCurrentToolTip close]; - - CPCurrentToolTip = [_CPToolTip toolTipWithString:_toolTip]; -} - /*! Returns the container view of the receiver @return the receiver's containing view diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index 5e2e74b005..77494eb2cc 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -113,14 +113,12 @@ @import "CPEvent.j" @import "CPText.j" @import "CPCompatibility.j" - @import "CPDOMWindowLayer.j" @import "CPPlatform.j" @import "CPPlatformWindow.j" @import "CPPlatformWindow+DOMKeys.j" - // List of all open native windows var PlatformWindows = [CPSet set]; @@ -1242,6 +1240,10 @@ var resizeTimer = nil; else if (type === "mousedown") { + // If we receive a click event, then we invalidate any scheduled + // or visible tooltips + [_CPToolTip invalidateCurrentToolTipIfNeeded]; + var button = aDOMEvent.button; _mouseDownIsRightClick = button == 2 || (CPBrowserIsOperatingSystem(CPMacOperatingSystem) && button == 0 && modifierFlags & CPControlKeyMask); diff --git a/AppKit/_CPToolTip.j b/AppKit/_CPToolTip.j index db37f34e3d..c67bf4b4c7 100644 --- a/AppKit/_CPToolTip.j +++ b/AppKit/_CPToolTip.j @@ -27,7 +27,10 @@ _CPToolTipWindowMask = 1 << 27; var _CPToolTipHeight = 24.0, - _CPToolTipFontSize = 11.0; + _CPToolTipFontSize = 11.0, + _CPToolTipDelay = 1.0, + _CPToolTipCurrentToolTip, + _CPToolTipCurrentToolTipTimer; /*! @ingroup appkit This is a basic tooltip that behaves mostly like Cocoa ones. @@ -41,6 +44,46 @@ var _CPToolTipHeight = 24.0, #pragma mark - #pragma mark Class Methods +/*! @ignore + Invalidate any scheduled tooltips, or hide any visible one +*/ ++ (void)invalidateCurrentToolTipIfNeeded +{ + if (_CPToolTipCurrentToolTipTimer) + { + [_CPToolTipCurrentToolTipTimer invalidate]; + _CPToolTipCurrentToolTipTimer = nil; + } + + if (_CPToolTipCurrentToolTip) + { + [_CPToolTipCurrentToolTip close]; + _CPToolTipCurrentToolTip = nil; + } +} + +/*! @ignore + Schedule a tooltip for the given view + @param aView the view that might display the tooltip +*/ ++ (void)scheduleToolTipForView:(CPView)aView +{ + if (![aView toolTip] || ![[aView toolTip] length]) + return; + + [_CPToolTip invalidateCurrentToolTipIfNeeded]; + + var callbackFunction = function() { + [_CPToolTip invalidateCurrentToolTipIfNeeded]; + _CPToolTipCurrentToolTip = [_CPToolTip toolTipWithString:[aView toolTip]]; + }; + + _CPToolTipCurrentToolTipTimer = [CPTimer scheduledTimerWithTimeInterval:_CPToolTipDelay + callback:callbackFunction + repeats:NO]; +} + + /*! Returns an initialized _CPToolTip with the given text and attach it to given view. @param aString the content of the tooltip */