00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __WEBVIEW_H__
00009 #define __WEBVIEW_H__
00010
00011 #include "WebViewListener.h"
00012 #include "WebKeyboardEvent.h"
00013 #include <map>
00014
00015 #if defined(_WIN32)
00016 #pragma warning( disable: 4251 )
00017 #endif
00018
00019 class WebViewWaitState;
00020 class WebViewProxy;
00021 class JSValueFutureImpl;
00022 class FutureValueCallback;
00023 class CheckKeyboardFocusCallback;
00024 namespace base { class Thread; }
00025 class LockImpl;
00026 namespace WebViewEvents { class InvokeCallback; }
00027
00028 namespace Awesomium {
00029
00030 class WebCore;
00031
00036 enum MouseButton {
00037 LEFT_MOUSE_BTN,
00038 MIDDLE_MOUSE_BTN,
00039 RIGHT_MOUSE_BTN
00040 };
00041
00045 enum URLFilteringMode {
00050 UFM_BLACKLIST,
00051
00056 UFM_WHITELIST,
00057
00058
00059 UFM_NONE
00060 };
00061
00065 struct _OSMExport Rect {
00066 int x, y, width, height;
00067
00068 Rect();
00069 Rect(int x, int y, int width, int height);
00070 bool isEmpty() const;
00071 };
00072
00076 typedef std::map<std::string, std::string> HeaderDefinition;
00077
00082 class _OSMExport WebView
00083 {
00084 public:
00085
00092 void destroy();
00093
00100 void setListener(WebViewListener* listener);
00101
00107 WebViewListener* getListener();
00108
00120 void loadURL(const std::string& url, const std::wstring& frameName = L"", const std::string& username = "", const std::string& password = "");
00121
00133 void loadURL(const std::wstring& url, const std::wstring& frameName = L"", const std::string& username = "", const std::string& password = "");
00134
00145 void loadHTML(const std::string& html, const std::wstring& frameName = L"");
00146
00157 void loadHTML(const std::wstring& html, const std::wstring& frameName = L"");
00158
00168 void loadFile(const std::string& file, const std::wstring& frameName = L"");
00169
00181 void goToHistoryOffset(int offset);
00182
00190 void executeJavascript(const std::string& javascript, const std::wstring& frameName = L"");
00191
00199 void executeJavascript(const std::wstring& javascript, const std::wstring& frameName = L"");
00200
00211 Awesomium::FutureJSValue executeJavascriptWithResult(const std::string& javascript, const std::wstring& frameName = L"");
00212
00223 Awesomium::FutureJSValue executeJavascriptWithResult(const std::wstring& javascript, const std::wstring& frameName = L"");
00224
00237 void callJavascriptFunction(const std::wstring& object, const std::wstring& function, const JSArguments& args, const std::wstring& frameName = L"");
00238
00246 void createObject(const std::wstring& objectName);
00247
00253 void destroyObject(const std::wstring& objectName);
00254
00264 void setObjectProperty(const std::wstring& objectName, const std::wstring& propName, const JSValue& value);
00265
00275 void setObjectCallback(const std::wstring& objectName, const std::wstring& callbackName);
00276
00282 bool isDirty();
00283
00299 void render(unsigned char* destination, int destRowSpan, int destDepth, Awesomium::Rect* renderedRect = 0);
00300
00307 void injectMouseMove(int x, int y);
00308
00314 void injectMouseDown(Awesomium::MouseButton button);
00315
00321 void injectMouseUp(Awesomium::MouseButton button);
00322
00328 void injectMouseWheel(int scrollAmount);
00329
00335 void injectKeyboardEvent(const WebKeyboardEvent& keyboardEvent);
00336
00340 void cut();
00341
00345 void copy();
00346
00350 void paste();
00351
00355 void selectAll();
00356
00360 void deselectAll();
00361
00372 void getContentAsText(std::wstring& result, int maxChars);
00373
00377 void zoomIn();
00378
00382 void zoomOut();
00383
00387 void resetZoom();
00388
00395 void resize(int width, int height);
00396
00400 void unfocus();
00401
00405 void focus();
00406
00412 void setTransparent(bool isTransparent);
00413
00420 void setURLFilteringMode(URLFilteringMode mode);
00421
00433 void addURLFilter(const std::wstring& filter);
00434
00438 void clearAllURLFilters();
00439
00448 void setHeaderDefinition(const std::string& name, const Awesomium::HeaderDefinition& definition);
00449
00461 void addHeaderRewriteRule(const std::wstring& rule, const std::string& name);
00462
00468 void removeHeaderRewriteRule(const std::wstring& rule);
00469
00476 void removeHeaderRewriteRulesByDefinitionName(const std::string& name);
00477
00478 protected:
00479 WebView(int width, int height, bool isTransparent, bool enableAsyncRendering, int maxAsyncRenderPerSec, base::Thread* coreThread);
00480 ~WebView();
00481
00482 void startup();
00483 void setDirty(bool val = true);
00484 void setAsyncDirty(bool val = true);
00485 void setFinishRender();
00486 void setFinishShutdown();
00487 void setFinishGetContentText();
00488 void setFinishResize();
00489
00490 void resolveJSValueFuture(int requestID, Awesomium::JSValue* result);
00491 void handleFutureJSValueCallback(const Awesomium::JSArguments& args);
00492 void nullifyFutureJSValueCallbacks();
00493 void handleCheckKeyboardFocus(bool isFocused);
00494
00495 base::Thread* coreThread;
00496 WebViewProxy* viewProxy;
00497 WebViewWaitState* waitState;
00498 WebViewListener* listener;
00499 LockImpl* dirtinessLock;
00500 bool dirtiness, isKeyboardFocused;
00501 LockImpl* jsValueFutureMapLock;
00502 std::map<int, JSValueFutureImpl*> jsValueFutureMap;
00503
00504 const bool enableAsyncRendering;
00505
00506 friend class WebCore;
00507 friend class ::WebViewProxy;
00508 friend class ::FutureValueCallback;
00509 friend class ::CheckKeyboardFocusCallback;
00510 };
00511
00512 }
00513
00514 #endif