Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: third_party/WebKit/Source/platform/PlatformKeyboardEvent.cpp

Issue 2290313002: Remove PlatformKeyboardEvent (Closed)
Patch Set: One more fix Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #include "platform/PlatformKeyboardEvent.h"
28
29 #if OS(WIN)
30 #include <windows.h>
31 #elif OS(MACOSX)
32 #import <Carbon/Carbon.h>
33 #endif
34
35 namespace blink {
36
37 #if OS(WIN)
38 static const unsigned short HIGHBITMASKSHORT = 0x8000;
39 #endif
40
41 PlatformKeyboardEvent::OverrideCapsLockState PlatformKeyboardEvent::s_overrideCa psLockState =
42 PlatformKeyboardEvent::OverrideCapsLockState::Default;
43
44 void PlatformKeyboardEvent::disambiguateKeyDownEvent(EventType type)
45 {
46 #if OS(WIN)
47 // No KeyDown events on Windows to disambiguate.
48 ASSERT_NOT_REACHED();
49 #else
50 // Can only change type from KeyDown to RawKeyDown or Char, as we lack infor mation for other conversions.
51 ASSERT(m_type == PlatformEvent::KeyDown);
52 ASSERT(type == PlatformEvent::RawKeyDown || type == PlatformEvent::Char);
53 m_type = type;
54
55 if (type == RawKeyDown) {
56 m_text = String();
57 m_unmodifiedText = String();
58 } else {
59 m_windowsVirtualKeyCode = 0;
60 #if OS(MACOSX)
61 if (m_text.length() == 1 && (m_text[0U] >= 0xF700 && m_text[0U] <= 0xF7F F)) {
62 // According to NSEvents.h, OpenStep reserves the range 0xF700-0xF8F F for function keys. However, some actual private use characters
63 // happen to be in this range, e.g. the Apple logo (Option+Shift+K).
64 // 0xF7FF is an arbitrary cut-off.
65 m_text = String();
66 m_unmodifiedText = String();
67 }
68 #endif
69 }
70 #endif
71 }
72
73 PlatformEvent::Modifiers PlatformKeyboardEvent::accessKeyModifiers()
74 {
75 // TODO(crbug.com/618397): Add a settings to control this behavior.
76 #if OS(MACOSX)
77 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey);
78 #else
79 return PlatformEvent::AltKey;
80 #endif
81 }
82
83 bool PlatformKeyboardEvent::currentCapsLockState()
84 {
85 switch (s_overrideCapsLockState) {
86 case OverrideCapsLockState::Default:
87 #if OS(WIN)
88 // FIXME: Does this even work inside the sandbox?
89 return GetKeyState(VK_CAPITAL) & 1;
90 #elif OS(MACOSX)
91 return GetCurrentKeyModifiers() & alphaLock;
92 #else
93 NOTIMPLEMENTED();
94 return false;
95 #endif
96 case OverrideCapsLockState::On:
97 return true;
98 case OverrideCapsLockState::Off:
99 default:
100 return false;
101 }
102 }
103
104 PlatformEvent::Modifiers PlatformKeyboardEvent::getCurrentModifierState()
105 {
106 unsigned modifiers = 0;
107 #if OS(WIN)
108 if (GetKeyState(VK_SHIFT) & HIGHBITMASKSHORT)
109 modifiers |= ShiftKey;
110 if (GetKeyState(VK_CONTROL) & HIGHBITMASKSHORT)
111 modifiers |= CtrlKey;
112 if (GetKeyState(VK_MENU) & HIGHBITMASKSHORT)
113 modifiers |= AltKey;
114 #elif OS(MACOSX)
115 UInt32 currentModifiers = GetCurrentKeyModifiers();
116 if (currentModifiers & ::shiftKey)
117 modifiers |= ShiftKey;
118 if (currentModifiers & ::controlKey)
119 modifiers |= CtrlKey;
120 if (currentModifiers & ::optionKey)
121 modifiers |= AltKey;
122 if (currentModifiers & ::cmdKey)
123 modifiers |= MetaKey;
124 #else
125 // TODO(crbug.com/538289): Implement on other platforms.
126 return static_cast<Modifiers>(0);
127 #endif
128 return static_cast<Modifiers>(modifiers);
129 }
130
131 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698