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

Side by Side Diff: content/child/npapi/plugin_web_event_converter_mac.mm

Issue 1851093005: Remove content/child/npapi (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_combined_01_02
Patch Set: rebase Created 4 years, 8 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
« no previous file with comments | « content/child/npapi/plugin_web_event_converter_mac.h ('k') | content/child/npapi/webplugin.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import <Cocoa/Cocoa.h>
6 #include <string.h>
7
8 #include "base/logging.h"
9 #include "content/child/npapi/plugin_web_event_converter_mac.h"
10 #include "third_party/WebKit/public/web/WebInputEvent.h"
11
12 using blink::WebInputEvent;
13 using blink::WebKeyboardEvent;
14 using blink::WebMouseEvent;
15 using blink::WebMouseWheelEvent;
16
17 namespace content {
18
19 namespace {
20
21 // Returns true if the given key is a modifier key.
22 bool KeyIsModifier(int native_key_code) {
23 switch (native_key_code) {
24 case 55: // Left command
25 case 54: // Right command
26 case 58: // Left option
27 case 61: // Right option
28 case 59: // Left control
29 case 62: // Right control
30 case 56: // Left shift
31 case 60: // Right shift
32 case 57: // Caps lock
33 return true;
34 default:
35 return false;
36 }
37 }
38
39 // Returns true if the caps lock flag should be set for the given event.
40 bool CapsLockIsActive(const WebInputEvent& event) {
41 // Only key events have accurate information for the caps lock flag; see
42 // <https://bugs.webkit.org/show_bug.cgi?id=46518>.
43 // For other types, use the live state.
44 if (WebInputEvent::isKeyboardEventType(event.type))
45 return (event.modifiers & WebInputEvent::CapsLockOn) != 0;
46 else
47 return ([[NSApp currentEvent] modifierFlags] & NSAlphaShiftKeyMask) != 0;
48 }
49
50 } // namespace
51
52 #pragma mark -
53
54 PluginWebEventConverter::PluginWebEventConverter() {
55 }
56
57 PluginWebEventConverter::~PluginWebEventConverter() {
58 }
59
60 bool PluginWebEventConverter::InitWithEvent(const WebInputEvent& web_event) {
61 memset(&cocoa_event_, 0, sizeof(cocoa_event_));
62 if (web_event.type == WebInputEvent::MouseWheel) {
63 return ConvertMouseWheelEvent(
64 *static_cast<const WebMouseWheelEvent*>(&web_event));
65 } else if (WebInputEvent::isMouseEventType(web_event.type)) {
66 return ConvertMouseEvent(*static_cast<const WebMouseEvent*>(&web_event));
67 } else if (WebInputEvent::isKeyboardEventType(web_event.type)) {
68 return ConvertKeyboardEvent(
69 *static_cast<const WebKeyboardEvent*>(&web_event));
70 }
71 DLOG(WARNING) << "Unknown event type " << web_event.type;
72 return false;
73 }
74
75 bool PluginWebEventConverter::ConvertKeyboardEvent(
76 const WebKeyboardEvent& key_event) {
77 cocoa_event_.data.key.keyCode = key_event.nativeKeyCode;
78
79 cocoa_event_.data.key.modifierFlags |= CocoaModifiers(key_event);
80
81 // Modifier keys have their own event type, and don't get character or
82 // repeat data.
83 if (KeyIsModifier(key_event.nativeKeyCode)) {
84 cocoa_event_.type = NPCocoaEventFlagsChanged;
85 return true;
86 }
87
88 cocoa_event_.data.key.characters = reinterpret_cast<NPNSString*>(
89 [NSString stringWithFormat:@"%S", key_event.text]);
90 cocoa_event_.data.key.charactersIgnoringModifiers =
91 reinterpret_cast<NPNSString*>(
92 [NSString stringWithFormat:@"%S", key_event.unmodifiedText]);
93
94 if (key_event.modifiers & WebInputEvent::IsAutoRepeat)
95 cocoa_event_.data.key.isARepeat = true;
96
97 switch (key_event.type) {
98 case WebInputEvent::KeyDown:
99 cocoa_event_.type = NPCocoaEventKeyDown;
100 return true;
101 case WebInputEvent::KeyUp:
102 cocoa_event_.type = NPCocoaEventKeyUp;
103 return true;
104 case WebInputEvent::RawKeyDown:
105 case WebInputEvent::Char:
106 // May be used eventually for IME, but currently not needed.
107 return false;
108 default:
109 NOTREACHED();
110 return false;
111 }
112 }
113
114 bool PluginWebEventConverter::ConvertMouseEvent(
115 const WebMouseEvent& mouse_event) {
116 cocoa_event_.data.mouse.pluginX = mouse_event.x;
117 cocoa_event_.data.mouse.pluginY = mouse_event.y;
118 cocoa_event_.data.mouse.modifierFlags |= CocoaModifiers(mouse_event);
119 cocoa_event_.data.mouse.clickCount = mouse_event.clickCount;
120 switch (mouse_event.button) {
121 case WebMouseEvent::ButtonLeft:
122 cocoa_event_.data.mouse.buttonNumber = 0;
123 break;
124 case WebMouseEvent::ButtonMiddle:
125 cocoa_event_.data.mouse.buttonNumber = 2;
126 break;
127 case WebMouseEvent::ButtonRight:
128 cocoa_event_.data.mouse.buttonNumber = 1;
129 break;
130 default:
131 cocoa_event_.data.mouse.buttonNumber = mouse_event.button;
132 break;
133 }
134 switch (mouse_event.type) {
135 case WebInputEvent::MouseDown:
136 cocoa_event_.type = NPCocoaEventMouseDown;
137 return true;
138 case WebInputEvent::MouseUp:
139 cocoa_event_.type = NPCocoaEventMouseUp;
140 return true;
141 case WebInputEvent::MouseMove: {
142 bool mouse_is_down =
143 (mouse_event.modifiers & WebInputEvent::LeftButtonDown) ||
144 (mouse_event.modifiers & WebInputEvent::RightButtonDown) ||
145 (mouse_event.modifiers & WebInputEvent::MiddleButtonDown);
146 cocoa_event_.type = mouse_is_down ? NPCocoaEventMouseDragged
147 : NPCocoaEventMouseMoved;
148 return true;
149 }
150 case WebInputEvent::MouseEnter:
151 cocoa_event_.type = NPCocoaEventMouseEntered;
152 return true;
153 case WebInputEvent::MouseLeave:
154 cocoa_event_.type = NPCocoaEventMouseExited;
155 return true;
156 default:
157 NOTREACHED();
158 return false;
159 }
160 }
161
162 bool PluginWebEventConverter::ConvertMouseWheelEvent(
163 const WebMouseWheelEvent& wheel_event) {
164 cocoa_event_.type = NPCocoaEventScrollWheel;
165 cocoa_event_.data.mouse.pluginX = wheel_event.x;
166 cocoa_event_.data.mouse.pluginY = wheel_event.y;
167 cocoa_event_.data.mouse.modifierFlags |= CocoaModifiers(wheel_event);
168 cocoa_event_.data.mouse.deltaX = wheel_event.deltaX;
169 cocoa_event_.data.mouse.deltaY = wheel_event.deltaY;
170 return true;
171 }
172
173 NSUInteger PluginWebEventConverter::CocoaModifiers(
174 const WebInputEvent& web_event) {
175 NSInteger modifiers = 0;
176 if (web_event.modifiers & WebInputEvent::ControlKey)
177 modifiers |= NSControlKeyMask;
178 if (web_event.modifiers & WebInputEvent::ShiftKey)
179 modifiers |= NSShiftKeyMask;
180 if (web_event.modifiers & WebInputEvent::AltKey)
181 modifiers |= NSAlternateKeyMask;
182 if (web_event.modifiers & WebInputEvent::MetaKey)
183 modifiers |= NSCommandKeyMask;
184 if (CapsLockIsActive(web_event))
185 modifiers |= NSAlphaShiftKeyMask;
186 return modifiers;
187 }
188
189 } // namespace content
OLDNEW
« no previous file with comments | « content/child/npapi/plugin_web_event_converter_mac.h ('k') | content/child/npapi/webplugin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698