summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 20:51:52 +0000
committerstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 20:51:52 +0000
commit9aff3e749be07838b251dcd675dbc39a4cadd6d2 (patch)
treea9480fa1f09e5c01997504a16249354b3e5adb6e
parentf4bff1e2cb4fc994a0f8453ae386222efa6f7b35 (diff)
downloadchromium_src-9aff3e749be07838b251dcd675dbc39a4cadd6d2.zip
chromium_src-9aff3e749be07838b251dcd675dbc39a4cadd6d2.tar.gz
chromium_src-9aff3e749be07838b251dcd675dbc39a4cadd6d2.tar.bz2
Partial implementation of NPN_ConvertPoint
Implements the plugin <-> screen coordinate conversions on the Mac. Window coordinate conversion is more difficult, and I'm not aware of any current need for it, so it remains unimplemented for now. BUG=29457 TEST=none Review URL: http://codereview.chromium.org/496001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35726 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/glue/plugins/plugin_host.cc15
-rw-r--r--webkit/glue/plugins/plugin_instance.cc70
-rw-r--r--webkit/glue/plugins/plugin_instance.h10
-rw-r--r--webkit/glue/plugins/webplugin_delegate_impl_mac.mm3
4 files changed, 91 insertions, 7 deletions
diff --git a/webkit/glue/plugins/plugin_host.cc b/webkit/glue/plugins/plugin_host.cc
index 3274937..a0bee9b 100644
--- a/webkit/glue/plugins/plugin_host.cc
+++ b/webkit/glue/plugins/plugin_host.cc
@@ -1038,20 +1038,21 @@ void NPN_UnscheduleTimer(NPP id, uint32 timer_id) {
plugin->UnscheduleTimer(timer_id);
}
-NPError NPN_PopUpContextMenu(NPP instance, NPMenu* menu) {
+NPError NPN_PopUpContextMenu(NPP id, NPMenu* menu) {
NOTIMPLEMENTED();
return NPERR_GENERIC_ERROR;
}
-NPBool NPN_ConvertPoint(NPP instance, double sourceX, double sourceY,
+NPBool NPN_ConvertPoint(NPP id, double sourceX, double sourceY,
NPCoordinateSpace sourceSpace,
double *destX, double *destY,
NPCoordinateSpace destSpace) {
- NOTIMPLEMENTED();
- if (destX)
- *destX = sourceX;
- if (destY)
- *destY = sourceY;
+ scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
+ if (plugin.get()) {
+ return plugin->ConvertPoint(sourceX, sourceY, sourceSpace,
+ destX, destY, destSpace);
+ }
+ NOTREACHED();
return FALSE;
}
diff --git a/webkit/glue/plugins/plugin_instance.cc b/webkit/glue/plugins/plugin_instance.cc
index b2919eb..4b9b966 100644
--- a/webkit/glue/plugins/plugin_instance.cc
+++ b/webkit/glue/plugins/plugin_instance.cc
@@ -19,6 +19,10 @@
#include "webkit/glue/plugins/plugin_string_stream.h"
#include "net/base/escape.h"
+#if defined(OS_MACOSX)
+#include <ApplicationServices/ApplicationServices.h>
+#endif
+
namespace NPAPI {
PluginInstance::PluginInstance(PluginLib *plugin, const std::string &mime_type)
@@ -489,4 +493,70 @@ void PluginInstance::RequestRead(NPStream* stream, NPByteRange* range_list) {
}
}
+bool PluginInstance::ConvertPoint(double source_x, double source_y,
+ NPCoordinateSpace source_space,
+ double* dest_x, double* dest_y,
+ NPCoordinateSpace dest_space) {
+#if defined(OS_MACOSX)
+ CGRect main_display_bounds = CGDisplayBounds(CGMainDisplayID());
+
+ double flipped_screen_x = source_x;
+ double flipped_screen_y = source_y;
+ switch(source_space) {
+ case NPCoordinateSpacePlugin:
+ flipped_screen_x += plugin_origin_.x();
+ flipped_screen_y += plugin_origin_.y();
+ break;
+ case NPCoordinateSpaceScreen:
+ flipped_screen_y = main_display_bounds.size.height - flipped_screen_y;
+ case NPCoordinateSpaceFlippedScreen:
+ break;
+ case NPCoordinateSpaceWindow:
+ case NPCoordinateSpaceFlippedWindow:
+ // Since a CG+Cocoa plugin has no way of getting a window reference, we
+ // may be able to get away without implementing this for now. If we do
+ // need to implement it later (e.g., for CALayer-based plugins) we'll need
+ // to get window bounds over IPC.
+ NOTIMPLEMENTED();
+ return false;
+ default:
+ NOTREACHED();
+ return false;
+ }
+
+ double target_x = flipped_screen_x;
+ double target_y = flipped_screen_y;
+ switch(dest_space) {
+ case NPCoordinateSpacePlugin:
+ target_x -= plugin_origin_.x();
+ target_y -= plugin_origin_.y();
+ break;
+ case NPCoordinateSpaceScreen:
+ target_y = main_display_bounds.size.height - flipped_screen_y;
+ case NPCoordinateSpaceFlippedScreen:
+ break;
+ case NPCoordinateSpaceWindow:
+ case NPCoordinateSpaceFlippedWindow:
+ // Since a CG+Cocoa plugin has no way of getting a window reference, we
+ // may be able to get away without implementing this for now. If we do
+ // need to implement it later (e.g., for CALayer-based plugins) we'll need
+ // to get window bounds over IPC.
+ NOTIMPLEMENTED();
+ return false;
+ default:
+ NOTREACHED();
+ return false;
+ }
+
+ if (dest_x)
+ *dest_x = target_x;
+ if (dest_y)
+ *dest_y = target_y;
+ return true;
+#else
+ NOTIMPLEMENTED();
+ return false;
+#endif
+}
+
} // namespace NPAPI
diff --git a/webkit/glue/plugins/plugin_instance.h b/webkit/glue/plugins/plugin_instance.h
index ec94162..4d82bb7 100644
--- a/webkit/glue/plugins/plugin_instance.h
+++ b/webkit/glue/plugins/plugin_instance.h
@@ -17,6 +17,7 @@
#include "app/gfx/native_widget_types.h"
#include "base/basictypes.h"
#include "base/file_path.h"
+#include "base/gfx/point.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "webkit/glue/plugins/nphostapi.h"
@@ -107,6 +108,9 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> {
void set_drawing_model(int value) { drawing_model_ = value; }
int event_model() { return event_model_; }
void set_event_model(int value) { event_model_ = value; }
+ // Updates the instance's tracking of the location of the plugin location
+ // relative to the upper left of the screen.
+ void set_plugin_origin(gfx::Point origin) { plugin_origin_ = origin; }
#endif
// Creates a stream for sending an URL. If notify_needed
@@ -157,6 +161,11 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> {
void UnscheduleTimer(uint32 timer_id);
+ bool ConvertPoint(double source_x, double source_y,
+ NPCoordinateSpace source_space,
+ double* dest_x, double* dest_y,
+ NPCoordinateSpace dest_space);
+
//
// NPAPI methods for calling the Plugin Instance
//
@@ -247,6 +256,7 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> {
#if defined(OS_MACOSX)
int drawing_model_;
int event_model_;
+ gfx::Point plugin_origin_;
#endif
MessageLoop* message_loop_;
scoped_refptr<PluginStreamUrl> plugin_data_stream_;
diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm
index 56e2c47..1a6999c 100644
--- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm
+++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm
@@ -416,6 +416,9 @@ void WebPluginDelegateImpl::UpdateWindowLocation(const WebMouseEvent& event) {
last_window_x_offset_ = event.globalX - event.windowX;
last_window_y_offset_ = event.globalY - event.windowY;
+ instance_->set_plugin_origin(gfx::Point(event.globalX - event.x,
+ event.globalY - event.y));
+
UpdateDummyWindowBoundsWithOffset(event.windowX - event.x,
event.windowY - event.y, 0, 0);
}