mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
4dab17b9d9
--HG-- rename : modules/plugin/test/Makefile.in => dom/plugins/test/Makefile.in rename : modules/plugin/test/crashtests/110650-1.html => dom/plugins/test/crashtests/110650-1.html rename : modules/plugin/test/crashtests/41276-1.html => dom/plugins/test/crashtests/41276-1.html rename : modules/plugin/test/crashtests/48856-1.html => dom/plugins/test/crashtests/48856-1.html rename : modules/plugin/test/crashtests/539897-1.html => dom/plugins/test/crashtests/539897-1.html rename : modules/plugin/test/crashtests/540114-1.html => dom/plugins/test/crashtests/540114-1.html rename : modules/plugin/test/crashtests/570884.html => dom/plugins/test/crashtests/570884.html rename : modules/plugin/test/crashtests/598862.html => dom/plugins/test/crashtests/598862.html rename : modules/plugin/test/crashtests/626602-1.html => dom/plugins/test/crashtests/626602-1.html rename : modules/plugin/test/crashtests/crashtests.list => dom/plugins/test/crashtests/crashtests.list rename : modules/plugin/test/mochitest/307-xo-redirect.sjs => dom/plugins/test/mochitest/307-xo-redirect.sjs rename : modules/plugin/test/mochitest/Makefile.in => dom/plugins/test/mochitest/Makefile.in rename : modules/plugin/test/mochitest/cocoa_focus.html => dom/plugins/test/mochitest/cocoa_focus.html rename : modules/plugin/test/mochitest/cocoa_window_focus.html => dom/plugins/test/mochitest/cocoa_window_focus.html rename : modules/plugin/test/mochitest/crashing_subpage.html => dom/plugins/test/mochitest/crashing_subpage.html rename : modules/plugin/test/mochitest/large-pic.jpg => dom/plugins/test/mochitest/large-pic.jpg rename : modules/plugin/test/mochitest/loremipsum.txt => dom/plugins/test/mochitest/loremipsum.txt rename : modules/plugin/test/mochitest/loremipsum.xtest => dom/plugins/test/mochitest/loremipsum.xtest rename : modules/plugin/test/mochitest/loremipsum.xtest^headers^ => dom/plugins/test/mochitest/loremipsum.xtest^headers^ rename : modules/plugin/test/mochitest/loremipsum_file.txt => dom/plugins/test/mochitest/loremipsum_file.txt rename : modules/plugin/test/mochitest/loremipsum_nocache.txt => dom/plugins/test/mochitest/loremipsum_nocache.txt rename : modules/plugin/test/mochitest/loremipsum_nocache.txt^headers^ => dom/plugins/test/mochitest/loremipsum_nocache.txt^headers^ rename : modules/plugin/test/mochitest/neverending.sjs => dom/plugins/test/mochitest/neverending.sjs rename : modules/plugin/test/mochitest/plugin_visibility_loader.html => dom/plugins/test/mochitest/plugin_visibility_loader.html rename : modules/plugin/test/mochitest/plugin_window.html => dom/plugins/test/mochitest/plugin_window.html rename : modules/plugin/test/mochitest/pluginstream.js => dom/plugins/test/mochitest/pluginstream.js rename : modules/plugin/test/mochitest/post.sjs => dom/plugins/test/mochitest/post.sjs rename : modules/plugin/test/mochitest/test_GCrace.html => dom/plugins/test/mochitest/test_GCrace.html rename : modules/plugin/test/mochitest/test_bug479979.xul => dom/plugins/test/mochitest/test_bug479979.xul rename : modules/plugin/test/mochitest/test_bug532208.html => dom/plugins/test/mochitest/test_bug532208.html rename : modules/plugin/test/mochitest/test_bug539565-1.html => dom/plugins/test/mochitest/test_bug539565-1.html rename : modules/plugin/test/mochitest/test_bug539565-2.html => dom/plugins/test/mochitest/test_bug539565-2.html rename : modules/plugin/test/mochitest/test_clear_site_data.html => dom/plugins/test/mochitest/test_clear_site_data.html rename : modules/plugin/test/mochitest/test_cocoa_focus.html => dom/plugins/test/mochitest/test_cocoa_focus.html rename : modules/plugin/test/mochitest/test_cocoa_window_focus.html => dom/plugins/test/mochitest/test_cocoa_window_focus.html rename : modules/plugin/test/mochitest/test_convertpoint.xul => dom/plugins/test/mochitest/test_convertpoint.xul rename : modules/plugin/test/mochitest/test_cookies.html => dom/plugins/test/mochitest/test_cookies.html rename : modules/plugin/test/mochitest/test_copyText.html => dom/plugins/test/mochitest/test_copyText.html rename : modules/plugin/test/mochitest/test_crash_nested_loop.html => dom/plugins/test/mochitest/test_crash_nested_loop.html rename : modules/plugin/test/mochitest/test_crash_notify.xul => dom/plugins/test/mochitest/test_crash_notify.xul rename : modules/plugin/test/mochitest/test_crash_notify_no_report.xul => dom/plugins/test/mochitest/test_crash_notify_no_report.xul rename : modules/plugin/test/mochitest/test_crash_submit.xul => dom/plugins/test/mochitest/test_crash_submit.xul rename : modules/plugin/test/mochitest/test_crashing.html => dom/plugins/test/mochitest/test_crashing.html rename : modules/plugin/test/mochitest/test_crashing2.html => dom/plugins/test/mochitest/test_crashing2.html rename : modules/plugin/test/mochitest/test_enumerate.html => dom/plugins/test/mochitest/test_enumerate.html rename : modules/plugin/test/mochitest/test_fullpage.html => dom/plugins/test/mochitest/test_fullpage.html rename : modules/plugin/test/mochitest/test_getauthenticationinfo.html => dom/plugins/test/mochitest/test_getauthenticationinfo.html rename : modules/plugin/test/mochitest/test_hanging.html => dom/plugins/test/mochitest/test_hanging.html rename : modules/plugin/test/mochitest/test_instantiation.html => dom/plugins/test/mochitest/test_instantiation.html rename : modules/plugin/test/mochitest/test_multipleinstanceobjects.html => dom/plugins/test/mochitest/test_multipleinstanceobjects.html rename : modules/plugin/test/mochitest/test_newstreamondestroy.html => dom/plugins/test/mochitest/test_newstreamondestroy.html rename : modules/plugin/test/mochitest/test_npn_asynccall.html => dom/plugins/test/mochitest/test_npn_asynccall.html rename : modules/plugin/test/mochitest/test_npn_timers.html => dom/plugins/test/mochitest/test_npn_timers.html rename : modules/plugin/test/mochitest/test_npobject_getters.html => dom/plugins/test/mochitest/test_npobject_getters.html rename : modules/plugin/test/mochitest/test_npruntime.xul => dom/plugins/test/mochitest/test_npruntime.xul rename : modules/plugin/test/mochitest/test_npruntime_construct.html => dom/plugins/test/mochitest/test_npruntime_construct.html rename : modules/plugin/test/mochitest/test_npruntime_identifiers.html => dom/plugins/test/mochitest/test_npruntime_identifiers.html rename : modules/plugin/test/mochitest/test_npruntime_npnevaluate.html => dom/plugins/test/mochitest/test_npruntime_npnevaluate.html rename : modules/plugin/test/mochitest/test_npruntime_npninvoke.html => dom/plugins/test/mochitest/test_npruntime_npninvoke.html rename : modules/plugin/test/mochitest/test_npruntime_npninvokedefault.html => dom/plugins/test/mochitest/test_npruntime_npninvokedefault.html rename : modules/plugin/test/mochitest/test_npruntime_npnsetexception.html => dom/plugins/test/mochitest/test_npruntime_npnsetexception.html rename : modules/plugin/test/mochitest/test_painting.html => dom/plugins/test/mochitest/test_painting.html rename : modules/plugin/test/mochitest/test_plugin_scroll_painting.html => dom/plugins/test/mochitest/test_plugin_scroll_painting.html rename : modules/plugin/test/mochitest/test_pluginstream_asfile.html => dom/plugins/test/mochitest/test_pluginstream_asfile.html rename : modules/plugin/test/mochitest/test_pluginstream_asfileonly.html => dom/plugins/test/mochitest/test_pluginstream_asfileonly.html rename : modules/plugin/test/mochitest/test_pluginstream_err.html => dom/plugins/test/mochitest/test_pluginstream_err.html rename : modules/plugin/test/mochitest/test_pluginstream_geturl.html => dom/plugins/test/mochitest/test_pluginstream_geturl.html rename : modules/plugin/test/mochitest/test_pluginstream_geturlnotify.html => dom/plugins/test/mochitest/test_pluginstream_geturlnotify.html rename : modules/plugin/test/mochitest/test_pluginstream_newstream.html => dom/plugins/test/mochitest/test_pluginstream_newstream.html rename : modules/plugin/test/mochitest/test_pluginstream_post.html => dom/plugins/test/mochitest/test_pluginstream_post.html rename : modules/plugin/test/mochitest/test_pluginstream_poststream.html => dom/plugins/test/mochitest/test_pluginstream_poststream.html rename : modules/plugin/test/mochitest/test_pluginstream_seek.html => dom/plugins/test/mochitest/test_pluginstream_seek.html rename : modules/plugin/test/mochitest/test_pluginstream_seek_close.html => dom/plugins/test/mochitest/test_pluginstream_seek_close.html rename : modules/plugin/test/mochitest/test_pluginstream_src.html => dom/plugins/test/mochitest/test_pluginstream_src.html rename : modules/plugin/test/mochitest/test_positioning.html => dom/plugins/test/mochitest/test_positioning.html rename : modules/plugin/test/mochitest/test_privatemode.xul => dom/plugins/test/mochitest/test_privatemode.xul rename : modules/plugin/test/mochitest/test_propertyAndMethod.html => dom/plugins/test/mochitest/test_propertyAndMethod.html rename : modules/plugin/test/mochitest/test_redirect_handling.html => dom/plugins/test/mochitest/test_redirect_handling.html rename : modules/plugin/test/mochitest/test_streamNotify.html => dom/plugins/test/mochitest/test_streamNotify.html rename : modules/plugin/test/mochitest/test_streamatclose.html => dom/plugins/test/mochitest/test_streamatclose.html rename : modules/plugin/test/mochitest/test_twostreams.html => dom/plugins/test/mochitest/test_twostreams.html rename : modules/plugin/test/mochitest/test_visibility.html => dom/plugins/test/mochitest/test_visibility.html rename : modules/plugin/test/mochitest/test_windowed_invalidate.html => dom/plugins/test/mochitest/test_windowed_invalidate.html rename : modules/plugin/test/mochitest/test_wmode.xul => dom/plugins/test/mochitest/test_wmode.xul rename : modules/plugin/test/mochitest/test_xulbrowser_plugin_visibility.xul => dom/plugins/test/mochitest/test_xulbrowser_plugin_visibility.xul rename : modules/plugin/test/mochitest/test_zero_opacity.html => dom/plugins/test/mochitest/test_zero_opacity.html rename : modules/plugin/test/mochitest/utils.js => dom/plugins/test/mochitest/utils.js rename : modules/plugin/test/mochitest/xulbrowser_plugin_visibility.xul => dom/plugins/test/mochitest/xulbrowser_plugin_visibility.xul rename : modules/plugin/test/reftest/border-padding-1-ref.html => dom/plugins/test/reftest/border-padding-1-ref.html rename : modules/plugin/test/reftest/border-padding-1.html => dom/plugins/test/reftest/border-padding-1.html rename : modules/plugin/test/reftest/border-padding-2-ref.html => dom/plugins/test/reftest/border-padding-2-ref.html rename : modules/plugin/test/reftest/border-padding-2.html => dom/plugins/test/reftest/border-padding-2.html rename : modules/plugin/test/reftest/border-padding-3-ref.html => dom/plugins/test/reftest/border-padding-3-ref.html rename : modules/plugin/test/reftest/border-padding-3.html => dom/plugins/test/reftest/border-padding-3.html rename : modules/plugin/test/reftest/div-alpha-opacity.html => dom/plugins/test/reftest/div-alpha-opacity.html rename : modules/plugin/test/reftest/div-alpha-zindex.html => dom/plugins/test/reftest/div-alpha-zindex.html rename : modules/plugin/test/reftest/div-sanity.html => dom/plugins/test/reftest/div-sanity.html rename : modules/plugin/test/reftest/plugin-alpha-opacity.html => dom/plugins/test/reftest/plugin-alpha-opacity.html rename : modules/plugin/test/reftest/plugin-alpha-zindex.html => dom/plugins/test/reftest/plugin-alpha-zindex.html rename : modules/plugin/test/reftest/plugin-background-1-step.html => dom/plugins/test/reftest/plugin-background-1-step.html rename : modules/plugin/test/reftest/plugin-background-10-step.html => dom/plugins/test/reftest/plugin-background-10-step.html rename : modules/plugin/test/reftest/plugin-background-2-step.html => dom/plugins/test/reftest/plugin-background-2-step.html rename : modules/plugin/test/reftest/plugin-background-5-step.html => dom/plugins/test/reftest/plugin-background-5-step.html rename : modules/plugin/test/reftest/plugin-background-ref.html => dom/plugins/test/reftest/plugin-background-ref.html rename : modules/plugin/test/reftest/plugin-background.css => dom/plugins/test/reftest/plugin-background.css rename : modules/plugin/test/reftest/plugin-background.html => dom/plugins/test/reftest/plugin-background.html rename : modules/plugin/test/reftest/plugin-background.js => dom/plugins/test/reftest/plugin-background.js rename : modules/plugin/test/reftest/plugin-busy-alpha-zindex.html => dom/plugins/test/reftest/plugin-busy-alpha-zindex.html rename : modules/plugin/test/reftest/plugin-canvas-alpha-zindex.html => dom/plugins/test/reftest/plugin-canvas-alpha-zindex.html rename : modules/plugin/test/reftest/plugin-sanity.html => dom/plugins/test/reftest/plugin-sanity.html rename : modules/plugin/test/reftest/plugin-transform-1-ref.html => dom/plugins/test/reftest/plugin-transform-1-ref.html rename : modules/plugin/test/reftest/plugin-transform-1.html => dom/plugins/test/reftest/plugin-transform-1.html rename : modules/plugin/test/reftest/plugin-transform-2-ref.html => dom/plugins/test/reftest/plugin-transform-2-ref.html rename : modules/plugin/test/reftest/plugin-transform-2.html => dom/plugins/test/reftest/plugin-transform-2.html rename : modules/plugin/test/reftest/plugin-transform-alpha-zindex.html => dom/plugins/test/reftest/plugin-transform-alpha-zindex.html rename : modules/plugin/test/reftest/pluginproblemui-direction-1-ref.html => dom/plugins/test/reftest/pluginproblemui-direction-1-ref.html rename : modules/plugin/test/reftest/pluginproblemui-direction-1.html => dom/plugins/test/reftest/pluginproblemui-direction-1.html rename : modules/plugin/test/reftest/pluginproblemui-direction-2-ref.html => dom/plugins/test/reftest/pluginproblemui-direction-2-ref.html rename : modules/plugin/test/reftest/pluginproblemui-direction-2.html => dom/plugins/test/reftest/pluginproblemui-direction-2.html rename : modules/plugin/test/reftest/reftest.list => dom/plugins/test/reftest/reftest.list rename : modules/plugin/test/reftest/windowless-clipping-1-ref.html => dom/plugins/test/reftest/windowless-clipping-1-ref.html rename : modules/plugin/test/reftest/windowless-clipping-1.html => dom/plugins/test/reftest/windowless-clipping-1.html rename : modules/plugin/test/testplugin/Info.plist => dom/plugins/test/testplugin/Info.plist rename : modules/plugin/test/testplugin/Makefile.in => dom/plugins/test/testplugin/Makefile.in rename : modules/plugin/test/testplugin/README => dom/plugins/test/testplugin/README rename : modules/plugin/test/testplugin/nptest.cpp => dom/plugins/test/testplugin/nptest.cpp rename : modules/plugin/test/testplugin/nptest.def => dom/plugins/test/testplugin/nptest.def rename : modules/plugin/test/testplugin/nptest.h => dom/plugins/test/testplugin/nptest.h rename : modules/plugin/test/testplugin/nptest.rc => dom/plugins/test/testplugin/nptest.rc rename : modules/plugin/test/testplugin/nptest_droid.cpp => dom/plugins/test/testplugin/nptest_droid.cpp rename : modules/plugin/test/testplugin/nptest_gtk2.cpp => dom/plugins/test/testplugin/nptest_gtk2.cpp rename : modules/plugin/test/testplugin/nptest_macosx.mm => dom/plugins/test/testplugin/nptest_macosx.mm rename : modules/plugin/test/testplugin/nptest_os2.cpp => dom/plugins/test/testplugin/nptest_os2.cpp rename : modules/plugin/test/testplugin/nptest_platform.h => dom/plugins/test/testplugin/nptest_platform.h rename : modules/plugin/test/testplugin/nptest_qt.cpp => dom/plugins/test/testplugin/nptest_qt.cpp rename : modules/plugin/test/testplugin/nptest_utils.cpp => dom/plugins/test/testplugin/nptest_utils.cpp rename : modules/plugin/test/testplugin/nptest_utils.h => dom/plugins/test/testplugin/nptest_utils.h rename : modules/plugin/test/testplugin/nptest_windows.cpp => dom/plugins/test/testplugin/nptest_windows.cpp rename : modules/plugin/test/unit/head_plugins.js => dom/plugins/test/unit/head_plugins.js rename : modules/plugin/test/unit/test_bug455213.js => dom/plugins/test/unit/test_bug455213.js rename : modules/plugin/test/unit/test_bug471245.js => dom/plugins/test/unit/test_bug471245.js
361 lines
11 KiB
Plaintext
361 lines
11 KiB
Plaintext
/* ***** BEGIN LICENSE BLOCK *****
|
|
*
|
|
* Copyright (c) 2008, Mozilla Corporation
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
* list of conditions and the following disclaimer.
|
|
* * 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.
|
|
* * Neither the name of the Mozilla Corporation nor the names of its
|
|
* contributors may be used to endorse or promote products derived from this
|
|
* software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT OWNER OR 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.
|
|
*
|
|
* Contributor(s):
|
|
* Josh Aas <josh@mozilla.com>
|
|
*
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
#include "nptest_platform.h"
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
using namespace std;
|
|
|
|
bool
|
|
pluginSupportsWindowMode()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
pluginSupportsWindowlessMode()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
NPError
|
|
pluginInstanceInit(InstanceData* instanceData)
|
|
{
|
|
NPP npp = instanceData->npp;
|
|
|
|
NPBool supportsCoreGraphics = false;
|
|
if ((NPN_GetValue(npp, NPNVsupportsCoreGraphicsBool, &supportsCoreGraphics) == NPERR_NO_ERROR) &&
|
|
supportsCoreGraphics) {
|
|
NPN_SetValue(npp, NPPVpluginDrawingModel, (void*)NPDrawingModelCoreGraphics);
|
|
} else {
|
|
printf("CoreGraphics drawing model not supported, can't create a plugin instance.\n");
|
|
return NPERR_INCOMPATIBLE_VERSION_ERROR;
|
|
}
|
|
|
|
#ifndef NP_NO_CARBON
|
|
// The test plugin will test using Carbon NPAPI if it is available. This
|
|
// is simply because we want to test Gecko's Carbon NPAPI support. You can
|
|
// override this behavior with an environment variable.
|
|
if (!getenv("TEST_COCOA_NPAPI")) {
|
|
NPBool supportsCarbonEvents = false;
|
|
if ((NPN_GetValue(npp, NPNVsupportsCarbonBool, &supportsCarbonEvents) == NPERR_NO_ERROR) &&
|
|
supportsCarbonEvents) {
|
|
instanceData->eventModel = NPEventModelCarbon;
|
|
return NPERR_NO_ERROR;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
NPBool supportsCocoaEvents = false;
|
|
if ((NPN_GetValue(npp, NPNVsupportsCocoaBool, &supportsCocoaEvents) == NPERR_NO_ERROR) &&
|
|
supportsCocoaEvents) {
|
|
NPN_SetValue(npp, NPPVpluginEventModel, (void*)NPEventModelCocoa);
|
|
instanceData->eventModel = NPEventModelCocoa;
|
|
} else {
|
|
printf("Cocoa event model not supported, can't create a plugin instance.\n");
|
|
return NPERR_INCOMPATIBLE_VERSION_ERROR;
|
|
}
|
|
|
|
return NPERR_NO_ERROR;
|
|
}
|
|
|
|
void
|
|
pluginInstanceShutdown(InstanceData* instanceData)
|
|
{
|
|
}
|
|
|
|
static bool
|
|
RectEquals(const NPRect& r1, const NPRect& r2)
|
|
{
|
|
return r1.left == r2.left && r1.top == r2.top &&
|
|
r1.right == r2.right && r1.bottom == r2.bottom;
|
|
}
|
|
|
|
void
|
|
pluginDoSetWindow(InstanceData* instanceData, NPWindow* newWindow)
|
|
{
|
|
// Ugh. Due to a terrible Gecko bug, we have to ignore position changes
|
|
// when the clip rect doesn't change; the position can be wrong
|
|
// when set by a path other than nsObjectFrame::FixUpPluginWindow.
|
|
int32_t oldX = instanceData->window.x;
|
|
int32_t oldY = instanceData->window.y;
|
|
bool clipChanged =
|
|
!RectEquals(instanceData->window.clipRect, newWindow->clipRect);
|
|
instanceData->window = *newWindow;
|
|
if (!clipChanged) {
|
|
instanceData->window.x = oldX;
|
|
instanceData->window.y = oldY;
|
|
}
|
|
}
|
|
|
|
void
|
|
pluginWidgetInit(InstanceData* instanceData, void* oldWindow)
|
|
{
|
|
// Should never be called since we don't support window mode
|
|
}
|
|
|
|
static void
|
|
GetColorsFromRGBA(PRUint32 rgba, float* r, float* g, float* b, float* a)
|
|
{
|
|
*b = (rgba & 0xFF) / 255.0;
|
|
*g = ((rgba & 0xFF00) >> 8) / 255.0;
|
|
*r = ((rgba & 0xFF0000) >> 16) / 255.0;
|
|
*a = ((rgba & 0xFF000000) >> 24) / 255.0;
|
|
}
|
|
|
|
static void
|
|
pluginDraw(InstanceData* instanceData, NPCocoaEvent* event)
|
|
{
|
|
if (!instanceData)
|
|
return;
|
|
|
|
notifyDidPaint(instanceData);
|
|
|
|
NPP npp = instanceData->npp;
|
|
if (!npp)
|
|
return;
|
|
|
|
const char* uaString = NPN_UserAgent(npp);
|
|
if (!uaString)
|
|
return;
|
|
|
|
NPWindow window = instanceData->window;
|
|
|
|
CGContextRef cgContext = NULL;
|
|
#ifndef NP_NO_CARBON
|
|
if (instanceData->eventModel == NPEventModelCocoa) {
|
|
cgContext = event->data.draw.context;
|
|
} else {
|
|
cgContext = ((NP_CGContext*)(window.window))->context;
|
|
}
|
|
#else
|
|
cgContext = event->data.draw.context;
|
|
#endif
|
|
|
|
float windowWidth = window.width;
|
|
float windowHeight = window.height;
|
|
|
|
switch(instanceData->scriptableObject->drawMode) {
|
|
case DM_DEFAULT: {
|
|
CFStringRef uaCFString = CFStringCreateWithCString(kCFAllocatorDefault, uaString, kCFStringEncodingASCII);
|
|
// save the cgcontext gstate
|
|
CGContextSaveGState(cgContext);
|
|
|
|
// we get a flipped context
|
|
CGContextTranslateCTM(cgContext, 0.0, windowHeight);
|
|
CGContextScaleCTM(cgContext, 1.0, -1.0);
|
|
|
|
// draw a gray background for the plugin
|
|
CGContextAddRect(cgContext, CGRectMake(0, 0, windowWidth, windowHeight));
|
|
CGContextSetGrayFillColor(cgContext, 0.5, 1.0);
|
|
CGContextDrawPath(cgContext, kCGPathFill);
|
|
|
|
// draw a black frame around the plugin
|
|
CGContextAddRect(cgContext, CGRectMake(0, 0, windowWidth, windowHeight));
|
|
CGContextSetGrayStrokeColor(cgContext, 0.0, 1.0);
|
|
CGContextSetLineWidth(cgContext, 6.0);
|
|
CGContextStrokePath(cgContext);
|
|
|
|
// draw the UA string using Core Text
|
|
CGContextSetTextMatrix(cgContext, CGAffineTransformIdentity);
|
|
|
|
// Initialize a rectangular path.
|
|
CGMutablePathRef path = CGPathCreateMutable();
|
|
CGRect bounds = CGRectMake(10.0, 10.0, PR_MAX(0.0, windowWidth - 20.0),
|
|
PR_MAX(0.0, windowHeight - 20.0));
|
|
CGPathAddRect(path, NULL, bounds);
|
|
|
|
// Initialize an attributed string.
|
|
CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
|
|
CFAttributedStringReplaceString(attrString, CFRangeMake(0, 0), uaCFString);
|
|
|
|
// Create a color and add it as an attribute to the string.
|
|
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
|
|
CGFloat components[] = { 0.0, 0.0, 0.0, 1.0 };
|
|
CGColorRef red = CGColorCreate(rgbColorSpace, components);
|
|
CGColorSpaceRelease(rgbColorSpace);
|
|
CFAttributedStringSetAttribute(attrString, CFRangeMake(0, 50), kCTForegroundColorAttributeName, red);
|
|
|
|
// Create the framesetter with the attributed string.
|
|
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString);
|
|
CFRelease(attrString);
|
|
|
|
// Create the frame and draw it into the graphics context
|
|
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
|
|
CFRelease(framesetter);
|
|
if (frame) {
|
|
CTFrameDraw(frame, cgContext);
|
|
CFRelease(frame);
|
|
}
|
|
|
|
// restore the cgcontext gstate
|
|
CGContextRestoreGState(cgContext);
|
|
break;
|
|
}
|
|
case DM_SOLID_COLOR: {
|
|
// save the cgcontext gstate
|
|
CGContextSaveGState(cgContext);
|
|
|
|
// we get a flipped context
|
|
CGContextTranslateCTM(cgContext, 0.0, windowHeight);
|
|
CGContextScaleCTM(cgContext, 1.0, -1.0);
|
|
|
|
// draw a solid background for the plugin
|
|
CGContextAddRect(cgContext, CGRectMake(0, 0, windowWidth, windowHeight));
|
|
|
|
float r,g,b,a;
|
|
GetColorsFromRGBA(instanceData->scriptableObject->drawColor, &r, &g, &b, &a);
|
|
CGContextSetRGBFillColor(cgContext, r, g, b, a);
|
|
CGContextDrawPath(cgContext, kCGPathFill);
|
|
|
|
// restore the cgcontext gstate
|
|
CGContextRestoreGState(cgContext);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
int16_t
|
|
pluginHandleEvent(InstanceData* instanceData, void* event)
|
|
{
|
|
#ifndef NP_NO_CARBON
|
|
if (instanceData->eventModel == NPEventModelCarbon) {
|
|
EventRecord* carbonEvent = (EventRecord*)event;
|
|
if (!carbonEvent)
|
|
return kNPEventNotHandled;
|
|
|
|
NPWindow* w = &instanceData->window;
|
|
switch (carbonEvent->what) {
|
|
case updateEvt:
|
|
pluginDraw(instanceData, NULL);
|
|
break;
|
|
case mouseDown:
|
|
case mouseUp:
|
|
case osEvt:
|
|
{
|
|
Rect globalBounds = {0};
|
|
WindowRef nativeWindow = static_cast<WindowRef>(static_cast<NP_CGContext*>(w->window)->window);
|
|
if (nativeWindow)
|
|
::GetWindowBounds(nativeWindow, kWindowStructureRgn, &globalBounds);
|
|
instanceData->lastMouseX = carbonEvent->where.h - w->x - globalBounds.left;
|
|
instanceData->lastMouseY = carbonEvent->where.v - w->y - globalBounds.top;
|
|
break;
|
|
}
|
|
default:
|
|
return kNPEventNotHandled;
|
|
}
|
|
|
|
return kNPEventHandled;
|
|
}
|
|
#endif
|
|
|
|
NPCocoaEvent* cocoaEvent = (NPCocoaEvent*)event;
|
|
if (!cocoaEvent)
|
|
return kNPEventNotHandled;
|
|
|
|
switch (cocoaEvent->type) {
|
|
case NPCocoaEventDrawRect:
|
|
pluginDraw(instanceData, cocoaEvent);
|
|
break;
|
|
case NPCocoaEventMouseDown:
|
|
case NPCocoaEventMouseUp:
|
|
case NPCocoaEventMouseMoved:
|
|
instanceData->lastMouseX = (int32_t)cocoaEvent->data.mouse.pluginX;
|
|
instanceData->lastMouseY = (int32_t)cocoaEvent->data.mouse.pluginY;
|
|
break;
|
|
case NPCocoaEventWindowFocusChanged:
|
|
instanceData->topLevelWindowActivationState = cocoaEvent->data.focus.hasFocus ?
|
|
ACTIVATION_STATE_ACTIVATED : ACTIVATION_STATE_DEACTIVATED;
|
|
instanceData->topLevelWindowActivationEventCount = instanceData->topLevelWindowActivationEventCount + 1;
|
|
break;
|
|
case NPCocoaEventFocusChanged:
|
|
instanceData->focusState = cocoaEvent->data.focus.hasFocus ?
|
|
ACTIVATION_STATE_ACTIVATED : ACTIVATION_STATE_DEACTIVATED;
|
|
instanceData->focusEventCount = instanceData->focusEventCount + 1;
|
|
break;
|
|
default:
|
|
return kNPEventNotHandled;
|
|
}
|
|
|
|
return kNPEventHandled;
|
|
}
|
|
|
|
int32_t pluginGetEdge(InstanceData* instanceData, RectEdge edge)
|
|
{
|
|
NPWindow* w = &instanceData->window;
|
|
switch (edge) {
|
|
case EDGE_LEFT:
|
|
return w->x;
|
|
case EDGE_TOP:
|
|
return w->y;
|
|
case EDGE_RIGHT:
|
|
return w->x + w->width;
|
|
case EDGE_BOTTOM:
|
|
return w->y + w->height;
|
|
}
|
|
return NPTEST_INT32_ERROR;
|
|
}
|
|
|
|
int32_t pluginGetClipRegionRectCount(InstanceData* instanceData)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
int32_t pluginGetClipRegionRectEdge(InstanceData* instanceData,
|
|
int32_t rectIndex, RectEdge edge)
|
|
{
|
|
if (rectIndex != 0)
|
|
return NPTEST_INT32_ERROR;
|
|
|
|
// We have to add the Cocoa titlebar height here since the clip rect
|
|
// is being returned relative to that
|
|
static const int COCOA_TITLEBAR_HEIGHT = 22;
|
|
|
|
NPWindow* w = &instanceData->window;
|
|
switch (edge) {
|
|
case EDGE_LEFT:
|
|
return w->clipRect.left;
|
|
case EDGE_TOP:
|
|
return w->clipRect.top + COCOA_TITLEBAR_HEIGHT;
|
|
case EDGE_RIGHT:
|
|
return w->clipRect.right;
|
|
case EDGE_BOTTOM:
|
|
return w->clipRect.bottom + COCOA_TITLEBAR_HEIGHT;
|
|
}
|
|
return NPTEST_INT32_ERROR;
|
|
}
|
|
|
|
void pluginDoInternalConsistencyCheck(InstanceData* instanceData, string& error)
|
|
{
|
|
}
|