PuzzleSDK
WebViewTest类 参考

#include <UIWebViewTest.h>

+ 类 WebViewTest 继承关系图:
+ WebViewTest 的协作图:

Public 成员函数

 CREATE_FUNC (WebViewTest)
 
virtual bool init () override
 
bool onWebViewShouldStartLoading (cocos2d::ui::WebView *sender, const std::string &url)
 
void onWebViewDidFinishLoading (cocos2d::ui::WebView *sender, const std::string &url)
 
void onWebViewDidFailLoading (cocos2d::ui::WebView *sender, const std::string &url)
 
- Public 成员函数 继承自 UIScene
 UIScene ()
 
 ~UIScene ()
 
virtual void onEnter () override
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual std::string title () const
 
virtual std::string subtitle () const
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 

Private 属性

cocos2d::ui::WebView * _webView
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 
- Protected 属性 继承自 UIScene
cocos2d::Layer * _uiLayer
 
cocos2d::ui::Layout * _widget
 
cocos2d::ui::Text * _sceneTitle
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

详细描述

在文件 UIWebViewTest.h33 行定义.

成员函数说明

◆ CREATE_FUNC()

WebViewTest::CREATE_FUNC ( WebViewTest  )

◆ init()

bool WebViewTest::init ( )
overridevirtual

重载 UIScene .

在文件 UIWebViewTest.cpp36 行定义.

37{
38 if (UIScene::init()) {
39 Size winSize = Director::getInstance()->getVisibleSize();
40
41
42 _webView = cocos2d::ui::WebView::create();
43 _webView->setPosition(winSize/2);
44 _webView->setContentSize(winSize * 0.5);
45 _webView->loadURL("https://www.baidu.com");
46 _webView->setScalesPageToFit(true);
47
48 _webView->setOnShouldStartLoading(CC_CALLBACK_2(WebViewTest::onWebViewShouldStartLoading, this));
49 _webView->setOnDidFinishLoading(CC_CALLBACK_2(WebViewTest::onWebViewDidFinishLoading, this));
50 _webView->setOnDidFailLoading(CC_CALLBACK_2(WebViewTest::onWebViewDidFailLoading, this));
51
52 this->addChild(_webView);
53
54 auto spriteHello = Sprite::create("Hello.png");
55 spriteHello->setPosition(winSize/2);
56 this->addChild(spriteHello);
57
58 TextField *urlTextField = TextField::create("Input a URL here", "Arial", 20);
59 urlTextField->setPlaceHolderColor(Color3B::RED);
60 urlTextField->setPosition(Vec2(winSize/2) + Vec2(-80, _webView->getContentSize().height/2 +
61 urlTextField->getContentSize().height/2 + 10));
62 this->addChild(urlTextField);
63
64 Text *httpLabel = Text::create("https:// ", "Arial", 20);
65 httpLabel->setTextColor(Color4B::GREEN);
66 httpLabel->setAnchorPoint(Vec2(1.0,0.5));
67 httpLabel->setPosition(urlTextField->getPosition() - Vec2(urlTextField->getContentSize().width/2,0));
68 this->addChild(httpLabel);
69
70
71 Button *resetBtn = Button::create("cocosui/animationbuttonnormal.png",
72 "cocosui/animationbuttonpressed.png");
73 resetBtn->setTitleText("Visit URL");
74 resetBtn->setPosition(Vec2(winSize/2) + Vec2(50, _webView->getContentSize().height/2 +
75 resetBtn->getContentSize().height/2 + 10));
76 resetBtn->addClickEventListener([=](Ref*){
77 if (urlTextField->getString().size() != 0)
78 {
79 _webView->loadURL(std::string("https://") + urlTextField->getString());
80 }
81 });
82 this->addChild(resetBtn);
83
84
85 Button *reloadBtn = Button::create("cocosui/animationbuttonnormal.png",
86 "cocosui/animationbuttonpressed.png");
87 reloadBtn->setTitleText("Reload");
88 reloadBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
89 reloadBtn->getContentSize().width/2 + 10,50 ));
90 reloadBtn->addClickEventListener([=](Ref*){
91 _webView->reload();
92 });
93 this->addChild(reloadBtn);
94
95 Button *forwardBtn = Button::create("cocosui/animationbuttonnormal.png",
96 "cocosui/animationbuttonpressed.png");
97 forwardBtn->setTitleText("Forward");
98 forwardBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
99 forwardBtn->getContentSize().width/2 + 10,0 ));
100 forwardBtn->addClickEventListener([=](Ref*){
101 _webView->goForward();
102 });
103 this->addChild(forwardBtn);
104
105
106
107 Button *backBtn = Button::create("cocosui/animationbuttonnormal.png",
108 "cocosui/animationbuttonpressed.png");
109 backBtn->setTitleText("Back");
110 backBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
111 backBtn->getContentSize().width/2 + 10,-50 ));
112 backBtn->addClickEventListener([=](Ref*){
113 _webView->goBack();
114 });
115 this->addChild(backBtn);
116
117
118 Button *loadFileBtn = Button::create("cocosui/animationbuttonnormal.png",
119 "cocosui/animationbuttonpressed.png");
120 loadFileBtn->setTitleText("Load FILE");
121 loadFileBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
122 loadFileBtn->getContentSize().width/2 + 10,50 ));
123 loadFileBtn->addClickEventListener([=](Ref*){
124 _webView->loadFile("Test.html");
125 });
126 this->addChild(loadFileBtn);
127
128 Button *loadHTMLBtn = Button::create("cocosui/animationbuttonnormal.png",
129 "cocosui/animationbuttonpressed.png");
130 loadHTMLBtn->setTitleText("Load Data");
131 loadHTMLBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
132 loadHTMLBtn->getContentSize().width/2 + 10,0 ));
133 loadHTMLBtn->addClickEventListener([=](Ref*){
134 _webView->loadHTMLString("<body style=\"font-size:50px;\">Hello World <img src=\"Icon.png\"/> </body>","Images/");
135 });
136 this->addChild(loadHTMLBtn);
137
138
139
140
141 Button *evalJsBtn = Button::create("cocosui/animationbuttonnormal.png",
142 "cocosui/animationbuttonpressed.png");
143 evalJsBtn->setTitleText("Evaluate JS");
144 evalJsBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
145 evalJsBtn->getContentSize().width/2 + 10,-50 ));
146 evalJsBtn->addClickEventListener([=](Ref*){
147 _webView->evaluateJS("alert(\"hello\")");
148 });
149 evalJsBtn->setName("evalJs");
150 this->addChild(evalJsBtn);
151
152 Button *opacityBtn = Button::create("cocosui/animationbuttonnormal.png",
153 "cocosui/animationbuttonpressed.png");
154 opacityBtn->setTitleText("Opacity 1.f");
155 opacityBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
156 opacityBtn->getContentSize().width/2 + 10, 100 ));
157 opacityBtn->addClickEventListener([=](Ref*){
158 auto currentOpacity = _webView->getOpacityWebView();
159 if(currentOpacity ==1.f){
160 _webView->setOpacityWebView(.5f);
161 opacityBtn->setTitleText("Opacity .5f");
162 }else if(currentOpacity == .5f){
163 _webView->setOpacityWebView(0);
164 opacityBtn->setTitleText("Opacity 0.f");
165 }else{
166 _webView->setOpacityWebView(1.f);
167 opacityBtn->setTitleText("Opacity 1.f");
168 }
169
170 });
171 opacityBtn->setName("Opacity");
172 this->addChild(opacityBtn);
173
174
175 Button *transparentBgBtn = Button::create("cocosui/animationbuttonnormal.png",
176 "cocosui/animationbuttonpressed.png");
177 transparentBgBtn->setTitleText("Transparent BG");
178 transparentBgBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
179 transparentBgBtn->getContentSize().width/2 + 10,-100 ));
180 transparentBgBtn->addClickEventListener([=](Ref*){
181 _webView->setBackgroundTransparent();
182 });
183 transparentBgBtn->setName("Transparent");
184 this->addChild(transparentBgBtn);
185
186 return true;
187 }
188 return false;
189}
virtual bool init() override
Definition: UIScene.cpp:46
bool onWebViewShouldStartLoading(cocos2d::ui::WebView *sender, const std::string &url)
cocos2d::ui::WebView * _webView
Definition: UIWebViewTest.h:45
void onWebViewDidFailLoading(cocos2d::ui::WebView *sender, const std::string &url)
void onWebViewDidFinishLoading(cocos2d::ui::WebView *sender, const std::string &url)

引用了 _webView, UIScene::init(), onWebViewDidFailLoading(), onWebViewDidFinishLoading() , 以及 onWebViewShouldStartLoading().

+ 函数调用图:

◆ onWebViewDidFailLoading()

void WebViewTest::onWebViewDidFailLoading ( cocos2d::ui::WebView *  sender,
const std::string &  url 
)

在文件 UIWebViewTest.cpp205 行定义.

206{
207 CCLOG("onWebViewDidFailLoading, url is %s", url.c_str());
208}

被这些函数引用 init().

+ 这是这个函数的调用关系图:

◆ onWebViewDidFinishLoading()

void WebViewTest::onWebViewDidFinishLoading ( cocos2d::ui::WebView *  sender,
const std::string &  url 
)

在文件 UIWebViewTest.cpp198 行定义.

199{
200 auto node = (ui::Button*)this->getChildByName("evalJs");
201 node->setTitleText("start loading...");
202 CCLOG("onWebViewDidFinishLoading, url is %s", url.c_str());
203}

被这些函数引用 init().

+ 这是这个函数的调用关系图:

◆ onWebViewShouldStartLoading()

bool WebViewTest::onWebViewShouldStartLoading ( cocos2d::ui::WebView *  sender,
const std::string &  url 
)

在文件 UIWebViewTest.cpp191 行定义.

192{
193 CCLOG("onWebViewShouldStartLoading, url is %s", url.c_str());
194 //don't do any OpenGL operation here!! It's forbidden!
195 return true;
196}

被这些函数引用 init().

+ 这是这个函数的调用关系图:

类成员变量说明

◆ _webView

cocos2d::ui::WebView* WebViewTest::_webView
private

在文件 UIWebViewTest.h45 行定义.

被这些函数引用 init().


该类的文档由以下文件生成: