Initial header for Mac and Linux support.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@113 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2010-10-09 18:23:06 +00:00
parent ea442f1c6b
commit 7898b6bf4f
11 changed files with 587 additions and 17 deletions

26
cef.gyp
View File

@ -412,9 +412,7 @@
'libcef/tracker.h',
'libcef/v8_impl.cc',
'libcef/v8_impl.h',
'libcef/webview_host.cc',
'libcef/webview_host.h',
'libcef/webwidget_host.cc',
'libcef/webwidget_host.h',
],
'conditions': [
@ -435,8 +433,30 @@
'libcef/printing/print_settings.h',
'libcef/printing/win_printing_context.cc',
'libcef/printing/win_printing_context.h',
'libcef/webview_host_win.cc',
'libcef/webwidget_host_win.cc',
],
}]
}],
[ 'OS=="mac"', {
'sources': [
'include/cef_types_mac.h',
'include/cef_mac.h',
'libcef/browser_webkit_glue_mac.mm',
'libcef/browser_webview_delegate_mac.mm',
'libcef/webview_host_mac.mm',
'libcef/webwidget_host_mac.mm',
],
}],
[ 'OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
'sources': [
'include/cef_types_linux.h',
'include/cef_linux.h',
'libcef/browser_webkit_glue_gtk.cc',
'libcef/browser_webview_delegate_gtk.cc',
'libcef/webview_host_gtk.cc',
'libcef/webwidget_host_gtk.cc',
],
}],
],
},
]

View File

@ -200,8 +200,12 @@ public:
// Bring in platform-specific definitions.
#ifdef _WIN32
#if defined(_WIN32)
#include "cef_win.h"
#elif defined(__APPLE__)
#include "cef_mac.h"
#elif defined(__linux__)
#include "cef_linux.h"
#endif

184
include/cef_linux.h Normal file
View File

@ -0,0 +1,184 @@
// Copyright (c) 2010 Marshall A. Greenblatt. 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 Google Inc. nor the name Chromium Embedded
// Framework 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.
#ifndef _CEF_LINUX_H
#define _CEF_LINUX_H
#if defined(__linux__)
#include <pthread.h>
#include "cef_types_linux.h"
// Atomic increment and decrement.
inline long CefAtomicIncrement(long volatile *pDest)
{
return __sync_add_and_fetch(pDest, 1);
}
inline long CefAtomicDecrement(long volatile *pDest)
{
return __sync_sub_and_fetch(pDest, 1);
}
// Critical section wrapper.
class CefCriticalSection
{
public:
CefCriticalSection()
{
pthread_mutexattr_init(&attr_);
pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&lock_, &attr_);
}
~CefCriticalSection()
{
pthread_mutex_destroy(&lock_);
pthread_mutexattr_destroy(&attr_);
}
void Lock()
{
pthread_mutex_lock(&lock_);
}
void Unlock()
{
pthread_mutex_unlock(&lock_);
}
pthread_mutex_t lock_;
pthread_mutexattr_t attr_;
};
// Class representing window information.
class CefWindowInfo : public cef_window_info_t
{
public:
CefWindowInfo()
{
Init();
}
~CefWindowInfo()
{
if(m_windowName)
cef_string_free(m_windowName);
}
CefWindowInfo(const CefWindowInfo& r)
{
Init();
*this = r;
}
CefWindowInfo(const cef_window_info_t& r)
{
Init();
*this = r;
}
void Init()
{
m_windowName = NULL;
m_x = 0;
m_y = 0;
m_nWidth = 0;
m_nHeight = 0;
}
CefWindowInfo& operator=(const CefWindowInfo& r)
{
return operator=(static_cast<const cef_window_info_t&>(r));
}
CefWindowInfo& operator=(const cef_window_info_t& r)
{
m_dwExStyle = r.m_dwExStyle;
if(m_windowName)
cef_string_free(m_windowName);
if(r.m_windowName)
m_windowName = cef_string_alloc(r.m_windowName);
else
m_windowName = NULL;
m_dwStyle = r.m_dwStyle;
m_x = r.m_x;
m_y = r.m_y;
m_nWidth = r.m_nWidth;
m_nHeight = r.m_nHeight;
return *this;
}
void SetAsChild(HWND hWndParent, RECT windowRect)
{
m_x = windowRect.left;
m_y = windowRect.top;
m_nWidth = windowRect.right - windowRect.left;
m_nHeight = windowRect.bottom - windowRect.top;
}
};
// Class representing print context information.
class CefPrintInfo : public cef_print_info_t
{
public:
CefPrintInfo()
{
Init();
}
~CefPrintInfo()
{
}
CefPrintInfo(const CefPrintInfo& r)
{
Init();
*this = r;
}
CefPrintInfo(const cef_print_info_t& r)
{
Init();
*this = r;
}
void Init()
{
m_hDC = NULL;
m_Scale = 0;
}
CefPrintInfo& operator=(const CefPrintInfo& r)
{
return operator=(static_cast<const cef_print_info_t&>(r));
}
CefPrintInfo& operator=(const cef_print_info_t& r)
{
m_Scale = r.m_Scale;
return *this;
}
};
// Window handle.
#define CefWindowHandle cef_window_handle_t
#endif // defined(__linux__)
#endif // _CEF_LINUX_H

184
include/cef_mac.h Normal file
View File

@ -0,0 +1,184 @@
// Copyright (c) 2010 Marshall A. Greenblatt. 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 Google Inc. nor the name Chromium Embedded
// Framework 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.
#ifndef _CEF_MAC_H
#define _CEF_MAC_H
#if defined(__APPLE__)
#include <pthread.h>
#include "cef_types_mac.h"
// Atomic increment and decrement.
inline long CefAtomicIncrement(long volatile *pDest)
{
return __sync_add_and_fetch(pDest, 1);
}
inline long CefAtomicDecrement(long volatile *pDest)
{
return __sync_sub_and_fetch(pDest, 1);
}
// Critical section wrapper.
class CefCriticalSection
{
public:
CefCriticalSection()
{
pthread_mutexattr_init(&attr_);
pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&lock_, &attr_);
}
~CefCriticalSection()
{
pthread_mutex_destroy(&lock_);
pthread_mutexattr_destroy(&attr_);
}
void Lock()
{
pthread_mutex_lock(&lock_);
}
void Unlock()
{
pthread_mutex_unlock(&lock_);
}
pthread_mutex_t lock_;
pthread_mutexattr_t attr_;
};
// Class representing window information.
class CefWindowInfo : public cef_window_info_t
{
public:
CefWindowInfo()
{
Init();
}
~CefWindowInfo()
{
if(m_windowName)
cef_string_free(m_windowName);
}
CefWindowInfo(const CefWindowInfo& r)
{
Init();
*this = r;
}
CefWindowInfo(const cef_window_info_t& r)
{
Init();
*this = r;
}
void Init()
{
m_windowName = NULL;
m_x = 0;
m_y = 0;
m_nWidth = 0;
m_nHeight = 0;
}
CefWindowInfo& operator=(const CefWindowInfo& r)
{
return operator=(static_cast<const cef_window_info_t&>(r));
}
CefWindowInfo& operator=(const cef_window_info_t& r)
{
m_dwExStyle = r.m_dwExStyle;
if(m_windowName)
cef_string_free(m_windowName);
if(r.m_windowName)
m_windowName = cef_string_alloc(r.m_windowName);
else
m_windowName = NULL;
m_dwStyle = r.m_dwStyle;
m_x = r.m_x;
m_y = r.m_y;
m_nWidth = r.m_nWidth;
m_nHeight = r.m_nHeight;
return *this;
}
void SetAsChild(HWND hWndParent, RECT windowRect)
{
m_x = windowRect.left;
m_y = windowRect.top;
m_nWidth = windowRect.right - windowRect.left;
m_nHeight = windowRect.bottom - windowRect.top;
}
};
// Class representing print context information.
class CefPrintInfo : public cef_print_info_t
{
public:
CefPrintInfo()
{
Init();
}
~CefPrintInfo()
{
}
CefPrintInfo(const CefPrintInfo& r)
{
Init();
*this = r;
}
CefPrintInfo(const cef_print_info_t& r)
{
Init();
*this = r;
}
void Init()
{
m_hDC = NULL;
m_Scale = 0;
}
CefPrintInfo& operator=(const CefPrintInfo& r)
{
return operator=(static_cast<const cef_print_info_t&>(r));
}
CefPrintInfo& operator=(const cef_print_info_t& r)
{
m_Scale = r.m_Scale;
return *this;
}
};
// Window handle.
#define CefWindowHandle cef_window_handle_t
#endif // defined(__APPLE__)
#endif // _CEF_MAC_H

View File

@ -1,4 +1,4 @@
// Copyright (c) 2009 Marshall A. Greenblatt. All rights reserved.
// Copyright (c) 2010 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@ -37,8 +37,12 @@ extern "C" {
// Bring in platform-specific definitions.
#ifdef _WIN32
#if defined(_WIN32)
#include "cef_types_win.h"
#elif defined(__APPLE__)
#include "cef_types_mac.h"
#elif defined(__linux__)
#include "cef_types_linux.h"
#endif

66
include/cef_types_linux.h Normal file
View File

@ -0,0 +1,66 @@
// Copyright (c) 2010 Marshall A. Greenblatt. 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 Google Inc. nor the name Chromium Embedded
// Framework 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.
#ifndef _CEF_TYPES_LINUX_H
#define _CEF_TYPES_LINUX_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__linux__)
#include "cef_string.h"
// Class representing window information.
typedef struct _cef_window_info_t
{
// Standard parameters required by CreateWindowEx()
cef_string_t m_windowName;
int m_x;
int m_y;
int m_nWidth;
int m_nHeight;
} cef_window_info_t;
// Class representing print context information.
typedef struct _cef_print_info_t
{
double m_Scale;
} cef_print_info_t;
// Window handle.
#define cef_window_handle_t void*
#endif // defined(__linux__)
#ifdef __cplusplus
}
#endif
#endif // _CEF_TYPES_LINUX_H

66
include/cef_types_mac.h Normal file
View File

@ -0,0 +1,66 @@
// Copyright (c) 2010 Marshall A. Greenblatt. 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 Google Inc. nor the name Chromium Embedded
// Framework 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.
#ifndef _CEF_TYPES_MAC_H
#define _CEF_TYPES_MAC_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__APPLE__)
#include "cef_string.h"
// Class representing window information.
typedef struct _cef_window_info_t
{
// Standard parameters required by CreateWindowEx()
cef_string_t m_windowName;
int m_x;
int m_y;
int m_nWidth;
int m_nHeight;
} cef_window_info_t;
// Class representing print context information.
typedef struct _cef_print_info_t
{
double m_Scale;
} cef_print_info_t;
// Window handle.
#define cef_window_handle_t void*
#endif // defined(__APPLE__)
#ifdef __cplusplus
}
#endif
#endif // _CEF_TYPES_MAC_H

View File

@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@ -10,6 +10,10 @@
#include "gfx/native_widget_types.h"
#include "webwidget_host.h"
#if defined(TOOLKIT_USES_GTK)
#include "webkit/glue/plugins/gtk_plugin_container_manager.h"
#endif
struct WebPreferences;
class BrowserWebViewDelegate;
@ -18,25 +22,44 @@ class WebDevToolsAgentClient;
class WebView;
}
// This class is a simple ViewHandle-based host for a WebView
// This class is a simple NativeView-based host for a WebView
class WebViewHost : public WebWidgetHost {
public:
// The new instance is deleted once the associated ViewHandle is destroyed.
// The new instance is deleted once the associated NativeView is destroyed.
// The newly created window should be resized after it is created, using the
// MoveWindow (or equivalent) function.
static WebViewHost* Create(gfx::NativeView parent_window,
static WebViewHost* Create(gfx::NativeView parent_view,
BrowserWebViewDelegate* delegate,
WebKit::WebDevToolsAgentClient* devtools_client,
const WebPreferences& prefs);
WebKit::WebView* webview() const;
#if defined(TOOLKIT_USES_GTK)
// Create a new plugin parent container for a given plugin XID.
void CreatePluginContainer(gfx::PluginWindowHandle id);
// Destroy the plugin parent container when a plugin has been destroyed.
void DestroyPluginContainer(gfx::PluginWindowHandle id);
GtkPluginContainerManager* plugin_container_manager() {
return &plugin_container_manager_;
}
#elif defined(OS_MACOSX)
void SetIsActive(bool active);
#endif
protected:
#if defined(OS_WIN)
virtual bool WndProc(UINT message, WPARAM wparam, LPARAM lparam) {
return false;
}
#endif
#if defined(TOOLKIT_USES_GTK)
// Helper class that creates and moves plugin containers.
GtkPluginContainerManager plugin_container_manager_;
#endif
};
#endif // _WEBVIEW_HOST_H

View File

@ -6,9 +6,9 @@
#define _WEBWIDGET_HOST_H
#include "base/basictypes.h"
#include "gfx/rect.h"
#include "base/scoped_ptr.h"
#include "gfx/native_widget_types.h"
#include "gfx/rect.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h"
@ -23,17 +23,25 @@ class WebKeyboardEvent;
struct WebScreenInfo;
}
// This class is a simple ViewHandle-based host for a WebWidget
#if defined(OS_MACOSX)
#ifdef __OBJC__
@class NSEvent;
#else
class NSEvent;
#endif
#endif
// This class is a simple NativeView-based host for a WebWidget
class WebWidgetHost {
public:
// The new instance is deleted once the associated ViewHandle is destroyed.
// The new instance is deleted once the associated NativeView is destroyed.
// The newly created window should be resized after it is created, using the
// MoveWindow (or equivalent) function.
static WebWidgetHost* Create(gfx::NativeView parent_view,
WebKit::WebWidgetClient* client);
#if defined(OS_MACOSX)
static void HandleEvent(gfx::NativeView view, NSEvent *event);
static void HandleEvent(gfx::NativeView view, NSEvent* event);
#endif
gfx::NativeView view_handle() const { return view_; }
@ -88,7 +96,7 @@ class WebWidgetHost {
void KeyEvent(NSEvent *);
void SetFocus(bool enable);
protected:
#elif defined(OS_LINUX)
#elif defined(TOOLKIT_USES_GTK)
public:
// ---------------------------------------------------------------------------
// This is needed on Linux because the GtkWidget creation is the same between
@ -99,14 +107,18 @@ class WebWidgetHost {
// parent: a GtkBox to pack the new widget at the end of
// host: a pointer to a WebWidgetHost (or subclass thereof)
// ---------------------------------------------------------------------------
static gfx::NativeView CreateWindow(gfx::NativeView parent_view,
static gfx::NativeView CreateWidget(gfx::NativeView parent_view,
WebWidgetHost* host);
void WindowDestroyed();
void Resize(const gfx::Size& size);
#endif
#if defined(OS_WIN)
void TrackMouseLeave(bool enable);
#endif
void ResetScrollRect();
void set_painting(bool value) {
#ifndef NDEBUG
painting_ = value;
@ -128,10 +140,17 @@ class WebWidgetHost {
int scroll_dx_;
int scroll_dy_;
#if defined(OS_WIN)
bool track_mouse_leave_;
#endif
#if defined(TOOLKIT_USES_GTK)
// Since GtkWindow resize is asynchronous, we have to stash the dimensions,
// so that the backing store doesn't have to wait for sizing to take place.
gfx::Size logical_size_;
#endif
WebKit::WebKeyboardEvent last_key_event_;
gfx::NativeView tooltip_view_;
std::wstring tooltip_text_;
bool tooltip_showing_;