Commit 94f99ce2 authored by darin's avatar darin

Reviewed by Ken.

        - did keyboard event cleanup to follow up on the keyCode work I did before
        - fixed 3485558: key identifers use lowercase hex, but the W3C document shows uppercase
        - fixed 3485564: key identifier for the Return key should be "Enter"
        - fixed 3485579: letter keys generate different key identifiers depending on whether the shift key is down
        - fixed 3485568: keyboard event modifier key bits are uninitialized; may have incorrect values
        - fixed 3481514: which attribute for DOM events reports incorrect value
        - fixed 3452569: charCode attribute for DOM events not supported

        * khtml/dom/dom2_events.h: Added charCode.
        * khtml/dom/dom2_events.cpp:
        (UIEvent::keyCode): Call through to KeyboardEventImpl instead of doing the work here;
        better factoring.
        (UIEvent::charCode): Added. Calls through to KeyboardEventImpl.
        (UIEvent::which): Call keyCode in KeyboardEventImpl to share code.

        * khtml/ecma/kjs_events.h: Added charCode property for DOMUIEvent.
        * khtml/ecma/kjs_events.cpp: (DOMUIEvent::getValueProperty): Added charCode.
        * khtml/ecma/kjs_events.lut.h: Regenerated.

        * khtml/html/html_formimpl.h:
        * khtml/html/html_formimpl.cpp:
        (HTMLInputElementImpl::defaultEventHandler): Remove checks for "U+00000d" since we now use "Enter"
        for that key; also, we use capitalized hex, so it would have to change to "U+00000D" anyway.
        (HTMLSelectElementImpl::defaultEventHandler): Ditto.
        * khtml/html/html_inlineimpl.cpp: (HTMLAnchorElementImpl::defaultEventHandler): Ditto.

        * khtml/khtmlview.cpp: (KHTMLView::keyPressEvent): Put !APPLE_CHANGES around code we are not
        using. It was doing a switch based on Qt key codes, but the key value it was using to check
        was a Macintosh virtual key code, which could yield strange results when the codes happen to
        match. Safer and smaller code size not to do any of it at all.

        * khtml/rendering/render_form.cpp:
        (RenderLineEdit::RenderLineEdit): Use a KLineEdit instead of LineEditWidget for APPLE_CHANGES.
        Allows us to put !APPLE_CHANGES around more Qt key code stuff.
        (RenderLineEdit::select): Cast to KLineEdit instead of LineEditWidget.
        (ComboBoxWidget::event): Put !APPLE_CHANGES around more unneeded Qt key code stuff.
        (TextAreaWidget::event): Put !APPLE_CHANGES around more unneeded Qt key code stuff.

        * khtml/xml/dom2_eventsimpl.h: Made id() const and added keyCode() and charCode().
        * khtml/xml/dom2_eventsimpl.cpp:
        (KeyboardEventImpl::KeyboardEventImpl): Initialize all fields in the empty constructor.
        Initialize all the modifier bits in the main constructor; the old code assumed they started
        off false, which is not a safe assumption. Also set m_altGraphKey false. Eliminated the
        unneeded check of text() before calling identifier(). Also adapted for the name change from
        identifier() to keyIdentifier().
        (KeyboardEventImpl::keyCode): Added. Returns the Windows virtual key code for keydown and
        keyup events, and the Unicode character for all other events.
        (KeyboardEventImpl::charCode): Added. Returns the Unicode character.

        * kwq/KWQEvent.h: Changed QCustomEvent to be a typedef for QEvent.
        (QEvent::QEvent): Removed AccelAvailable, and added KParts, so I could remove some ugly
        constants from the KParts code.
        (QMouseEvent::button): Use a cast here since the field is now int.
        (QMouseEvent::state): Use a cast here since the field is now int.
        (QMouseEvent::stateAfter): Use a cast here since the field is now int, and use the new
        _stateAfter field.
        (QTimerEvent::QTimerEvent): Moved the constructor to be inline since it's so simple.
        (QKeyEvent::QKeyEvent): Removed type and button state parameters, now unneeded.
        Also removed now-unused _key, _ascii, and _count fields, and key(), ascii(),
        and count() functions.
        (QKeyEvent::state): Made inline.
        (QKeyEvent::isAccepted): Made inline.
        (QKeyEvent::text): Made inline.
        (QKeyEvent::isAutoRepeat): Made inline.
        (QKeyEvent::accept): Made inline.
        (QKeyEvent::ignore): Made inline.
        (QKeyEvent::unmodifiedText): Made inline.
        (QKeyEvent::keyIdentifier): Made inline and chnaged name from identifier().
        * kwq/KWQEvent.mm:
        (keyIdentifierForKeyEvent): Renamed from identifierForKeyText and changed parameter
        to be the event. Cleaned up the code a little bit, and wrote a comment or two.
        Changed from lowercase hex to uppercase, and called toupper on the key so that
        letter a-z would work properly. (A non-Unicode toupper is just the ticket here,
        because I am only sure we want to do this for a-z, not other lowercase characters.)
        (isKeypadEvent): Added. Uses virtual key codes to decide if a key event is a keypad
        event, so we can set the state flag correctly.
        (WindowsKeyCodeForKeyEvent): Added Clear key to the switch statement; it was missing.
        Changed to no longe use the characterCode helper function since this was the only
        place it was needed.
        (mouseButtonForEvent): Added. Similar logic to what was in KWQKHTMLPart before; better
        factoring to have it in here.
        (nonMouseButtonsForEvent): Ditto.
        (QMouseEvent::QMouseEvent): Rewrote constructors. One matches the one from Qt that's
        used in some places in KHTML code. The other takes an NSEvent and uses the new functions
        above to compute the button and state.
        (QKeyEvent::QKeyEvent): Computer type based on the passed-in NSEvent. Compute the
        auto-repeat flag based on the event and also the "forceAutoRepeat" parameter. Compute
        the button state based on the event too.

        * kwq/KWQKHTMLPart.h: Remove buttonForCurrentEvent and stateForCurrentEvent. Both
        are now in KWQEvent.mm.
        * kwq/KWQKHTMLPart.mm:
        (KWQKHTMLPart::keyEvent): Remove extra parameters in code that creates QKeyEvent, now
        that QKeyEvent can handle everything itself.
        (KWQKHTMLPart::mouseDown): Same thing as above, only for QMouseEvent.
        (KWQKHTMLPart::mouseDragged): Ditto.
        (KWQKHTMLPart::mouseUp): Ditto.
        (KWQKHTMLPart::mouseMoved): Ditto.
        (KWQKHTMLPart::sendContextMenuEvent): Ditto.

        * kwq/KWQKPartsEvent.h: Tweaked the class around a little so it can work without
        taking advantage of QCustomEvent's data pointer.
        * kwq/KWQKPartsEvent.mm:
        (KParts::Event::Event): Changed so it does a strdup on the event name and uses the
        new event type pre-allocated in KWQEvent.h for us.
        (KParts::Event::~Event): Free the event name.
        (KParts::Event::test): Reimplemented this.

        * kwq/KWQKPartsPart.h: (KParts::Part::event): Removed now-unnecessary cast to change
        a QCustomEvent into a QEvent.

        * kwq/KWQNamespace.h: Removed the Qt::Key enum. All the code that used it was already
        broken because of the mixup between Qt and Macintosh key codes.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5556 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a59e26d7
2003-11-17 Darin Adler <darin@apple.com>
Reviewed by Ken.
- did keyboard event cleanup to follow up on the keyCode work I did before
- fixed 3485558: key identifers use lowercase hex, but the W3C document shows uppercase
- fixed 3485564: key identifier for the Return key should be "Enter"
- fixed 3485579: letter keys generate different key identifiers depending on whether the shift key is down
- fixed 3485568: keyboard event modifier key bits are uninitialized; may have incorrect values
- fixed 3481514: which attribute for DOM events reports incorrect value
- fixed 3452569: charCode attribute for DOM events not supported
* khtml/dom/dom2_events.h: Added charCode.
* khtml/dom/dom2_events.cpp:
(UIEvent::keyCode): Call through to KeyboardEventImpl instead of doing the work here;
better factoring.
(UIEvent::charCode): Added. Calls through to KeyboardEventImpl.
(UIEvent::which): Call keyCode in KeyboardEventImpl to share code.
* khtml/ecma/kjs_events.h: Added charCode property for DOMUIEvent.
* khtml/ecma/kjs_events.cpp: (DOMUIEvent::getValueProperty): Added charCode.
* khtml/ecma/kjs_events.lut.h: Regenerated.
* khtml/html/html_formimpl.h:
* khtml/html/html_formimpl.cpp:
(HTMLInputElementImpl::defaultEventHandler): Remove checks for "U+00000d" since we now use "Enter"
for that key; also, we use capitalized hex, so it would have to change to "U+00000D" anyway.
(HTMLSelectElementImpl::defaultEventHandler): Ditto.
* khtml/html/html_inlineimpl.cpp: (HTMLAnchorElementImpl::defaultEventHandler): Ditto.
* khtml/khtmlview.cpp: (KHTMLView::keyPressEvent): Put !APPLE_CHANGES around code we are not
using. It was doing a switch based on Qt key codes, but the key value it was using to check
was a Macintosh virtual key code, which could yield strange results when the codes happen to
match. Safer and smaller code size not to do any of it at all.
* khtml/rendering/render_form.cpp:
(RenderLineEdit::RenderLineEdit): Use a KLineEdit instead of LineEditWidget for APPLE_CHANGES.
Allows us to put !APPLE_CHANGES around more Qt key code stuff.
(RenderLineEdit::select): Cast to KLineEdit instead of LineEditWidget.
(ComboBoxWidget::event): Put !APPLE_CHANGES around more unneeded Qt key code stuff.
(TextAreaWidget::event): Put !APPLE_CHANGES around more unneeded Qt key code stuff.
* khtml/xml/dom2_eventsimpl.h: Made id() const and added keyCode() and charCode().
* khtml/xml/dom2_eventsimpl.cpp:
(KeyboardEventImpl::KeyboardEventImpl): Initialize all fields in the empty constructor.
Initialize all the modifier bits in the main constructor; the old code assumed they started
off false, which is not a safe assumption. Also set m_altGraphKey false. Eliminated the
unneeded check of text() before calling identifier(). Also adapted for the name change from
identifier() to keyIdentifier().
(KeyboardEventImpl::keyCode): Added. Returns the Windows virtual key code for keydown and
keyup events, and the Unicode character for all other events.
(KeyboardEventImpl::charCode): Added. Returns the Unicode character.
* kwq/KWQEvent.h: Changed QCustomEvent to be a typedef for QEvent.
(QEvent::QEvent): Removed AccelAvailable, and added KParts, so I could remove some ugly
constants from the KParts code.
(QMouseEvent::button): Use a cast here since the field is now int.
(QMouseEvent::state): Use a cast here since the field is now int.
(QMouseEvent::stateAfter): Use a cast here since the field is now int, and use the new
_stateAfter field.
(QTimerEvent::QTimerEvent): Moved the constructor to be inline since it's so simple.
(QKeyEvent::QKeyEvent): Removed type and button state parameters, now unneeded.
Also removed now-unused _key, _ascii, and _count fields, and key(), ascii(),
and count() functions.
(QKeyEvent::state): Made inline.
(QKeyEvent::isAccepted): Made inline.
(QKeyEvent::text): Made inline.
(QKeyEvent::isAutoRepeat): Made inline.
(QKeyEvent::accept): Made inline.
(QKeyEvent::ignore): Made inline.
(QKeyEvent::unmodifiedText): Made inline.
(QKeyEvent::keyIdentifier): Made inline and chnaged name from identifier().
* kwq/KWQEvent.mm:
(keyIdentifierForKeyEvent): Renamed from identifierForKeyText and changed parameter
to be the event. Cleaned up the code a little bit, and wrote a comment or two.
Changed from lowercase hex to uppercase, and called toupper on the key so that
letter a-z would work properly. (A non-Unicode toupper is just the ticket here,
because I am only sure we want to do this for a-z, not other lowercase characters.)
(isKeypadEvent): Added. Uses virtual key codes to decide if a key event is a keypad
event, so we can set the state flag correctly.
(WindowsKeyCodeForKeyEvent): Added Clear key to the switch statement; it was missing.
Changed to no longe use the characterCode helper function since this was the only
place it was needed.
(mouseButtonForEvent): Added. Similar logic to what was in KWQKHTMLPart before; better
factoring to have it in here.
(nonMouseButtonsForEvent): Ditto.
(QMouseEvent::QMouseEvent): Rewrote constructors. One matches the one from Qt that's
used in some places in KHTML code. The other takes an NSEvent and uses the new functions
above to compute the button and state.
(QKeyEvent::QKeyEvent): Computer type based on the passed-in NSEvent. Compute the
auto-repeat flag based on the event and also the "forceAutoRepeat" parameter. Compute
the button state based on the event too.
* kwq/KWQKHTMLPart.h: Remove buttonForCurrentEvent and stateForCurrentEvent. Both
are now in KWQEvent.mm.
* kwq/KWQKHTMLPart.mm:
(KWQKHTMLPart::keyEvent): Remove extra parameters in code that creates QKeyEvent, now
that QKeyEvent can handle everything itself.
(KWQKHTMLPart::mouseDown): Same thing as above, only for QMouseEvent.
(KWQKHTMLPart::mouseDragged): Ditto.
(KWQKHTMLPart::mouseUp): Ditto.
(KWQKHTMLPart::mouseMoved): Ditto.
(KWQKHTMLPart::sendContextMenuEvent): Ditto.
* kwq/KWQKPartsEvent.h: Tweaked the class around a little so it can work without
taking advantage of QCustomEvent's data pointer.
* kwq/KWQKPartsEvent.mm:
(KParts::Event::Event): Changed so it does a strdup on the event name and uses the
new event type pre-allocated in KWQEvent.h for us.
(KParts::Event::~Event): Free the event name.
(KParts::Event::test): Reimplemented this.
* kwq/KWQKPartsPart.h: (KParts::Part::event): Removed now-unnecessary cast to change
a QCustomEvent into a QEvent.
* kwq/KWQNamespace.h: Removed the Qt::Key enum. All the code that used it was already
broken because of the mixup between Qt and Macintosh key codes.
2003-11-17 Ken Kocienda <kocienda@apple.com>
Reviewed by Maciej
......
......@@ -286,16 +286,22 @@ int UIEvent::keyCode() const
throw DOMException(DOMException::INVALID_STATE_ERR);
KeyboardEventImpl *keyEvent = dynamic_cast<KeyboardEventImpl*>(impl);
if (keyEvent) {
#if APPLE_CHANGES
if (impl->id() == EventImpl::KEYDOWN_EVENT || impl->id() == EventImpl::KEYUP_EVENT) {
return keyEvent->qKeyEvent()->WindowsKeyCode();
}
#endif
return keyEvent->qKeyEvent()->ascii();
}
if (keyEvent)
return keyEvent->keyCode();
else
return 0;
}
return 0;
int UIEvent::charCode() const
{
if (!impl)
throw DOMException(DOMException::INVALID_STATE_ERR);
KeyboardEventImpl *keyEvent = dynamic_cast<KeyboardEventImpl*>(impl);
if (keyEvent)
return keyEvent->charCode();
else
return 0;
}
int UIEvent::pageX() const
......@@ -354,15 +360,10 @@ int UIEvent::which() const
// Note: This property supports both key events and mouse events
// Netscape's "which" returns a virtual key code for keydown and keyup, and a character code for keypress.
// That's exactly what IE's "keyCode" returns.
KeyboardEventImpl *keyEvent = dynamic_cast<KeyboardEventImpl*>(impl);
if (keyEvent) {
#if APPLE_CHANGES
if (impl->id() == EventImpl::KEYDOWN_EVENT || impl->id() == EventImpl::KEYUP_EVENT) {
return keyEvent->qKeyEvent()->WindowsKeyCode();
}
#endif
return keyEvent->qKeyEvent()->ascii();
}
if (keyEvent)
return keyEvent->keyCode();
// For khtml, the return values for left, middle and right mouse buttons are 0, 1, 2, respectively.
// For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively.
......
......@@ -329,6 +329,12 @@ public:
*/
int keyCode() const;
/**
* Non-standard extension to support IE-style charCode event property.
*
*/
int charCode() const;
/**
* Non-standard extensions to support Netscape-style pageX and pageY event properties.
*
......
......@@ -440,6 +440,7 @@ const ClassInfo DOMUIEvent::info = { "UIEvent", &DOMEvent::info, &DOMUIEventTabl
view DOMUIEvent::View DontDelete|ReadOnly
detail DOMUIEvent::Detail DontDelete|ReadOnly
keyCode DOMUIEvent::KeyCode DontDelete|ReadOnly
charCode DOMUIEvent::CharCode DontDelete|ReadOnly
layerX DOMUIEvent::LayerX DontDelete|ReadOnly
layerY DOMUIEvent::LayerY DontDelete|ReadOnly
pageX DOMUIEvent::PageX DontDelete|ReadOnly
......@@ -472,6 +473,8 @@ Value DOMUIEvent::getValueProperty(ExecState *exec, int token) const
return Number(static_cast<DOM::UIEvent>(event).detail());
case KeyCode:
return Number(static_cast<DOM::UIEvent>(event).keyCode());
case CharCode:
return Number(static_cast<DOM::UIEvent>(event).charCode());
case LayerX:
return Number(static_cast<DOM::UIEvent>(event).layerX());
case LayerY:
......
......@@ -121,7 +121,7 @@ namespace KJS {
// no put - all read-only
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
enum { View, Detail, KeyCode, LayerX, LayerY, PageX, PageY, Which, InitUIEvent };
enum { View, Detail, KeyCode, CharCode, LayerX, LayerY, PageX, PageY, Which, InitUIEvent };
DOM::UIEvent toUIEvent() const { return static_cast<DOM::UIEvent>(event); }
};
......
......@@ -77,7 +77,7 @@ namespace KJS {
const struct HashEntry DOMUIEventTableEntries[] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ "charCode", DOMUIEvent::CharCode, DontDelete|ReadOnly, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ "view", DOMUIEvent::View, DontDelete|ReadOnly, 0, &DOMUIEventTableEntries[8] },
{ "keyCode", DOMUIEvent::KeyCode, DontDelete|ReadOnly, 0, 0 },
......
......@@ -143,6 +143,7 @@ long HTMLFormElementImpl::length() const
}
#if APPLE_CHANGES
void HTMLFormElementImpl::submitClick()
{
bool submitFound = false;
......@@ -160,7 +161,8 @@ void HTMLFormElementImpl::submitClick()
if (!submitFound) // submit the form without a submit or image input
prepareSubmit();
}
#endif
#endif // APPLE_CHANGES
static QCString encodeCString(const QCString& e)
{
......@@ -1799,30 +1801,30 @@ void HTMLInputElementImpl::defaultEventHandler(EventImpl *evt)
case IMAGE:
case RESET:
case SUBMIT:
// simulate mouse click for spacebar, return, and enter
if (key == "U+000020" || key == "U+00000d" || key == "Enter") {
// simulate mouse click for spacebar and enter
if (key == "U+000020" || key == "Enter") {
m_form->submitClick();
evt->setDefaultHandled();
}
break;
case CHECKBOX:
case RADIO:
// for return or enter, find the first successful image or submit element
// for enter, find the first successful image or submit element
// send it a simulated mouse click
if (key == "U+00000d" || key == "Enter") {
if (key == "Enter") {
m_form->submitClick();
evt->setDefaultHandled();
}
break;
case TEXT:
case PASSWORD: {
// For enter or return, find the first successful image or submit element
// For enter, find the first successful image or submit element
// send it a simulated mouse click only if the text input manager has
// no marked text. If it does, then return needs to work in the
// "accept" role for the input method.
QWidget *widget = static_cast<RenderWidget *>(m_render)->widget();
bool hasMarkedText = widget ? static_cast<QLineEdit *>(widget)->hasMarkedText() : false;
if (!hasMarkedText && (key == "U+00000d" || key == "Enter")) {
if (!hasMarkedText && key == "Enter") {
m_form->submitClick();
evt->setDefaultHandled();
}
......@@ -2341,6 +2343,7 @@ void HTMLSelectElementImpl::notifyOptionSelected(HTMLOptionElementImpl *selected
}
#if APPLE_CHANGES
void HTMLSelectElementImpl::defaultEventHandler(EventImpl *evt)
{
// Use key press event here since sending simulated mouse events
......@@ -2352,14 +2355,15 @@ void HTMLSelectElementImpl::defaultEventHandler(EventImpl *evt)
DOMString key = static_cast<KeyboardEventImpl *>(evt)->keyIdentifier();
if (key == "U+00000d" || key == "Enter") {
if (key == "Enter") {
m_form->submitClick();
evt->setDefaultHandled();
}
}
HTMLGenericFormElementImpl::defaultEventHandler(evt);
}
#endif
#endif // APPLE_CHANGES
void HTMLSelectElementImpl::accessKeyAction()
{
......
......@@ -109,7 +109,7 @@ void HTMLAnchorElementImpl::defaultEventHandler(EventImpl *evt)
}
if ( k ) {
if (k->keyIdentifier() != "U+00000d" && k->keyIdentifier() != "Enter") {
if (k->keyIdentifier() != "Enter") {
HTMLElementImpl::defaultEventHandler(evt);
return;
}
......
......@@ -954,6 +954,7 @@ void KHTMLView::keyPressEvent( QKeyEvent *_ke )
}
}
#if !APPLE_CHANGES
int offs = (clipper()->height() < 30) ? clipper()->height() : 30;
if (_ke->state()&ShiftButton)
switch(_ke->key())
......@@ -1040,6 +1041,7 @@ void KHTMLView::keyPressEvent( QKeyEvent *_ke )
return;
}
_ke->accept();
#endif
}
void KHTMLView::keyReleaseEvent(QKeyEvent *_ke)
......
......@@ -473,6 +473,8 @@ QString RenderPushButton::defaultLabel()
// -------------------------------------------------------------------------------
#if !APPLE_CHANGES
LineEditWidget::LineEditWidget(QWidget *parent)
: KLineEdit(parent)
{
......@@ -500,12 +502,18 @@ bool LineEditWidget::event( QEvent *e )
return KLineEdit::event( e );
}
#endif
// -----------------------------------------------------------------------------
RenderLineEdit::RenderLineEdit(HTMLInputElementImpl *element)
: RenderFormElement(element), m_updating(false)
{
#if APPLE_CHANGES
KLineEdit *edit = new KLineEdit(view()->viewport());
#else
LineEditWidget *edit = new LineEditWidget(view()->viewport());
#endif
connect(edit,SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()));
connect(edit,SIGNAL(textChanged(const QString &)),this,SLOT(slotTextChanged(const QString &)));
connect(edit,SIGNAL(clicked()),this,SLOT(slotClicked()));
......@@ -513,6 +521,7 @@ RenderLineEdit::RenderLineEdit(HTMLInputElementImpl *element)
if(element->inputType() == HTMLInputElementImpl::PASSWORD)
edit->setEchoMode( QLineEdit::Password );
#if !APPLE_CHANGES
if ( element->autoComplete() ) {
QStringList completions = view()->formCompletionItems(element->name().string());
if (completions.count()) {
......@@ -520,6 +529,7 @@ RenderLineEdit::RenderLineEdit(HTMLInputElementImpl *element)
edit->setContextMenuEnabled(true);
}
}
#endif
setQWidget(edit);
}
......@@ -643,7 +653,7 @@ void RenderLineEdit::slotTextChanged(const QString &string)
void RenderLineEdit::select()
{
static_cast<LineEditWidget*>(m_widget)->selectAll();
static_cast<KLineEdit*>(m_widget)->selectAll();
}
// ---------------------------------------------------------------------------
......@@ -932,6 +942,7 @@ ComboBoxWidget::ComboBoxWidget(QWidget *parent)
bool ComboBoxWidget::event(QEvent *e)
{
#if !APPLE_CHANGES
if (e->type()==QEvent::KeyPress)
{
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
......@@ -946,6 +957,7 @@ bool ComboBoxWidget::event(QEvent *e)
return KComboBox::event(e);
}
}
#endif
return KComboBox::event(e);
}
......@@ -1376,6 +1388,7 @@ TextAreaWidget::TextAreaWidget(int wrap, QWidget* parent)
bool TextAreaWidget::event( QEvent *e )
{
#if !APPLE_CHANGES
if ( e->type() == QEvent::AccelAvailable && isReadOnly() ) {
QKeyEvent* ke = (QKeyEvent*) e;
if ( ke->state() & ControlButton ) {
......@@ -1392,6 +1405,7 @@ bool TextAreaWidget::event( QEvent *e )
}
}
}
#endif
return KTextEdit::event( e );
}
......
......@@ -519,6 +519,13 @@ bool MouseEventImpl::isMouseEvent() const
KeyboardEventImpl::KeyboardEventImpl()
{
m_keyEvent = 0;
m_keyIdentifier = 0;
m_keyLocation = KeyboardEvent::DOM_KEY_LOCATION_STANDARD;
m_ctrlKey = false;
m_shiftKey = false;
m_altKey = false;
m_metaKey = false;
m_altGraphKey = false;
}
KeyboardEventImpl::KeyboardEventImpl(QKeyEvent *key, AbstractViewImpl *view)
......@@ -530,34 +537,23 @@ KeyboardEventImpl::KeyboardEventImpl(QKeyEvent *key, AbstractViewImpl *view)
#else
m_keyEvent = new QKeyEvent(key->type(), key->key(), key->ascii(), key->state(), key->text(), key->isAutoRepeat(), key->count());
#endif
// Events are supposed to be accepted by default in Qt!
// This line made QLineEdit's keyevents be ignored, so they were sent to the khtmlview
// (and e.g. space would make it scroll down)
//qKeyEvent->ignore();
// m_keyIdentifier should contain the unicode value of the pressed key if available.
// key->text() returns the unicode sequence as a QString
if (!key->text().isNull()) {
DOMString identifier(m_keyEvent->identifier());
m_keyIdentifier = identifier.implementation();
m_keyIdentifier->ref();
}
else {
m_keyIdentifier = DOMString("Unidentified").implementation();
m_keyIdentifier->ref();
}
// key->state returns enum ButtonState, which is ShiftButton, ControlButton and AltButton or'ed together.
#if APPLE_CHANGES
DOMString identifier(key->keyIdentifier());
m_keyIdentifier = identifier.implementation();
m_keyIdentifier->ref();
#else
m_keyIdentifier = 0;
// need the equivalent of the above for KDE
#endif
int keyState = key->state();
if (keyState & Qt::ControlButton)
m_ctrlKey = true;
if (keyState & Qt::ShiftButton)
m_shiftKey = true;
if (keyState & Qt::AltButton)
m_altKey = true;
if (keyState & Qt::MetaButton)
m_metaKey = true;
// altGraphKey is not supported by Qt.
m_ctrlKey = keyState & Qt::ControlButton;
m_shiftKey = keyState & Qt::ShiftButton;
m_altKey = keyState & Qt::AltButton;
m_metaKey = keyState & Qt::MetaButton;
m_altGraphKey = false; // altGraphKey is not supported by Qt.
// Note: we only support testing for num pad
m_keyLocation = (keyState & Qt::Keypad) ? KeyboardEvent::DOM_KEY_LOCATION_NUMPAD : KeyboardEvent::DOM_KEY_LOCATION_STANDARD;
......@@ -622,6 +618,36 @@ void KeyboardEventImpl::initKeyboardEvent(const DOMString &typeArg,
m_altGraphKey = altGraphKeyArg;
}
int KeyboardEventImpl::keyCode() const
{
if (!m_keyEvent) {
return 0;
}
switch (m_id) {
case KEYDOWN_EVENT:
case KEYUP_EVENT:
#if APPLE_CHANGES
return m_keyEvent->WindowsKeyCode();
#else
// need the equivalent of the above for KDE
#endif
default:
return charCode();
}
}
int KeyboardEventImpl::charCode() const
{
if (!m_keyEvent) {
return 0;
}
QString text = m_keyEvent->text();
if (text.length() != 1) {
return 0;
}
return text[0].unicode();
}
bool KeyboardEventImpl::isKeyboardEvent() const
{
return true;
......
......@@ -98,7 +98,7 @@ public:
EventImpl(EventId _id, bool canBubbleArg, bool cancelableArg);
virtual ~EventImpl();
EventId id() { return m_id; }
EventId id() const { return m_id; }
DOMString type() const;
NodeImpl *target() const;
......@@ -285,6 +285,9 @@ public:
bool altGraphKey() const { return m_altGraphKey; }
QKeyEvent *qKeyEvent() const { return m_keyEvent; }
int keyCode() const; // key code for keydown and keyup, character for other events
int charCode() const;
virtual bool isKeyboardEvent() const;
......
......@@ -51,14 +51,14 @@ public:
MouseMove,
FocusIn,
FocusOut,
AccelAvailable,
KeyPress,
KeyRelease,
Paint,
Resize
Resize,
KParts
};
QEvent( Type t ) : _type(t) {}
QEvent(Type type) : _type(type) { }
virtual ~QEvent();
Type type() const { return _type; }
......@@ -67,32 +67,35 @@ private:
Type _type;
};
typedef QEvent QCustomEvent;
class QMouseEvent : public QEvent {
public:
QMouseEvent(Type type, const QPoint &pos, int button, int state);
QMouseEvent(Type type, const QPoint &pos, int button, int state, int clickCount);
QMouseEvent(Type type, const QPoint &pos, const QPoint &global, int button, int state);
int x() { return _position.x(); }
int y() { return _position.y(); }
int globalX() { return _position.x(); } // we never really return global X
int globalY() { return _position.y(); } // we never really return global Y
QMouseEvent(Type, const QPoint &pos, int button, int state);
QMouseEvent(Type, NSEvent *);
const QPoint &pos() const { return _position; }
ButtonState button() { return _button; }
ButtonState state() { return _state; }
ButtonState stateAfter();
int x() const { return _position.x(); }
int y() const { return _position.y(); }
int globalX() const { return _position.x(); } // we never really return global X
int globalY() const { return _position.y(); } // we never really return global Y
ButtonState button() const { return static_cast<ButtonState>(_button); }
ButtonState state() const { return static_cast<ButtonState>(_state); }
ButtonState stateAfter() const { return static_cast<ButtonState>(_stateAfter); }
int clickCount() { return _clickCount; }
private:
QPoint _position;
ButtonState _button;
ButtonState _state;
int _button;
int _state;
int _stateAfter;
int _clickCount;
};
class QTimerEvent : public QEvent {
public:
QTimerEvent(int timerId);
QTimerEvent(int timerId) : QEvent(Timer), _timerId(timerId) { }
int timerId() const { return _timerId; }
......@@ -102,30 +105,25 @@ private:
class QKeyEvent : public QEvent {
public:
QKeyEvent(NSEvent *, Type, int buttonState, bool autoRepeat);
QKeyEvent(NSEvent *, bool forceAutoRepeat = false);
ButtonState state() const { return static_cast<ButtonState>(_state); }
bool isAccepted() const { return _isAccepted; }
QString text() const { return _text; }
bool isAutoRepeat() const { return _autoRepeat; }
void accept() { _isAccepted = true; }
void ignore() { _isAccepted = false; }
int key() const;
int WindowsKeyCode() const { return _WindowsKeyCode; }
ButtonState state() const;
void accept();
void ignore();
bool isAutoRepeat() const;
bool isAccepted() const;
int count() const;
QString text() const;
QString unmodifiedText() const;
int ascii() const;
QString identifier() const;
QString unmodifiedText() const { return _unmodifiedText; }
QString keyIdentifier() const { return _keyIdentifier; }
private:
int _key;
int _ascii;
ButtonState _state;
</