2 * This file is part of the DOM implementation for KDE.
4 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
5 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
6 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
7 * Copyright (C) 2003, 2005, 2006 Apple Computer, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
25 #include "KeyboardEvent.h"
27 #include "EventNames.h"
28 #include "PlatformKeyboardEvent.h"
32 using namespace EventNames;
34 KeyboardEvent::KeyboardEvent()
36 , m_keyLocation(DOM_KEY_LOCATION_STANDARD)
37 , m_altGraphKey(false)
41 KeyboardEvent::KeyboardEvent(const PlatformKeyboardEvent& key, AbstractView* view)
42 : UIEventWithKeyState(key.isKeyUp() ? keyupEvent : key.isAutoRepeat() ? keypressEvent : keydownEvent,
43 true, true, view, 0, key.ctrlKey(), key.altKey(), key.shiftKey(), key.metaKey())
44 , m_keyEvent(new PlatformKeyboardEvent(key))
45 , m_keyIdentifier(key.keyIdentifier())
46 , m_keyLocation(key.isKeypad() ? DOM_KEY_LOCATION_NUMPAD : DOM_KEY_LOCATION_STANDARD)
47 , m_altGraphKey(false)
51 KeyboardEvent::KeyboardEvent(const AtomicString& eventType, bool canBubble, bool cancelable, AbstractView *view,
52 const String &keyIdentifier, unsigned keyLocation,
53 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey)
54 : UIEventWithKeyState(eventType, canBubble, cancelable, view, 0, ctrlKey, altKey, shiftKey, metaKey)
56 , m_keyIdentifier(keyIdentifier)
57 , m_keyLocation(keyLocation)
58 , m_altGraphKey(altGraphKey)
62 KeyboardEvent::~KeyboardEvent()
67 void KeyboardEvent::initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view,
68 const String &keyIdentifier, unsigned keyLocation,
69 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey)
74 initUIEvent(type, canBubble, cancelable, view, 0);
76 m_keyIdentifier = keyIdentifier;
77 m_keyLocation = keyLocation;
79 m_shiftKey = shiftKey;
82 m_altGraphKey = altGraphKey;
85 int KeyboardEvent::keyCode() const
89 if (type() == keydownEvent || type() == keyupEvent)
90 return m_keyEvent->WindowsKeyCode();
94 int KeyboardEvent::charCode() const
98 String text = m_keyEvent->text();
99 if (text.length() != 1)
104 bool KeyboardEvent::isKeyboardEvent() const
109 int KeyboardEvent::which() const
111 // Netscape's "which" returns a virtual key code for keydown and keyup, and a character code for keypress.
112 // That's exactly what IE's "keyCode" returns. So they are the same for keyboard events.
116 } // namespace WebCore