Commit 996df135 authored by staikos's avatar staikos
Browse files

Add quite a bit of keyboard handling in editing and non-editing mode for

QtWebKit, as well as some focus fixes.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@23545 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 12b7163a
2007-06-14 George Staikos <staikos@kde.org>
Reviewed by Lars.
Implement missing tab support and a slight refactor.
* platform/qt/PlatformKeyboardEventQt.cpp:
(WebCore::keyIdentifierForQtKeyCode):
(WebCore::windowsKeyCodeForKeyEvent):
(WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
2007-06-14 Dave Hyatt <hyatt@apple.com>
 
Fix for Bugzilla bug 14806, missing text for bold/italic fonts in non-English Windows installs.
......@@ -125,6 +125,10 @@ static String keyIdentifierForQtKeyCode(int keyCode)
// Standard says that DEL becomes U+007F.
case Qt::Key_Delete:
return "U+007F";
case Qt::Key_Tab:
return "U+0009";
case Qt::Key_Backtab:
return "U+0009";
default:
return String::format("U+%04X", toupper(keyCode));
}
......@@ -168,6 +172,7 @@ static int windowsKeyCodeForKeyEvent(unsigned int keycode)
*/
case Qt::Key_Backspace:
return VK_BACK; // (08) BACKSPACE key
case Qt::Key_Backtab:
case Qt::Key_Tab:
return VK_TAB; // (09) TAB key
case Qt::Key_Clear:
......@@ -427,17 +432,18 @@ static int windowsKeyCodeForKeyEvent(unsigned int keycode)
PlatformKeyboardEvent::PlatformKeyboardEvent(QKeyEvent* event, bool isKeyUp)
{
const int state = event->modifiers();
m_text = event->text();
m_unmodifiedText = event->text(); // FIXME: not correct
m_keyIdentifier = keyIdentifierForQtKeyCode(event->key());
m_isKeyUp = isKeyUp;
m_autoRepeat = event->isAutoRepeat();
m_ctrlKey = (state & Qt::ControlModifier) != 0;
m_altKey = (state & Qt::AltModifier) != 0;
m_metaKey = (state & Qt::MetaModifier) != 0;
m_WindowsKeyCode = windowsKeyCodeForKeyEvent(event->key());
m_isKeypad = (event->modifiers() & Qt::KeypadModifier) != 0;
m_shiftKey = (event->modifiers() & Qt::ShiftModifier) != 0;
m_ctrlKey = (event->modifiers() & Qt::ControlModifier) != 0;
m_altKey = (event->modifiers() & Qt::AltModifier) != 0;
m_metaKey = (event->modifiers() & Qt::MetaModifier) != 0;
m_isKeypad = (state & Qt::KeypadModifier) != 0;
m_shiftKey = (state & Qt::ShiftModifier) != 0 || event->key() == Qt::Key_Backtab; // Simulate Shift+Tab with Key_Backtab
}
}
......
......@@ -25,6 +25,7 @@
#include "qwebpage_p.h"
#include "qwebframe_p.h"
#include "FocusController.h"
#include "FrameLoaderClientQt.h"
#include "Frame.h"
#include "FrameTree.h"
......@@ -36,6 +37,7 @@
#include "PlatformKeyboardEvent.h"
#include "PlatformWheelEvent.h"
#include "ResourceRequest.h"
#include "SelectionController.h"
#include "markup.h"
#include "RenderTreeAsText.h"
......@@ -51,10 +53,10 @@
#include "wtf/HashMap.h"
#include <qpainter.h>
#include <qdebug.h>
#include <qevent.h>
#include <qpainter.h>
#include <qscrollbar.h>
#include <qdebug.h>
using namespace WebCore;
......@@ -66,7 +68,7 @@ void QWebFramePrivate::init(QWebFrame *qframe, WebCore::Page *page, QWebFrameDat
q->setMidLineWidth(0);
q->setFrameShape(QFrame::NoFrame);
q->setMouseTracking(true);
q->setFocusPolicy(Qt::StrongFocus);
q->setFocusPolicy(Qt::ClickFocus);
q->verticalScrollBar()->setSingleStep(20);
q->horizontalScrollBar()->setSingleStep(20);
......@@ -98,18 +100,6 @@ void QWebFramePrivate::_q_adjustScrollbars()
vbar->setPageStep(viewportSize.height());
}
void QWebFramePrivate::_q_handleKeyEvent(QKeyEvent *ev, bool isKeyUp)
{
PlatformKeyboardEvent kevent(ev, isKeyUp);
if (!eventHandler)
return;
bool handled = eventHandler->keyEvent(kevent);
ev->setAccepted(handled);
}
QWebFrame::QWebFrame(QWebPage *parent, QWebFrameData *frameData)
: QAbstractScrollArea(parent)
, d(new QWebFramePrivate)
......@@ -283,7 +273,10 @@ void QWebFrame::mousePressEvent(QMouseEvent *ev)
if (!d->eventHandler)
return;
d->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 1));
if (ev->button() == Qt::RightButton)
d->eventHandler->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
else d->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 1));
setFocus();
}
void QWebFrame::mouseReleaseEvent(QMouseEvent *ev)
......@@ -292,6 +285,7 @@ void QWebFrame::mouseReleaseEvent(QMouseEvent *ev)
return;
d->eventHandler->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
setFocus();
}
void QWebFrame::wheelEvent(QWheelEvent *e)
......@@ -304,16 +298,95 @@ void QWebFrame::wheelEvent(QWheelEvent *e)
e->setAccepted(accepted);
if (!accepted)
QAbstractScrollArea::wheelEvent(e);
setFocus();
}
void QWebFrame::keyPressEvent(QKeyEvent *ev)
{
d->_q_handleKeyEvent(ev, false);
PlatformKeyboardEvent kevent(ev, false);
if (!d->eventHandler)
return;
bool handled = d->eventHandler->keyEvent(kevent);
if (handled) {
} else {
handled = true;
QScrollBar *h, *v;
h = horizontalScrollBar();
v = verticalScrollBar();
switch (ev->key()) {
case Qt::Key_Up:
v->setValue(v->value() - 10);
viewport()->update();
break;
case Qt::Key_Down:
v->setValue(v->value() + 10);
viewport()->update();
break;
case Qt::Key_Left:
h->setValue(h->value() - 10);
viewport()->update();
break;
case Qt::Key_Right:
h->setValue(h->value() + 10);
viewport()->update();
break;
case Qt::Key_PageUp:
v->setValue(v->value() - viewport()->height());
viewport()->update();
break;
case Qt::Key_PageDown:
v->setValue(v->value() + viewport()->height());
viewport()->update();
break;
default:
handled = false;
break;
}
}
ev->setAccepted(handled);
}
void QWebFrame::keyReleaseEvent(QKeyEvent *ev)
{
d->_q_handleKeyEvent(ev, true);
if (ev->isAutoRepeat()) {
ev->setAccepted(true);
return;
}
PlatformKeyboardEvent kevent(ev, true);
if (!d->eventHandler)
return;
bool handled = d->eventHandler->keyEvent(kevent);
ev->setAccepted(handled);
}
void QWebFrame::focusInEvent(QFocusEvent *e)
{
if (e->reason() != Qt::PopupFocusReason) {
d->frame->page()->focusController()->setFocusedFrame(d->frame);
d->frame->setIsActive(true);
}
QAbstractScrollArea::focusInEvent(e);
}
void QWebFrame::focusOutEvent(QFocusEvent *e)
{
QAbstractScrollArea::focusOutEvent(e);
if (e->reason() != Qt::PopupFocusReason) {
d->frame->selectionController()->clear();
d->frame->setIsActive(false);
}
}
bool QWebFrame::focusNextPrevChild(bool next)
{
Q_UNUSED(next)
return false;
}
/*!\reimp
......@@ -322,3 +395,4 @@ void QWebFrame::scrollContentsBy(int dx, int dy)
{
viewport()->scroll(dx, dy);
}
......@@ -72,6 +72,9 @@ protected:
virtual void keyPressEvent(QKeyEvent*);
virtual void keyReleaseEvent(QKeyEvent*);
virtual void scrollContentsBy(int dx, int dy);
virtual void focusInEvent(QFocusEvent *e);
virtual void focusOutEvent(QFocusEvent *e);
virtual bool focusNextPrevChild(bool next);
private:
friend class QWebPage;
......
......@@ -72,7 +72,6 @@ public:
QWebFrameData *frameData);
void _q_adjustScrollbars();
void _q_handleKeyEvent(QKeyEvent *ev, bool isKeyUp);
QWebFrame *q;
WebCore::FrameLoaderClientQt *frameLoaderClient;
......
2007-06-14 George Staikos <staikos@kde.org>
Reviewed by Lars.
Implement most of the editing commands, better focus handling, fix some
keyboard and mouse handling, and add keyboard navigation. May be
refactored later as the key switches are ugly.
* Api/qwebframe.cpp:
(QWebFramePrivate::init):
(QWebFrame::mousePressEvent):
(QWebFrame::mouseReleaseEvent):
(QWebFrame::wheelEvent):
(QWebFrame::keyPressEvent):
(QWebFrame::keyReleaseEvent):
(QWebFrame::focusInEvent):
(QWebFrame::focusOutEvent):
(QWebFrame::focusNextPrevChild):
* Api/qwebframe.h:
* Api/qwebframe_p.h:
* WebCoreSupport/EditorClientQt.cpp:
(WebCore::EditorClientQt::handleKeypress):
2007-06-14 George Staikos <staikos@kde.org>
Reviewed by Lars.
......
......@@ -33,6 +33,7 @@
#include "qwebpage.h"
#include "qwebpage_p.h"
#include "Document.h"
#include "EditCommandQt.h"
#include "Editor.h"
#include "FocusController.h"
......@@ -216,21 +217,30 @@ void EditorClientQt::toggleGrammarChecking()
void EditorClientQt::handleKeypress(KeyboardEvent* event)
{
Frame* frame = m_page->d->page->focusController()->focusedOrMainFrame();
if (!frame)
if (!frame || !frame->document()->focusedNode())
return;
const PlatformKeyboardEvent* kevent = event->keyEvent();
if (kevent && !kevent->isKeyUp()) {
Node* start = frame->selectionController()->start().node();
if (start && start->isContentEditable()) {
switch(kevent->WindowsKeyCode()) {
if (kevent->isKeyUp())
return;
Node* start = frame->selectionController()->start().node();
if (!start)
return;
// FIXME: refactor all of this to use Actions or something like them
if (start->isContentEditable()) {
switch(kevent->WindowsKeyCode()) {
case VK_RETURN:
frame->editor()->execCommand("InsertLineBreak");
break;
case VK_BACK:
frame->editor()->deleteWithDirection(SelectionController::BACKWARD,
CharacterGranularity, false, true);
CharacterGranularity, false, true);
break;
case VK_DELETE:
frame->editor()->deleteWithDirection(SelectionController::FORWARD,
CharacterGranularity, false, true);
CharacterGranularity, false, true);
break;
case VK_LEFT:
if (kevent->shiftKey())
......@@ -252,16 +262,86 @@ void EditorClientQt::handleKeypress(KeyboardEvent* event)
frame->editor()->execCommand("MoveDownAndModifySelection");
else frame->editor()->execCommand("MoveDown");
break;
case VK_RETURN:
frame->editor()->insertLineBreak();
case VK_PRIOR: // PageUp
frame->editor()->execCommand("MoveUpByPageAndModifyCaret");
break;
case VK_NEXT: // PageDown
frame->editor()->execCommand("MoveDownByPageAndModifyCaret");
break;
case VK_TAB:
return;
default:
if (!kevent->ctrlKey() && !kevent->altKey())
if (!kevent->ctrlKey() && !kevent->altKey() && !kevent->text().isEmpty()) {
frame->editor()->insertText(kevent->text(), event);
}
event->setDefaultHandled();
} else if (kevent->ctrlKey()) {
switch (kevent->WindowsKeyCode()) {
case VK_A:
frame->editor()->execCommand("SelectAll");
break;
case VK_B:
frame->editor()->execCommand("ToggleBold");
break;
case VK_C:
frame->editor()->execCommand("Copy");
break;
case VK_I:
frame->editor()->execCommand("ToggleItalic");
break;
case VK_V:
frame->editor()->execCommand("Paste");
break;
case VK_X:
frame->editor()->execCommand("Cut");
break;
case VK_Y:
frame->editor()->execCommand("Redo");
break;
case VK_Z:
frame->editor()->execCommand("Undo");
break;
default:
return;
}
} else return;
}
} else {
switch (kevent->WindowsKeyCode()) {
case VK_UP:
frame->editor()->execCommand("MoveUp");
break;
case VK_DOWN:
frame->editor()->execCommand("MoveDown");
break;
case VK_PRIOR: // PageUp
frame->editor()->execCommand("MoveUpByPageAndModifyCaret");
break;
case VK_NEXT: // PageDown
frame->editor()->execCommand("MoveDownByPageAndModifyCaret");
break;
case VK_HOME:
if (kevent->ctrlKey())
frame->editor()->execCommand("MoveToBeginningOfDocument");
break;
case VK_END:
if (kevent->ctrlKey())
frame->editor()->execCommand("MoveToEndOfDocument");
break;
default:
if (kevent->ctrlKey()) {
switch(kevent->WindowsKeyCode()) {
case VK_A:
frame->editor()->execCommand("SelectAll");
break;
case VK_C: case VK_X:
frame->editor()->execCommand("Copy");
break;
default:
return;
}
} else return;
}
}
event->setDefaultHandled();
}
void EditorClientQt::handleInputMethodKeypress(KeyboardEvent*)
......
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