1
0

UIWebView-inl.h 6.6 KB

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