UIWebView-inl.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /****************************************************************************
  2. Copyright (c) 2014-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. /// @cond DO_NOT_SHOW
  22. #include "ui/UIWebView.h"
  23. #include "platform/CCGLView.h"
  24. #include "base/CCDirector.h"
  25. #include "platform/CCFileUtils.h"
  26. #include "ui/UIWebViewImpl-tizen.h"
  27. NS_CC_BEGIN
  28. namespace experimental{
  29. namespace ui{
  30. WebView::WebView()
  31. : _impl(new WebViewImpl(this)),
  32. _onJSCallback(nullptr),
  33. _onShouldStartLoading(nullptr),
  34. _onDidFinishLoading(nullptr),
  35. _onDidFailLoading(nullptr)
  36. {
  37. }
  38. WebView::~WebView()
  39. {
  40. CC_SAFE_DELETE(_impl);
  41. }
  42. WebView *WebView::create()
  43. {
  44. auto webView = new(std::nothrow) WebView();
  45. if (webView && webView->init())
  46. {
  47. webView->autorelease();
  48. return webView;
  49. }
  50. CC_SAFE_DELETE(webView);
  51. return nullptr;
  52. }
  53. void WebView::setJavascriptInterfaceScheme(const std::string &scheme)
  54. {
  55. _impl->setJavascriptInterfaceScheme(scheme);
  56. }
  57. void WebView::loadData(const cocos2d::Data &data,
  58. const std::string &MIMEType,
  59. const std::string &encoding,
  60. const std::string &baseURL)
  61. {
  62. _impl->loadData(data, MIMEType, encoding, baseURL);
  63. }
  64. void WebView::loadHTMLString(const std::string &string, const std::string &baseURL)
  65. {
  66. _impl->loadHTMLString(string, baseURL);
  67. }
  68. void WebView::loadURL(const std::string &url)
  69. {
  70. this->loadURL(url, false);
  71. }
  72. void WebView::loadURL(const std::string& url, bool cleanCachedData)
  73. {
  74. _impl->loadURL(url, cleanCachedData);
  75. }
  76. void WebView::loadFile(const std::string &fileName)
  77. {
  78. _impl->loadFile(fileName);
  79. }
  80. void WebView::PostURL(const std::string &url,const std::string& data)
  81. {
  82. _impl->PostURL(url,data);
  83. }
  84. void WebView::stopLoading()
  85. {
  86. _impl->stopLoading();
  87. }
  88. void WebView::reload()
  89. {
  90. _impl->reload();
  91. }
  92. bool WebView::canGoBack()
  93. {
  94. return _impl->canGoBack();
  95. }
  96. bool WebView::canGoForward()
  97. {
  98. return _impl->canGoForward();
  99. }
  100. void WebView::goBack()
  101. {
  102. _impl->goBack();
  103. }
  104. void WebView::goForward()
  105. {
  106. _impl->goForward();
  107. }
  108. void WebView::evaluateJS(const std::string &js)
  109. {
  110. _impl->evaluateJS(js);
  111. }
  112. void WebView::setScalesPageToFit(bool const scalesPageToFit)
  113. {
  114. _impl->setScalesPageToFit(scalesPageToFit);
  115. }
  116. void WebView::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags)
  117. {
  118. cocos2d::ui::Widget::draw(renderer, transform, flags);
  119. _impl->draw(renderer, transform, flags);
  120. }
  121. void WebView::setVisible(bool visible)
  122. {
  123. Node::setVisible(visible);
  124. if (!visible || isRunning())
  125. {
  126. _impl->setVisible(visible);
  127. }
  128. }
  129. void WebView::setOpacityWebView(float opacity){
  130. _impl->setOpacityWebView(opacity);
  131. }
  132. float WebView::getOpacityWebView() const{
  133. return _impl->getOpacityWebView();
  134. }
  135. void WebView::setBackgroundTransparent()
  136. {
  137. _impl->setBackgroundTransparent();
  138. };
  139. void WebView::onEnter()
  140. {
  141. Widget::onEnter();
  142. if(isVisible())
  143. {
  144. _impl->setVisible(true);
  145. }
  146. }
  147. void WebView::onExit()
  148. {
  149. Widget::onExit();
  150. _impl->setVisible(false);
  151. }
  152. void WebView::setBounces(bool bounces)
  153. {
  154. _impl->setBounces(bounces);
  155. }
  156. cocos2d::ui::Widget* WebView::createCloneInstance()
  157. {
  158. return WebView::create();
  159. }
  160. void WebView::copySpecialProperties(Widget* model)
  161. {
  162. WebView* webView = dynamic_cast<WebView*>(model);
  163. if (webView)
  164. {
  165. this->_impl = webView->_impl;
  166. this->_onShouldStartLoading = webView->_onShouldStartLoading;
  167. this->_onDidFinishLoading = webView->_onDidFinishLoading;
  168. this->_onDidFailLoading = webView->_onDidFailLoading;
  169. this->_onJSCallback = webView->_onJSCallback;
  170. }
  171. }
  172. void WebView::setOnDidFailLoading(const ccWebViewCallback &callback)
  173. {
  174. _onDidFailLoading = callback;
  175. }
  176. void WebView::setOnDidFinishLoading(const ccWebViewCallback &callback)
  177. {
  178. _onDidFinishLoading = callback;
  179. }
  180. void WebView::setOnShouldStartLoading(const std::function<bool(WebView *sender, const std::string &url)> &callback)
  181. {
  182. _onShouldStartLoading = callback;
  183. }
  184. void WebView::setOnJSCallback(const ccWebViewCallback &callback)
  185. {
  186. _onJSCallback = callback;
  187. }
  188. std::function<bool(WebView *sender, const std::string &url)> WebView::getOnShouldStartLoading()const
  189. {
  190. return _onShouldStartLoading;
  191. }
  192. WebView::ccWebViewCallback WebView::getOnDidFailLoading()const
  193. {
  194. return _onDidFailLoading;
  195. }
  196. WebView::ccWebViewCallback WebView::getOnDidFinishLoading()const
  197. {
  198. return _onDidFinishLoading;
  199. }
  200. WebView::ccWebViewCallback WebView::getOnJSCallback()const
  201. {
  202. return _onJSCallback;
  203. }
  204. } // namespace ui
  205. } // namespace experimental
  206. } //namespace cocos2d
  207. /// @endcond