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

Side by Side Diff: webkit/plugins/npapi/plugin_instance_mac.mm

Issue 19761007: Move NPAPI implementation out of webkit/plugins/npapi and into content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
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 #import <AppKit/AppKit.h>
6
7 #include "base/logging.h"
8 #include "build/build_config.h"
9 #include "webkit/plugins/npapi/plugin_instance.h"
10
11 // When C++ exceptions are disabled, the C++ library defines |try| and
12 // |catch| so as to allow exception-expecting C++ code to build properly when
13 // language support for exceptions is not present. These macros interfere
14 // with the use of |@try| and |@catch| in Objective-C files such as this one.
15 // Undefine these macros here, after everything has been #included, since
16 // there will be no C++ uses and only Objective-C uses from this point on.
17 #undef try
18 #undef catch
19
20 namespace webkit {
21 namespace npapi {
22
23 namespace {
24
25 // Returns an autoreleased NSEvent constructed from the given np_event,
26 // targeting the given window.
27 NSEvent* NSEventForNPCocoaEvent(NPCocoaEvent* np_event, NSWindow* window) {
28 bool mouse_down = 1;
29 switch (np_event->type) {
30 case NPCocoaEventMouseDown:
31 mouse_down = 1;
32 break;
33 case NPCocoaEventMouseUp:
34 mouse_down = 0;
35 break;
36 default:
37 // If plugins start bringing up context menus for things other than
38 // clicks, this will need more plumbing; for now just log it and proceed
39 // as if it were a mouse down.
40 NOTREACHED();
41 }
42 NSEventType event_type = NSLeftMouseDown;
43 switch (np_event->data.mouse.buttonNumber) {
44 case 0:
45 event_type = mouse_down ? NSLeftMouseDown : NSLeftMouseUp;
46 break;
47 case 1:
48 event_type = mouse_down ? NSRightMouseDown : NSRightMouseUp;
49 break;
50 default:
51 event_type = mouse_down ? NSOtherMouseDown : NSOtherMouseUp;
52 break;
53 }
54
55 NSInteger click_count = np_event->data.mouse.clickCount;
56 NSInteger modifiers = np_event->data.mouse.modifierFlags;
57 // NPCocoaEvent doesn't have a timestamp, so just use the current time.
58 NSEvent* event =
59 [NSEvent mouseEventWithType:event_type
60 location:NSZeroPoint
61 modifierFlags:modifiers
62 timestamp:[[NSApp currentEvent] timestamp]
63 windowNumber:[window windowNumber]
64 context:[NSGraphicsContext currentContext]
65 eventNumber:0
66 clickCount:click_count
67 pressure:1.0];
68 return event;
69 }
70
71 } // namespace
72
73 NPError PluginInstance::PopUpContextMenu(NPMenu* menu) {
74 if (!currently_handled_event_)
75 return NPERR_GENERIC_ERROR;
76
77 CGRect main_display_bounds = CGDisplayBounds(CGMainDisplayID());
78 NSPoint screen_point = NSMakePoint(
79 plugin_origin_.x() + currently_handled_event_->data.mouse.pluginX,
80 plugin_origin_.y() + currently_handled_event_->data.mouse.pluginY);
81 // Plugin offsets are upper-left based, so flip vertically for Cocoa.
82 screen_point.y = main_display_bounds.size.height - screen_point.y;
83
84 NSMenu* nsmenu = reinterpret_cast<NSMenu*>(menu);
85 NPError return_val = NPERR_NO_ERROR;
86 @try {
87 [nsmenu popUpMenuPositioningItem:nil atLocation:screen_point inView:nil];
88 }
89 @catch (NSException* e) {
90 NSLog(@"Caught exception while handling PopUpContextMenu: %@", e);
91 return_val = NPERR_GENERIC_ERROR;
92 }
93
94 return return_val;
95 }
96
97 ScopedCurrentPluginEvent::ScopedCurrentPluginEvent(PluginInstance* instance,
98 NPCocoaEvent* event)
99 : instance_(instance) {
100 instance_->set_currently_handled_event(event);
101 }
102
103 ScopedCurrentPluginEvent::~ScopedCurrentPluginEvent() {
104 instance_->set_currently_handled_event(NULL);
105 }
106
107 } // namespace npapi
108 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698