background/BackgroundPlugin.cpp \
form/FormPlugin.cpp \
paint/PaintPlugin.cpp \
- surface/SurfacePlugin.cpp \
LOCAL_C_INCLUDES += \
$(LOCAL_PATH) \
$(LOCAL_PATH)/background \
$(LOCAL_PATH)/form \
$(LOCAL_PATH)/paint \
- $(LOCAL_PATH)/surface \
external/webkit/WebCore/bridge \
external/webkit/WebCore/plugins \
external/webkit/WebCore/platform/android/JavaVM \
kForm_PluginType = 4,
kText_PluginType = 5,
kPaint_PluginType = 6,
- kSurface_PluginType = 7,
};
typedef uint32_t PluginType;
extern NPNetscapeFuncs* browser;
extern ANPBitmapInterfaceV0 gBitmapI;
-extern ANPLogInterfaceV0 gLogI;
extern ANPCanvasInterfaceV0 gCanvasI;
+extern ANPLogInterfaceV0 gLogI;
extern ANPPaintInterfaceV0 gPaintI;
-extern ANPPathInterfaceV0 gPathI;
+extern ANPSurfaceInterfaceV0 gSurfaceI;
extern ANPTypefaceInterfaceV0 gTypefaceI;
extern uint32_t getMSecs();
BackgroundPlugin::BackgroundPlugin(NPP inst) : SubPlugin(inst) {
- m_paint = gPaintI.newPaint();
- gPaintI.setFlags(m_paint, gPaintI.getFlags(m_paint) | kAntiAlias_ANPPaintFlag);
- gPaintI.setColor(m_paint, 0xFFFF0000);
- gPaintI.setTextSize(m_paint, 16);
-
- ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle);
- gPaintI.setTypeface(m_paint, tf);
- gTypefaceI.unref(tf);
+ // initialize the drawing surface
+ m_surfaceReady = false;
+ m_surface = gSurfaceI.newSurface(inst, kRGBA_ANPSurfaceType, false);
+ if(!m_surface)
+ gLogI.log(inst, kError_ANPLogType, "----%p Unable to create RGBA surface", inst);
- //initialize variables
+ //initialize bitmap transparency variables
mFinishedStageOne = false;
mFinishedStageTwo = false;
mFinishedStageThree = false;
}
BackgroundPlugin::~BackgroundPlugin() {
+ gSurfaceI.deleteSurface(m_surface);
}
bool BackgroundPlugin::supportsDrawingModel(ANPDrawingModel model) {
- return (model == kBitmap_ANPDrawingModel);
+ return (model == kSurface_ANPDrawingModel);
}
-void BackgroundPlugin::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) {
- ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);
+void BackgroundPlugin::drawPlugin(int surfaceWidth, int surfaceHeight) {
- ANPRectF clipR;
- clipR.left = clip.left;
- clipR.top = clip.top;
- clipR.right = clip.right;
- clipR.bottom = clip.bottom;
- gCanvasI.clipRect(canvas, &clipR);
+ // get the plugin's dimensions according to the DOM
+ PluginObject *obj = (PluginObject*) inst()->pdata;
+ const int W = obj->window->width;
+ const int H = obj->window->height;
- draw(canvas);
- gCanvasI.deleteCanvas(canvas);
-}
+ // compute the current zoom level
+ const float zoomFactorW = static_cast<float>(surfaceWidth) / W;
+ const float zoomFactorH = static_cast<float>(surfaceHeight) / H;
+
+ // check to make sure the zoom level is uniform
+ if (zoomFactorW + .01 < zoomFactorH && zoomFactorW - .01 > zoomFactorH)
+ gLogI.log(inst(), kError_ANPLogType, " ------ %p zoom is out of sync (%f,%f)",
+ inst(), zoomFactorW, zoomFactorH);
-void BackgroundPlugin::draw(ANPCanvas* canvas) {
+ // scale the variables based on the zoom level
+ const int fontSize = (int)(zoomFactorW * 16);
+ const int leftMargin = (int)(zoomFactorW * 10);
+ // lock the surface
+ ANPBitmap bitmap;
+ if (!m_surfaceReady || !gSurfaceI.lock(m_surface, &bitmap, NULL)) {
+ gLogI.log(inst(), kError_ANPLogType, " ------ %p unable to lock the plugin", inst());
+ return;
+ }
+
+ // create a canvas
+ ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);
gCanvasI.drawColor(canvas, 0xFFFFFFFF);
+ ANPPaint* paint = gPaintI.newPaint();
+ gPaintI.setFlags(paint, gPaintI.getFlags(paint) | kAntiAlias_ANPPaintFlag);
+ gPaintI.setColor(paint, 0xFFFF0000);
+ gPaintI.setTextSize(paint, fontSize);
+
+ ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle);
+ gPaintI.setTypeface(paint, tf);
+ gTypefaceI.unref(tf);
+
ANPFontMetrics fm;
- gPaintI.getFontMetrics(m_paint, &fm);
+ gPaintI.getFontMetrics(paint, &fm);
- gPaintI.setColor(m_paint, 0xFF0000FF);
+ gPaintI.setColor(paint, 0xFF0000FF);
const char c[] = "This is a background plugin.";
- gCanvasI.drawText(canvas, c, sizeof(c)-1, 10, -fm.fTop, m_paint);
+ gCanvasI.drawText(canvas, c, sizeof(c)-1, leftMargin, -fm.fTop, paint);
+
+ // clean up variables and unlock the surface
+ gPaintI.deletePaint(paint);
+ gCanvasI.deleteCanvas(canvas);
+ gSurfaceI.unlock(m_surface);
}
int16 BackgroundPlugin::handleEvent(const ANPEvent* evt) {
- NPP instance = this->inst();
-
switch (evt->eventType) {
case kDraw_ANPEventType:
- switch (evt->data.draw.model) {
- case kBitmap_ANPDrawingModel:
- test_bitmap_transparency(evt);
- drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip);
- return 1;
- default:
- break; // unknown drawing model
+ gLogI.log(inst(), kError_ANPLogType, " ------ %p the plugin did not request draw events", inst());
+ break;
+ case kSurface_ANPEventType:
+ switch (evt->data.surface.action) {
+ case kCreated_ANPSurfaceAction:
+ m_surfaceReady = true;
+ return 1;
+ case kDestroyed_ANPSurfaceAction:
+ m_surfaceReady = false;
+ return 1;
+ case kChanged_ANPSurfaceAction:
+ drawPlugin(evt->data.surface.data.changed.width,
+ evt->data.surface.data.changed.height);
+ return 1;
+ }
+ break;
+ case kLifecycle_ANPEventType:
+ if (evt->data.lifecycle.action == kOnLoad_ANPLifecycleAction) {
+ gLogI.log(inst(), kDebug_ANPLogType, " ------ %p the plugin received an onLoad event", inst());
+ return 1;
}
+ break;
case kTouch_ANPEventType:
- gLogI.log(instance, kError_ANPLogType, " ------ %p the plugin did not request touch events", instance);
+ gLogI.log(inst(), kError_ANPLogType, " ------ %p the plugin did not request touch events", inst());
+ break;
case kKey_ANPEventType:
- gLogI.log(instance, kError_ANPLogType, " ------ %p the plugin did not request key events", instance);
+ gLogI.log(inst(), kError_ANPLogType, " ------ %p the plugin did not request key events", inst());
+ break;
default:
break;
}
bool mFinishedStageThree; // check opaque
private:
- void draw(ANPCanvas*);
- void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip);
+ void drawPlugin(int surfaceWidth, int surfaceHeight);
- ANPPaint* m_paint;
+ bool m_surfaceReady;
+ ANPSurface* m_surface;
void test_logging();
void test_timers();
gLogI.log(instance, kDebug_ANPLogType, "----%p Recvd Nav Key %d", instance, keyCode);
if (!m_activeInput) {
+ gWindowI.showKeyboard(instance, true);
switchActiveInput(&m_usernameInput);
}
else if (m_activeInput == &m_usernameInput) {
#include "BackgroundPlugin.h"
#include "FormPlugin.h"
#include "PaintPlugin.h"
-#include "SurfacePlugin.h"
#include "android_npapi.h"
NPNetscapeFuncs* browser;
obj->pluginType = kPaint_PluginType;
obj->activePlugin = new PaintPlugin(instance);
}
- else if (!strcmp(argv[i], "RGBA_Surface")) {
- obj->pluginType = kSurface_PluginType;
- obj->activePlugin = new SurfacePlugin(instance, kRGBA_ANPSurfaceType);
- }
gLogI.log(instance, kDebug_ANPLogType, "------ %p PluginType is %d", instance, obj->pluginType);
break;
}
// initialize the drawing surface
m_surfaceReady = false;
- m_surface = gSurfaceI.newSurface(inst, kRGBA_ANPSurfaceType);
+ m_surface = gSurfaceI.newSurface(inst, kRGBA_ANPSurfaceType, true);
if(!m_surface)
gLogI.log(inst, kError_ANPLogType, "----%p Unable to create RGBA surface", inst);
case kDestroyed_ANPSurfaceAction:
m_surfaceReady = false;
return 1;
+ case kChanged_ANPSurfaceAction:
+ // get the plugin's dimensions according to the DOM
+ PluginObject *obj = (PluginObject*) inst()->pdata;
+ const int pW = obj->window->width;
+ const int pH = obj->window->height;
+ // get the plugin's surface dimensions
+ const int sW = evt->data.surface.data.changed.width;
+ const int sH = evt->data.surface.data.changed.height;
+ if (pW != sW || pH != sH)
+ gLogI.log(inst(), kError_ANPLogType,
+ "----%p Invalid Surface Dimensions (%d,%d):(%d,%d)",
+ inst(), pW, pH, sW, sH);
+ return 1;
}
break;
+++ /dev/null
-/*
- * Copyright 2009, The Android Open Source Project
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 COMPUTER, INC. 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.
- */
-
-#include "SurfacePlugin.h"
-
-#include <stdio.h>
-#include <sys/time.h>
-#include <time.h>
-#include <math.h>
-#include <string.h>
-
-extern NPNetscapeFuncs* browser;
-extern ANPLogInterfaceV0 gLogI;
-extern ANPPaintInterfaceV0 gPaintI;
-extern ANPSurfaceInterfaceV0 gSurfaceI;
-extern ANPTypefaceInterfaceV0 gTypefaceI;
-extern ANPWindowInterfaceV0 gWindowI;
-
-///////////////////////////////////////////////////////////////////////////////
-
-SurfacePlugin::SurfacePlugin(NPP inst, ANPSurfaceType surfaceType) : SubPlugin(inst) {
-
- m_surface = gSurfaceI.newSurface(inst, surfaceType);
-
- if(!m_surface)
- gLogI.log(inst, kError_ANPLogType, "----%p Unable to create surface (%d)", inst, surfaceType);
-}
-
-SurfacePlugin::~SurfacePlugin() {
- if (m_surface)
- gSurfaceI.deleteSurface(m_surface);
-}
-
-bool SurfacePlugin::supportsDrawingModel(ANPDrawingModel model) {
- return (model == kSurface_ANPDrawingModel);
-}
-
-void SurfacePlugin::draw() {
- NPP instance = this->inst();
- PluginObject *obj = (PluginObject*) instance->pdata;
-
- ANPBitmap bitmap;
-
- bool value = gSurfaceI.lock(m_surface, &bitmap, NULL);
- gLogI.log(instance, kDebug_ANPLogType, "----%p locking: %b", instance, value);
- gSurfaceI.unlock(m_surface);
-}
-
-int16 SurfacePlugin::handleEvent(const ANPEvent* evt) {
- NPP instance = this->inst();
-
- switch (evt->eventType) {
- case kDraw_ANPEventType:
- switch (evt->data.draw.model) {
- case kSurface_ANPDrawingModel:
- if (m_surface)
- draw();
- return 1;
- default:
- break; // unknown drawing model
- }
- default:
- break;
- }
- return 0; // unknown or unhandled event
-}
+++ /dev/null
-/*
- * Copyright 2009, The Android Open Source Project
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 COMPUTER, INC. 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.
- */
-
-#include "PluginObject.h"
-
-#ifndef surfacePlugin__DEFINED
-#define surfacePlugin__DEFINED
-
-class SurfacePlugin : public SubPlugin {
-public:
- SurfacePlugin(NPP inst, ANPSurfaceType surfaceType);
- virtual ~SurfacePlugin();
- virtual bool supportsDrawingModel(ANPDrawingModel);
- virtual int16 handleEvent(const ANPEvent* evt);
-private:
- void draw();
- ANPSurface* m_surface;
-
-};
-#endif // surfacePlugin__DEFINED