Fixed: wrong nextValidKeyView in a CPScrollView

Previously, the nextValidKeyView was wrong when the views were in a scrollView. Cappuccino did not take in account the possibility of scrolling, the lowest views were considered as outside of the platformWindow.

Now, it works as cocoa! The nextValidKeyView is the good one in a scrollView.

This pull request fixes another issue as well. A CPTextField can now become firstResponder even if the textField is not visible (as in cocoa). Previously a jump of the (html)window occurred to the textField. Now, cappuccino will internally scroll if needed to the element, focus it and then go back to previous scrolling position.
This commit is contained in:
Alexandre Wilhelm committed 2015-04-13 16:10:44 -07:00
1 parent 44c686f494
commit da15cc4de7
3 files changed
+75 -1

No files matched your search

+10 -1
View File
@@ -843,7 +843,16 @@ var CPComboBoxTextSubview = @"text",
// In FireFox this needs to be done in setTimeout, otherwise there is no caret
// We have to save the input element now, when we lose focus it will change.
var element = [self _inputElement];
window.setTimeout(function() { element.focus(); }, 0);
window.setTimeout(function() {
// This will prevent to jump to the focused element
var previousScrollingOrigin = [self _scrollToVisibleRectAndReturnPreviousOrigin];
element.focus();
[self _restorePreviousScrollingOrigin:previousScrollingOrigin];
}, 0);
#endif
return NO;
+59
View File
@@ -1,3 +1,4 @@
<<<<<<< Local Changes
/*
* CPTextField.j
* AppKit
@@ -28,6 +29,7 @@
@import "_CPImageAndTextView.j"
@class CPPasteboard
@class CPScrollView
@global CPApp
@global CPStringPboardType
@@ -88,7 +90,12 @@ function CPTextFieldBlurFunction(anEvent, owner, domElement, inputElement, resig
{
window.setTimeout(function()
{
// This will prevent to jump to the focused element
var previousScrollingOrigin = [owner _scrollToVisibleRectAndReturnPreviousOrigin];
inputElement.focus();
[owner _restorePreviousScrollingOrigin:previousScrollingOrigin];
}, 0.0);
}
}
@@ -643,6 +650,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
_stringValue = [self stringValue];
#if PLATFORM(DOM)
[self _setCSSStyleForInputElement];
@@ -672,8 +680,13 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
if (CPTextFieldInputOwner !== self)
return;
// This will prevent to jump to the focused element
var previousScrollingOrigin = [self _scrollToVisibleRectAndReturnPreviousOrigin];
element.focus();
[self _restorePreviousScrollingOrigin:previousScrollingOrigin];
// Select the text if the textfield became first responder through keyboard interaction
if (!_willBecomeFirstResponderByClick)
[self _selectText:self immediately:YES];
@@ -783,7 +796,13 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
// even if the value has not changed.
if ([self _valueIsValid:newValue] === NO)
{
// This will prevent to jump to the focused element
var previousScrollingOrigin = [self _scrollToVisibleRectAndReturnPreviousOrigin];
element.focus();
[self _restorePreviousScrollingOrigin:previousScrollingOrigin];
return NO;
}
}
@@ -1951,17 +1970,55 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
if (!wind)
return NO;
var scrollView = [self enclosingScrollView],
previousContentViewBoundsOrigin;
// Here we scroll to the textField, otherwise the textField could not be in the usable platformRect
var previousScrollingOrigin = [self _scrollToVisibleRectAndReturnPreviousOrigin];
var frame = [self convertRectToBase:[self contentRectForBounds:[self bounds]]],
usableRect = [[wind platformWindow] usableContentFrame];
frame.origin = [wind convertBaseToGlobal:frame.origin];
// Here we restore the the previous scrolling posiition
[self _restorePreviousScrollingOrigin:previousScrollingOrigin];
return (CGRectGetMinX(frame) >= CGRectGetMinX(usableRect) &&
CGRectGetMaxX(frame) <= CGRectGetMaxX(usableRect) &&
CGRectGetMinY(frame) >= CGRectGetMinY(usableRect) &&
CGRectGetMaxY(frame) <= CGRectGetMaxY(usableRect));
}
/*!
@ignore
*/
- (CGPoint)_scrollToVisibleRectAndReturnPreviousOrigin
{
var scrollView = [self enclosingScrollView],
previousContentViewBoundsOrigin;
// Here we scroll to the textField, otherwise the textField could not be in the usable platformRect
if ([scrollView isKindOfClass:[CPScrollView class]])
{
previousContentViewBoundsOrigin = CGPointMakeCopy([[scrollView contentView] boundsOrigin]);
if(![[self superview] scrollRectToVisible:[self frame]])
previousContentViewBoundsOrigin = nil;
}
return previousContentViewBoundsOrigin;
}
/*!
@ignore
*/
- (void)_restorePreviousScrollingOrigin:(CGPoint)scrollingOrigin
{
if (scrollingOrigin)
[[[self enclosingScrollView] contentView] setBoundsOrigin:scrollingOrigin];
}
@end
var secureStringForString = function(aString)
@@ -2111,3 +2168,5 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
}
@end
=======
>>>>>>> External Changes
+6
View File
@@ -457,7 +457,13 @@ CPTokenFieldDeleteButtonType = 1;
window.setTimeout(function()
{
// This will prevent to jump to the focused element
var previousScrollingOrigin = [self _scrollToVisibleRectAndReturnPreviousOrigin];
element.focus();
[self _restorePreviousScrollingOrigin:previousScrollingOrigin];
CPTokenFieldInputOwner = self;
}, 0.0);