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 class WindowOpenCallback;
00025 namespace base { class Thread; }
00026 class LockImpl;
00027 namespace WebViewEvents { class InvokeCallback; }
00028
00029 namespace Awesomium {
00030
00031 class WebCore;
00032
00037 enum MouseButton {
00038 LEFT_MOUSE_BTN,
00039 MIDDLE_MOUSE_BTN,
00040 RIGHT_MOUSE_BTN
00041 };
00042
00046 enum URLFilteringMode {
00051 UFM_BLACKLIST,
00052
00057 UFM_WHITELIST,
00058
00059
00060 UFM_NONE
00061 };
00062
00066 struct _OSMExport Rect {
00067 int x, y, width, height;
00068
00069 Rect();
00070 Rect(int x, int y, int width, int height);
00071 bool isEmpty() const;
00072 };
00073
00077 typedef std::map<std::string, std::string> HeaderDefinition;
00078
00083 class _OSMExport WebView
00084 {
00085 public:
00086
00093 void destroy();
00094
00101 void setListener(WebViewListener* listener);
00102
00108 WebViewListener* getListener();
00109
00121 void loadURL(const std::string& url, const std::wstring& frameName = L"", const std::string& username = "", const std::string& password = "");
00122
00134 void loadURL(const std::wstring& url, const std::wstring& frameName = L"", const std::string& username = "", const std::string& password = "");
00135
00146 void loadHTML(const std::string& html, const std::wstring& frameName = L"");
00147
00158 void loadHTML(const std::wstring& html, const std::wstring& frameName = L"");
00159
00169 void loadFile(const std::string& file, const std::wstring& frameName = L"");
00170
00182 void goToHistoryOffset(int offset);
00183
00191 void executeJavascript(const std::string& javascript, const std::wstring& frameName = L"");
00192
00200 void executeJavascript(const std::wstring& javascript, const std::wstring& frameName = L"");
00201
00212 Awesomium::FutureJSValue executeJavascriptWithResult(const std::string& javascript, const std::wstring& frameName = L"");
00213
00224 Awesomium::FutureJSValue executeJavascriptWithResult(const std::wstring& javascript, const std::wstring& frameName = L"");
00225
00238 void callJavascriptFunction(const std::wstring& object, const std::wstring& function, const JSArguments& args, const std::wstring& frameName = L"");
00239
00247 void createObject(const std::wstring& objectName);
00248
00254 void destroyObject(const std::wstring& objectName);
00255
00265 void setObjectProperty(const std::wstring& objectName, const std::wstring& propName, const JSValue& value);
00266
00276 void setObjectCallback(const std::wstring& objectName, const std::wstring& callbackName);
00277
00283 bool isDirty();
00284
00300 void render(unsigned char* destination, int destRowSpan, int destDepth, Awesomium::Rect* renderedRect = 0);
00301
00308 void injectMouseMove(int x, int y);
00309
00315 void injectMouseDown(Awesomium::MouseButton button);
00316
00322 void injectMouseUp(Awesomium::MouseButton button);
00323
00329 void injectMouseWheel(int scrollAmount);
00330
00336 void injectKeyboardEvent(const WebKeyboardEvent& keyboardEvent);
00337
00341 void cut();
00342
00346 void copy();
00347
00351 void paste();
00352
00356 void selectAll();
00357
00361 void deselectAll();
00362
00373 void getContentAsText(std::wstring& result, int maxChars);
00374
00378 void zoomIn();
00379
00383 void zoomOut();
00384
00388 void resetZoom();
00389
00396 void resize(int width, int height);
00397
00401 void unfocus();
00402
00406 void focus();
00407
00413 void setTransparent(bool isTransparent);
00414
00421 void setURLFilteringMode(URLFilteringMode mode);
00422
00434 void addURLFilter(const std::wstring& filter);
00435
00439 void clearAllURLFilters();
00440
00449 void setHeaderDefinition(const std::string& name, const Awesomium::HeaderDefinition& definition);
00450
00462 void addHeaderRewriteRule(const std::wstring& rule, const std::string& name);
00463
00469 void removeHeaderRewriteRule(const std::wstring& rule);
00470
00477 void removeHeaderRewriteRulesByDefinitionName(const std::string& name);
00478
00486 void setOpensExternalLinksInCallingFrame(bool isEnabled);
00487
00488 protected:
00489 WebView(int width, int height, bool isTransparent, bool enableAsyncRendering, int maxAsyncRenderPerSec, base::Thread* coreThread);
00490 ~WebView();
00491
00492 void startup();
00493 void setDirty(bool val = true);
00494 void setAsyncDirty(bool val = true);
00495 void setFinishRender();
00496 void setFinishShutdown();
00497 void setFinishGetContentText();
00498 void setFinishResize();
00499
00500 void resolveJSValueFuture(int requestID, Awesomium::JSValue* result);
00501 void handleFutureJSValueCallback(const Awesomium::JSArguments& args);
00502 void nullifyFutureJSValueCallbacks();
00503 void handleCheckKeyboardFocus(bool isFocused);
00504 void openExternalLink(const std::string& url, const std::wstring& source);
00505
00506 base::Thread* coreThread;
00507 WebViewProxy* viewProxy;
00508 WebViewWaitState* waitState;
00509 WebViewListener* listener;
00510 LockImpl* dirtinessLock;
00511 bool dirtiness, isKeyboardFocused;
00512 LockImpl* jsValueFutureMapLock;
00513 std::map<int, JSValueFutureImpl*> jsValueFutureMap;
00514
00515 const bool enableAsyncRendering;
00516
00517 friend class WebCore;
00518 friend class ::WebViewProxy;
00519 friend class ::FutureValueCallback;
00520 friend class ::CheckKeyboardFocusCallback;
00521 friend class ::WindowOpenCallback;
00522 };
00523
00524 }
00525
00526 #endif