Commit 2c233b84 authored by aroben@apple.com's avatar aroben@apple.com

Add support for painting windowless plugins on Windows

This gets the video on the front page of vimeo.com painting (though
you can't make it play because we don't support mouse events yet).

Fixes <http://webkit.org/b/44274> <rdar://problem/8330398> Windowless
plugins don't paint in WebKit2 on Windows

Reviewed by Sam Weinig.

* WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
(WebKit::NPN_GetValue): Tell the plugin that we support windowless
mode on Windows.
(WebKit::NPN_SetValue): Implemented handling of NPPVpluginWindowBool
by calling through to NetscapePlugin::setIsWindowed.

* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
(WebKit::NetscapePlugin::NetscapePlugin): Added initialization of
m_isWindowed. It defaults to false on Mac and true on other platforms,
matching WebCore's PluginView.

* WebProcess/Plugins/Netscape/NetscapePlugin.h: Added m_isWindowed.
(WebKit::NetscapePlugin::setIsWindowed): Added standard setter.

* WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm:
(WebKit::NetscapePlugin::platformPaint): Moved Mac-specific context
translation code here from PluginView::paint.

* WebProcess/Plugins/Netscape/win/NetscapePluginWin.cpp:
(WebKit::NetscapePlugin::platformPaint): Implemented. Code was ported
from WebCore's PluginViewWin.cpp.

* WebProcess/Plugins/Plugin.h: Updated the comment for Plugin::paint
to explain the coordinate system of the context.

* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::paint): Changed to translate the context from
document to window coordinates. We were previously trying to translate
to plugin-local coordinates, but this only worked for documents whose
origin was the same as the window's origin (i.e., the main frame). The
plugin takes care of any further translations needed. (Mac translates
the context into plugin-local coordinates, and Windows leaves it in
window coordinates.)

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65705 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 542573ee
2010-08-19 Adam Roben <aroben@apple.com>
Add support for painting windowless plugins on Windows
This gets the video on the front page of vimeo.com painting (though
you can't make it play because we don't support mouse events yet).
Fixes <http://webkit.org/b/44274> <rdar://problem/8330395> Windowless
plugins don't paint in WebKit2 on Windows
Reviewed by Sam Weinig.
* WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
(WebKit::NPN_GetValue): Tell the plugin that we support windowless
mode on Windows.
(WebKit::NPN_SetValue): Implemented handling of NPPVpluginWindowBool
by calling through to NetscapePlugin::setIsWindowed.
* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
(WebKit::NetscapePlugin::NetscapePlugin): Added initialization of
m_isWindowed. It defaults to false on Mac and true on other platforms,
matching WebCore's PluginView.
* WebProcess/Plugins/Netscape/NetscapePlugin.h: Added m_isWindowed.
(WebKit::NetscapePlugin::setIsWindowed): Added standard setter.
* WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm:
(WebKit::NetscapePlugin::platformPaint): Moved Mac-specific context
translation code here from PluginView::paint.
* WebProcess/Plugins/Netscape/win/NetscapePluginWin.cpp:
(WebKit::NetscapePlugin::platformPaint): Implemented. Code was ported
from WebCore's PluginViewWin.cpp.
* WebProcess/Plugins/Plugin.h: Updated the comment for Plugin::paint
to explain the coordinate system of the context.
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::paint): Changed to translate the context from
document to window coordinates. We were previously trying to translate
to plugin-local coordinates, but this only worked for documents whose
origin was the same as the window's origin (i.e., the main frame). The
plugin takes care of any further translations needed. (Mac translates
the context into plugin-local coordinates, and Windows leaves it in
window coordinates.)
2010-08-19 Adam Roben <aroben@apple.com>
Implement PluginInfoStore::pluginsDirectories
......
......@@ -440,6 +440,10 @@ static NPError NPN_GetValue(NPP npp, NPNVariable variable, void *value)
*(NPBool*)value = false;
break;
#endif
#elif PLATFORM(WIN)
case NPNVSupportsWindowless:
*(NPBool*)value = true;
break;
#endif
default:
notImplemented();
......@@ -468,7 +472,12 @@ static NPError NPN_SetValue(NPP npp, NPPVariable variable, void *value)
}
#endif
case NPPVpluginWindowBool:
case NPPVpluginWindowBool: {
RefPtr<NetscapePlugin> plugin = NetscapePlugin::fromNPP(npp);
plugin->setIsWindowed(value);
return NPERR_NO_ERROR;
}
case NPPVpluginTransparentBool:
default:
notImplemented();
......
......@@ -46,6 +46,11 @@ NetscapePlugin::NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule)
, m_pluginModule(pluginModule)
, m_npWindow()
, m_isStarted(false)
#if PLATFORM(MAC)
, m_isWindowed(false)
#else
, m_isWindowed(true)
#endif
, m_inNPPNew(false)
, m_loadManually(false)
#if PLATFORM(MAC)
......
......@@ -62,6 +62,7 @@ public:
void loadURL(const WTF::String& method, const WTF::String& urlString, const WTF::String& target, const WebCore::HTTPHeaderMap& headerFields,
const Vector<char>& httpBody, bool sendNotification, void* notificationData);
NPError destroyStream(NPStream*, NPReason);
void setIsWindowed(bool windowed) { m_isWindowed = windowed; }
void setStatusbarText(const WTF::String&);
static void setException(const WTF::String&);
bool evaluate(NPObject*, const WTF::String&scriptString, NPVariant* result);
......@@ -156,6 +157,7 @@ private:
CString m_userAgent;
bool m_isStarted;
bool m_isWindowed;
bool m_inNPPNew;
bool m_loadManually;
RefPtr<NetscapePluginStream> m_manualStream;
......
......@@ -137,6 +137,9 @@ static inline NPCocoaEvent initializeEvent(NPCocoaEventType type)
void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirtyRect)
{
// Translate the context so that the origin is at the top left corner of the plug-in view.
context->translate(frameRect().x(), frameRect().y());
switch (m_eventModel) {
case NPEventModelCocoa: {
// Don't send draw events when we're using the Core Animation drawing model.
......
......@@ -26,6 +26,7 @@
#include "NetscapePlugin.h"
#include "NotImplemented.h"
#include <WebCore/GraphicsContext.h>
using namespace WebCore;
......@@ -37,9 +38,47 @@ bool NetscapePlugin::platformPostInitialize()
return true;
}
void NetscapePlugin::platformPaint(GraphicsContext*, const IntRect&)
void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirtyRect)
{
notImplemented();
// FIXME: Call SetWindow here if we haven't called it yet (see r59904).
if (m_isWindowed) {
// FIXME: Paint windowed plugins into context if context->shouldIncludeChildWindows() is true.
return;
}
// FIXME: Support transparent plugins.
HDC hdc = context->getWindowsContext(dirtyRect, false);
m_npWindow.type = NPWindowTypeDrawable;
m_npWindow.window = hdc;
WINDOWPOS windowpos = { 0, 0, 0, 0, 0, 0, 0 };
windowpos.x = m_frameRect.x();
windowpos.y = m_frameRect.y();
windowpos.cx = m_frameRect.width();
windowpos.cy = m_frameRect.height();
NPEvent npEvent;
npEvent.event = WM_WINDOWPOSCHANGED;
npEvent.wParam = 0;
npEvent.lParam = reinterpret_cast<uintptr_t>(&windowpos);
NPP_HandleEvent(&npEvent);
callSetWindow();
RECT dirtyWinRect = dirtyRect;
npEvent.event = WM_PAINT;
npEvent.wParam = reinterpret_cast<uintptr_t>(hdc);
npEvent.lParam = reinterpret_cast<uintptr_t>(&dirtyWinRect);
NPP_HandleEvent(&npEvent);
// FIXME: Support transparent plugins.
context->releaseWindowsContext(hdc, dirtyRect, false);
}
bool NetscapePlugin::platformHandleMouseEvent(const WebMouseEvent&)
......
......@@ -63,7 +63,8 @@ public:
// Destroys the plug-in.
virtual void destroy() = 0;
// Tells the plug-in to paint itself into the given graphics context. The passed in dirty rect is in window coordinates.
// Tells the plug-in to paint itself into the given graphics context. The passed-in context and
// dirty rect are in window coordinates. The context is saved/restored by the caller.
virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect) = 0;
#if PLATFORM(MAC)
......
......@@ -374,19 +374,20 @@ void PluginView::paint(GraphicsContext* context, const IntRect& dirtyRect)
{
if (context->paintingDisabled() || !m_plugin || !m_isInitialized)
return;
IntRect dirtyRectInWindowCoordinates = parent()->contentsToWindow(dirtyRect);
IntRect paintRectInWindowCoordinates = intersection(dirtyRectInWindowCoordinates, clipRectInWindowCoordinates());
if (paintRectInWindowCoordinates.isEmpty())
return;
// context is in document coordinates. Translate it to window coordinates.
IntPoint documentOriginInWindowCoordinates = parent()->contentsToWindow(IntPoint());
context->save();
// Translate the context so that the origin is at the top left corner of the plug-in view.
context->translate(frameRect().x(), frameRect().y());
context->translate(-documentOriginInWindowCoordinates.x(), -documentOriginInWindowCoordinates.y());
m_plugin->paint(context, paintRectInWindowCoordinates);
context->restore();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment