[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:13:16 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 94f99ce23e814727d99006677c23cdee1ded1647
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Nov 18 01:52:35 2003 +0000

            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

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index d5efd79..a011a23 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,121 @@
+2003-11-17  Darin Adler  <darin at 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 at apple.com>
 
         Reviewed by Maciej
diff --git a/WebCore/khtml/dom/dom2_events.cpp b/WebCore/khtml/dom/dom2_events.cpp
index a0b5ccc..7031450 100644
--- a/WebCore/khtml/dom/dom2_events.cpp
+++ b/WebCore/khtml/dom/dom2_events.cpp
@@ -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. 
diff --git a/WebCore/khtml/dom/dom2_events.h b/WebCore/khtml/dom/dom2_events.h
index 3c5bd19..caddc6f 100644
--- a/WebCore/khtml/dom/dom2_events.h
+++ b/WebCore/khtml/dom/dom2_events.h
@@ -330,6 +330,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.
      *
      */
diff --git a/WebCore/khtml/ecma/kjs_events.cpp b/WebCore/khtml/ecma/kjs_events.cpp
index b1cdb96..d508bb9 100644
--- a/WebCore/khtml/ecma/kjs_events.cpp
+++ b/WebCore/khtml/ecma/kjs_events.cpp
@@ -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:
diff --git a/WebCore/khtml/ecma/kjs_events.h b/WebCore/khtml/ecma/kjs_events.h
index 1f4a24c..0ec51eb 100644
--- a/WebCore/khtml/ecma/kjs_events.h
+++ b/WebCore/khtml/ecma/kjs_events.h
@@ -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); }
   };
 
diff --git a/WebCore/khtml/ecma/kjs_events.lut.h b/WebCore/khtml/ecma/kjs_events.lut.h
index 4ddcd52..271a840 100644
--- a/WebCore/khtml/ecma/kjs_events.lut.h
+++ b/WebCore/khtml/ecma/kjs_events.lut.h
@@ -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 },
diff --git a/WebCore/khtml/html/html_formimpl.cpp b/WebCore/khtml/html/html_formimpl.cpp
index 51b834b..8182251 100644
--- a/WebCore/khtml/html/html_formimpl.cpp
+++ b/WebCore/khtml/html/html_formimpl.cpp
@@ -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()
 {
diff --git a/WebCore/khtml/html/html_inlineimpl.cpp b/WebCore/khtml/html/html_inlineimpl.cpp
index ded9e43..81eee34 100644
--- a/WebCore/khtml/html/html_inlineimpl.cpp
+++ b/WebCore/khtml/html/html_inlineimpl.cpp
@@ -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;
             }
diff --git a/WebCore/khtml/khtmlview.cpp b/WebCore/khtml/khtmlview.cpp
index 6e66202..bf878ae 100644
--- a/WebCore/khtml/khtmlview.cpp
+++ b/WebCore/khtml/khtmlview.cpp
@@ -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)
diff --git a/WebCore/khtml/rendering/render_form.cpp b/WebCore/khtml/rendering/render_form.cpp
index f5a6d10..e482816 100644
--- a/WebCore/khtml/rendering/render_form.cpp
+++ b/WebCore/khtml/rendering/render_form.cpp
@@ -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 );
 }
 
diff --git a/WebCore/khtml/xml/dom2_eventsimpl.cpp b/WebCore/khtml/xml/dom2_eventsimpl.cpp
index 62b7c2a..7720cd3 100644
--- a/WebCore/khtml/xml/dom2_eventsimpl.cpp
+++ b/WebCore/khtml/xml/dom2_eventsimpl.cpp
@@ -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;
diff --git a/WebCore/khtml/xml/dom2_eventsimpl.h b/WebCore/khtml/xml/dom2_eventsimpl.h
index 26556f9..fd283cd 100644
--- a/WebCore/khtml/xml/dom2_eventsimpl.h
+++ b/WebCore/khtml/xml/dom2_eventsimpl.h
@@ -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;
 
diff --git a/WebCore/kwq/KWQEvent.h b/WebCore/kwq/KWQEvent.h
index 5560afa..9774fc8 100644
--- a/WebCore/kwq/KWQEvent.h
+++ b/WebCore/kwq/KWQEvent.h
@@ -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;
+    int _state;
     QString _text;
     QString _unmodifiedText;
-    QString _identifier;
+    QString _keyIdentifier;
     bool _autoRepeat;
-    int _count;
     bool _isAccepted;
     int _WindowsKeyCode;
 };
@@ -133,8 +131,10 @@ private:
 class QFocusEvent : public QEvent {
 public:
     enum Reason { Popup, Other };
+
+    QFocusEvent(Type type) : QEvent(type) { }
+
     static Reason reason() { return Other; }
-    QFocusEvent (Type type) : QEvent (type) {}
 };
 
 class QHideEvent;
@@ -143,19 +143,8 @@ class QWheelEvent;
 class QContextMenuEvent;
 
 class QResizeEvent : public QEvent {
- public:
-    QResizeEvent() : QEvent(Resize) {}
-};
-
-
-class QCustomEvent : public QEvent {
 public:
-    QCustomEvent(Type type, void *data = 0) : QEvent(type), d(data) { }
-    void *data() const { return d; }
-    void setData(void *data) { d = data; }
-
-private:
-    void *d;
+    QResizeEvent() : QEvent(Resize) { }
 };
 
 #endif
diff --git a/WebCore/kwq/KWQEvent.mm b/WebCore/kwq/KWQEvent.mm
index 15ce791..df568a4 100644
--- a/WebCore/kwq/KWQEvent.mm
+++ b/WebCore/kwq/KWQEvent.mm
@@ -24,68 +24,22 @@
  */
 
 #import "KWQEvent.h"
-#import "KWQLogging.h"
-
-QEvent::~QEvent()
-{
-}
-
-
-QMouseEvent::QMouseEvent( Type t, const QPoint &pos, int b, int s )
-    : QEvent(t), _position(pos), _button((ButtonState)b), _state((ButtonState)s)
-{
-}
-
-QMouseEvent::QMouseEvent( Type t, const QPoint &pos, int b, int s, int cs )
-    : QEvent(t), _position(pos), _button((ButtonState)b), _state((ButtonState)s), _clickCount(cs)
-{
-}
-
-QMouseEvent::QMouseEvent(Type t, const QPoint &pos, const QPoint &, int b, int s)
-    : QEvent(t), _position(pos), _button((ButtonState)b), _state((ButtonState)s)
-{
-}
-
-Qt::ButtonState QMouseEvent::stateAfter()
-{
-    return _state;
-}
 
+#import "KWQLogging.h"
 
-QTimerEvent::QTimerEvent(int t)
-    : QEvent(Timer)
-{
-    _timerId = t;
-}
-
-static char hexDigit(int i) {
-    if (i < 0 || i > 16) {
-        ERROR("illegal hex digit");
-        return '0';
-    }
-    int h = i;
-    if (h >= 10) {
-        h = h - 10 + 'a'; 
-    }
-    else {
-        h += '0';
-    }
-    return h;
-}
-
-static QString identifierForKeyText(const QString &text)
+static QString keyIdentifierForKeyEvent(NSEvent *event)
 {
-    int count = text.length();
-    if (count == 0 || count > 1) {
-#ifdef APPLE_CHANGES
-        LOG(Events, "received an unexpected number of characters in key event: %d", count);
-#endif
+    NSString *s = [event charactersIgnoringModifiers];
+    if ([s length] != 1) {
+        LOG(Events, "received an unexpected number of characters in key event: %u", [s length]);
         return "Unidentified";
     }
-    ushort c = text[0].unicode();
+    unichar c = [s characterAtIndex:0];
     switch (c) {
         // Each identifier listed in the DOM spec is listed here.
-        // Many are simply commented out since they do not appear on standard Macintosh keyboards.
+        // Many are simply commented out since they do not appear on standard Macintosh keyboards
+        // or are on a key that doesn't have a corresponding character.
+
         // "Accept"
         // "AllCandidates"
         // "Alt"
@@ -97,10 +51,11 @@ static QString identifierForKeyText(const QString &text)
         // "BrowserSearch"
         // "BrowserStop"
         // "CapsLock"
+
         // "Clear"
         case NSClearLineFunctionKey:
             return "Clear";
-            break;
+
         // "CodeInput"
         // "Compose"
         // "Control"
@@ -108,146 +63,125 @@ static QString identifierForKeyText(const QString &text)
         // "Convert"
         // "Copy"
         // "Cut"
+
         // "Down"
         case NSDownArrowFunctionKey:
             return "Down";
-            break;
         // "End"
         case NSEndFunctionKey:
             return "End";
-            break;
         // "Enter"
-        case 0x3:
+        case 0x3: case 0xD: // Macintosh calls the one on the main keyboard Return, but Windows calls it Enter, so we'll do the same for the DOM
             return "Enter";
-            break;
+
         // "EraseEof"
+
         // "Execute"
         case NSExecuteFunctionKey:
             return "Execute";
-            break;
+
         // "Exsel"
+
         // "F1"
         case NSF1FunctionKey:
             return "F1";
-            break;
         // "F2"
         case NSF2FunctionKey:
             return "F2";
-            break;
         // "F3"
         case NSF3FunctionKey:
             return "F3";
-            break;
         // "F4"
         case NSF4FunctionKey:
             return "F4";
-            break;
         // "F5"
         case NSF5FunctionKey:
             return "F5";
-            break;
         // "F6"
         case NSF6FunctionKey:
             return "F6";
-            break;
         // "F7"
         case NSF7FunctionKey:
             return "F7";
-            break;
         // "F8"
         case NSF8FunctionKey:
             return "F8";
-            break;
         // "F9"
         case NSF9FunctionKey:
             return "F9";
-            break;
         // "F10"
         case NSF10FunctionKey:
             return "F10";
-            break;
         // "F11"
         case NSF11FunctionKey:
             return "F11";
-            break;
         // "F12"
         case NSF12FunctionKey:
             return "F12";
-            break;
         // "F13"
         case NSF13FunctionKey:
             return "F13";
-            break;
         // "F14"
         case NSF14FunctionKey:
             return "F14";
-            break;
         // "F15"
         case NSF15FunctionKey:
             return "F15";
-            break;
         // "F16"
         case NSF16FunctionKey:
             return "F16";
-            break;
         // "F17"
         case NSF17FunctionKey:
             return "F17";
-            break;
         // "F18"
         case NSF18FunctionKey:
             return "F18";
-            break;
         // "F19"
         case NSF19FunctionKey:
             return "F19";
-            break;
         // "F20"
         case NSF20FunctionKey:
             return "F20";
-            break;
         // "F21"
         case NSF21FunctionKey:
             return "F21";
-            break;
         // "F22"
         case NSF22FunctionKey:
             return "F22";
-            break;
         // "F23"
         case NSF23FunctionKey:
             return "F23";
-            break;
         // "F24"
         case NSF24FunctionKey:
             return "F24";
-            break;
+
         // "FinalMode"
+
         // "Find"
         case NSFindFunctionKey:
             return "Find";
-            break;
         // "ForwardDelete" (Non-standard)
         case NSDeleteFunctionKey:
             return "ForwardDelete";
-            break;
+
         // "FullWidth"
         // "HalfWidth"
         // "HangulMode"
         // "HanjaMode"
+
         // "Help"
         case NSHelpFunctionKey:
             return "Help";
-            break;
+
         // "Hiragana"
+
         // "Home"
         case NSHomeFunctionKey:
             return "Home";
-            break;
         // "Insert"
         case NSInsertFunctionKey:
             return "Left";
-            break;
+
         // "JapaneseHiragana"
         // "JapaneseKatakana"
         // "JapaneseRomaji"
@@ -258,90 +192,121 @@ static QString identifierForKeyText(const QString &text)
         // "LaunchApplication1"
         // "LaunchApplication2"
         // "LaunchMail"
+
         // "Left"
         case NSLeftArrowFunctionKey:
             return "Left";
-            break;
+
         // "Meta"
         // "MediaNextTrack"
         // "MediaPlayPause"
         // "MediaPreviousTrack"
         // "MediaStop"
+
         // "ModeChange"
         case NSModeSwitchFunctionKey:
             return "ModeChange";
-            break;
+
         // "Nonconvert"
         // "NumLock"
+
         // "PageDown"
         case NSPageDownFunctionKey:
             return "PageDown";
-            break;
         // "PageUp"
         case NSPageUpFunctionKey:
             return "PageUp";
-            break;
+
         // "Paste"
+
         // "Pause"
         case NSPauseFunctionKey:
             return "Pause";
-            break;
+
         // "Play"
         // "PreviousCandidate"
+
         // "PrintScreen"
         case NSPrintScreenFunctionKey:
             return "PrintScreen";
-            break;
+
         // "Process"
         // "Props"
+
         // "Right"
         case NSRightArrowFunctionKey:
             return "Right";
-            break;
+
         // "RomanCharacters"
         // "Scroll"
         // "Select"
         // "SelectMedia"
         // "Shift"
+
         // "Stop"
         case NSStopFunctionKey:
             return "Stop";
-            break;
         // "Up"
         case NSUpArrowFunctionKey:
             return "Up";
-            break;
         // "Undo"
         case NSUndoFunctionKey:
             return "Undo";
-            break;
+
         // "VolumeDown"
         // "VolumeMute"
         // "VolumeUp"
         // "Win"
         // "Zoom"
+
         default:
-            char escaped[5];
-            escaped[0] = hexDigit((c >> 12) & 0xf);
-            escaped[1] = hexDigit((c >> 8) & 0xf);
-            escaped[2] = hexDigit((c >> 4) & 0xf);
-            escaped[3] = hexDigit(c & 0xf);
-            escaped[4] = '\0';
-            NSString *nsstring = [[NSString alloc] initWithFormat:@"U+00%s", escaped];
-            QString qstring = QString::fromNSString(nsstring);
-            [nsstring release];
-            return qstring;
+            return QString().sprintf("U+%06X", toupper(c));
     }
 }
 
-static int characterCode(NSString *characters)
+static bool isKeypadEvent(NSEvent *event)
 {
-    return [characters length] != 1 ? 0 : [characters characterAtIndex:0];
+    // Check that this is the type of event that has a keyCode.
+    switch ([event type]) {
+	case NSKeyDown:
+	case NSKeyUp:
+	case NSFlagsChanged:
+            break;
+        default:
+            return false;
+    }
+
+    switch ([event keyCode]) {
+        case 71: // Clear
+        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
+            return true;
+     }
+     
+     return false;
 }
 
-static int WindowsKeyCode(NSEvent *event)
+static int WindowsKeyCodeForKeyEvent(NSEvent *event)
 {
     switch ([event keyCode]) {
+        // VK_CLEAR (0C) CLEAR key
+        case 71: return 0x0C;
+
         // VK_NUMPAD0 (60) Numeric keypad 0 key
         case 82: return 0x60;
         // VK_NUMPAD1 (61) Numeric keypad 1 key
@@ -375,7 +340,12 @@ static int WindowsKeyCode(NSEvent *event)
         case 75: return 0x6F;
      }
 
-    switch (characterCode([event charactersIgnoringModifiers])) {
+    NSString *s = [event charactersIgnoringModifiers];
+    if ([s length] != 1) {
+        return 0;
+    }
+
+    switch ([s characterAtIndex:0]) {
         // VK_LBUTTON (01) Left mouse button
         // VK_RBUTTON (02) Right mouse button
         // VK_CANCEL (03) Control-break processing
@@ -668,74 +638,119 @@ static int WindowsKeyCode(NSEvent *event)
     }
 
     return 0;
- }
- 
-QKeyEvent::QKeyEvent(NSEvent *event, Type t, int buttonState, bool autoRepeat)
-    : QEvent(t),
-      _key([event keyCode]),
-      _ascii(characterCode([event characters])),
-      _state((ButtonState)buttonState),
-      _text(QString::fromNSString([event characters])),
-      _unmodifiedText(QString::fromNSString([event charactersIgnoringModifiers])),
-      _identifier(identifierForKeyText(_unmodifiedText)),
-      _autoRepeat(autoRepeat),
-      _count(1),
-      _isAccepted(false),
-      _WindowsKeyCode(::WindowsKeyCode(event))
-{
 }
 
-int QKeyEvent::key() const
+static int mouseButtonForEvent(NSEvent *event)
 {
-    return _key;
+    switch ([event type]) {
+        case NSLeftMouseDown:
+        case NSLeftMouseUp:
+        case NSLeftMouseDragged:
+            return Qt::LeftButton;
+        case NSRightMouseDown:
+        case NSRightMouseUp:
+        case NSRightMouseDragged:
+            return Qt::RightButton;
+        case NSOtherMouseDown:
+        case NSOtherMouseUp:
+        case NSOtherMouseDragged:
+            return Qt::MidButton;
+        default:
+            return Qt::NoButton;
+    }
 }
 
-Qt::ButtonState QKeyEvent::state() const
+static int nonMouseButtonsForEvent(NSEvent *event)
 {
-    return _state;
-}
+    int buttons = 0;
 
-void QKeyEvent::accept()
-{
-    _isAccepted = true;
-}
+    unsigned modifiers = [event modifierFlags];
 
-void QKeyEvent::ignore()
-{
-    _isAccepted = false;
-}
+    if (modifiers & NSControlKeyMask) {
+        buttons |= Qt::ControlButton;
+    }
+    if (modifiers & NSShiftKeyMask) {
+        buttons |= Qt::ShiftButton;
+    }
+    if (modifiers & NSAlternateKeyMask) {
+        buttons |= Qt::AltButton;
+    }
+    if (modifiers & NSCommandKeyMask) {
+        buttons |= Qt::MetaButton;
+    }
 
-bool QKeyEvent::isAutoRepeat() const
-{
-    return _autoRepeat;
-}
+    // I tried using NSNumericPadKeyMask, but it does not seem to work reliably.
+    // One possible explanation is that the documentation says "Set if any key in
+    // the numeric keypad is pressed." which may mean that it gets set if there
+    // is any key down on the numeric keypad. But it could just be some kind of bug
+    // or a mistake on my part. We could revisit this some day.
+    if (isKeypadEvent(event)) {
+        buttons |= Qt::Keypad;
+    }
 
-QString QKeyEvent::text(void) const
-{
-    return _text;
+    return buttons;
 }
 
-QString QKeyEvent::unmodifiedText(void) const
-{
-    return _unmodifiedText;
-}
+// ======== 
 
-int QKeyEvent::ascii(void) const
+QEvent::~QEvent()
 {
-    return _ascii;
 }
 
-int QKeyEvent::count(void) const
+// ======== 
+
+QMouseEvent::QMouseEvent(Type type, const QPoint &position, int button, int state)
+    : QEvent(type), _position(position)
 {
-    return _count;
+    _button = button;
+    if (type == MouseMove) {
+        _clickCount = 0;
+        _state = state | button;
+        _stateAfter = state | button;
+    } else {
+        _clickCount = 1;
+        if (type == MouseButtonRelease) {
+            _state = state | button;
+            _stateAfter = state & ~button;
+        } else {
+            _state = state & ~button;
+            _stateAfter = state | button;
+        }
+    }
 }
 
-bool QKeyEvent::isAccepted(void) const
+QMouseEvent::QMouseEvent(Type type, NSEvent *event)
+    : QEvent(type), _position([event locationInWindow])
 {
-    return _isAccepted;
+    int button = mouseButtonForEvent(event);
+    int state = nonMouseButtonsForEvent(event);
+    _button = button;
+    if (type == MouseMove) {
+        _clickCount = 0;
+        _state = state | button;
+        _stateAfter = state | button;
+    } else {
+        _clickCount = [event clickCount];
+        if (type == MouseButtonRelease) {
+            _state = state | button;
+            _stateAfter = state & ~button;
+        } else {
+            _state = state & ~button;
+            _stateAfter = state | button;
+        }
+    }
 }
 
-QString QKeyEvent::identifier() const
+// ======== 
+
+QKeyEvent::QKeyEvent(NSEvent *event, bool forceAutoRepeat)
+    : QEvent([event type] == NSKeyDown ? KeyPress : KeyRelease),
+      _state(nonMouseButtonsForEvent(event)),
+      _text(QString::fromNSString([event characters])),
+      _unmodifiedText(QString::fromNSString([event charactersIgnoringModifiers])),
+      _keyIdentifier(keyIdentifierForKeyEvent(event)),
+      _autoRepeat(forceAutoRepeat || [event isARepeat]),
+      _isAccepted(false),
+      _WindowsKeyCode(WindowsKeyCodeForKeyEvent(event))
 {
-    return _identifier;
 }
diff --git a/WebCore/kwq/KWQKHTMLPart.h b/WebCore/kwq/KWQKHTMLPart.h
index d62a07d..8cd0e66 100644
--- a/WebCore/kwq/KWQKHTMLPart.h
+++ b/WebCore/kwq/KWQKHTMLPart.h
@@ -254,9 +254,6 @@ private:
     virtual void khtmlMouseMoveEvent(khtml::MouseMoveEvent *);
     virtual void khtmlMouseReleaseEvent(khtml::MouseReleaseEvent *);
     
-    static int buttonForCurrentEvent();
-    static int stateForCurrentEvent();
-
     bool passWidgetMouseDownEventToWidget(khtml::MouseEvent *);
     bool passWidgetMouseDownEventToWidget(khtml::RenderWidget *);
     bool passWidgetMouseDownEventToWidget(QWidget *);
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index 3e55763..2435362 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -1519,8 +1519,7 @@ bool KWQKHTMLPart::keyEvent(NSEvent *event)
     NSEvent *oldCurrentEvent = _currentEvent;
     _currentEvent = [event retain];
 
-    QEvent::Type type = [event type] == NSKeyDown ? QEvent::KeyPress : QEvent::KeyRelease;
-    QKeyEvent qEvent(event, type, stateForCurrentEvent(), [event isARepeat]);
+    QKeyEvent qEvent(event);
     bool result = !node->dispatchKeyEvent(&qEvent);
 
     // We want to send both a down and a press for the initial key event.
@@ -1528,8 +1527,8 @@ bool KWQKHTMLPart::keyEvent(NSEvent *event)
     // which causes it to send a press to the DOM.
     // That's not a great hack; it would be good to do this in a better way.
     if ([event type] == NSKeyDown && ![event isARepeat]) {
-	QKeyEvent qEvent(event, QEvent::KeyPress, stateForCurrentEvent(), true);
-        if (!node->dispatchKeyEvent(&qEvent)) {
+	QKeyEvent repeatEvent(event, true);
+        if (!node->dispatchKeyEvent(&repeatEvent)) {
 	    result = true;
 	}
     }
@@ -1898,53 +1897,6 @@ bool KWQKHTMLPart::passSubframeEventToSubframe(NodeImpl::MouseEvent &event)
     return false;
 }
 
-int KWQKHTMLPart::buttonForCurrentEvent()
-{
-    KWQ_BLOCK_EXCEPTIONS;
-    
-    switch ([_currentEvent type]) {
-    case NSLeftMouseDown:
-    case NSLeftMouseUp:
-        return Qt::LeftButton;
-    case NSRightMouseDown:
-    case NSRightMouseUp:
-        return Qt::RightButton;
-    case NSOtherMouseDown:
-    case NSOtherMouseUp:
-        return Qt::MidButton;
-    default:
-        return 0;
-    }
-    KWQ_UNBLOCK_EXCEPTIONS;
-
-    return 0;
-}
-
-int KWQKHTMLPart::stateForCurrentEvent()
-{
-    KWQ_BLOCK_EXCEPTIONS;
-
-    int state = buttonForCurrentEvent();
-    unsigned modifiers =  [_currentEvent modifierFlags];
-
-    if (modifiers & NSControlKeyMask)
-        state |= Qt::ControlButton;
-    if (modifiers & NSShiftKeyMask)
-        state |= Qt::ShiftButton;
-    if (modifiers & NSAlternateKeyMask)
-        state |= Qt::AltButton;
-    if (modifiers & NSCommandKeyMask)
-        state |= Qt::MetaButton;
-    if (modifiers & NSNumericPadKeyMask)
-        state |= Qt::Keypad;
-    
-    return state;
-
-    KWQ_UNBLOCK_EXCEPTIONS;
-
-    return buttonForCurrentEvent();
-}
-
 void KWQKHTMLPart::mouseDown(NSEvent *event)
 {
     KHTMLView *v = d->m_view;
@@ -1972,8 +1924,7 @@ void KWQKHTMLPart::mouseDown(NSEvent *event)
     // Sending an event can result in the destruction of the view and part.
     // We ref so that happens after we return from the KHTMLView function.
     v->ref();
-    QMouseEvent kEvent(QEvent::MouseButtonPress, QPoint([event locationInWindow]),
-        buttonForCurrentEvent(), stateForCurrentEvent(), [event clickCount]);
+    QMouseEvent kEvent(QEvent::MouseButtonPress, event);
     v->viewportMousePressEvent(&kEvent);
     v->deref();
     
@@ -2002,7 +1953,7 @@ void KWQKHTMLPart::mouseDragged(NSEvent *event)
     // Sending an event can result in the destruction of the view and part.
     // We ref so that happens after we return from the KHTMLView function.
     v->ref();
-    QMouseEvent kEvent(QEvent::MouseMove, QPoint([event locationInWindow]), Qt::LeftButton, Qt::LeftButton);
+    QMouseEvent kEvent(QEvent::MouseMove, event);
     v->viewportMouseMoveEvent(&kEvent);
     v->deref();
     
@@ -2037,12 +1988,10 @@ void KWQKHTMLPart::mouseUp(NSEvent *event)
     // treated as another double click. Hence the "% 2" below.
     int clickCount = [event clickCount];
     if (clickCount > 0 && clickCount % 2 == 0) {
-        QMouseEvent doubleClickEvent(QEvent::MouseButtonDblClick, QPoint([event locationInWindow]),
-            buttonForCurrentEvent(), stateForCurrentEvent(), clickCount);
+        QMouseEvent doubleClickEvent(QEvent::MouseButtonDblClick, event);
         v->viewportMouseDoubleClickEvent(&doubleClickEvent);
     } else {
-        QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint([event locationInWindow]),
-            buttonForCurrentEvent(), stateForCurrentEvent(), clickCount);
+        QMouseEvent releaseEvent(QEvent::MouseButtonRelease, event);
         v->viewportMouseReleaseEvent(&releaseEvent);
     }
     v->deref();
@@ -2133,7 +2082,7 @@ void KWQKHTMLPart::mouseMoved(NSEvent *event)
     // Sending an event can result in the destruction of the view and part.
     // We ref so that happens after we return from the KHTMLView function.
     v->ref();
-    QMouseEvent kEvent(QEvent::MouseMove, QPoint([event locationInWindow]), 0, stateForCurrentEvent());
+    QMouseEvent kEvent(QEvent::MouseMove, event);
     v->viewportMouseMoveEvent(&kEvent);
     v->deref();
     
@@ -2157,8 +2106,7 @@ bool KWQKHTMLPart::sendContextMenuEvent(NSEvent *event)
     NSEvent *oldCurrentEvent = _currentEvent;
     _currentEvent = [event retain];
     
-    QMouseEvent qev(QEvent::MouseButtonPress, QPoint([event locationInWindow]),
-        buttonForCurrentEvent(), stateForCurrentEvent(), [event clickCount]);
+    QMouseEvent qev(QEvent::MouseButtonPress, event);
 
     int xm, ym;
     v->viewportToContents(qev.x(), qev.y(), xm, ym);
diff --git a/WebCore/kwq/KWQKPartsEvent.h b/WebCore/kwq/KWQKPartsEvent.h
index f67e5b0..a1be62c 100644
--- a/WebCore/kwq/KWQKPartsEvent.h
+++ b/WebCore/kwq/KWQKPartsEvent.h
@@ -23,8 +23,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef EVENT_H_
-#define EVENT_H_
+#ifndef KWQKPARTSEVENT_H_
+#define KWQKPARTSEVENT_H_
 
 #include "KWQEvent.h"
 
@@ -32,12 +32,19 @@ class QPainter;
 
 namespace KParts {
 
-class Event : public QCustomEvent {
+class Event : public QEvent {
 public:
+    Event(const char *);
+    ~Event();
+
     static bool test(const QEvent *);
     static bool test(const QEvent *, const char *);
 
-    Event(const char *);
+private:
+    char *_name;
+
+    Event(const Event &);
+    Event &operator=(const Event &);
 };
 
 } // namespace KParts
diff --git a/WebCore/kwq/KWQKPartsEvent.mm b/WebCore/kwq/KWQKPartsEvent.mm
index 6ed8218..67893b5 100644
--- a/WebCore/kwq/KWQKPartsEvent.mm
+++ b/WebCore/kwq/KWQKPartsEvent.mm
@@ -25,32 +25,25 @@
 
 #import "KWQKPartsEvent.h"
 
-class QPainter;
-
-#define KPARTS_EVENT_MAGIC 42
-
 namespace KParts {
 
-bool Event::test(const QEvent *event)
+Event::Event(const char *name) : QEvent(KParts), _name(strdup(name))
 {
-  if ( !event )
-    return false;
-  
-  return ( event->type() == (QEvent::Type)(1000 + KPARTS_EVENT_MAGIC ) );
 }
 
-bool Event::test(const QEvent *event, const char *name)
+Event::~Event()
 {
-  if ( !test( event ) )
-    return false;
-  
-  return ( strcmp( name, (const char *)((QCustomEvent *)event)->data() ) == 0 );
+    free(_name);
 }
 
+bool Event::test(const QEvent *event)
+{
+    return event && event->type() == KParts;
+}
 
-Event::Event(const char *eventName)
- : QCustomEvent( (QEvent::Type)(1000 + KPARTS_EVENT_MAGIC), (void *)eventName )
+bool Event::test(const QEvent *event, const char *name)
 {
+    return event && event->type() == KParts && strcmp(name, static_cast<const Event *>(event)->_name) == 0;
 }
 
 } // namespace KParts
diff --git a/WebCore/kwq/KWQKPartsPart.h b/WebCore/kwq/KWQKPartsPart.h
index a75836d..0acf4bf 100644
--- a/WebCore/kwq/KWQKPartsPart.h
+++ b/WebCore/kwq/KWQKPartsPart.h
@@ -53,7 +53,7 @@ public:
     void ref() { ++_ref; }
     void deref() { if (!--_ref) delete this; }
 
-    bool event(QEvent *event) { customEvent((QCustomEvent *)event); return true; }
+    bool event(QEvent *event) { customEvent(event); return true; }
     virtual void customEvent(QCustomEvent *);
     
 private:
diff --git a/WebCore/kwq/KWQNamespace.h b/WebCore/kwq/KWQNamespace.h
index b7f8ea4..b0aff26 100644
--- a/WebCore/kwq/KWQNamespace.h
+++ b/WebCore/kwq/KWQNamespace.h
@@ -80,146 +80,6 @@ public:
         SolidPattern,
     };
 
-    enum Key {
-        Key_Escape = 0x1000,            
-        Key_Tab = 0x1001,
-        Key_Backtab = 0x1002, Key_BackTab = Key_Backtab,
-        Key_Backspace = 0x1003, Key_BackSpace = Key_Backspace,
-        Key_Return = 0x1004,
-        Key_Enter = 0x1005,
-        Key_Insert = 0x1006,
-        Key_Delete = 0x1007,
-        Key_Pause = 0x1008,
-        Key_Print = 0x1009,
-        Key_SysReq = 0x100a,
-        Key_Home = 0x1010,              
-        Key_End = 0x1011,
-        Key_Left = 0x1012,
-        Key_Up = 0x1013,
-        Key_Right = 0x1014,
-        Key_Down = 0x1015,
-        Key_Prior = 0x1016, Key_PageUp = Key_Prior,
-        Key_Next = 0x1017, Key_PageDown = Key_Next,
-        Key_Shift = 0x1020,             
-        Key_Control = 0x1021,
-        Key_Meta = 0x1022,
-        Key_Alt = 0x1023,
-        Key_CapsLock = 0x1024,
-        Key_NumLock = 0x1025,
-        Key_ScrollLock = 0x1026,
-        Key_F1 = 0x1030,                
-        Key_F2 = 0x1031,
-        Key_F3 = 0x1032,
-        Key_F4 = 0x1033,
-        Key_F5 = 0x1034,
-        Key_F6 = 0x1035,
-        Key_F7 = 0x1036,
-        Key_F8 = 0x1037,
-        Key_F9 = 0x1038,
-        Key_F10 = 0x1039,
-        Key_F11 = 0x103a,
-        Key_F12 = 0x103b,
-        Key_F13 = 0x103c,
-        Key_F14 = 0x103d,
-        Key_F15 = 0x103e,
-        Key_F16 = 0x103f,
-        Key_F17 = 0x1040,
-        Key_F18 = 0x1041,
-        Key_F19 = 0x1042,
-        Key_F20 = 0x1043,
-        Key_F21 = 0x1044,
-        Key_F22 = 0x1045,
-        Key_F23 = 0x1046,
-        Key_F24 = 0x1047,
-        Key_F25 = 0x1048,               
-        Key_F26 = 0x1049,
-        Key_F27 = 0x104a,
-        Key_F28 = 0x104b,
-        Key_F29 = 0x104c,
-        Key_F30 = 0x104d,
-        Key_F31 = 0x104e,
-        Key_F32 = 0x104f,
-        Key_F33 = 0x1050,
-        Key_F34 = 0x1051,
-        Key_F35 = 0x1052,
-        Key_Super_L = 0x1053,           
-        Key_Super_R = 0x1054,
-        Key_Menu = 0x1055,
-        Key_Hyper_L = 0x1056,
-        Key_Hyper_R = 0x1057,
-        Key_Help = 0x1058,
-        Key_Space = 0x20,               
-        Key_Any = Key_Space,
-        Key_Exclam = 0x21,
-        Key_QuoteDbl = 0x22,
-        Key_NumberSign = 0x23,
-        Key_Dollar = 0x24,
-        Key_Percent = 0x25,
-        Key_Ampersand = 0x26,
-        Key_Apostrophe = 0x27,
-        Key_ParenLeft = 0x28,
-        Key_ParenRight = 0x29,
-        Key_Asterisk = 0x2a,
-        Key_Plus = 0x2b,
-        Key_Comma = 0x2c,
-        Key_Minus = 0x2d,
-        Key_Period = 0x2e,
-        Key_Slash = 0x2f,
-        Key_0 = 0x30,
-        Key_1 = 0x31,
-        Key_2 = 0x32,
-        Key_3 = 0x33,
-        Key_4 = 0x34,
-        Key_5 = 0x35,
-        Key_6 = 0x36,
-        Key_7 = 0x37,
-        Key_8 = 0x38,
-        Key_9 = 0x39,
-        Key_Colon = 0x3a,
-        Key_Semicolon = 0x3b,
-        Key_Less = 0x3c,
-        Key_Equal = 0x3d,
-        Key_Greater = 0x3e,
-        Key_Question = 0x3f,
-        Key_At = 0x40,
-        Key_A = 0x41,
-        Key_B = 0x42,
-        Key_C = 0x43,
-        Key_D = 0x44,
-        Key_E = 0x45,
-        Key_F = 0x46,
-        Key_G = 0x47,
-        Key_H = 0x48,
-        Key_I = 0x49,
-        Key_J = 0x4a,
-        Key_K = 0x4b,
-        Key_L = 0x4c,
-        Key_M = 0x4d,
-        Key_N = 0x4e,
-        Key_O = 0x4f,
-        Key_P = 0x50,
-        Key_Q = 0x51,
-        Key_R = 0x52,
-        Key_S = 0x53,
-        Key_T = 0x54,
-        Key_U = 0x55,
-        Key_V = 0x56,
-        Key_W = 0x57,
-        Key_X = 0x58,
-        Key_Y = 0x59,
-        Key_Z = 0x5a,
-        Key_BracketLeft = 0x5b,
-        Key_Backslash = 0x5c,
-        Key_BracketRight = 0x5d,
-        Key_AsciiCircum = 0x5e,
-        Key_Underscore = 0x5f,
-        Key_QuoteLeft = 0x60,
-        Key_BraceLeft = 0x7b,
-        Key_Bar = 0x7c,
-        Key_BraceRight = 0x7d,
-        Key_AsciiTilde = 0x7e,
-    };
-    
     enum RasterOp { // raster op mode
         CopyROP,
         OrROP,

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list