Commit d1ecae1d authored by ap@apple.com's avatar ap@apple.com

Reviewed by Darin Adler.

        https://bugs.webkit.org/show_bug.cgi?id=57260
        Clean up text input code a little

WebKit/mac:
        * WebCoreSupport/WebEditorClient.mm:
        (WebEditorClient::handleKeyboardEvent):
        (WebEditorClient::handleInputMethodKeydown):
        * WebView/WebHTMLViewInternal.h:
        Renamed _interceptEditingKeyEvent:shouldSaveCommand:, becasue it doesn't really intercept
        anything. It's just a version it interpretKeyEvents: that tells us whether it was handled,
        and also possibly saves resulting commands for later execution.

        * WebView/WebHTMLView.mm:
        (-[WebHTMLView _interpretKeyEvent:savingCommands:]): Changed to use early return. Changed
        return value in case platformEvent is null to be less mysterious. Moved receivedNOOP from
        WebHTMLViewPrivate to WebHTMLViewInterpretKeyEventsParameters, as this is just part of event
        handling state, like the other booleans there. Don't call interpretKeyEvents: again simply
        because the first call resulted in no saved commands, becasue it's confusing and apparently
        useless (I couldn't find any broken behavior).
        (-[WebHTMLView unmarkText]): Cleaned upo BOOL vs. bool constants.
        (-[WebHTMLView setMarkedText:selectedRange:]): Ditto.
        (-[WebHTMLView doCommandBySelector:]): Ditto.
        (-[WebHTMLView insertText:]): Ditto.

        * WebView/WebViewInternal.h: There was no _interceptEditingKeyEvent:shouldSaveCommand:
        method on WebView.

WebKit2:
        * UIProcess/API/mac/WKView.mm:
        (-[WKView doCommandBySelector:]): This NSTextInput protocol method lacked a LOG() call.
        (-[WKView keyDown:]): Added (possibly useless) event protection to match performKeyEquivalent:
        and also WebKit1.

        * WebProcess/WebPage/mac/WebPageMac.mm: Removed an obsolete comment.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@82148 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b9d6dd41
2011-03-28 Alexey Proskuryakov <ap@apple.com>
Reviewed by Darin Adler.
https://bugs.webkit.org/show_bug.cgi?id=57260
Clean up text input code a little
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::handleKeyboardEvent):
(WebEditorClient::handleInputMethodKeydown):
* WebView/WebHTMLViewInternal.h:
Renamed _interceptEditingKeyEvent:shouldSaveCommand:, becasue it doesn't really intercept
anything. It's just a version it interpretKeyEvents: that tells us whether it was handled,
and also possibly saves resulting commands for later execution.
* WebView/WebHTMLView.mm:
(-[WebHTMLView _interpretKeyEvent:savingCommands:]): Changed to use early return. Changed
return value in case platformEvent is null to be less mysterious. Moved receivedNOOP from
WebHTMLViewPrivate to WebHTMLViewInterpretKeyEventsParameters, as this is just part of event
handling state, like the other booleans there. Don't call interpretKeyEvents: again simply
because the first call resulted in no saved commands, becasue it's confusing and apparently
useless (I couldn't find any broken behavior).
(-[WebHTMLView unmarkText]): Cleaned upo BOOL vs. bool constants.
(-[WebHTMLView setMarkedText:selectedRange:]): Ditto.
(-[WebHTMLView doCommandBySelector:]): Ditto.
(-[WebHTMLView insertText:]): Ditto.
* WebView/WebViewInternal.h: There was no _interceptEditingKeyEvent:shouldSaveCommand:
method on WebView.
2011-03-27 Jer Noble <jer.noble@apple.com>
Reviewed by Maciej Stachowiak.
......
......@@ -621,7 +621,7 @@ void WebEditorClient::handleKeyboardEvent(KeyboardEvent* event)
{
Frame* frame = event->target()->toNode()->document()->frame();
WebHTMLView *webHTMLView = [[kit(frame) frameView] documentView];
if ([webHTMLView _interceptEditingKeyEvent:event shouldSaveCommand:NO])
if ([webHTMLView _interpretKeyEvent:event savingCommands:NO])
event->setDefaultHandled();
}
......@@ -629,7 +629,7 @@ void WebEditorClient::handleInputMethodKeydown(KeyboardEvent* event)
{
Frame* frame = event->target()->toNode()->document()->frame();
WebHTMLView *webHTMLView = [[kit(frame) frameView] documentView];
if ([webHTMLView _interceptEditingKeyEvent:event shouldSaveCommand:YES])
if ([webHTMLView _interpretKeyEvent:event savingCommands:YES])
event->setDefaultHandled();
}
......
......@@ -462,11 +462,12 @@ static CachedResourceClient* promisedDataClient()
struct WebHTMLViewInterpretKeyEventsParameters {
KeyboardEvent* event;
BOOL eventWasHandled;
BOOL shouldSaveCommand;
bool eventWasHandled;
bool shouldSaveCommands;
bool receivedNOOP;
// The Input Method may consume an event and not tell us, in
// which case we should not bubble the event up the DOM
BOOL consumedByIM;
bool consumedByIM;
};
@interface WebHTMLViewPrivate : NSObject {
......@@ -523,7 +524,6 @@ struct WebHTMLViewInterpretKeyEventsParameters {
BOOL transparentBackground;
WebHTMLViewInterpretKeyEventsParameters* interpretKeyEventsParameters;
BOOL receivedNOOP;
WebDataSource *dataSource;
WebCore::CachedImage* promisedDragTIFFDataSource;
......@@ -5440,59 +5440,58 @@ static CGPoint coreGraphicsScreenPointForAppKitScreenPoint(NSPoint point)
[self _updateMouseoverWithFakeEvent];
}
- (BOOL)_interceptEditingKeyEvent:(KeyboardEvent*)event shouldSaveCommand:(BOOL)shouldSave
- (BOOL)_interpretKeyEvent:(KeyboardEvent*)event savingCommands:(BOOL)savingCommands
{
// Ask AppKit to process the key event -- it will call back with either insertText or doCommandBySelector.
ASSERT(!savingCommands || event->keypressCommands().isEmpty()); // Save commands once for each event.
WebHTMLViewInterpretKeyEventsParameters parameters;
parameters.eventWasHandled = false;
parameters.shouldSaveCommand = shouldSave;
parameters.shouldSaveCommands = savingCommands;
parameters.receivedNOOP = false;
// If we're intercepting the initial IM call we assume that the IM has consumed the event,
// and only change this assumption if one of the NSTextInput/Responder callbacks is used.
// We assume the IM will *not* consume hotkey sequences
parameters.consumedByIM = !event->metaKey() && shouldSave;
parameters.consumedByIM = savingCommands && !event->metaKey();
if (const PlatformKeyboardEvent* platformEvent = event->keyEvent()) {
NSEvent *macEvent = platformEvent->macEvent();
if ([macEvent type] == NSKeyDown && [_private->completionController filterKeyDown:macEvent])
return true;
if ([macEvent type] == NSFlagsChanged)
return false;
parameters.event = event;
_private->interpretKeyEventsParameters = &parameters;
_private->receivedNOOP = NO;
const Vector<KeypressCommand>& commands = event->keypressCommands();
bool hasKeypressCommand = !commands.isEmpty();
// FIXME: interpretKeyEvents doesn't match application key equivalents (such as Cmd+A),
// and sends noop: for those. As a result, we don't handle those from within WebCore,
// but send a full sequence of DOM events, including an unneeded keypress.
if (parameters.shouldSaveCommand || !hasKeypressCommand)
[self interpretKeyEvents:[NSArray arrayWithObject:macEvent]];
else {
size_t size = commands.size();
// Are there commands that would just cause text insertion if executed via Editor?
// WebKit doesn't have enough information about mode to decide how they should be treated, so we leave it upon WebCore
// to either handle them immediately (e.g. Tab that changes focus) or let a keypress event be generated
// (e.g. Tab that inserts a Tab character, or Enter).
bool haveTextInsertionCommands = false;
const PlatformKeyboardEvent* platformEvent = event->keyEvent();
if (!platformEvent)
return NO;
NSEvent *macEvent = platformEvent->macEvent();
if ([macEvent type] == NSKeyDown && [_private->completionController filterKeyDown:macEvent])
return YES;
if ([macEvent type] == NSFlagsChanged)
return NO;
parameters.event = event;
_private->interpretKeyEventsParameters = &parameters;
const Vector<KeypressCommand>& commands = event->keypressCommands();
if (savingCommands)
[self interpretKeyEvents:[NSArray arrayWithObject:macEvent]];
else {
size_t size = commands.size();
// Are there commands that would just cause text insertion if executed via Editor?
// WebKit doesn't have enough information about mode to decide how they should be treated, so we leave it upon WebCore
// to either handle them immediately (e.g. Tab that changes focus) or let a keypress event be generated
// (e.g. Tab that inserts a Tab character, or Enter).
bool haveTextInsertionCommands = false;
for (size_t i = 0; i < size; ++i) {
if ([self coreCommandBySelector:NSSelectorFromString(commands[i].commandName)].isTextInsertion())
haveTextInsertionCommands = true;
}
if (!haveTextInsertionCommands || platformEvent->type() == PlatformKeyboardEvent::Char) {
for (size_t i = 0; i < size; ++i) {
if ([self coreCommandBySelector:NSSelectorFromString(commands[i].commandName)].isTextInsertion())
haveTextInsertionCommands = true;
}
if (!haveTextInsertionCommands || platformEvent->type() == PlatformKeyboardEvent::Char) {
for (size_t i = 0; i < size; ++i) {
if (commands[i].commandName == "insertText:")
[self insertText:commands[i].text];
else
[self doCommandBySelector:NSSelectorFromString(commands[i].commandName)];
}
if (commands[i].commandName == "insertText:")
[self insertText:commands[i].text];
else
[self doCommandBySelector:NSSelectorFromString(commands[i].commandName)];
}
}
_private->interpretKeyEventsParameters = 0;
}
return (!_private->receivedNOOP && parameters.eventWasHandled) || parameters.consumedByIM;
_private->interpretKeyEventsParameters = 0;
return (!parameters.receivedNOOP && parameters.eventWasHandled) || parameters.consumedByIM;
}
- (WebCore::CachedImage*)promisedDragTIFFDataSource
......@@ -5838,8 +5837,8 @@ static CGPoint coreGraphicsScreenPointForAppKitScreenPoint(NSPoint point)
_private->interpretKeyEventsParameters = 0;
if (parameters) {
parameters->eventWasHandled = YES;
parameters->consumedByIM = NO;
parameters->eventWasHandled = true;
parameters->consumedByIM = false;
}
if (Frame* coreFrame = core([self _frame]))
......@@ -5877,8 +5876,8 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
_private->interpretKeyEventsParameters = 0;
if (parameters) {
parameters->eventWasHandled = YES;
parameters->consumedByIM = NO;
parameters->eventWasHandled = true;
parameters->consumedByIM = false;
}
Frame* coreFrame = core([self _frame]);
......@@ -5915,15 +5914,16 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
// The same call to interpretKeyEvents can do more than one command.
WebHTMLViewInterpretKeyEventsParameters* parameters = _private->interpretKeyEventsParameters;
if (parameters)
parameters->consumedByIM = NO;
parameters->consumedByIM = false;
if (selector == @selector(noop:)) {
_private->receivedNOOP = YES;
if (parameters)
parameters->receivedNOOP = true;
return;
}
KeyboardEvent* event = parameters ? parameters->event : 0;
bool shouldSaveCommand = parameters && parameters->shouldSaveCommand;
bool shouldSaveCommand = parameters && parameters->shouldSaveCommands;
if (event && shouldSaveCommand)
event->keypressCommands().append(KeypressCommand(NSStringFromSelector(selector)));
......@@ -5974,7 +5974,7 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
WebHTMLViewInterpretKeyEventsParameters* parameters = _private->interpretKeyEventsParameters;
_private->interpretKeyEventsParameters = 0;
if (parameters)
parameters->consumedByIM = NO;
parameters->consumedByIM = false;
// We don't support inserting an attributed string but input methods don't appear to require this.
RefPtr<Frame> coreFrame = core([self _frame]);
......@@ -6005,7 +6005,7 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
// We assume it's from the input method if we have marked text.
// FIXME: In theory, this could be wrong for some input methods, so we should try to find
// another way to determine if the call is from the input method
bool shouldSaveCommand = parameters && parameters->shouldSaveCommand;
bool shouldSaveCommand = parameters && parameters->shouldSaveCommands;
if (event && shouldSaveCommand && !isFromInputMethod) {
event->keypressCommands().append(KeypressCommand("insertText:", text));
_private->interpretKeyEventsParameters = parameters;
......@@ -6030,7 +6030,7 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
if (isFromInputMethod) {
// Allow doCommandBySelector: to be called after insertText: by resetting interpretKeyEventsParameters
_private->interpretKeyEventsParameters = parameters;
parameters->consumedByIM = YES;
parameters->consumedByIM = true;
return;
}
......
......@@ -49,7 +49,7 @@ namespace WebCore {
- (WebFrame *)_frame;
- (void)_lookUpInDictionaryFromMenu:(id)sender;
- (void)_hoverFeedbackSuspendedChanged;
- (BOOL)_interceptEditingKeyEvent:(WebCore::KeyboardEvent *)event shouldSaveCommand:(BOOL)shouldSave;
- (BOOL)_interpretKeyEvent:(WebCore::KeyboardEvent *)event savingCommands:(BOOL)savingCommands;
- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard;
- (NSEvent *)_mouseDownEvent;
#ifndef BUILDING_ON_TIGER
......
......@@ -57,7 +57,6 @@ namespace WebCore {
#ifdef __cplusplus
@interface WebView (WebViewEditingExtras)
- (BOOL)_interceptEditingKeyEvent:(WebCore::KeyboardEvent*)event shouldSaveCommand:(BOOL)shouldSave;
- (BOOL)_shouldChangeSelectedDOMRange:(DOMRange *)currentRange toDOMRange:(DOMRange *)proposedRange affinity:(NSSelectionAffinity)selectionAffinity stillSelecting:(BOOL)flag;
@end
......
2011-03-28 Alexey Proskuryakov <ap@apple.com>
Reviewed by Darin Adler.
https://bugs.webkit.org/show_bug.cgi?id=57260
Clean up text input code a little
* UIProcess/API/mac/WKView.mm:
(-[WKView doCommandBySelector:]): This NSTextInput protocol method lacked a LOG() call.
(-[WKView keyDown:]): Added (possibly useless) event protection to match performKeyEquivalent:
and also WebKit1.
* WebProcess/WebPage/mac/WebPageMac.mm: Removed an obsolete comment.
2011-03-28 Jeff Miller <jeffm@apple.com>
Reviewed by Adam Roben.
......
......@@ -1025,6 +1025,8 @@ static const short kIOHIDEventTypeScroll = 6;
- (void)doCommandBySelector:(SEL)selector
{
LOG(TextInput, "doCommandBySelector:\"%s\"", sel_getName(selector));
if (!_data->_isInInterpretKeyEvents) {
[super doCommandBySelector:selector];
return;
......@@ -1122,6 +1124,11 @@ static const short kIOHIDEventTypeScroll = 6;
- (void)keyDown:(NSEvent *)theEvent
{
// There's a chance that responding to this event will run a nested event loop, and
// fetching a new event might release the old one. Retaining and then autoreleasing
// the current event prevents that from causing a problem inside WebKit or AppKit code.
[[event retain] autorelease];
if (_data->_pluginComplexTextInputIdentifier) {
// Try feeding the keyboard event directly to the plug-in.
NSString *string = nil;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment