diff --git a/AppKit/CPColorPicker.j b/AppKit/CPColorPicker.j index ea3afcd88..66af9b289 100644 --- a/AppKit/CPColorPicker.j +++ b/AppKit/CPColorPicker.j @@ -125,7 +125,8 @@ _brightnessSlider = [[CPSlider alloc] initWithFrame:CGRectMake(0, (aFrame.size.height - 34), aFrame.size.width, 15)]; [_brightnessSlider setValue:15.0 forThemeAttribute:@"track-width"]; - [_brightnessSlider setValue:[CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[CPColorPicker class]] pathForResource:@"brightness_bar.png"]]] forThemeAttribute:@"track-color"]; + var brightnessImage = [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[CPColorPicker class]] pathForResource:@"brightness_bar.png"] size:CGSizeMake(272, 20)]; + [_brightnessSlider setValue:[CPColor colorWithPatternImage:brightnessImage] forThemeAttribute:@"track-color"]; [_brightnessSlider setMinValue:0.0]; [_brightnessSlider setMaxValue:100.0]; diff --git a/AppKit/CPColorWell.j b/AppKit/CPColorWell.j index 15fa5343b..fb1b0f0dc 100644 --- a/AppKit/CPColorWell.j +++ b/AppKit/CPColorWell.j @@ -255,6 +255,8 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv var colorPanel = [CPColorPanel sharedColorPanel]; + [colorPanel setPlatformWindow:[[self window] platformWindow]]; + [colorPanel setColor:_color]; [colorPanel orderFront:self]; } diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index 98ba7eaa7..9f880a537 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -411,6 +411,8 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); [self setThemeState:CPThemeStateEditable]; else [self unsetThemeState:CPThemeStateEditable]; + + [self updateTrackingAreas]; } /*! @@ -432,6 +434,8 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); // We only allow first responder status if the field is enabled. if (!shouldBeEnabled && [[self window] firstResponder] === self) [[self window] makeFirstResponder:nil]; + + [self updateTrackingAreas]; } /*! @@ -441,6 +445,8 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); - (void)setSelectable:(BOOL)aFlag { _isSelectable = aFlag; + + [self updateTrackingAreas]; } /*! @@ -999,14 +1005,11 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); [self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]]; } -- (void)mouseMoved:(CPEvent)anEvent -{ - [super mouseMoved:anEvent]; - [self _updateCursorForEvent:anEvent]; -} - - (void)mouseDown:(CPEvent)anEvent { + if (![self isEnabled]) + return [[self nextResponder] mouseDown:anEvent]; + // Don't track! (ever?) if ([self isEditable] && [self isEnabled]) { @@ -1261,27 +1264,6 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); [_delegate controlTextDidEndEditing:note]; } -- (void)_updateCursorForEvent:(CPEvent)anEvent -{ - var frame = CGRectMakeCopy([self frame]), - contentInset = [self currentValueForThemeAttribute:@"content-inset"]; - - frame = [[self superview] convertRectToBase:CGRectInsetByInset(frame, contentInset)]; - - if ([self isEnabled] && ([self isSelectable] || [self isEditable]) && CGRectContainsPoint(frame, [anEvent locationInWindow])) - { -#if PLATFORM(DOM) - self._DOMElement.style.cursor = "text"; -#endif - } - else - { -#if PLATFORM(DOM) - self._DOMElement.style.cursor = "default"; -#endif - } -} - /*! Returns the string in the text field. */ @@ -2202,4 +2184,29 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey", [_source setObjectValue:aValue]; } -@end \ No newline at end of file +@end + +@implementation CPTextField (CPTrackingArea) + +- (void)updateTrackingAreas +{ + [self removeAllTrackingAreas]; + + if ([self isEnabled] && (_isEditable || _isSelectable)) + { + var myBounds = CGRectMakeCopy([self bounds]), + contentInset = [self currentValueForThemeAttribute:@"content-inset"]; + + [self addTrackingArea:[[CPTrackingArea alloc] initWithRect:CGRectInsetByInset(myBounds, contentInset) + options:CPTrackingMouseEnteredAndExited | CPTrackingCursorUpdate | CPTrackingActiveInKeyWindow + owner:self + userInfo:nil]]; + } +} + +- (void)cursorUpdate:(CPEvent)anEvent +{ + [[CPCursor IBeamCursor] set]; +} + +@end diff --git a/AppKit/Platform/CPPlatformWindow.j b/AppKit/Platform/CPPlatformWindow.j index f73c9205f..16b1a4954 100644 --- a/AppKit/Platform/CPPlatformWindow.j +++ b/AppKit/Platform/CPPlatformWindow.j @@ -60,6 +60,7 @@ var PrimaryPlatformWindow = NULL; BOOL _mouseIsDown; BOOL _mouseDownIsRightClick; + int _firstMouseDownButton; CGPoint _lastMouseEventLocation; CPWindow _mouseDownWindow; CPTimeInterval _lastMouseUp; diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index fa54e8892..15d55a070 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -1245,12 +1245,16 @@ _CPPlatformWindowWillCloseNotification = @"_CPPlatformWindowWillCloseNotificatio { if (_mouseIsDown) { + if (aDOMEvent.button !== _firstMouseDownButton) + return; + event = _CPEventFromNativeMouseEvent(aDOMEvent, _mouseDownIsRightClick ? CPRightMouseUp : CPLeftMouseUp, location, modifierFlags, timestamp, windowNumber, nil, -1, CPDOMEventGetClickCount(_lastMouseUp, timestamp, location), 0, nil); _mouseIsDown = NO; _lastMouseUp = event; _mouseDownWindow = nil; _mouseDownIsRightClick = NO; + _firstMouseDownButton = -1; } if (_DOMEventMode) @@ -1270,6 +1274,16 @@ _CPPlatformWindowWillCloseNotification = @"_CPPlatformWindowWillCloseNotificatio _mouseDownIsRightClick = button == 2 || (CPBrowserIsOperatingSystem(CPMacOperatingSystem) && button == 0 && modifierFlags & CPControlKeyMask); + // If mouse is already down, that means that a second mouse button is pushed. This could interfere in mouse events treatment. Just ignore it. + // BUT we have to track which button will be first released. + if (_mouseIsDown) + { + _mouseDownIsRightClick = !_mouseDownIsRightClick; + return; + } + + _firstMouseDownButton = button; + if ((sourceElement.tagName === "INPUT" || sourceElement.tagName === "TEXTAREA") && sourceElement != _DOMFocusElement) { if ([CPPlatform supportsDragAndDrop])