Merge revision 799 changes:
- Mac: Trigger keydown events for single keystrokes (issue #664). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1025@801 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
494b676c5f
commit
b0435f2ffa
|
@ -80,6 +80,9 @@ struct WebDropData;
|
|||
- (BOOL)isOpaque;
|
||||
- (void)setFrame:(NSRect)frameRect;
|
||||
|
||||
// Forward the keyboard event to the editor
|
||||
- (void)forwardKeyEventToEditor: (NSEvent *)theEvent;
|
||||
|
||||
// Register this WebView as a drag/drop target.
|
||||
- (void)registerDragDrop;
|
||||
|
||||
|
|
|
@ -198,6 +198,9 @@ void ExtractUnderlines(
|
|||
// This code is mostly copied and adapted from
|
||||
// content/browser/renderer_host/render_widget_host_mac
|
||||
- (void)keyDown:(NSEvent *)theEvent {
|
||||
if (browser_ && browser_->UIT_GetWebView())
|
||||
browser_->UIT_GetWebViewHost()->KeyEvent(theEvent);
|
||||
|
||||
// Records the current marked text state, so that we can know if the marked
|
||||
// text was deleted or not after handling the key down event.
|
||||
BOOL oldHasMarkedText = hasMarkedText_;
|
||||
|
@ -208,7 +211,7 @@ void ExtractUnderlines(
|
|||
if (hasMarkedText_ && underlines_.size() <= 1) {
|
||||
// Check for backspace or delete.
|
||||
if ([theEvent keyCode] == 0x33 || [theEvent keyCode] == 0x75)
|
||||
browser_->UIT_GetWebViewHost()->KeyEvent(theEvent);
|
||||
[self forwardKeyEventToEditor: theEvent];
|
||||
}
|
||||
|
||||
textToBeInserted_.clear();
|
||||
|
@ -235,7 +238,7 @@ void ExtractUnderlines(
|
|||
keyboard_event.text[1] = 0;
|
||||
browser_->UIT_GetWebView()->handleInputEvent(keyboard_event);
|
||||
} else {
|
||||
browser_->UIT_GetWebViewHost()->KeyEvent(theEvent);
|
||||
[self forwardKeyEventToEditor: theEvent];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,6 +269,46 @@ void ExtractUnderlines(
|
|||
}
|
||||
}
|
||||
|
||||
- (void)forwardKeyEventToEditor: (NSEvent *)theEvent {
|
||||
if ([theEvent type] != NSKeyDown)
|
||||
return;
|
||||
|
||||
if ([theEvent modifierFlags] & (NSNumericPadKeyMask | NSFunctionKeyMask)) {
|
||||
// Don't send a Char event for non-char keys like arrows, function keys and
|
||||
// clear.
|
||||
switch ([theEvent keyCode]) {
|
||||
case 81: // =
|
||||
case 75: // /
|
||||
case 67: // *
|
||||
case 78: // -
|
||||
case 69: // +
|
||||
case 76: // Enter
|
||||
case 65: // .
|
||||
case 82: // 0
|
||||
case 83: // 1
|
||||
case 84: // 2
|
||||
case 85: // 3
|
||||
case 86: // 4
|
||||
case 87: // 5
|
||||
case 88: // 6
|
||||
case 89: // 7
|
||||
case 91: // 8
|
||||
case 92: // 9
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (browser_ && browser_->UIT_GetWebView()) {
|
||||
WebKeyboardEvent keyboard_event(
|
||||
WebInputEventFactory::keyboardEvent(theEvent));
|
||||
keyboard_event.type = WebInputEvent::Char;
|
||||
browser_->UIT_GetWebViewHost()->SetLastKeyEvent(keyboard_event);
|
||||
browser_->UIT_GetWebView()->handleInputEvent(keyboard_event);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)keyUp:(NSEvent *)theEvent {
|
||||
if (browser_ && browser_->UIT_GetWebView())
|
||||
browser_->UIT_GetWebViewHost()->KeyEvent(theEvent);
|
||||
|
|
|
@ -106,6 +106,9 @@ class WebWidgetHost {
|
|||
WebKit::WebScreenInfo GetScreenInfo();
|
||||
|
||||
WebKit::WebKeyboardEvent GetLastKeyEvent() const { return last_key_event_; }
|
||||
|
||||
void SetLastKeyEvent(WebKit::WebKeyboardEvent keyEvent)
|
||||
{ last_key_event_ = keyEvent; }
|
||||
|
||||
void SetTooltipText(const CefString& tooltip_text);
|
||||
|
||||
|
|
|
@ -318,43 +318,6 @@ void WebWidgetHost::KeyEvent(NSEvent *event) {
|
|||
WebKeyboardEvent keyboard_event(WebInputEventFactory::keyboardEvent(event));
|
||||
last_key_event_ = keyboard_event;
|
||||
webwidget_->handleInputEvent(keyboard_event);
|
||||
|
||||
if ([event type] != NSKeyDown)
|
||||
return;
|
||||
|
||||
if ([event modifierFlags] & (NSNumericPadKeyMask | NSFunctionKeyMask)) {
|
||||
// Don't send a Char event for non-char keys like arrows, function keys and
|
||||
// clear.
|
||||
switch ([event keyCode]) {
|
||||
case 81: // =
|
||||
case 75: // /
|
||||
case 67: // *
|
||||
case 78: // -
|
||||
case 69: // +
|
||||
case 76: // Enter
|
||||
case 65: // .
|
||||
case 82: // 0
|
||||
case 83: // 1
|
||||
case 84: // 2
|
||||
case 85: // 3
|
||||
case 86: // 4
|
||||
case 87: // 5
|
||||
case 88: // 6
|
||||
case 89: // 7
|
||||
case 91: // 8
|
||||
case 92: // 9
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Send a Char event here to emulate the keyboard events.
|
||||
// TODO(hbono): Bug 20852 <http://crbug.com/20852> implement the NSTextInput
|
||||
// protocol and remove this code.
|
||||
keyboard_event.type = WebInputEvent::Char;
|
||||
last_key_event_ = keyboard_event;
|
||||
webwidget_->handleInputEvent(keyboard_event);
|
||||
}
|
||||
|
||||
void WebWidgetHost::SetFocus(bool enable) {
|
||||
|
|
Loading…
Reference in New Issue