/opensource.apple.com/source/WebCore/WebCore-4523.12/dom/KeyboardEvent.cpp
C++ | 161 lines | 124 code | 18 blank | 19 comment | 8 complexity | 02c6f44bcbfe80141ebb3869edcb0f8c MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, MPL-2.0, LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, IPL-1.0, ISC, AGPL-1.0, AGPL-3.0, JSON, Apache-2.0, 0BSD
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>KeyboardEvent.cpp</title>
- <style type="text/css">
- .enscript-comment { font-style: italic; color: rgb(178,34,34); }
- .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
- .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
- .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
- .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
- .enscript-string { font-weight: bold; color: rgb(188,143,143); }
- .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
- .enscript-type { font-weight: bold; color: rgb(34,139,34); }
- .enscript-highlight { text-decoration: underline; color: 0; }
- </style>
- </head>
- <body id="top">
- <h1 style="margin:8px;" id="f1">KeyboardEvent.cpp <span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
- <hr/>
- <div></div>
- <pre>
- <span class="enscript-comment">/**
- * Copyright (C) 2001 Peter Kelly (<a href="mailto:pmk@post.com">pmk@post.com</a>)
- * Copyright (C) 2001 Tobias Anton (<a href="mailto:anton@stud.fbi.fh-darmstadt.de">anton@stud.fbi.fh-darmstadt.de</a>)
- * Copyright (C) 2006 Samuel Weinig (<a href="mailto:sam.weinig@gmail.com">sam.weinig@gmail.com</a>)
- * Copyright (C) 2003, 2005, 2006, 2007 Apple Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"config.h"</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"KeyboardEvent.h"</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"EventNames.h"</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"PlatformKeyboardEvent.h"</span>
- namespace WebCore {
- using namespace EventNames;
- <span class="enscript-function-name">KeyboardEvent::KeyboardEvent</span>()
- : m_keyEvent(0)
- , m_keyLocation(DOM_KEY_LOCATION_STANDARD)
- , m_altGraphKey(false)
- {
- }
- <span class="enscript-function-name">KeyboardEvent::KeyboardEvent</span>(<span class="enscript-type">const</span> PlatformKeyboardEvent& key, AbstractView* view)
- : UIEventWithKeyState(key.isKeyUp() ? keyupEvent : key.isAutoRepeat() ? keypressEvent : keydownEvent,
- true, true, view, 0, key.ctrlKey(), key.altKey(), key.shiftKey(), key.metaKey())
- , m_keyEvent(<span class="enscript-keyword">new</span> PlatformKeyboardEvent(key))
- , m_keyIdentifier(key.keyIdentifier())
- , m_keyLocation(key.isKeypad() ? DOM_KEY_LOCATION_NUMPAD : DOM_KEY_LOCATION_STANDARD)
- , m_altGraphKey(false)
- {
- }
- <span class="enscript-function-name">KeyboardEvent::KeyboardEvent</span>(<span class="enscript-type">const</span> AtomicString& eventType, <span class="enscript-type">bool</span> canBubble, <span class="enscript-type">bool</span> cancelable, AbstractView *view,
- <span class="enscript-type">const</span> String &keyIdentifier, <span class="enscript-type">unsigned</span> keyLocation,
- <span class="enscript-type">bool</span> ctrlKey, <span class="enscript-type">bool</span> altKey, <span class="enscript-type">bool</span> shiftKey, <span class="enscript-type">bool</span> metaKey, <span class="enscript-type">bool</span> altGraphKey)
- : UIEventWithKeyState(eventType, canBubble, cancelable, view, 0, ctrlKey, altKey, shiftKey, metaKey)
- , m_keyEvent(0)
- , m_keyIdentifier(keyIdentifier)
- , m_keyLocation(keyLocation)
- , m_altGraphKey(altGraphKey)
- {
- }
- <span class="enscript-function-name">KeyboardEvent::~KeyboardEvent</span>()
- {
- <span class="enscript-keyword">delete</span> m_keyEvent;
- }
- <span class="enscript-type">void</span> <span class="enscript-function-name">KeyboardEvent::initKeyboardEvent</span>(<span class="enscript-type">const</span> AtomicString& type, <span class="enscript-type">bool</span> canBubble, <span class="enscript-type">bool</span> cancelable, AbstractView* view,
- <span class="enscript-type">const</span> String &keyIdentifier, <span class="enscript-type">unsigned</span> keyLocation,
- <span class="enscript-type">bool</span> ctrlKey, <span class="enscript-type">bool</span> altKey, <span class="enscript-type">bool</span> shiftKey, <span class="enscript-type">bool</span> metaKey, <span class="enscript-type">bool</span> altGraphKey)
- {
- <span class="enscript-keyword">if</span> (dispatched())
- <span class="enscript-keyword">return</span>;
- initUIEvent(type, canBubble, cancelable, view, 0);
- m_keyIdentifier = keyIdentifier;
- m_keyLocation = keyLocation;
- m_ctrlKey = ctrlKey;
- m_shiftKey = shiftKey;
- m_altKey = altKey;
- m_metaKey = metaKey;
- m_altGraphKey = altGraphKey;
- }
- <span class="enscript-type">bool</span> <span class="enscript-function-name">KeyboardEvent::getModifierState</span>(<span class="enscript-type">const</span> String& keyIdentifier) <span class="enscript-type">const</span>
- {
- <span class="enscript-keyword">if</span> (keyIdentifier == <span class="enscript-string">"Control"</span>)
- <span class="enscript-keyword">return</span> ctrlKey();
- <span class="enscript-keyword">if</span> (keyIdentifier == <span class="enscript-string">"Shift"</span>)
- <span class="enscript-keyword">return</span> shiftKey();
- <span class="enscript-keyword">if</span> (keyIdentifier == <span class="enscript-string">"Alt"</span>)
- <span class="enscript-keyword">return</span> altKey();
- <span class="enscript-keyword">if</span> (keyIdentifier == <span class="enscript-string">"Meta"</span>)
- <span class="enscript-keyword">return</span> metaKey();
- <span class="enscript-keyword">return</span> false;
- }
- <span class="enscript-type">int</span> <span class="enscript-function-name">KeyboardEvent::keyCode</span>() <span class="enscript-type">const</span>
- {
- <span class="enscript-keyword">if</span> (!m_keyEvent)
- <span class="enscript-keyword">return</span> 0;
- <span class="enscript-keyword">if</span> (type() == keydownEvent || type() == keyupEvent)
- <span class="enscript-keyword">return</span> m_keyEvent->WindowsKeyCode();
- <span class="enscript-keyword">return</span> charCode();
- }
- <span class="enscript-type">int</span> <span class="enscript-function-name">KeyboardEvent::charCode</span>() <span class="enscript-type">const</span>
- {
- <span class="enscript-keyword">if</span> (!m_keyEvent)
- <span class="enscript-keyword">return</span> 0;
- String text = m_keyEvent->text();
- <span class="enscript-keyword">if</span> (text.length() != 1)
- <span class="enscript-keyword">return</span> 0;
- <span class="enscript-keyword">return</span> text[0];
- }
- <span class="enscript-type">bool</span> <span class="enscript-function-name">KeyboardEvent::isKeyboardEvent</span>() <span class="enscript-type">const</span>
- {
- <span class="enscript-keyword">return</span> true;
- }
- <span class="enscript-type">int</span> <span class="enscript-function-name">KeyboardEvent::which</span>() <span class="enscript-type">const</span>
- {
- <span class="enscript-comment">// Netscape's "which" returns a virtual key code for keydown and keyup, and a character code for keypress.
- </span> <span class="enscript-comment">// That's exactly what IE's "keyCode" returns. So they are the same for keyboard events.
- </span> <span class="enscript-keyword">return</span> keyCode();
- }
- KeyboardEvent* <span class="enscript-function-name">findKeyboardEvent</span>(Event* event)
- {
- <span class="enscript-keyword">for</span> (Event* e = event; e; e = e->underlyingEvent())
- <span class="enscript-keyword">if</span> (e->isKeyboardEvent())
- <span class="enscript-keyword">return</span> static_cast<KeyboardEvent*>(e);
- <span class="enscript-keyword">return</span> 0;
- }
- } <span class="enscript-comment">// namespace WebCore
- </span></pre>
- <hr />
- </body></html>