forked from cocos2d/cocos2d-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIWebView-inl.h
204 lines (167 loc) · 6.14 KB
/
UIWebView-inl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/****************************************************************************
Copyright (c) 2014-2015 Chukong Technologies Inc.
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.
****************************************************************************/
/// @cond DO_NOT_SHOW
#include "UIWebView.h"
#include "platform/CCGLView.h"
#include "base/CCDirector.h"
#include "platform/CCFileUtils.h"
NS_CC_BEGIN
namespace experimental{
namespace ui{
WebView::WebView()
: _impl(new WebViewImpl(this)),
_onJSCallback(nullptr),
_onShouldStartLoading(nullptr),
_onDidFinishLoading(nullptr),
_onDidFailLoading(nullptr)
{
}
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);
}
void WebView::loadURL(const std::string &url)
{
_impl->loadURL(url);
}
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);
}
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;
}
}
void WebView::setOnDidFailLoading(const ccWebViewCallback &callback)
{
_onDidFailLoading = callback;
}
void WebView::setOnDidFinishLoading(const ccWebViewCallback &callback)
{
_onDidFinishLoading = callback;
}
void WebView::setOnShouldStartLoading(const std::function<bool(WebView *sender, const std::string &url)> &callback)
{
_onShouldStartLoading = callback;
}
void WebView::setOnJSCallback(const ccWebViewCallback &callback)
{
_onJSCallback = callback;
}
std::function<bool(WebView *sender, const std::string &url)> WebView::getOnShouldStartLoading()const
{
return _onShouldStartLoading;
}
WebView::ccWebViewCallback WebView::getOnDidFailLoading()const
{
return _onDidFailLoading;
}
WebView::ccWebViewCallback WebView::getOnDidFinishLoading()const
{
return _onDidFinishLoading;
}
WebView::ccWebViewCallback WebView::getOnJSCallback()const
{
return _onJSCallback;
}
} // namespace ui
} // namespace experimental
} //namespace cocos2d
/// @endcond