PageRenderTime 73ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>KeyboardEvent.cpp</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">KeyboardEvent.cpp&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. <span class="enscript-comment">/**
  24. * Copyright (C) 2001 Peter Kelly (<a href="mailto:pmk@post.com">pmk@post.com</a>)
  25. * Copyright (C) 2001 Tobias Anton (<a href="mailto:anton@stud.fbi.fh-darmstadt.de">anton@stud.fbi.fh-darmstadt.de</a>)
  26. * Copyright (C) 2006 Samuel Weinig (<a href="mailto:sam.weinig@gmail.com">sam.weinig@gmail.com</a>)
  27. * Copyright (C) 2003, 2005, 2006, 2007 Apple Inc. All rights reserved.
  28. *
  29. * This library is free software; you can redistribute it and/or
  30. * modify it under the terms of the GNU Library General Public
  31. * License as published by the Free Software Foundation; either
  32. * version 2 of the License, or (at your option) any later version.
  33. *
  34. * This library is distributed in the hope that it will be useful,
  35. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  37. * Library General Public License for more details.
  38. *
  39. * You should have received a copy of the GNU Library General Public License
  40. * along with this library; see the file COPYING.LIB. If not, write to
  41. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  42. * Boston, MA 02110-1301, USA.
  43. */</span>
  44. #<span class="enscript-reference">include</span> <span class="enscript-string">&quot;config.h&quot;</span>
  45. #<span class="enscript-reference">include</span> <span class="enscript-string">&quot;KeyboardEvent.h&quot;</span>
  46. #<span class="enscript-reference">include</span> <span class="enscript-string">&quot;EventNames.h&quot;</span>
  47. #<span class="enscript-reference">include</span> <span class="enscript-string">&quot;PlatformKeyboardEvent.h&quot;</span>
  48. namespace WebCore {
  49. using namespace EventNames;
  50. <span class="enscript-function-name">KeyboardEvent::KeyboardEvent</span>()
  51. : m_keyEvent(0)
  52. , m_keyLocation(DOM_KEY_LOCATION_STANDARD)
  53. , m_altGraphKey(false)
  54. {
  55. }
  56. <span class="enscript-function-name">KeyboardEvent::KeyboardEvent</span>(<span class="enscript-type">const</span> PlatformKeyboardEvent&amp; key, AbstractView* view)
  57. : UIEventWithKeyState(key.isKeyUp() ? keyupEvent : key.isAutoRepeat() ? keypressEvent : keydownEvent,
  58. true, true, view, 0, key.ctrlKey(), key.altKey(), key.shiftKey(), key.metaKey())
  59. , m_keyEvent(<span class="enscript-keyword">new</span> PlatformKeyboardEvent(key))
  60. , m_keyIdentifier(key.keyIdentifier())
  61. , m_keyLocation(key.isKeypad() ? DOM_KEY_LOCATION_NUMPAD : DOM_KEY_LOCATION_STANDARD)
  62. , m_altGraphKey(false)
  63. {
  64. }
  65. <span class="enscript-function-name">KeyboardEvent::KeyboardEvent</span>(<span class="enscript-type">const</span> AtomicString&amp; eventType, <span class="enscript-type">bool</span> canBubble, <span class="enscript-type">bool</span> cancelable, AbstractView *view,
  66. <span class="enscript-type">const</span> String &amp;keyIdentifier, <span class="enscript-type">unsigned</span> keyLocation,
  67. <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)
  68. : UIEventWithKeyState(eventType, canBubble, cancelable, view, 0, ctrlKey, altKey, shiftKey, metaKey)
  69. , m_keyEvent(0)
  70. , m_keyIdentifier(keyIdentifier)
  71. , m_keyLocation(keyLocation)
  72. , m_altGraphKey(altGraphKey)
  73. {
  74. }
  75. <span class="enscript-function-name">KeyboardEvent::~KeyboardEvent</span>()
  76. {
  77. <span class="enscript-keyword">delete</span> m_keyEvent;
  78. }
  79. <span class="enscript-type">void</span> <span class="enscript-function-name">KeyboardEvent::initKeyboardEvent</span>(<span class="enscript-type">const</span> AtomicString&amp; type, <span class="enscript-type">bool</span> canBubble, <span class="enscript-type">bool</span> cancelable, AbstractView* view,
  80. <span class="enscript-type">const</span> String &amp;keyIdentifier, <span class="enscript-type">unsigned</span> keyLocation,
  81. <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)
  82. {
  83. <span class="enscript-keyword">if</span> (dispatched())
  84. <span class="enscript-keyword">return</span>;
  85. initUIEvent(type, canBubble, cancelable, view, 0);
  86. m_keyIdentifier = keyIdentifier;
  87. m_keyLocation = keyLocation;
  88. m_ctrlKey = ctrlKey;
  89. m_shiftKey = shiftKey;
  90. m_altKey = altKey;
  91. m_metaKey = metaKey;
  92. m_altGraphKey = altGraphKey;
  93. }
  94. <span class="enscript-type">bool</span> <span class="enscript-function-name">KeyboardEvent::getModifierState</span>(<span class="enscript-type">const</span> String&amp; keyIdentifier) <span class="enscript-type">const</span>
  95. {
  96. <span class="enscript-keyword">if</span> (keyIdentifier == <span class="enscript-string">&quot;Control&quot;</span>)
  97. <span class="enscript-keyword">return</span> ctrlKey();
  98. <span class="enscript-keyword">if</span> (keyIdentifier == <span class="enscript-string">&quot;Shift&quot;</span>)
  99. <span class="enscript-keyword">return</span> shiftKey();
  100. <span class="enscript-keyword">if</span> (keyIdentifier == <span class="enscript-string">&quot;Alt&quot;</span>)
  101. <span class="enscript-keyword">return</span> altKey();
  102. <span class="enscript-keyword">if</span> (keyIdentifier == <span class="enscript-string">&quot;Meta&quot;</span>)
  103. <span class="enscript-keyword">return</span> metaKey();
  104. <span class="enscript-keyword">return</span> false;
  105. }
  106. <span class="enscript-type">int</span> <span class="enscript-function-name">KeyboardEvent::keyCode</span>() <span class="enscript-type">const</span>
  107. {
  108. <span class="enscript-keyword">if</span> (!m_keyEvent)
  109. <span class="enscript-keyword">return</span> 0;
  110. <span class="enscript-keyword">if</span> (type() == keydownEvent || type() == keyupEvent)
  111. <span class="enscript-keyword">return</span> m_keyEvent-&gt;WindowsKeyCode();
  112. <span class="enscript-keyword">return</span> charCode();
  113. }
  114. <span class="enscript-type">int</span> <span class="enscript-function-name">KeyboardEvent::charCode</span>() <span class="enscript-type">const</span>
  115. {
  116. <span class="enscript-keyword">if</span> (!m_keyEvent)
  117. <span class="enscript-keyword">return</span> 0;
  118. String text = m_keyEvent-&gt;text();
  119. <span class="enscript-keyword">if</span> (text.length() != 1)
  120. <span class="enscript-keyword">return</span> 0;
  121. <span class="enscript-keyword">return</span> text[0];
  122. }
  123. <span class="enscript-type">bool</span> <span class="enscript-function-name">KeyboardEvent::isKeyboardEvent</span>() <span class="enscript-type">const</span>
  124. {
  125. <span class="enscript-keyword">return</span> true;
  126. }
  127. <span class="enscript-type">int</span> <span class="enscript-function-name">KeyboardEvent::which</span>() <span class="enscript-type">const</span>
  128. {
  129. <span class="enscript-comment">// Netscape's &quot;which&quot; returns a virtual key code for keydown and keyup, and a character code for keypress.
  130. </span> <span class="enscript-comment">// That's exactly what IE's &quot;keyCode&quot; returns. So they are the same for keyboard events.
  131. </span> <span class="enscript-keyword">return</span> keyCode();
  132. }
  133. KeyboardEvent* <span class="enscript-function-name">findKeyboardEvent</span>(Event* event)
  134. {
  135. <span class="enscript-keyword">for</span> (Event* e = event; e; e = e-&gt;underlyingEvent())
  136. <span class="enscript-keyword">if</span> (e-&gt;isKeyboardEvent())
  137. <span class="enscript-keyword">return</span> static_cast&lt;KeyboardEvent*&gt;(e);
  138. <span class="enscript-keyword">return</span> 0;
  139. }
  140. } <span class="enscript-comment">// namespace WebCore
  141. </span></pre>
  142. <hr />
  143. </body></html>