2014-08-26 14:26:37 +08:00
|
|
|
/****************************************************************************
|
2015-03-24 20:23:51 +08:00
|
|
|
Copyright (c) 2014-2015 Chukong Technologies Inc.
|
2014-08-26 14:26:37 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @cond DO_NOT_SHOW
|
2014-08-26 14:26:37 +08:00
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "ui/UIWebView.h"
|
2014-08-26 14:26:37 +08:00
|
|
|
#include "platform/CCGLView.h"
|
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "platform/CCFileUtils.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
namespace experimental{
|
|
|
|
namespace ui{
|
|
|
|
|
|
|
|
WebView::WebView()
|
2014-09-15 18:02:11 +08:00
|
|
|
: _impl(new WebViewImpl(this)),
|
|
|
|
_onJSCallback(nullptr),
|
|
|
|
_onShouldStartLoading(nullptr),
|
|
|
|
_onDidFinishLoading(nullptr),
|
|
|
|
_onDidFailLoading(nullptr)
|
2014-08-26 14:26:37 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WebView::~WebView()
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(_impl);
|
|
|
|
}
|
|
|
|
|
|
|
|
WebView *WebView::create()
|
|
|
|
{
|
|
|
|
auto webView = new(std::nothrow) WebView();
|
|
|
|
if (webView && webView->init())
|
|
|
|
{
|
|
|
|
webView->autorelease();
|
|
|
|
return webView;
|
|
|
|
}
|
|
|
|
CC_SAFE_DELETE(webView);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::setJavascriptInterfaceScheme(const std::string &scheme)
|
|
|
|
{
|
|
|
|
_impl->setJavascriptInterfaceScheme(scheme);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::loadData(const cocos2d::Data &data,
|
|
|
|
const std::string &MIMEType,
|
|
|
|
const std::string &encoding,
|
|
|
|
const std::string &baseURL)
|
|
|
|
{
|
|
|
|
_impl->loadData(data, MIMEType, encoding, baseURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::loadHTMLString(const std::string &string, const std::string &baseURL)
|
|
|
|
{
|
|
|
|
_impl->loadHTMLString(string, baseURL);
|
|
|
|
}
|
|
|
|
|
2014-09-15 18:02:11 +08:00
|
|
|
void WebView::loadURL(const std::string &url)
|
2014-08-26 14:26:37 +08:00
|
|
|
{
|
2014-09-15 18:02:11 +08:00
|
|
|
_impl->loadURL(url);
|
2014-08-26 14:26:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::loadFile(const std::string &fileName)
|
|
|
|
{
|
|
|
|
_impl->loadFile(fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::stopLoading()
|
|
|
|
{
|
|
|
|
_impl->stopLoading();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::reload()
|
|
|
|
{
|
|
|
|
_impl->reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebView::canGoBack()
|
|
|
|
{
|
|
|
|
return _impl->canGoBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebView::canGoForward()
|
|
|
|
{
|
|
|
|
return _impl->canGoForward();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::goBack()
|
|
|
|
{
|
|
|
|
_impl->goBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::goForward()
|
|
|
|
{
|
|
|
|
_impl->goForward();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::evaluateJS(const std::string &js)
|
|
|
|
{
|
|
|
|
_impl->evaluateJS(js);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::setScalesPageToFit(bool const scalesPageToFit)
|
|
|
|
{
|
|
|
|
_impl->setScalesPageToFit(scalesPageToFit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags)
|
|
|
|
{
|
|
|
|
cocos2d::ui::Widget::draw(renderer, transform, flags);
|
|
|
|
_impl->draw(renderer, transform, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::setVisible(bool visible)
|
|
|
|
{
|
|
|
|
Node::setVisible(visible);
|
|
|
|
_impl->setVisible(visible);
|
|
|
|
}
|
2014-09-15 18:02:11 +08:00
|
|
|
|
|
|
|
cocos2d::ui::Widget* WebView::createCloneInstance()
|
|
|
|
{
|
|
|
|
return WebView::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::copySpecialProperties(Widget* model)
|
|
|
|
{
|
|
|
|
WebView* webView = dynamic_cast<WebView*>(model);
|
|
|
|
if (webView)
|
|
|
|
{
|
|
|
|
this->_impl = webView->_impl;
|
|
|
|
this->_onShouldStartLoading = webView->_onShouldStartLoading;
|
|
|
|
this->_onDidFinishLoading = webView->_onDidFinishLoading;
|
|
|
|
this->_onDidFailLoading = webView->_onDidFailLoading;
|
|
|
|
this->_onJSCallback = webView->_onJSCallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-18 11:52:23 +08:00
|
|
|
void WebView::setOnDidFailLoading(const ccWebViewCallback &callback)
|
2014-09-15 18:02:11 +08:00
|
|
|
{
|
|
|
|
_onDidFailLoading = callback;
|
|
|
|
}
|
|
|
|
|
2014-09-18 11:52:23 +08:00
|
|
|
void WebView::setOnDidFinishLoading(const ccWebViewCallback &callback)
|
2014-09-15 18:02:11 +08:00
|
|
|
{
|
|
|
|
_onDidFinishLoading = callback;
|
|
|
|
}
|
|
|
|
|
2014-09-18 00:04:48 +08:00
|
|
|
void WebView::setOnShouldStartLoading(const std::function<bool(WebView *sender, const std::string &url)> &callback)
|
2014-09-15 18:02:11 +08:00
|
|
|
{
|
|
|
|
_onShouldStartLoading = callback;
|
|
|
|
}
|
|
|
|
|
2014-09-18 11:52:23 +08:00
|
|
|
void WebView::setOnJSCallback(const ccWebViewCallback &callback)
|
2014-09-15 18:02:11 +08:00
|
|
|
{
|
|
|
|
_onJSCallback = callback;
|
|
|
|
}
|
|
|
|
|
2014-09-18 00:04:48 +08:00
|
|
|
std::function<bool(WebView *sender, const std::string &url)> WebView::getOnShouldStartLoading()const
|
2014-09-15 18:02:11 +08:00
|
|
|
{
|
|
|
|
return _onShouldStartLoading;
|
|
|
|
}
|
|
|
|
|
2014-09-18 11:52:23 +08:00
|
|
|
WebView::ccWebViewCallback WebView::getOnDidFailLoading()const
|
2014-09-15 18:02:11 +08:00
|
|
|
{
|
|
|
|
return _onDidFailLoading;
|
|
|
|
}
|
|
|
|
|
2014-09-18 11:52:23 +08:00
|
|
|
WebView::ccWebViewCallback WebView::getOnDidFinishLoading()const
|
2014-09-15 18:02:11 +08:00
|
|
|
{
|
|
|
|
return _onDidFinishLoading;
|
|
|
|
}
|
|
|
|
|
2014-09-18 11:52:23 +08:00
|
|
|
WebView::ccWebViewCallback WebView::getOnJSCallback()const
|
2014-09-15 18:02:11 +08:00
|
|
|
{
|
|
|
|
return _onJSCallback;
|
|
|
|
}
|
|
|
|
|
2014-08-26 16:53:37 +08:00
|
|
|
} // namespace ui
|
|
|
|
} // namespace experimental
|
|
|
|
} //namespace cocos2d
|
2014-08-26 14:26:37 +08:00
|
|
|
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @endcond
|