1 // Copyright (c) 2010 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 #ifndef CONTENT_CHILD_NPAPI_PLUGIN_WEB_EVENT_CONVERTER_MAC_H_ 6 #define CONTENT_CHILD_NPAPI_PLUGIN_WEB_EVENT_CONVERTER_MAC_H_ 7 8 #include "third_party/npapi/bindings/npapi.h" 9 10 namespace blink { 11 class WebInputEvent; 12 class WebKeyboardEvent; 13 class WebMouseEvent; 14 class WebMouseWheelEvent; 15 } 16 17 namespace content { 18 19 // Utility class to translating WebInputEvent structs to equivalent structures 20 // suitable for sending to Mac plugins (via NPP_HandleEvent). 21 class PluginWebEventConverter { 22 public: 23 PluginWebEventConverter(); 24 virtual ~PluginWebEventConverter(); 25 26 // Initializes a converter for the given web event. Returns false if the event 27 // could not be converted. 28 bool InitWithEvent(const blink::WebInputEvent& web_event); 29 30 // Returns a pointer to a plugin event--suitable for passing to 31 // NPP_HandleEvent--corresponding to the the web event this converter was 32 // created with. The pointer is valid only as long as this object is. 33 // Returns NULL iff InitWithEvent returned false. plugin_event()34 NPCocoaEvent* plugin_event() { return &cocoa_event_; } 35 36 private: 37 // Stores a converted plugin representation of the given web event, suitable 38 // for returning from plugin_event. 39 // Returns true if the event was successfully converted. 40 bool ConvertKeyboardEvent(const blink::WebKeyboardEvent& web_event); 41 bool ConvertMouseEvent(const blink::WebMouseEvent& web_event); 42 bool ConvertMouseWheelEvent(const blink::WebMouseWheelEvent& web_event); 43 44 // Returns the Cocoa translation of web_event's modifiers. 45 static NSUInteger CocoaModifiers(const blink::WebInputEvent& web_event); 46 47 NPCocoaEvent cocoa_event_; 48 49 DISALLOW_COPY_AND_ASSIGN(PluginWebEventConverter); 50 }; 51 52 } // namespace content 53 54 #endif // CONTENT_CHILD_NPAPI_PLUGIN_WEB_EVENT_CONVERTER_MAC_H_ 55