<commit_before>/*
Cursor support by browser:
    OS X 10.6/Chrome 8       : All
    OS X 10.6/Safari 5       : All
    OS X 10.6/Firefox 3      : All except disappearingItemCursor (no url() support)
    OS X 10.6/Firefox 3.5    : All except disappearingItemCursor (no url() support)
    OS X 10.6/Firefox 3.6    : All except disappearingItemCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor (no url() support)
    OS X 10.6/Firefox 4.0b10 : All
    OS X/Opera 9             : All except disappearingItemCursor, closedHandCursor, openHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor, resizeUpDownCursor, resizeLeftRightCursor  (no url() support)
    OS X/Opera 10            : All except disappearingItemCursor, closedHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor (no url() support)
    OS X/Opera 11            : All except disappearingItemCursor, closedHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor (no url() support)
    Win XP/Chrome 8          : All
    Win XP/Safari 5          : All
    Win XP/Firefox 3         : All
    Win XP/Firefox 3.5       : All
    Win XP/Firefox 3.6       : All
    Win XP/Firefox 4.0b10    : All
    Win XP/Opera 10          : All except disappearingItemCursor, closedHandCursor, openHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor, resizeUpDownCursor, resizeLeftRightCursor (no url() support)
    Win XP/Opera 11          : All except disappearingItemCursor, closedHandCursor, openHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor, resizeUpDownCursor, resizeLeftRightCursor (no url() support)
    Win XP/IE 7              : All
    Win XP/IE 8              : All
*/

@import <Foundation/CPObject.j>

@global CPApp

var currentCursor = nil,
    cursorStack = [],
    cursors = {},
    ieCursorMap = {};

@implementation CPCursor : CPObject
{
    CPString _cssString @accessors(readonly);
    CPString _hotSpot @accessors(readonly, getter=hotSpot);
    CPImage  _image @accessors(readonly, getter=image);
    BOOL     _isSetOnMouseEntered @accessors(readwrite, getter=isSetOnMouseEntered, setter=setOnMouseEntered:);
    BOOL     _isSetOnMouseExited @accessors(readwrite, getter=isSetOnMouseExited, setter=setOnMouseExited:);
}

+ (void)initialize
{
    if (self !== CPCursor)
        return;

    // IE < 9 does not support some CSS cursors, we map them to supported ones
    ieCursorMap = {
        "ew-resize":   "e-resize",
        "ns-resize":   "n-resize",
        "nesw-resize": "ne-resize",
        "nwse-resize": "nw-resize"
    };
}

- (id)initWithCSSString:(CPString)aString
{
    if (self = [super init])
        _cssString = aString;

    return self;
}

/*!
    Init a cursor with the given image and hotspot.
    hotspot is supported in CSS3 (but not IE).
*/
- (id)initWithImage:(CPImage)image hotSpot:(CGPoint)hotSpot
{
    _hotSpot = hotSpot;
    _image = image;
    return [self initWithCSSString:"url(" + [_image filename] + ")" + hotSpot.x + " " + hotSpot.y + ", auto"];
}

/*!
    Init a cursor with the given image and hotspot. This is provided
    for compliance with Cocoa. Note that foregroundColor and backgroundColor are ignored
    (as they are in Cocoa). See http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSCursor_Class/Reference/Reference.html
*/
- (id)initWithImage:(CPImage)image foregroundColorHint:(CPColor)foregroundColor backgroundColorHint:(CPColor)backgroundColor hotSpot:(CGPoint)aHotSpot
{
    return [self initWithImage:image hotSpot:aHotSpot];
}

+ (void)hide
{
    [self _setCursorCSS:@"none"]; // Not supported in IE < 9
}

+ (void)unhide
{
    [self _setCursorCSS:[currentCursor _cssString]];
}

+ (void)setHiddenUntilMouseMoves:(BOOL)flag
{
    if (flag)
        [CPCursor hide];
    else
        [CPCursor unhide];
}

- (void)pop
{
    [CPCursor pop];
}

+ (void)pop
{
    if (cursorStack.length > 1)
    {
        cursorStack.pop();
        currentCursor = cursorStack[cursorStack.length - 1];
    }
}

- (void)push
{
    cursorStack.push(self);
    currentCursor = cursorStack[cursorStack.length - 1];
}

- (void)set
{
    currentCursor = self;

#if PLATFORM(DOM)
    [[self class] _setCursorCSS:_cssString];
#endif
}

- (void)mouseEntered:(CPEvent)event
{
}

- (void)mouseExited:(CPEvent)event
{
}

+ (CPCursor)currentCursor
{
    return currentCursor;
}

+ (void)_setCursorCSS:(CPString)aString<commit_msg>Simplified currentCursor assignment.<commit_after>/*
Cursor support by browser:
    OS X 10.6/Chrome 8       : All
    OS X 10.6/Safari 5       : All
    OS X 10.6/Firefox 3      : All except disappearingItemCursor (no url() support)
    OS X 10.6/Firefox 3.5    : All except disappearingItemCursor (no url() support)
    OS X 10.6/Firefox 3.6    : All except disappearingItemCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor (no url() support)
    OS X 10.6/Firefox 4.0b10 : All
    OS X/Opera 9             : All except disappearingItemCursor, closedHandCursor, openHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor, resizeUpDownCursor, resizeLeftRightCursor  (no url() support)
    OS X/Opera 10            : All except disappearingItemCursor, closedHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor (no url() support)
    OS X/Opera 11            : All except disappearingItemCursor, closedHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor (no url() support)
    Win XP/Chrome 8          : All
    Win XP/Safari 5          : All
    Win XP/Firefox 3         : All
    Win XP/Firefox 3.5       : All
    Win XP/Firefox 3.6       : All
    Win XP/Firefox 4.0b10    : All
    Win XP/Opera 10          : All except disappearingItemCursor, closedHandCursor, openHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor, resizeUpDownCursor, resizeLeftRightCursor (no url() support)
    Win XP/Opera 11          : All except disappearingItemCursor, closedHandCursor, openHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor, resizeUpDownCursor, resizeLeftRightCursor (no url() support)
    Win XP/IE 7              : All
    Win XP/IE 8              : All
*/

@import <Foundation/CPObject.j>

@global CPApp

var currentCursor = nil,
    cursorStack = [],
    cursors = {},
    ieCursorMap = {};

@implementation CPCursor : CPObject
{
    CPString _cssString @accessors(readonly);
    CPString _hotSpot @accessors(readonly, getter=hotSpot);
    CPImage  _image @accessors(readonly, getter=image);
    BOOL     _isSetOnMouseEntered @accessors(readwrite, getter=isSetOnMouseEntered, setter=setOnMouseEntered:);
    BOOL     _isSetOnMouseExited @accessors(readwrite, getter=isSetOnMouseExited, setter=setOnMouseExited:);
}

+ (void)initialize
{
    if (self !== CPCursor)
        return;

    // IE < 9 does not support some CSS cursors, we map them to supported ones
    ieCursorMap = {
        "ew-resize":   "e-resize",
        "ns-resize":   "n-resize",
        "nesw-resize": "ne-resize",
        "nwse-resize": "nw-resize"
    };
}

- (id)initWithCSSString:(CPString)aString
{
    if (self = [super init])
        _cssString = aString;

    return self;
}

/*!
    Init a cursor with the given image and hotspot.
    hotspot is supported in CSS3 (but not IE).
*/
- (id)initWithImage:(CPImage)image hotSpot:(CGPoint)hotSpot
{
    _hotSpot = hotSpot;
    _image = image;
    return [self initWithCSSString:"url(" + [_image filename] + ")" + hotSpot.x + " " + hotSpot.y + ", auto"];
}

/*!
    Init a cursor with the given image and hotspot. This is provided
    for compliance with Cocoa. Note that foregroundColor and backgroundColor are ignored
    (as they are in Cocoa). See http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSCursor_Class/Reference/Reference.html
*/
- (id)initWithImage:(CPImage)image foregroundColorHint:(CPColor)foregroundColor backgroundColorHint:(CPColor)backgroundColor hotSpot:(CGPoint)aHotSpot
{
    return [self initWithImage:image hotSpot:aHotSpot];
}

+ (void)hide
{
    [self _setCursorCSS:@"none"]; // Not supported in IE < 9
}

+ (void)unhide
{
    [self _setCursorCSS:[currentCursor _cssString]];
}

+ (void)setHiddenUntilMouseMoves:(BOOL)flag
{
    if (flag)
        [CPCursor hide];
    else
        [CPCursor unhide];
}

- (void)pop
{
    [CPCursor pop];
}

+ (void)pop
{
    if (cursorStack.length > 1)
    {
        cursorStack.pop();
        currentCursor = cursorStack[cursorStack.length - 1];
    }
}

- (void)push
{
    cursorStack.push(self);
    currentCursor = self;
}

- (void)set
{
    currentCursor = self;

#if PLATFORM(DOM)
    [[self class] _setCursorCSS:_cssString];
#endif
}

- (void)mouseEntered:(CPEvent)event
{
}

- (void)mouseExited:(CPEvent)event
{
}

+ (CPCursor)currentCursor
{
    return currentCursor;
}

+ (void)_setCursorCSS:(CPString)aString
{'fraction_non_alphanumeric': 0.10444347636680462, 'fraction_numerical': 0.012306686996297103, 'mean_word_length': 3.4664396887159534, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1307074', 'n_tokens_mistral': 3067, 'n_tokens_neox': 2845, 'n_words': 712}