Changeset 5226 in webkit


Ignore:
Timestamp:
Oct 20, 2003 10:28:10 AM (21 years ago)
Author:
kocienda
Message:

Reviewed by David

  • khtml/dom/dom2_events.cpp: (UIEvent::keyCode): Change over to use ascii value for key code. (UIEvent::which): Ditto. (KeyboardEvent::KeyboardEvent): New key event class which tracks the DOM Level 3 spec more closely. (KeyboardEvent::operator = ): New function. (KeyboardEvent::~KeyboardEvent): New function. (KeyboardEvent::ctrlKey): New function. (KeyboardEvent::shiftKey): New function. (KeyboardEvent::altKey): New function. (KeyboardEvent::metaKey): New function. (KeyboardEvent::altGraphKey): New function. (KeyboardEvent::initKeyboardEvent): New function.
  • khtml/dom/dom2_events.h: Ditto.
  • khtml/html/html_formimpl.cpp: (HTMLGenericFormElementImpl::defaultEventHandler): Use key identifiers to test which key was pressed, instead of removed keyVal(). (HTMLInputElementImpl::defaultEventHandler): Ditto. (HTMLSelectElementImpl::defaultEventHandler): Ditto.
  • khtml/html/html_inlineimpl.cpp: (HTMLAnchorElementImpl::defaultEventHandler): Change casts to match new class name. Use key identifiers to test which key was pressed, instead of removed keyVal(). Use new modifier accessors.
  • khtml/xml/dom2_eventsimpl.cpp: (EventImpl::typeToId): Some reorganization of the constants in the switch statements. Name change for these to remove the KHTML_ prefix from the key up and key down events will happen soon. (EventImpl::idToType): Ditto. (KeyboardEventImpl::KeyboardEventImpl): New key event class which tracks the DOM Level 3 spec more closely. (KeyboardEventImpl::~KeyboardEventImpl): Ditto. (KeyboardEventImpl::initKeyboardEvent): Ditto.
  • khtml/xml/dom2_eventsimpl.h: (DOM::EventImpl::): Some reorganization of the constants in the switch statements. Name change for these to remove the KHTML_ prefix from the key up and key down events will happen soon. (DOM::KeyboardEventImpl::keyIdentifier): New function. (DOM::KeyboardEventImpl::keyLocation): New function. (DOM::KeyboardEventImpl::ctrlKey): New function. (DOM::KeyboardEventImpl::shiftKey): New function. (DOM::KeyboardEventImpl::altKey): New function. (DOM::KeyboardEventImpl::metaKey): New function. (DOM::KeyboardEventImpl::altGraphKey): New function. (DOM::KeyboardEventImpl::qKeyEvent): New function.
  • khtml/xml/dom_docimpl.cpp: (DocumentImpl::createEvent): Now can create keyboard events.
  • khtml/xml/dom_nodeimpl.cpp: (NodeImpl::dispatchKeyEvent): Class name changes.
  • kwq/KWQEvent.h: Added QString identifier member.
  • kwq/KWQEvent.mm: (hexDigit): Added helper. (identifierForKeyText): Added new function to map keys to DOM key identifiers as listed in the DOM spec. (QKeyEvent::identifier): Added accessor.
  • kwq/KWQKHTMLPart.mm: (KWQKHTMLPart::stateForCurrentEvent): Added check to see if a key press is on one of the numeric keypad keys.
  • kwq/KWQLogging.h: Added log constant for DOM events.
  • kwq/KWQLogging.m: Ditto
Location:
trunk/WebCore
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog-2003-10-25

    r5222 r5226  
     12003-10-20  Ken Kocienda  <kocienda@apple.com>
     2
     3        Reviewed by David
     4
     5        * khtml/dom/dom2_events.cpp:
     6        (UIEvent::keyCode): Change over to use ascii value for key code.
     7        (UIEvent::which): Ditto.
     8        (KeyboardEvent::KeyboardEvent): New key event class which
     9        tracks the DOM Level 3 spec more closely.
     10        (KeyboardEvent::operator = ): New function.
     11        (KeyboardEvent::~KeyboardEvent): New function.
     12        (KeyboardEvent::ctrlKey): New function.
     13        (KeyboardEvent::shiftKey): New function.
     14        (KeyboardEvent::altKey): New function.
     15        (KeyboardEvent::metaKey): New function.
     16        (KeyboardEvent::altGraphKey): New function.
     17        (KeyboardEvent::initKeyboardEvent): New function.
     18        * khtml/dom/dom2_events.h: Ditto.
     19        * khtml/html/html_formimpl.cpp:
     20        (HTMLGenericFormElementImpl::defaultEventHandler): Use key
     21        identifiers to test which key was pressed, instead of removed keyVal().
     22        (HTMLInputElementImpl::defaultEventHandler): Ditto.
     23        (HTMLSelectElementImpl::defaultEventHandler): Ditto.
     24        * khtml/html/html_inlineimpl.cpp:
     25        (HTMLAnchorElementImpl::defaultEventHandler): Change casts to match new
     26        class name. Use key identifiers to test which key was pressed,
     27        instead of removed keyVal(). Use new modifier accessors.
     28        * khtml/xml/dom2_eventsimpl.cpp:
     29        (EventImpl::typeToId): Some reorganization of the constants in the
     30        switch statements. Name change for these to remove the KHTML_ prefix
     31        from the key up and key down events will happen soon.
     32        (EventImpl::idToType): Ditto.
     33        (KeyboardEventImpl::KeyboardEventImpl): New key event class which
     34        tracks the DOM Level 3 spec more closely.
     35        (KeyboardEventImpl::~KeyboardEventImpl): Ditto.
     36        (KeyboardEventImpl::initKeyboardEvent): Ditto.
     37        * khtml/xml/dom2_eventsimpl.h:
     38        (DOM::EventImpl::): Some reorganization of the constants in the
     39        switch statements. Name change for these to remove the KHTML_ prefix
     40        from the key up and key down events will happen soon.
     41        (DOM::KeyboardEventImpl::keyIdentifier): New function.
     42        (DOM::KeyboardEventImpl::keyLocation): New function.
     43        (DOM::KeyboardEventImpl::ctrlKey): New function.
     44        (DOM::KeyboardEventImpl::shiftKey): New function.
     45        (DOM::KeyboardEventImpl::altKey): New function.
     46        (DOM::KeyboardEventImpl::metaKey): New function.
     47        (DOM::KeyboardEventImpl::altGraphKey): New function.
     48        (DOM::KeyboardEventImpl::qKeyEvent): New function.
     49        * khtml/xml/dom_docimpl.cpp:
     50        (DocumentImpl::createEvent): Now can create keyboard events.
     51        * khtml/xml/dom_nodeimpl.cpp:
     52        (NodeImpl::dispatchKeyEvent): Class name changes.
     53        * kwq/KWQEvent.h: Added QString identifier member.
     54        * kwq/KWQEvent.mm:
     55        (hexDigit): Added helper.
     56        (identifierForKeyText): Added new function to map keys to DOM
     57        key identifiers as listed in the DOM spec.
     58        (QKeyEvent::identifier): Added accessor.
     59        * kwq/KWQKHTMLPart.mm:
     60        (KWQKHTMLPart::stateForCurrentEvent): Added check to see if
     61        a key press is on one of the numeric keypad keys.
     62        * kwq/KWQLogging.h: Added log constant for DOM events.
     63        * kwq/KWQLogging.m: Ditto
     64
    1652003-10-20  David Hyatt  <hyatt@apple.com>
    266
  • trunk/WebCore/ChangeLog-2005-08-23

    r5222 r5226  
     12003-10-20  Ken Kocienda  <kocienda@apple.com>
     2
     3        Reviewed by David
     4
     5        * khtml/dom/dom2_events.cpp:
     6        (UIEvent::keyCode): Change over to use ascii value for key code.
     7        (UIEvent::which): Ditto.
     8        (KeyboardEvent::KeyboardEvent): New key event class which
     9        tracks the DOM Level 3 spec more closely.
     10        (KeyboardEvent::operator = ): New function.
     11        (KeyboardEvent::~KeyboardEvent): New function.
     12        (KeyboardEvent::ctrlKey): New function.
     13        (KeyboardEvent::shiftKey): New function.
     14        (KeyboardEvent::altKey): New function.
     15        (KeyboardEvent::metaKey): New function.
     16        (KeyboardEvent::altGraphKey): New function.
     17        (KeyboardEvent::initKeyboardEvent): New function.
     18        * khtml/dom/dom2_events.h: Ditto.
     19        * khtml/html/html_formimpl.cpp:
     20        (HTMLGenericFormElementImpl::defaultEventHandler): Use key
     21        identifiers to test which key was pressed, instead of removed keyVal().
     22        (HTMLInputElementImpl::defaultEventHandler): Ditto.
     23        (HTMLSelectElementImpl::defaultEventHandler): Ditto.
     24        * khtml/html/html_inlineimpl.cpp:
     25        (HTMLAnchorElementImpl::defaultEventHandler): Change casts to match new
     26        class name. Use key identifiers to test which key was pressed,
     27        instead of removed keyVal(). Use new modifier accessors.
     28        * khtml/xml/dom2_eventsimpl.cpp:
     29        (EventImpl::typeToId): Some reorganization of the constants in the
     30        switch statements. Name change for these to remove the KHTML_ prefix
     31        from the key up and key down events will happen soon.
     32        (EventImpl::idToType): Ditto.
     33        (KeyboardEventImpl::KeyboardEventImpl): New key event class which
     34        tracks the DOM Level 3 spec more closely.
     35        (KeyboardEventImpl::~KeyboardEventImpl): Ditto.
     36        (KeyboardEventImpl::initKeyboardEvent): Ditto.
     37        * khtml/xml/dom2_eventsimpl.h:
     38        (DOM::EventImpl::): Some reorganization of the constants in the
     39        switch statements. Name change for these to remove the KHTML_ prefix
     40        from the key up and key down events will happen soon.
     41        (DOM::KeyboardEventImpl::keyIdentifier): New function.
     42        (DOM::KeyboardEventImpl::keyLocation): New function.
     43        (DOM::KeyboardEventImpl::ctrlKey): New function.
     44        (DOM::KeyboardEventImpl::shiftKey): New function.
     45        (DOM::KeyboardEventImpl::altKey): New function.
     46        (DOM::KeyboardEventImpl::metaKey): New function.
     47        (DOM::KeyboardEventImpl::altGraphKey): New function.
     48        (DOM::KeyboardEventImpl::qKeyEvent): New function.
     49        * khtml/xml/dom_docimpl.cpp:
     50        (DocumentImpl::createEvent): Now can create keyboard events.
     51        * khtml/xml/dom_nodeimpl.cpp:
     52        (NodeImpl::dispatchKeyEvent): Class name changes.
     53        * kwq/KWQEvent.h: Added QString identifier member.
     54        * kwq/KWQEvent.mm:
     55        (hexDigit): Added helper.
     56        (identifierForKeyText): Added new function to map keys to DOM
     57        key identifiers as listed in the DOM spec.
     58        (QKeyEvent::identifier): Added accessor.
     59        * kwq/KWQKHTMLPart.mm:
     60        (KWQKHTMLPart::stateForCurrentEvent): Added check to see if
     61        a key press is on one of the numeric keypad keys.
     62        * kwq/KWQLogging.h: Added log constant for DOM events.
     63        * kwq/KWQLogging.m: Ditto
     64
    1652003-10-20  David Hyatt  <hyatt@apple.com>
    266
  • trunk/WebCore/khtml/dom/dom2_events.cpp

    r3993 r5226  
    262262        throw DOMException(DOMException::INVALID_STATE_ERR);
    263263   
    264     KeyEventImpl *keyEvent = dynamic_cast<KeyEventImpl*>(impl);
     264    KeyboardEventImpl *keyEvent = dynamic_cast<KeyboardEventImpl*>(impl);
    265265    if (keyEvent)
    266         return keyEvent->keyVal();
     266        return keyEvent->qKeyEvent()->ascii();
    267267    else
    268268        return 0;
     
    324324    // Note: This property supports both key events and mouse events
    325325
    326     // Value is just like keyCode()
    327     KeyEventImpl *keyEvent = dynamic_cast<KeyEventImpl*>(impl);
     326    // Value is just ascii of key event
     327    KeyboardEventImpl *keyEvent = dynamic_cast<KeyboardEventImpl*>(impl);
    328328    if (keyEvent)
    329         return keyEvent->keyVal();
     329        return keyEvent->qKeyEvent()->ascii();
    330330
    331331    // For khtml, the return values for left, middle and right mouse buttons are 0, 1, 2, respectively.
     
    600600
    601601
     602// -----------------------------------------------------------------------------
     603
     604KeyboardEvent::KeyboardEvent() : UIEvent()
     605{
     606}
     607
     608KeyboardEvent::KeyboardEvent(const KeyboardEvent &other) : UIEvent(other)
     609{
     610}
     611
     612KeyboardEvent::KeyboardEvent(const Event &other) : UIEvent()
     613{
     614    (*this)=other;
     615}
     616
     617KeyboardEvent::KeyboardEvent(KeyboardEventImpl *impl) : UIEvent(impl)
     618{
     619}
     620
     621KeyboardEvent &KeyboardEvent::operator = (const KeyboardEvent &other)
     622{
     623    UIEvent::operator = (other);
     624    return *this;
     625}
     626
     627KeyboardEvent &KeyboardEvent::operator = (const Event &other)
     628{
     629    Event e;
     630    e = other;
     631    if (!e.isNull() && !e.handle()->isKeyboardEvent()) {
     632        if ( impl ) impl->deref();
     633        impl = 0;
     634    } else
     635        UIEvent::operator = (other);
     636    return *this;
     637}
     638
     639KeyboardEvent::~KeyboardEvent()
     640{
     641}
     642
     643bool KeyboardEvent::ctrlKey() const
     644{
     645    if (!impl)
     646        throw DOMException(DOMException::INVALID_STATE_ERR);
     647
     648    return static_cast<KeyboardEventImpl*>(impl)->ctrlKey();
     649}
     650
     651bool KeyboardEvent::shiftKey() const
     652{
     653    if (!impl)
     654        throw DOMException(DOMException::INVALID_STATE_ERR);
     655
     656    return static_cast<KeyboardEventImpl*>(impl)->shiftKey();
     657}
     658
     659bool KeyboardEvent::altKey() const
     660{
     661    if (!impl)
     662        throw DOMException(DOMException::INVALID_STATE_ERR);
     663
     664    return static_cast<KeyboardEventImpl*>(impl)->altKey();
     665}
     666
     667bool KeyboardEvent::metaKey() const
     668{
     669    if (!impl)
     670        throw DOMException(DOMException::INVALID_STATE_ERR);
     671
     672    return static_cast<KeyboardEventImpl*>(impl)->metaKey();
     673}
     674
     675bool KeyboardEvent::altGraphKey() const
     676{
     677    if (!impl)
     678        throw DOMException(DOMException::INVALID_STATE_ERR);
     679
     680    return static_cast<KeyboardEventImpl*>(impl)->altGraphKey();
     681}
     682
     683void KeyboardEvent::initKeyboardEvent(const DOMString &typeArg,
     684                                        bool canBubbleArg,
     685                                        bool cancelableArg,
     686                                        const AbstractView &viewArg,
     687                                        const DOMString &keyIdentifierArg,
     688                                        unsigned long keyLocationArg,
     689                                        bool ctrlKeyArg,
     690                                        bool shiftKeyArg,
     691                                        bool altKeyArg,
     692                                        bool metaKeyArg,
     693                                        bool altGraphKeyArg)
     694{
     695    if (!impl)
     696        throw DOMException(DOMException::INVALID_STATE_ERR);
     697
     698    static_cast<KeyboardEventImpl*>(impl)->initKeyboardEvent(typeArg,canBubbleArg,
     699        cancelableArg,viewArg,keyIdentifierArg,keyLocationArg,ctrlKeyArg,altKeyArg,
     700        shiftKeyArg,metaKeyArg,altGraphKeyArg);
     701}
     702                                   
  • trunk/WebCore/khtml/dom/dom2_events.h

    r3993 r5226  
    3535class MouseEvent;
    3636class MutationEvent;
     37class KeyboardEvent;
    3738class AbstractView;
    3839
     
    4243class MouseEventImpl;
    4344class MutationEventImpl;
     45class KeyboardEventImpl;
    4446
    4547
     
    661663
    662664
     665/**
     666 * Introduced in DOM Level 3
     667 *
     668 * The KeyboardEvent interface provides specific contextual information
     669 * associated with Keyboard events.
     670 *
     671 */
     672class KeyboardEvent : public UIEvent {
     673public:
     674    KeyboardEvent();
     675    KeyboardEvent(const KeyboardEvent &other);
     676    KeyboardEvent(const Event &other);
     677    KeyboardEvent & operator = (const KeyboardEvent &other);
     678    KeyboardEvent & operator = (const Event &other);
     679    virtual ~KeyboardEvent();
     680
     681    // KeyLocationCode
     682    static const unsigned long DOM_KEY_LOCATION_STANDARD      = 0x00;
     683    static const unsigned long DOM_KEY_LOCATION_LEFT          = 0x01;
     684    static const unsigned long DOM_KEY_LOCATION_RIGHT         = 0x02;
     685    static const unsigned long DOM_KEY_LOCATION_NUMPAD        = 0x03;
     686    static const unsigned long DOM_KEY_LOCATION_UNKNOWN       = 0x04;
     687   
     688    /**
     689     * Holds the identifier of the key.
     690     *
     691     */
     692    DOMString keyIdentifier() const;
     693
     694    /**
     695     * Contains an indication of the location of they key on the device.
     696     *
     697     */
     698    unsigned long keyLocation() const;
     699
     700    /**
     701     * Used to indicate whether the 'ctrl' key was depressed during the firing
     702     * of the event.
     703     */
     704    bool ctrlKey() const;
     705
     706    /**
     707     * Used to indicate whether the 'shift' key was depressed during the firing
     708     * of the event.
     709     *
     710     */
     711    bool shiftKey() const;
     712
     713    /**
     714     * Used to indicate whether the 'alt' key was depressed during the firing
     715     * of the event. On some platforms this key may map to an alternative key
     716     * name.
     717     *
     718     */
     719    bool altKey() const;
     720
     721    /**
     722     * Used to indicate whether the 'meta' key was depressed during the firing
     723     * of the event. On some platforms this key may map to an alternative key
     724     * name.
     725     *
     726     */
     727    bool metaKey() const;
     728
     729    /**
     730     * Used to indicate whether the 'alt graph' (?) key was depressed during the firing
     731     * of the event. On some platforms this key may map to an alternative key
     732     * name.
     733     *
     734     */
     735    bool altGraphKey() const;
     736
     737    void initKeyboardEvent(const DOMString &typeArg,
     738                                bool canBubbleArg,
     739                                bool cancelableArg,
     740                                const AbstractView &viewArg,
     741                                const DOMString &keyIdentifierArg,
     742                                unsigned long keyLocationArg,
     743                                bool ctrlKeyArg,
     744                                bool shiftKeyArg,
     745                                bool altKeyArg,
     746                                bool metaKeyArg,
     747                                bool altGraphKeyArg);
     748                                       
     749protected:
     750    KeyboardEvent(KeyboardEventImpl *impl);
     751};
    663752
    664753}; //namespace
  • trunk/WebCore/khtml/html/html_formimpl.cpp

    r5218 r5226  
    857857            evt->id()==EventImpl::KHTML_KEYUP_EVENT)
    858858        {
    859             KeyEventImpl * k = static_cast<KeyEventImpl *>(evt);
     859            KeyboardEventImpl * k = static_cast<KeyboardEventImpl *>(evt);
    860860            if (k->keyVal() == QChar('\n').unicode() && m_render && m_render->isWidget() && k->qKeyEvent)
    861861                QApplication::sendEvent(static_cast<RenderWidget *>(m_render)->widget(), k->qKeyEvent);
     
    17261726            return;
    17271727       
    1728         unsigned long keyVal = static_cast<KeyEventImpl *>(evt)->keyVal();
     1728        DOMString key = static_cast<KeyboardEventImpl *>(evt)->keyIdentifier();
    17291729       
    17301730        switch (m_type) {
     
    17331733            case SUBMIT:
    17341734                // simulate mouse click for spacebar, return, and enter
    1735                 if (keyVal == ' ' || keyVal == '\r' || keyVal == 0x3) {
     1735                if (key == "U+000020" || key == "U+00000d" || key == "Enter") {
    17361736                    simulateButtonClickForEvent(evt);
    17371737                }
     
    17411741                // for return or enter, find the first successful image or submit element
    17421742                // send it a simulated mouse click
    1743                 if (keyVal == '\r' || keyVal == 0x3) {
     1743                if (key == "U+00000d" || key == "Enter") {
    17441744                    QPtrListIterator<HTMLGenericFormElementImpl> it(m_form->formElements);
    17451745                    for (; it.current(); ++it) {
     
    22802280            return;
    22812281       
    2282         unsigned long keyVal = static_cast<KeyEventImpl *>(evt)->keyVal();
     2282        DOMString key = static_cast<KeyboardEventImpl *>(evt)->keyIdentifier();
    22832283       
    2284         if (keyVal == '\r' || keyVal == 0x3) {
     2284        if (key == "U+00000d" || key == "Enter") {
    22852285            QPtrListIterator<HTMLGenericFormElementImpl> it(m_form->formElements);
    22862286            for (; it.current(); ++it) {
  • trunk/WebCore/khtml/html/html_inlineimpl.cpp

    r4704 r5226  
    6262{
    6363    // React on clicks and on keypresses.
    64     // Don't make this KEYUP_EVENT again, it makes khtml follow links it shouldn't,
     64    // Don't make this KHTML_KEYUP_EVENT again, it makes khtml follow links it shouldn't,
    6565    // when pressing Enter in the combo.
    6666    if ( ( evt->id() == EventImpl::KHTML_CLICK_EVENT ||
     
    7070            e = static_cast<MouseEventImpl*>( evt );
    7171
    72         KeyEventImpl *k = 0;
     72        KeyboardEventImpl *k = 0;
    7373        if (evt->id() == EventImpl::KHTML_KEYDOWN_EVENT)
    74             k = static_cast<KeyEventImpl *>( evt );
     74            k = static_cast<KeyboardEventImpl *>( evt );
    7575
    7676        QString utarget;
     
    8383
    8484        if ( k ) {
    85             if (k->virtKeyVal() != KeyEventImpl::DOM_VK_ENTER) {
     85            if (k->keyIdentifier() != "Enter") {
    8686                HTMLElementImpl::defaultEventHandler(evt);
    8787                return;
    8888            }
    89             if (k->qKeyEvent) k->qKeyEvent->accept();
     89            if (k->qKeyEvent()) k->qKeyEvent()->accept();
    9090        }
    9191
     
    139139            else if ( k )
    140140            {
    141               if ( k->checkModifier(Qt::ShiftButton) )
     141              if ( k->shiftKey() )
    142142                state |= Qt::ShiftButton;
    143               if ( k->checkModifier(Qt::AltButton) )
     143              if ( k->altKey() )
    144144                state |= Qt::AltButton;
    145               if ( k->checkModifier(Qt::ControlButton) )
     145              if ( k->ctrlKey() )
    146146                state |= Qt::ControlButton;
    147147            }
  • trunk/WebCore/khtml/xml/dom2_eventsimpl.cpp

    r4840 r5226  
    222222    else if (type == "contextmenu")
    223223        return CONTEXTMENU_EVENT;
     224    else if (type == "keydown")
     225        return KHTML_KEYDOWN_EVENT;
     226    else if (type == "keyup")
     227        return KHTML_KEYUP_EVENT;
     228    else if (type == "textInput")
     229        return TEXTINPUT_EVENT;
    224230    // ignore: KHTML_DBLCLICK_EVENT
    225231    // ignore: KHTML_CLICK_EVENT
     
    288294        case CONTEXTMENU_EVENT:
    289295            return "contextmenu";
     296        case KHTML_KEYDOWN_EVENT:
     297            return "keydown";
     298        case KHTML_KEYUP_EVENT:
     299            return "keyup";
     300        case TEXTINPUT_EVENT:
     301            return "textInput";
    290302        // khtml extensions
    291303        case KHTML_DBLCLICK_EVENT:
     
    297309        case KHTML_ERROR_EVENT:
    298310            return "khtml_error";
    299         case KHTML_KEYDOWN_EVENT:
    300             return "khtml_keydown";
    301311        case KHTML_KEYPRESS_EVENT:
    302312            return "khtml_keypress";
    303         case KHTML_KEYUP_EVENT:
    304             return "khtml_keyup";
    305313        case KHTML_MOVE_EVENT:
    306314            return "khtml_move";
     
    552560//---------------------------------------------------------------------------------------------
    553561
    554 
    555 KeyEventImpl::KeyEventImpl()
    556 {
    557   qKeyEvent = 0;
    558 }
    559 
    560 KeyEventImpl::KeyEventImpl(QKeyEvent *key, AbstractViewImpl *view)
     562KeyboardEventImpl::KeyboardEventImpl()
     563{
     564  m_keyEvent = 0;
     565}
     566
     567KeyboardEventImpl::KeyboardEventImpl(QKeyEvent *key, AbstractViewImpl *view)
    561568  : UIEventImpl(key->type() == QEvent::KeyRelease ? KHTML_KEYUP_EVENT : key->isAutoRepeat() ? KHTML_KEYPRESS_EVENT : KHTML_KEYDOWN_EVENT,
    562569                true,true,view,0)
    563570{
    564   qKeyEvent = new QKeyEvent(key->type(), key->key(), key->ascii(), key->state(), key->text(), key->isAutoRepeat(), key->count() );
    565   // Events are supposed to be accepted by default in Qt!
    566   // This line made QLineEdit's keyevents be ignored, so they were sent to the khtmlview
    567   // (and e.g. space would make it scroll down)
    568   //qKeyEvent->ignore();
    569 
    570   m_detail = key->count();
    571 
    572   m_numPad = false;
    573   m_keyVal = 0;
    574   m_virtKeyVal = DOM_VK_UNDEFINED;
    575   m_inputGenerated = true;
    576 
    577   switch(key->key())
    578   {
    579   case Qt::Key_Enter:
    580       m_numPad = true;
    581       /* fall through */
    582   case Qt::Key_Return:
    583       m_virtKeyVal = DOM_VK_ENTER;
    584       break;
    585   case Qt::Key_NumLock:
    586       m_numPad = true;
    587       m_virtKeyVal = DOM_VK_NUM_LOCK;
    588       break;
    589   case Qt::Key_Alt:
    590       m_virtKeyVal = DOM_VK_RIGHT_ALT;
    591       // ### DOM_VK_LEFT_ALT;
    592       break;
    593   case Qt::Key_Control:
    594       m_virtKeyVal = DOM_VK_LEFT_CONTROL;
    595       // ### DOM_VK_RIGHT_CONTROL
    596       break;
    597   case Qt::Key_Shift:
    598       m_virtKeyVal = DOM_VK_LEFT_SHIFT;
    599       // ### DOM_VK_RIGHT_SHIFT
    600       break;
    601   case Qt::Key_Meta:
    602       m_virtKeyVal = DOM_VK_LEFT_META;
    603       // ### DOM_VK_RIGHT_META
    604       break;
    605   case Qt::Key_CapsLock:
    606       m_virtKeyVal = DOM_VK_CAPS_LOCK;
    607       break;
    608   case Qt::Key_Delete:
    609       m_virtKeyVal = DOM_VK_DELETE;
    610       break;
    611   case Qt::Key_End:
    612       m_virtKeyVal = DOM_VK_END;
    613       break;
    614   case Qt::Key_Escape:
    615       m_virtKeyVal = DOM_VK_ESCAPE;
    616       break;
    617   case Qt::Key_Home:
    618       m_virtKeyVal = DOM_VK_HOME;
    619       break;
    620   case Qt::Key_Insert:
    621       m_virtKeyVal = DOM_VK_INSERT;
    622       break;
    623   case Qt::Key_Pause:
    624       m_virtKeyVal = DOM_VK_PAUSE;
    625       break;
    626   case Qt::Key_Print:
    627       m_virtKeyVal = DOM_VK_PRINTSCREEN;
    628       break;
    629   case Qt::Key_ScrollLock:
    630       m_virtKeyVal = DOM_VK_SCROLL_LOCK;
    631       break;
    632   case Qt::Key_Left:
    633       m_virtKeyVal = DOM_VK_LEFT;
    634       break;
    635   case Qt::Key_Right:
    636       m_virtKeyVal = DOM_VK_RIGHT;
    637       break;
    638   case Qt::Key_Up:
    639       m_virtKeyVal = DOM_VK_UP;
    640       break;
    641   case Qt::Key_Down:
    642       m_virtKeyVal = DOM_VK_DOWN;
    643       break;
    644   case Qt::Key_Next:
    645       m_virtKeyVal = DOM_VK_PAGE_DOWN;
    646       break;
    647   case Qt::Key_Prior:
    648       m_virtKeyVal = DOM_VK_PAGE_UP;
    649       break;
    650   case Qt::Key_F1:
    651       m_virtKeyVal = DOM_VK_F1;
    652       break;
    653   case Qt::Key_F2:
    654       m_virtKeyVal = DOM_VK_F2;
    655       break;
    656   case Qt::Key_F3:
    657       m_virtKeyVal = DOM_VK_F3;
    658       break;
    659   case Qt::Key_F4:
    660       m_virtKeyVal = DOM_VK_F4;
    661       break;
    662   case Qt::Key_F5:
    663       m_virtKeyVal = DOM_VK_F5;
    664       break;
    665   case Qt::Key_F6:
    666       m_virtKeyVal = DOM_VK_F6;
    667       break;
    668   case Qt::Key_F7:
    669       m_virtKeyVal = DOM_VK_F7;
    670       break;
    671   case Qt::Key_F8:
    672       m_virtKeyVal = DOM_VK_F8;
    673       break;
    674   case Qt::Key_F9:
    675       m_virtKeyVal = DOM_VK_F9;
    676       break;
    677   case Qt::Key_F10:
    678       m_virtKeyVal = DOM_VK_F10;
    679       break;
    680   case Qt::Key_F11:
    681       m_virtKeyVal = DOM_VK_F11;
    682       break;
    683   case Qt::Key_F12:
    684       m_virtKeyVal = DOM_VK_F12;
    685       break;
    686   case Qt::Key_F13:
    687       m_virtKeyVal = DOM_VK_F13;
    688       break;
    689   case Qt::Key_F14:
    690       m_virtKeyVal = DOM_VK_F14;
    691       break;
    692   case Qt::Key_F15:
    693       m_virtKeyVal = DOM_VK_F15;
    694       break;
    695   case Qt::Key_F16:
    696       m_virtKeyVal = DOM_VK_F16;
    697       break;
    698   case Qt::Key_F17:
    699       m_virtKeyVal = DOM_VK_F17;
    700       break;
    701   case Qt::Key_F18:
    702       m_virtKeyVal = DOM_VK_F18;
    703       break;
    704   case Qt::Key_F19:
    705       m_virtKeyVal = DOM_VK_F19;
    706       break;
    707   case Qt::Key_F20:
    708       m_virtKeyVal = DOM_VK_F20;
    709       break;
    710   case Qt::Key_F21:
    711       m_virtKeyVal = DOM_VK_F21;
    712       break;
    713   case Qt::Key_F22:
    714       m_virtKeyVal = DOM_VK_F22;
    715       break;
    716   case Qt::Key_F23:
    717       m_virtKeyVal = DOM_VK_F23;
    718       break;
    719   case Qt::Key_F24:
    720       m_virtKeyVal = DOM_VK_F24;
    721       break;
    722   default:
    723       m_virtKeyVal = DOM_VK_UNDEFINED;
    724       break;
    725   }
    726 
    727   // m_keyVal should contain the unicode value
    728   // of the pressed key if available.
    729   if (m_virtKeyVal == DOM_VK_UNDEFINED && !key->text().isNull())
    730       m_keyVal = key->text().unicode()[0];
    731 
    732   //  m_numPad = ???
    733 
    734   // key->state returns enum ButtonState, which is ShiftButton, ControlButton and AltButton or'ed together.
    735   m_modifier = key->state();
    736 
    737   // key->text() returns the unicode sequence as a QString
    738   m_outputString = DOMString(key->text());
    739 }
    740 
    741 KeyEventImpl::KeyEventImpl(EventId _id,
    742                            bool canBubbleArg,
    743                            bool cancelableArg,
    744                            AbstractViewImpl *viewArg,
    745                            unsigned short detailArg,
    746                            DOMString &outputStringArg,
    747                            unsigned long keyValArg,
    748                            unsigned long virtKeyValArg,
    749                            bool inputGeneratedArg,
    750                            bool numPadArg)
    751   : UIEventImpl(_id,canBubbleArg,cancelableArg,viewArg,detailArg)
    752 {
    753   qKeyEvent = 0;
    754   m_keyVal = keyValArg;
    755   m_virtKeyVal = virtKeyValArg;
    756   m_inputGenerated = inputGeneratedArg;
    757   m_outputString = outputStringArg;
    758   m_numPad = numPadArg;
    759   m_modifier = 0;
    760 }
    761 
    762 KeyEventImpl::~KeyEventImpl()
    763 {
    764     delete qKeyEvent;
    765 }
    766 
    767 bool KeyEventImpl::checkModifier(unsigned long modifierArg)
    768 {
    769   return ((m_modifier && modifierArg) == modifierArg);
    770 }
    771 
    772 void KeyEventImpl::initKeyEvent(DOMString &typeArg,
    773                                 bool canBubbleArg,
    774                                 bool cancelableArg,
    775                                 const AbstractView &viewArg,
    776                                 long detailArg,
    777                                 DOMString &outputStringArg,
    778                                 unsigned long keyValArg,
    779                                 unsigned long virtKeyValArg,
    780                                 bool inputGeneratedArg,
    781                                 bool numPadArg)
    782 {
    783   UIEventImpl::initUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg);
    784 
    785   m_outputString = outputStringArg;
    786   m_keyVal = keyValArg;
    787   m_virtKeyVal = virtKeyValArg;
    788   m_inputGenerated = inputGeneratedArg;
    789   m_numPad = numPadArg;
    790 }
    791 
    792 void KeyEventImpl::initModifier(unsigned long modifierArg,
    793                                 bool valueArg)
    794 {
    795   if (valueArg)
    796       m_modifier |= modifierArg;
    797   else
    798       m_modifier &= (modifierArg ^ 0xFFFFFFFF);
    799 }
    800 
    801 bool             KeyEventImpl::inputGenerated() const
    802 {
    803   return m_inputGenerated;
    804 }
    805 
    806 unsigned long    KeyEventImpl::keyVal() const
    807 {
    808   return m_keyVal;
    809 }
    810 
    811 DOMString        KeyEventImpl::outputString() const
    812 {
    813   return m_outputString;
     571    m_keyEvent = new QKeyEvent(key->type(), key->key(), key->ascii(), key->state(), key->text(), key->isAutoRepeat(), key->count());
     572    // Events are supposed to be accepted by default in Qt!
     573    // This line made QLineEdit's keyevents be ignored, so they were sent to the khtmlview
     574    // (and e.g. space would make it scroll down)
     575    //qKeyEvent->ignore();
     576
     577    // m_keyIdentifier should contain the unicode value of the pressed key if available.
     578    // key->text() returns the unicode sequence as a QString
     579    if (!key->text().isNull()) {
     580        DOMString identifier(m_keyEvent->identifier());
     581        m_keyIdentifier = identifier.implementation();
     582        m_keyIdentifier->ref();
     583    }
     584    else {
     585        m_keyIdentifier = DOMString("Unidentified").implementation();
     586        m_keyIdentifier->ref();
     587    }
     588
     589    // key->state returns enum ButtonState, which is ShiftButton, ControlButton and AltButton or'ed together.
     590    int keyState = key->state();
     591    if (keyState & Qt::ControlButton)
     592        m_ctrlKey = true;
     593    if (keyState & Qt::ShiftButton)
     594        m_shiftKey = true;
     595    if (keyState & Qt::AltButton)
     596        m_altKey = true;
     597    if (keyState & Qt::MetaButton)
     598        m_metaKey = true;
     599    // altGraphKey is not supported by Qt.
     600   
     601    // Note: we only support testing for num pad
     602    m_keyLocation = (keyState & Qt::Keypad) ? KeyboardEvent::DOM_KEY_LOCATION_NUMPAD : KeyboardEvent::DOM_KEY_LOCATION_STANDARD;
     603}
     604
     605KeyboardEventImpl::KeyboardEventImpl(EventId _id,
     606                                        bool canBubbleArg,
     607                                        bool cancelableArg,
     608                                        AbstractViewImpl *viewArg,
     609                                        const DOMString &keyIdentifierArg,
     610                                        unsigned long keyLocationArg,
     611                                        bool ctrlKeyArg,
     612                                        bool shiftKeyArg,
     613                                        bool altKeyArg,
     614                                        bool metaKeyArg,
     615                                        bool altGraphKeyArg)
     616  : UIEventImpl(_id,canBubbleArg,cancelableArg,viewArg,0)
     617{
     618    m_keyEvent = 0;
     619    m_keyIdentifier = keyIdentifierArg.implementation();
     620    if (m_keyIdentifier)
     621        m_keyIdentifier->ref();
     622    m_keyLocation = keyLocationArg;
     623    m_ctrlKey = ctrlKeyArg;
     624    m_shiftKey = shiftKeyArg;
     625    m_altKey = altKeyArg;
     626    m_metaKey = metaKeyArg;
     627    m_altGraphKey = altGraphKeyArg;
     628}
     629
     630KeyboardEventImpl::~KeyboardEventImpl()
     631{
     632    delete m_keyEvent;
     633    if (m_keyIdentifier)
     634        m_keyIdentifier->deref();
     635}
     636
     637void KeyboardEventImpl::initKeyboardEvent(const DOMString &typeArg,
     638                        bool canBubbleArg,
     639                        bool cancelableArg,
     640                        const AbstractView &viewArg,
     641                        const DOMString &keyIdentifierArg,
     642                        unsigned long keyLocationArg,
     643                        bool ctrlKeyArg,
     644                        bool shiftKeyArg,
     645                        bool altKeyArg,
     646                        bool metaKeyArg,
     647                        bool altGraphKeyArg)
     648{
     649    if (m_keyIdentifier)
     650        m_keyIdentifier->deref();
     651
     652    UIEventImpl::initUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, 0);
     653    m_keyIdentifier = keyIdentifierArg.implementation();
     654    if (m_keyIdentifier)
     655        m_keyIdentifier->ref();
     656    m_keyLocation = keyLocationArg;
     657    m_ctrlKey = ctrlKeyArg;
     658    m_shiftKey = shiftKeyArg;
     659    m_altKey = altKeyArg;
     660    m_metaKey = metaKeyArg;
     661    m_altGraphKey = altGraphKeyArg;
    814662}
    815663
  • trunk/WebCore/khtml/xml/dom2_eventsimpl.h

    r5129 r5226  
    7979        SCROLL_EVENT,
    8080        CONTEXTMENU_EVENT,
     81        // Keyboard events
     82        KHTML_KEYDOWN_EVENT,
     83        KHTML_KEYUP_EVENT,
     84        // Text events
     85        TEXTINPUT_EVENT,
    8186        // khtml events (not part of DOM)
    8287        KHTML_DBLCLICK_EVENT, // for html ondblclick
     
    8489        KHTML_DRAGDROP_EVENT,
    8590        KHTML_ERROR_EVENT,
    86         KHTML_KEYDOWN_EVENT,
    8791        KHTML_KEYPRESS_EVENT,
    88         KHTML_KEYUP_EVENT,
    8992        KHTML_MOVE_EVENT,
    9093        KHTML_ORIGCLICK_MOUSEUP_EVENT
     
    123126    static DOMString idToType(EventId id);
    124127
    125     void setDefaultHandled();
     128    virtual void setDefaultHandled();
    126129    bool defaultHandled() const { return m_defaultHandled; }
    127130
     
    238241
    239242
    240 // Introduced in DOM Level 3:
    241 /**
    242  * DOM::KeyEvent
    243  * The detail attribute inherited from UIEvent is used to indicate
    244  * the number of keypresses which have occurred during key repetition.
    245  * If this information is not available this value should be 0.
    246  */
    247 class KeyEventImpl : public UIEventImpl {
    248 public:
    249   KeyEventImpl();
    250   KeyEventImpl(EventId _id,
    251                bool canBubbleArg,
    252                bool cancelableArg,
    253                AbstractViewImpl *viewArg,
    254                unsigned short detailArg,
    255                DOMString &outputStringArg,
    256                unsigned long keyValArg,
    257                unsigned long virtKeyValArg,
    258                bool inputGeneratedArg,
    259                bool numPadArg);
    260 
    261   KeyEventImpl(QKeyEvent *key, AbstractViewImpl *view);
    262 
    263   virtual ~KeyEventImpl();
    264 
    265   // VirtualKeyCode
    266   enum KeyCodes  {
    267          DOM_VK_UNDEFINED               = 0x0,
    268          DOM_VK_RIGHT_ALT               = 0x01,
    269          DOM_VK_LEFT_ALT                = 0x02,
    270          DOM_VK_LEFT_CONTROL            = 0x03,
    271          DOM_VK_RIGHT_CONTROL           = 0x04,
    272          DOM_VK_LEFT_SHIFT              = 0x05,
    273          DOM_VK_RIGHT_SHIFT             = 0x06,
    274          DOM_VK_LEFT_META               = 0x07,
    275          DOM_VK_RIGHT_META              = 0x08,
    276          DOM_VK_CAPS_LOCK               = 0x09,
    277          DOM_VK_DELETE                  = 0x0A,
    278          DOM_VK_END                     = 0x0B,
    279          DOM_VK_ENTER                   = 0x0C,
    280          DOM_VK_ESCAPE                  = 0x0D,
    281          DOM_VK_HOME                    = 0x0E,
    282          DOM_VK_INSERT                  = 0x0F,
    283          DOM_VK_NUM_LOCK                = 0x10,
    284          DOM_VK_PAUSE                   = 0x11,
    285          DOM_VK_PRINTSCREEN             = 0x12,
    286          DOM_VK_SCROLL_LOCK             = 0x13,
    287          DOM_VK_LEFT                    = 0x14,
    288          DOM_VK_RIGHT                   = 0x15,
    289          DOM_VK_UP                      = 0x16,
    290          DOM_VK_DOWN                    = 0x17,
    291          DOM_VK_PAGE_DOWN               = 0x18,
    292          DOM_VK_PAGE_UP                 = 0x19,
    293          DOM_VK_F1                      = 0x1A,
    294          DOM_VK_F2                      = 0x1B,
    295          DOM_VK_F3                      = 0x1C,
    296          DOM_VK_F4                      = 0x1D,
    297          DOM_VK_F5                      = 0x1E,
    298          DOM_VK_F6                      = 0x1F,
    299          DOM_VK_F7                      = 0x20,
    300          DOM_VK_F8                      = 0x21,
    301          DOM_VK_F9                      = 0x22,
    302          DOM_VK_F10                     = 0x23,
    303          DOM_VK_F11                     = 0x24,
    304          DOM_VK_F12                     = 0x25,
    305          DOM_VK_F13                     = 0x26,
    306          DOM_VK_F14                     = 0x27,
    307          DOM_VK_F15                     = 0x28,
    308          DOM_VK_F16                     = 0x29,
    309          DOM_VK_F17                     = 0x2A,
    310          DOM_VK_F18                     = 0x2B,
    311          DOM_VK_F19                     = 0x2C,
    312          DOM_VK_F20                     = 0x2D,
    313          DOM_VK_F21                     = 0x2E,
    314          DOM_VK_F22                     = 0x2F,
    315          DOM_VK_F23                     = 0x30,
    316          DOM_VK_F24                     = 0x31
    317   };
    318 
    319  /**
    320   *  checkModifier
    321   *
    322   * Note: the below description does not match the actual behaviour.
    323   *       it's extended in a way that you can query multiple modifiers
    324   *       at once by logically OR`ing them.
    325   *       also, we use the Qt modifier enum instead of the DOM one.
    326   *
    327   * The CheckModifier method is used to check the status of a single
    328   * modifier key associated with a KeyEvent. The identifier of the
    329   * modifier in question is passed into the CheckModifier function. If
    330   * the modifier is triggered it will return true. If not, it will
    331   * return false.  The list of keys below represents the allowable
    332   * modifier paramaters for this method:
    333   *     DOM_VK_LEFT_ALT
    334   *     DOM_VK_RIGHT_ALT
    335   *     DOM_VK_LEFT_CONTROL
    336   *     DOM_VK_RIGHT_CONTROL
    337   *     DOM_VK_LEFT_SHIFT
    338   *     DOM_VK_RIGHT_SHIFT
    339   *     DOM_VK_META
    340   *
    341   * Parameters:
    342   *
    343   * modifer of type unsigned long
    344   *   The modifier which the user wishes to query.
    345   *
    346   * Return Value: boolean
    347   *   The status of the modifier represented as a boolean.
    348   *
    349   * No Exceptions
    350   */
    351  bool checkModifier(unsigned long modiferArg);
    352 
    353  /**
    354   * initKeyEvent
    355   *
    356   * The initKeyEvent method is used to initialize the value of a
    357   * MouseEvent created through the DocumentEvent interface. This
    358   * method may only be called before the KeyEvent has been dispatched
    359   * via the dispatchEvent method, though it may be called multiple
    360   * times during that phase if necessary. If called multiple times,
    361   * the final invocation takes precedence. This method has no effect
    362   * if called after the event has been dispatched.
    363   *
    364   * Parameters:
    365   *
    366   * typeArg of type DOMString
    367   *   Specifies the event type.
    368   * canBubbleArg of type boolean
    369   *   Specifies whether or not the event can bubble.
    370   * cancelableArg of type boolean
    371   *   Specifies whether or not the event's default action can be prevent.
    372   * viewArg of type views::AbstractView
    373   *   Specifies the KeyEvent's AbstractView.
    374   * detailArg of type unsigned short
    375   *   Specifies the number of repeated keypresses, if available.
    376   * outputStringArg of type DOMString
    377   *   Specifies the KeyEvent's outputString attribute
    378   * keyValArg of type unsigned long
    379   *   Specifies the KeyEvent's keyValattribute
    380   * virtKeyValArg of type unsigned long
    381   *   Specifies the KeyEvent's virtKeyValattribute
    382   * inputGeneratedArg of type boolean
    383   *   Specifies the KeyEvent's inputGeneratedattribute
    384   * numPadArg of type boolean
    385   *   Specifies the KeyEvent's numPadattribute
    386   *
    387   * No Return Value.
    388   * No Exceptions.
    389   */
    390  void initKeyEvent(DOMString &typeArg,
    391                    bool canBubbleArg,
    392                    bool cancelableArg,
    393                    const AbstractView &viewArg,
    394                    long detailArg,
    395                    DOMString &outputStringArg,
    396                    unsigned long keyValArg,
    397                    unsigned long virtKeyValArg,
    398                    bool inputGeneratedArg,
    399                    bool numPadArg);
    400  /**
    401   * initModifier
    402   *
    403   * The initModifier method is used to initialize the values of any
    404   * modifiers associated with a KeyEvent created through the
    405   * DocumentEvent interface. This method may only be called before the
    406   * KeyEvent has been dispatched via the dispatchEvent method, though
    407   * it may be called multiple times during that phase if necessary. If
    408   * called multiple times with the same modifier property the final
    409   * invocation takes precedence. Unless explicitly give a value of
    410   * true, all modifiers have a value of false. This method has no
    411   * effect if called after the event has been dispatched.  The list of
    412   * keys below represents the allowable modifier paramaters for this
    413   * method:
    414   *    DOM_VK_LEFT_ALT
    415   *    DOM_VK_RIGHT_ALT
    416   *    DOM_VK_LEFT_CONTROL
    417   *    DOM_VK_RIGHT_CONTROL
    418   *    DOM_VK_LEFT_SHIFT
    419   *    DOM_VK_RIGHT_SHIFT
    420   *    DOM_VK_META
    421   *
    422   * Parameters:
    423   *
    424   * modifier of type unsigned long
    425   *   The modifier which the user wishes to initialize
    426   * value of type boolean
    427   *   The new value of the modifier.
    428   *
    429   * No Return Value
    430   * No Exceptions
    431   */
    432  void initModifier(unsigned long modifierArg, bool valueArg);
    433 
    434  //Attributes:
    435 
    436  /**
    437   * inputGenerated of type boolean
    438   *
    439   *  The inputGenerated attribute indicates whether the key event will
    440   *  normally cause visible output. If the key event does not
    441   *  generate any visible output, such as the use of a function key
    442   *  or the combination of certain modifier keys used in conjunction
    443   *  with another key, then the value will be false. If visible
    444   *  output is normally generated by the key event then the value
    445   *  will be true.  The value of inputGenerated does not guarantee
    446   *  the creation of a character. If a key event causing visible
    447   *  output is cancelable it may be prevented from causing
    448   *  output. This attribute is intended primarily to differentiate
    449   *  between keys events which may or may not produce visible output
    450   *  depending on the system state.
    451   */
    452  bool             inputGenerated() const;
    453 
    454  /** keyVal of type unsigned long
    455   *
    456   *  The value of keyVal holds the value of the Unicode character
    457   *  associated with the depressed key. If the key has no Unicode
    458   *  representation or no Unicode character is available the value is
    459   *  0.
    460   */
    461  unsigned long    keyVal() const;
    462 
    463  /** numPad of type boolean
    464   *
    465   *  The numPad attribute indicates whether or not the key event was
    466   *  generated on the number pad section of the keyboard. If the number
    467   *  pad was used to generate the key event the value is true,
    468   *  otherwise the value is false.
    469   */
    470     bool             numPad() const { return m_numPad; }
    471 
    472  /**
    473   *outputString of type DOMString
    474   *
    475   *  outputString holds the value of the output generated by the key
    476   *  event. This may be a single Unicode character or it may be a
    477   *  string. It may also be null in the case where no output was
    478   *  generated by the key event.
    479   */
    480  DOMString        outputString() const;
    481 
    482  /** virtKeyVal of type unsigned long
    483   *
    484   *  When the key associated with a key event is not representable via
    485   *  a Unicode character virtKeyVale holds the virtual key code
    486   *  associated with the depressed key. If the key has a Unicode
    487   *  representation or no virtual code is available the value is
    488   *  DOM_VK_UNDEFINED.
    489   */
    490     unsigned long virtKeyVal() const { return m_virtKeyVal; }
    491 
     243// Introduced in DOM Level 3
     244class KeyboardEventImpl : public UIEventImpl {
     245public:
     246    KeyboardEventImpl();
     247    KeyboardEventImpl(QKeyEvent *key, AbstractViewImpl *view);
     248    KeyboardEventImpl(EventId _id,
     249                bool canBubbleArg,
     250                bool cancelableArg,
     251                AbstractViewImpl *viewArg,
     252                const DOMString &keyIdentifierArg,
     253                unsigned long keyLocationArg,
     254                bool ctrlKeyArg,
     255                bool shiftKeyArg,
     256                bool altKeyArg,
     257                bool metaKeyArg,
     258                bool altGraphKeyArg);
     259    virtual ~KeyboardEventImpl();
     260   
     261    void initKeyboardEvent(const DOMString &typeArg,
     262                bool canBubbleArg,
     263                bool cancelableArg,
     264                const AbstractView &viewArg,
     265                const DOMString &keyIdentifierArg,
     266                unsigned long keyLocationArg,
     267                bool ctrlKeyArg,
     268                bool shiftKeyArg,
     269                bool altKeyArg,
     270                bool metaKeyArg,
     271                bool altGraphKeyArg);
     272   
     273    DOMString keyIdentifier() const { return m_keyIdentifier; }
     274    unsigned long keyLocation() const { return m_keyLocation; }
     275   
     276    bool ctrlKey() const { return m_ctrlKey; }
     277    bool shiftKey() const { return m_shiftKey; }
     278    bool altKey() const { return m_altKey; }
     279    bool metaKey() const { return m_metaKey; }
     280    bool altGraphKey() const { return m_altGraphKey; }
     281   
     282    QKeyEvent *qKeyEvent() const { return m_keyEvent; }
     283   
    492284    virtual bool isKeyboardEvent() { return true; }
    493285
    494  QKeyEvent *qKeyEvent;
    495 
    496286private:
    497   unsigned long m_keyVal;
    498   unsigned long m_virtKeyVal;
    499   bool m_inputGenerated;
    500   DOMString m_outputString;
    501   bool m_numPad;
    502   // bitfield containing state of modifiers. not part of the dom.
    503   unsigned long    m_modifier;
     287    QKeyEvent *m_keyEvent;
     288    DOMStringImpl *m_keyIdentifier;
     289    unsigned long m_keyLocation;
     290    bool m_ctrlKey : 1;
     291    bool m_shiftKey : 1;
     292    bool m_altKey : 1;
     293    bool m_metaKey : 1;
     294    bool m_altGraphKey : 1;
    504295};
    505296
  • trunk/WebCore/khtml/xml/dom_docimpl.cpp

    r5128 r5226  
    21562156    else if (eventType == "MutationEvents")
    21572157        return new MutationEventImpl();
     2158    else if (eventType == "KeyboardEvents")
     2159        return new KeyboardEventImpl();
    21582160    else if (eventType == "HTMLEvents")
    21592161        return new EventImpl();
  • trunk/WebCore/khtml/xml/dom_nodeimpl.cpp

    r5107 r5226  
    738738    int exceptioncode = 0;
    739739    //kdDebug(6010) << "DOM::NodeImpl: dispatching keyboard event" << endl;
    740     KeyEventImpl *keyEventImpl = new KeyEventImpl(key, getDocument()->defaultView());
    741     keyEventImpl->ref();
    742     bool r = dispatchEvent(keyEventImpl,exceptioncode,true);
     740    KeyboardEventImpl *keyboardEventImpl = new KeyboardEventImpl(key, getDocument()->defaultView());
     741    keyboardEventImpl->ref();
     742    bool r = dispatchEvent(keyboardEventImpl,exceptioncode,true);
    743743
    744744#if APPLE_CHANGES
     
    746746    // or if the element is default-handled by the DOM. Otherwise we let it just
    747747    // let it get handled by AppKit
    748     if (keyEventImpl->defaultHandled())
     748    if (keyboardEventImpl->defaultHandled())
    749749#else
    750750    // the default event handler should accept() the internal QKeyEvent
    751751    // to prevent the view from further evaluating it.
    752     if (!keyEventImpl->defaultPrevented() && !keyEventImpl->qKeyEvent->isAccepted())
     752    if (!keyboardEventImpl->defaultPrevented() && !keyboardEventImpl->qKeyEvent->isAccepted())
    753753#endif
    754754      r = false;
    755755
    756     keyEventImpl->deref();
     756    keyboardEventImpl->deref();
    757757    return r;
    758758}
  • trunk/WebCore/kwq/KWQEvent.h

    r4266 r5226  
    111111    QString text() const;
    112112    int ascii() const;
     113    QString identifier() const;
    113114 private:
    114115    int _key;
     
    116117    ButtonState _state;
    117118    QString _text;
     119    QString _identifier;
    118120    bool _autoRepeat;
    119121    int _count;
  • trunk/WebCore/kwq/KWQEvent.mm

    r3376 r5226  
    5959}
    6060
     61static char hexDigit(int i) {
     62    if (i < 0 || i > 16) {
     63        ERROR("illegal hex digit");
     64        return '0';
     65    }
     66    int h = i;
     67    if (h >= 10) {
     68        h = h - 10 + 'a';
     69    }
     70    else {
     71        h += '0';
     72    }
     73    return h;
     74}
     75
     76static QString identifierForKeyText(const QString &text)
     77{
     78    int count = text.length();
     79    if (count == 0 || count > 1) {
     80#ifdef APPLE_CHANGES
     81        LOG(Events, "received an unexpected number of characters in key event: %d", count);
     82#endif
     83        return "Unidentified";
     84    }
     85    ushort c = text[0].unicode();
     86    switch (c) {
     87        // Each identifier listed in the DOM spec is listed here.
     88        // Many are simply commented out since they do not appear on standard Macintosh keyboards.
     89        // "Accept"
     90        // "AllCandidates"
     91        // "Alt"
     92        // "Apps"
     93        // "BrowserBack"
     94        // "BrowserForward"
     95        // "BrowserHome"
     96        // "BrowserRefresh"
     97        // "BrowserSearch"
     98        // "BrowserStop"
     99        // "CapsLock"
     100        // "Clear"
     101        case NSClearLineFunctionKey:
     102            return "Clear";
     103            break;
     104        // "CodeInput"
     105        // "Compose"
     106        // "Control"
     107        // "Crsel"
     108        // "Convert"
     109        // "Copy"
     110        // "Cut"
     111        // "Down"
     112        case NSDownArrowFunctionKey:
     113            return "Down";
     114            break;
     115        // "End"
     116        case NSEndFunctionKey:
     117            return "End";
     118            break;
     119        // "Enter"
     120        case 0x3:
     121            return "Enter";
     122            break;
     123        // "EraseEof"
     124        // "Execute"
     125        case NSExecuteFunctionKey:
     126            return "Execute";
     127            break;
     128        // "Exsel"
     129        // "F1"
     130        case NSF1FunctionKey:
     131            return "F1";
     132            break;
     133        // "F2"
     134        case NSF2FunctionKey:
     135            return "F2";
     136            break;
     137        // "F3"
     138        case NSF3FunctionKey:
     139            return "F3";
     140            break;
     141        // "F4"
     142        case NSF4FunctionKey:
     143            return "F4";
     144            break;
     145        // "F5"
     146        case NSF5FunctionKey:
     147            return "F5";
     148            break;
     149        // "F6"
     150        case NSF6FunctionKey:
     151            return "F6";
     152            break;
     153        // "F7"
     154        case NSF7FunctionKey:
     155            return "F7";
     156            break;
     157        // "F8"
     158        case NSF8FunctionKey:
     159            return "F8";
     160            break;
     161        // "F9"
     162        case NSF9FunctionKey:
     163            return "F9";
     164            break;
     165        // "F10"
     166        case NSF10FunctionKey:
     167            return "F10";
     168            break;
     169        // "F11"
     170        case NSF11FunctionKey:
     171            return "F11";
     172            break;
     173        // "F12"
     174        case NSF12FunctionKey:
     175            return "F12";
     176            break;
     177        // "F13"
     178        case NSF13FunctionKey:
     179            return "F13";
     180            break;
     181        // "F14"
     182        case NSF14FunctionKey:
     183            return "F14";
     184            break;
     185        // "F15"
     186        case NSF15FunctionKey:
     187            return "F15";
     188            break;
     189        // "F16"
     190        case NSF16FunctionKey:
     191            return "F16";
     192            break;
     193        // "F17"
     194        case NSF17FunctionKey:
     195            return "F17";
     196            break;
     197        // "F18"
     198        case NSF18FunctionKey:
     199            return "F18";
     200            break;
     201        // "F19"
     202        case NSF19FunctionKey:
     203            return "F19";
     204            break;
     205        // "F20"
     206        case NSF20FunctionKey:
     207            return "F20";
     208            break;
     209        // "F21"
     210        case NSF21FunctionKey:
     211            return "F21";
     212            break;
     213        // "F22"
     214        case NSF22FunctionKey:
     215            return "F22";
     216            break;
     217        // "F23"
     218        case NSF23FunctionKey:
     219            return "F23";
     220            break;
     221        // "F24"
     222        case NSF24FunctionKey:
     223            return "F24";
     224            break;
     225        // "FinalMode"
     226        // "Find"
     227        case NSFindFunctionKey:
     228            return "Find";
     229            break;
     230        // "ForwardDelete" (Non-standard)
     231        case NSDeleteFunctionKey:
     232            return "ForwardDelete";
     233            break;
     234        // "FullWidth"
     235        // "HalfWidth"
     236        // "HangulMode"
     237        // "HanjaMode"
     238        // "Help"
     239        case NSHelpFunctionKey:
     240            return "Help";
     241            break;
     242        // "Hiragana"
     243        // "Home"
     244        case NSHomeFunctionKey:
     245            return "Home";
     246            break;
     247        // "Insert"
     248        case NSInsertFunctionKey:
     249            return "Left";
     250            break;
     251        // "JapaneseHiragana"
     252        // "JapaneseKatakana"
     253        // "JapaneseRomaji"
     254        // "JunjaMode"
     255        // "KanaMode"
     256        // "KanjiMode"
     257        // "Katakana"
     258        // "LaunchApplication1"
     259        // "LaunchApplication2"
     260        // "LaunchMail"
     261        // "Left"
     262        case NSLeftArrowFunctionKey:
     263            return "Left";
     264            break;
     265        // "Meta"
     266        // "MediaNextTrack"
     267        // "MediaPlayPause"
     268        // "MediaPreviousTrack"
     269        // "MediaStop"
     270        // "ModeChange"
     271        case NSModeSwitchFunctionKey:
     272            return "ModeChange";
     273            break;
     274        // "Nonconvert"
     275        // "NumLock"
     276        // "PageDown"
     277        case NSPageDownFunctionKey:
     278            return "PageDown";
     279            break;
     280        // "PageUp"
     281        case NSPageUpFunctionKey:
     282            return "PageUp";
     283            break;
     284        // "Paste"
     285        // "Pause"
     286        case NSPauseFunctionKey:
     287            return "Pause";
     288            break;
     289        // "Play"
     290        // "PreviousCandidate"
     291        // "PrintScreen"
     292        case NSPrintScreenFunctionKey:
     293            return "PrintScreen";
     294            break;
     295        // "Process"
     296        // "Props"
     297        // "Right"
     298        case NSRightArrowFunctionKey:
     299            return "Right";
     300            break;
     301        // "RomanCharacters"
     302        // "Scroll"
     303        // "Select"
     304        // "SelectMedia"
     305        // "Shift"
     306        // "Stop"
     307        case NSStopFunctionKey:
     308            return "Stop";
     309            break;
     310        // "Up"
     311        case NSUpArrowFunctionKey:
     312            return "Up";
     313            break;
     314        // "Undo"
     315        case NSUndoFunctionKey:
     316            return "Undo";
     317            break;
     318        // "VolumeDown"
     319        // "VolumeMute"
     320        // "VolumeUp"
     321        // "Win"
     322        // "Zoom"
     323        default:
     324            char escaped[5];
     325            escaped[0] = hexDigit((c >> 12) & 0xf);
     326            escaped[1] = hexDigit((c >> 8) & 0xf);
     327            escaped[2] = hexDigit((c >> 4) & 0xf);
     328            escaped[3] = hexDigit(c & 0xf);
     329            escaped[4] = '\0';
     330            NSString *nsstring = [[NSString alloc] initWithFormat:@"U+00%s", escaped];
     331            QString qstring = QString::fromNSString(nsstring);
     332            [nsstring release];
     333            return qstring;
     334    }
     335}
    61336
    62337QKeyEvent::QKeyEvent(Type t, int key, int ascii, int buttonState, const QString &text, bool autoRepeat, ushort count)
     
    70345      _isAccepted(false)
    71346{
     347    _identifier = identifierForKeyText(text);
    72348}
    73349
     
    116392    return _isAccepted;
    117393}
     394
     395QString QKeyEvent::identifier() const
     396{
     397    return _identifier;
     398}
  • trunk/WebCore/kwq/KWQKHTMLPart.mm

    r5145 r5226  
    16951695    if (modifiers & NSCommandKeyMask)
    16961696        state |= Qt::MetaButton;
     1697    if (modifiers & NSNumericPadKeyMask)
     1698        state |= Qt::Keypad;
    16971699   
    16981700    return state;
  • trunk/WebCore/kwq/KWQLogging.h

    r3376 r5226  
    3535extern KWQLogChannel KWQLogLoading;
    3636extern KWQLogChannel KWQLogPopupBlocking;
     37extern KWQLogChannel KWQLogEvents;
  • trunk/WebCore/kwq/KWQLogging.m

    r3376 r5226  
    3232
    3333KWQLogChannel KWQLogPopupBlocking =     { 0x00000040, "WebCoreLogLevel", KWQLogChannelUninitialized };
     34
     35KWQLogChannel KWQLogEvents =            { 0x00000080, "WebCoreLogLevel", KWQLogChannelUninitialized };
Note: See TracChangeset for help on using the changeset viewer.