Permalink
Browse files

Updated to new version of Berkelium

- better rendering using two callbacks
- added delegate for external host callbacks
  • Loading branch information...
1 parent 7faf3f1 commit 4a72b124edbf1354be5e54cfb9c08ec5a7c5b486 Jeroen Dierckx committed Sep 1, 2010
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
@@ -33,6 +33,7 @@
#ifndef _BERKELIUM_HPP_
#define _BERKELIUM_HPP_
#include "berkelium/Platform.hpp"
+#include "berkelium/WeakString.hpp"
namespace sandbox {
class BrokerServices;
class TargetServices;
@@ -42,12 +43,22 @@ enum DepEnforcement;
}
namespace Berkelium {
+/** May be implemented to handle global errors gracefully.
+ */
+class BERKELIUM_EXPORT ErrorDelegate {
+public:
+ virtual ~ErrorDelegate() {}
+};
+
/* TODO: Allow forkedProcessHook to be called without requiring the
library to be initialized/in memory (unless this is a sub-process).
i.e. an inline function that first searches for "--type=" in argv,
then uses dlopen or GetProcAddress.
*/
+/** Called by child processes.
+ * Should only ever be called from subprocess.cpp (berkelium.exe).
+ */
#ifdef _WIN32
void BERKELIUM_EXPORT forkedProcessHook(
sandbox::BrokerServices* (*ptrGetBrokerServices)(),
@@ -57,12 +68,29 @@ void BERKELIUM_EXPORT forkedProcessHook(
void BERKELIUM_EXPORT forkedProcessHook(int argc, char **argv);
#endif
-void BERKELIUM_EXPORT init();
+/** Iniitialize berkelium's global object.
+ * \param homeDirectory Just like Chrome's --user-data-dir command line flag.
+ * If homeDirectory is null or empty, creates a temporary data directory.
+ */
+void BERKELIUM_EXPORT init(FileString homeDirectory);
+
+/** Destroys Berkelium and attempts to free as much memory as possible.
+ * Note: You must destroy all Window and Context objects before calling
+ * Berkelium::destroy()!
+ */
void BERKELIUM_EXPORT destroy();
-void BERKELIUM_EXPORT update();
+void BERKELIUM_EXPORT setErrorHandler(ErrorDelegate * errorHandler);
-int BERKELIUM_EXPORT renderToBuffer(char *buffer, int width, int height);
+/** Runs the message loop until all pending messages are processed.
+ * Must be called from the same thread as all other Berkelium functions,
+ * usually your program's main (UI) thread.
+ * For now, you have to poll to receive updates without blocking indefinitely.
+ *
+ * Your WindowDelegate's should only receive callbacks synchronously with
+ * this call to update.
+ */
+void BERKELIUM_EXPORT update();
}
@@ -39,16 +39,39 @@ class BrowsingInstance;
namespace Berkelium {
class ContextImpl;
+/** A context holds onto a reference counted profile object.
+ * The Window class calls clone() on a context, so you can safely
+ * destroy a Context after making all the Windows you want.
+ *
+ * No functions currently exist for this object.
+ */
class BERKELIUM_EXPORT Context {
protected:
Context();
public:
+ /** Creates an all-new context with no shared state and a refcount of 1.
+ */
+ static Context* create();
+
+ /** Deletes this Context object, which decrements the refcount for the
+ * underlying context data.
+ */
+ void destroy();
+ /** Deprecated destructor
+ * \deprecated destroy()
+ */
virtual ~Context();
- virtual Context* clone()const=0;
- virtual ContextImpl *getImpl()=0;
- virtual const ContextImpl *getImpl()const=0;
+
+ /** Returns a new Context object which increments the refcount of
+ * the internal context information. Called by Window::create.
+ */
+ virtual Context* clone() const = 0;
+
+
+ virtual ContextImpl* getImpl() = 0;
+ virtual const ContextImpl* getImpl() const = 0;
};
}
@@ -36,6 +36,7 @@
#include "berkelium/Platform.hpp"
#if BERKELIUM_PLATFORM == PLATFORM_WINDOWS
+#include <windows.h>
#elif BERKELIUM_PLATFORM == PLATFORM_LINUX
// FIXME this really only works for toolkit == gtk
// We use alternate definitions since we can't properly forward
@@ -64,6 +65,7 @@ class WindowImpl;
class BERKELIUM_EXPORT Cursor {
public:
#if BERKELIUM_PLATFORM == PLATFORM_WINDOWS
+ HCURSOR GetCursor() const;
#elif BERKELIUM_PLATFORM == PLATFORM_LINUX
GdkCursorEnum GetCursorType() const;
GdkCursorPtr GetCustomCursor() const;
@@ -77,6 +79,9 @@ class BERKELIUM_EXPORT Cursor {
Cursor(); // Non-copyable
#if BERKELIUM_PLATFORM == PLATFORM_WINDOWS
+ Cursor(const HCURSOR handle);
+
+ HCURSOR mHandle;
#elif BERKELIUM_PLATFORM == PLATFORM_LINUX
Cursor(const GdkCursorEnum& _type, GdkCursorPtr _cursor);
@@ -36,19 +36,29 @@
namespace Berkelium {
struct Rect {
- int mTop;
int mLeft;
+ int mTop;
int mWidth;
int mHeight;
- int top() const { return mTop; }
- int left() const { return mLeft; }
- int width() const { return mWidth; }
- int height() const { return mHeight; }
- int right() const { return mLeft + mWidth; }
- int bottom() const { return mTop + mHeight; }
+ inline int y() const { return mTop; }
+ inline int x() const { return mLeft; }
+ inline int top() const { return mTop; }
+ inline int left() const { return mLeft; }
+ inline int width() const { return mWidth; }
+ inline int height() const { return mHeight; }
+ inline int right() const { return mLeft + mWidth; }
+ inline int bottom() const { return mTop + mHeight; }
+
+ template <class T>
+ inline void setFromRect(const T&sourceRect) {
+ mLeft = sourceRect.x();
+ mTop = sourceRect.y();
+ mWidth = sourceRect.width();
+ mHeight = sourceRect.height();
+ }
- bool contains(int x, int y) const {
+ inline bool contains(int x, int y) const {
return (x >= left() && x < right() &&
y >= top() && y < bottom());
}
@@ -38,10 +38,9 @@ namespace Berkelium {
template <class T> class AutoSingleton {
static std::auto_ptr<T>sInstance;
public:
- static T&getSingleton() {
+ static T& getSingleton() {
if (sInstance.get()==NULL) {
- std::auto_ptr<T> tmp(new T);
- sInstance = tmp;
+ throw std::exception();
}
return *static_cast<T*>(sInstance.get());
}
@@ -0,0 +1,134 @@
+/* Berkelium - Embedded Chromium
+ * SafeString.hpp
+ *
+ * Copyright (c) 2009, Patrick Reiter Horn
+ * 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 Sirikata 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 _BERKELIUM_WEAK_STRING_HPP_
+#define _BERKELIUM_WEAK_STRING_HPP_
+
+#include "berkelium/Platform.hpp"
+
+namespace Berkelium {
+
+// Simple POD string class. Data must be owned by caller.
+template <class CharType>
+struct WeakString {
+ const CharType* mData;
+ size_t mLength;
+
+ typedef CharType Type;
+
+ inline const CharType* data() const {
+ return mData;
+ }
+
+ inline size_t length() const {
+ return mLength;
+ }
+
+ inline size_t size() const {
+ return mLength;
+ }
+
+ template <class StrType>
+ inline StrType& get(StrType& ret) const {
+ if (!mData || !mLength) {
+ ret = StrType();
+ }
+ ret = StrType(mData, mLength);
+ return ret;
+ }
+
+ template <class StrType>
+ inline StrType get() const {
+ if (!mData || !mLength) {
+ return StrType();
+ }
+ return StrType(mData, mLength);
+ }
+
+ template <class StrType>
+ inline static WeakString<CharType> point_to(const StrType&input) {
+ WeakString<CharType> ret;
+ ret.mData = input.data();
+ ret.mLength = input.length();
+ return ret;
+ }
+
+ inline static WeakString<CharType> point_to(const CharType*input_data,
+ size_t input_length) {
+ WeakString<CharType> ret;
+ ret.mData = input_data;
+ ret.mLength = input_length;
+ return ret;
+ }
+
+ inline static WeakString<CharType> empty() {
+ WeakString<CharType> ret;
+ ret.mData = NULL;
+ ret.mLength = 0;
+ return ret;
+ }
+};
+
+template <class StrType, class CharType>
+inline StrType &operator+(const StrType&lhs, WeakString<CharType>&rhs) {
+ StrType temp;
+ return lhs + rhs.get(temp);
+}
+
+template <class StrType, class CharType>
+inline StrType &operator+=(StrType&lhs, WeakString<CharType>&rhs) {
+ StrType temp;
+ return lhs += rhs.get(temp);
+}
+
+template <class OstreamType, class CharType>
+inline OstreamType &operator<< (OstreamType&lhs, WeakString<CharType>&rhs) {
+ size_t length = rhs.length();
+ const CharType *data = rhs.data();
+ for (size_t i = 0; i < length; i++) {
+ lhs << data[i];
+ }
+ return lhs;
+}
+
+typedef WeakString<char> URLString;
+typedef WeakString<wchar_t> WideString;
+
+#if BERKELIUM_PLATFORM == PLATFORM_WINDOWS
+typedef WeakString<wchar_t> FileString;
+#else
+typedef WeakString<char> FileString;
+#endif
+
+}
+
+#endif
@@ -37,12 +37,30 @@
namespace Berkelium {
+/** A widget is a rectangular canvas which can be painted to. A Widget
+ * maintains its own focus state, and can accept input just like a Window.
+ * Widgets have very limited use in practice--mostly just dropdowns.
+ */
class BERKELIUM_EXPORT Widget {
public:
+ /** Deprecated virtual destructor.
+ * \deprecated Use the safer destroy() method instead.
+ */
virtual ~Widget() {}
+ /** Safe destructor for widget. Should clean up all resources.
+ * Note: WindowDelegate::onWidgetDestroyed will be called synchronously.
+ */
+ void destroy(); // defined in src/RenderWidget.cpp
+
+ /** Gets a unique id for this widget.
+ * \returns the widget's routing id
+ */
+ virtual int getId() const = 0;
+
virtual void focus()=0;
virtual void unfocus()=0;
+ virtual bool hasFocus() const = 0;
virtual void mouseMoved(int xPos, int yPos)=0;
virtual void mouseButton(unsigned int buttonID, bool down)=0;
Oops, something went wrong.

0 comments on commit 4a72b12

Please sign in to comment.