Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cappuccino/cappuccino
Browse files Browse the repository at this point in the history
  • Loading branch information
aljungberg committed Oct 22, 2012
2 parents 4bedd52 + a973be2 commit f4dc08f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 56 deletions.
55 changes: 2 additions & 53 deletions AppKit/CPView.j
Expand Up @@ -98,9 +98,6 @@ var CPViewFlags = { },
CPViewHasCustomDrawRect = 1 << 0,
CPViewHasCustomLayoutSubviews = 1 << 1;

var CPCurrentToolTip,
CPCurrentToolTipTimer,
CPToolTipDelay = 1.0;

/*!
@ingroup appkit
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions AppKit/Platform/DOM/CPPlatformWindow+DOM.j
Expand Up @@ -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];

Expand Down Expand Up @@ -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);

Expand Down
45 changes: 44 additions & 1 deletion AppKit/_CPToolTip.j
Expand Up @@ -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.
Expand All @@ -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
*/
Expand Down

0 comments on commit f4dc08f

Please sign in to comment.