Commit f6b969fd authored by andersca@apple.com's avatar andersca@apple.com

Verify drawing coordinates, add crude painting support

https://bugs.webkit.org/show_bug.cgi?id=41984

Reviewed by Sam Weinig.

* WebKit2.xcodeproj/project.pbxproj:
Add NetscapePluginMac.cpp.

* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
(WebKit::NetscapePlugin::NetscapePlugin):
Initialize drawing and event models.

(WebKit::NetscapePlugin::initialize):
Call platformPostInitialize.

(WebKit::NetscapePlugin::destroy):
Call NPP_Destroy.

(WebKit::NetscapePlugin::paint):
Call platformPaint.

* WebProcess/Plugins/Netscape/NetscapePlugin.h:
Add member functions.

* WebProcess/Plugins/Netscape/mac/NetscapePluginMac.cpp: Added.
(WebKit::NetscapePlugin::platformPostInitialize):
Set default event and drawing models and verify that they are compatible.

(WebKit::NetscapePlugin::platformPaint):
Send a paint event (assuming the Cocoa event model currently).

* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::paint):
Change the paint rect to be in window coordinates.

(WebKit::PluginView::viewGeometryDidChange):
(WebKit::PluginView::clipRectInWindowCoordinates):
* WebProcess/Plugins/PluginView.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@62993 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2f9a8b55
2010-07-09 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig.
Verify drawing coordinates, add crude painting support
https://bugs.webkit.org/show_bug.cgi?id=41984
* WebKit2.xcodeproj/project.pbxproj:
Add NetscapePluginMac.cpp.
* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
(WebKit::NetscapePlugin::NetscapePlugin):
Initialize drawing and event models.
(WebKit::NetscapePlugin::initialize):
Call platformPostInitialize.
(WebKit::NetscapePlugin::destroy):
Call NPP_Destroy.
(WebKit::NetscapePlugin::paint):
Call platformPaint.
* WebProcess/Plugins/Netscape/NetscapePlugin.h:
Add member functions.
* WebProcess/Plugins/Netscape/mac/NetscapePluginMac.cpp: Added.
(WebKit::NetscapePlugin::platformPostInitialize):
Set default event and drawing models and verify that they are compatible.
(WebKit::NetscapePlugin::platformPaint):
Send a paint event (assuming the Cocoa event model currently).
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::paint):
Change the paint rect to be in window coordinates.
(WebKit::PluginView::viewGeometryDidChange):
(WebKit::PluginView::clipRectInWindowCoordinates):
* WebProcess/Plugins/PluginView.h:
2010-07-09 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig.
......
......@@ -63,6 +63,7 @@
1AA1CD07100FA1BA0078DEBC /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AA1CD06100FA1BA0078DEBC /* Carbon.framework */; };
1AADE6FF10D855FC00D3D63D /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AADE6FE10D855FC00D3D63D /* ApplicationServices.framework */; };
1AE117F611DBB30900981615 /* ProcessLauncher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE117F511DBB30900981615 /* ProcessLauncher.cpp */; };
1AE5B7FB11E7AED200BA6767 /* NetscapePluginMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.cpp */; };
1AEFCC1211D01F96008219D3 /* PluginInfoStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */; };
1AEFCC1311D01F96008219D3 /* PluginInfoStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AEFCC1111D01F96008219D3 /* PluginInfoStore.cpp */; };
1AEFCCBD11D02C5E008219D3 /* PluginInfoStoreMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEFCCBC11D02C5E008219D3 /* PluginInfoStoreMac.mm */; };
......@@ -332,6 +333,7 @@
1AA1CD06100FA1BA0078DEBC /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = "<absolute>"; };
1AADE6FE10D855FC00D3D63D /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = System/Library/Frameworks/ApplicationServices.framework; sourceTree = SDKROOT; };
1AE117F511DBB30900981615 /* ProcessLauncher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProcessLauncher.cpp; sourceTree = "<group>"; };
1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetscapePluginMac.cpp; sourceTree = "<group>"; };
1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginInfoStore.h; sourceTree = "<group>"; };
1AEFCC1111D01F96008219D3 /* PluginInfoStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginInfoStore.cpp; sourceTree = "<group>"; };
1AEFCCBC11D02C5E008219D3 /* PluginInfoStoreMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PluginInfoStoreMac.mm; sourceTree = "<group>"; };
......@@ -669,6 +671,7 @@
1A6FBA0111E6812B00DB1371 /* mac */ = {
isa = PBXGroup;
children = (
1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.cpp */,
1A6FBA0211E6813E00DB1371 /* NetscapePluginModuleMac.cpp */,
);
path = mac;
......@@ -1412,6 +1415,7 @@
1A6FBA0311E6813E00DB1371 /* NetscapePluginModuleMac.cpp in Sources */,
1A6FBA2B11E6862700DB1371 /* NetscapeBrowserFuncs.cpp in Sources */,
1A6FBD2911E69BC200DB1371 /* NetscapePlugin.cpp in Sources */,
1AE5B7FB11E7AED200BA6767 /* NetscapePluginMac.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -25,6 +25,7 @@
#include "NetscapePlugin.h"
#include <WebCore/GraphicsContext.h>
#include <WebCore/IntRect.h>
using namespace WebCore;
......@@ -34,6 +35,11 @@ namespace WebKit {
NetscapePlugin::NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule)
: m_pluginModule(pluginModule)
, m_npWindow()
, m_isStarted(false)
#if PLATFORM(MAC)
, m_drawingModel(static_cast<NPDrawingModel>(-1))
, m_eventModel(static_cast<NPEventModel>(-1))
#endif
{
m_npp.ndata = this;
m_npp.pdata = 0;
......@@ -66,18 +72,30 @@ bool NetscapePlugin::initialize(const KURL&, const Vector<String>& paramNames, c
if (error != NPERR_NO_ERROR)
return false;
m_isStarted = true;
// FIXME: This is not correct in all cases.
m_npWindow.type = NPWindowTypeDrawable;
if (!platformPostInitialize()) {
destroy();
return false;
}
return true;
}
void NetscapePlugin::destroy()
{
ASSERT(m_isStarted);
m_pluginModule->pluginFuncs().destroy(&m_npp, 0);
m_isStarted = false;
}
void NetscapePlugin::paint(GraphicsContext* context, const IntRect& dirtyRect)
{
platformPaint(context, dirtyRect);
}
void NetscapePlugin::geometryDidChange(const IntRect& frameRect, const IntRect& clipRect)
......
......@@ -45,6 +45,9 @@ private:
void callSetWindow();
bool platformPostInitialize();
void platformPaint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect);
// Plugin
virtual bool initialize(const WebCore::KURL&, const Vector<WebCore::String>& paramNames, const Vector<WebCore::String>& paramValues, const WebCore::String& mimeType, bool loadManually);
virtual void destroy();
......@@ -54,11 +57,30 @@ private:
RefPtr<NetscapePluginModule> m_pluginModule;
NPP_t m_npp;
NPWindow m_npWindow;
WebCore::IntRect m_frameRect;
WebCore::IntRect m_clipRect;
bool m_isStarted;
#if PLATFORM(MAC)
NPDrawingModel m_drawingModel;
NPEventModel m_eventModel;
#endif
};
// Move these functions to NetscapePluginWin.cpp
#if !PLATFORM(MAC)
inline bool NetscapePlugin::platformPostInitialize()
{
return true;
}
inline void NetscapePlugin::platformPaint(WebCore::GraphicsContext*, const WebCore::IntRect&)
{
}
#endif
} // namespace WebKit
#endif // NetscapePlugin_h
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "NetscapePlugin.h"
#include <WebCore/GraphicsContext.h>
using namespace WebCore;
namespace WebKit {
bool NetscapePlugin::platformPostInitialize()
{
if (m_drawingModel == static_cast<NPDrawingModel>(-1)) {
#ifndef NP_NO_QUICKDRAW
// Default to QuickDraw if the plugin did not specify a drawing model.
m_drawingModel = NPDrawingModelQuickDraw;
#else
// QuickDraw is not available, so we can't default to it. Instead, default to CoreGraphics.
m_drawingModel = NPDrawingModelCoreGraphics;
#endif
}
if (m_eventModel == static_cast<NPEventModel>(-1)) {
// If the plug-in did not specify a drawing model we default to Carbon when it is available.
#ifndef NP_NO_CARBON
m_eventModel = NPEventModelCarbon;
#else
m_eventModel = NPEventModelCocoa;
#endif // NP_NO_CARBON
}
#if !defined(NP_NO_CARBON) && !defined(NP_NO_QUICKDRAW)
// The CA drawing model does not work with the Carbon event model.
if (m_drawingModel == NPDrawingModelCoreAnimation && m_eventModel == NPEventModelCarbon)
return false;
// The Cocoa event model does not work with the QuickDraw drawing model.
if (m_eventModel == NPEventModelCocoa && m_drawingModel == NPDrawingModelQuickDraw)
return false;
#endif
#ifndef NP_NO_QUICKDRAW
// Right now we don't support the QuickDraw drawing model at all
if (m_drawingModel == NPDrawingModelQuickDraw)
return false;
#endif
return true;
}
void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirtyRect)
{
NPCocoaEvent event;
event.type = NPCocoaEventDrawRect;
event.version = 0;
event.data.draw.context = context->platformContext();
event.data.draw.x = dirtyRect.x() - m_frameRect.x();
event.data.draw.y = dirtyRect.y() - m_frameRect.y();
event.data.draw.width = dirtyRect.width();
event.data.draw.height = dirtyRect.height();
m_pluginModule->pluginFuncs().event(&m_npp, &event);
}
} // namespace WebKit
......@@ -58,11 +58,19 @@ void PluginView::paint(GraphicsContext* context, const IntRect& dirtyRect)
if (context->paintingDisabled())
return;
IntRect paintRect = intersection(dirtyRect, frameRect());
if (paintRect.isEmpty())
IntRect dirtyRectInWindowCoordinates = parent()->contentsToWindow(dirtyRect);
IntRect paintRectInWindowCoordinates = intersection(dirtyRectInWindowCoordinates, clipRectInWindowCoordinates());
if (paintRectInWindowCoordinates.isEmpty())
return;
m_plugin->paint(context, paintRect);
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());
m_plugin->paint(context, paintRectInWindowCoordinates);
context->restore();
}
void PluginView::frameRectsChanged()
......@@ -85,15 +93,23 @@ void PluginView::viewGeometryDidChange()
// Get the frame rect in window coordinates.
IntRect frameRectInWindowCoordinates = parent()->contentsToWindow(frameRect());
m_plugin->geometryDidChange(frameRectInWindowCoordinates, clipRectInWindowCoordinates());
}
IntRect PluginView::clipRectInWindowCoordinates() const
{
ASSERT(parent());
// Get the frame rect in window coordinates.
IntRect frameRectInWindowCoordinates = parent()->contentsToWindow(frameRect());
// Get the window clip rect for the enclosing layer (in window coordinates).
RenderLayer* layer = m_pluginElement->renderer()->enclosingLayer();
FrameView* parentView = m_pluginElement->document()->frame()->view();
IntRect windowClipRect = parentView->windowClipRectForLayer(layer, true);
// Intersect the two rects to get the view clip rect in window coordinates.
IntRect clipRectInWindowCoordinates = intersection(frameRectInWindowCoordinates, windowClipRect);
m_plugin->geometryDidChange(frameRectInWindowCoordinates, clipRectInWindowCoordinates);
return intersection(frameRectInWindowCoordinates, windowClipRect);
}
void PluginView::invalidateRect(const IntRect&)
......
......@@ -49,6 +49,7 @@ private:
virtual ~PluginView();
void viewGeometryDidChange();
WebCore::IntRect clipRectInWindowCoordinates() const;
// WebCore::Widget
virtual void setFrameRect(const WebCore::IntRect&);
......
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