From d1e31da2e5aa1195c5530a07265ca1f040579c0e Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Wed, 8 Jul 2015 13:34:57 -0700 Subject: [PATCH] Fixed: selection did not work in Cappuccino when doing a right click or dragging Previously, the selection of a textField did not work as expected when the user did a right click or a drag even if the label was set to none selectable. Now, with the css style user-select, a textField can only be selected if it is selectable and enable. Credit to @primalmotion --- AppKit/CPTextField.j | 17 +++++++++++++++++ AppKit/Platform/DOM/CPPlatformWindow+DOM.j | 1 + 2 files changed, 18 insertions(+) diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index 74c670605..2340467ff 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -432,6 +432,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 _setCSSSelectionStyleForDOMElement]; } /*! @@ -441,6 +443,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); - (void)setSelectable:(BOOL)aFlag { _isSelectable = aFlag; + [self _setCSSSelectionStyleForDOMElement]; } /*! @@ -700,6 +703,20 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); return YES; } +/*! + Set the selection css style for the DOM element of the textField + @ignore +*/ +- (void)_setCSSSelectionStyleForDOMElement +{ +#if PLATFORM (DOM) + if (_isSelectable && [self isEnabled]) + _DOMElement.style[CPBrowserStyleProperty(@"user-select")] = @"text"; + else + _DOMElement.style[CPBrowserStyleProperty(@"user-select")] = @"none"; +#endif +} + /*! Set the css style for the input element of the textField @ignore diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index fa6dd7ec8..e96a5708c 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -365,6 +365,7 @@ _CPPlatformWindowWillCloseNotification = @"_CPPlatformWindowWillCloseNotificatio _DOMBodyElement.style["-khtml-user-select"] = "none"; _DOMBodyElement.webkitTouchCallout = "none"; + _DOMBodyElement.style[CPBrowserStyleProperty(@"user-select")] = @"none"; [self createDOMElements]; [self _addLayers];