├── Awesomium.sln ├── Awesomium.xcodeproj ├── ajs.mode1v3 ├── ajs.pbxuser └── project.pbxproj ├── Awesomium ├── Awesomium.rc ├── Awesomium.vcproj ├── Doxyfile ├── include │ ├── ClientObject.h │ ├── JSValue.h │ ├── PlatformUtils.h │ ├── PopupWidget.h │ ├── RenderBuffer.h │ ├── RequestContext.h │ ├── ResourceLoaderBridge.h │ ├── WebCore.h │ ├── WebCoreProxy.h │ ├── WebView.h │ ├── WebViewEvent.h │ ├── WebViewListener.h │ └── WebViewProxy.h ├── resource.h └── src │ ├── ClientObject.cpp │ ├── InitMacApplication.mm │ ├── JSValue.cpp │ ├── Makefile │ ├── NavigationController.h │ ├── PlatformUtils.cpp │ ├── PopupWidget.cpp │ ├── RenderBuffer.cpp │ ├── RequestContext.cpp │ ├── ResourceLoaderBridge.cpp │ ├── WebCore.cpp │ ├── WebCoreProxy.cpp │ ├── WebView.cpp │ ├── WebViewEvent.cpp │ ├── WebViewProxy.cpp │ ├── WebkitGlue.cpp │ └── WindowlessPlugin.h ├── Awesomium_Prefix.pch ├── English.lproj └── InfoPlist.strings ├── Info.plist ├── LICENSE.txt ├── app ├── Application.h ├── InputManager.cpp ├── InputManager.h ├── KeyboardHook.cpp ├── KeyboardHook.h ├── TerrainCamera.cpp ├── TerrainCamera.h ├── app.vcproj └── main.cpp ├── debug ├── Plugins.cfg ├── resources.cfg └── testing │ ├── excanvas.pack.js │ ├── jquery.flot.pack.js │ ├── jquery.js │ └── testResults.html ├── release ├── Plugins.cfg ├── resources.cfg └── testing │ ├── excanvas.pack.js │ ├── jquery.flot.pack.js │ ├── jquery.js │ └── testResults.html └── unitTest ├── TestFramework.h ├── Test_EvalJavascript.h ├── Test_RenderAsync.h ├── Test_RenderSync.h ├── Timer.h ├── main.cpp └── unitTest.vcproj /Awesomium.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual Studio 2005 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Awesomium", "Awesomium\Awesomium.vcproj", "{3B9598C3-7BC7-47D3-B5D7-7E3DA9018C4C}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "app", "app\app.vcproj", "{8B0CC956-BBDF-4703-A29D-43740B6914ED}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {3B9598C3-7BC7-47D3-B5D7-7E3DA9018C4C} = {3B9598C3-7BC7-47D3-B5D7-7E3DA9018C4C} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unitTest", "unitTest\unitTest.vcproj", "{BBFA1D07-3A8D-49A1-806F-675C8C98B740}" 12 | ProjectSection(ProjectDependencies) = postProject 13 | {3B9598C3-7BC7-47D3-B5D7-7E3DA9018C4C} = {3B9598C3-7BC7-47D3-B5D7-7E3DA9018C4C} 14 | EndProjectSection 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Win32 = Debug|Win32 19 | Release|Win32 = Release|Win32 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {3B9598C3-7BC7-47D3-B5D7-7E3DA9018C4C}.Debug|Win32.ActiveCfg = Debug|Win32 23 | {3B9598C3-7BC7-47D3-B5D7-7E3DA9018C4C}.Debug|Win32.Build.0 = Debug|Win32 24 | {3B9598C3-7BC7-47D3-B5D7-7E3DA9018C4C}.Release|Win32.ActiveCfg = Release|Win32 25 | {3B9598C3-7BC7-47D3-B5D7-7E3DA9018C4C}.Release|Win32.Build.0 = Release|Win32 26 | {8B0CC956-BBDF-4703-A29D-43740B6914ED}.Debug|Win32.ActiveCfg = Debug|Win32 27 | {8B0CC956-BBDF-4703-A29D-43740B6914ED}.Debug|Win32.Build.0 = Debug|Win32 28 | {8B0CC956-BBDF-4703-A29D-43740B6914ED}.Release|Win32.ActiveCfg = Release|Win32 29 | {8B0CC956-BBDF-4703-A29D-43740B6914ED}.Release|Win32.Build.0 = Release|Win32 30 | {BBFA1D07-3A8D-49A1-806F-675C8C98B740}.Debug|Win32.ActiveCfg = Debug|Win32 31 | {BBFA1D07-3A8D-49A1-806F-675C8C98B740}.Debug|Win32.Build.0 = Debug|Win32 32 | {BBFA1D07-3A8D-49A1-806F-675C8C98B740}.Release|Win32.ActiveCfg = Release|Win32 33 | {BBFA1D07-3A8D-49A1-806F-675C8C98B740}.Release|Win32.Build.0 = Release|Win32 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | EndGlobal 39 | -------------------------------------------------------------------------------- /Awesomium/Awesomium.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE 31 | BEGIN 32 | "resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE 36 | BEGIN 37 | "#include ""afxres.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Version 53 | // 54 | 55 | VS_VERSION_INFO VERSIONINFO 56 | FILEVERSION 0,0,2,19929 57 | PRODUCTVERSION 0,0,2,19929 58 | FILEFLAGSMASK 0x17L 59 | #ifdef _DEBUG 60 | FILEFLAGS 0x1L 61 | #else 62 | FILEFLAGS 0x0L 63 | #endif 64 | FILEOS 0x4L 65 | FILETYPE 0x2L 66 | FILESUBTYPE 0x0L 67 | BEGIN 68 | BLOCK "StringFileInfo" 69 | BEGIN 70 | BLOCK "040904b0" 71 | BEGIN 72 | VALUE "FileDescription", "Awesomium Dynamic Link Library" 73 | VALUE "FileVersion", "0, 0, 2, 19929" 74 | VALUE "InternalName", "Awesomium" 75 | VALUE "LegalCopyright", "Copyright (C) 2009 Adam J. Simmons and the Sirikata team" 76 | VALUE "OriginalFilename", "Awesomium.dll" 77 | VALUE "ProductName", "Awesomium Dynamic Link Library" 78 | VALUE "ProductVersion", "0, 0, 2, 19929" 79 | END 80 | END 81 | BLOCK "VarFileInfo" 82 | BEGIN 83 | VALUE "Translation", 0x409, 1200 84 | END 85 | END 86 | 87 | #endif // English (U.S.) resources 88 | ///////////////////////////////////////////////////////////////////////////// 89 | 90 | 91 | 92 | #ifndef APSTUDIO_INVOKED 93 | ///////////////////////////////////////////////////////////////////////////// 94 | // 95 | // Generated from the TEXTINCLUDE 3 resource. 96 | // 97 | 98 | 99 | ///////////////////////////////////////////////////////////////////////////// 100 | #endif // not APSTUDIO_INVOKED 101 | 102 | -------------------------------------------------------------------------------- /Awesomium/Awesomium.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 25 | 28 | 31 | 34 | 37 | 40 | 56 | 59 | 62 | 65 | 73 | 76 | 79 | 82 | 85 | 88 | 91 | 94 | 97 | 98 | 106 | 109 | 112 | 115 | 118 | 121 | 131 | 134 | 137 | 140 | 145 | 148 | 151 | 154 | 157 | 160 | 163 | 166 | 169 | 170 | 171 | 172 | 173 | 174 | 179 | 182 | 185 | 186 | 189 | 190 | 193 | 194 | 197 | 198 | 199 | 202 | 205 | 206 | 209 | 210 | 213 | 214 | 217 | 218 | 221 | 222 | 225 | 226 | 229 | 230 | 233 | 234 | 237 | 238 | 239 | 242 | 245 | 246 | 249 | 250 | 253 | 254 | 255 | 258 | 261 | 262 | 265 | 266 | 269 | 270 | 273 | 274 | 275 | 278 | 281 | 282 | 285 | 286 | 289 | 290 | 291 | 292 | 295 | 298 | 299 | 302 | 303 | 306 | 307 | 310 | 311 | 314 | 315 | 316 | 319 | 320 | 323 | 324 | 325 | 326 | 327 | 328 | -------------------------------------------------------------------------------- /Awesomium/include/ClientObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #ifndef __CLIENTOBJECT_H__ 27 | #define __CLIENTOBJECT_H__ 28 | 29 | #include "webkit/glue/cpp_bound_class.h" 30 | #include "JSValue.h" 31 | 32 | namespace Awesomium { class WebView; } 33 | class NamedCallback; 34 | class FutureValueCallback; 35 | class CheckKeyboardFocusCallback; 36 | 37 | class ClientObject : public CppBoundClass 38 | { 39 | public: 40 | ClientObject(Awesomium::WebView* view); 41 | ~ClientObject(); 42 | 43 | void initInternalCallbacks(); 44 | 45 | void setProperty(const std::string& name, const Awesomium::JSValue& value); 46 | 47 | void setCallback(const std::string& name); 48 | 49 | protected: 50 | 51 | std::map clientProperties; 52 | std::map clientCallbacks; 53 | FutureValueCallback* futureValueCallback; 54 | CheckKeyboardFocusCallback* checkKeyboardFocusCallback; 55 | Awesomium::WebView* view; 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Awesomium/include/JSValue.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #ifndef __JSVALUE_H__ 27 | #define __JSVALUE_H__ 28 | 29 | #include 30 | #include 31 | #include "PlatformUtils.h" 32 | 33 | namespace Impl { 34 | 35 | typedef enum { 36 | VariantType_NULL, 37 | VariantType_BOOLEAN, 38 | VariantType_INTEGER, 39 | VariantType_DOUBLE, 40 | VariantType_STRING 41 | } VariantType; 42 | 43 | struct VariantValue 44 | { 45 | VariantType type; 46 | 47 | std::string stringValue; 48 | 49 | union { 50 | bool booleanValue; 51 | int integerValue; 52 | double doubleValue; 53 | } numericValue; 54 | }; 55 | 56 | } 57 | 58 | namespace Awesomium 59 | { 60 | 61 | class WebView; 62 | 63 | /** 64 | * JSValue is a class that represents a Javascript value. It can be initialized from 65 | * and converted to several types: boolean, integer, double, string 66 | */ 67 | class _OSMExport JSValue 68 | { 69 | Impl::VariantValue varValue; 70 | public: 71 | /// Creates a null JSValue. 72 | JSValue(); 73 | 74 | /// Creates a JSValue initialized with a boolean. 75 | JSValue(bool value); 76 | 77 | /// Creates a JSValue initialized with an integer. 78 | JSValue(int value); 79 | 80 | /// Creates a JSValue initialized with a double. 81 | JSValue(double value); 82 | 83 | /// Creates a JSValue initialized with a string. 84 | JSValue(const char* value); 85 | 86 | /// Creates a JSValue initialized with a string. 87 | JSValue(const std::string& value); 88 | 89 | /// Returns whether or not this JSValue is a boolean. 90 | bool isBoolean() const; 91 | 92 | /// Returns whether or not this JSValue is an integer. 93 | bool isInteger() const; 94 | 95 | /// Returns whether or not this JSValue is a double. 96 | bool isDouble() const; 97 | 98 | /// Returns whether or not this JSValue is a number (integer or double). 99 | bool isNumber() const; 100 | 101 | /// Returns whether or not this JSValue is a string. 102 | bool isString() const; 103 | 104 | /// Returns whether or not this JSValue is null. 105 | bool isNull() const; 106 | 107 | /** 108 | * Returns this JSValue as a string (converting if necessary). 109 | * 110 | * @note If this JSValue is not a string, the returned reference 111 | * is only valid until the next call to JSValue::toString. 112 | */ 113 | const std::string& toString() const; 114 | 115 | /// Returns this JSValue as an integer (converting if necessary). 116 | int toInteger() const; 117 | 118 | /// Returns this JSValue as a double (converting if necessary). 119 | double toDouble() const; 120 | 121 | /// Returns this JSValue as a boolean (converting if necessary). 122 | bool toBoolean() const; 123 | }; 124 | 125 | typedef std::vector JSArguments; 126 | 127 | /** 128 | * FutureJSValue is a special wrapper around a JSValue that allows 129 | * asynchronous retrieval of the actual value at a later time. 130 | * 131 | * If you are unfamiliar with the concept of a 'Future', please see: 132 | * 133 | */ 134 | class _OSMExport FutureJSValue 135 | { 136 | public: 137 | FutureJSValue(); 138 | ~FutureJSValue(); 139 | 140 | /** 141 | * If the internal JSValue has been computed, immediately returns 142 | * the value, else, blocks the calling thread until it has. 143 | */ 144 | const JSValue& get(); 145 | 146 | protected: 147 | void init(WebView* source, int requestID); 148 | 149 | JSValue value; 150 | WebView* source; 151 | int requestID; 152 | 153 | friend class WebView; 154 | }; 155 | 156 | } 157 | 158 | #endif 159 | -------------------------------------------------------------------------------- /Awesomium/include/PlatformUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #ifndef __PLATFORM_UTILS_H__ 27 | #define __PLATFORM_UTILS_H__ 28 | 29 | #if defined(__WIN32__) || defined(_WIN32) 30 | # if defined(OSM_NONCLIENT_BUILD) 31 | # define _OSMExport __declspec( dllexport ) 32 | # else 33 | # define _OSMExport __declspec( dllimport ) 34 | # endif 35 | #else 36 | # if defined(__GNUC__) && __GNUC__ >= 4 37 | # define _OSMExport __attribute__ ((visibility("default"))) 38 | # else 39 | # define _OSMExport 40 | # endif 41 | #endif 42 | 43 | namespace Impl { 44 | void initCommandLine(); 45 | void initWebCorePlatform(); 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Awesomium/include/PopupWidget.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #ifndef __POPUP_WIDGET_H__ 27 | #define __POPUP_WIDGET_H__ 28 | 29 | #include 30 | #include "skia/ext/platform_canvas.h" 31 | #include "WebCanvas.h" 32 | #include "base/basictypes.h" 33 | #include "WebWidget.h" 34 | #include "WebWidgetClient.h" 35 | #include "base/gfx/platform_canvas.h" 36 | #include "WebInputEvent.h" 37 | #include "base/gfx/rect.h" 38 | #include "RenderBuffer.h" 39 | 40 | class WebViewProxy; 41 | using WebKit::WebWidget; 42 | 43 | 44 | WebKit::WebCanvas *SkiaCanvasToWebCanvas (skia::PlatformCanvas *canvas); 45 | 46 | class PopupWidget : public WebKit::WebWidgetClient 47 | { 48 | WebWidget* widget; 49 | WebViewProxy* parent; 50 | skia::PlatformCanvas* canvas; 51 | gfx::Rect dirtyArea; 52 | gfx::Rect mWindowRect; 53 | public: 54 | PopupWidget(WebViewProxy* parent); 55 | ~PopupWidget(); 56 | 57 | WebWidget* getWidget(); 58 | 59 | void renderToWebView(Awesomium::RenderBuffer* context, bool isParentTransparent); 60 | 61 | void didScrollWebView(int dx, int dy); 62 | 63 | bool isVisible(); 64 | 65 | void translatePointRelative(int& x, int& y); 66 | 67 | /** 68 | * The following methods are inherited from WebWidgetDelegate 69 | */ 70 | 71 | // Called when a region of the WebWidget needs to be re-painted. 72 | void didInvalidateRect(const WebKit::WebRect& rect); 73 | 74 | // Called when a region of the WebWidget, given by clip_rect, should be 75 | // scrolled by the specified dx and dy amounts. 76 | void didScrollRect(int dx, int dy, const WebKit::WebRect& clip_rect); 77 | 78 | // This method is called to instruct the window containing the WebWidget to 79 | // show itself as the topmost window. This method is only used after a 80 | // successful call to CreateWebWidget. |disposition| indicates how this new 81 | // window should be displayed, but generally only means something for WebViews. 82 | void show(WebKit::WebNavigationPolicy policy); 83 | 84 | // This method is called to instruct the window containing the WebWidget to 85 | // close. Note: This method should just be the trigger that causes the 86 | // WebWidget to eventually close. It should not actually be destroyed until 87 | // after this call returns. 88 | void closeWidgetSoon(); 89 | 90 | // This method is called to focus the window containing the WebWidget so 91 | // that it receives keyboard events. 92 | void didFocus(); 93 | 94 | // This method is called to unfocus the window containing the WebWidget so that 95 | // it no longer receives keyboard events. 96 | void didBlur(); 97 | 98 | void didChangeCursor(const WebKit::WebCursorInfo& cursor); 99 | 100 | // Returns the rectangle of the WebWidget in screen coordinates. 101 | WebKit::WebRect windowRect(); 102 | 103 | // This method is called to re-position the WebWidget on the screen. The given 104 | // rect is in screen coordinates. The implementation may choose to ignore 105 | // this call or modify the given rect. This method may be called before Show 106 | // has been called. 107 | // TODO(darin): this is more of a request; does this need to take effect 108 | // synchronously? 109 | void setWindowRect(const WebKit::WebRect& rect); 110 | 111 | // Returns the rectangle of the window in which this WebWidget is embeded in. 112 | WebKit::WebRect rootWindowRect(); 113 | 114 | // Returns the resizer rectangle of the window this WebWidget is in. This 115 | // is used on Mac to determine if a scrollbar is over the in-window resize 116 | // area at the bottom right corner. 117 | WebKit::WebRect windowResizerRect(); 118 | 119 | // Suppress input events to other windows, and do not return until the widget 120 | // is closed. This is used to support |window.showModalDialog|. 121 | void runModal(); 122 | 123 | WebKit::WebScreenInfo screenInfo(); 124 | }; 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /Awesomium/include/RenderBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #ifndef __RENDERBUFFER_H__ 27 | #define __RENDERBUFFER_H__ 28 | 29 | #include "base/gfx/rect.h" 30 | 31 | namespace Awesomium { 32 | 33 | void copyBuffers(int width, int height, unsigned char* src, int srcRowSpan, unsigned char* dest, int destRowSpan, int destDepth, bool convertToRGBA); 34 | 35 | class RenderBuffer 36 | { 37 | public: 38 | unsigned char* buffer; 39 | int width, height, rowSpan; 40 | 41 | RenderBuffer(int width, int height); 42 | 43 | ~RenderBuffer(); 44 | 45 | void reserve(int width, int height); 46 | void copyFrom(unsigned char* srcBuffer, int srcRowSpan); 47 | void copyArea(unsigned char* srcBuffer, int srcRowSpan, const gfx::Rect& srcRect, bool forceOpaque = false); 48 | void copyTo(unsigned char* destBuffer, int destRowSpan, int destDepth, bool convertToRGBA); 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Awesomium/include/RequestContext.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_REQUEST_CONTEXT_H__ 6 | #define WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_REQUEST_CONTEXT_H__ 7 | 8 | #include "net/http/http_cache.h" 9 | #include "net/url_request/url_request_context.h" 10 | 11 | // A basic URLRequestContext that only provides an in-memory cookie store. 12 | class TestShellRequestContext : public URLRequestContext { 13 | public: 14 | // Use an in-memory cache 15 | TestShellRequestContext(); 16 | 17 | // Use an on-disk cache at the specified location. Optionally, use the cache 18 | // in playback or record mode. 19 | TestShellRequestContext(const std::wstring& cache_path, 20 | net::HttpCache::Mode cache_mode, 21 | bool no_proxy); 22 | 23 | ~TestShellRequestContext(); 24 | 25 | virtual const std::string& GetUserAgent(const GURL& url) const; 26 | 27 | private: 28 | void Init(const std::wstring& cache_path, net::HttpCache::Mode cache_mode, 29 | bool no_proxy); 30 | }; 31 | 32 | #endif // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_REQUEST_CONTEXT_H__ 33 | -------------------------------------------------------------------------------- /Awesomium/include/ResourceLoaderBridge.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef WEBKIT_TOOLS_TEST_SHELL_SIMPLE_RESOURCE_LOADER_BRIDGE_H__ 6 | #define WEBKIT_TOOLS_TEST_SHELL_SIMPLE_RESOURCE_LOADER_BRIDGE_H__ 7 | 8 | #include 9 | 10 | class GURL; 11 | class URLRequestContext; 12 | 13 | class SimpleResourceLoaderBridge { 14 | public: 15 | // Call this function to initialize the simple resource loader bridge. If 16 | // the given context is null, then a default TestShellRequestContext will be 17 | // instantiated. Otherwise, a reference is taken to the given request 18 | // context, which will be released when Shutdown is called. The caller 19 | // should not hold another reference to the request context! It is safe to 20 | // call this function multiple times. 21 | // 22 | // NOTE: If this function is not called, then a default request context will 23 | // be initialized lazily. 24 | // 25 | static void Init(URLRequestContext* context); 26 | 27 | // Call this function to shutdown the simple resource loader bridge. 28 | static void Shutdown(); 29 | 30 | // May only be called after Init. 31 | static void SetCookie( 32 | const GURL& url, const GURL& policy_url, const std::string& cookie); 33 | static std::string GetCookies( 34 | const GURL& url, const GURL& policy_url); 35 | }; 36 | 37 | #endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_RESOURCE_LOADER_BRIDGE_H__ 38 | -------------------------------------------------------------------------------- /Awesomium/include/WebCore.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #ifndef __WEBCORE_H__ 27 | #define __WEBCORE_H__ 28 | 29 | #include "PlatformUtils.h" 30 | #include "WebView.h" 31 | #include 32 | #include 33 | #include 34 | 35 | namespace base { class Thread; class AtExitManager; } 36 | class WebCoreProxy; 37 | class WebViewEvent; 38 | class WindowlessPlugin; 39 | class NamedCallback; 40 | std::string GetDataResource(int id); 41 | class Lock; 42 | 43 | namespace Awesomium { 44 | 45 | /** 46 | * An enumeration of the three verbosity settings for the Awesomium Log. 47 | */ 48 | enum LogLevel 49 | { 50 | LOG_NONE, // No log is created 51 | LOG_NORMAL, // Logs only errors 52 | LOG_VERBOSE // Logs everything 53 | }; 54 | 55 | /** 56 | * An enumeration of the two output pixel formats that WebView::render will use. 57 | */ 58 | enum PixelFormat 59 | { 60 | PF_BGRA, // BGRA byte ordering [Blue, Green, Red, Alpha] 61 | PF_RGBA // RGBA byte ordering [Red, Green, Blue, Alpha] 62 | }; 63 | 64 | /** 65 | * The WebCore singleton manages the creation of WebViews, the internal worker thread, 66 | * and various other global states that are required to embed Chromium. 67 | */ 68 | class _OSMExport WebCore 69 | { 70 | public: 71 | /** 72 | * Instantiates the WebCore singleton (you can access it later with 73 | * WebCore::Get or GetPointer). 74 | * 75 | * @param level The logging level to use (default is LOG_NORMAL). 76 | * 77 | * @param enablePlugins Whether or not to enable embedded plugins. 78 | * 79 | * @param pixelFormat The pixel-format/byte-ordering to use when rendering WebViews. 80 | */ 81 | WebCore(LogLevel level = LOG_NORMAL, bool enablePlugins = true, PixelFormat pixelFormat = PF_BGRA); 82 | 83 | /** 84 | * Destroys the WebCore singleton. (Also destroys any lingering WebViews) 85 | */ 86 | ~WebCore(); 87 | 88 | /** 89 | * Retrieves the WebCore singleton. 90 | * 91 | * @note This will assert if the singleton is not instantiated. 92 | * 93 | * @return Returns a reference to the instance. 94 | */ 95 | static WebCore& Get(); 96 | 97 | /** 98 | * Retrieves the WebCore singleton. 99 | * 100 | * @return Returns a pointer to the instance. 101 | */ 102 | static WebCore* GetPointer(); 103 | 104 | /** 105 | * Sets the base directory. 106 | * 107 | * @param baseDirectory The absolute path to your base directory. The base directory is a 108 | * location that holds all of your local assets. It will be used for 109 | * WebView::loadFile and WebView::loadHTML (to resolve relative URL's). 110 | */ 111 | void setBaseDirectory(const std::string& baseDirectory); 112 | 113 | /** 114 | * Creates a new WebView. 115 | * 116 | * @param width The width of the WebView in pixels. 117 | * @param height The height of the WebView in pixels. 118 | * 119 | * @param isTransparent Whether or not the background of a WebView should be rendered as transparent. 120 | * 121 | * @param enableAsyncRendering Enables fully-asynchronous rendering, see the note below. 122 | * @param maxAsyncRenderPerSec The maximum times per second this WebView should asynchronously render. 123 | * 124 | * @note When asynchronous rendering is enabled, all rendering takes place on another thread asynchronously. 125 | * The benefit of this behavior is that you may see a marked performance increase on machines with 126 | * multi-core processors (especially when a WebView has high-animation content). 127 | * 128 | * @return Returns a pointer to the created WebView. 129 | */ 130 | WebView* createWebView(int width, int height, bool isTransparent = false, bool enableAsyncRendering = false, int maxAsyncRenderPerSec = 70); 131 | 132 | /** 133 | * Sets a custom response page to use when a WebView encounters a certain 134 | * HTML status code from the server (such as '404 - File not found'). 135 | * 136 | * @param statusCode The status code this response page should be associated with. 137 | * See 138 | * 139 | * @param filePath The local page to load as a response, should be a path relative to the base directory. 140 | */ 141 | void setCustomResponsePage(int statusCode, const std::string& filePath); 142 | 143 | /** 144 | * Updates the WebCore and allows it to conduct various operations such as the propagation 145 | * of bound JS callbacks and the invocation of any queued listener events. 146 | */ 147 | void update(); 148 | 149 | /** 150 | * Retrieves the base directory. 151 | * 152 | * @return Returns the current base directory. 153 | */ 154 | const std::string& getBaseDirectory() const; 155 | 156 | /** 157 | * Retrieves the pixel format being used. 158 | */ 159 | PixelFormat getPixelFormat() const; 160 | 161 | /** 162 | * Returns whether or not plugins are enabled. 163 | */ 164 | bool arePluginsEnabled() const; 165 | 166 | /** 167 | * Pauses the internal thread of the Awesomium WebCore. 168 | * 169 | * @note The pause and resume functions were added as 170 | * a temporary workaround for threading issues with 171 | * Flash plugins on the Mac OSX platform. You should 172 | * call WebCore::pause right before handling the 173 | * message loop in your main thread (usually via 174 | * SDL_PollEvents) and immediately call resume after. 175 | */ 176 | void pause(); 177 | 178 | /** 179 | * Resumes the internal thread of the Awesomium WebCore. 180 | * 181 | * @note See WebCore::pause. 182 | */ 183 | void resume(); 184 | 185 | friend class WebView; 186 | friend class FutureJSValue; 187 | friend class ::WebCoreProxy; 188 | friend class ::WebViewProxy; 189 | friend class ::NamedCallback; 190 | friend class ::WindowlessPlugin; 191 | friend std::string GetDataResource(int id); 192 | 193 | protected: 194 | static WebCore* instance; 195 | base::Thread* coreThread; 196 | WebCoreProxy* coreProxy; 197 | base::AtExitManager* atExitMgr; 198 | std::vector views; 199 | std::deque eventQueue; // treat as std::queue, missing swap(). 200 | std::map customResponsePageMap; 201 | std::string baseDirectory; 202 | bool logOpen; 203 | bool pluginsEnabled; 204 | const PixelFormat pixelFormat; 205 | Lock *eventQueueLock, *baseDirLock, *customResponsePageLock; 206 | 207 | void queueEvent(WebViewEvent* event); 208 | void removeWebView(WebView* view); 209 | 210 | void purgePluginMessages(); 211 | 212 | void resolveJSValueFuture(WebView* view, int requestID, JSValue* result); 213 | 214 | void getCustomResponsePage(int statusCode, std::string& filePathResult); 215 | }; 216 | 217 | } 218 | 219 | #endif 220 | -------------------------------------------------------------------------------- /Awesomium/include/WebCoreProxy.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #ifndef __WEBCOREPROXY_H__ 27 | #define __WEBCOREPROXY_H__ 28 | 29 | #include "base/ref_counted.h" 30 | #include "base/timer.h" 31 | #include "webkit/glue/webkit_glue.h" 32 | #include "webkit/glue/webkitclient_impl.h" 33 | #include "WebCString.h" 34 | #include "WebKit.h" 35 | #include "WebString.h" 36 | #include "WebURL.h" 37 | #include "webkit/glue/simple_webmimeregistry_impl.h" 38 | #include "base/waitable_event.h" 39 | #include 40 | #include 41 | 42 | namespace base { class Thread; } 43 | namespace Awesomium { class WebCore; } 44 | 45 | class WebCoreProxy : public base::RefCountedThreadSafe, 46 | public webkit_glue::WebKitClientImpl 47 | { 48 | public: 49 | WebCoreProxy(base::Thread* coreThread, bool pluginsEnabled); 50 | 51 | void startup(); 52 | 53 | ~WebCoreProxy(); 54 | 55 | void pause(); 56 | void resume(); 57 | 58 | bool sandboxEnabled(); 59 | 60 | WebKit::WebMimeRegistry* mimeRegistry(); 61 | 62 | WebKit::WebSandboxSupport* sandboxSupport(); 63 | 64 | WebKit::WebMessagePortChannel* createMessagePortChannel(); 65 | 66 | WebKit::WebStorageNamespace* createLocalStorageNamespace(const WebKit::WebString& path); 67 | 68 | WebKit::WebStorageNamespace* createSessionStorageNamespace(); 69 | 70 | unsigned long long visitedLinkHash(const char* canonicalURL, size_t length); 71 | 72 | bool isLinkVisited(unsigned long long linkHash); 73 | 74 | void setCookies(const WebKit::WebURL& url, const WebKit::WebURL& policy_url, 75 | const WebKit::WebString& value); 76 | 77 | WebKit::WebString cookies(const WebKit::WebURL& url, const WebKit::WebURL& policy_url); 78 | 79 | void prefetchHostName(const WebKit::WebString&); 80 | 81 | WebKit::WebData loadResource(const char* name); 82 | 83 | WebKit::WebString defaultLocale(); 84 | 85 | WebKit::WebClipboard *clipboard(); 86 | protected: 87 | void asyncStartup(); 88 | 89 | void asyncPause(); 90 | 91 | void pumpPluginMessages(); 92 | void pumpThrottledMessages(); 93 | void purgePluginMessages(); 94 | 95 | class Clipboard; 96 | Clipboard *webclipboard; 97 | 98 | base::Thread* coreThread; 99 | bool pluginsEnabled; 100 | base::RepeatingTimer pluginMessageTimer; 101 | webkit_glue::SimpleWebMimeRegistryImpl mime_registry_; 102 | base::WaitableEvent threadWaitEvent, pauseRequestEvent; 103 | 104 | #if defined(WIN32) 105 | std::list throttledMessages; 106 | #endif 107 | 108 | friend class Awesomium::WebCore; 109 | }; 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /Awesomium/include/WebViewEvent.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #ifndef __WEBVIEWEVENT_H__ 27 | #define __WEBVIEWEVENT_H__ 28 | 29 | #include "WebView.h" 30 | 31 | class WebViewProxy; 32 | 33 | class WebViewEvent 34 | { 35 | public: 36 | WebViewEvent(Awesomium::WebView* view); 37 | virtual ~WebViewEvent() {} 38 | virtual void run() = 0; 39 | protected: 40 | Awesomium::WebView* view; 41 | }; 42 | 43 | namespace WebViewEvents 44 | { 45 | 46 | class BeginLoad : public WebViewEvent 47 | { 48 | std::string url; 49 | std::wstring frameName; 50 | int statusCode; 51 | std::wstring mimeType; 52 | public: 53 | BeginLoad(Awesomium::WebView* view, const std::string& url, const std::wstring& frameName, int statusCode, const std::wstring& mimeType); 54 | void run(); 55 | }; 56 | 57 | class FinishLoad : public WebViewEvent 58 | { 59 | public: 60 | FinishLoad(Awesomium::WebView* view); 61 | void run(); 62 | }; 63 | 64 | class BeginNavigate : public WebViewEvent 65 | { 66 | std::string url; 67 | std::wstring frameName; 68 | public: 69 | BeginNavigate(Awesomium::WebView* view, const std::string& url, const std::wstring& frameName); 70 | void run(); 71 | }; 72 | 73 | class ReceiveTitle : public WebViewEvent 74 | { 75 | std::wstring title; 76 | std::wstring frameName; 77 | public: 78 | ReceiveTitle(Awesomium::WebView* view, const std::wstring& title, const std::wstring& frameName); 79 | void run(); 80 | }; 81 | 82 | class InvokeCallback : public WebViewEvent 83 | { 84 | std::string name; 85 | Awesomium::JSArguments args; 86 | public: 87 | InvokeCallback(Awesomium::WebView* view, const std::string& name, const Awesomium::JSArguments& args); 88 | void run(); 89 | }; 90 | 91 | class ChangeTooltip : public WebViewEvent 92 | { 93 | std::wstring tooltip; 94 | public: 95 | ChangeTooltip(Awesomium::WebView* view, const std::wstring& tooltip); 96 | void run(); 97 | }; 98 | 99 | #if defined(_WIN32) 100 | 101 | class ChangeCursor : public WebViewEvent 102 | { 103 | HCURSOR cursor; 104 | public: 105 | ChangeCursor(Awesomium::WebView* view, const HCURSOR& cursor); 106 | void run(); 107 | }; 108 | 109 | #endif 110 | 111 | class ChangeKeyboardFocus : public WebViewEvent 112 | { 113 | bool isFocused; 114 | public: 115 | ChangeKeyboardFocus(Awesomium::WebView* view, bool isFocused); 116 | void run(); 117 | }; 118 | 119 | class ChangeTargetURL : public WebViewEvent 120 | { 121 | std::string url; 122 | public: 123 | ChangeTargetURL(Awesomium::WebView* view, const std::string& url); 124 | void run(); 125 | }; 126 | } 127 | 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /Awesomium/include/WebViewListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #ifndef __WEBVIEWLISTENER_H__ 27 | #define __WEBVIEWLISTENER_H__ 28 | 29 | #include 30 | #include "JSValue.h" 31 | 32 | #if defined(_WIN32) 33 | #include 34 | #endif 35 | 36 | namespace Awesomium { 37 | 38 | /** 39 | * WebViewListener is a virtual interface that you can use to receive notifications 40 | * from a certain WebView. Simply make a class that inherits from WebViewListener 41 | * and register it via WebView::setListener. 42 | */ 43 | class _OSMExport WebViewListener 44 | { 45 | public: 46 | virtual ~WebViewListener() {} 47 | 48 | /** 49 | * This event is fired when a WebView begins navigating to a new URL. 50 | * 51 | * @param url The URL that is being navigated to. 52 | * 53 | * @param frameName The name of the frame that this event originated from. 54 | */ 55 | virtual void onBeginNavigation(const std::string& url, const std::wstring& frameName) = 0; 56 | 57 | /** 58 | * This event is fired when a WebView begins to actually receive data from a server. 59 | * 60 | * @param url The URL of the frame that is being loaded. 61 | * 62 | * @param frameName The name of the frame that this event originated from. 63 | * 64 | * @param statusCode The HTTP status code returned by the server. 65 | * 66 | * @param mimeType The mime-type of the content that is being loaded. 67 | */ 68 | virtual void onBeginLoading(const std::string& url, const std::wstring& frameName, int statusCode, const std::wstring& mimeType) = 0; 69 | 70 | /** 71 | * This event is fired when all loads have finished for a WebView. 72 | */ 73 | virtual void onFinishLoading() = 0; 74 | 75 | /** 76 | * This event is fired when a Client callback has been invoked via Javascript from a page. 77 | * 78 | * @param name The name of the client callback that was invoked (specifically, "Client._this_name_here_(...)"). 79 | * 80 | * @param args The arguments passed to the callback. 81 | */ 82 | virtual void onCallback(const std::string& name, const Awesomium::JSArguments& args) = 0; 83 | 84 | /** 85 | * This event is fired when a page title is received. 86 | * 87 | * @param title The page title. 88 | * 89 | * @param frameName The name of the frame that this event originated from. 90 | */ 91 | virtual void onReceiveTitle(const std::wstring& title, const std::wstring& frameName) = 0; 92 | 93 | /** 94 | * This event is fired when a tooltip has changed state. 95 | * 96 | * @param tooltip The tooltip text (or, is an empty string when the tooltip should disappear). 97 | */ 98 | virtual void onChangeTooltip(const std::wstring& tooltip) = 0; 99 | 100 | #if defined(_WIN32) 101 | /** 102 | * This event is fired when a cursor has changed state. [Windows-only] 103 | * 104 | * @param cursor The cursor handle/type. 105 | */ 106 | virtual void onChangeCursor(const HCURSOR& cursor) = 0; 107 | #endif 108 | 109 | /** 110 | * This event is fired when keyboard focus has changed. 111 | * 112 | * @param isFocused Whether or not the keyboard is currently focused. 113 | */ 114 | virtual void onChangeKeyboardFocus(bool isFocused) = 0; 115 | 116 | /** 117 | * This event is fired when the target URL has changed. This is usually the result of 118 | * hovering over a link on the page. 119 | * 120 | * @param url The updated target URL (or empty if the target URL is cleared). 121 | */ 122 | virtual void onChangeTargetURL(const std::string& url) = 0; 123 | }; 124 | 125 | } 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /Awesomium/include/WebViewProxy.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #ifndef __WEBVIEWPROXY_H__ 27 | #define __WEBVIEWPROXY_H__ 28 | 29 | #include "RenderBuffer.h" 30 | #include "PopupWidget.h" 31 | #include "WebView.h" 32 | #include "ClientObject.h" 33 | #include 34 | #include "base/basictypes.h" 35 | #include "webkit/glue/webview.h" 36 | #include "WebCursorInfo.h" 37 | #include "WebURLRequest.h" 38 | #include "WebNavigationType.h" 39 | #include "webkit/glue/webview_delegate.h" 40 | #include "webkit/glue/webpreferences.h" 41 | #include "webkit/glue/webdropdata.h" 42 | #include "webkit/glue/webcursor.h" 43 | #include "base/gfx/platform_canvas.h" 44 | #include "WebHTTPBody.h" 45 | #include "WebInputEvent.h" 46 | #include "WebHistoryItem.h" 47 | #include "SkCanvas.h" 48 | #include "base/gfx/rect.h" 49 | #include "base/message_loop.h" 50 | #include "base/timer.h" 51 | #include "base/lock.h" 52 | 53 | using WebKit::WebFrame; 54 | class NavigationEntry; 55 | class NavigationController; 56 | 57 | class WebViewProxy : public WebViewDelegate 58 | { 59 | int refCount; 60 | int width, height; 61 | gfx::Rect dirtyArea; 62 | Awesomium::RenderBuffer* renderBuffer; 63 | Awesomium::RenderBuffer* backBuffer; 64 | skia::PlatformCanvas* canvas; 65 | int mouseX, mouseY; 66 | int buttonState; 67 | int modifiers; 68 | ::WebView* view; 69 | Awesomium::WebView* parent; 70 | std::vector popups; 71 | bool isPopupsDirty; 72 | bool needsPainting; 73 | ClientObject* clientObject; 74 | WebKit::WebCursorInfo curCursor; 75 | std::wstring curTooltip; 76 | LockImpl *renderBufferLock, *refCountLock; 77 | base::RepeatingTimer renderTimer; 78 | const bool enableAsyncRendering; 79 | bool isAsyncRenderDirty; 80 | int maxAsyncRenderPerSec; 81 | bool isTransparent; 82 | GURL lastTargetURL; 83 | NavigationController* navController; 84 | int pageID, nextPageID; 85 | 86 | friend class NavigationController; 87 | 88 | void closeAllPopups(); 89 | void handleMouseEvent(WebKit::WebInputEvent::Type type, short buttonID); 90 | void overrideIFrameWindow(const std::wstring& frameName); 91 | bool navigate(NavigationEntry* entry, bool reload); 92 | void updateForCommittedLoad(WebFrame* frame, bool is_new_navigation); 93 | void updateURL(WebFrame* frame); 94 | void updateSessionHistory(WebFrame* frame); 95 | template void initializeWebEvent(EventType &event, WebKit::WebInputEvent::Type type); 96 | public: 97 | 98 | WebViewProxy(int width, int height, bool isTransparent, bool enableAsyncRendering, int maxAsyncRenderPerSec, Awesomium::WebView* parent); 99 | 100 | ~WebViewProxy(); 101 | 102 | void asyncStartup(); 103 | void asyncShutdown(); 104 | 105 | void loadURL(const std::string& url, const std::wstring& frameName, const std::string& username, const std::string& password); 106 | void loadHTML(const std::string& html, const std::wstring& frameName); 107 | void loadFile(const std::string& file, const std::wstring& frameName); 108 | 109 | void goToHistoryOffset(int offset); 110 | void refresh(); 111 | 112 | void executeJavascript(const std::string& javascript, const std::wstring& frameName = std::wstring()); 113 | void setProperty(const std::string& name, const Awesomium::JSValue& value); 114 | void setCallback(const std::string& name); 115 | 116 | void mayBeginRender(); 117 | 118 | WebKit::WebRect render(); 119 | 120 | void copyRenderBuffer(unsigned char* destination, int destRowSpan, int destDepth); 121 | 122 | void renderAsync(); 123 | 124 | void renderSync(unsigned char* destination, int destRowSpan, int destDepth, Awesomium::Rect* renderedRect); 125 | 126 | void paint(); 127 | 128 | void injectMouseMove(int x, int y); 129 | void injectMouseDown(short mouseButtonID); 130 | void injectMouseUp(short mouseButtonID); 131 | void injectMouseWheel(int scrollAmountX, int scrollAmountY); 132 | 133 | void injectKeyEvent(bool press, int modifiers, int windowsCode, int nativeCode); 134 | void injectTextEvent(string16 text); 135 | #if defined(_WIN32) 136 | void injectKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); 137 | #elif defined(__APPLE__) 138 | void injectKeyboardEvent(NSEvent* keyboardEvent); 139 | #endif 140 | 141 | void cut(); 142 | void copy(); 143 | void paste(); 144 | 145 | void selectAll(); 146 | void deselectAll(); 147 | 148 | void getContentAsText(std::wstring* result, int maxChars); 149 | 150 | void zoomIn(); 151 | void zoomOut(); 152 | void resetZoom(); 153 | 154 | void resize(int width, int height); 155 | 156 | void setTransparent(bool isTransparent); 157 | 158 | void invalidatePopups(); 159 | 160 | void closePopup(PopupWidget* popup); 161 | 162 | void checkKeyboardFocus(); 163 | 164 | void AddRef(); 165 | void Release(); 166 | 167 | /** 168 | * The following functions are inherited from WebViewDelegate 169 | */ 170 | 171 | ::WebView* CreateWebView(::WebView* webview, bool user_gesture, const GURL& creator_url); 172 | 173 | WebWidget* CreatePopupWidgetWithInfo(::WebView* webview, const WebKit::WebPopupMenuInfo& popup_info); 174 | WebWidget* CreatePopupWidget(::WebView* webview, bool focus_on_show); 175 | 176 | WebKit::WebMediaPlayer* CreateWebMediaPlayer(WebKit::WebMediaPlayerClient* client); 177 | 178 | WebPluginDelegate* CreatePluginDelegate(::WebView* webview, const GURL& url, const std::string& mime_type, 179 | const std::string& clsid, std::string* actual_mime_type); 180 | 181 | void OpenURL(::WebView* webview, const GURL& url, const GURL& referrer, WebKit::WebNavigationPolicy disposition); 182 | 183 | void DidStartLoading(::WebView* webview); 184 | 185 | void DidStopLoading(::WebView* webview); 186 | 187 | void WindowObjectCleared(WebFrame* webframe); 188 | 189 | WebKit::WebNavigationPolicy PolicyForNavigationAction( 190 | ::WebView* webview, 191 | WebFrame* frame, 192 | const WebKit::WebURLRequest& request, 193 | WebKit::WebNavigationType type, 194 | WebKit::WebNavigationPolicy default_policy, 195 | bool is_redirect); 196 | 197 | void DidStartProvisionalLoadForFrame(::WebView* webview, WebFrame* frame, NavigationGesture gesture); 198 | 199 | void DidReceiveProvisionalLoadServerRedirect(::WebView* webview, WebFrame* frame); 200 | 201 | void DidFailProvisionalLoadWithError(::WebView* webview, const WebKit::WebURLError& error, WebFrame* frame); 202 | 203 | void LoadNavigationErrorPage(WebFrame* frame, const WebKit::WebURLRequest& failed_request, const WebKit::WebURLError& error, 204 | const std::string& html, bool replace); 205 | 206 | void DidCommitLoadForFrame(::WebView* webview, WebFrame* frame, bool is_new_navigation); 207 | 208 | void DidReceiveTitle(::WebView* webview, const std::wstring& title, WebFrame* frame); 209 | 210 | void DidFinishLoadForFrame(::WebView* webview, WebFrame* frame); 211 | 212 | void DidFailLoadWithError(::WebView* webview, const WebKit::WebURLError& error, WebFrame* forFrame); 213 | 214 | void DidFinishDocumentLoadForFrame(::WebView* webview, WebFrame* frame); 215 | 216 | bool DidLoadResourceFromMemoryCache(::WebView* webview, const WebKit::WebURLRequest& request, 217 | const WebKit::WebURLResponse& response, WebFrame* frame); 218 | 219 | void DidHandleOnloadEventsForFrame(::WebView* webview, WebFrame* frame); 220 | 221 | void DidChangeLocationWithinPageForFrame(::WebView* webview, WebFrame* frame, bool is_new_navigation); 222 | 223 | void DidReceiveIconForFrame(::WebView* webview, WebFrame* frame); 224 | 225 | void WillPerformClientRedirect(::WebView* webview, WebFrame* frame, const GURL& src_url, 226 | const GURL& dest_url, unsigned int delay_seconds, unsigned int fire_date); 227 | 228 | void DidCancelClientRedirect(::WebView* webview, WebFrame* frame); 229 | 230 | void DidCompleteClientRedirect(::WebView* webview, WebFrame* frame, const GURL& source); 231 | 232 | void WillCloseFrame(::WebView* webview, WebFrame* frame); 233 | 234 | void AssignIdentifierToRequest(::WebView* webview, uint32 identifier, const WebKit::WebURLRequest& request); 235 | 236 | void WillSendRequest(::WebView* webview, uint32 identifier, WebKit::WebURLRequest* request); 237 | 238 | void DidFinishLoading(::WebView* webview, uint32 identifier); 239 | 240 | void DidFailLoadingWithError(::WebView* webview, uint32 identifier, const WebKit::WebURLError& error); 241 | 242 | void AddMessageToConsole(::WebView* webview, const std::wstring& message, unsigned int line_no, 243 | const std::wstring& source_id); 244 | 245 | void ShowModalHTMLDialog(const GURL& url, int width, int height, const std::string& json_arguments, 246 | std::string* json_retval); 247 | 248 | void RunJavaScriptAlert(WebFrame* webframe, const std::wstring& message); 249 | 250 | bool RunJavaScriptConfirm(WebFrame* webframe, const std::wstring& message); 251 | 252 | bool RunJavaScriptPrompt(WebFrame* webframe, const std::wstring& message, const std::wstring& default_value, 253 | std::wstring* result); 254 | 255 | bool RunBeforeUnloadConfirm(WebFrame* webframe, const std::wstring& message); 256 | 257 | void UpdateTargetURL(::WebView* webview, const GURL& url); 258 | 259 | void RunFileChooser(bool multi_select, 260 | const string16& title, 261 | const FilePath& initial_filename, 262 | WebFileChooserCallback* file_chooser); 263 | 264 | void ShowContextMenu( 265 | ::WebView* webview, ContextNodeType node, 266 | int x, int y, 267 | const GURL& link_url, const GURL& image_url, 268 | const GURL& page_url, const GURL& frame_url, 269 | const std::wstring& selection_text, 270 | const std::wstring& misspelled_word, int edit_flags, 271 | const std::string& security_info, const std::string& frame_encoding); 272 | 273 | void StartDragging(::WebView* webview, const WebKit::WebDragData& drop_data); 274 | 275 | void TakeFocus(::WebView* webview, bool reverse); 276 | 277 | void JSOutOfMemory(); 278 | 279 | bool ShouldBeginEditing(::WebView* webview, std::wstring range); 280 | 281 | bool ShouldEndEditing(::WebView* webview, std::wstring range); 282 | 283 | bool ShouldInsertNode(::WebView* webview, std::wstring node, std::wstring range, std::wstring action); 284 | 285 | bool ShouldInsertText(::WebView* webview, std::wstring text, std::wstring range, std::wstring action); 286 | 287 | bool ShouldChangeSelectedRange(::WebView* webview, std::wstring fromRange, std::wstring toRange, 288 | std::wstring affinity, bool stillSelecting); 289 | 290 | bool ShouldDeleteRange(::WebView* webview, std::wstring range); 291 | 292 | bool ShouldApplyStyle(::WebView* webview, std::wstring style, std::wstring range); 293 | 294 | bool SmartInsertDeleteEnabled(); 295 | void DidBeginEditing(); 296 | void DidChangeSelection(); 297 | void DidChangeContents(); 298 | void DidEndEditing(); 299 | 300 | void UserMetricsRecordAction(const std::wstring& action); 301 | void UserMetricsRecordComputedAction(const std::wstring& action); 302 | 303 | void DidDownloadImage(int id, const GURL& image_url, bool errored, const SkBitmap& image); 304 | 305 | void GoToEntryAtOffsetAsync(int offset); 306 | 307 | int GetHistoryBackListCount(); 308 | int GetHistoryForwardListCount(); 309 | 310 | void OnNavStateChanged(::WebView* webview); 311 | 312 | void SetTooltipText(::WebView* webview, const std::wstring& tooltip_text); 313 | 314 | void DownloadUrl(const GURL& url, const GURL& referrer); 315 | 316 | void SpellCheck(const std::wstring& word, int& misspell_location, int& misspell_length); 317 | 318 | void SetInputMethodState(bool enabled); 319 | 320 | void ScriptedPrint(WebFrame* frame); 321 | 322 | void WebInspectorOpened(int num_resources); 323 | 324 | void TransitionToCommittedForNewPage(); 325 | 326 | void didInvalidateRect(const WebKit::WebRect& rect); 327 | 328 | void didScrollRect(int dx, int dy, const WebKit::WebRect& clip_rect); 329 | 330 | void closeWidgetSoon(); 331 | 332 | void didFocus(); 333 | 334 | void didBlur(); 335 | 336 | void didChangeCursor(const WebKit::WebCursorInfo& cursor); 337 | 338 | WebKit::WebRect windowRect(); 339 | 340 | void setWindowRect(const WebKit::WebRect& rect); 341 | 342 | WebKit::WebRect rootWindowRect(); 343 | 344 | WebKit::WebRect windowResizerRect(); 345 | 346 | void DidMovePlugin(const WebPluginGeometry& move); 347 | 348 | void runModal(); 349 | 350 | void show(WebKit::WebNavigationPolicy); 351 | 352 | WebKit::WebScreenInfo screenInfo(); 353 | }; 354 | 355 | #endif 356 | -------------------------------------------------------------------------------- /Awesomium/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Awesomium.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /Awesomium/src/ClientObject.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #include "ClientObject.h" 27 | #include "WebCore.h" 28 | #include "WebViewEvent.h" 29 | 30 | void initFromCppArgumentList(const CppArgumentList& args, Awesomium::JSArguments& result); 31 | 32 | class NamedCallback 33 | { 34 | std::string name; 35 | Awesomium::WebView* view; 36 | public: 37 | NamedCallback(const std::string& name, Awesomium::WebView* view); 38 | 39 | void handleCallback(const CppArgumentList& args, CppVariant* result); 40 | }; 41 | 42 | class FutureValueCallback 43 | { 44 | Awesomium::WebView* view; 45 | public: 46 | FutureValueCallback(Awesomium::WebView* view) : view(view) {} 47 | 48 | void handleCallback(const CppArgumentList& args, CppVariant* result); 49 | }; 50 | 51 | class CheckKeyboardFocusCallback 52 | { 53 | Awesomium::WebView* view; 54 | public: 55 | CheckKeyboardFocusCallback(Awesomium::WebView* view) : view(view) {} 56 | 57 | void handleCallback(const CppArgumentList& args, CppVariant* result); 58 | }; 59 | 60 | ClientObject::ClientObject(Awesomium::WebView* view) : futureValueCallback(0), checkKeyboardFocusCallback(0), view(view) 61 | { 62 | } 63 | 64 | ClientObject::~ClientObject() 65 | { 66 | if(futureValueCallback) 67 | delete futureValueCallback; 68 | 69 | if(checkKeyboardFocusCallback) 70 | delete checkKeyboardFocusCallback; 71 | 72 | for(std::map::iterator i = clientProperties.begin(); i != clientProperties.end(); i++) 73 | delete i->second; 74 | 75 | for(std::map::iterator i = clientCallbacks.begin(); i != clientCallbacks.end(); i++) 76 | delete i->second; 77 | } 78 | 79 | void ClientObject::initInternalCallbacks() 80 | { 81 | if(!futureValueCallback) 82 | { 83 | futureValueCallback = new FutureValueCallback(view); 84 | CppBoundClass::Callback* callback = NewCallback(futureValueCallback, &FutureValueCallback::handleCallback); 86 | BindCallback("____futureValue", callback); 87 | } 88 | 89 | if(!checkKeyboardFocusCallback) 90 | { 91 | checkKeyboardFocusCallback = new CheckKeyboardFocusCallback(view); 92 | CppBoundClass::Callback* callback = NewCallback(checkKeyboardFocusCallback, &CheckKeyboardFocusCallback::handleCallback); 94 | BindCallback("____checkKeyboardFocus", callback); 95 | } 96 | } 97 | 98 | void ClientObject::setProperty(const std::string& name, const Awesomium::JSValue& value) 99 | { 100 | std::map::iterator i = clientProperties.find(name); 101 | 102 | if(i == clientProperties.end()) 103 | { 104 | CppVariant* newValue = new CppVariant(); 105 | 106 | if(value.isString()) 107 | newValue->Set(value.toString()); 108 | else if(value.isInteger()) 109 | newValue->Set(value.toInteger()); 110 | else if(value.isDouble()) 111 | newValue->Set(value.toDouble()); 112 | else if(value.isBoolean()) 113 | newValue->Set(value.toBoolean()); 114 | else 115 | newValue->SetNull(); 116 | 117 | clientProperties[name] = newValue; 118 | 119 | BindProperty(name, newValue); 120 | } 121 | else 122 | { 123 | if(value.isString()) 124 | i->second->Set(value.toString()); 125 | else if(value.isInteger()) 126 | i->second->Set(value.toInteger()); 127 | else if(value.isDouble()) 128 | i->second->Set(value.toDouble()); 129 | else if(value.isBoolean()) 130 | i->second->Set(value.toBoolean()); 131 | else 132 | i->second->SetNull(); 133 | } 134 | } 135 | 136 | void ClientObject::setCallback(const std::string& name) 137 | { 138 | if(clientCallbacks.find(name) == clientCallbacks.end()) 139 | { 140 | NamedCallback* namedCallback = new NamedCallback(name, view); 141 | 142 | clientCallbacks[name] = namedCallback; 143 | 144 | CppBoundClass::Callback* callback = NewCallback(namedCallback, &NamedCallback::handleCallback); 146 | BindCallback(name, callback); 147 | } 148 | } 149 | 150 | NamedCallback::NamedCallback(const std::string& name, Awesomium::WebView* view) : name(name), view(view) 151 | { 152 | } 153 | 154 | void NamedCallback::handleCallback(const CppArgumentList& args, CppVariant* result) 155 | { 156 | Awesomium::JSArguments jsArgs; 157 | initFromCppArgumentList(args, jsArgs); 158 | 159 | Awesomium::WebCore::Get().queueEvent(new WebViewEvents::InvokeCallback(view, name, jsArgs)); 160 | result->SetNull(); 161 | } 162 | 163 | void FutureValueCallback::handleCallback(const CppArgumentList& args, CppVariant* result) 164 | { 165 | Awesomium::JSArguments jsArgs; 166 | initFromCppArgumentList(args, jsArgs); 167 | 168 | view->handleFutureJSValueCallback(jsArgs); 169 | result->SetNull(); 170 | } 171 | 172 | void CheckKeyboardFocusCallback::handleCallback(const CppArgumentList& args, CppVariant* result) 173 | { 174 | Awesomium::JSArguments jsArgs; 175 | initFromCppArgumentList(args, jsArgs); 176 | 177 | if(jsArgs.size()) 178 | view->handleCheckKeyboardFocus(jsArgs[0].toBoolean()); 179 | 180 | result->SetNull(); 181 | } 182 | 183 | void initFromCppArgumentList(const CppArgumentList& args, Awesomium::JSArguments& result) 184 | { 185 | for(CppArgumentList::const_iterator i = args.begin(); i != args.end(); i++) 186 | { 187 | if(i->isInt32()) 188 | result.push_back(i->ToInt32()); 189 | else if(i->isDouble()) 190 | result.push_back(i->ToDouble()); 191 | else if(i->isBool()) 192 | result.push_back(i->ToBoolean()); 193 | else if(i->isString()) 194 | result.push_back(i->ToString()); 195 | else 196 | result.push_back(Awesomium::JSValue()); 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /Awesomium/src/InitMacApplication.mm: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | void initMacApplication() 5 | { 6 | [NSApplication sharedApplication]; 7 | } -------------------------------------------------------------------------------- /Awesomium/src/JSValue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #include "JSValue.h" 27 | #include "WebCore.h" 28 | #include 29 | 30 | template 31 | inline NumberType stringToNumber(const std::string& numberString) 32 | { 33 | if(numberString.substr(0, 4).compare("true") == 0) return 1; 34 | else if(numberString.substr(0, 4).compare("false") == 0) return 0; 35 | 36 | std::istringstream converter(numberString); 37 | 38 | NumberType result; 39 | return (converter >> result).fail() ? 0 : result; 40 | } 41 | 42 | template 43 | inline std::string numberToString(const NumberType &number) 44 | { 45 | std::ostringstream converter; 46 | 47 | return (converter << number).fail() ? "" : converter.str(); 48 | } 49 | 50 | using namespace Awesomium; 51 | using namespace Impl; 52 | 53 | JSValue::JSValue() 54 | { 55 | varValue.type = VariantType_NULL; 56 | } 57 | 58 | JSValue::JSValue(bool value) 59 | { 60 | varValue.type = VariantType_BOOLEAN; 61 | varValue.numericValue.booleanValue = value; 62 | } 63 | 64 | JSValue::JSValue(int value) 65 | { 66 | varValue.type = VariantType_INTEGER; 67 | varValue.numericValue.integerValue = value; 68 | } 69 | 70 | JSValue::JSValue(double value) 71 | { 72 | varValue.type = VariantType_DOUBLE; 73 | varValue.numericValue.doubleValue = value; 74 | } 75 | 76 | JSValue::JSValue(const char* value) 77 | { 78 | varValue.type = VariantType_STRING; 79 | varValue.stringValue = value; 80 | } 81 | 82 | JSValue::JSValue(const std::string& value) 83 | { 84 | varValue.type = VariantType_STRING; 85 | varValue.stringValue = value; 86 | } 87 | 88 | bool JSValue::isBoolean() const 89 | { 90 | return varValue.type == VariantType_BOOLEAN; 91 | } 92 | 93 | bool JSValue::isInteger() const 94 | { 95 | return varValue.type == VariantType_INTEGER; 96 | } 97 | 98 | bool JSValue::isDouble() const 99 | { 100 | return varValue.type == VariantType_DOUBLE; 101 | } 102 | 103 | bool JSValue::isNumber() const 104 | { 105 | return varValue.type == VariantType_INTEGER || varValue.type == VariantType_DOUBLE; 106 | } 107 | 108 | bool JSValue::isString() const 109 | { 110 | return varValue.type == VariantType_STRING; 111 | } 112 | 113 | bool JSValue::isNull() const 114 | { 115 | return varValue.type == VariantType_NULL; 116 | } 117 | 118 | const std::string& JSValue::toString() const 119 | { 120 | if(isString()) 121 | return varValue.stringValue; 122 | 123 | static std::string tempResult; 124 | 125 | if(isInteger()) 126 | tempResult = numberToString(varValue.numericValue.integerValue); 127 | else if(isDouble()) 128 | tempResult = numberToString(varValue.numericValue.doubleValue); 129 | else if(isBoolean()) 130 | tempResult = numberToString(varValue.numericValue.booleanValue); 131 | else 132 | tempResult = ""; 133 | 134 | return tempResult; 135 | } 136 | 137 | int JSValue::toInteger() const 138 | { 139 | if(isString()) 140 | return stringToNumber(varValue.stringValue); 141 | else if(isInteger()) 142 | return varValue.numericValue.integerValue; 143 | else if(isDouble()) 144 | return (int)varValue.numericValue.doubleValue; 145 | else if(isBoolean()) 146 | return (int)varValue.numericValue.booleanValue; 147 | else 148 | return 0; 149 | } 150 | 151 | double JSValue::toDouble() const 152 | { 153 | if(isString()) 154 | return stringToNumber(varValue.stringValue); 155 | else if(isInteger()) 156 | return (double)varValue.numericValue.integerValue; 157 | else if(isDouble()) 158 | return varValue.numericValue.doubleValue; 159 | else if(isBoolean()) 160 | return (double)varValue.numericValue.booleanValue; 161 | else 162 | return 0; 163 | } 164 | 165 | bool JSValue::toBoolean() const 166 | { 167 | if(isString()) 168 | return stringToNumber(varValue.stringValue); 169 | else if(isInteger()) 170 | return !!varValue.numericValue.integerValue; 171 | else if(isDouble()) 172 | return !!static_cast(varValue.numericValue.doubleValue); 173 | else if(isBoolean()) 174 | return varValue.numericValue.booleanValue; 175 | else 176 | return false; 177 | } 178 | 179 | FutureJSValue::FutureJSValue() : source(0), requestID(0) 180 | { 181 | } 182 | 183 | FutureJSValue::~FutureJSValue() 184 | { 185 | } 186 | 187 | void FutureJSValue::init(WebView* source, int requestID) 188 | { 189 | this->source = source; 190 | this->requestID = requestID; 191 | } 192 | 193 | const JSValue& FutureJSValue::get() 194 | { 195 | if(requestID) 196 | { 197 | Awesomium::WebCore::Get().resolveJSValueFuture(source, requestID, &value); 198 | requestID = 0; 199 | } 200 | 201 | return value; 202 | } 203 | -------------------------------------------------------------------------------- /Awesomium/src/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ifeq ($(CHROMIUMDIR),) 3 | CHROMIUMDIR=../../../chromium/chromium 4 | endif 5 | 6 | ifeq ($(CHROMIUMMODE),) 7 | CHROMIUMMODE=Release 8 | endif 9 | 10 | ifeq ($(CHROMIUMMODE),Debug) 11 | DEBUGFLAGS=-D_DEBUG 12 | else 13 | DEBUGFLAGS=-DNDEBUG 14 | endif 15 | 16 | ifeq ($(ARCHFLAGS),) 17 | ARCHFLAGS=-m32 18 | endif 19 | 20 | ifeq ($(CHROMIUMBUILDER),make) 21 | #### make build system 22 | 23 | CHLIBS=$(CHROMIUMLIBPATH) 24 | ifeq ($(CHLIBS),) 25 | CHLIBS=$(CHROMIUMDIR)/src/out/$(CHROMIUMMODE)/obj 26 | endif 27 | 28 | LIBDIRS=. app base chrome net media webkit sandboxwebkit skia printing v8/tools/gyp sdch build/temp_gyp 29 | THIRDPARTYLIBDIRS=bzip2 ffmpeg harfbuzz hunspell icu38 libevent libjpeg libpng libxml libxslt lzma_sdk modp_b64 sqlite zlib 30 | 31 | CHROMIUMLDFLAGS=$(addprefix -L$(CHLIBS)/,$(LIBDIRS)) $(addprefix -L$(CHLIBS)/third_party/,$(THIRDPARTYLIBDIRS)) 32 | TPLIBS=-llibevent -lzlib -llibpng -llibxml -llibjpeg -llibxslt -lbzip2 33 | 34 | else 35 | #### scons build system 36 | 37 | ifeq ($(CHROMIUMLIBPATH),) 38 | CHROMIUMLIBPATH=$(CHROMIUMDIR)/src/sconsbuild/$(CHROMIUMMODE)/lib 39 | endif 40 | 41 | CHROMIUMLDFLAGS=-L$(CHROMIUMLIBPATH) 42 | TPLIBS=-levent -lxslt -ljpeg -lpng -lz -lxml2 -lbz2 43 | endif 44 | CHROMIUMLIBS=$(CHROMIUMLDFLAGS) $(TPLIBS) -lsmime3 -lplds4 -lplc4 -lnspr4 -lpthread -ldl -lgdk-x11-2.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lgio-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lfontconfig -lfreetype -lrt -lgconf-2 -lglib-2.0 -lX11 -lasound -lcommon -lbrowser -ldebugger -lrenderer -lutility -lprinting -lapp_base -lbase -licui18n -licuuc -licudata -lbase_gfx -lskia -llinux_versioninfo -lharfbuzz -lharfbuzz_interface -lnet -lgoogleurl -lsdch -lmodp_b64 -lv8_snapshot -lv8_base -lglue -lwebcore -lpcre -lwtf -lsqlite3 -lwebkit -lmedia -lffmpeg -lhunspell -lplugin 45 | 46 | # Flags that affect both compiling and linking 47 | CLIBFLAGS=$(ARCHFLAGS) -fvisibility=hidden -fvisibility-inlines-hidden -fPIC -pthread -Wall -fno-rtti 48 | 49 | CFLAGS=$(DEBUGFLAGS) $(CLIBFLAGS) -Wall -D_REENTRANT -D__STDC_FORMAT_MACROS -DCHROMIUM_BUILD -DU_STATIC_IMPLEMENTATION -g -I ../include `pkg-config --cflags gtk+-2.0 glib-2.0 gio-unix-2.0` $(addprefix -I$(CHROMIUMDIR)/src/,. third_party/npapi third_party/WebKit/JavaScriptCore third_party/icu38/public/common deps/third_party/icu42/public/common skia/config third_party/skia/include/core webkit/api/public third_party/WebKit/WebCore/platform/text) 50 | 51 | LIBS=-shared $(CLIBFLAGS) -g -Wl,--start-group `pkg-config --libs gtk+-2.0 glib-2.0 gio-unix-2.0 gconf-2.0` -lssl3 -lnss3 -lnssutil3 $(CHROMIUMLIBS) -Wl,--end-group 52 | 53 | SRCS=$(wildcard *.cpp) 54 | OBJS=$(SRCS:.cpp=.o) 55 | HEADERS=$(wildcard ../include/*.h) 56 | 57 | TARGET=../lib/libawesomium.so 58 | 59 | #all: mymain 60 | 61 | all: $(TARGET) 62 | 63 | $(TARGET): $(OBJS) 64 | @mkdir ../lib 2>/dev/null || true 65 | g++ $(OBJS) $(LIBS) -o $@ 66 | 67 | %.o: %.cpp $(HEADERS) 68 | g++ $(CFLAGS) -c $< -o $@ 69 | 70 | clean: 71 | rm -f $(OBJS) $(TARGET) 72 | 73 | mymain: $(OBJS) 74 | g++ $(CFLAGS) $(OBJS) $(LIBS) -o mymain 75 | 76 | -------------------------------------------------------------------------------- /Awesomium/src/PlatformUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #include "PlatformUtils.h" 27 | 28 | #ifndef SUPPRESS_LEAK_CHECKING 29 | #define SUPPRESS_LEAK_CHECKING 1 30 | #endif 31 | 32 | #if SUPPRESS_LEAK_CHECKING 33 | 34 | #ifdef _WIN32 35 | typedef int64 int46_t; 36 | typedef uint64 uint64_t; 37 | typedef int32 int32_t; 38 | typedef uint32 uint32_t; 39 | typedef int16 int16_t; 40 | typedef uint16 uint16_t; 41 | typedef int8 int8_t; 42 | typedef uint8 uint8_t; 43 | #endif 44 | 45 | #include "wtf/RefCountedLeakCounter.h" 46 | #endif 47 | 48 | void suppressLeakChecking() 49 | { 50 | #if SUPPRESS_LEAK_CHECKING 51 | WTF::RefCountedLeakCounter::suppressMessages("..."); 52 | #endif 53 | } 54 | 55 | #include "base/command_line.h" 56 | 57 | void Impl::initCommandLine() 58 | { 59 | const char* argv[] = { "Awesomium" }; 60 | CommandLine::Init(1, argv); 61 | } 62 | 63 | #if defined(__APPLE__) 64 | #include "AtomicString.h" 65 | #include "TextEncodingRegistry.h" 66 | #include "WebSystemInterface.h" 67 | #include "base/message_loop.h" 68 | 69 | void Impl::initWebCorePlatform() 70 | { 71 | //MessageLoopForUI main_message_loop; 72 | 73 | WebCore::AtomicString::init(); 74 | WebCore::atomicCanonicalTextEncodingName("fake"); 75 | InitWebCoreSystemInterface(); 76 | suppressLeakChecking(); 77 | } 78 | #else 79 | #include "AtomicString.h" 80 | #include "TextEncodingRegistry.h" 81 | void Impl::initWebCorePlatform() 82 | { 83 | WebCore::AtomicString::init(); 84 | WebCore::atomicCanonicalTextEncodingName("fake"); 85 | suppressLeakChecking(); 86 | } 87 | #endif 88 | -------------------------------------------------------------------------------- /Awesomium/src/PopupWidget.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #include "PopupWidget.h" 27 | #include "WebPopupMenu.h" 28 | #include "WebViewProxy.h" 29 | #include "WebSize.h" 30 | #include "WebRect.h" 31 | #include "WebScreenInfo.h" 32 | #include "skia/ext/platform_canvas.h" 33 | 34 | inline WebKit::WebCanvas *SkiaCanvasToWebCanvas (skia::PlatformCanvas *canvas) { 35 | #ifndef WEBKIT_USING_SKIA 36 | return canvas->getTopPlatformDevice().GetBitmapContext(); 37 | #else 38 | return canvas; 39 | #endif 40 | } 41 | 42 | PopupWidget::PopupWidget(WebViewProxy* parent) : parent(parent), canvas(0) 43 | { 44 | widget = WebKit::WebPopupMenu::create(this); 45 | } 46 | 47 | PopupWidget::~PopupWidget() 48 | { 49 | if(canvas) 50 | delete canvas; 51 | 52 | widget->close(); 53 | } 54 | 55 | WebWidget* PopupWidget::getWidget() 56 | { 57 | return widget; 58 | } 59 | 60 | void PopupWidget::renderToWebView(Awesomium::RenderBuffer* context, bool isParentTransparent) 61 | { 62 | if(mWindowRect.IsEmpty()) 63 | return; 64 | 65 | if(!canvas) 66 | canvas = new skia::PlatformCanvas(mWindowRect.width(), mWindowRect.height(), false); 67 | 68 | if(!dirtyArea.IsEmpty()) 69 | { 70 | widget->layout(); 71 | widget->paint(SkiaCanvasToWebCanvas(canvas), WebKit::WebRect(dirtyArea)); 72 | dirtyArea = gfx::Rect(); 73 | } 74 | 75 | const SkBitmap& sourceBitmap = canvas->getTopPlatformDevice().accessBitmap(false); 76 | SkAutoLockPixels sourceBitmapLock(sourceBitmap); 77 | 78 | context->copyArea((unsigned char*)sourceBitmap.getPixels(), sourceBitmap.rowBytes(), mWindowRect, isParentTransparent); 79 | 80 | } 81 | 82 | void PopupWidget::didScrollWebView(int dx, int dy) 83 | { 84 | if(mWindowRect.IsEmpty()) 85 | return; 86 | 87 | mWindowRect.Offset(dx, dy); 88 | } 89 | 90 | bool PopupWidget::isVisible() 91 | { 92 | return !mWindowRect.IsEmpty(); 93 | } 94 | 95 | void PopupWidget::translatePointRelative(int& x, int& y) 96 | { 97 | if(!mWindowRect.IsEmpty()) 98 | { 99 | x -= mWindowRect.x(); 100 | y -= mWindowRect.y(); 101 | } 102 | } 103 | 104 | // Called when a region of the WebWidget needs to be re-painted. 105 | void PopupWidget::didInvalidateRect(const WebKit::WebRect& rect) 106 | { 107 | gfx::Rect clientRect(mWindowRect.width(), mWindowRect.height()); 108 | dirtyArea = clientRect.Intersect(dirtyArea.Union(gfx::Rect(rect))); 109 | parent->invalidatePopups(); 110 | } 111 | 112 | // Called when a region of the WebWidget, given by clip_rect, should be 113 | // scrolled by the specified dx and dy amounts. 114 | void PopupWidget::didScrollRect(int dx, int dy, const WebKit::WebRect& clip_rect) 115 | { 116 | WebKit::WebSize size = widget->size(); 117 | dirtyArea = gfx::Rect(size.width, size.height); 118 | parent->invalidatePopups(); 119 | } 120 | 121 | // This method is called to instruct the window containing the WebWidget to 122 | // show itself as the topmost window. This method is only used after a 123 | // successful call to CreateWebWidget. |disposition| indicates how this new 124 | // window should be displayed, but generally only means something for WebViews. 125 | void PopupWidget::show(WebKit::WebNavigationPolicy policy) 126 | { 127 | } 128 | 129 | // This method is called to instruct the window containing the WebWidget to 130 | // close. Note: This method should just be the trigger that causes the 131 | // WebWidget to eventually close. It should not actually be destroyed until 132 | // after this call returns. 133 | void PopupWidget::closeWidgetSoon() 134 | { 135 | MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(parent, &WebViewProxy::closePopup, this)); 136 | } 137 | 138 | // This method is called to focus the window containing the WebWidget so 139 | // that it receives keyboard events. 140 | void PopupWidget::didFocus() { widget->setFocus(true); } 141 | 142 | // This method is called to unfocus the window containing the WebWidget so that 143 | // it no longer receives keyboard events. 144 | void PopupWidget::didBlur() { widget->setFocus(false); } 145 | 146 | void PopupWidget::didChangeCursor(const WebKit::WebCursorInfo& cursor) { 147 | } 148 | 149 | // Returns the rectangle of the WebWidget in screen coordinates. 150 | WebKit::WebRect PopupWidget::windowRect() 151 | { 152 | return WebKit::WebRect(mWindowRect); 153 | } 154 | 155 | // This method is called to re-position the WebWidget on the screen. The given 156 | // rect is in screen coordinates. The implementation may choose to ignore 157 | // this call or modify the given rect. This method may be called before Show 158 | // has been called. 159 | // TODO(darin): this is more of a request; does this need to take effect 160 | // synchronously? 161 | void PopupWidget::setWindowRect(const WebKit::WebRect& rect) 162 | { 163 | mWindowRect = gfx::Rect(rect); 164 | widget->resize(WebKit::WebSize(rect.width, rect.height)); 165 | dirtyArea = dirtyArea.Union(gfx::Rect(rect.width, rect.height)); 166 | } 167 | 168 | // Returns the rectangle of the window in which this WebWidget is embeded in. 169 | WebKit::WebRect PopupWidget::rootWindowRect() 170 | { 171 | return parent->windowRect(); 172 | } 173 | 174 | WebKit::WebRect PopupWidget::windowResizerRect() 175 | { 176 | return windowRect(); 177 | } 178 | 179 | // Suppress input events to other windows, and do not return until the widget 180 | // is closed. This is used to support |window.showModalDialog|. 181 | void PopupWidget::runModal() {} 182 | 183 | WebKit::WebScreenInfo PopupWidget::screenInfo() { 184 | WebKit::WebScreenInfo ret; 185 | ret.availableRect = WebKit::WebRect(0,0,1024,768); // PRHFIXME: Huge hack, hardcode some screen size here. 186 | ret.depth = 24; 187 | ret.isMonochrome = false; 188 | ret.depthPerComponent = 8; 189 | ret.rect = WebKit::WebRect(0,0,1024,768); 190 | return ret; 191 | } 192 | -------------------------------------------------------------------------------- /Awesomium/src/RenderBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #include "RenderBuffer.h" 27 | #include 28 | #include 29 | #include "base/gfx/rect.h" 30 | 31 | using namespace Awesomium; 32 | 33 | void Awesomium::copyBuffers(int width, int height, unsigned char* src, int srcRowSpan, unsigned char* dest, int destRowSpan, int destDepth, bool convertToRGBA) 34 | { 35 | assert(destDepth == 3 || destDepth == 4); 36 | 37 | if(!convertToRGBA) 38 | { 39 | if(destDepth == 3) 40 | { 41 | for(int row = 0; row < height; row++) 42 | for(int col = 0; col < width; col++) 43 | memcpy(dest + row * destRowSpan + col * 3, src + row * srcRowSpan + col * 4, 3); 44 | } 45 | else if(destDepth == 4) 46 | { 47 | for(int row = 0; row < height; row++) 48 | memcpy(dest + row * destRowSpan, src + row * srcRowSpan, srcRowSpan); 49 | } 50 | } 51 | else 52 | { 53 | if(destDepth == 3) 54 | { 55 | int srcRowOffset, destRowOffset; 56 | for(int row = 0; row < height; row++) 57 | { 58 | srcRowOffset = row * srcRowSpan; 59 | destRowOffset = row * destRowSpan; 60 | 61 | for(int col = 0; col < width; col++) 62 | { 63 | dest[destRowOffset + col * 3] = src[srcRowOffset + col * 4 + 2]; 64 | dest[destRowOffset + col * 3 + 1] = src[srcRowOffset + col * 4 + 1]; 65 | dest[destRowOffset + col * 3 + 2] = src[srcRowOffset + col * 4]; 66 | } 67 | } 68 | } 69 | else if(destDepth == 4) 70 | { 71 | int srcRowOffset, destRowOffset; 72 | for(int row = 0; row < height; row++) 73 | { 74 | srcRowOffset = row * srcRowSpan; 75 | destRowOffset = row * destRowSpan; 76 | 77 | for(int colOffset = 0; colOffset < srcRowSpan; colOffset += 4) 78 | { 79 | dest[destRowOffset + colOffset] = src[srcRowOffset + colOffset + 2]; 80 | dest[destRowOffset + colOffset + 1] = src[srcRowOffset + colOffset + 1]; 81 | dest[destRowOffset + colOffset + 2] = src[srcRowOffset + colOffset]; 82 | dest[destRowOffset + colOffset + 3] = src[srcRowOffset + colOffset + 3]; 83 | } 84 | } 85 | } 86 | } 87 | } 88 | 89 | RenderBuffer::RenderBuffer(int width, int height) : buffer(0), width(0), height(0), rowSpan(0) 90 | { 91 | reserve(width, height); 92 | } 93 | 94 | RenderBuffer::~RenderBuffer() 95 | { 96 | if(buffer) 97 | delete[] buffer; 98 | } 99 | 100 | void RenderBuffer::reserve(int width, int height) 101 | { 102 | if(this->width != width || this->height != height) 103 | { 104 | this->width = width; 105 | this->height = height; 106 | 107 | rowSpan = width * 4; 108 | 109 | if(buffer) 110 | delete[] buffer; 111 | 112 | buffer = new unsigned char[width * height * 4]; 113 | memset(buffer, 255, width * height * 4); 114 | } 115 | } 116 | 117 | void RenderBuffer::copyFrom(unsigned char* srcBuffer, int srcRowSpan) 118 | { 119 | for(int row = 0; row < height; row++) 120 | memcpy(buffer + row * rowSpan, srcBuffer + row * srcRowSpan, rowSpan); 121 | } 122 | 123 | void RenderBuffer::copyArea(unsigned char* srcBuffer, int srcRowSpan, const gfx::Rect& srcRect, bool forceOpaque) 124 | { 125 | if(gfx::Rect(width, height).Contains(srcRect)) 126 | { 127 | for(int row = 0; row < srcRect.height(); row++) 128 | memcpy(buffer + (row + srcRect.y()) * rowSpan + (srcRect.x() * 4), srcBuffer + row * srcRowSpan, srcRect.width() * 4); 129 | 130 | if(forceOpaque) 131 | for(int row = 0; row < srcRect.height(); row++) 132 | for(int col = 0; col < srcRect.width(); col++) 133 | buffer[(row + srcRect.y()) * rowSpan + (col + srcRect.x()) * 4 + 3] = 255; 134 | } 135 | else 136 | { 137 | gfx::Rect intersect = gfx::Rect(width, height).Intersect(srcRect); 138 | if(intersect.IsEmpty()) 139 | return; 140 | 141 | int srcOffsetX = intersect.x() - srcRect.x(); 142 | int srcOffsetY = intersect.y() - srcRect.y(); 143 | 144 | for(int row = 0; row < intersect.height(); row++) 145 | memcpy(buffer + (row + intersect.y()) * rowSpan + (intersect.x() * 4), srcBuffer + (row + srcOffsetY) * srcRowSpan + (srcOffsetX * 4), intersect.width() * 4); 146 | 147 | if(forceOpaque) 148 | for(int row = 0; row < intersect.height(); row++) 149 | for(int col = 0; col < intersect.width(); col++) 150 | buffer[(row + intersect.y()) * rowSpan + (col + intersect.x()) * 4 + 3] = 255; 151 | } 152 | } 153 | 154 | void RenderBuffer::copyTo(unsigned char* destBuffer, int destRowSpan, int destDepth, bool convertToRGBA) 155 | { 156 | copyBuffers(width, height, buffer, width * 4, destBuffer, destRowSpan, destDepth, convertToRGBA); 157 | } 158 | -------------------------------------------------------------------------------- /Awesomium/src/RequestContext.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "RequestContext.h" 6 | #include "net/base/host_resolver_impl.h" 7 | #include "net/base/host_resolver.h" 8 | #include "net/base/cookie_monster.h" 9 | #include "net/proxy/proxy_service.h" 10 | #include "webkit/glue/webkit_glue.h" 11 | 12 | TestShellRequestContext::TestShellRequestContext() { 13 | Init(std::wstring(), net::HttpCache::NORMAL, false); 14 | } 15 | 16 | TestShellRequestContext::TestShellRequestContext( 17 | const std::wstring& cache_path, 18 | net::HttpCache::Mode cache_mode, 19 | bool no_proxy) { 20 | Init(cache_path, cache_mode, no_proxy); 21 | } 22 | 23 | void TestShellRequestContext::Init( 24 | const std::wstring& cache_path, 25 | net::HttpCache::Mode cache_mode, 26 | bool no_proxy) { 27 | cookie_store_ = new net::CookieMonster(); 28 | 29 | // hard-code A-L and A-C for test shells 30 | accept_language_ = "en-us,en"; 31 | accept_charset_ = "iso-8859-1,*,utf-8"; 32 | 33 | /* 34 | net::ProxyInfo proxy_info; 35 | proxy_info.UseDirect(); 36 | proxy_service_ = net::ProxyService::Create(no_proxy ? &proxy_info : NULL); 37 | */ 38 | proxy_service_ = net::ProxyService::CreateNull(); //PRHFIXME: Ideally shouldn't be null. 39 | net::HttpCache *cache; 40 | net::SSLConfigService *ssl_config_service = net::SSLConfigService::CreateSystemSSLConfigService(); 41 | if (cache_path.empty()) { 42 | cache = new net::HttpCache(net::CreateSystemHostResolver(), proxy_service_, ssl_config_service, 0); 43 | } else { 44 | cache = new net::HttpCache(net::CreateSystemHostResolver(), proxy_service_, ssl_config_service, cache_path, 0); 45 | } 46 | cache->set_mode(cache_mode); 47 | http_transaction_factory_ = cache; 48 | } 49 | 50 | TestShellRequestContext::~TestShellRequestContext() { 51 | delete cookie_store_; 52 | delete http_transaction_factory_; 53 | delete proxy_service_; 54 | } 55 | 56 | const std::string& TestShellRequestContext::GetUserAgent( 57 | const GURL& url) const { 58 | return webkit_glue::GetUserAgent(url); 59 | } 60 | -------------------------------------------------------------------------------- /Awesomium/src/WebCore.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #include "WebCore.h" 27 | #include "WebCoreProxy.h" 28 | #include "WebViewEvent.h" 29 | #include "base/lock.h" 30 | #include "base/thread.h" 31 | #include "base/at_exit.h" 32 | #include "base/path_service.h" 33 | #include "base/file_util.h" 34 | #include "base/message_loop.h" 35 | 36 | Awesomium::WebCore* Awesomium::WebCore::instance = 0; 37 | static MessageLoop* messageLoop = 0; 38 | 39 | namespace Awesomium { 40 | 41 | WebCore::WebCore(LogLevel level, bool enablePlugins, PixelFormat pixelFormat ) : pluginsEnabled(enablePlugins), pixelFormat(pixelFormat) 42 | { 43 | assert(!instance); 44 | instance = this; 45 | 46 | logOpen = level != LOG_NONE; 47 | 48 | atExitMgr = new base::AtExitManager(); 49 | 50 | Impl::initCommandLine(); 51 | 52 | if(logOpen) 53 | { 54 | FilePath log_filename; 55 | PathService::Get(base::DIR_EXE, &log_filename); 56 | log_filename = log_filename.Append(FILE_PATH_LITERAL("awesomium.log")); 57 | logging::InitLogging(log_filename.value().c_str(), 58 | level == LOG_VERBOSE ? logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG : logging::LOG_ONLY_TO_FILE, 59 | logging::LOCK_LOG_FILE, logging::DELETE_OLD_LOG_FILE); 60 | } 61 | 62 | if(level == LOG_NORMAL) 63 | logging::SetMinLogLevel(logging::LOG_WARNING); 64 | else if(level == LOG_VERBOSE) 65 | logging::SetMinLogLevel(logging::LOG_INFO); 66 | else if(level == LOG_NONE) 67 | logging::SetMinLogLevel(logging::LOG_NUM_SEVERITIES); 68 | 69 | eventQueueLock = new Lock(); 70 | baseDirLock = new Lock(); 71 | customResponsePageLock = new Lock(); 72 | 73 | messageLoop = new MessageLoop(); 74 | 75 | LOG(INFO) << "Creating the core thread."; 76 | coreThread = new base::Thread("CoreThread"); 77 | #if defined(_WIN32) 78 | // An internal message loop type of UI seems to be required on 79 | // Windows for proper clipboard functionality 80 | coreThread->StartWithOptions(base::Thread::Options(MessageLoop::TYPE_UI, 0)); 81 | #else 82 | coreThread->Start(); 83 | #endif 84 | 85 | LOG(INFO) << "Creating the WebCore."; 86 | coreProxy = new WebCoreProxy(coreThread, pluginsEnabled); 87 | Impl::initWebCorePlatform(); 88 | coreProxy->AddRef(); 89 | coreProxy->startup(); 90 | } 91 | 92 | WebCore::~WebCore() 93 | { 94 | assert(instance); 95 | 96 | if(views.size()) 97 | { 98 | std::vector viewsToDestroy(views); 99 | 100 | for(std::vector::iterator i = viewsToDestroy.begin(); i != viewsToDestroy.end();) 101 | { 102 | (*i)->destroy(); 103 | i = viewsToDestroy.erase(i); 104 | } 105 | } 106 | 107 | messageLoop->RunAllPending(); 108 | delete messageLoop; 109 | 110 | LOG(INFO) << "Releasing the WebCore soon."; 111 | coreThread->message_loop()->ReleaseSoon(FROM_HERE, coreProxy); 112 | LOG(INFO) << "Destroying the core thread."; 113 | delete coreThread; 114 | LOG(INFO) << "The core thread has been destroyed."; 115 | delete customResponsePageLock; 116 | delete eventQueueLock; 117 | delete baseDirLock; 118 | 119 | LOG(INFO) << "The WebCore has been shutdown."; 120 | 121 | if(logOpen) 122 | logging::CloseLogFile(); 123 | 124 | delete atExitMgr; 125 | 126 | instance = 0; 127 | } 128 | 129 | WebCore& WebCore::Get() 130 | { 131 | assert(instance); 132 | 133 | return *instance; 134 | } 135 | 136 | WebCore* WebCore::GetPointer() 137 | { 138 | return instance; 139 | } 140 | 141 | void WebCore::setBaseDirectory(const std::string& baseDirectory) 142 | { 143 | AutoLock autoBaseDirLock(*baseDirLock); 144 | 145 | this->baseDirectory = baseDirectory; 146 | 147 | if(this->baseDirectory.size()) 148 | if(this->baseDirectory[this->baseDirectory.size() - 1] != '\\') 149 | this->baseDirectory += "\\"; 150 | } 151 | 152 | Awesomium::WebView* WebCore::createWebView(int width, int height, bool isTransparent, bool enableAsyncRendering, int maxAsyncRenderPerSec) 153 | { 154 | Awesomium::WebView* view = new Awesomium::WebView(width, height, isTransparent, enableAsyncRendering, maxAsyncRenderPerSec, coreThread); 155 | 156 | views.push_back(view); 157 | 158 | view->startup(); 159 | 160 | return view; 161 | } 162 | 163 | void WebCore::setCustomResponsePage(int statusCode, const std::string& filePath) 164 | { 165 | AutoLock autoCustomResponsePageLock(*customResponsePageLock); 166 | 167 | customResponsePageMap[statusCode] = filePath; 168 | } 169 | 170 | void WebCore::update() 171 | { 172 | messageLoop->RunAllPending(); 173 | std::deque eventQueueCopy; 174 | 175 | { 176 | AutoLock autoQueueLock(*eventQueueLock); 177 | eventQueue.swap(eventQueueCopy); 178 | } 179 | 180 | while(!eventQueueCopy.empty()) 181 | { 182 | WebViewEvent* event = eventQueueCopy.front(); 183 | event->run(); 184 | delete event; 185 | 186 | eventQueueCopy.pop_front(); 187 | } 188 | } 189 | 190 | const std::string& WebCore::getBaseDirectory() const 191 | { 192 | AutoLock autoBaseDirLock(*baseDirLock); 193 | 194 | return baseDirectory; 195 | } 196 | 197 | PixelFormat WebCore::getPixelFormat() const 198 | { 199 | return pixelFormat; 200 | } 201 | 202 | bool WebCore::arePluginsEnabled() const 203 | { 204 | return pluginsEnabled; 205 | } 206 | 207 | void WebCore::pause() 208 | { 209 | coreProxy->pause(); 210 | } 211 | 212 | void WebCore::resume() 213 | { 214 | coreProxy->resume(); 215 | } 216 | 217 | void WebCore::queueEvent(WebViewEvent* event) 218 | { 219 | AutoLock autoQueueLock(*eventQueueLock); 220 | 221 | eventQueue.push_front(event); 222 | } 223 | 224 | void WebCore::removeWebView(WebView* view) 225 | { 226 | // Parse event queue in case one of the events references this view 227 | update(); 228 | 229 | for(std::vector::iterator i = views.begin(); i != views.end(); i++) 230 | { 231 | if((*i) == view) 232 | { 233 | views.erase(i); 234 | break; 235 | } 236 | } 237 | } 238 | 239 | void WebCore::purgePluginMessages() 240 | { 241 | if(pluginsEnabled) 242 | coreProxy->purgePluginMessages(); 243 | } 244 | 245 | void WebCore::resolveJSValueFuture(WebView* view, int requestID, JSValue* result) 246 | { 247 | for(std::vector::iterator i = views.begin(); i != views.end(); i++) 248 | { 249 | if((*i) == view) 250 | { 251 | view->resolveJSValueFuture(requestID, result); 252 | return; 253 | } 254 | } 255 | } 256 | 257 | void WebCore::getCustomResponsePage(int statusCode, std::string& filePathResult) 258 | { 259 | AutoLock autoCustomResponsePageLock(*customResponsePageLock); 260 | 261 | std::map::iterator i = customResponsePageMap.find(statusCode); 262 | 263 | if(i != customResponsePageMap.end()) 264 | filePathResult = i->second; 265 | else 266 | filePathResult = ""; 267 | } 268 | 269 | } 270 | 271 | -------------------------------------------------------------------------------- /Awesomium/src/WebCoreProxy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #include "WebCoreProxy.h" 27 | #include "base/thread.h" 28 | #include "ResourceLoaderBridge.h" 29 | #include "RequestContext.h" 30 | #include "base/icu_util.h" 31 | #include "WebData.h" 32 | #include "WebClipboard.h" 33 | #include 34 | #include "media/base/media.h" 35 | #include "base/string_util.h" 36 | #include "base/path_service.h" 37 | #if defined(WIN32) 38 | #include "base/resource_util.h" 39 | #include "net/base/net_module.h" 40 | StringPiece NetResourceProvider(int key); 41 | #elif defined(__APPLE__) 42 | #include 43 | void initMacApplication(); 44 | #endif 45 | 46 | // PRHFIXME: Unimplemented. 47 | class WebCoreProxy::Clipboard: public WebKit::WebClipboard { 48 | WebCoreProxy *proxy; 49 | public: 50 | Clipboard(WebCoreProxy *proxy) : proxy(proxy) { 51 | } 52 | typedef WebKit::WebString WebString; 53 | bool isFormatAvailable(Format fmt) { 54 | return false; 55 | } 56 | WebString readPlainText() { 57 | return WebString(); 58 | } 59 | WebString readHTML(WebKit::WebURL*weburl) { 60 | *weburl = WebKit::WebURL(); 61 | return WebString(); 62 | } 63 | void writeHTML( 64 | const WebString& htmlText, const WebKit::WebURL&, 65 | const WebString& plainText, bool writeSmartPaste) { 66 | } 67 | virtual void writeURL( 68 | const WebKit::WebURL&, const WebString& title) { 69 | } 70 | virtual void writeImage( 71 | const WebKit::WebImage&, const WebKit::WebURL&, const WebString& title) { 72 | } 73 | }; 74 | 75 | WebCoreProxy::WebCoreProxy(base::Thread* coreThread, bool pluginsEnabled) : coreThread(coreThread), 76 | pluginsEnabled(pluginsEnabled), threadWaitEvent(false, false), pauseRequestEvent(false, false) 77 | { 78 | static bool icuLoaded = false; 79 | 80 | // This is necessary if the WebCoreProxy is created twice during a program's lifecycle 81 | // because ICU will assert if it is initialized twice. 82 | if(!icuLoaded) 83 | { 84 | if(icu_util::Initialize()) 85 | { 86 | LOG(INFO) << "ICU successfully initialized."; 87 | icuLoaded = true; 88 | } 89 | else 90 | { 91 | LOG(ERROR) << "ICU failed initialization! Have you forgotten to include the DLL?"; 92 | } 93 | } 94 | webclipboard = new Clipboard(this); 95 | 96 | WebKit::initialize(this); 97 | FilePath module_path; 98 | bool initialized_media_library = 99 | PathService::Get(base::DIR_MODULE, &module_path) && 100 | media::InitializeMediaLibrary(module_path); 101 | if (initialized_media_library) { 102 | LOG(INFO) << "Media library successfully initialized"; 103 | WebKit::enableMediaPlayer(); 104 | } else { 105 | LOG(ERROR) << "Failed to initialize media library! Check that avcodec, avutil and avformat are in the same directory as the executable."; 106 | } 107 | } 108 | 109 | WebCoreProxy::~WebCoreProxy() 110 | { 111 | LOG(INFO) << "Destroying the WebCore."; 112 | 113 | #if defined(WIN32) 114 | if(pluginsEnabled) 115 | { 116 | throttledMessages.clear(); 117 | 118 | MSG msg; 119 | while(PeekMessage(&msg, 0, NULL, NULL, PM_REMOVE)) {} 120 | 121 | pluginMessageTimer.Stop(); 122 | } 123 | #endif 124 | 125 | LOG(INFO) << "Shutting down Resource Loader Bridge."; 126 | SimpleResourceLoaderBridge::Shutdown(); 127 | } 128 | 129 | void WebCoreProxy::startup() 130 | { 131 | coreThread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &WebCoreProxy::asyncStartup)); 132 | } 133 | 134 | void WebCoreProxy::pause() 135 | { 136 | coreThread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &WebCoreProxy::asyncPause)); 137 | pauseRequestEvent.Wait(); 138 | } 139 | 140 | void WebCoreProxy::asyncPause() 141 | { 142 | //PlatformThread::Sleep(5); 143 | pauseRequestEvent.Signal(); 144 | threadWaitEvent.Wait(); 145 | } 146 | 147 | void WebCoreProxy::resume() 148 | { 149 | threadWaitEvent.Signal(); 150 | } 151 | 152 | bool WebCoreProxy::sandboxEnabled() { 153 | return false; 154 | } 155 | 156 | WebKit::WebMimeRegistry* WebCoreProxy::mimeRegistry() 157 | { 158 | return &mime_registry_; 159 | } 160 | 161 | WebKit::WebSandboxSupport* WebCoreProxy::sandboxSupport() 162 | { 163 | return NULL; 164 | } 165 | 166 | unsigned long long WebCoreProxy::visitedLinkHash(const char* canonicalURL, size_t length) 167 | { 168 | return 0; 169 | } 170 | 171 | bool WebCoreProxy::isLinkVisited(unsigned long long linkHash) 172 | { 173 | return false; 174 | } 175 | 176 | void WebCoreProxy::setCookies(const WebKit::WebURL& url, const WebKit::WebURL& policy_url, 177 | const WebKit::WebString& value) 178 | { 179 | SimpleResourceLoaderBridge::SetCookie(url, policy_url, UTF16ToUTF8(value)); 180 | } 181 | 182 | WebKit::WebString WebCoreProxy::cookies(const WebKit::WebURL& url, const WebKit::WebURL& policy_url) 183 | { 184 | return UTF8ToUTF16(SimpleResourceLoaderBridge::GetCookies(url, policy_url)); 185 | } 186 | 187 | void WebCoreProxy::prefetchHostName(const WebKit::WebString&) 188 | { 189 | } 190 | 191 | WebKit::WebMessagePortChannel* 192 | WebCoreProxy::createMessagePortChannel() { 193 | NOTREACHED(); 194 | return NULL; 195 | } 196 | WebKit::WebStorageNamespace* 197 | WebCoreProxy::createLocalStorageNamespace( 198 | const WebKit::WebString& path) { 199 | // The "WebStorage" interface is used for renderer WebKit -> browser WebKit 200 | // communication only. "WebStorageClient" will be used for browser WebKit -> 201 | // renderer WebKit. So this will never be implemented. 202 | NOTREACHED(); 203 | return 0; 204 | } 205 | 206 | WebKit::WebStorageNamespace* 207 | WebCoreProxy::createSessionStorageNamespace() { 208 | // The "WebStorage" interface is used for renderer WebKit -> browser WebKit 209 | // communication only. "WebStorageClient" will be used for browser WebKit -> 210 | // renderer WebKit. So this will never be implemented. 211 | NOTREACHED(); 212 | return 0; 213 | } 214 | 215 | WebKit::WebClipboard *WebCoreProxy::clipboard() { 216 | return webclipboard; 217 | } 218 | 219 | WebKit::WebData WebCoreProxy::loadResource(const char* name) 220 | { 221 | if (!strcmp(name, "deleteButton")) { 222 | // Create a red 30x30 square. 223 | const char red_square[] = 224 | "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" 225 | "\x00\x00\x00\x1e\x00\x00\x00\x1e\x04\x03\x00\x00\x00\xc9\x1e\xb3" 226 | "\x91\x00\x00\x00\x30\x50\x4c\x54\x45\x00\x00\x00\x80\x00\x00\x00" 227 | "\x80\x00\x80\x80\x00\x00\x00\x80\x80\x00\x80\x00\x80\x80\x80\x80" 228 | "\x80\xc0\xc0\xc0\xff\x00\x00\x00\xff\x00\xff\xff\x00\x00\x00\xff" 229 | "\xff\x00\xff\x00\xff\xff\xff\xff\xff\x7b\x1f\xb1\xc4\x00\x00\x00" 230 | "\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a" 231 | "\x9c\x18\x00\x00\x00\x17\x49\x44\x41\x54\x78\x01\x63\x98\x89\x0a" 232 | "\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d" 233 | "\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60" 234 | "\x82"; 235 | return WebKit::WebData(red_square, arraysize(red_square)); 236 | } 237 | return webkit_glue::WebKitClientImpl::loadResource(name); 238 | } 239 | 240 | WebKit::WebString WebCoreProxy::defaultLocale() 241 | { 242 | return ASCIIToUTF16("en-US"); 243 | } 244 | 245 | void WebCoreProxy::asyncStartup() 246 | { 247 | SimpleResourceLoaderBridge::Init(new TestShellRequestContext()); 248 | 249 | #if defined(WIN32) 250 | net::NetModule::SetResourceProvider(NetResourceProvider); 251 | #elif defined(__APPLE__) 252 | initMacApplication(); 253 | #endif 254 | 255 | if(pluginsEnabled) 256 | pluginMessageTimer.Start(base::TimeDelta::FromMilliseconds(10), this, &WebCoreProxy::pumpPluginMessages); 257 | 258 | LOG(INFO) << "The WebCore is now online."; 259 | } 260 | 261 | void WebCoreProxy::pumpPluginMessages() 262 | { 263 | #if defined(WIN32) 264 | MSG msg; 265 | 266 | while(PeekMessage(&msg, 0, NULL, NULL, PM_REMOVE)) 267 | { 268 | if(msg.message == WM_USER + 1) 269 | { 270 | throttledMessages.push_back(msg); 271 | 272 | if(throttledMessages.size() == 1) 273 | coreThread->message_loop()->PostDelayedTask(FROM_HERE, NewRunnableMethod(this, &WebCoreProxy::pumpThrottledMessages), 5); 274 | } 275 | else 276 | { 277 | TranslateMessage(&msg); 278 | DispatchMessage(&msg); 279 | } 280 | } 281 | #elif defined(__APPLE__) 282 | /* 283 | // OSX Message Pump 284 | EventRef event = NULL; 285 | EventTargetRef targetWindow; 286 | targetWindow = GetEventDispatcherTarget(); 287 | 288 | // If we are unable to get the target then we no longer care about events. 289 | if( !targetWindow ) return; 290 | 291 | // Grab the next event, process it if it is a window event 292 | if( ReceiveNextEvent( 0, NULL, kEventDurationNoWait, true, &event ) == noErr ) 293 | { 294 | printf("OSM> Class: %d, Kind: %d\n", GetEventClass(event), GetEventKind(event)); 295 | // Dispatch the event 296 | SendEventToEventTarget( event, targetWindow ); 297 | ReleaseEvent( event ); 298 | } 299 | */ 300 | #endif 301 | } 302 | 303 | void WebCoreProxy::pumpThrottledMessages() 304 | { 305 | #if defined(WIN32) 306 | if(!throttledMessages.size()) 307 | return; 308 | 309 | MSG msg = throttledMessages.back(); 310 | throttledMessages.pop_back(); 311 | 312 | TranslateMessage(&msg); 313 | DispatchMessage(&msg); 314 | 315 | if(throttledMessages.size()) 316 | coreThread->message_loop()->PostDelayedTask(FROM_HERE, NewRunnableMethod(this, &WebCoreProxy::pumpThrottledMessages), 5); 317 | #endif 318 | } 319 | 320 | void WebCoreProxy::purgePluginMessages() 321 | { 322 | #if defined(WIN32) 323 | throttledMessages.clear(); 324 | 325 | MSG msg; 326 | while(PeekMessage(&msg, 0, NULL, NULL, PM_REMOVE)) 327 | { 328 | } 329 | #endif 330 | } 331 | 332 | #if defined(WIN32) 333 | StringPiece NetResourceProvider(int key) 334 | { 335 | void* data_ptr; 336 | size_t data_size; 337 | 338 | return base::GetDataResourceFromModule(::GetModuleHandle(0), key, &data_ptr, &data_size) ? 339 | std::string(static_cast(data_ptr), data_size) : std::string(); 340 | } 341 | #endif 342 | -------------------------------------------------------------------------------- /Awesomium/src/WebViewEvent.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #include "WebViewEvent.h" 27 | #include "WebViewProxy.h" 28 | 29 | WebViewEvent::WebViewEvent(Awesomium::WebView* view) : view(view) 30 | { 31 | } 32 | 33 | using namespace WebViewEvents; 34 | 35 | BeginLoad::BeginLoad(Awesomium::WebView* view, const std::string& url, const std::wstring& frameName, int statusCode, const std::wstring& mimeType) : WebViewEvent(view), 36 | url(url), frameName(frameName), statusCode(statusCode), mimeType(mimeType) 37 | { 38 | } 39 | 40 | void BeginLoad::run() 41 | { 42 | Awesomium::WebViewListener* listener = view->getListener(); 43 | 44 | if(listener) 45 | listener->onBeginLoading(url, frameName, statusCode, mimeType); 46 | } 47 | 48 | FinishLoad::FinishLoad(Awesomium::WebView* view) : WebViewEvent(view) 49 | { 50 | } 51 | 52 | void FinishLoad::run() 53 | { 54 | Awesomium::WebViewListener* listener = view->getListener(); 55 | 56 | if(listener) 57 | listener->onFinishLoading(); 58 | } 59 | 60 | BeginNavigate::BeginNavigate(Awesomium::WebView* view, const std::string& url, const std::wstring& frameName) : WebViewEvent(view), url(url), frameName(frameName) 61 | { 62 | } 63 | 64 | void BeginNavigate::run() 65 | { 66 | Awesomium::WebViewListener* listener = view->getListener(); 67 | 68 | if(listener) 69 | listener->onBeginNavigation(url, frameName); 70 | } 71 | 72 | ReceiveTitle::ReceiveTitle(Awesomium::WebView* view, const std::wstring& title, const std::wstring& frameName) : WebViewEvent(view), title(title), frameName(frameName) 73 | { 74 | } 75 | 76 | void ReceiveTitle::run() 77 | { 78 | Awesomium::WebViewListener* listener = view->getListener(); 79 | 80 | if(listener) 81 | listener->onReceiveTitle(title, frameName); 82 | } 83 | 84 | InvokeCallback::InvokeCallback(Awesomium::WebView* view, const std::string& name, const Awesomium::JSArguments& args) : WebViewEvent(view), 85 | name(name), args(args) 86 | { 87 | } 88 | 89 | void InvokeCallback::run() 90 | { 91 | Awesomium::WebViewListener* listener = view->getListener(); 92 | 93 | if(listener) 94 | listener->onCallback(name, args); 95 | } 96 | 97 | ChangeTooltip::ChangeTooltip(Awesomium::WebView* view, const std::wstring& tooltip) : WebViewEvent(view), tooltip(tooltip) 98 | { 99 | } 100 | 101 | void ChangeTooltip::run() 102 | { 103 | Awesomium::WebViewListener* listener = view->getListener(); 104 | 105 | if(listener) 106 | listener->onChangeTooltip(tooltip); 107 | } 108 | 109 | #if defined(_WIN32) 110 | 111 | ChangeCursor::ChangeCursor(Awesomium::WebView* view, const HCURSOR& cursor) : WebViewEvent(view), cursor(cursor) 112 | { 113 | } 114 | 115 | void ChangeCursor::run() 116 | { 117 | Awesomium::WebViewListener* listener = view->getListener(); 118 | 119 | if(listener) 120 | listener->onChangeCursor(cursor); 121 | } 122 | 123 | #endif 124 | 125 | ChangeKeyboardFocus::ChangeKeyboardFocus(Awesomium::WebView* view, bool isFocused) : WebViewEvent(view), isFocused(isFocused) 126 | { 127 | } 128 | 129 | void ChangeKeyboardFocus::run() 130 | { 131 | Awesomium::WebViewListener* listener = view->getListener(); 132 | 133 | if(listener) 134 | listener->onChangeKeyboardFocus(isFocused); 135 | } 136 | 137 | ChangeTargetURL::ChangeTargetURL(Awesomium::WebView* view, const std::string& url) : WebViewEvent(view), url(url) 138 | { 139 | } 140 | 141 | void ChangeTargetURL::run() 142 | { 143 | Awesomium::WebViewListener* listener = view->getListener(); 144 | 145 | if(listener) 146 | listener->onChangeTargetURL(url); 147 | } 148 | 149 | -------------------------------------------------------------------------------- /Awesomium/src/WebkitGlue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Awesomium, a library that makes it easy for 3 | developers to embed web-content in their applications. 4 | 5 | Copyright (C) 2009 Adam J. Simmons 6 | 7 | Project Website: 8 | 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | 02110-1301 USA 24 | */ 25 | 26 | #include "base/logging.h" 27 | #include "base/path_service.h" 28 | #include "base/file_util.h" 29 | #include "net/base/mime_util.h" 30 | #include "webkit/glue/webkit_glue.h" 31 | #include "webkit/glue/plugins/plugin_list.h" 32 | #include "googleurl/src/gurl.h" 33 | #include "WebCore.h" 34 | #include "base/clipboard.h" 35 | #include "base/lazy_instance.h" 36 | #include "googleurl/src/gurl.h" 37 | #include "webkit/glue/scoped_clipboard_writer_glue.h" 38 | #include "SkBitmap.h" 39 | #include "base/string16.h" 40 | #include "base/string_util.h" 41 | 42 | #if defined(_WIN32) 43 | #pragma warning( disable: 4996 ) 44 | #endif 45 | 46 | std::wstring stringToWide(const std::string &stringToConvert) 47 | { 48 | size_t size = mbstowcs(0, stringToConvert.c_str(), 0) + 1; 49 | wchar_t *temp = new wchar_t[size]; 50 | mbstowcs(temp, stringToConvert.c_str(), size); 51 | std::wstring result(temp); 52 | delete[] temp; 53 | return result; 54 | } 55 | 56 | namespace webkit_glue 57 | { 58 | 59 | bool HistoryContains(const char16* url, int url_len, const char* document_host, int document_host_len, 60 | bool is_dns_prefetch_enabled) 61 | { 62 | return false; 63 | } 64 | 65 | void PrefetchDns(const std::string& hostname) {} 66 | 67 | void PrecacheUrl(const char16* url, int url_length) {} 68 | 69 | void AppendToLog(const char* file, int line, const char* msg) 70 | { 71 | logging::LogMessage(file, line).stream() << msg; 72 | } 73 | /* 74 | bool GetMimeTypeFromExtension(const std::wstring &ext, std::string *mime_type) 75 | { 76 | return net::GetMimeTypeFromExtension(ext, mime_type); 77 | } 78 | 79 | bool GetMimeTypeFromFile(const std::wstring &file_path, std::string *mime_type) 80 | { 81 | return net::GetMimeTypeFromFile(file_path, mime_type); 82 | } 83 | 84 | bool GetPreferredExtensionForMimeType(const std::string& mime_type, std::wstring* ext) 85 | { 86 | return net::GetPreferredExtensionForMimeType(mime_type, ext); 87 | } 88 | */ 89 | string16 GetLocalizedString(int message_id) 90 | { 91 | // TODO - Replace hard-coded strings with dynamic localization. 92 | // The following definitions are derived from webkit_strings_en-US.rc 93 | 94 | switch(message_id) 95 | { 96 | case 12372: return UTF8ToUTF16("This is a searchable index. Enter search keywords: "); 97 | case 12373: return UTF8ToUTF16("Submit"); 98 | case 12374: return UTF8ToUTF16("Submit"); 99 | case 12375: return UTF8ToUTF16("Reset"); 100 | case 12376: return UTF8ToUTF16("Choose File"); 101 | case 12377: return UTF8ToUTF16("No file chosen"); 102 | case 12378: return UTF8ToUTF16("Drag file here"); 103 | case 12379: return UTF8ToUTF16("No recent searches"); 104 | case 12380: return UTF8ToUTF16("Recent Searches"); 105 | case 12381: return UTF8ToUTF16("Clear Recent Searches"); 106 | case 12382: return UTF8ToUTF16("%s%dx%d"); 107 | case 12383: return UTF8ToUTF16("web area"); 108 | case 12384: return UTF8ToUTF16("link"); 109 | case 12385: return UTF8ToUTF16("list marker"); 110 | case 12386: return UTF8ToUTF16("image map"); 111 | case 12387: return UTF8ToUTF16("heading"); 112 | case 12388: return UTF8ToUTF16("press"); 113 | case 12389: return UTF8ToUTF16("select"); 114 | case 12390: return UTF8ToUTF16("activate"); 115 | case 12391: return UTF8ToUTF16("uncheck"); 116 | case 12392: return UTF8ToUTF16("check"); 117 | case 12393: return UTF8ToUTF16("jump"); 118 | case 12394: return UTF8ToUTF16("2048 (High Grade)"); 119 | case 12395: return UTF8ToUTF16("1024 (Medium Grade)"); 120 | case 12396: return UTF8ToUTF16("$1 plugin is not installed"); 121 | case 12397: return UTF8ToUTF16("The required plugin is not installed"); 122 | case 12398: return UTF8ToUTF16("Click here to download plugin"); 123 | case 12399: return UTF8ToUTF16("After installing the plugin, click here to refresh"); 124 | case 12400: return UTF8ToUTF16("No plugin available to display this content"); 125 | case 12401: return UTF8ToUTF16("Downloading plugin..."); 126 | case 12402: return UTF8ToUTF16("Get Plugin"); 127 | case 12403: return UTF8ToUTF16("Cancel"); 128 | case 12404: return UTF8ToUTF16("$1 plugin needed"); 129 | case 12405: return UTF8ToUTF16("Additional plugin needed"); 130 | case 12406: return UTF8ToUTF16("Please confirm that you would like to install the $1 plugin. You should only install plugins that you trust."); 131 | case 12407: return UTF8ToUTF16("Please confirm that you would like to install this plugin. You should only install plugins that you trust."); 132 | case 12408: return UTF8ToUTF16("Install"); 133 | case 12409: return UTF8ToUTF16("Cancel"); 134 | case 12410: return UTF8ToUTF16("Failed to install plugin from $1"); 135 | case 12411: return UTF8ToUTF16("Plugin installation failed"); 136 | default: return UTF8ToUTF16("????"); 137 | }; 138 | 139 | /* 140 | const ATLSTRINGRESOURCEIMAGE* image = AtlGetStringResourceImage(_AtlBaseModule.GetModuleInstance(), message_id); 141 | 142 | if (!image) 143 | return L"????"; 144 | else 145 | return std::wstring(image->achString, image->nLength); 146 | */ 147 | } 148 | 149 | StringPiece GetDataResource(int resource_id) 150 | { 151 | /* 152 | #if defined(__APPLE__) 153 | return ""; 154 | #else 155 | switch(resource_id) 156 | { 157 | case IDR_BROKENIMAGE: 158 | { 159 | static std::string broken_image_data; 160 | 161 | if(broken_image_data.empty()) 162 | { 163 | std::wstring path = stringToWide(Awesomium::WebCore::Get().getBaseDirectory()); 164 | file_util::AppendToPath(&path, L"missingImage.gif"); 165 | bool success = file_util::ReadFileToString(path, &broken_image_data); 166 | if(!success) 167 | LOG(ERROR) << "Couldn't find missingImage.gif in the base directory. " << 168 | "This file is needed for broken image placeholders."; 169 | } 170 | 171 | return broken_image_data; 172 | } 173 | case IDR_FEED_PREVIEW: 174 | { 175 | // It is necessary to return a feed preview template that contains 176 | // a {{URL}} substring where the feed URL should go; see the code 177 | // that computes feed previews in feed_preview.cc:MakeFeedPreview. 178 | // This fixes issue #932714. 179 | // 180 | 181 | return std::string("Feed preview for {{URL}}"); 182 | } 183 | default: 184 | return ""; 185 | } 186 | #endif 187 | */ 188 | 189 | return ""; 190 | } 191 | 192 | #if defined(WIN32) 193 | HCURSOR LoadCursor(int cursor_id) 194 | { 195 | return NULL; 196 | } 197 | #endif 198 | 199 | bool GetApplicationDirectory(std::wstring *path) 200 | { 201 | return PathService::Get(base::DIR_EXE, path); 202 | } 203 | 204 | GURL GetInspectorURL() 205 | { 206 | return GURL(); 207 | } 208 | 209 | std::string GetUIResourceProtocol() 210 | { 211 | return ""; 212 | } 213 | 214 | bool GetExeDirectory(std::wstring *path) 215 | { 216 | return PathService::Get(base::DIR_EXE, path); 217 | } 218 | 219 | bool SpellCheckWord(const wchar_t* word, int word_len, int* misspelling_start, int* misspelling_len) 220 | { 221 | // Report all words being correctly spelled. 222 | *misspelling_start = 0; 223 | *misspelling_len = 0; 224 | return true; 225 | } 226 | 227 | void GetPlugins(bool refresh, std::vector* plugins) 228 | { 229 | //#if defined(WIN32) 230 | NPAPI::PluginList::Singleton()->GetPlugins(refresh, plugins); 231 | //#else 232 | // return false; 233 | //#endif 234 | } 235 | 236 | bool IsPluginRunningInRendererProcess() 237 | { 238 | /** 239 | * The plugin is actually running in the renderer process however we return 240 | * false here as a workaround to the rare event where a plugin is destroyed 241 | * and then immediately created. The issue is that if we return true and there 242 | * are no active instances using the plugin library, the lib uses deferred 243 | * destruction (posts a message to the loop). This causes a rather nasty 244 | * error if a plugin instance is immediately created after the 245 | * post to invoke deferred destruction of the lib is made. 246 | */ 247 | 248 | return false; 249 | } 250 | 251 | #if defined(WIN32) 252 | bool EnsureFontLoaded(HFONT font) 253 | { 254 | return true; 255 | } 256 | 257 | MONITORINFOEX GetMonitorInfoForWindow(HWND window) 258 | { 259 | HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY); 260 | MONITORINFOEX monitorInfo; 261 | monitorInfo.cbSize = sizeof(MONITORINFOEX); 262 | GetMonitorInfo(monitor, &monitorInfo); 263 | return monitorInfo; 264 | } 265 | 266 | bool DownloadUrl(const std::string& url, HWND caller_window) 267 | { 268 | return false; 269 | } 270 | #endif 271 | 272 | bool GetPluginFinderURL(std::string* plugin_finder_url) 273 | { 274 | return false; 275 | } 276 | 277 | bool IsDefaultPluginEnabled() 278 | { 279 | return false; 280 | } 281 | 282 | std::wstring GetWebKitLocale() 283 | { 284 | return L"en-US"; 285 | } 286 | 287 | uint64 VisitedLinkHash(const char* canonical_url, size_t length) 288 | { 289 | return 0; 290 | } 291 | 292 | bool IsLinkVisited(uint64 link_hash) 293 | { 294 | return false; 295 | } 296 | 297 | #if defined(WIN32) 298 | bool IsMediaPlayerAvailable() 299 | { 300 | return false; 301 | } 302 | 303 | base::LazyInstance clipboard(base::LINKER_INITIALIZED); 304 | 305 | Clipboard* ClipboardGetClipboard() { 306 | return clipboard.Pointer(); 307 | } 308 | 309 | bool ClipboardIsFormatAvailable(const Clipboard::FormatType& format) { 310 | return ClipboardGetClipboard()->IsFormatAvailable(format); 311 | } 312 | 313 | void ClipboardReadText(string16* result) { 314 | ClipboardGetClipboard()->ReadText(result); 315 | } 316 | 317 | void ClipboardReadAsciiText(std::string* result) { 318 | ClipboardGetClipboard()->ReadAsciiText(result); 319 | } 320 | 321 | void ClipboardReadHTML(string16* markup, GURL* url) { 322 | std::string url_str; 323 | ClipboardGetClipboard()->ReadHTML(markup, url ? &url_str : NULL); 324 | if (url) 325 | *url = GURL(url_str); 326 | } 327 | #endif 328 | } // namespace webkit_glue 329 | 330 | #if defined(_WIN32) 331 | #if defined(OS_WIN) 332 | void ScopedClipboardWriterGlue::WriteBitmapFromPixels( 333 | const void* pixels, const gfx::Size& size) { 334 | ScopedClipboardWriter::WriteBitmapFromPixels(pixels, size); 335 | } 336 | #endif 337 | 338 | ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() { 339 | } 340 | #endif 341 | -------------------------------------------------------------------------------- /Awesomium_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Awesomium' target in the 'Awesomium' project. 3 | // 4 | 5 | #include 6 | #include "base/basictypes.h" 7 | -------------------------------------------------------------------------------- /English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pathorn/awesomium/0810331c8e16f5a7418f46fdc6fd15d9470a8d78/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.apple.${PRODUCT_NAME:identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleShortVersionString 20 | 1.01 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | CSResourcesFileMapped 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/InputManager.cpp: -------------------------------------------------------------------------------- 1 | #include "InputManager.h" 2 | 3 | InputManager *InputManager::mInputManager; 4 | 5 | InputManager::InputManager( void ) : 6 | mMouse( 0 ), 7 | mKeyboard( 0 ), 8 | mInputSystem( 0 ) { 9 | } 10 | 11 | InputManager::~InputManager( void ) { 12 | if( mInputSystem ) { 13 | if( mMouse ) { 14 | mInputSystem->destroyInputObject( mMouse ); 15 | mMouse = 0; 16 | } 17 | 18 | if( mKeyboard ) { 19 | mInputSystem->destroyInputObject( mKeyboard ); 20 | mKeyboard = 0; 21 | } 22 | 23 | if( mJoysticks.size() > 0 ) { 24 | itJoystick = mJoysticks.begin(); 25 | itJoystickEnd = mJoysticks.end(); 26 | for(; itJoystick != itJoystickEnd; ++itJoystick ) { 27 | mInputSystem->destroyInputObject( *itJoystick ); 28 | } 29 | 30 | mJoysticks.clear(); 31 | } 32 | 33 | // If you use OIS1.0RC1 or above, uncomment this line 34 | // and comment the line below it 35 | mInputSystem->destroyInputSystem( mInputSystem ); 36 | //mInputSystem->destroyInputSystem(); 37 | mInputSystem = 0; 38 | 39 | // Clear Listeners 40 | mKeyListeners.clear(); 41 | mMouseListeners.clear(); 42 | mJoystickListeners.clear(); 43 | } 44 | } 45 | 46 | void InputManager::initialise( Ogre::RenderWindow *renderWindow ) { 47 | if( !mInputSystem ) { 48 | // Setup basic variables 49 | OIS::ParamList paramList; 50 | size_t windowHnd = 0; 51 | std::ostringstream windowHndStr; 52 | 53 | // Get window handle 54 | renderWindow->getCustomAttribute( "WINDOW", &windowHnd ); 55 | 56 | // Fill parameter list 57 | windowHndStr << (unsigned int) windowHnd; 58 | paramList.insert( std::make_pair( std::string( "WINDOW" ), windowHndStr.str() ) ); 59 | paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" ))); 60 | paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); 61 | //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND"))); 62 | //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE"))); 63 | // Create inputsystem 64 | mInputSystem = OIS::InputManager::createInputSystem( paramList ); 65 | 66 | // If possible create a buffered keyboard 67 | if( mInputSystem->numKeyboards() > 0 ) { 68 | mKeyboard = static_cast( mInputSystem->createInputObject( OIS::OISKeyboard, true ) ); 69 | mKeyboard->setEventCallback( this ); 70 | } 71 | 72 | // If possible create a buffered mouse 73 | if( mInputSystem->numMice() > 0 ) { 74 | mMouse = static_cast( mInputSystem->createInputObject( OIS::OISMouse, true ) ); 75 | mMouse->setEventCallback( this ); 76 | 77 | // Get window size 78 | unsigned int width, height, depth; 79 | int left, top; 80 | renderWindow->getMetrics( width, height, depth, left, top ); 81 | 82 | // Set mouse region 83 | this->setWindowExtents( width, height ); 84 | } 85 | 86 | // If possible create all joysticks in buffered mode 87 | if( mInputSystem->numJoySticks() > 0 ) { 88 | mJoysticks.resize( mInputSystem->numJoySticks() ); 89 | 90 | itJoystick = mJoysticks.begin(); 91 | itJoystickEnd = mJoysticks.end(); 92 | for(; itJoystick != itJoystickEnd; ++itJoystick ) { 93 | (*itJoystick) = static_cast( mInputSystem->createInputObject( OIS::OISJoyStick, true ) ); 94 | (*itJoystick)->setEventCallback( this ); 95 | } 96 | } 97 | } 98 | } 99 | 100 | void InputManager::capture( void ) { 101 | // Need to capture / update each device every frame 102 | if( mMouse ) { 103 | mMouse->capture(); 104 | } 105 | 106 | if( mKeyboard ) { 107 | mKeyboard->capture(); 108 | } 109 | 110 | if( mJoysticks.size() > 0 ) { 111 | itJoystick = mJoysticks.begin(); 112 | itJoystickEnd = mJoysticks.end(); 113 | for(; itJoystick != itJoystickEnd; ++itJoystick ) { 114 | (*itJoystick)->capture(); 115 | } 116 | } 117 | } 118 | 119 | void InputManager::addKeyListener( OIS::KeyListener *keyListener, const std::string& instanceName ) { 120 | if( mKeyboard ) { 121 | // Check for duplicate items 122 | itKeyListener = mKeyListeners.find( instanceName ); 123 | if( itKeyListener == mKeyListeners.end() ) { 124 | mKeyListeners[ instanceName ] = keyListener; 125 | } 126 | else { 127 | // Duplicate Item 128 | } 129 | } 130 | } 131 | 132 | void InputManager::addMouseListener( OIS::MouseListener *mouseListener, const std::string& instanceName ) { 133 | if( mMouse ) { 134 | // Check for duplicate items 135 | itMouseListener = mMouseListeners.find( instanceName ); 136 | if( itMouseListener == mMouseListeners.end() ) { 137 | mMouseListeners[ instanceName ] = mouseListener; 138 | } 139 | else { 140 | // Duplicate Item 141 | } 142 | } 143 | } 144 | 145 | void InputManager::addJoystickListener( OIS::JoyStickListener *joystickListener, const std::string& instanceName ) { 146 | if( mJoysticks.size() > 0 ) { 147 | // Check for duplicate items 148 | itJoystickListener = mJoystickListeners.find( instanceName ); 149 | if( itJoystickListener == mJoystickListeners.end() ) { 150 | mJoystickListeners[ instanceName ] = joystickListener; 151 | } 152 | else { 153 | // Duplicate Item 154 | } 155 | } 156 | } 157 | 158 | void InputManager::removeKeyListener( const std::string& instanceName ) { 159 | // Check if item exists 160 | itKeyListener = mKeyListeners.find( instanceName ); 161 | if( itKeyListener != mKeyListeners.end() ) { 162 | mKeyListeners.erase( itKeyListener ); 163 | } 164 | else { 165 | // Doesn't Exist 166 | } 167 | } 168 | 169 | void InputManager::removeMouseListener( const std::string& instanceName ) { 170 | // Check if item exists 171 | itMouseListener = mMouseListeners.find( instanceName ); 172 | if( itMouseListener != mMouseListeners.end() ) { 173 | mMouseListeners.erase( itMouseListener ); 174 | } 175 | else { 176 | // Doesn't Exist 177 | } 178 | } 179 | 180 | void InputManager::removeJoystickListener( const std::string& instanceName ) { 181 | // Check if item exists 182 | itJoystickListener = mJoystickListeners.find( instanceName ); 183 | if( itJoystickListener != mJoystickListeners.end() ) { 184 | mJoystickListeners.erase( itJoystickListener ); 185 | } 186 | else { 187 | // Doesn't Exist 188 | } 189 | } 190 | 191 | void InputManager::removeKeyListener( OIS::KeyListener *keyListener ) { 192 | itKeyListener = mKeyListeners.begin(); 193 | itKeyListenerEnd = mKeyListeners.end(); 194 | for(; itKeyListener != itKeyListenerEnd; ++itKeyListener ) { 195 | if( itKeyListener->second == keyListener ) { 196 | mKeyListeners.erase( itKeyListener ); 197 | break; 198 | } 199 | } 200 | } 201 | 202 | void InputManager::removeMouseListener( OIS::MouseListener *mouseListener ) { 203 | itMouseListener = mMouseListeners.begin(); 204 | itMouseListenerEnd = mMouseListeners.end(); 205 | for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) { 206 | if( itMouseListener->second == mouseListener ) { 207 | mMouseListeners.erase( itMouseListener ); 208 | break; 209 | } 210 | } 211 | } 212 | 213 | void InputManager::removeJoystickListener( OIS::JoyStickListener *joystickListener ) { 214 | itJoystickListener = mJoystickListeners.begin(); 215 | itJoystickListenerEnd = mJoystickListeners.end(); 216 | for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) { 217 | if( itJoystickListener->second == joystickListener ) { 218 | mJoystickListeners.erase( itJoystickListener ); 219 | break; 220 | } 221 | } 222 | } 223 | 224 | void InputManager::removeAllListeners( void ) { 225 | mKeyListeners.clear(); 226 | mMouseListeners.clear(); 227 | mJoystickListeners.clear(); 228 | } 229 | 230 | void InputManager::removeAllKeyListeners( void ) { 231 | mKeyListeners.clear(); 232 | } 233 | 234 | void InputManager::removeAllMouseListeners( void ) { 235 | mMouseListeners.clear(); 236 | } 237 | 238 | void InputManager::removeAllJoystickListeners( void ) { 239 | mJoystickListeners.clear(); 240 | } 241 | 242 | void InputManager::setWindowExtents( int width, int height ) { 243 | // Set mouse region (if window resizes, we should alter this to reflect as well) 244 | const OIS::MouseState &mouseState = mMouse->getMouseState(); 245 | mouseState.width = width; 246 | mouseState.height = height; 247 | } 248 | 249 | OIS::Mouse* InputManager::getMouse( void ) { 250 | return mMouse; 251 | } 252 | 253 | OIS::Keyboard* InputManager::getKeyboard( void ) { 254 | return mKeyboard; 255 | } 256 | 257 | OIS::JoyStick* InputManager::getJoystick( unsigned int index ) { 258 | // Make sure it's a valid index 259 | if( index < mJoysticks.size() ) { 260 | return mJoysticks[ index ]; 261 | } 262 | 263 | return 0; 264 | } 265 | 266 | int InputManager::getNumOfJoysticks( void ) { 267 | // Cast to keep compiler happy ^^ 268 | return (int) mJoysticks.size(); 269 | } 270 | 271 | bool InputManager::keyPressed( const OIS::KeyEvent &e ) { 272 | itKeyListener = mKeyListeners.begin(); 273 | itKeyListenerEnd = mKeyListeners.end(); 274 | for(; itKeyListener != itKeyListenerEnd; ++itKeyListener ) { 275 | if(!itKeyListener->second->keyPressed( e )) 276 | break; 277 | } 278 | 279 | return true; 280 | } 281 | 282 | bool InputManager::keyReleased( const OIS::KeyEvent &e ) { 283 | itKeyListener = mKeyListeners.begin(); 284 | itKeyListenerEnd = mKeyListeners.end(); 285 | for(; itKeyListener != itKeyListenerEnd; ++itKeyListener ) { 286 | if(!itKeyListener->second->keyReleased( e )) 287 | break; 288 | } 289 | 290 | return true; 291 | } 292 | 293 | bool InputManager::mouseMoved( const OIS::MouseEvent &e ) { 294 | itMouseListener = mMouseListeners.begin(); 295 | itMouseListenerEnd = mMouseListeners.end(); 296 | for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) { 297 | if(!itMouseListener->second->mouseMoved( e )) 298 | break; 299 | } 300 | 301 | return true; 302 | } 303 | 304 | bool InputManager::mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id ) { 305 | itMouseListener = mMouseListeners.begin(); 306 | itMouseListenerEnd = mMouseListeners.end(); 307 | for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) { 308 | if(!itMouseListener->second->mousePressed( e, id )) 309 | break; 310 | } 311 | 312 | return true; 313 | } 314 | 315 | bool InputManager::mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id ) { 316 | itMouseListener = mMouseListeners.begin(); 317 | itMouseListenerEnd = mMouseListeners.end(); 318 | for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) { 319 | if(!itMouseListener->second->mouseReleased( e, id )) 320 | break; 321 | } 322 | 323 | return true; 324 | } 325 | 326 | bool InputManager::povMoved( const OIS::JoyStickEvent &e, int pov ) { 327 | itJoystickListener = mJoystickListeners.begin(); 328 | itJoystickListenerEnd = mJoystickListeners.end(); 329 | for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) { 330 | if(!itJoystickListener->second->povMoved( e, pov )) 331 | break; 332 | } 333 | 334 | return true; 335 | } 336 | 337 | bool InputManager::axisMoved( const OIS::JoyStickEvent &e, int axis ) { 338 | itJoystickListener = mJoystickListeners.begin(); 339 | itJoystickListenerEnd = mJoystickListeners.end(); 340 | for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) { 341 | if(!itJoystickListener->second->axisMoved( e, axis )) 342 | break; 343 | } 344 | 345 | return true; 346 | } 347 | 348 | bool InputManager::sliderMoved( const OIS::JoyStickEvent &e, int sliderID ) { 349 | itJoystickListener = mJoystickListeners.begin(); 350 | itJoystickListenerEnd = mJoystickListeners.end(); 351 | for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) { 352 | if(!itJoystickListener->second->sliderMoved( e, sliderID )) 353 | break; 354 | } 355 | 356 | return true; 357 | } 358 | 359 | bool InputManager::buttonPressed( const OIS::JoyStickEvent &e, int button ) { 360 | itJoystickListener = mJoystickListeners.begin(); 361 | itJoystickListenerEnd = mJoystickListeners.end(); 362 | for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) { 363 | if(!itJoystickListener->second->buttonPressed( e, button )) 364 | break; 365 | } 366 | 367 | return true; 368 | } 369 | 370 | bool InputManager::buttonReleased( const OIS::JoyStickEvent &e, int button ) { 371 | itJoystickListener = mJoystickListeners.begin(); 372 | itJoystickListenerEnd = mJoystickListeners.end(); 373 | for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) { 374 | if(!itJoystickListener->second->buttonReleased( e, button )) 375 | break; 376 | } 377 | 378 | return true; 379 | } 380 | 381 | InputManager* InputManager::getSingletonPtr( void ) { 382 | if( !mInputManager ) { 383 | mInputManager = new InputManager(); 384 | } 385 | 386 | return mInputManager; 387 | } -------------------------------------------------------------------------------- /app/InputManager.h: -------------------------------------------------------------------------------- 1 | #ifndef __InputManager_H__ 2 | #define __InputManager_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | class InputManager : public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener { 12 | public: 13 | virtual ~InputManager( void ); 14 | 15 | void initialise( Ogre::RenderWindow *renderWindow ); 16 | void capture( void ); 17 | 18 | void addKeyListener( OIS::KeyListener *keyListener, const std::string& instanceName ); 19 | void addMouseListener( OIS::MouseListener *mouseListener, const std::string& instanceName ); 20 | void addJoystickListener( OIS::JoyStickListener *joystickListener, const std::string& instanceName ); 21 | 22 | void removeKeyListener( const std::string& instanceName ); 23 | void removeMouseListener( const std::string& instanceName ); 24 | void removeJoystickListener( const std::string& instanceName ); 25 | 26 | void removeKeyListener( OIS::KeyListener *keyListener ); 27 | void removeMouseListener( OIS::MouseListener *mouseListener ); 28 | void removeJoystickListener( OIS::JoyStickListener *joystickListener ); 29 | 30 | void removeAllListeners( void ); 31 | void removeAllKeyListeners( void ); 32 | void removeAllMouseListeners( void ); 33 | void removeAllJoystickListeners( void ); 34 | 35 | void setWindowExtents( int width, int height ); 36 | 37 | OIS::Mouse* getMouse( void ); 38 | OIS::Keyboard* getKeyboard( void ); 39 | OIS::JoyStick* getJoystick( unsigned int index ); 40 | 41 | int getNumOfJoysticks( void ); 42 | 43 | static InputManager* getSingletonPtr( void ); 44 | private: 45 | InputManager( void ); 46 | InputManager( const InputManager& ) { } 47 | InputManager & operator = ( const InputManager& ); 48 | 49 | bool keyPressed( const OIS::KeyEvent &e ); 50 | bool keyReleased( const OIS::KeyEvent &e ); 51 | 52 | bool mouseMoved( const OIS::MouseEvent &e ); 53 | bool mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id ); 54 | bool mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id ); 55 | 56 | bool povMoved( const OIS::JoyStickEvent &e, int pov ); 57 | bool axisMoved( const OIS::JoyStickEvent &e, int axis ); 58 | bool sliderMoved( const OIS::JoyStickEvent &e, int sliderID ); 59 | bool buttonPressed( const OIS::JoyStickEvent &e, int button ); 60 | bool buttonReleased( const OIS::JoyStickEvent &e, int button ); 61 | 62 | OIS::InputManager *mInputSystem; 63 | OIS::Mouse *mMouse; 64 | OIS::Keyboard *mKeyboard; 65 | 66 | std::vector mJoysticks; 67 | std::vector::iterator itJoystick; 68 | std::vector::iterator itJoystickEnd; 69 | 70 | std::map mKeyListeners; 71 | std::map mMouseListeners; 72 | std::map mJoystickListeners; 73 | 74 | std::map::iterator itKeyListener; 75 | std::map::iterator itMouseListener; 76 | std::map::iterator itJoystickListener; 77 | 78 | std::map::iterator itKeyListenerEnd; 79 | std::map::iterator itMouseListenerEnd; 80 | std::map::iterator itJoystickListenerEnd; 81 | 82 | static InputManager *mInputManager; 83 | }; 84 | 85 | #endif -------------------------------------------------------------------------------- /app/KeyboardHook.cpp: -------------------------------------------------------------------------------- 1 | #include "KeyboardHook.h" 2 | 3 | LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam); 4 | 5 | KeyboardHook* KeyboardHook::instance = 0; 6 | 7 | KeyboardHook::KeyboardHook(HookListener* listener) : listener(listener) 8 | { 9 | instance = this; 10 | 11 | HINSTANCE hInstance = GetModuleHandle(0); 12 | 13 | getMsgHook = SetWindowsHookEx(WH_GETMESSAGE, GetMessageProc, hInstance, GetCurrentThreadId()); 14 | } 15 | 16 | KeyboardHook::~KeyboardHook() 17 | { 18 | UnhookWindowsHookEx(getMsgHook); 19 | 20 | instance = 0; 21 | } 22 | 23 | void KeyboardHook::handleHook(UINT msg, HWND hwnd, WPARAM wParam, LPARAM lParam) 24 | { 25 | switch(msg) 26 | { 27 | case WM_KEYDOWN: 28 | case WM_KEYUP: 29 | case WM_CHAR: 30 | case WM_DEADCHAR: 31 | case WM_SYSKEYDOWN: 32 | case WM_SYSKEYUP: 33 | case WM_SYSDEADCHAR: 34 | case WM_SYSCHAR: 35 | case WM_IME_CHAR: 36 | case WM_IME_COMPOSITION: 37 | case WM_IME_COMPOSITIONFULL: 38 | case WM_IME_CONTROL: 39 | case WM_IME_ENDCOMPOSITION: 40 | case WM_IME_KEYDOWN: 41 | case WM_IME_KEYUP: 42 | case WM_IME_NOTIFY: 43 | case WM_IME_REQUEST: 44 | case WM_IME_SELECT: 45 | case WM_IME_SETCONTEXT: 46 | case WM_IME_STARTCOMPOSITION: 47 | case WM_HELP: 48 | case WM_CANCELMODE: 49 | { 50 | if(listener) 51 | listener->handleKeyMessage(hwnd, msg, wParam, lParam); 52 | 53 | break; 54 | } 55 | } 56 | } 57 | 58 | LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam) 59 | { 60 | if(nCode == HC_ACTION) 61 | { 62 | MSG *msg = (MSG*)lParam; 63 | if(wParam & PM_REMOVE) 64 | KeyboardHook::instance->handleHook(msg->message, msg->hwnd, msg->wParam, msg->lParam); 65 | } 66 | 67 | return CallNextHookEx(KeyboardHook::instance->getMsgHook, nCode, wParam, lParam); 68 | } -------------------------------------------------------------------------------- /app/KeyboardHook.h: -------------------------------------------------------------------------------- 1 | #ifndef __KeyboardHook_H__ 2 | #define __KeyboardHook_H__ 3 | 4 | #include 5 | 6 | 7 | class HookListener 8 | { 9 | public: 10 | virtual void handleKeyMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) = 0; 11 | }; 12 | 13 | class KeyboardHook 14 | { 15 | public: 16 | HHOOK getMsgHook; 17 | static KeyboardHook* instance; 18 | HookListener* listener; 19 | 20 | KeyboardHook(HookListener* listener); 21 | ~KeyboardHook(); 22 | 23 | void handleHook(UINT msg, HWND hwnd, WPARAM wParam, LPARAM lParam); 24 | }; 25 | 26 | 27 | #endif -------------------------------------------------------------------------------- /app/TerrainCamera.cpp: -------------------------------------------------------------------------------- 1 | #include "TerrainCamera.h" 2 | 3 | using namespace Ogre; 4 | 5 | TerrainCamera::TerrainCamera(Ogre::SceneNode *baseNode, Ogre::Camera *camera, Vector3 offset, Real height) : baseNode(baseNode), camera(camera), height(height) 6 | { 7 | pivotNode = baseNode->createChildSceneNode(baseNode->getName()+"_PivotNode", Ogre::Vector3(700, 300, 700)); 8 | camNode = pivotNode->createChildSceneNode(baseNode->getName()+"_CameraNode", offset); 9 | camNode->yaw(Degree(180)); 10 | camNode->attachObject(camera); 11 | rayQuery = camera->getSceneManager()->createRayQuery(Ray(pivotNode->getPosition(), Vector3::NEGATIVE_UNIT_Y)); 12 | clampToTerrain(); 13 | } 14 | 15 | TerrainCamera::~TerrainCamera() 16 | { 17 | camNode->detachAllObjects(); 18 | baseNode->removeAndDestroyChild(pivotNode->getName()); 19 | } 20 | 21 | Camera* TerrainCamera::getCamera() 22 | { 23 | return camera; 24 | } 25 | 26 | void TerrainCamera::spin(const Ogre::Radian &angle) 27 | { 28 | pivotNode->yaw(angle); 29 | } 30 | 31 | void TerrainCamera::pitch(const Ogre::Radian &angle) 32 | { 33 | camNode->pitch(angle); 34 | } 35 | 36 | void TerrainCamera::translate(const Ogre::Vector3& displacement) 37 | { 38 | pivotNode->translate(displacement, Ogre::Node::TS_LOCAL); 39 | } 40 | 41 | void TerrainCamera::clampToTerrain() 42 | { 43 | rayQuery->setRay(Ray(pivotNode->getPosition() + Vector3(0, 200, 0), Vector3::NEGATIVE_UNIT_Y)); 44 | RaySceneQueryResult &qryResult = rayQuery->execute(); 45 | RaySceneQueryResult::iterator i = qryResult.begin(); 46 | if(i != qryResult.end() && i->worldFragment) 47 | pivotNode->setPosition(pivotNode->getPosition().x, i->worldFragment->singleIntersection.y + 1 + height, pivotNode->getPosition().z); 48 | } 49 | 50 | void TerrainCamera::orientPlaneToCamera(Ogre::SceneNode* planeNode, int planeHeight) 51 | { 52 | pivotNode->translate(Ogre::Vector3(0, 0, 270), Ogre::Node::TS_LOCAL); 53 | 54 | planeNode->setPosition(pivotNode->getPosition()); 55 | 56 | pivotNode->translate(Ogre::Vector3(0, 0, -270), Ogre::Node::TS_LOCAL); 57 | 58 | planeNode->setOrientation(pivotNode->getOrientation()); 59 | planeNode->yaw(Degree(90)); 60 | 61 | rayQuery->setRay(Ray(planeNode->getPosition() + Vector3(0, 170, 0), Vector3::NEGATIVE_UNIT_Y)); 62 | RaySceneQueryResult &qryResult = rayQuery->execute(); 63 | RaySceneQueryResult::iterator i = qryResult.begin(); 64 | if(i != qryResult.end() && i->worldFragment) 65 | planeNode->setPosition(planeNode->getPosition().x, i->worldFragment->singleIntersection.y + planeHeight / 2, planeNode->getPosition().z); 66 | } -------------------------------------------------------------------------------- /app/TerrainCamera.h: -------------------------------------------------------------------------------- 1 | #ifndef __TerrainCamera_H__ 2 | #define __TerrainCamera_H__ 3 | 4 | #include "Ogre.h" 5 | 6 | class TerrainCamera 7 | { 8 | Ogre::SceneNode *baseNode, *pivotNode, *camNode; 9 | Ogre::Camera *camera; 10 | Ogre::RaySceneQuery *rayQuery; 11 | Ogre::Real height; 12 | public: 13 | TerrainCamera(Ogre::SceneNode *baseNode, Ogre::Camera *camera, Ogre::Vector3 offset = Ogre::Vector3(0, 40, -60), Ogre::Real height = 20); 14 | 15 | ~TerrainCamera(); 16 | 17 | Ogre::Camera* getCamera(); 18 | 19 | void spin(const Ogre::Radian &angle); 20 | 21 | void pitch(const Ogre::Radian &angle); 22 | 23 | void translate(const Ogre::Vector3& displacement); 24 | 25 | void clampToTerrain(); 26 | 27 | void orientPlaneToCamera(Ogre::SceneNode* planeNode, int planeHeight); 28 | }; 29 | 30 | #endif -------------------------------------------------------------------------------- /app/app.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 25 | 28 | 31 | 34 | 37 | 40 | 52 | 55 | 58 | 61 | 69 | 72 | 75 | 78 | 81 | 84 | 87 | 90 | 94 | 95 | 103 | 106 | 109 | 112 | 115 | 118 | 127 | 130 | 133 | 136 | 145 | 148 | 151 | 154 | 157 | 160 | 163 | 166 | 170 | 171 | 172 | 173 | 174 | 175 | 180 | 183 | 184 | 187 | 188 | 191 | 192 | 195 | 196 | 199 | 200 | 203 | 204 | 207 | 208 | 211 | 212 | 213 | 218 | 219 | 224 | 225 | 226 | 227 | 228 | 229 | -------------------------------------------------------------------------------- /app/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Application.h" 2 | #include 3 | 4 | int main() 5 | { 6 | try 7 | { 8 | Application app; 9 | 10 | while(!app.shouldQuit) 11 | app.update(); 12 | } 13 | catch( Ogre::Exception& e ) 14 | { 15 | ShowCursor(true); 16 | MessageBox(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL); 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /debug/Plugins.cfg: -------------------------------------------------------------------------------- 1 | # Defines plugins to load 2 | 3 | # Define plugin folder 4 | PluginFolder=. 5 | 6 | # Define plugins 7 | Plugin=RenderSystem_Direct3D9_d 8 | Plugin=RenderSystem_GL_d 9 | Plugin=Plugin_OctreeSceneManager_d 10 | 11 | 12 | -------------------------------------------------------------------------------- /debug/resources.cfg: -------------------------------------------------------------------------------- 1 | [General] 2 | FileSystem=../media 3 | 4 | -------------------------------------------------------------------------------- /debug/testing/excanvas.pack.js: -------------------------------------------------------------------------------- 1 | if(!window.CanvasRenderingContext2D){(function(){var m=Math;var mr=m.round;var ms=m.sin;var mc=m.cos;var Z=10;var Z2=Z/2;var G_vmlCanvasManager_={init:function(opt_doc){var doc=opt_doc||document;if(/MSIE/.test(navigator.userAgent)&&!window.opera){var self=this;doc.attachEvent("onreadystatechange",function(){self.init_(doc)})}},init_:function(doc){if(doc.readyState=="complete"){if(!doc.namespaces["g_vml_"]){doc.namespaces.add("g_vml_","urn:schemas-microsoft-com:vml")}var ss=doc.createStyleSheet();ss.cssText="canvas{display:inline-block;overflow:hidden;"+"text-align:left;width:300px;height:150px}"+"g_vml_\\:*{behavior:url(#default#VML)}";var els=doc.getElementsByTagName("canvas");for(var i=0;i"){var tagName="/"+el.tagName;var ns;while((ns=el.nextSibling)&&ns.tagName!=tagName){ns.removeNode()}if(ns){ns.removeNode()}}el.parentNode.replaceChild(newEl,el);return newEl},initElement:function(el){el=this.fixElement_(el);el.getContext=function(){if(this.context_){return this.context_}return this.context_=new CanvasRenderingContext2D_(this)};el.attachEvent('onpropertychange',onPropertyChange);el.attachEvent('onresize',onResize);var attrs=el.attributes;if(attrs.width&&attrs.width.specified){el.style.width=attrs.width.nodeValue+"px"}else{el.width=el.clientWidth}if(attrs.height&&attrs.height.specified){el.style.height=attrs.height.nodeValue+"px"}else{el.height=el.clientHeight}return el}};function onPropertyChange(e){var el=e.srcElement;switch(e.propertyName){case'width':el.style.width=el.attributes.width.nodeValue+"px";el.getContext().clearRect();break;case'height':el.style.height=el.attributes.height.nodeValue+"px";el.getContext().clearRect();break}}function onResize(e){var el=e.srcElement;if(el.firstChild){el.firstChild.style.width=el.clientWidth+'px';el.firstChild.style.height=el.clientHeight+'px'}}G_vmlCanvasManager_.init();var dec2hex=[];for(var i=0;i<16;i++){for(var j=0;j<16;j++){dec2hex[i*16+j]=i.toString(16)+j.toString(16)}}function createMatrixIdentity(){return[[1,0,0],[0,1,0],[0,0,1]]}function matrixMultiply(m1,m2){var result=createMatrixIdentity();for(var x=0;x<3;x++){for(var y=0;y<3;y++){var sum=0;for(var z=0;z<3;z++){sum+=m1[x][z]*m2[z][y]}result[x][y]=sum}}return result}function copyState(o1,o2){o2.fillStyle=o1.fillStyle;o2.lineCap=o1.lineCap;o2.lineJoin=o1.lineJoin;o2.lineWidth=o1.lineWidth;o2.miterLimit=o1.miterLimit;o2.shadowBlur=o1.shadowBlur;o2.shadowColor=o1.shadowColor;o2.shadowOffsetX=o1.shadowOffsetX;o2.shadowOffsetY=o1.shadowOffsetY;o2.strokeStyle=o1.strokeStyle;o2.arcScaleX_=o1.arcScaleX_;o2.arcScaleY_=o1.arcScaleY_}function processStyle(styleString){var str,alpha=1;styleString=String(styleString);if(styleString.substring(0,3)=="rgb"){var start=styleString.indexOf("(",3);var end=styleString.indexOf(")",start+1);var guts=styleString.substring(start+1,end).split(",");str="#";for(var i=0;i<3;i++){str+=dec2hex[Number(guts[i])]}if((guts.length==4)&&(styleString.substr(3,1)=="a")){alpha=guts[3]}}else{str=styleString}return[str,alpha]}function processLineCap(lineCap){switch(lineCap){case"butt":return"flat";case"round":return"round";case"square":default:return"square"}}function CanvasRenderingContext2D_(surfaceElement){this.m_=createMatrixIdentity();this.mStack_=[];this.aStack_=[];this.currentPath_=[];this.strokeStyle="#000";this.fillStyle="#000";this.lineWidth=1;this.lineJoin="miter";this.lineCap="butt";this.miterLimit=Z*1;this.globalAlpha=1;this.canvas=surfaceElement;var el=surfaceElement.ownerDocument.createElement('div');el.style.width=surfaceElement.clientWidth+'px';el.style.height=surfaceElement.clientHeight+'px';el.style.overflow='hidden';el.style.position='absolute';surfaceElement.appendChild(el);this.element_=el;this.arcScaleX_=1;this.arcScaleY_=1}var contextPrototype=CanvasRenderingContext2D_.prototype;contextPrototype.clearRect=function(){this.element_.innerHTML="";this.currentPath_=[]};contextPrototype.beginPath=function(){this.currentPath_=[]};contextPrototype.moveTo=function(aX,aY){this.currentPath_.push({type:"moveTo",x:aX,y:aY});this.currentX_=aX;this.currentY_=aY};contextPrototype.lineTo=function(aX,aY){this.currentPath_.push({type:"lineTo",x:aX,y:aY});this.currentX_=aX;this.currentY_=aY};contextPrototype.bezierCurveTo=function(aCP1x,aCP1y,aCP2x,aCP2y,aX,aY){this.currentPath_.push({type:"bezierCurveTo",cp1x:aCP1x,cp1y:aCP1y,cp2x:aCP2x,cp2y:aCP2y,x:aX,y:aY});this.currentX_=aX;this.currentY_=aY};contextPrototype.quadraticCurveTo=function(aCPx,aCPy,aX,aY){var cp1x=this.currentX_+2.0/3.0*(aCPx-this.currentX_);var cp1y=this.currentY_+2.0/3.0*(aCPy-this.currentY_);var cp2x=cp1x+(aX-this.currentX_)/3.0;var cp2y=cp1y+(aY-this.currentY_)/3.0;this.bezierCurveTo(cp1x,cp1y,cp2x,cp2y,aX,aY)};contextPrototype.arc=function(aX,aY,aRadius,aStartAngle,aEndAngle,aClockwise){aRadius*=Z;var arcType=aClockwise?"at":"wa";var xStart=aX+(mc(aStartAngle)*aRadius)-Z2;var yStart=aY+(ms(aStartAngle)*aRadius)-Z2;var xEnd=aX+(mc(aEndAngle)*aRadius)-Z2;var yEnd=aY+(ms(aEndAngle)*aRadius)-Z2;if(xStart==xEnd&&!aClockwise){xStart+=0.125}this.currentPath_.push({type:arcType,x:aX,y:aY,radius:aRadius,xStart:xStart,yStart:yStart,xEnd:xEnd,yEnd:yEnd})};contextPrototype.rect=function(aX,aY,aWidth,aHeight){this.moveTo(aX,aY);this.lineTo(aX+aWidth,aY);this.lineTo(aX+aWidth,aY+aHeight);this.lineTo(aX,aY+aHeight);this.closePath()};contextPrototype.strokeRect=function(aX,aY,aWidth,aHeight){this.beginPath();this.moveTo(aX,aY);this.lineTo(aX+aWidth,aY);this.lineTo(aX+aWidth,aY+aHeight);this.lineTo(aX,aY+aHeight);this.closePath();this.stroke()};contextPrototype.fillRect=function(aX,aY,aWidth,aHeight){this.beginPath();this.moveTo(aX,aY);this.lineTo(aX+aWidth,aY);this.lineTo(aX+aWidth,aY+aHeight);this.lineTo(aX,aY+aHeight);this.closePath();this.fill()};contextPrototype.createLinearGradient=function(aX0,aY0,aX1,aY1){var gradient=new CanvasGradient_("gradient");return gradient};contextPrototype.createRadialGradient=function(aX0,aY0,aR0,aX1,aY1,aR1){var gradient=new CanvasGradient_("gradientradial");gradient.radius1_=aR0;gradient.radius2_=aR1;gradient.focus_.x=aX0;gradient.focus_.y=aY0;return gradient};contextPrototype.drawImage=function(image,var_args){var dx,dy,dw,dh,sx,sy,sw,sh;var oldRuntimeWidth=image.runtimeStyle.width;var oldRuntimeHeight=image.runtimeStyle.height;image.runtimeStyle.width='auto';image.runtimeStyle.height='auto';var w=image.width;var h=image.height;image.runtimeStyle.width=oldRuntimeWidth;image.runtimeStyle.height=oldRuntimeHeight;if(arguments.length==3){dx=arguments[1];dy=arguments[2];sx=sy=0;sw=dw=w;sh=dh=h}else if(arguments.length==5){dx=arguments[1];dy=arguments[2];dw=arguments[3];dh=arguments[4];sx=sy=0;sw=w;sh=h}else if(arguments.length==9){sx=arguments[1];sy=arguments[2];sw=arguments[3];sh=arguments[4];dx=arguments[5];dy=arguments[6];dw=arguments[7];dh=arguments[8]}else{throw"Invalid number of arguments";}var d=this.getCoords_(dx,dy);var w2=sw/2;var h2=sh/2;var vmlStr=[];var W=10;var H=10;vmlStr.push(' ','','');this.element_.insertAdjacentHTML("BeforeEnd",vmlStr.join(""))};contextPrototype.stroke=function(aFill){var lineStr=[];var lineOpen=false;var a=processStyle(aFill?this.fillStyle:this.strokeStyle);var color=a[0];var opacity=a[1]*this.globalAlpha;var W=10;var H=10;lineStr.push('max.x){max.x=c.x}if(min.y==null||c.ymax.y){max.y=c.y}}}lineStr.push(' ">');if(typeof this.fillStyle=="object"){var focus={x:"50%",y:"50%"};var width=(max.x-min.x);var height=(max.y-min.y);var dimension=(width>height)?width:height;focus.x=mr((this.fillStyle.focus_.x/width)*100+50)+"%";focus.y=mr((this.fillStyle.focus_.y/height)*100+50)+"%";var colors=[];if(this.fillStyle.type_=="gradientradial"){var inside=(this.fillStyle.radius1_/dimension*100);var expansion=(this.fillStyle.radius2_/dimension*100)-inside}else{var inside=0;var expansion=100}var insidecolor={offset:null,color:null};var outsidecolor={offset:null,color:null};this.fillStyle.colors_.sort(function(cs1,cs2){return cs1.offset-cs2.offset});for(var i=0;iinsidecolor.offset||insidecolor.offset==null){insidecolor.offset=fs.offset;insidecolor.color=fs.color}if(fs.offset')}else if(aFill){lineStr.push('')}else{lineStr.push('')}lineStr.push("");this.element_.insertAdjacentHTML("beforeEnd",lineStr.join(""))};contextPrototype.fill=function(){this.stroke(true)};contextPrototype.closePath=function(){this.currentPath_.push({type:"close"})};contextPrototype.getCoords_=function(aX,aY){return{x:Z*(aX*this.m_[0][0]+aY*this.m_[1][0]+this.m_[2][0])-Z2,y:Z*(aX*this.m_[0][1]+aY*this.m_[1][1]+this.m_[2][1])-Z2}};contextPrototype.save=function(){var o={};copyState(this,o);this.aStack_.push(o);this.mStack_.push(this.m_);this.m_=matrixMultiply(createMatrixIdentity(),this.m_)};contextPrototype.restore=function(){copyState(this.aStack_.pop(),this);this.m_=this.mStack_.pop()};contextPrototype.translate=function(aX,aY){var m1=[[1,0,0],[0,1,0],[aX,aY,1]];this.m_=matrixMultiply(m1,this.m_)};contextPrototype.rotate=function(aRot){var c=mc(aRot);var s=ms(aRot);var m1=[[c,s,0],[-s,c,0],[0,0,1]];this.m_=matrixMultiply(m1,this.m_)};contextPrototype.scale=function(aX,aY){this.arcScaleX_*=aX;this.arcScaleY_*=aY;var m1=[[aX,0,0],[0,aY,0],[0,0,1]];this.m_=matrixMultiply(m1,this.m_)};contextPrototype.clip=function(){};contextPrototype.arcTo=function(){};contextPrototype.createPattern=function(){return new CanvasPattern_};function CanvasGradient_(aType){this.type_=aType;this.radius1_=0;this.radius2_=0;this.colors_=[];this.focus_={x:0,y:0}}CanvasGradient_.prototype.addColorStop=function(aOffset,aColor){aColor=processStyle(aColor);this.colors_.push({offset:1-aOffset,color:aColor})};function CanvasPattern_(){}G_vmlCanvasManager=G_vmlCanvasManager_;CanvasRenderingContext2D=CanvasRenderingContext2D_;CanvasGradient=CanvasGradient_;CanvasPattern=CanvasPattern_})()} 2 | -------------------------------------------------------------------------------- /debug/testing/testResults.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 81 | 82 | 83 | 84 |
85 | 86 |

Test: Synchronous Render

87 |
88 | 89 |

90 | 91 |

Test: Asynchronous Render

92 |
93 | 94 |

95 | 96 |

Test: Javascript Evaluation

97 |
98 | 99 |
100 | 101 | -------------------------------------------------------------------------------- /release/Plugins.cfg: -------------------------------------------------------------------------------- 1 | # Defines plugins to load 2 | 3 | # Define plugin folder 4 | PluginFolder=. 5 | 6 | # Define plugins 7 | Plugin=RenderSystem_Direct3D9 8 | Plugin=RenderSystem_GL 9 | Plugin=Plugin_OctreeSceneManager -------------------------------------------------------------------------------- /release/resources.cfg: -------------------------------------------------------------------------------- 1 | [General] 2 | FileSystem=../media 3 | 4 | -------------------------------------------------------------------------------- /release/testing/excanvas.pack.js: -------------------------------------------------------------------------------- 1 | if(!window.CanvasRenderingContext2D){(function(){var m=Math;var mr=m.round;var ms=m.sin;var mc=m.cos;var Z=10;var Z2=Z/2;var G_vmlCanvasManager_={init:function(opt_doc){var doc=opt_doc||document;if(/MSIE/.test(navigator.userAgent)&&!window.opera){var self=this;doc.attachEvent("onreadystatechange",function(){self.init_(doc)})}},init_:function(doc){if(doc.readyState=="complete"){if(!doc.namespaces["g_vml_"]){doc.namespaces.add("g_vml_","urn:schemas-microsoft-com:vml")}var ss=doc.createStyleSheet();ss.cssText="canvas{display:inline-block;overflow:hidden;"+"text-align:left;width:300px;height:150px}"+"g_vml_\\:*{behavior:url(#default#VML)}";var els=doc.getElementsByTagName("canvas");for(var i=0;i"){var tagName="/"+el.tagName;var ns;while((ns=el.nextSibling)&&ns.tagName!=tagName){ns.removeNode()}if(ns){ns.removeNode()}}el.parentNode.replaceChild(newEl,el);return newEl},initElement:function(el){el=this.fixElement_(el);el.getContext=function(){if(this.context_){return this.context_}return this.context_=new CanvasRenderingContext2D_(this)};el.attachEvent('onpropertychange',onPropertyChange);el.attachEvent('onresize',onResize);var attrs=el.attributes;if(attrs.width&&attrs.width.specified){el.style.width=attrs.width.nodeValue+"px"}else{el.width=el.clientWidth}if(attrs.height&&attrs.height.specified){el.style.height=attrs.height.nodeValue+"px"}else{el.height=el.clientHeight}return el}};function onPropertyChange(e){var el=e.srcElement;switch(e.propertyName){case'width':el.style.width=el.attributes.width.nodeValue+"px";el.getContext().clearRect();break;case'height':el.style.height=el.attributes.height.nodeValue+"px";el.getContext().clearRect();break}}function onResize(e){var el=e.srcElement;if(el.firstChild){el.firstChild.style.width=el.clientWidth+'px';el.firstChild.style.height=el.clientHeight+'px'}}G_vmlCanvasManager_.init();var dec2hex=[];for(var i=0;i<16;i++){for(var j=0;j<16;j++){dec2hex[i*16+j]=i.toString(16)+j.toString(16)}}function createMatrixIdentity(){return[[1,0,0],[0,1,0],[0,0,1]]}function matrixMultiply(m1,m2){var result=createMatrixIdentity();for(var x=0;x<3;x++){for(var y=0;y<3;y++){var sum=0;for(var z=0;z<3;z++){sum+=m1[x][z]*m2[z][y]}result[x][y]=sum}}return result}function copyState(o1,o2){o2.fillStyle=o1.fillStyle;o2.lineCap=o1.lineCap;o2.lineJoin=o1.lineJoin;o2.lineWidth=o1.lineWidth;o2.miterLimit=o1.miterLimit;o2.shadowBlur=o1.shadowBlur;o2.shadowColor=o1.shadowColor;o2.shadowOffsetX=o1.shadowOffsetX;o2.shadowOffsetY=o1.shadowOffsetY;o2.strokeStyle=o1.strokeStyle;o2.arcScaleX_=o1.arcScaleX_;o2.arcScaleY_=o1.arcScaleY_}function processStyle(styleString){var str,alpha=1;styleString=String(styleString);if(styleString.substring(0,3)=="rgb"){var start=styleString.indexOf("(",3);var end=styleString.indexOf(")",start+1);var guts=styleString.substring(start+1,end).split(",");str="#";for(var i=0;i<3;i++){str+=dec2hex[Number(guts[i])]}if((guts.length==4)&&(styleString.substr(3,1)=="a")){alpha=guts[3]}}else{str=styleString}return[str,alpha]}function processLineCap(lineCap){switch(lineCap){case"butt":return"flat";case"round":return"round";case"square":default:return"square"}}function CanvasRenderingContext2D_(surfaceElement){this.m_=createMatrixIdentity();this.mStack_=[];this.aStack_=[];this.currentPath_=[];this.strokeStyle="#000";this.fillStyle="#000";this.lineWidth=1;this.lineJoin="miter";this.lineCap="butt";this.miterLimit=Z*1;this.globalAlpha=1;this.canvas=surfaceElement;var el=surfaceElement.ownerDocument.createElement('div');el.style.width=surfaceElement.clientWidth+'px';el.style.height=surfaceElement.clientHeight+'px';el.style.overflow='hidden';el.style.position='absolute';surfaceElement.appendChild(el);this.element_=el;this.arcScaleX_=1;this.arcScaleY_=1}var contextPrototype=CanvasRenderingContext2D_.prototype;contextPrototype.clearRect=function(){this.element_.innerHTML="";this.currentPath_=[]};contextPrototype.beginPath=function(){this.currentPath_=[]};contextPrototype.moveTo=function(aX,aY){this.currentPath_.push({type:"moveTo",x:aX,y:aY});this.currentX_=aX;this.currentY_=aY};contextPrototype.lineTo=function(aX,aY){this.currentPath_.push({type:"lineTo",x:aX,y:aY});this.currentX_=aX;this.currentY_=aY};contextPrototype.bezierCurveTo=function(aCP1x,aCP1y,aCP2x,aCP2y,aX,aY){this.currentPath_.push({type:"bezierCurveTo",cp1x:aCP1x,cp1y:aCP1y,cp2x:aCP2x,cp2y:aCP2y,x:aX,y:aY});this.currentX_=aX;this.currentY_=aY};contextPrototype.quadraticCurveTo=function(aCPx,aCPy,aX,aY){var cp1x=this.currentX_+2.0/3.0*(aCPx-this.currentX_);var cp1y=this.currentY_+2.0/3.0*(aCPy-this.currentY_);var cp2x=cp1x+(aX-this.currentX_)/3.0;var cp2y=cp1y+(aY-this.currentY_)/3.0;this.bezierCurveTo(cp1x,cp1y,cp2x,cp2y,aX,aY)};contextPrototype.arc=function(aX,aY,aRadius,aStartAngle,aEndAngle,aClockwise){aRadius*=Z;var arcType=aClockwise?"at":"wa";var xStart=aX+(mc(aStartAngle)*aRadius)-Z2;var yStart=aY+(ms(aStartAngle)*aRadius)-Z2;var xEnd=aX+(mc(aEndAngle)*aRadius)-Z2;var yEnd=aY+(ms(aEndAngle)*aRadius)-Z2;if(xStart==xEnd&&!aClockwise){xStart+=0.125}this.currentPath_.push({type:arcType,x:aX,y:aY,radius:aRadius,xStart:xStart,yStart:yStart,xEnd:xEnd,yEnd:yEnd})};contextPrototype.rect=function(aX,aY,aWidth,aHeight){this.moveTo(aX,aY);this.lineTo(aX+aWidth,aY);this.lineTo(aX+aWidth,aY+aHeight);this.lineTo(aX,aY+aHeight);this.closePath()};contextPrototype.strokeRect=function(aX,aY,aWidth,aHeight){this.beginPath();this.moveTo(aX,aY);this.lineTo(aX+aWidth,aY);this.lineTo(aX+aWidth,aY+aHeight);this.lineTo(aX,aY+aHeight);this.closePath();this.stroke()};contextPrototype.fillRect=function(aX,aY,aWidth,aHeight){this.beginPath();this.moveTo(aX,aY);this.lineTo(aX+aWidth,aY);this.lineTo(aX+aWidth,aY+aHeight);this.lineTo(aX,aY+aHeight);this.closePath();this.fill()};contextPrototype.createLinearGradient=function(aX0,aY0,aX1,aY1){var gradient=new CanvasGradient_("gradient");return gradient};contextPrototype.createRadialGradient=function(aX0,aY0,aR0,aX1,aY1,aR1){var gradient=new CanvasGradient_("gradientradial");gradient.radius1_=aR0;gradient.radius2_=aR1;gradient.focus_.x=aX0;gradient.focus_.y=aY0;return gradient};contextPrototype.drawImage=function(image,var_args){var dx,dy,dw,dh,sx,sy,sw,sh;var oldRuntimeWidth=image.runtimeStyle.width;var oldRuntimeHeight=image.runtimeStyle.height;image.runtimeStyle.width='auto';image.runtimeStyle.height='auto';var w=image.width;var h=image.height;image.runtimeStyle.width=oldRuntimeWidth;image.runtimeStyle.height=oldRuntimeHeight;if(arguments.length==3){dx=arguments[1];dy=arguments[2];sx=sy=0;sw=dw=w;sh=dh=h}else if(arguments.length==5){dx=arguments[1];dy=arguments[2];dw=arguments[3];dh=arguments[4];sx=sy=0;sw=w;sh=h}else if(arguments.length==9){sx=arguments[1];sy=arguments[2];sw=arguments[3];sh=arguments[4];dx=arguments[5];dy=arguments[6];dw=arguments[7];dh=arguments[8]}else{throw"Invalid number of arguments";}var d=this.getCoords_(dx,dy);var w2=sw/2;var h2=sh/2;var vmlStr=[];var W=10;var H=10;vmlStr.push(' ','','');this.element_.insertAdjacentHTML("BeforeEnd",vmlStr.join(""))};contextPrototype.stroke=function(aFill){var lineStr=[];var lineOpen=false;var a=processStyle(aFill?this.fillStyle:this.strokeStyle);var color=a[0];var opacity=a[1]*this.globalAlpha;var W=10;var H=10;lineStr.push('max.x){max.x=c.x}if(min.y==null||c.ymax.y){max.y=c.y}}}lineStr.push(' ">');if(typeof this.fillStyle=="object"){var focus={x:"50%",y:"50%"};var width=(max.x-min.x);var height=(max.y-min.y);var dimension=(width>height)?width:height;focus.x=mr((this.fillStyle.focus_.x/width)*100+50)+"%";focus.y=mr((this.fillStyle.focus_.y/height)*100+50)+"%";var colors=[];if(this.fillStyle.type_=="gradientradial"){var inside=(this.fillStyle.radius1_/dimension*100);var expansion=(this.fillStyle.radius2_/dimension*100)-inside}else{var inside=0;var expansion=100}var insidecolor={offset:null,color:null};var outsidecolor={offset:null,color:null};this.fillStyle.colors_.sort(function(cs1,cs2){return cs1.offset-cs2.offset});for(var i=0;iinsidecolor.offset||insidecolor.offset==null){insidecolor.offset=fs.offset;insidecolor.color=fs.color}if(fs.offset')}else if(aFill){lineStr.push('')}else{lineStr.push('')}lineStr.push("");this.element_.insertAdjacentHTML("beforeEnd",lineStr.join(""))};contextPrototype.fill=function(){this.stroke(true)};contextPrototype.closePath=function(){this.currentPath_.push({type:"close"})};contextPrototype.getCoords_=function(aX,aY){return{x:Z*(aX*this.m_[0][0]+aY*this.m_[1][0]+this.m_[2][0])-Z2,y:Z*(aX*this.m_[0][1]+aY*this.m_[1][1]+this.m_[2][1])-Z2}};contextPrototype.save=function(){var o={};copyState(this,o);this.aStack_.push(o);this.mStack_.push(this.m_);this.m_=matrixMultiply(createMatrixIdentity(),this.m_)};contextPrototype.restore=function(){copyState(this.aStack_.pop(),this);this.m_=this.mStack_.pop()};contextPrototype.translate=function(aX,aY){var m1=[[1,0,0],[0,1,0],[aX,aY,1]];this.m_=matrixMultiply(m1,this.m_)};contextPrototype.rotate=function(aRot){var c=mc(aRot);var s=ms(aRot);var m1=[[c,s,0],[-s,c,0],[0,0,1]];this.m_=matrixMultiply(m1,this.m_)};contextPrototype.scale=function(aX,aY){this.arcScaleX_*=aX;this.arcScaleY_*=aY;var m1=[[aX,0,0],[0,aY,0],[0,0,1]];this.m_=matrixMultiply(m1,this.m_)};contextPrototype.clip=function(){};contextPrototype.arcTo=function(){};contextPrototype.createPattern=function(){return new CanvasPattern_};function CanvasGradient_(aType){this.type_=aType;this.radius1_=0;this.radius2_=0;this.colors_=[];this.focus_={x:0,y:0}}CanvasGradient_.prototype.addColorStop=function(aOffset,aColor){aColor=processStyle(aColor);this.colors_.push({offset:1-aOffset,color:aColor})};function CanvasPattern_(){}G_vmlCanvasManager=G_vmlCanvasManager_;CanvasRenderingContext2D=CanvasRenderingContext2D_;CanvasGradient=CanvasGradient_;CanvasPattern=CanvasPattern_})()} 2 | -------------------------------------------------------------------------------- /release/testing/testResults.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 81 | 82 | 83 | 84 |
85 | 86 |

Test: Synchronous Render

87 |
88 | 89 |

90 | 91 |

Test: Asynchronous Render

92 |
93 | 94 |

95 | 96 |

Test: Javascript Evaluation

97 |
98 | 99 |
100 | 101 | -------------------------------------------------------------------------------- /unitTest/TestFramework.h: -------------------------------------------------------------------------------- 1 | #ifndef __TestFramework_H__ 2 | #define __TestFramework_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "Timer.h" 8 | 9 | #define LOG(X) std::cout << X << std::endl; 10 | 11 | inline void logTestValue(const std::string& testName, double value) 12 | { 13 | std::string path = "testing\\TESTDATA_" + testName + ".js"; 14 | 15 | std::ifstream inputfile(path.c_str()); 16 | 17 | bool shouldAppend = false; 18 | if(inputfile.is_open() && inputfile.good()) 19 | shouldAppend = true; 20 | 21 | inputfile.close(); 22 | 23 | std::fstream file; 24 | 25 | if(shouldAppend) 26 | file.open(path.c_str()); 27 | else 28 | file.open(path.c_str(), std::fstream::out|std::fstream::trunc); 29 | 30 | if(shouldAppend) 31 | { 32 | char c; 33 | while(true) 34 | { 35 | file.get(c); 36 | 37 | if(!file.good()) 38 | { 39 | LOG("Could not log value for test '" + testName + 40 | "', reached end of file while trying to append value."); 41 | break; 42 | } 43 | else if(c == ';') 44 | { 45 | file.seekp((int)file.tellg() - 3); 46 | file << "[" << 1000*time(NULL) << ", " << value << "]," << std::endl; 47 | file << "];"; 48 | break; 49 | } 50 | } 51 | } 52 | else 53 | { 54 | file << "var " + testName + " = [" << std::endl; 55 | file << "[" << 1000*time(NULL) << ", " << value << "]," << std::endl; 56 | file << "];"; 57 | } 58 | 59 | file.close(); 60 | } 61 | 62 | class Test 63 | { 64 | std::string testName; 65 | public: 66 | Test(const std::string& name) : testName(name) 67 | { 68 | log("Created"); 69 | } 70 | 71 | ~Test() 72 | { 73 | log("Destroyed"); 74 | } 75 | 76 | virtual bool run() = 0; 77 | 78 | inline void log(const std::string& str) 79 | { 80 | std::cout << "Test[" << testName << "] : " << str << std::endl; 81 | } 82 | }; 83 | 84 | struct TestConstructor 85 | { 86 | virtual Test* Construct() = 0; 87 | }; 88 | 89 | template 90 | struct Constructor : TestConstructor 91 | { 92 | Test* Construct() 93 | { 94 | return new TestType(); 95 | } 96 | }; 97 | 98 | #endif -------------------------------------------------------------------------------- /unitTest/Test_EvalJavascript.h: -------------------------------------------------------------------------------- 1 | #include "TestFramework.h" 2 | #include "WebCore.h" 3 | #include 4 | 5 | #define LENGTH_SEC 5 6 | 7 | class Test_EvalJavascript : public Test, public Awesomium::WebViewListener 8 | { 9 | Awesomium::WebView* webView; 10 | bool hasLoaded; 11 | public: 12 | Test_EvalJavascript() : Test("EvalJavascript"), hasLoaded(false) 13 | { 14 | webView = Awesomium::WebCore::Get().createWebView(15, 15, false, true); 15 | webView->loadFile("tests/EvalJavascript.html"); 16 | webView->setListener(this); 17 | 18 | Sleep(100); 19 | } 20 | 21 | ~Test_EvalJavascript() 22 | { 23 | webView->setListener(0); 24 | webView->destroy(); 25 | } 26 | 27 | bool run() 28 | { 29 | log("Running"); 30 | log("Waiting for page to load..."); 31 | while(!hasLoaded) 32 | { 33 | Awesomium::WebCore::Get().update(); 34 | Sleep(50); 35 | } 36 | log("Page loaded, running Javascript test"); 37 | 38 | timer t; 39 | t.start(); 40 | int loopCount = 0; 41 | double result; 42 | Awesomium::FutureJSValue futureVal; 43 | 44 | while(t.elapsed_time() < LENGTH_SEC) 45 | { 46 | futureVal = webView->executeJavascriptWithResult("test(987654321, 123456789, 'awesomium')"); 47 | 48 | //Sleep(1); 49 | 50 | result = futureVal.get().toDouble(); 51 | 52 | if((int)result != 25417574) 53 | { 54 | log("Test failed, incorrect value returned:"); 55 | LOG(result); 56 | return false; 57 | } 58 | 59 | loopCount++; 60 | } 61 | 62 | logTestValue("EvalJavascript", loopCount / (double)LENGTH_SEC); 63 | 64 | return true; 65 | } 66 | 67 | void onBeginNavigation(const std::string& url, const std::wstring& frameName) {} 68 | void onBeginLoading(const std::string& url, const std::wstring& frameName, int statusCode, const std::wstring& mimeType) {} 69 | void onFinishLoading() { hasLoaded = true; } 70 | void onCallback(const std::string& name, const Awesomium::JSArguments& args) {} 71 | void onReceiveTitle(const std::wstring& title, const std::wstring& frameName) {} 72 | void onChangeTooltip(const std::wstring& tooltip) {} 73 | #if defined(_WIN32) 74 | void onChangeCursor(const HCURSOR& cursor) {} 75 | #endif 76 | void onChangeKeyboardFocus(bool isFocused) {} 77 | void onChangeTargetURL(const std::string& url) {} 78 | }; 79 | -------------------------------------------------------------------------------- /unitTest/Test_RenderAsync.h: -------------------------------------------------------------------------------- 1 | #include "TestFramework.h" 2 | #include "WebCore.h" 3 | #include 4 | 5 | #define WIDTH 600 6 | #define HEIGHT 600 7 | #define LENGTH_SEC 5 8 | 9 | class Test_RenderAsync : public Test 10 | { 11 | Awesomium::WebView* webView; 12 | public: 13 | Test_RenderAsync() : Test("RenderAsync") 14 | { 15 | webView = Awesomium::WebCore::Get().createWebView(WIDTH, HEIGHT, false, true); 16 | webView->loadFile("tests/RenderTest.html"); 17 | Sleep(100); 18 | } 19 | 20 | ~Test_RenderAsync() 21 | { 22 | webView->destroy(); 23 | } 24 | 25 | bool run() 26 | { 27 | log("Running"); 28 | 29 | unsigned char* buffer = new unsigned char[WIDTH * HEIGHT * 4]; 30 | 31 | timer t; 32 | t.start(); 33 | int loopCount = 0; 34 | int renderCount = 0; 35 | 36 | while(t.elapsed_time() < LENGTH_SEC) 37 | { 38 | if(webView->isDirty()) 39 | { 40 | renderCount++; 41 | webView->render(buffer, WIDTH * 4, 4); 42 | } 43 | 44 | loopCount++; 45 | Sleep(1); 46 | } 47 | 48 | delete[] buffer; 49 | 50 | logTestValue("RenderAsync_LoopCount", loopCount / (double)LENGTH_SEC); 51 | logTestValue("RenderAsync_RenderCount", renderCount / (double)LENGTH_SEC); 52 | 53 | return true; 54 | } 55 | }; -------------------------------------------------------------------------------- /unitTest/Test_RenderSync.h: -------------------------------------------------------------------------------- 1 | #include "TestFramework.h" 2 | #include "WebCore.h" 3 | #include 4 | 5 | #define WIDTH 600 6 | #define HEIGHT 600 7 | #define LENGTH_SEC 5 8 | 9 | class Test_RenderSync : public Test 10 | { 11 | Awesomium::WebView* webView; 12 | public: 13 | Test_RenderSync() : Test("RenderSync") 14 | { 15 | webView = Awesomium::WebCore::Get().createWebView(WIDTH, HEIGHT); 16 | webView->loadFile("tests/RenderTest.html"); 17 | Sleep(100); 18 | } 19 | 20 | ~Test_RenderSync() 21 | { 22 | webView->destroy(); 23 | } 24 | 25 | bool run() 26 | { 27 | log("Running"); 28 | 29 | unsigned char* buffer = new unsigned char[WIDTH * HEIGHT * 4]; 30 | 31 | timer t; 32 | t.start(); 33 | int loopCount = 0; 34 | int renderCount = 0; 35 | 36 | while(t.elapsed_time() < LENGTH_SEC) 37 | { 38 | if(webView->isDirty()) 39 | { 40 | renderCount++; 41 | webView->render(buffer, WIDTH * 4, 4); 42 | } 43 | 44 | loopCount++; 45 | Sleep(1); 46 | } 47 | 48 | delete[] buffer; 49 | 50 | logTestValue("RenderSync_LoopCount", loopCount / (double)LENGTH_SEC); 51 | logTestValue("RenderSync_RenderCount", renderCount / (double)LENGTH_SEC); 52 | 53 | return true; 54 | } 55 | }; -------------------------------------------------------------------------------- /unitTest/Timer.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMER_H 2 | #define TIMER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /** 9 | * Timer utility class obtained from: 10 | */ 11 | class timer 12 | { 13 | friend std::ostream& operator<<(std::ostream& os, timer& t); 14 | 15 | private: 16 | bool running; 17 | clock_t start_clock; 18 | time_t start_time; 19 | double acc_time; 20 | 21 | public: 22 | 23 | double elapsed_time(); 24 | 25 | // 'running' is initially false. A timer needs to be explicitly started 26 | // using 'start' or 'restart' 27 | timer() : running(false), start_clock(0), start_time(0), acc_time(0) { } 28 | 29 | void start(const char* msg = 0); 30 | void restart(const char* msg = 0); 31 | void stop(const char* msg = 0); 32 | void check(const char* msg = 0); 33 | 34 | }; // class timer 35 | 36 | //=========================================================================== 37 | // Return the total time that the timer has been in the "running" 38 | // state since it was first "started" or last "restarted". For 39 | // "short" time periods (less than an hour), the actual cpu time 40 | // used is reported instead of the elapsed time. 41 | 42 | inline double timer::elapsed_time() 43 | { 44 | time_t acc_sec = time(0) - start_time; 45 | if (acc_sec < 3600) 46 | return (clock() - start_clock) / (1.0 * CLOCKS_PER_SEC); 47 | else 48 | return (1.0 * acc_sec); 49 | 50 | } // timer::elapsed_time 51 | 52 | //=========================================================================== 53 | // Start a timer. If it is already running, let it continue running. 54 | // Print an optional message. 55 | 56 | inline void timer::start(const char* msg) 57 | { 58 | // Print an optional message, something like "Starting timer t"; 59 | if (msg) std::cout << msg << std::endl; 60 | 61 | // Return immediately if the timer is already running 62 | if (running) return; 63 | 64 | // Set timer status to running and set the start time 65 | running = true; 66 | start_clock = clock(); 67 | start_time = time(0); 68 | 69 | } // timer::start 70 | 71 | //=========================================================================== 72 | // Turn the timer off and start it again from 0. Print an optional message. 73 | 74 | inline void timer::restart(const char* msg) 75 | { 76 | // Print an optional message, something like "Restarting timer t"; 77 | if (msg) std::cout << msg << std::endl; 78 | 79 | // Set timer status to running, reset accumulated time, and set start time 80 | running = true; 81 | acc_time = 0; 82 | start_clock = clock(); 83 | start_time = time(0); 84 | 85 | } // timer::restart 86 | 87 | //=========================================================================== 88 | // Stop the timer and print an optional message. 89 | 90 | inline void timer::stop(const char* msg) 91 | { 92 | // Print an optional message, something like "Stopping timer t"; 93 | if (msg) std::cout << msg << std::endl; 94 | 95 | // Compute accumulated running time and set timer status to not running 96 | if (running) acc_time += elapsed_time(); 97 | running = false; 98 | 99 | } // timer::stop 100 | 101 | //=========================================================================== 102 | // Print out an optional message followed by the current timer timing. 103 | 104 | inline void timer::check(const char* msg) 105 | { 106 | // Print an optional message, something like "Checking timer t"; 107 | if (msg) std::cout << msg << " : "; 108 | 109 | std::cout << "Elapsed time [" << std::setiosflags(std::ios::fixed) 110 | << std::setprecision(2) 111 | << acc_time + (running ? elapsed_time() : 0) << "] seconds\n"; 112 | 113 | } // timer::check 114 | 115 | //=========================================================================== 116 | // Allow timers to be printed to ostreams using the syntax 'os << t' 117 | // for an ostream 'os' and a timer 't'. For example, "cout << t" will 118 | // print out the total amount of time 't' has been "running". 119 | 120 | inline std::ostream& operator<<(std::ostream& os, timer& t) 121 | { 122 | os << std::setprecision(2) << std::setiosflags(std::ios::fixed) 123 | << t.acc_time + (t.running ? t.elapsed_time() : 0); 124 | return os; 125 | } 126 | 127 | //=========================================================================== 128 | 129 | #endif // TIMER_H 130 | 131 | -------------------------------------------------------------------------------- /unitTest/main.cpp: -------------------------------------------------------------------------------- 1 | #include "TestFramework.h" 2 | #include "WebCore.h" 3 | #include "Test_RenderSync.h" 4 | #include "Test_RenderAsync.h" 5 | #include "Test_EvalJavascript.h" 6 | #include 7 | #include 8 | #include 9 | 10 | std::string getCurrentWorkingDirectory(); 11 | 12 | int main() 13 | { 14 | Awesomium::WebCore* webCore = new Awesomium::WebCore(Awesomium::LOG_VERBOSE); 15 | webCore->setBaseDirectory(getCurrentWorkingDirectory() + "..\\media\\"); 16 | 17 | std::vector tests; 18 | tests.push_back(new Constructor()); 19 | tests.push_back(new Constructor()); 20 | tests.push_back(new Constructor()); 21 | 22 | size_t numTests = tests.size(); 23 | size_t numPassed = 0; 24 | 25 | while(tests.size()) 26 | { 27 | TestConstructor* testConstructor = tests.back(); 28 | Test* test = testConstructor->Construct(); 29 | tests.pop_back(); 30 | delete testConstructor; 31 | 32 | if(test->run()) 33 | numPassed++; 34 | 35 | delete test; 36 | } 37 | 38 | std::cout << (numPassed == numTests? "Testing Succeeded! " : "Testing Failed! ") << numPassed << " out of " << 39 | numTests << " tests passed." << std::endl; 40 | std::cout << "Press any key to continue..."; 41 | while(!kbhit()) Sleep(0); 42 | 43 | delete webCore; 44 | 45 | return 0; 46 | } 47 | 48 | #include 49 | #include 50 | 51 | std::string getCurrentWorkingDirectory() 52 | { 53 | std::string workingDirectory = ""; 54 | char currentPath[_MAX_PATH]; 55 | getcwd(currentPath, _MAX_PATH); 56 | workingDirectory = currentPath; 57 | 58 | return workingDirectory + "\\"; 59 | } -------------------------------------------------------------------------------- /unitTest/unitTest.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 24 | 27 | 30 | 33 | 36 | 39 | 50 | 53 | 56 | 59 | 66 | 69 | 72 | 75 | 78 | 81 | 84 | 87 | 90 | 91 | 99 | 102 | 105 | 108 | 111 | 114 | 122 | 125 | 128 | 131 | 140 | 143 | 146 | 149 | 152 | 155 | 158 | 161 | 164 | 165 | 166 | 167 | 168 | 169 | 174 | 177 | 178 | 181 | 182 | 185 | 186 | 189 | 190 | 193 | 194 | 197 | 198 | 199 | 204 | 205 | 210 | 211 | 212 | 213 | 214 | 215 | --------------------------------------------------------------------------------