123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- #ifndef __COCOS2D_UI_WEBVIEW_H
- #define __COCOS2D_UI_WEBVIEW_H
- #include "platform/CCPlatformConfig.h"
- #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) && !defined(CC_PLATFORM_OS_TVOS)
- #include "ui/UIWidget.h"
- #include "ui/GUIExport.h"
- #include "base/CCData.h"
- NS_CC_BEGIN
- namespace experimental{
- namespace ui{
-
- class WebViewImpl;
- class CC_GUI_DLL WebView : public cocos2d::ui::Widget {
- public:
-
- static WebView *create();
-
- void setJavascriptInterfaceScheme(const std::string &scheme);
-
- void loadData(const cocos2d::Data &data,
- const std::string &MIMEType,
- const std::string &encoding,
- const std::string &baseURL);
-
-
- void loadHTMLString(const std::string &string, const std::string &baseURL = "");
-
- void loadURL(const std::string &url);
-
- void loadURL(const std::string &url, bool cleanCachedData);
-
- void loadFile(const std::string &fileName);
-
- void stopLoading();
-
- void reload();
-
- bool canGoBack();
-
- bool canGoForward();
-
- void goBack();
-
- void goForward();
-
- void evaluateJS(const std::string &js);
-
- void setScalesPageToFit(const bool scalesPageToFit);
-
-
- void setOnShouldStartLoading(const std::function<bool(WebView *sender, const std::string &url)>& callback);
-
-
- typedef std::function<void(WebView *sender, const std::string &url)> ccWebViewCallback;
-
- void setOnDidFinishLoading(const ccWebViewCallback& callback);
-
-
- void setOnDidFailLoading(const ccWebViewCallback& callback);
-
-
- void setOnJSCallback(const ccWebViewCallback& callback);
-
-
- std::function<bool(WebView *sender, const std::string &url)> getOnShouldStartLoading()const;
-
-
- ccWebViewCallback getOnDidFinishLoading()const;
-
-
- ccWebViewCallback getOnDidFailLoading()const;
-
- ccWebViewCallback getOnJSCallback()const;
-
- void setBounces(bool bounce);
- virtual void draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) override;
-
- virtual void setVisible(bool visible) override;
- virtual void onEnter() override;
- virtual void onExit() override;
-
- protected:
- virtual cocos2d::ui::Widget* createCloneInstance() override;
- virtual void copySpecialProperties(Widget* model) override;
-
- std::function<bool(WebView *sender, const std::string &url)> _onShouldStartLoading;
-
- ccWebViewCallback _onDidFinishLoading;
-
- ccWebViewCallback _onDidFailLoading;
-
- ccWebViewCallback _onJSCallback;
- CC_CONSTRUCTOR_ACCESS:
-
- WebView();
-
-
- virtual ~WebView();
- private:
- WebViewImpl *_impl;
- friend class WebViewImpl;
- };
-
- }
- }
- }
- #endif
- #endif
|