mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Make CEF compliant with Google/Chromium style (issue #473).
- Add a new check_style tool based on Google's cpplint that can be used to verify compliance of pending changes and specific files/directories. - Update existing CEF source code to be compliant with the style requirements. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@463 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -3,23 +3,26 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "osrplugin.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "cefclient.h"
|
||||
#include "client_popup_handler.h"
|
||||
#include "resource.h"
|
||||
#include "resource_util.h"
|
||||
#include "string_util.h"
|
||||
#include "util.h"
|
||||
#include <gl/gl.h>
|
||||
#include <gl/glu.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <sstream>
|
||||
#include "cefclient/osrplugin.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
#include <windows.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <gl/gl.h>
|
||||
#include <gl/glu.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "cefclient/cefclient.h"
|
||||
#include "cefclient/client_popup_handler.h"
|
||||
#include "cefclient/resource.h"
|
||||
#include "cefclient/resource_util.h"
|
||||
#include "cefclient/string_util.h"
|
||||
#include "cefclient/util.h"
|
||||
|
||||
// Initialized in NP_Initialize.
|
||||
NPNetscapeFuncs* g_osrbrowser = NULL;
|
||||
|
||||
@@ -38,11 +41,9 @@ bool g_offscreenTransparent = false;
|
||||
#define GL_BYTE_COUNT (g_offscreenTransparent?4:3)
|
||||
|
||||
// Class holding pointers for the client plugin window.
|
||||
class ClientPlugin
|
||||
{
|
||||
public:
|
||||
ClientPlugin()
|
||||
{
|
||||
class ClientPlugin {
|
||||
public:
|
||||
ClientPlugin() {
|
||||
hWnd = NULL;
|
||||
hDC = NULL;
|
||||
hRC = NULL;
|
||||
@@ -59,19 +60,16 @@ class ClientOSRHandler : public CefClient,
|
||||
public CefLoadHandler,
|
||||
public CefRequestHandler,
|
||||
public CefDisplayHandler,
|
||||
public CefRenderHandler
|
||||
{
|
||||
public:
|
||||
ClientOSRHandler(ClientPlugin* plugin)
|
||||
public CefRenderHandler {
|
||||
public:
|
||||
explicit ClientOSRHandler(ClientPlugin* plugin)
|
||||
: plugin_(plugin),
|
||||
view_buffer_(NULL),
|
||||
view_buffer_size_(0),
|
||||
popup_buffer_(NULL),
|
||||
popup_buffer_size_(0)
|
||||
{
|
||||
popup_buffer_size_(0) {
|
||||
}
|
||||
~ClientOSRHandler()
|
||||
{
|
||||
~ClientOSRHandler() {
|
||||
if (view_buffer_)
|
||||
delete [] view_buffer_;
|
||||
if (popup_buffer_)
|
||||
@@ -79,16 +77,21 @@ public:
|
||||
}
|
||||
|
||||
// CefClient methods
|
||||
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
|
||||
// CefLifeSpanHandler methods
|
||||
|
||||
@@ -97,8 +100,7 @@ public:
|
||||
CefWindowInfo& windowInfo,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings) OVERRIDE
|
||||
{
|
||||
CefBrowserSettings& settings) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
windowInfo.m_bWindowRenderingDisabled = TRUE;
|
||||
@@ -106,8 +108,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE
|
||||
{
|
||||
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the view size to match the plugin window size.
|
||||
@@ -116,19 +117,17 @@ public:
|
||||
g_offscreenBrowser = browser;
|
||||
}
|
||||
|
||||
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE
|
||||
{
|
||||
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE {
|
||||
g_offscreenBrowser = NULL;
|
||||
}
|
||||
|
||||
// CefLoadHandler methods
|
||||
|
||||
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame) OVERRIDE
|
||||
{
|
||||
CefRefPtr<CefFrame> frame) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(!browser->IsPopup() && frame->IsMain()) {
|
||||
if (!browser->IsPopup() && frame->IsMain()) {
|
||||
// We've just started loading a page
|
||||
SetLoading(true);
|
||||
}
|
||||
@@ -136,11 +135,10 @@ public:
|
||||
|
||||
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) OVERRIDE
|
||||
{
|
||||
int httpStatusCode) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(!browser->IsPopup() && frame->IsMain()) {
|
||||
if (!browser->IsPopup() && frame->IsMain()) {
|
||||
// We've just finished loading a page
|
||||
SetLoading(false);
|
||||
}
|
||||
@@ -153,12 +151,11 @@ public:
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefRefPtr<CefResponse> response,
|
||||
int loadFlags) OVERRIDE
|
||||
{
|
||||
int loadFlags) OVERRIDE {
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
std::string url = request->GetURL();
|
||||
if(url == "http://tests/transparency") {
|
||||
if (url == "http://tests/transparency") {
|
||||
resourceStream = GetBinaryResourceReader(IDS_TRANSPARENCY);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
@@ -171,8 +168,7 @@ public:
|
||||
|
||||
virtual void OnNavStateChange(CefRefPtr<CefBrowser> browser,
|
||||
bool canGoBack,
|
||||
bool canGoForward) OVERRIDE
|
||||
{
|
||||
bool canGoForward) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the "back" and "forward" button state in the HTML.
|
||||
@@ -186,8 +182,7 @@ public:
|
||||
|
||||
virtual void OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& url) OVERRIDE
|
||||
{
|
||||
const CefString& url) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the "url" value in the HTML.
|
||||
@@ -199,8 +194,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) OVERRIDE
|
||||
{
|
||||
const CefString& title) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the "title" value in the HTML.
|
||||
@@ -215,8 +209,7 @@ public:
|
||||
// CefRenderHandler methods
|
||||
|
||||
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser,
|
||||
CefRect& rect) OVERRIDE
|
||||
{
|
||||
CefRect& rect) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// The simulated screen and view rectangle are the same. This is necessary
|
||||
@@ -228,8 +221,7 @@ public:
|
||||
}
|
||||
|
||||
virtual bool GetScreenRect(CefRefPtr<CefBrowser> browser,
|
||||
CefRect& rect) OVERRIDE
|
||||
{
|
||||
CefRect& rect) OVERRIDE {
|
||||
return GetViewRect(browser, rect);
|
||||
}
|
||||
|
||||
@@ -237,8 +229,7 @@ public:
|
||||
int viewX,
|
||||
int viewY,
|
||||
int& screenX,
|
||||
int& screenY) OVERRIDE
|
||||
{
|
||||
int& screenY) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Convert the point from view coordinates to actual screen coordinates.
|
||||
@@ -250,13 +241,12 @@ public:
|
||||
}
|
||||
|
||||
virtual void OnPopupShow(CefRefPtr<CefBrowser> browser,
|
||||
bool show) OVERRIDE
|
||||
{
|
||||
bool show) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(!show) {
|
||||
if (!show) {
|
||||
// Clear the popup buffer.
|
||||
popup_rect_.Set(0,0,0,0);
|
||||
popup_rect_.Set(0, 0, 0, 0);
|
||||
if (popup_buffer_) {
|
||||
delete [] popup_buffer_;
|
||||
popup_buffer_ = NULL;
|
||||
@@ -266,8 +256,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
|
||||
const CefRect& rect) OVERRIDE
|
||||
{
|
||||
const CefRect& rect) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if (rect.width > 0) {
|
||||
@@ -282,8 +271,7 @@ public:
|
||||
virtual void OnPaint(CefRefPtr<CefBrowser> browser,
|
||||
PaintElementType type,
|
||||
const RectList& dirtyRects,
|
||||
const void* buffer) OVERRIDE
|
||||
{
|
||||
const void* buffer) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
wglMakeCurrent(plugin_->hDC, plugin_->hRC);
|
||||
@@ -297,7 +285,7 @@ public:
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, g_textureID);
|
||||
|
||||
|
||||
if (type == PET_VIEW) {
|
||||
// Paint the view.
|
||||
if (g_offscreenTransparent)
|
||||
@@ -310,8 +298,8 @@ public:
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, g_width, g_height,
|
||||
GL_IMAGE_FORMAT, GL_UNSIGNED_BYTE, view_buffer_);
|
||||
}
|
||||
|
||||
if(popup_rect_.width > 0) {
|
||||
|
||||
if (popup_rect_.width > 0) {
|
||||
if (type == PET_POPUP) {
|
||||
// Paint the popup.
|
||||
if (g_offscreenTransparent)
|
||||
@@ -339,8 +327,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
|
||||
CefCursorHandle cursor) OVERRIDE
|
||||
{
|
||||
CefCursorHandle cursor) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Change the plugin window's cursor.
|
||||
@@ -349,9 +336,8 @@ public:
|
||||
SetCursor(cursor);
|
||||
}
|
||||
|
||||
private:
|
||||
void SetLoading(bool isLoading)
|
||||
{
|
||||
private:
|
||||
void SetLoading(bool isLoading) {
|
||||
// Set the "stop" and "reload" button state in the HTML.
|
||||
std::stringstream ss;
|
||||
ss << "document.getElementById('stop').disabled = "
|
||||
@@ -362,10 +348,9 @@ private:
|
||||
}
|
||||
|
||||
// Size the RGB buffer.
|
||||
void SetBufferSize(int width, int height, bool view)
|
||||
{
|
||||
void SetBufferSize(int width, int height, bool view) {
|
||||
int dst_size = width * height * GL_BYTE_COUNT;
|
||||
|
||||
|
||||
// Allocate a new buffer if necesary.
|
||||
if (view) {
|
||||
if (dst_size > view_buffer_size_) {
|
||||
@@ -385,8 +370,7 @@ private:
|
||||
}
|
||||
|
||||
// Set the contents of the RGBA buffer.
|
||||
void SetRGBA(const void* src, int width, int height, bool view)
|
||||
{
|
||||
void SetRGBA(const void* src, int width, int height, bool view) {
|
||||
SetBufferSize(width, height, view);
|
||||
ConvertToRGBA((unsigned char*)src, view?view_buffer_:popup_buffer_, width,
|
||||
height);
|
||||
@@ -394,23 +378,21 @@ private:
|
||||
|
||||
// Convert from BGRA to RGBA format and from upper-left to lower-left origin.
|
||||
static void ConvertToRGBA(const unsigned char* src, unsigned char* dst,
|
||||
int width, int height)
|
||||
{
|
||||
int width, int height) {
|
||||
int sp = 0, dp = (height-1) * width * 4;
|
||||
for(int i = 0; i < height; i++) {
|
||||
for(int j = 0; j < width; j++, dp += 4, sp += 4) {
|
||||
dst[dp] = src[sp+2]; // R
|
||||
dst[dp+1] = src[sp+1]; // G
|
||||
dst[dp+2] = src[sp]; // B
|
||||
dst[dp+3] = src[sp+3]; // A
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++, dp += 4, sp += 4) {
|
||||
dst[dp] = src[sp+2]; // R
|
||||
dst[dp+1] = src[sp+1]; // G
|
||||
dst[dp+2] = src[sp]; // B
|
||||
dst[dp+3] = src[sp+3]; // A
|
||||
}
|
||||
dp -= width * 8;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the contents of the RGB buffer.
|
||||
void SetRGB(const void* src, int width, int height, bool view)
|
||||
{
|
||||
void SetRGB(const void* src, int width, int height, bool view) {
|
||||
SetBufferSize(width, height, view);
|
||||
ConvertToRGB((unsigned char*)src, view?view_buffer_:popup_buffer_, width,
|
||||
height);
|
||||
@@ -418,14 +400,13 @@ private:
|
||||
|
||||
// Convert from BGRA to RGB format and from upper-left to lower-left origin.
|
||||
static void ConvertToRGB(const unsigned char* src, unsigned char* dst,
|
||||
int width, int height)
|
||||
{
|
||||
int width, int height) {
|
||||
int sp = 0, dp = (height-1) * width * 3;
|
||||
for(int i = 0; i < height; i++) {
|
||||
for(int j = 0; j < width; j++, dp += 3, sp += 4) {
|
||||
dst[dp] = src[sp+2]; // R
|
||||
dst[dp+1] = src[sp+1]; // G
|
||||
dst[dp+2] = src[sp]; // B
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++, dp += 3, sp += 4) {
|
||||
dst[dp] = src[sp+2]; // R
|
||||
dst[dp+1] = src[sp+1]; // G
|
||||
dst[dp+2] = src[sp]; // B
|
||||
}
|
||||
dp -= width * 6;
|
||||
}
|
||||
@@ -447,14 +428,13 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
LPARAM lParam);
|
||||
|
||||
// Enable GL.
|
||||
void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
|
||||
{
|
||||
void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC) {
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
int format;
|
||||
|
||||
|
||||
// Get the device context.
|
||||
*hDC = GetDC(hWnd);
|
||||
|
||||
|
||||
// Set the pixel format for the DC.
|
||||
ZeroMemory(&pfd, sizeof(pfd));
|
||||
pfd.nSize = sizeof(pfd);
|
||||
@@ -466,7 +446,7 @@ void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
format = ChoosePixelFormat(*hDC, &pfd);
|
||||
SetPixelFormat(*hDC, format, &pfd);
|
||||
|
||||
|
||||
// Create and enable the render context.
|
||||
*hRC = wglCreateContext(*hDC);
|
||||
wglMakeCurrent(*hDC, *hRC);
|
||||
@@ -483,20 +463,18 @@ void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
|
||||
}
|
||||
|
||||
// Disable GL.
|
||||
void DisableGL(HWND hWnd, HDC hDC, HGLRC hRC)
|
||||
{
|
||||
void DisableGL(HWND hWnd, HDC hDC, HGLRC hRC) {
|
||||
// Delete the texture.
|
||||
if(g_textureID != -1)
|
||||
if (g_textureID != -1)
|
||||
glDeleteTextures(1, &g_textureID);
|
||||
|
||||
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(hRC);
|
||||
ReleaseDC(hWnd, hDC);
|
||||
}
|
||||
|
||||
// Size the GL view.
|
||||
void SizeGL(ClientPlugin* plugin, int width, int height)
|
||||
{
|
||||
void SizeGL(ClientPlugin* plugin, int width, int height) {
|
||||
g_width = width;
|
||||
g_height = height;
|
||||
|
||||
@@ -517,7 +495,7 @@ void SizeGL(ClientPlugin* plugin, int width, int height)
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// Delete the existing exture.
|
||||
if(g_textureID != -1)
|
||||
if (g_textureID != -1)
|
||||
glDeleteTextures(1, &g_textureID);
|
||||
|
||||
// Create a new texture.
|
||||
@@ -543,16 +521,15 @@ void SizeGL(ClientPlugin* plugin, int width, int height)
|
||||
}
|
||||
|
||||
delete [] buffer;
|
||||
|
||||
if(g_offscreenBrowser.get())
|
||||
|
||||
if (g_offscreenBrowser.get())
|
||||
g_offscreenBrowser->SetSize(PET_VIEW, width, height);
|
||||
}
|
||||
|
||||
// Render the view contents.
|
||||
void RenderGL(ClientPlugin* plugin)
|
||||
{
|
||||
void RenderGL(ClientPlugin* plugin) {
|
||||
wglMakeCurrent(plugin->hDC, plugin->hRC);
|
||||
|
||||
|
||||
struct {
|
||||
float tu, tv;
|
||||
float x, y, z;
|
||||
@@ -567,20 +544,20 @@ void RenderGL(ClientPlugin* plugin)
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
//glTranslatef(0.0f, 0.0f, -3.0f);
|
||||
// glTranslatef(0.0f, 0.0f, -3.0f);
|
||||
|
||||
// Draw the background gradient.
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
glBegin(GL_QUADS);
|
||||
glColor4f(1.0,0.0,0.0,1.0); // red
|
||||
glVertex2f(-1.0,-1.0);
|
||||
glVertex2f(1.0,-1.0);
|
||||
glColor4f(0.0,0.0,1.0,1.0); // blue
|
||||
glColor4f(1.0, 0.0, 0.0, 1.0); // red
|
||||
glVertex2f(-1.0, -1.0);
|
||||
glVertex2f(1.0, -1.0);
|
||||
glColor4f(0.0, 0.0, 1.0, 1.0); // blue
|
||||
glVertex2f(1.0, 1.0);
|
||||
glVertex2f(-1.0, 1.0);
|
||||
glEnd();
|
||||
glPopAttrib();
|
||||
|
||||
|
||||
// Rotate the view based on the mouse spin.
|
||||
glRotatef(-g_spinX, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(-g_spinY, 0.0f, 1.0f, 0.0f);
|
||||
@@ -615,17 +592,17 @@ NPError NPP_NewImpl(NPMIMEType plugin_type, NPP instance, uint16 mode,
|
||||
if (instance == NULL)
|
||||
return NPERR_INVALID_INSTANCE_ERROR;
|
||||
|
||||
ClientPlugin *plugin = new ClientPlugin;
|
||||
ClientPlugin* plugin = new ClientPlugin;
|
||||
instance->pdata = reinterpret_cast<void*>(plugin);
|
||||
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError NPP_DestroyImpl(NPP instance, NPSavedData** save) {
|
||||
ClientPlugin *plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
|
||||
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
|
||||
if (plugin) {
|
||||
if(plugin->hWnd) {
|
||||
if (plugin->hWnd) {
|
||||
DestroyWindow(plugin->hWnd);
|
||||
DisableGL(plugin->hWnd, plugin->hDC, plugin->hRC);
|
||||
}
|
||||
@@ -642,14 +619,13 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
||||
if (window_info == NULL)
|
||||
return NPERR_GENERIC_ERROR;
|
||||
|
||||
ClientPlugin *plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
HWND parent_hwnd = reinterpret_cast<HWND>(window_info->window);
|
||||
|
||||
if (plugin->hWnd == NULL)
|
||||
{
|
||||
|
||||
if (plugin->hWnd == NULL) {
|
||||
WNDCLASS wc;
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
|
||||
|
||||
// Register the window class.
|
||||
wc.style = CS_OWNDC;
|
||||
wc.lpfnWndProc = PluginWndProc;
|
||||
@@ -662,7 +638,7 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = L"ClientOSRPlugin";
|
||||
RegisterClass(&wc);
|
||||
|
||||
|
||||
// Create the main window.
|
||||
plugin->hWnd = CreateWindow(L"ClientOSRPlugin", L"Client OSR Plugin",
|
||||
WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, 0, 0, 0, 0, parent_hwnd, NULL,
|
||||
@@ -670,7 +646,7 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
||||
|
||||
SetWindowLongPtr(plugin->hWnd, GWLP_USERDATA,
|
||||
reinterpret_cast<LONG_PTR>(plugin));
|
||||
|
||||
|
||||
// Enable GL drawing for the window.
|
||||
EnableGL(plugin->hWnd, &(plugin->hDC), &(plugin->hRC));
|
||||
|
||||
@@ -699,22 +675,20 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
||||
|
||||
// Plugin window procedure.
|
||||
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
LPARAM lParam) {
|
||||
static POINT lastMousePos, curMousePos;
|
||||
static bool mouseRotation = false;
|
||||
static bool mouseTracking = false;
|
||||
|
||||
ClientPlugin* plugin =
|
||||
reinterpret_cast<ClientPlugin*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
|
||||
|
||||
switch(message)
|
||||
{
|
||||
|
||||
switch (message) {
|
||||
case WM_CREATE:
|
||||
// Start the timer that's used for redrawing.
|
||||
SetTimer(hWnd, 1, 20, NULL);
|
||||
return 0;
|
||||
|
||||
|
||||
case WM_DESTROY:
|
||||
// Stop the timer that's used for redrawing.
|
||||
KillTimer(hWnd, 1);
|
||||
@@ -724,10 +698,10 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
g_offscreenBrowser = NULL;
|
||||
return 0;
|
||||
|
||||
case WM_TIMER:
|
||||
case WM_TIMER:
|
||||
RenderGL(plugin);
|
||||
break;
|
||||
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_RBUTTONDOWN:
|
||||
SetCapture(hWnd);
|
||||
@@ -740,7 +714,7 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
} else {
|
||||
if (g_offscreenBrowser.get()) {
|
||||
g_offscreenBrowser->SendMouseClickEvent(LOWORD(lParam), HIWORD(lParam),
|
||||
(message==WM_LBUTTONDOWN?MBT_LEFT:MBT_RIGHT), false, 1);
|
||||
(message == WM_LBUTTONDOWN?MBT_LEFT:MBT_RIGHT), false, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -757,13 +731,13 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
} else {
|
||||
if (g_offscreenBrowser.get()) {
|
||||
g_offscreenBrowser->SendMouseClickEvent(LOWORD(lParam), HIWORD(lParam),
|
||||
(message==WM_LBUTTONUP?MBT_LEFT:MBT_RIGHT), true, 1);
|
||||
(message == WM_LBUTTONUP?MBT_LEFT:MBT_RIGHT), true, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
if(mouseRotation) {
|
||||
if (mouseRotation) {
|
||||
// Apply rotation effect.
|
||||
curMousePos.x = LOWORD(lParam);
|
||||
curMousePos.y = HIWORD(lParam);
|
||||
@@ -809,23 +783,24 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
GET_WHEEL_DELTA_WPARAM(wParam));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case WM_SIZE: {
|
||||
int width = LOWORD(lParam);
|
||||
int width = LOWORD(lParam);
|
||||
int height = HIWORD(lParam);
|
||||
if(width > 0 && height > 0)
|
||||
if (width > 0 && height > 0)
|
||||
SizeGL(plugin, width, height);
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_SETFOCUS:
|
||||
case WM_KILLFOCUS:
|
||||
if (g_offscreenBrowser.get())
|
||||
g_offscreenBrowser->SendFocusEvent(message==WM_SETFOCUS);
|
||||
g_offscreenBrowser->SendFocusEvent(message == WM_SETFOCUS);
|
||||
break;
|
||||
|
||||
case WM_CAPTURECHANGED:
|
||||
case WM_CANCELMODE:
|
||||
if(!mouseRotation) {
|
||||
if (!mouseRotation) {
|
||||
if (g_offscreenBrowser.get())
|
||||
g_offscreenBrowser->SendCaptureLostEvent();
|
||||
}
|
||||
@@ -846,7 +821,7 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
type = KT_KEYDOWN;
|
||||
else if (message == WM_KEYUP || message == WM_SYSKEYUP)
|
||||
type = KT_KEYUP;
|
||||
|
||||
|
||||
if (message == WM_SYSKEYDOWN || message == WM_SYSKEYUP ||
|
||||
message == WM_SYSCHAR)
|
||||
sysChar = true;
|
||||
@@ -862,7 +837,8 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
PAINTSTRUCT ps;
|
||||
BeginPaint(hWnd, &ps);
|
||||
EndPaint(hWnd, &ps);
|
||||
} return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
return 0;
|
||||
@@ -871,36 +847,31 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
NPError API_CALL NP_OSRGetEntryPoints(NPPluginFuncs* pFuncs)
|
||||
{
|
||||
NPError API_CALL NP_OSRGetEntryPoints(NPPluginFuncs* pFuncs) {
|
||||
pFuncs->newp = NPP_NewImpl;
|
||||
pFuncs->destroy = NPP_DestroyImpl;
|
||||
pFuncs->setwindow = NPP_SetWindowImpl;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_OSRInitialize(NPNetscapeFuncs* pFuncs)
|
||||
{
|
||||
NPError API_CALL NP_OSRInitialize(NPNetscapeFuncs* pFuncs) {
|
||||
g_osrbrowser = pFuncs;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_OSRShutdown(void)
|
||||
{
|
||||
NPError API_CALL NP_OSRShutdown(void) {
|
||||
g_osrbrowser = NULL;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> GetOffScreenBrowser()
|
||||
{
|
||||
CefRefPtr<CefBrowser> GetOffScreenBrowser() {
|
||||
return g_offscreenBrowser;
|
||||
}
|
||||
|
||||
void SetOffScreenTransparent(bool transparent)
|
||||
{
|
||||
void SetOffScreenTransparent(bool transparent) {
|
||||
g_offscreenTransparent = transparent;
|
||||
}
|
||||
|
||||
#endif // OS_WIN
|
||||
#endif // OS_WIN
|
||||
|
Reference in New Issue
Block a user