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.
5 #import <AppKit/AppKit.h>
7 #include "base/logging.h"
8 #include "build/build_config.h"
9 #include "content/child/npapi/plugin_instance.h"
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.
22 NPError PluginInstance::PopUpContextMenu(NPMenu* menu) {
23 if (!currently_handled_event_)
24 return NPERR_GENERIC_ERROR;
26 CGRect main_display_bounds = CGDisplayBounds(CGMainDisplayID());
27 NSPoint screen_point = NSMakePoint(
28 plugin_origin_.x() + currently_handled_event_->data.mouse.pluginX,
29 plugin_origin_.y() + currently_handled_event_->data.mouse.pluginY);
30 // Plugin offsets are upper-left based, so flip vertically for Cocoa.
31 screen_point.y = main_display_bounds.size.height - screen_point.y;
33 NSMenu* nsmenu = reinterpret_cast<NSMenu*>(menu);
34 NPError return_val = NPERR_NO_ERROR;
36 [nsmenu popUpMenuPositioningItem:nil atLocation:screen_point inView:nil];
38 @catch (NSException* e) {
39 NSLog(@"Caught exception while handling PopUpContextMenu: %@", e);
40 return_val = NPERR_GENERIC_ERROR;
46 ScopedCurrentPluginEvent::ScopedCurrentPluginEvent(PluginInstance* instance,
48 : instance_(instance) {
49 instance_->set_currently_handled_event(event);
52 ScopedCurrentPluginEvent::~ScopedCurrentPluginEvent() {
53 instance_->set_currently_handled_event(NULL);
56 } // namespace content