1/*
2 * Copyright (C) 2006 Apple Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#include "config.h"
22#include "UIEventWithKeyState.h"
23
24namespace WebCore {
25
26auto UIEventWithKeyState::modifiersFromInitializer(const EventModifierInit& initializer) -> OptionSet<Modifier>
27{
28 OptionSet<Modifier> result;
29 if (initializer.ctrlKey)
30 result.add(Modifier::ControlKey);
31 if (initializer.altKey)
32 result.add(Modifier::AltKey);
33 if (initializer.shiftKey)
34 result.add(Modifier::ShiftKey);
35 if (initializer.metaKey)
36 result.add(Modifier::MetaKey);
37 if (initializer.modifierAltGraph)
38 result.add(Modifier::AltGraphKey);
39 if (initializer.modifierCapsLock)
40 result.add(Modifier::CapsLockKey);
41 return result;
42}
43
44bool UIEventWithKeyState::getModifierState(const String& keyIdentifier) const
45{
46 if (keyIdentifier == "Control")
47 return ctrlKey();
48 if (keyIdentifier == "Shift")
49 return shiftKey();
50 if (keyIdentifier == "Alt")
51 return altKey();
52 if (keyIdentifier == "Meta")
53 return metaKey();
54 if (keyIdentifier == "AltGraph")
55 return altGraphKey();
56 if (keyIdentifier == "CapsLock")
57 return capsLockKey();
58 // FIXME: The specification also has Fn, FnLock, Hyper, NumLock, Super, ScrollLock, Symbol, SymbolLock.
59 return false;
60}
61
62void UIEventWithKeyState::setModifierKeys(bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey)
63{
64 OptionSet<Modifier> result;
65 if (ctrlKey)
66 result.add(Modifier::ControlKey);
67 if (altKey)
68 result.add(Modifier::AltKey);
69 if (shiftKey)
70 result.add(Modifier::ShiftKey);
71 if (metaKey)
72 result.add(Modifier::MetaKey);
73 if (altGraphKey)
74 result.add(Modifier::AltGraphKey);
75 m_modifiers = result;
76}
77
78UIEventWithKeyState* findEventWithKeyState(Event* event)
79{
80 for (Event* e = event; e; e = e->underlyingEvent())
81 if (e->isKeyboardEvent() || e->isMouseEvent())
82 return static_cast<UIEventWithKeyState*>(e);
83 return 0;
84}
85
86} // namespace WebCore
87