bool EditorClientWx::handleEditingKeyboardEvent(KeyboardEvent* event) { Node* node = event->target()->toNode(); ASSERT(node); Frame* frame = node->document()->frame(); ASSERT(frame); const PlatformKeyboardEvent* keyEvent = event->keyEvent(); //NB: this is what windows does, but they also have a keypress event for Alt+Enter which clearly won't get hit with this if (!keyEvent || keyEvent->altKey()) // do not treat this as text input if Alt is down return false; Editor::Command command = frame->editor()->command(interpretKeyEvent(event)); if (keyEvent->type() == PlatformEvent::RawKeyDown) { // WebKit doesn't have enough information about mode to decide how commands that just insert text if executed via Editor should be treated, // so we leave it upon WebCore to either handle them immediately (e.g. Tab that changes focus) or if not to let a CHAR event be generated // (e.g. Tab that inserts a Tab character, or Enter). return !command.isTextInsertion() && command.execute(event); } if (command.execute(event)) return true; // Don't insert null or control characters as they can result in unexpected behaviour if (event->charCode() < ' ') return false; return frame->editor()->insertText(event->keyEvent()->text(), event); }
bool WebPage::handleEditingKeyboardEvent(KeyboardEvent* evt) { Node* node = evt->target()->toNode(); ASSERT(node); Frame* frame = node->document()->frame(); ASSERT(frame); const PlatformKeyboardEvent* keyEvent = evt->keyEvent(); if (!keyEvent) return false; Editor::Command command = frame->editor()->command(interpretKeyEvent(evt)); if (keyEvent->type() == PlatformKeyboardEvent::RawKeyDown) { // WebKit doesn't have enough information about mode to decide how commands that just insert text if executed via Editor 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). return !command.isTextInsertion() && command.execute(evt); } if (command.execute(evt)) return true; // Don't insert null or control characters as they can result in unexpected behaviour if (evt->charCode() < ' ') return false; return frame->editor()->insertText(evt->keyEvent()->text(), evt); }
// Like interpretKeyEvent, but with pressing down OSModifier+|keyCode|. // OSModifier is the platform's standard modifier key: control on most // platforms, but meta (command) on Mac. const char* interpretOSModifierKeyPress(char keyCode) { #if OS(MACOSX) WebInputEvent::Modifiers osModifier = WebInputEvent::MetaKey; #else WebInputEvent::Modifiers osModifier = WebInputEvent::ControlKey; #endif return interpretKeyEvent(createFakeKeyboardEvent( keyCode, osModifier, WebInputEvent::RawKeyDown)); }
TEST_F(KeyboardTest, TestEscape) { WebKeyboardEvent keyboardEvent; setupKeyDownEvent(&keyboardEvent, VKEY_ESCAPE, noModifiers); const char* result = interpretKeyEvent(keyboardEvent, PlatformEvent::RawKeyDown); EXPECT_STREQ("Cancel", result); }
// Like interpretKeyEvent, but with pressing down OSModifier+|keyCode|. // OSModifier is the platform's standard modifier key: control on most // platforms, but meta (command) on Mac. const char* interpretOSModifierKeyPress(char keyCode) { WebKeyboardEvent keyboardEvent; #if OS(MACOSX) WebInputEvent::Modifiers osModifier = WebInputEvent::MetaKey; #else WebInputEvent::Modifiers osModifier = WebInputEvent::ControlKey; #endif setupKeyDownEvent(&keyboardEvent, keyCode, osModifier); return interpretKeyEvent(keyboardEvent, PlatformEvent::RawKeyDown); }
void EditorClientBlackBerry::handleKeyboardEvent(KeyboardEvent* event) { ASSERT(event); const PlatformKeyboardEvent* platformEvent = event->keyEvent(); if (!platformEvent) return; ASSERT(event->target()->toNode()); Frame* frame = event->target()->toNode()->document()->frame(); ASSERT(frame); String commandName = interpretKeyEvent(event); // Check to see we are not trying to insert text on key down. ASSERT(!(event->type() == eventNames().keydownEvent && frame->editor()->command(commandName).isTextInsertion())); if (!commandName.isEmpty()) { // Hot key handling. Cancel processing mode. if (commandName != "DeleteBackward") m_webPagePrivate->m_inputHandler->setProcessingChange(false); if (frame->editor()->command(commandName).execute()) event->setDefaultHandled(); return; } if (!frame->editor()->canEdit()) return; // Text insertion commands should only be triggered from keypressEvent. // There is an assert guaranteeing this in // EventHandler::handleTextInputEvent. Note that windowsVirtualKeyCode // is not set for keypressEvent: special keys should have been already // handled in keydownEvent, which is called first. if (event->type() != eventNames().keypressEvent) return; // Don't insert null or control characters as they can result in unexpected behaviour. if (event->charCode() < ' ') return; // Don't insert anything if a modifier is pressed. if (event->ctrlKey() || event->altKey()) return; if (!platformEvent->text().isEmpty()) { if (frame->editor()->insertText(platformEvent->text(), event)) event->setDefaultHandled(); } }
static void handleKeyDown(Frame& frame, KeyboardEvent& event, const PlatformKeyboardEvent&) { String commandName = interpretKeyEvent(event); if (commandName.isEmpty()) return; // We shouldn't insert text through the editor. Let WebCore decide // how to handle that (say, Tab, which could also be used to // change focus). Editor::Command command = frame.editor().command(commandName); if (command.isTextInsertion()) return; command.execute(); event.setDefaultHandled(); }
static void handleKeyPress(Frame& frame, KeyboardEvent& event, const PlatformKeyboardEvent& platformEvent) { String commandName = interpretKeyEvent(event); if (!commandName.isEmpty()) { frame.editor().command(commandName).execute(); event.setDefaultHandled(); return; } // Don't insert null or control characters as they can result in unexpected behaviour if (event.charCode() < ' ') return; // Don't insert anything if a modifier is pressed and it has not been handled yet if (platformEvent.ctrlKey() || platformEvent.altKey()) return; if (frame.editor().insertText(platformEvent.text(), &event)) event.setDefaultHandled(); }
void EditorClientAndroid::handleKeyboardEvent(KeyboardEvent* event) { ASSERT(m_page); Frame* frame = m_page->focusController()->focusedOrMainFrame(); if (!frame) return; const PlatformKeyboardEvent* keyEvent = event->keyEvent(); // TODO: If the event is not coming from Android Java, e.g. from JavaScript, // PlatformKeyboardEvent is null. We should support this later. if (!keyEvent) return; Editor::Command command = frame->editor()->command(interpretKeyEvent(event)); if (keyEvent->type() == PlatformKeyboardEvent::RawKeyDown) { if (!command.isTextInsertion() && command.execute(event)) { // This function mimics the Windows version. However, calling event->setDefaultHandled() // prevents the javascript key events for the delete key from happening. // Update: Safari doesn't send delete key events to javascript so // we will mimic that behavior. event->setDefaultHandled(); } return; } if (command.execute(event)) { event->setDefaultHandled(); return; } // Don't insert null or control characters as they can result in unexpected behaviour if (event->charCode() < ' ') return; if (frame->editor()->insertText(keyEvent->text(), event)) event->setDefaultHandled(); }
const char* interpretDomKey(const char* key) { return interpretKeyEvent(createFakeKeyboardEvent( 0, noModifiers, WebInputEvent::RawKeyDown, key)); }
// Like interpretKeyEvent, but with typing a newline. const char* interpretNewLine(int modifiers) { return interpretKeyEvent( createFakeKeyboardEvent('\r', modifiers, WebInputEvent::Char)); }
// Like interpretKeyEvent, but with pressing down ctrl+|keyCode|. const char* interpretCtrlKeyPress(char keyCode) { return interpretKeyEvent(createFakeKeyboardEvent( keyCode, WebInputEvent::ControlKey, WebInputEvent::RawKeyDown)); }
// Like interpretKeyEvent, but with typing a tab. const char* interpretTab(int modifiers) { WebKeyboardEvent keyboardEvent; setupKeyDownEvent(&keyboardEvent, '\t', modifiers); return interpretKeyEvent(keyboardEvent, PlatformEvent::Char); }
// Like interpretKeyEvent, but with pressing down ctrl+|keyCode|. const char* interpretCtrlKeyPress(char keyCode) { WebKeyboardEvent keyboardEvent; setupKeyDownEvent(&keyboardEvent, keyCode, WebInputEvent::ControlKey); return interpretKeyEvent(keyboardEvent, PlatformEvent::RawKeyDown); }
bool EditorClientImpl::handleEditingKeyboardEvent(KeyboardEvent* evt) { const PlatformKeyboardEvent* keyEvent = evt->keyEvent(); // do not treat this as text input if it's a system key event if (!keyEvent || keyEvent->isSystemKey()) return false; Frame* frame = evt->target()->toNode()->document()->frame(); if (!frame) return false; String commandName = interpretKeyEvent(evt); Editor::Command command = frame->editor()->command(commandName); if (keyEvent->type() == PlatformEvent::RawKeyDown) { // WebKit doesn't have enough information about mode to decide how // commands that just insert text if executed via Editor 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). if (command.isTextInsertion() || commandName.isEmpty()) return false; if (command.execute(evt)) { if (m_webView->client()) m_webView->client()->didExecuteCommand(WebString(commandName)); return true; } return false; } if (command.execute(evt)) { if (m_webView->client()) m_webView->client()->didExecuteCommand(WebString(commandName)); return true; } // Here we need to filter key events. // On Gtk/Linux, it emits key events with ASCII text and ctrl on for ctrl-<x>. // In Webkit, EditorClient::handleKeyboardEvent in // WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp drop such events. // On Mac, it emits key events with ASCII text and meta on for Command-<x>. // These key events should not emit text insert event. // Alt key would be used to insert alternative character, so we should let // through. Also note that Ctrl-Alt combination equals to AltGr key which is // also used to insert alternative character. // http://code.google.com/p/chromium/issues/detail?id=10846 // Windows sets both alt and meta are on when "Alt" key pressed. // http://code.google.com/p/chromium/issues/detail?id=2215 // Also, we should not rely on an assumption that keyboards don't // send ASCII characters when pressing a control key on Windows, // which may be configured to do it so by user. // See also http://en.wikipedia.org/wiki/Keyboard_Layout // FIXME(ukai): investigate more detail for various keyboard layout. if (evt->keyEvent()->text().length() == 1) { UChar ch = evt->keyEvent()->text()[0U]; // Don't insert null or control characters as they can result in // unexpected behaviour if (ch < ' ') return false; #if !OS(WINDOWS) // Don't insert ASCII character if ctrl w/o alt or meta is on. // On Mac, we should ignore events when meta is on (Command-<x>). if (ch < 0x80) { if (evt->keyEvent()->ctrlKey() && !evt->keyEvent()->altKey()) return false; #if OS(DARWIN) if (evt->keyEvent()->metaKey()) return false; #endif } #endif } if (!frame->editor()->canEdit()) return false; return frame->editor()->insertText(evt->keyEvent()->text(), evt); }
bool EditorClientWinCE::handleEditingKeyboardEvent(KeyboardEvent* event) { Node* node = event->target()->toNode(); ASSERT(node); Frame* frame = node->document()->frame(); ASSERT(frame); const PlatformKeyboardEvent* keyEvent = event->keyEvent(); if (!keyEvent) return false; bool caretBrowsing = frame->settings()->caretBrowsingEnabled(); if (caretBrowsing) { switch (keyEvent->windowsVirtualKeyCode()) { case VK_LEFT: frame->selection()->modify(keyEvent->shiftKey() ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove, DirectionLeft, keyEvent->ctrlKey() ? WordGranularity : CharacterGranularity, UserTriggered); return true; case VK_RIGHT: frame->selection()->modify(keyEvent->shiftKey() ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove, DirectionRight, keyEvent->ctrlKey() ? WordGranularity : CharacterGranularity, UserTriggered); return true; case VK_UP: frame->selection()->modify(keyEvent->shiftKey() ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove, DirectionBackward, keyEvent->ctrlKey() ? ParagraphGranularity : LineGranularity, UserTriggered); return true; case VK_DOWN: frame->selection()->modify(keyEvent->shiftKey() ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove, DirectionForward, keyEvent->ctrlKey() ? ParagraphGranularity : LineGranularity, UserTriggered); return true; } } Editor::Command command = frame->editor()->command(interpretKeyEvent(event)); if (keyEvent->type() == PlatformEvent::RawKeyDown) { // WebKit doesn't have enough information about mode to decide how commands that just insert text if executed via Editor 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). return !command.isTextInsertion() && command.execute(event); } if (command.execute(event)) return true; // Don't insert null or control characters as they can result in unexpected behaviour if (event->charCode() < ' ') return false; // Don't insert anything if a modifier is pressed if (keyEvent->ctrlKey() || keyEvent->altKey()) return false; return frame->editor()->insertText(event->keyEvent()->text(), event); }
TEST_F(KeyboardTest, TestEscape) { const char* result = interpretKeyEvent(createFakeKeyboardEvent( VKEY_ESCAPE, noModifiers, WebInputEvent::RawKeyDown)); EXPECT_STREQ("Cancel", result); }