mirror of https://github.com/axmolengine/axmol.git
fix conflict
This commit is contained in:
commit
e4920ffdea
1
AUTHORS
1
AUTHORS
|
@ -920,6 +920,7 @@ Developers:
|
|||
Fix video scale issue in iOS
|
||||
Fix iOS VideoPlayer memory leak
|
||||
Added c++11 random library support
|
||||
Added WebView widget which supports iOS and Android
|
||||
|
||||
billtt
|
||||
Fixed a bug that Node::setScale(float) may not work properly
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
cocos2d-x-3.3?? ??
|
||||
[NEW] ActionManager: added removeAllActionsByTag()
|
||||
[NEW] Node: added stopAllActionsByTag()
|
||||
[NEW] UI: added `WebView` on iOS and Android
|
||||
|
||||
[FIX] Node: create unneeded temple `Vec2` object in `setPosition(int, int)`, `setPositionX()` and `setPositionY()`
|
||||
|
||||
|
@ -64,7 +65,7 @@ cocos2d-x-3.3alpha0 Aug.28 2014
|
|||
|
||||
[FIX] Lua-binding: replace dynamic_cast to std::is_base_of in object_to_luaval
|
||||
|
||||
[3rd] fbx-conv: complex FBX model support which is sseful for reskin, multiple meshes and multiple materials support
|
||||
[3rd] fbx-conv: complex FBX model support which is useful for reskin, multiple meshes and multiple materials support
|
||||
|
||||
cocos2d-x-3.2 Jul.17 2014
|
||||
[NEW] Node: added getChildByName method for get a node that can be cast to Type T
|
||||
|
|
|
@ -1350,6 +1350,14 @@
|
|||
1ABA68B11888D700007D1BB4 /* CCFontCharMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ABA68AD1888D700007D1BB4 /* CCFontCharMap.h */; };
|
||||
1AC0269C1914068200FA920D /* ConvertUTF.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AC026991914068200FA920D /* ConvertUTF.h */; };
|
||||
1AC0269D1914068200FA920D /* ConvertUTF.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AC026991914068200FA920D /* ConvertUTF.h */; };
|
||||
29394CF019B01DBA00D2DE1A /* UIWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEC19B01DBA00D2DE1A /* UIWebView.h */; };
|
||||
29394CF119B01DBA00D2DE1A /* UIWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEC19B01DBA00D2DE1A /* UIWebView.h */; };
|
||||
29394CF219B01DBA00D2DE1A /* UIWebView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CED19B01DBA00D2DE1A /* UIWebView.mm */; };
|
||||
29394CF319B01DBA00D2DE1A /* UIWebView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CED19B01DBA00D2DE1A /* UIWebView.mm */; };
|
||||
29394CF419B01DBA00D2DE1A /* UIWebViewImpl_iOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEE19B01DBA00D2DE1A /* UIWebViewImpl_iOS.h */; };
|
||||
29394CF519B01DBA00D2DE1A /* UIWebViewImpl_iOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEE19B01DBA00D2DE1A /* UIWebViewImpl_iOS.h */; };
|
||||
29394CF619B01DBA00D2DE1A /* UIWebViewImpl_iOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CEF19B01DBA00D2DE1A /* UIWebViewImpl_iOS.mm */; };
|
||||
29394CF719B01DBA00D2DE1A /* UIWebViewImpl_iOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CEF19B01DBA00D2DE1A /* UIWebViewImpl_iOS.mm */; };
|
||||
2986667F18B1B246000E39CA /* CCTweenFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2986667818B1B079000E39CA /* CCTweenFunction.cpp */; };
|
||||
299754F4193EC95400A54AC3 /* ObjectFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299754F2193EC95400A54AC3 /* ObjectFactory.cpp */; };
|
||||
299754F5193EC95400A54AC3 /* ObjectFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299754F2193EC95400A54AC3 /* ObjectFactory.cpp */; };
|
||||
|
@ -2296,6 +2304,10 @@
|
|||
2905FA1318CF08D100240AA3 /* UIWidget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIWidget.cpp; sourceTree = "<group>"; };
|
||||
2905FA1418CF08D100240AA3 /* UIWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWidget.h; sourceTree = "<group>"; };
|
||||
29080DEB191B82CE0066F8DF /* UIDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeprecated.h; sourceTree = "<group>"; };
|
||||
29394CEC19B01DBA00D2DE1A /* UIWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWebView.h; sourceTree = "<group>"; };
|
||||
29394CED19B01DBA00D2DE1A /* UIWebView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIWebView.mm; sourceTree = "<group>"; };
|
||||
29394CEE19B01DBA00D2DE1A /* UIWebViewImpl_iOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWebViewImpl_iOS.h; sourceTree = "<group>"; };
|
||||
29394CEF19B01DBA00D2DE1A /* UIWebViewImpl_iOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIWebViewImpl_iOS.mm; sourceTree = "<group>"; };
|
||||
2958244919873D8E00F9746D /* UIScale9Sprite.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIScale9Sprite.cpp; sourceTree = "<group>"; };
|
||||
2958244A19873D8E00F9746D /* UIScale9Sprite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScale9Sprite.h; sourceTree = "<group>"; };
|
||||
2986667818B1B079000E39CA /* CCTweenFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTweenFunction.cpp; sourceTree = "<group>"; };
|
||||
|
@ -4005,6 +4017,10 @@
|
|||
29CB8F521929D65500C841D6 /* experimental */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
29394CEC19B01DBA00D2DE1A /* UIWebView.h */,
|
||||
29394CED19B01DBA00D2DE1A /* UIWebView.mm */,
|
||||
29394CEE19B01DBA00D2DE1A /* UIWebViewImpl_iOS.h */,
|
||||
29394CEF19B01DBA00D2DE1A /* UIWebViewImpl_iOS.mm */,
|
||||
3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */,
|
||||
3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */,
|
||||
);
|
||||
|
@ -5023,6 +5039,7 @@
|
|||
1A570093180BC5A10088DEC7 /* CCActionTween.h in Headers */,
|
||||
50ABBD4A1925AB0000A911A9 /* Mat4.h in Headers */,
|
||||
15AE1A6919AAD40300C27E9E /* b2WorldCallbacks.h in Headers */,
|
||||
29394CF419B01DBA00D2DE1A /* UIWebViewImpl_iOS.h in Headers */,
|
||||
1A57009A180BC5C10088DEC7 /* CCAtlasNode.h in Headers */,
|
||||
15AE190819AAD35000C27E9E /* CCDatas.h in Headers */,
|
||||
1A5700A0180BC5D20088DEC7 /* CCNode.h in Headers */,
|
||||
|
@ -5220,6 +5237,7 @@
|
|||
15AE191019AAD35000C27E9E /* CCInputDelegate.h in Headers */,
|
||||
15AE184C19AAD30800C27E9E /* SimpleAudioEngine.h in Headers */,
|
||||
50ABBDA11925AB4100A911A9 /* CCGroupCommand.h in Headers */,
|
||||
29394CF019B01DBA00D2DE1A /* UIWebView.h in Headers */,
|
||||
15AE186519AAD31D00C27E9E /* CDOpenALSupport.h in Headers */,
|
||||
15AE1B5C19AADA9900C27E9E /* UITextAtlas.h in Headers */,
|
||||
1A5702FC180BCE750088DEC7 /* CCTMXXMLParser.h in Headers */,
|
||||
|
@ -5550,6 +5568,7 @@
|
|||
15AE1AB319AAD40300C27E9E /* b2CircleContact.h in Headers */,
|
||||
5034CA2E191D591100CE6051 /* ccShader_PositionTextureA8Color.frag in Headers */,
|
||||
15AE1A4F19AAD3D500C27E9E /* b2Shape.h in Headers */,
|
||||
29394CF519B01DBA00D2DE1A /* UIWebViewImpl_iOS.h in Headers */,
|
||||
50ABBD5B1925AB0000A911A9 /* Vec2.h in Headers */,
|
||||
50ABBD411925AB0000A911A9 /* CCMath.h in Headers */,
|
||||
1A5701A0180BCB590088DEC7 /* CCFont.h in Headers */,
|
||||
|
@ -5662,6 +5681,7 @@
|
|||
15AE1BAC19AADFDF00C27E9E /* UILayout.h in Headers */,
|
||||
1A570230180BCC1A0088DEC7 /* CCParticleSystemQuad.h in Headers */,
|
||||
15AE1AF619AAD42500C27E9E /* chipmunk_ffi.h in Headers */,
|
||||
29394CF119B01DBA00D2DE1A /* UIWebView.h in Headers */,
|
||||
15AE18B419AAD33D00C27E9E /* CCBSelectorResolver.h in Headers */,
|
||||
B24AA988195A675C007B4522 /* CCFastTMXLayer.h in Headers */,
|
||||
15AE1AB919AAD40300C27E9E /* b2EdgeAndCircleContact.h in Headers */,
|
||||
|
@ -6114,6 +6134,7 @@
|
|||
15AE187A19AAD33D00C27E9E /* CCBAnimationManager.cpp in Sources */,
|
||||
15AE1B6D19AADA9900C27E9E /* UIHelper.cpp in Sources */,
|
||||
15AE1A8A19AAD40300C27E9E /* b2PulleyJoint.cpp in Sources */,
|
||||
29394CF219B01DBA00D2DE1A /* UIWebView.mm in Sources */,
|
||||
15AE1BD419AAE01E00C27E9E /* CCControlSaturationBrightnessPicker.cpp in Sources */,
|
||||
1A57019D180BCB590088DEC7 /* CCFont.cpp in Sources */,
|
||||
1A5701A1180BCB590088DEC7 /* CCFontAtlas.cpp in Sources */,
|
||||
|
@ -6279,6 +6300,7 @@
|
|||
15AE196E19AAD35700C27E9E /* CCActionTimelineCache.cpp in Sources */,
|
||||
50ABBEB31925AB6F00A911A9 /* CCUserDefault.mm in Sources */,
|
||||
50ABBEB51925AB6F00A911A9 /* CCUserDefaultAndroid.cpp in Sources */,
|
||||
29394CF619B01DBA00D2DE1A /* UIWebViewImpl_iOS.mm in Sources */,
|
||||
50ABBE831925AB6F00A911A9 /* ccFPSImages.c in Sources */,
|
||||
15AE1B7019AADA9900C27E9E /* CocosGUI.cpp in Sources */,
|
||||
15AE19D019AAD3A700C27E9E /* AttachmentLoader.cpp in Sources */,
|
||||
|
@ -6622,6 +6644,7 @@
|
|||
50ABBD9C1925AB4100A911A9 /* ccGLStateCache.cpp in Sources */,
|
||||
1A5701E7180BCB8C0088DEC7 /* CCTransition.cpp in Sources */,
|
||||
15AE1AC019AAD40300C27E9E /* b2MotorJoint.cpp in Sources */,
|
||||
29394CF319B01DBA00D2DE1A /* UIWebView.mm in Sources */,
|
||||
15AE18BD19AAD33D00C27E9E /* CCLabelBMFontLoader.cpp in Sources */,
|
||||
50ABC01E1926664800A911A9 /* CCThread.cpp in Sources */,
|
||||
15AE1B3A19AAD43700C27E9E /* cpBB.c in Sources */,
|
||||
|
@ -6664,6 +6687,7 @@
|
|||
15AE1BFD19AAE01E00C27E9E /* CCInvocation.cpp in Sources */,
|
||||
B24AA98A195A675C007B4522 /* CCFastTMXTiledMap.cpp in Sources */,
|
||||
15AE18CE19AAD33D00C27E9E /* CCNodeLoader.cpp in Sources */,
|
||||
29394CF719B01DBA00D2DE1A /* UIWebViewImpl_iOS.mm in Sources */,
|
||||
15AE1AC619AAD40300C27E9E /* b2GearJoint.cpp in Sources */,
|
||||
B24AA986195A675C007B4522 /* CCFastTMXLayer.cpp in Sources */,
|
||||
1A57022E180BCC1A0088DEC7 /* CCParticleSystemQuad.cpp in Sources */,
|
||||
|
|
|
@ -865,6 +865,8 @@
|
|||
290E94B6196FC16900694919 /* CocostudioParserTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 290E94B3196FC16900694919 /* CocostudioParserTest.cpp */; };
|
||||
295824591987415900F9746D /* UIScale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 295824571987415900F9746D /* UIScale9SpriteTest.cpp */; };
|
||||
2958245A1987415900F9746D /* UIScale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 295824571987415900F9746D /* UIScale9SpriteTest.cpp */; };
|
||||
298D7F6F19AC31F300FF096D /* UIWebViewTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 298D7F6D19AC31F300FF096D /* UIWebViewTest.cpp */; };
|
||||
29AFEF6719ACCAA000F6B10A /* Test.html in Resources */ = {isa = PBXBuildFile; fileRef = 29AFEF6619ACCAA000F6B10A /* Test.html */; };
|
||||
29FBBBFE196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */; };
|
||||
29FBBBFF196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */; };
|
||||
38FA2E73194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 38FA2E71194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp */; };
|
||||
|
@ -2886,6 +2888,9 @@
|
|||
290E94B4196FC16900694919 /* CocostudioParserTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CocostudioParserTest.h; path = ../CocostudioParserTest.h; sourceTree = "<group>"; };
|
||||
295824571987415900F9746D /* UIScale9SpriteTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIScale9SpriteTest.cpp; sourceTree = "<group>"; };
|
||||
295824581987415900F9746D /* UIScale9SpriteTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScale9SpriteTest.h; sourceTree = "<group>"; };
|
||||
298D7F6D19AC31F300FF096D /* UIWebViewTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UIWebViewTest.cpp; path = UIWebViewTest/UIWebViewTest.cpp; sourceTree = "<group>"; };
|
||||
298D7F6E19AC31F300FF096D /* UIWebViewTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UIWebViewTest.h; path = UIWebViewTest/UIWebViewTest.h; sourceTree = "<group>"; };
|
||||
29AFEF6619ACCAA000F6B10A /* Test.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = Test.html; path = "../tests/cpp-tests/Resources/Test.html"; sourceTree = "<group>"; };
|
||||
29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocostudioParserJsonTest.cpp; sourceTree = "<group>"; };
|
||||
29FBBBFD196A9ECD00E65826 /* CocostudioParserJsonTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocostudioParserJsonTest.h; sourceTree = "<group>"; };
|
||||
38FA2E71194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ActionTimelineTestScene.cpp; sourceTree = "<group>"; };
|
||||
|
@ -6495,6 +6500,7 @@
|
|||
1AC35CB518CED84500F37B72 /* effect1.raw */,
|
||||
1AC35CB618CED84500F37B72 /* effect1.wav */,
|
||||
1AC35CC418CED84500F37B72 /* pew-pew-lei.wav */,
|
||||
29AFEF6619ACCAA000F6B10A /* Test.html */,
|
||||
);
|
||||
name = Resources;
|
||||
sourceTree = "<group>";
|
||||
|
@ -6907,6 +6913,15 @@
|
|||
path = UIWidgetAddNodeTest;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
298D7F6C19AC31C000FF096D /* UIWebViewTest */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
298D7F6D19AC31F300FF096D /* UIWebViewTest.cpp */,
|
||||
298D7F6E19AC31F300FF096D /* UIWebViewTest.h */,
|
||||
);
|
||||
name = UIWebViewTest;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -6988,6 +7003,7 @@
|
|||
29FBBC00196A9F0D00E65826 /* UIAndEditorTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
298D7F6C19AC31C000FF096D /* UIWebViewTest */,
|
||||
295824571987415900F9746D /* UIScale9SpriteTest.cpp */,
|
||||
295824581987415900F9746D /* UIScale9SpriteTest.h */,
|
||||
29080D1F191B595E0066F8DF /* CocosGUIScene.cpp */,
|
||||
|
@ -7816,6 +7832,7 @@
|
|||
1AC35D0918CED84500F37B72 /* TileMaps in Resources */,
|
||||
1AC35CFF18CED84500F37B72 /* Particles in Resources */,
|
||||
1AC35C8818CECF1400F37B72 /* Default-568h@2x.png in Resources */,
|
||||
29AFEF6719ACCAA000F6B10A /* Test.html in Resources */,
|
||||
1AC35CD518CED84500F37B72 /* ccb in Resources */,
|
||||
1AC35CE118CED84500F37B72 /* configs in Resources */,
|
||||
1AC35CE918CED84500F37B72 /* extensions in Resources */,
|
||||
|
@ -8316,6 +8333,7 @@
|
|||
1AC35B3E18CECF0C00F37B72 /* Bug-422.cpp in Sources */,
|
||||
29080DAC191B595E0066F8DF /* UIFocusTest.cpp in Sources */,
|
||||
1AC35BF618CECF0C00F37B72 /* HttpClientTest.cpp in Sources */,
|
||||
298D7F6F19AC31F300FF096D /* UIWebViewTest.cpp in Sources */,
|
||||
29080DA6191B595E0066F8DF /* UIButtonTest_Editor.cpp in Sources */,
|
||||
1AC35B5018CECF0C00F37B72 /* ClickAndMoveTest.cpp in Sources */,
|
||||
);
|
||||
|
|
|
@ -72,6 +72,8 @@ bool nodeComparisonLess(Node* n1, Node* n2)
|
|||
// XXX: Yes, nodes might have a sort problem once every 15 days if the game runs at 60 FPS and each frame sprites are reordered.
|
||||
int Node::s_globalOrderOfArrival = 1;
|
||||
|
||||
// MARK: Constructor, Destructor, Init
|
||||
|
||||
Node::Node(void)
|
||||
: _rotationX(0.0f)
|
||||
, _rotationY(0.0f)
|
||||
|
@ -144,6 +146,20 @@ Node::Node(void)
|
|||
_transform = _inverse = _additionalTransform = Mat4::IDENTITY;
|
||||
}
|
||||
|
||||
Node * Node::create()
|
||||
{
|
||||
Node * ret = new (std::nothrow) Node();
|
||||
if (ret && ret->init())
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Node::~Node()
|
||||
{
|
||||
CCLOGINFO( "deallocing Node: %p - tag: %i", this, _tag );
|
||||
|
@ -194,6 +210,34 @@ bool Node::init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void Node::cleanup()
|
||||
{
|
||||
// actions
|
||||
this->stopAllActions();
|
||||
this->unscheduleAllSelectors();
|
||||
|
||||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if ( _scriptType != kScriptTypeNone)
|
||||
{
|
||||
int action = kNodeOnCleanup;
|
||||
BasicScriptData data(this,(void*)&action);
|
||||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
||||
}
|
||||
#endif // #if CC_ENABLE_SCRIPT_BINDING
|
||||
|
||||
// timers
|
||||
for( const auto &child: _children)
|
||||
child->cleanup();
|
||||
}
|
||||
|
||||
std::string Node::getDescription() const
|
||||
{
|
||||
return StringUtils::format("<Node | Tag = %d", _tag);
|
||||
}
|
||||
|
||||
// MARK: getters / setters
|
||||
|
||||
float Node::getSkewX() const
|
||||
{
|
||||
return _skewX;
|
||||
|
@ -758,46 +802,7 @@ Rect Node::getBoundingBox() const
|
|||
return RectApplyAffineTransform(rect, getNodeToParentAffineTransform());
|
||||
}
|
||||
|
||||
Node * Node::create()
|
||||
{
|
||||
Node * ret = new (std::nothrow) Node();
|
||||
if (ret && ret->init())
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Node::cleanup()
|
||||
{
|
||||
// actions
|
||||
this->stopAllActions();
|
||||
this->unscheduleAllSelectors();
|
||||
|
||||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if ( _scriptType != kScriptTypeNone)
|
||||
{
|
||||
int action = kNodeOnCleanup;
|
||||
BasicScriptData data(this,(void*)&action);
|
||||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
||||
}
|
||||
#endif // #if CC_ENABLE_SCRIPT_BINDING
|
||||
|
||||
// timers
|
||||
for( const auto &child: _children)
|
||||
child->cleanup();
|
||||
}
|
||||
|
||||
|
||||
std::string Node::getDescription() const
|
||||
{
|
||||
return StringUtils::format("<Node | Tag = %d", _tag);
|
||||
}
|
||||
// MARK: Children logic
|
||||
|
||||
// lazy allocs
|
||||
void Node::childrenAlloc()
|
||||
|
@ -1184,6 +1189,8 @@ void Node::sortAllChildren()
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: draw / visit
|
||||
|
||||
void Node::draw()
|
||||
{
|
||||
auto renderer = Director::getInstance()->getRenderer();
|
||||
|
@ -1292,6 +1299,8 @@ Mat4 Node::transform(const Mat4& parentTransform)
|
|||
return ret;
|
||||
}
|
||||
|
||||
// MARK: events
|
||||
|
||||
void Node::onEnter()
|
||||
{
|
||||
if (_onEnterCallback)
|
||||
|
@ -1420,6 +1429,8 @@ void Node::setActionManager(ActionManager* actionManager)
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: actions
|
||||
|
||||
Action * Node::runAction(Action* action)
|
||||
{
|
||||
CCASSERT( action != nullptr, "Argument must be non-nil");
|
||||
|
@ -1460,7 +1471,7 @@ ssize_t Node::getNumberOfRunningActions() const
|
|||
return _actionManager->getNumberOfRunningActionsInTarget(this);
|
||||
}
|
||||
|
||||
// Node - Callbacks
|
||||
// MARK: Callbacks
|
||||
|
||||
void Node::setScheduler(Scheduler* scheduler)
|
||||
{
|
||||
|
@ -1591,6 +1602,8 @@ void Node::update(float fDelta)
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: coordinates
|
||||
|
||||
AffineTransform Node::getNodeToParentAffineTransform() const
|
||||
{
|
||||
AffineTransform ret;
|
||||
|
@ -1845,6 +1858,8 @@ void Node::updateTransform()
|
|||
child->updateTransform();
|
||||
}
|
||||
|
||||
// MARK: components
|
||||
|
||||
Component* Node::getComponent(const std::string& name)
|
||||
{
|
||||
if( _componentContainer )
|
||||
|
@ -1882,6 +1897,9 @@ void Node::removeAllComponents()
|
|||
}
|
||||
|
||||
#if CC_USE_PHYSICS
|
||||
|
||||
// MARK: Physics
|
||||
|
||||
void Node::updatePhysicsBodyTransform(Scene* scene)
|
||||
{
|
||||
updatePhysicsBodyScale(scene);
|
||||
|
@ -2035,6 +2053,8 @@ PhysicsBody* Node::getPhysicsBody() const
|
|||
}
|
||||
#endif //CC_USE_PHYSICS
|
||||
|
||||
// MARK: Opacity and Color
|
||||
|
||||
GLubyte Node::getOpacity(void) const
|
||||
{
|
||||
return _realOpacity;
|
||||
|
@ -2184,6 +2204,7 @@ void Node::disableCascadeColor()
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Camera
|
||||
void Node::setCameraMask(unsigned short mask, bool applyChildren)
|
||||
{
|
||||
_cameraMask = mask;
|
||||
|
@ -2195,6 +2216,8 @@ void Node::setCameraMask(unsigned short mask, bool applyChildren)
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Deprecated
|
||||
|
||||
__NodeRGBA::__NodeRGBA()
|
||||
{
|
||||
CCLOG("NodeRGBA deprecated.");
|
||||
|
|
|
@ -236,8 +236,6 @@
|
|||
<ClCompile Include="..\3d\CCSkeleton3D.cpp" />
|
||||
<ClCompile Include="..\3d\CCSprite3D.cpp" />
|
||||
<ClCompile Include="..\3d\CCSprite3DMaterial.cpp" />
|
||||
<ClCompile Include="..\3d\CCSubMesh.cpp" />
|
||||
<ClCompile Include="..\3d\CCSubMeshState.cpp" />
|
||||
<ClCompile Include="..\base\atitc.cpp" />
|
||||
<ClCompile Include="..\base\base64.cpp" />
|
||||
<ClCompile Include="..\base\CCAutoreleasePool.cpp" />
|
||||
|
@ -280,7 +278,6 @@
|
|||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\base\CCIMEDispatcher.cpp" />
|
||||
<ClCompile Include="..\base\CCModuleManager.cpp" />
|
||||
<ClCompile Include="..\base\CCNS.cpp" />
|
||||
<ClCompile Include="..\base\CCProfiling.cpp" />
|
||||
<ClCompile Include="..\base\ccRandom.cpp" />
|
||||
|
@ -462,8 +459,6 @@
|
|||
<ClInclude Include="..\3d\CCSkeleton3D.h" />
|
||||
<ClInclude Include="..\3d\CCSprite3D.h" />
|
||||
<ClInclude Include="..\3d\CCSprite3DMaterial.h" />
|
||||
<ClInclude Include="..\3d\CCSubMesh.h" />
|
||||
<ClInclude Include="..\3d\CCSubMeshState.h" />
|
||||
<ClInclude Include="..\base\atitc.h" />
|
||||
<ClInclude Include="..\base\base64.h" />
|
||||
<ClInclude Include="..\base\CCAutoreleasePool.h" />
|
||||
|
@ -496,7 +491,6 @@
|
|||
<ClInclude Include="..\base\CCIMEDispatcher.h" />
|
||||
<ClInclude Include="..\base\ccMacros.h" />
|
||||
<ClInclude Include="..\base\CCMap.h" />
|
||||
<ClInclude Include="..\base\CCModuleManager.h" />
|
||||
<ClInclude Include="..\base\CCNS.h" />
|
||||
<ClInclude Include="..\base\CCPlatformConfig.h" />
|
||||
<ClInclude Include="..\base\CCPlatformMacros.h" />
|
||||
|
|
|
@ -623,12 +623,6 @@
|
|||
<ClCompile Include="..\3d\CCSkeleton3D.cpp">
|
||||
<Filter>3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\3d\CCSubMeshState.cpp">
|
||||
<Filter>3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\3d\CCSubMesh.cpp">
|
||||
<Filter>3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\3d\CCAttachNode.cpp">
|
||||
<Filter>3d</Filter>
|
||||
</ClCompile>
|
||||
|
@ -647,9 +641,6 @@
|
|||
<ClCompile Include="..\renderer\CCVertexIndexData.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\base\CCModuleManager.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\base\ccRandom.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
|
@ -1313,12 +1304,6 @@
|
|||
<ClInclude Include="..\3d\CCSkeleton3D.h">
|
||||
<Filter>3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\3d\CCSubMeshState.h">
|
||||
<Filter>3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\3d\CCSubMesh.h">
|
||||
<Filter>3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\3d\CCAttachNode.h">
|
||||
<Filter>3d</Filter>
|
||||
</ClInclude>
|
||||
|
@ -1337,9 +1322,6 @@
|
|||
<ClInclude Include="..\renderer\CCVertexIndexData.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\base\CCModuleManager.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\base\ccRandom.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -85,6 +85,8 @@ list(REMOVE_ITEM cocos2d_source_files
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/base/CCController-android.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/base/CCUserDefaultAndroid.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ui/UIVideoPlayerAndroid.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ui/UIWebView.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ui/UIWebViewImpl_android.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/storage/local-storage/LocalStorageAndroid.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/base/CCEventController.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/base/CCEventListenerController.cpp"
|
||||
|
|
|
@ -33,11 +33,10 @@ import android.content.pm.PackageManager;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.util.Log;
|
||||
import android.widget.FrameLayout;
|
||||
import android.preference.PreferenceManager.OnActivityResultListener;
|
||||
import android.util.Log;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener {
|
||||
// ===========================================================
|
||||
|
@ -55,6 +54,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
private Cocos2dxHandler mHandler;
|
||||
private static Cocos2dxActivity sContext = null;
|
||||
private Cocos2dxVideoHelper mVideoHelper = null;
|
||||
private Cocos2dxWebViewHelper mWebViewHelper = null;
|
||||
|
||||
public static Context getContext() {
|
||||
return sContext;
|
||||
|
@ -102,6 +102,10 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
if (mVideoHelper == null) {
|
||||
mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout);
|
||||
}
|
||||
|
||||
if(mWebViewHelper == null){
|
||||
mWebViewHelper = new Cocos2dxWebViewHelper(mFrameLayout);
|
||||
}
|
||||
}
|
||||
|
||||
//native method,call GLViewImpl::getGLContextAttrs() to get the OpenGL ES context attributions
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
package org.cocos2dx.lib;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
public class Cocos2dxWebView extends WebView {
|
||||
private static final String TAG = Cocos2dxWebViewHelper.class.getSimpleName();
|
||||
|
||||
private int viewTag;
|
||||
private String jsScheme;
|
||||
|
||||
public Cocos2dxWebView(Context context) {
|
||||
this(context, -1);
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public Cocos2dxWebView(Context context, int viewTag) {
|
||||
super(context);
|
||||
this.viewTag = viewTag;
|
||||
this.jsScheme = "";
|
||||
|
||||
this.setFocusable(true);
|
||||
this.setFocusableInTouchMode(true);
|
||||
|
||||
this.getSettings().setSupportZoom(false);
|
||||
|
||||
this.getSettings().setJavaScriptEnabled(true);
|
||||
|
||||
// `searchBoxJavaBridge_` has big security risk. http://jvn.jp/en/jp/JVN53768697
|
||||
try {
|
||||
Method method = this.getClass().getMethod("removeJavascriptInterface", new Class[]{String.class});
|
||||
method.invoke(this, "searchBoxJavaBridge_");
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "This API level do not support `removeJavascriptInterface`");
|
||||
}
|
||||
|
||||
this.setWebViewClient(new Cocos2dxWebViewClient());
|
||||
this.setWebChromeClient(new WebChromeClient());
|
||||
}
|
||||
|
||||
public void setJavascriptInterfaceScheme(String scheme) {
|
||||
this.jsScheme = scheme != null ? scheme : "";
|
||||
}
|
||||
|
||||
public void setScalesPageToFit(boolean scalesPageToFit) {
|
||||
this.getSettings().setSupportZoom(scalesPageToFit);
|
||||
}
|
||||
|
||||
class Cocos2dxWebViewClient extends WebViewClient {
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String urlString) {
|
||||
URI uri = URI.create(urlString);
|
||||
if (uri != null && uri.getScheme().equals(jsScheme)) {
|
||||
Cocos2dxWebViewHelper._onJsCallback(viewTag, urlString);
|
||||
return true;
|
||||
}
|
||||
return Cocos2dxWebViewHelper._shouldStartLoading(viewTag, urlString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
super.onPageFinished(view, url);
|
||||
Cocos2dxWebViewHelper._didFinishLoading(viewTag, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||||
super.onReceivedError(view, errorCode, description, failingUrl);
|
||||
Cocos2dxWebViewHelper._didFailLoading(viewTag, failingUrl);
|
||||
}
|
||||
}
|
||||
|
||||
public void setWebViewRect(int left, int top, int maxWidth, int maxHeight) {
|
||||
fixSize(left, top, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
private void fixSize(int left, int top, int width, int height) {
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.leftMargin = left;
|
||||
layoutParams.topMargin = top;
|
||||
layoutParams.width = width;
|
||||
layoutParams.height = height;
|
||||
this.setLayoutParams(layoutParams);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,296 @@
|
|||
package org.cocos2dx.lib;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
|
||||
public class Cocos2dxWebViewHelper {
|
||||
private static final String TAG = Cocos2dxWebViewHelper.class.getSimpleName();
|
||||
private static Handler handler;
|
||||
private static Cocos2dxActivity cocos2dxActivity;
|
||||
private static FrameLayout layout;
|
||||
|
||||
private static SparseArray<Cocos2dxWebView> webViews;
|
||||
private static int viewTag = 0;
|
||||
|
||||
public Cocos2dxWebViewHelper(FrameLayout layout) {
|
||||
Cocos2dxWebViewHelper.layout = layout;
|
||||
Cocos2dxWebViewHelper.handler = new Handler(Looper.myLooper());
|
||||
|
||||
Cocos2dxWebViewHelper.cocos2dxActivity = (Cocos2dxActivity) Cocos2dxActivity.getContext();
|
||||
Cocos2dxWebViewHelper.webViews = new SparseArray<Cocos2dxWebView>();
|
||||
}
|
||||
|
||||
private static native boolean shouldStartLoading(int index, String message);
|
||||
|
||||
public static boolean _shouldStartLoading(int index, String message) {
|
||||
return !shouldStartLoading(index, message);
|
||||
}
|
||||
|
||||
private static native void didFinishLoading(int index, String message);
|
||||
|
||||
public static void _didFinishLoading(int index, String message) {
|
||||
didFinishLoading(index, message);
|
||||
}
|
||||
|
||||
private static native void didFailLoading(int index, String message);
|
||||
|
||||
public static void _didFailLoading(int index, String message) {
|
||||
didFailLoading(index, message);
|
||||
}
|
||||
|
||||
private static native void onJsCallback(int index, String message);
|
||||
|
||||
public static void _onJsCallback(int index, String message) {
|
||||
onJsCallback(index, message);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static int createWebView() {
|
||||
final int index = viewTag;
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = new Cocos2dxWebView(cocos2dxActivity, index);
|
||||
FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
layout.addView(webView, lParams);
|
||||
|
||||
webViews.put(index, webView);
|
||||
}
|
||||
});
|
||||
return viewTag++;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void removeWebView(final int index) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webViews.remove(index);
|
||||
layout.removeView(webView);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void setVisible(final int index, final boolean visible) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void setWebViewRect(final int index, final int left, final int top, final int maxWidth, final int maxHeight) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.setWebViewRect(left, top, maxWidth, maxHeight);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void setJavascriptInterfaceScheme(final int index, final String scheme) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.setJavascriptInterfaceScheme(scheme);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void loadData(final int index, final String data, final String mimeType, final String encoding, final String baseURL) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.loadDataWithBaseURL(baseURL, data, mimeType, encoding, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void loadHTMLString(final int index, final String htmlString, final String mimeType, final String encoding) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.loadData(htmlString, mimeType, encoding);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void loadUrl(final int index, final String url) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.loadUrl(url);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void loadFile(final int index, final String filePath) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.loadUrl(filePath);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void stopLoading(final int index) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.stopLoading();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static void reload(final int index) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static <T> T callInMainThread(Callable<T> call) throws ExecutionException, InterruptedException {
|
||||
FutureTask<T> task = new FutureTask<T>(call);
|
||||
handler.post(task);
|
||||
return task.get();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static boolean canGoBack(final int index) {
|
||||
Callable<Boolean> callable = new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
return webView != null && webView.canGoBack();
|
||||
}
|
||||
};
|
||||
try {
|
||||
return callInMainThread(callable);
|
||||
} catch (ExecutionException e) {
|
||||
return false;
|
||||
} catch (InterruptedException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static boolean canGoForward(final int index) {
|
||||
Callable<Boolean> callable = new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
return webView != null && webView.canGoForward();
|
||||
}
|
||||
};
|
||||
try {
|
||||
return callInMainThread(callable);
|
||||
} catch (ExecutionException e) {
|
||||
return false;
|
||||
} catch (InterruptedException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void goBack(final int index) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.goBack();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void goForward(final int index) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.goForward();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void evaluateJS(final int index, final String js) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.loadUrl("javascript:" + js);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void setScalesPageToFit(final int index, final boolean scalesPageToFit) {
|
||||
cocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.setScalesPageToFit(scalesPageToFit);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -31,6 +31,8 @@ UIRelativeBox.cpp \
|
|||
UIVideoPlayerAndroid.cpp \
|
||||
UIDeprecated.cpp \
|
||||
UIScale9Sprite.cpp \
|
||||
UIWebView.cpp \
|
||||
UIWebViewImpl_android.cpp \
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \
|
||||
$(LOCAL_PATH)/../editor-support
|
||||
|
|
|
@ -47,6 +47,7 @@ THE SOFTWARE.
|
|||
#include "ui/UIRelativeBox.h"
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
#include "ui/UIVideoPlayer.h"
|
||||
#include "ui/UIWebView.h"
|
||||
#endif
|
||||
#include "ui/UIDeprecated.h"
|
||||
#include "ui/GUIExport.h"
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 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.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#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))
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // namespace ui
|
||||
} // namespace experimental
|
||||
} //namespace cocos2d
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 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.
|
||||
****************************************************************************/
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
#include "UIWebViewImpl_android.h"
|
||||
#include "UIWebView-inl.h"
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,176 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 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.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __Cocos2d_Plugin_WebView_H_
|
||||
#define __Cocos2d_Plugin_WebView_H_
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
|
||||
#include "ui/UIWidget.h"
|
||||
#include "base/CCData.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
namespace experimental{
|
||||
namespace ui{
|
||||
|
||||
class WebViewImpl;
|
||||
|
||||
class WebView : public cocos2d::ui::Widget {
|
||||
public:
|
||||
/**
|
||||
* Allocates and initializes a WebView.
|
||||
*/
|
||||
static WebView *create();
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
WebView();
|
||||
|
||||
/**
|
||||
* Default destructor
|
||||
*/
|
||||
virtual ~WebView();
|
||||
|
||||
/**
|
||||
* Call before a web view begins loading.
|
||||
* @param sender The web view that is about to load new content.
|
||||
* @param url content URL.
|
||||
* @return YES if the web view should begin loading content; otherwise, NO .
|
||||
*/
|
||||
std::function<bool(WebView *sender, std::string url)> shouldStartLoading;
|
||||
/**
|
||||
* Call after a web view finishes loading.
|
||||
* @param sender The web view that has finished loading.
|
||||
* @param url content URL.
|
||||
*/
|
||||
std::function<void(WebView *sender, std::string url)> didFinishLoading;
|
||||
/**
|
||||
* Call if a web view failed to load content.
|
||||
* @param sender The web view that has failed loading.
|
||||
* @param url content URL.
|
||||
*/
|
||||
std::function<void(WebView *sender, std::string url)> didFailLoading;
|
||||
|
||||
/**
|
||||
* Set javascript interface scheme.
|
||||
* @see #onJsCallback
|
||||
*/
|
||||
void setJavascriptInterfaceScheme(const std::string &scheme);
|
||||
|
||||
/**
|
||||
* This callback called when load URL that start with javascript interface scheme.
|
||||
*/
|
||||
std::function<void(WebView *sender, std::string message)> onJsCallback;
|
||||
|
||||
/**
|
||||
* Sets the main page contents, MIME type, content encoding, and base URL.
|
||||
* @param data The content for the main page.
|
||||
* @param MIMEType The MIME type of the data.
|
||||
* @param encoding the encoding of the data.
|
||||
* @param baseURL The base URL for the content.
|
||||
*/
|
||||
void loadData(const cocos2d::Data &data,
|
||||
const std::string &MIMEType,
|
||||
const std::string &encoding,
|
||||
const std::string &baseURL);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the main page content and base URL.
|
||||
* @param string The content for the main page.
|
||||
* @param baseURL The base URL for the content.
|
||||
*/
|
||||
void loadHTMLString(const std::string &string, const std::string &baseURL);
|
||||
|
||||
/**
|
||||
* Loads the given URL.
|
||||
* @param url content URL
|
||||
*/
|
||||
void loadUrl(const std::string &url);
|
||||
|
||||
/**
|
||||
* Loads the given fileName.
|
||||
* @param fileName content fileName
|
||||
*/
|
||||
void loadFile(const std::string &fileName);
|
||||
|
||||
/**
|
||||
* Stops the current load.
|
||||
*/
|
||||
void stopLoading();
|
||||
|
||||
/**
|
||||
* Reloads the current URL.
|
||||
*/
|
||||
void reload();
|
||||
|
||||
/**
|
||||
* Gets whether this WebView has a back history item.
|
||||
* @return web view has a back history item.
|
||||
*/
|
||||
bool canGoBack();
|
||||
|
||||
/**
|
||||
* Gets whether this WebView has a forward history item.
|
||||
* @return web view has a forward history item.
|
||||
*/
|
||||
bool canGoForward();
|
||||
|
||||
/**
|
||||
* Goes back in the history.
|
||||
*/
|
||||
void goBack();
|
||||
|
||||
/**
|
||||
* Goes forward in the history.
|
||||
*/
|
||||
void goForward();
|
||||
|
||||
/**
|
||||
* evaluates JavaScript in the context of the currently displayed page
|
||||
*/
|
||||
void evaluateJS(const std::string &js);
|
||||
|
||||
/**
|
||||
* Set WebView should support zooming. The default value is false.
|
||||
*/
|
||||
void setScalesPageToFit(const bool scalesPageToFit);
|
||||
|
||||
virtual void draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) override;
|
||||
|
||||
virtual void setVisible(bool visible) override;
|
||||
|
||||
private:
|
||||
WebViewImpl *_impl;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace experimental
|
||||
}//namespace cocos2d
|
||||
|
||||
#endif
|
||||
|
||||
#endif //__Cocos2d_Plugin_WebView_H_
|
|
@ -0,0 +1,30 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 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.
|
||||
****************************************************************************/
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
#include "UIWebViewImpl_iOS.h"
|
||||
#include "UIWebView-inl.h"
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,435 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "UIWebViewImpl_android.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include "jni/JniHelper.h"
|
||||
#include <jni.h>
|
||||
|
||||
#include "UIWebView.h"
|
||||
#include "platform/CCGLView.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
|
||||
#define CLASS_NAME "org/cocos2dx/lib/Cocos2dxWebViewHelper"
|
||||
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,"",__VA_ARGS__)
|
||||
|
||||
extern "C" {
|
||||
/*
|
||||
* Class: org_cocos2dx_lib_Cocos2dxWebViewHelper
|
||||
* Method: shouldStartLoading
|
||||
* Signature: (ILjava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_cocos2dx_lib_Cocos2dxWebViewHelper_shouldStartLoading(JNIEnv *env, jclass, jint index, jstring jurl) {
|
||||
auto charUrl = env->GetStringUTFChars(jurl, NULL);
|
||||
std::string url = charUrl;
|
||||
env->ReleaseStringUTFChars(jurl, charUrl);
|
||||
return cocos2d::experimental::ui::WebViewImpl::shouldStartLoading(index, url);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_cocos2dx_lib_Cocos2dxWebViewHelper
|
||||
* Method: didFinishLoading
|
||||
* Signature: (ILjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxWebViewHelper_didFinishLoading(JNIEnv *env, jclass, jint index, jstring jurl) {
|
||||
// LOGD("didFinishLoading");
|
||||
auto charUrl = env->GetStringUTFChars(jurl, NULL);
|
||||
std::string url = charUrl;
|
||||
env->ReleaseStringUTFChars(jurl, charUrl);
|
||||
cocos2d::experimental::ui::WebViewImpl::didFinishLoading(index, url);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_cocos2dx_lib_Cocos2dxWebViewHelper
|
||||
* Method: didFailLoading
|
||||
* Signature: (ILjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxWebViewHelper_didFailLoading(JNIEnv *env, jclass, jint index, jstring jurl) {
|
||||
// LOGD("didFailLoading");
|
||||
auto charUrl = env->GetStringUTFChars(jurl, NULL);
|
||||
std::string url = charUrl;
|
||||
env->ReleaseStringUTFChars(jurl, charUrl);
|
||||
cocos2d::experimental::ui::WebViewImpl::didFailLoading(index, url);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_cocos2dx_lib_Cocos2dxWebViewHelper
|
||||
* Method: onJsCallback
|
||||
* Signature: (ILjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxWebViewHelper_onJsCallback(JNIEnv *env, jclass, jint index, jstring jmessage) {
|
||||
// LOGD("jsCallback");
|
||||
auto charMessage = env->GetStringUTFChars(jmessage, NULL);
|
||||
std::string message = charMessage;
|
||||
env->ReleaseStringUTFChars(jmessage, charMessage);
|
||||
cocos2d::experimental::ui::WebViewImpl::onJsCallback(index, message);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
int createWebViewJNI() {
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "createWebView", "()I")) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
jint viewTag = t.env->CallStaticIntMethod(t.classID, t.methodID);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
return viewTag;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void removeWebViewJNI(const int index) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "removeWebView", "(I)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setWebViewRectJNI(const int index, const int left, const int top, const int width, const int height) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setWebViewRect", "(IIIII)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, left, top, width, height);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setJavascriptInterfaceSchemeJNI(const int index, const std::string &scheme) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setJavascriptInterfaceScheme", "(ILjava/lang/String;)V")) {
|
||||
jstring jScheme = t.env->NewStringUTF(scheme.c_str());
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jScheme);
|
||||
|
||||
t.env->DeleteLocalRef(jScheme);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void loadDataJNI(const int index, const std::string &data, const std::string &MIMEType, const std::string &encoding, const std::string &baseURL) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "loadData", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")) {
|
||||
jstring jData = t.env->NewStringUTF(data.c_str());
|
||||
jstring jMIMEType = t.env->NewStringUTF(MIMEType.c_str());
|
||||
jstring jEncoding = t.env->NewStringUTF(encoding.c_str());
|
||||
jstring jBaseURL = t.env->NewStringUTF(baseURL.c_str());
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jData, jMIMEType, jEncoding, jBaseURL);
|
||||
|
||||
t.env->DeleteLocalRef(jData);
|
||||
t.env->DeleteLocalRef(jMIMEType);
|
||||
t.env->DeleteLocalRef(jEncoding);
|
||||
t.env->DeleteLocalRef(jBaseURL);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void loadHTMLStringJNI(const int index, const std::string &string, const std::string &baseURL) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "loadHTMLString", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")) {
|
||||
jstring jString = t.env->NewStringUTF(string.c_str());
|
||||
jstring jBaseURL = t.env->NewStringUTF(baseURL.c_str());
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jString, jBaseURL,nullptr);
|
||||
|
||||
t.env->DeleteLocalRef(jString);
|
||||
t.env->DeleteLocalRef(jBaseURL);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void loadUrlJNI(const int index, const std::string &url) {
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "loadUrl", "(ILjava/lang/String;)V")) {
|
||||
jstring jUrl = t.env->NewStringUTF(url.c_str());
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jUrl);
|
||||
|
||||
t.env->DeleteLocalRef(jUrl);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void loadFileJNI(const int index, const std::string &filePath) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "loadFile", "(ILjava/lang/String;)V")) {
|
||||
jstring jFilePath = t.env->NewStringUTF(filePath.c_str());
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jFilePath);
|
||||
|
||||
t.env->DeleteLocalRef(jFilePath);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void stopLoadingJNI(const int index) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "stopLoading", "(I)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void reloadJNI(const int index) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "reload", "(I)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
bool canGoBackJNI(const int index) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "canGoBack", "(I)Z")) {
|
||||
jboolean ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, index);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
return ret;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool canGoForwardJNI(const int index) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "canGoForward", "(I)Z")) {
|
||||
jboolean ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, index);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
return ret;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void goBackJNI(const int index) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "goBack", "(I)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void goForwardJNI(const int index) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "goForward", "(I)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void evaluateJSJNI(const int index, const std::string &js) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "evaluateJS", "(ILjava/lang/String;)V")) {
|
||||
jstring jjs = t.env->NewStringUTF(js.c_str());
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jjs);
|
||||
|
||||
t.env->DeleteLocalRef(jjs);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setScalesPageToFitJNI(const int index, const bool scalesPageToFit) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setScalesPageToFit", "(IZ)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, scalesPageToFit);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setWebViewVisibleJNI(const int index, const bool visible) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
cocos2d::JniMethodInfo t;
|
||||
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setVisible", "(IZ)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, visible);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
std::string getUrlStringByFileName(const std::string &fileName) {
|
||||
// LOGD("error: %s,%d",__func__,__LINE__);
|
||||
const std::string basePath("file:///android_asset/");
|
||||
std::string fullPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(fileName);
|
||||
const std::string assetsPath("assets/");
|
||||
|
||||
std::string urlString;
|
||||
if (fullPath.find(assetsPath) != std::string::npos) {
|
||||
urlString = fullPath.replace(fullPath.find_first_of(assetsPath), assetsPath.length(), basePath);
|
||||
} else {
|
||||
urlString = fullPath;
|
||||
}
|
||||
|
||||
return urlString;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace cocos2d {
|
||||
namespace experimental {
|
||||
namespace ui{
|
||||
|
||||
static std::unordered_map<int, cocos2d::experimental::ui::WebViewImpl*> s_WebViewImpls;
|
||||
|
||||
WebViewImpl::WebViewImpl(WebView *webView) : _viewTag(-1), _webView(webView) {
|
||||
_viewTag = createWebViewJNI();
|
||||
s_WebViewImpls[_viewTag] = this;
|
||||
}
|
||||
|
||||
WebViewImpl::~WebViewImpl() {
|
||||
removeWebViewJNI(_viewTag);
|
||||
s_WebViewImpls.erase(_viewTag);
|
||||
}
|
||||
|
||||
void WebViewImpl::loadData(const Data &data, const std::string &MIMEType, const std::string &encoding, const std::string &baseURL) {
|
||||
std::string dataString(reinterpret_cast<char *>(data.getBytes()), static_cast<unsigned int>(data.getSize()));
|
||||
loadDataJNI(_viewTag, dataString, MIMEType, encoding, baseURL);
|
||||
}
|
||||
|
||||
void WebViewImpl::loadHTMLString(const std::string &string, const std::string &baseURL) {
|
||||
loadHTMLStringJNI(_viewTag, string, baseURL);
|
||||
}
|
||||
|
||||
void WebViewImpl::loadUrl(const std::string &url) {
|
||||
loadUrlJNI(_viewTag, url);
|
||||
}
|
||||
|
||||
void WebViewImpl::loadFile(const std::string &fileName) {
|
||||
auto fullPath = getUrlStringByFileName(fileName);
|
||||
loadFileJNI(_viewTag, fullPath);
|
||||
}
|
||||
|
||||
void WebViewImpl::stopLoading() {
|
||||
stopLoadingJNI(_viewTag);
|
||||
}
|
||||
|
||||
void WebViewImpl::reload() {
|
||||
reloadJNI(_viewTag);
|
||||
}
|
||||
|
||||
bool WebViewImpl::canGoBack() {
|
||||
return canGoBackJNI(_viewTag);
|
||||
}
|
||||
|
||||
bool WebViewImpl::canGoForward() {
|
||||
return canGoForwardJNI(_viewTag);
|
||||
}
|
||||
|
||||
void WebViewImpl::goBack() {
|
||||
goBackJNI(_viewTag);
|
||||
}
|
||||
|
||||
void WebViewImpl::goForward() {
|
||||
goForwardJNI(_viewTag);
|
||||
}
|
||||
|
||||
void WebViewImpl::setJavascriptInterfaceScheme(const std::string &scheme) {
|
||||
setJavascriptInterfaceSchemeJNI(_viewTag, scheme);
|
||||
}
|
||||
|
||||
void WebViewImpl::evaluateJS(const std::string &js) {
|
||||
evaluateJSJNI(_viewTag, js);
|
||||
}
|
||||
|
||||
void WebViewImpl::setScalesPageToFit(const bool scalesPageToFit) {
|
||||
setScalesPageToFitJNI(_viewTag, scalesPageToFit);
|
||||
}
|
||||
|
||||
bool WebViewImpl::shouldStartLoading(const int viewTag, const std::string &url) {
|
||||
auto it = s_WebViewImpls.find(viewTag);
|
||||
if (it != s_WebViewImpls.end()) {
|
||||
auto webView = s_WebViewImpls[viewTag]->_webView;
|
||||
if (webView->shouldStartLoading) {
|
||||
return webView->shouldStartLoading(webView, url);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WebViewImpl::didFinishLoading(const int viewTag, const std::string &url){
|
||||
auto it = s_WebViewImpls.find(viewTag);
|
||||
if (it != s_WebViewImpls.end()) {
|
||||
auto webView = s_WebViewImpls[viewTag]->_webView;
|
||||
if (webView->didFinishLoading) {
|
||||
webView->didFinishLoading(webView, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebViewImpl::didFailLoading(const int viewTag, const std::string &url){
|
||||
auto it = s_WebViewImpls.find(viewTag);
|
||||
if (it != s_WebViewImpls.end()) {
|
||||
auto webView = s_WebViewImpls[viewTag]->_webView;
|
||||
if (webView->didFailLoading) {
|
||||
webView->didFailLoading(webView, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebViewImpl::onJsCallback(const int viewTag, const std::string &message){
|
||||
auto it = s_WebViewImpls.find(viewTag);
|
||||
if (it != s_WebViewImpls.end()) {
|
||||
auto webView = s_WebViewImpls[viewTag]->_webView;
|
||||
if (webView->onJsCallback) {
|
||||
webView->onJsCallback(webView, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebViewImpl::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) {
|
||||
if (flags & cocos2d::Node::FLAGS_TRANSFORM_DIRTY) {
|
||||
auto directorInstance = cocos2d::Director::getInstance();
|
||||
auto glView = directorInstance->getOpenGLView();
|
||||
auto frameSize = glView->getFrameSize();
|
||||
|
||||
auto winSize = directorInstance->getWinSize();
|
||||
|
||||
auto leftBottom = this->_webView->convertToWorldSpace(cocos2d::Point::ZERO);
|
||||
auto rightTop = this->_webView->convertToWorldSpace(cocos2d::Point(this->_webView->getContentSize().width,this->_webView->getContentSize().height));
|
||||
|
||||
auto uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2 ) * glView->getScaleX();
|
||||
auto uiTop = frameSize.height /2 - (rightTop.y - winSize.height / 2) * glView->getScaleY();
|
||||
|
||||
setWebViewRectJNI(_viewTag,uiLeft,uiTop,
|
||||
(rightTop.x - leftBottom.x) * glView->getScaleX(),
|
||||
(rightTop.y - leftBottom.y) * glView->getScaleY());
|
||||
}
|
||||
}
|
||||
|
||||
void WebViewImpl::setVisible(bool visible) {
|
||||
setWebViewVisibleJNI(_viewTag, visible);
|
||||
}
|
||||
} // namespace ui
|
||||
} // namespace experimental
|
||||
} //namespace cocos2d
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 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.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __cocos2d_plugin_WebViewImpl_android_H_
|
||||
#define __cocos2d_plugin_WebViewImpl_android_H_
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
namespace cocos2d {
|
||||
class Data;
|
||||
class Renderer;
|
||||
class Mat4;
|
||||
|
||||
namespace experimental {
|
||||
namespace ui{
|
||||
class WebView;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace cocos2d {
|
||||
namespace experimental {
|
||||
namespace ui{
|
||||
|
||||
class WebViewImpl {
|
||||
public:
|
||||
WebViewImpl(cocos2d::experimental::ui::WebView *webView);
|
||||
|
||||
virtual ~WebViewImpl();
|
||||
|
||||
void setJavascriptInterfaceScheme(const std::string &scheme);
|
||||
|
||||
void loadData(const cocos2d::Data &data, const std::string &MIMEType, const std::string &encoding, const std::string &baseURL);
|
||||
|
||||
void loadHTMLString(const std::string &string, const std::string &baseURL);
|
||||
|
||||
void loadUrl(const std::string &url);
|
||||
|
||||
void loadFile(const std::string &fileName);
|
||||
|
||||
void stopLoading();
|
||||
|
||||
void reload();
|
||||
|
||||
bool canGoBack();
|
||||
|
||||
bool canGoForward();
|
||||
|
||||
void goBack();
|
||||
|
||||
void goForward();
|
||||
|
||||
void evaluateJS(const std::string &js);
|
||||
|
||||
void setScalesPageToFit(const bool scalesPageToFit);
|
||||
|
||||
virtual void draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags);
|
||||
|
||||
virtual void setVisible(bool visible);
|
||||
|
||||
static bool shouldStartLoading(const int viewTag, const std::string &url);
|
||||
static void didFinishLoading(const int viewTag, const std::string &url);
|
||||
static void didFailLoading(const int viewTag, const std::string &url);
|
||||
static void onJsCallback(const int viewTag, const std::string &message);
|
||||
|
||||
private:
|
||||
int _viewTag;
|
||||
WebView *_webView;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace experimental
|
||||
} //cocos2d
|
||||
|
||||
#endif //__cocos2d_plugin_WebViewImpl_android_H_
|
|
@ -0,0 +1,91 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 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.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __cocos2d_plugin_WebViewImpl_IOS_H_
|
||||
#define __cocos2d_plugin_WebViewImpl_IOS_H_
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
@class UIWebViewWrapper;
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
class Data;
|
||||
class Renderer;
|
||||
class Mat4;
|
||||
|
||||
namespace experimental {
|
||||
namespace ui{
|
||||
|
||||
class WebView;
|
||||
|
||||
class WebViewImpl {
|
||||
public:
|
||||
WebViewImpl(WebView *webView);
|
||||
|
||||
virtual ~WebViewImpl();
|
||||
|
||||
void setJavascriptInterfaceScheme(const std::string &scheme);
|
||||
|
||||
void loadData(const cocos2d::Data &data,
|
||||
const std::string &MIMEType,
|
||||
const std::string &encoding,
|
||||
const std::string &baseURL);
|
||||
|
||||
void loadHTMLString(const std::string &string, const std::string &baseURL);
|
||||
|
||||
void loadUrl(const std::string &url);
|
||||
|
||||
void loadFile(const std::string &fileName);
|
||||
|
||||
void stopLoading();
|
||||
|
||||
void reload();
|
||||
|
||||
bool canGoBack();
|
||||
|
||||
bool canGoForward();
|
||||
|
||||
void goBack();
|
||||
|
||||
void goForward();
|
||||
|
||||
void evaluateJS(const std::string &js);
|
||||
|
||||
void setScalesPageToFit(const bool scalesPageToFit);
|
||||
|
||||
virtual void draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags);
|
||||
|
||||
virtual void setVisible(bool visible);
|
||||
|
||||
private:
|
||||
UIWebViewWrapper *_uiWebViewWrapper;
|
||||
WebView *_webView;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace experimental
|
||||
}//namespace cocos2d
|
||||
|
||||
#endif //__cocos2d_plugin_WebViewImpl_IOS_H_
|
|
@ -0,0 +1,353 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 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.
|
||||
****************************************************************************/
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
||||
|
||||
#include "UIWebViewImpl_iOS.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCGLView.h"
|
||||
#include "CCEAGLView.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "ui/UIWebView.h"
|
||||
|
||||
@interface UIWebViewWrapper : NSObject
|
||||
@property (nonatomic) std::function<bool(std::string url)> shouldStartLoading;
|
||||
@property (nonatomic) std::function<void(std::string url)> didFinishLoading;
|
||||
@property (nonatomic) std::function<void(std::string url)> didFailLoading;
|
||||
@property (nonatomic) std::function<void(std::string url)> onJsCallback;
|
||||
|
||||
@property(nonatomic, readonly, getter=canGoBack) BOOL canGoBack;
|
||||
@property(nonatomic, readonly, getter=canGoForward) BOOL canGoForward;
|
||||
|
||||
+ (instancetype)webViewWrapper;
|
||||
|
||||
- (void)setVisible:(bool)visible;
|
||||
|
||||
- (void)setFrameWithX:(float)x y:(float)y width:(float)width height:(float)height;
|
||||
|
||||
- (void)setJavascriptInterfaceScheme:(const std::string &)scheme;
|
||||
|
||||
- (void)loadData:(const std::string &)data MIMEType:(const std::string &)MIMEType textEncodingName:(const std::string &)encodingName baseURL:(const std::string &)baseURL;
|
||||
|
||||
- (void)loadHTMLString:(const std::string &)string baseURL:(const std::string &)baseURL;
|
||||
|
||||
- (void)loadUrl:(const std::string &)urlString;
|
||||
|
||||
- (void)loadFile:(const std::string &)filePath;
|
||||
|
||||
- (void)stopLoading;
|
||||
|
||||
- (void)reload;
|
||||
|
||||
- (void)evaluateJS:(const std::string &)js;
|
||||
|
||||
- (void)goBack;
|
||||
|
||||
- (void)goForward;
|
||||
|
||||
- (void)setScalesPageToFit:(const bool)scalesPageToFit;
|
||||
@end
|
||||
|
||||
|
||||
@interface UIWebViewWrapper () <UIWebViewDelegate>
|
||||
@property(nonatomic, retain) UIWebView *uiWebView;
|
||||
@property(nonatomic, copy) NSString *jsScheme;
|
||||
@end
|
||||
|
||||
@implementation UIWebViewWrapper {
|
||||
|
||||
}
|
||||
|
||||
+ (instancetype)webViewWrapper {
|
||||
return [[[self alloc] init] autorelease];
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.uiWebView = nil;
|
||||
self.shouldStartLoading = nullptr;
|
||||
self.didFinishLoading = nullptr;
|
||||
self.didFailLoading = nullptr;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
self.uiWebView.delegate = nil;
|
||||
[self.uiWebView removeFromSuperview];
|
||||
self.jsScheme = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)setupWebView {
|
||||
if (!self.uiWebView) {
|
||||
self.uiWebView = [[[UIWebView alloc] init] autorelease];
|
||||
self.uiWebView.delegate = self;
|
||||
}
|
||||
if (!self.uiWebView.superview) {
|
||||
auto view = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
auto eaglview = (CCEAGLView *) view->getEAGLView();
|
||||
[eaglview addSubview:self.uiWebView];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setVisible:(bool)visible {
|
||||
self.uiWebView.hidden = !visible;
|
||||
}
|
||||
|
||||
- (void)setFrameWithX:(float)x y:(float)y width:(float)width height:(float)height {
|
||||
if (!self.uiWebView) {[self setupWebView];}
|
||||
CGRect newFrame = CGRectMake(x, y, width, height);
|
||||
if (!CGRectEqualToRect(self.uiWebView.frame, newFrame)) {
|
||||
self.uiWebView.frame = CGRectMake(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setJavascriptInterfaceScheme:(const std::string &)scheme {
|
||||
self.jsScheme = @(scheme.c_str());
|
||||
}
|
||||
|
||||
- (void)loadData:(const std::string &)data MIMEType:(const std::string &)MIMEType textEncodingName:(const std::string &)encodingName baseURL:(const std::string &)baseURL {
|
||||
[self.uiWebView loadData:[NSData dataWithBytes:data.c_str() length:data.length()]
|
||||
MIMEType:@(MIMEType.c_str())
|
||||
textEncodingName:@(encodingName.c_str())
|
||||
baseURL:[NSURL URLWithString:@(baseURL.c_str())]];
|
||||
}
|
||||
|
||||
- (void)loadHTMLString:(const std::string &)string baseURL:(const std::string &)baseURL {
|
||||
[self.uiWebView loadHTMLString:@(string.c_str()) baseURL:[NSURL URLWithString:@(baseURL.c_str())]];
|
||||
}
|
||||
|
||||
- (void)loadUrl:(const std::string &)urlString {
|
||||
if (!self.uiWebView) {[self setupWebView];}
|
||||
NSURL *url = [NSURL URLWithString:@(urlString.c_str())];
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:url];
|
||||
[self.uiWebView loadRequest:request];
|
||||
}
|
||||
|
||||
- (void)loadFile:(const std::string &)filePath {
|
||||
if (!self.uiWebView) {[self setupWebView];}
|
||||
NSURL *url = [NSURL fileURLWithPath:@(filePath.c_str())];
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:url];
|
||||
[self.uiWebView loadRequest:request];
|
||||
}
|
||||
|
||||
- (void)stopLoading {
|
||||
[self.uiWebView stopLoading];
|
||||
}
|
||||
|
||||
- (void)reload {
|
||||
[self.uiWebView reload];
|
||||
}
|
||||
|
||||
- (BOOL)canGoForward {
|
||||
return self.uiWebView.canGoForward;
|
||||
}
|
||||
|
||||
- (BOOL)canGoBack {
|
||||
return self.uiWebView.canGoBack;
|
||||
}
|
||||
|
||||
- (void)goBack {
|
||||
[self.uiWebView goBack];
|
||||
}
|
||||
|
||||
- (void)goForward {
|
||||
[self.uiWebView goForward];
|
||||
}
|
||||
|
||||
- (void)evaluateJS:(const std::string &)js {
|
||||
if (!self.uiWebView) {[self setupWebView];}
|
||||
[self.uiWebView stringByEvaluatingJavaScriptFromString:@(js.c_str())];
|
||||
}
|
||||
|
||||
- (void)setScalesPageToFit:(const bool)scalesPageToFit {
|
||||
self.uiWebView.scalesPageToFit = scalesPageToFit;
|
||||
}
|
||||
|
||||
#pragma mark - UIWebViewDelegate
|
||||
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
|
||||
NSString *url = [[request URL] absoluteString];
|
||||
if ([[[request URL] scheme] isEqualToString:self.jsScheme]) {
|
||||
self.onJsCallback([url UTF8String]);
|
||||
return NO;
|
||||
}
|
||||
if (self.shouldStartLoading && url) {
|
||||
return self.shouldStartLoading([url UTF8String]);
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)webViewDidFinishLoad:(UIWebView *)webView {
|
||||
if (self.didFinishLoading) {
|
||||
NSString *url = [[webView.request URL] absoluteString];
|
||||
self.didFinishLoading([url UTF8String]);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
|
||||
if (self.didFailLoading) {
|
||||
NSString *url = error.userInfo[NSURLErrorFailingURLStringErrorKey];
|
||||
if (url) {
|
||||
self.didFailLoading([url UTF8String]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
namespace cocos2d {
|
||||
namespace experimental {
|
||||
namespace ui{
|
||||
|
||||
WebViewImpl::WebViewImpl(WebView *webView)
|
||||
: _uiWebViewWrapper([UIWebViewWrapper webViewWrapper]),
|
||||
_webView(webView) {
|
||||
[_uiWebViewWrapper retain];
|
||||
|
||||
_uiWebViewWrapper.shouldStartLoading = [this](std::string url) {
|
||||
if (this->_webView->shouldStartLoading) {
|
||||
return this->_webView->shouldStartLoading(this->_webView, url);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
_uiWebViewWrapper.didFinishLoading = [this](std::string url) {
|
||||
if (this->_webView->didFinishLoading) {
|
||||
this->_webView->didFinishLoading(this->_webView, url);
|
||||
}
|
||||
};
|
||||
_uiWebViewWrapper.didFailLoading = [this](std::string url) {
|
||||
if (this->_webView->didFailLoading) {
|
||||
this->_webView->didFailLoading(this->_webView, url);
|
||||
}
|
||||
};
|
||||
_uiWebViewWrapper.onJsCallback = [this](std::string url) {
|
||||
if (this->_webView->onJsCallback) {
|
||||
this->_webView->onJsCallback(this->_webView, url);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
WebViewImpl::~WebViewImpl(){
|
||||
[_uiWebViewWrapper release];
|
||||
_uiWebViewWrapper = nullptr;
|
||||
}
|
||||
|
||||
void WebViewImpl::setJavascriptInterfaceScheme(const std::string &scheme) {
|
||||
[_uiWebViewWrapper setJavascriptInterfaceScheme:scheme];
|
||||
}
|
||||
|
||||
void WebViewImpl::loadData(const Data &data,
|
||||
const std::string &MIMEType,
|
||||
const std::string &encoding,
|
||||
const std::string &baseURL) {
|
||||
|
||||
std::string dataString(reinterpret_cast<char *>(data.getBytes()), static_cast<unsigned int>(data.getSize()));
|
||||
[_uiWebViewWrapper loadData:dataString MIMEType:MIMEType textEncodingName:encoding baseURL:baseURL];
|
||||
}
|
||||
|
||||
void WebViewImpl::loadHTMLString(const std::string &string, const std::string &baseURL) {
|
||||
[_uiWebViewWrapper loadHTMLString:string baseURL:baseURL];
|
||||
}
|
||||
|
||||
void WebViewImpl::loadUrl(const std::string &url) {
|
||||
[_uiWebViewWrapper loadUrl:url];
|
||||
}
|
||||
|
||||
void WebViewImpl::loadFile(const std::string &fileName) {
|
||||
auto fullPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(fileName);
|
||||
[_uiWebViewWrapper loadFile:fullPath];
|
||||
}
|
||||
|
||||
void WebViewImpl::stopLoading() {
|
||||
[_uiWebViewWrapper stopLoading];
|
||||
}
|
||||
|
||||
void WebViewImpl::reload() {
|
||||
[_uiWebViewWrapper reload];
|
||||
}
|
||||
|
||||
bool WebViewImpl::canGoBack() {
|
||||
return _uiWebViewWrapper.canGoBack;
|
||||
}
|
||||
|
||||
bool WebViewImpl::canGoForward() {
|
||||
return _uiWebViewWrapper.canGoForward;
|
||||
}
|
||||
|
||||
void WebViewImpl::goBack() {
|
||||
[_uiWebViewWrapper goBack];
|
||||
}
|
||||
|
||||
void WebViewImpl::goForward() {
|
||||
[_uiWebViewWrapper goForward];
|
||||
}
|
||||
|
||||
void WebViewImpl::evaluateJS(const std::string &js) {
|
||||
[_uiWebViewWrapper evaluateJS:js];
|
||||
}
|
||||
|
||||
void WebViewImpl::setScalesPageToFit(const bool scalesPageToFit) {
|
||||
[_uiWebViewWrapper setScalesPageToFit:scalesPageToFit];
|
||||
}
|
||||
|
||||
void WebViewImpl::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) {
|
||||
if (flags & cocos2d::Node::FLAGS_TRANSFORM_DIRTY) {
|
||||
|
||||
auto direcrot = cocos2d::Director::getInstance();
|
||||
auto glView = direcrot->getOpenGLView();
|
||||
auto frameSize = glView->getFrameSize();
|
||||
|
||||
auto scaleFactor = [static_cast<CCEAGLView *>(glView->getEAGLView()) contentScaleFactor];
|
||||
|
||||
auto winSize = direcrot->getWinSize();
|
||||
|
||||
auto leftBottom = this->_webView->convertToWorldSpace(cocos2d::Vec2::ZERO);
|
||||
auto rightTop = this->_webView->convertToWorldSpace(cocos2d::Vec2(this->_webView->getContentSize().width, this->_webView->getContentSize().height));
|
||||
|
||||
auto x = (frameSize.width / 2 + (leftBottom.x - winSize.width / 2) * glView->getScaleX()) / scaleFactor;
|
||||
auto y = (frameSize.height / 2 - (rightTop.y - winSize.height / 2) * glView->getScaleY()) / scaleFactor;
|
||||
auto width = (rightTop.x - leftBottom.x) * glView->getScaleX() / scaleFactor;
|
||||
auto height = (rightTop.y - leftBottom.y) * glView->getScaleY() / scaleFactor;
|
||||
|
||||
[_uiWebViewWrapper setFrameWithX:x
|
||||
y:y
|
||||
width:width
|
||||
height:height];
|
||||
}
|
||||
}
|
||||
|
||||
void WebViewImpl::setVisible(bool visible){
|
||||
[_uiWebViewWrapper setVisible:visible];
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace experimental
|
||||
} //namespace cocos2d
|
||||
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
|
@ -779,6 +779,8 @@
|
|||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxTypefaces.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoView.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebView.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerAdapter.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerDelegate.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerUtils.java",
|
||||
|
@ -1036,6 +1038,14 @@
|
|||
"cocos/ui/UIVideoPlayer.h",
|
||||
"cocos/ui/UIVideoPlayerAndroid.cpp",
|
||||
"cocos/ui/UIVideoPlayerIOS.mm",
|
||||
"cocos/ui/UIWebView-inl.h",
|
||||
"cocos/ui/UIWebView.cpp",
|
||||
"cocos/ui/UIWebView.h",
|
||||
"cocos/ui/UIWebView.mm",
|
||||
"cocos/ui/UIWebViewImpl_android.cpp",
|
||||
"cocos/ui/UIWebViewImpl_android.h",
|
||||
"cocos/ui/UIWebViewImpl_iOS.h",
|
||||
"cocos/ui/UIWebViewImpl_iOS.mm",
|
||||
"cocos/ui/UIWidget.cpp",
|
||||
"cocos/ui/UIWidget.h",
|
||||
"cocos/ui/proj.wp8/libGUI.vcxproj",
|
||||
|
|
|
@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch
|
|||
APP_LDFLAGS := -latomic
|
||||
|
||||
|
||||
APP_DEBUG := $(strip $(NDK_DEBUG))
|
||||
ifeq ($(APP_DEBUG),1)
|
||||
ifeq ($(NDK_DEBUG),1)
|
||||
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
|
||||
APP_OPTIM := debug
|
||||
else
|
||||
APP_CPPFLAGS += -DNDEBUG
|
||||
APP_OPTIM := release
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch
|
|||
APP_LDFLAGS := -latomic
|
||||
|
||||
|
||||
APP_DEBUG := $(strip $(NDK_DEBUG))
|
||||
ifeq ($(APP_DEBUG),1)
|
||||
ifeq ($(NDK_DEBUG),1)
|
||||
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
|
||||
APP_OPTIM := debug
|
||||
else
|
||||
APP_CPPFLAGS += -DNDEBUG
|
||||
APP_OPTIM := release
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch
|
|||
APP_LDFLAGS := -latomic
|
||||
|
||||
|
||||
APP_DEBUG := $(strip $(NDK_DEBUG))
|
||||
ifeq ($(APP_DEBUG),1)
|
||||
ifeq ($(NDK_DEBUG),1)
|
||||
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
|
||||
APP_OPTIM := debug
|
||||
else
|
||||
APP_CPPFLAGS += -DNDEBUG
|
||||
APP_OPTIM := release
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch
|
|||
APP_LDFLAGS := -latomic
|
||||
|
||||
|
||||
APP_DEBUG := $(strip $(NDK_DEBUG))
|
||||
ifeq ($(APP_DEBUG),1)
|
||||
ifeq ($(NDK_DEBUG),1)
|
||||
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
|
||||
APP_OPTIM := debug
|
||||
else
|
||||
APP_CPPFLAGS += -DNDEBUG
|
||||
APP_OPTIM := release
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -104,6 +104,7 @@ Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp \
|
|||
Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp \
|
||||
Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp \
|
||||
Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp \
|
||||
Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp \
|
||||
Classes/UITest/CocoStudioGUITest/CustomWidget/CustomImageView.cpp \
|
||||
Classes/UITest/CocoStudioGUITest/CustomWidget/CustomImageViewReader.cpp \
|
||||
Classes/UITest/CocoStudioGUITest/CustomWidget/CustomParticleWidget.cpp \
|
||||
|
|
|
@ -29,6 +29,20 @@ g_guisTests[] =
|
|||
Director::getInstance()->replaceScene(scene);
|
||||
}
|
||||
},
|
||||
#endif
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
{
|
||||
"WebViewTest",
|
||||
[](Ref* sender)
|
||||
{
|
||||
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
||||
sceneManager->setCurrentUISceneId(KWebViewTest);
|
||||
sceneManager->setMinUISceneId(KWebViewTest);
|
||||
sceneManager->setMaxUISceneId(KWebViewTest);
|
||||
Scene* scene = sceneManager->currentUIScene();
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
}
|
||||
},
|
||||
#endif
|
||||
{
|
||||
"focus test",
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "UIFocusTest/UIFocusTest.h"
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
#include "UIVideoPlayerTest/UIVideoPlayerTest.h"
|
||||
#include "UIWebViewTest/UIWebViewTest.h"
|
||||
#endif
|
||||
#include "UIScale9SpriteTest.h"
|
||||
|
||||
|
@ -94,6 +95,7 @@ static const char* s_testArray[] =
|
|||
"UIFocusTest-ListView",
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
"UIVideoPlayerTest",
|
||||
"UIWebViewTest",
|
||||
#endif
|
||||
"UIScale9SpriteTest",
|
||||
"UIScale9SpriteHierarchialTest",
|
||||
|
@ -328,6 +330,8 @@ Scene *UISceneManager::currentUIScene()
|
|||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
case kUIVideoPlayerTest:
|
||||
return VideoPlayerTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
case KWebViewTest:
|
||||
return WebViewTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
#endif
|
||||
case kUIScale9SpriteTest:
|
||||
return UIScale9SpriteTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
|
|
|
@ -92,6 +92,7 @@ enum
|
|||
kUIFocusTest_ListView,
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
kUIVideoPlayerTest,
|
||||
KWebViewTest,
|
||||
#endif
|
||||
kUIScale9SpriteTest,
|
||||
kUIScale9SpriteHierarchialTest,
|
||||
|
|
|
@ -0,0 +1,168 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "UIWebViewTest.h"
|
||||
|
||||
WebViewTest::WebViewTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
WebViewTest::~WebViewTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool WebViewTest::init()
|
||||
{
|
||||
if (UIScene::init()) {
|
||||
Size winSize = Director::getInstance()->getVisibleSize();
|
||||
|
||||
|
||||
_webView = cocos2d::experimental::ui::WebView::create();
|
||||
_webView->setPosition(winSize/2);
|
||||
_webView->setContentSize(winSize * 0.5);
|
||||
_webView->loadUrl("http://www.google.com");
|
||||
_webView->setScalesPageToFit(true);
|
||||
|
||||
_webView->shouldStartLoading = CC_CALLBACK_2(WebViewTest::onWebViewShouldStartLoading, this);
|
||||
_webView->didFinishLoading = CC_CALLBACK_2(WebViewTest::onWebViewDidFinishLoading, this);
|
||||
_webView->didFailLoading = CC_CALLBACK_2(WebViewTest::onWebViewDidFailLoading, this);
|
||||
|
||||
this->addChild(_webView);
|
||||
|
||||
TextField *urlTextField = TextField::create("Input a URL here", "Arial", 20);
|
||||
urlTextField->setPlaceHolderColor(Color3B::RED);
|
||||
urlTextField->setPosition(Vec2(winSize/2) + Vec2(-80, _webView->getContentSize().height/2 +
|
||||
urlTextField->getContentSize().height/2 + 10));
|
||||
this->addChild(urlTextField);
|
||||
|
||||
Text *httpLabel = Text::create("http:// ", "Arial", 20);
|
||||
httpLabel->setTextColor(Color4B::GREEN);
|
||||
httpLabel->setAnchorPoint(Vec2(1.0,0.5));
|
||||
httpLabel->setPosition(urlTextField->getPosition() - Vec2(urlTextField->getContentSize().width/2,0));
|
||||
this->addChild(httpLabel);
|
||||
|
||||
|
||||
Button *resetBtn = Button::create("cocosui/animationbuttonnormal.png",
|
||||
"cocosui/animationbuttonpressed.png");
|
||||
resetBtn->setTitleText("Visit URL");
|
||||
resetBtn->setPosition(Vec2(winSize/2) + Vec2(50, _webView->getContentSize().height/2 +
|
||||
resetBtn->getContentSize().height/2 + 10));
|
||||
resetBtn->addClickEventListener([=](Ref*){
|
||||
_webView->loadUrl(std::string("http://") + urlTextField->getStringValue());
|
||||
});
|
||||
this->addChild(resetBtn);
|
||||
|
||||
|
||||
Button *reloadBtn = Button::create("cocosui/animationbuttonnormal.png",
|
||||
"cocosui/animationbuttonpressed.png");
|
||||
reloadBtn->setTitleText("Reload");
|
||||
reloadBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
|
||||
reloadBtn->getContentSize().width/2 + 10,50 ));
|
||||
reloadBtn->addClickEventListener([=](Ref*){
|
||||
_webView->reload();
|
||||
});
|
||||
this->addChild(reloadBtn);
|
||||
|
||||
Button *forwardBtn = Button::create("cocosui/animationbuttonnormal.png",
|
||||
"cocosui/animationbuttonpressed.png");
|
||||
forwardBtn->setTitleText("Forward");
|
||||
forwardBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
|
||||
forwardBtn->getContentSize().width/2 + 10,0 ));
|
||||
forwardBtn->addClickEventListener([=](Ref*){
|
||||
_webView->goForward();
|
||||
});
|
||||
this->addChild(forwardBtn);
|
||||
|
||||
|
||||
|
||||
Button *backBtn = Button::create("cocosui/animationbuttonnormal.png",
|
||||
"cocosui/animationbuttonpressed.png");
|
||||
backBtn->setTitleText("Back");
|
||||
backBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
|
||||
backBtn->getContentSize().width/2 + 10,-50 ));
|
||||
backBtn->addClickEventListener([=](Ref*){
|
||||
_webView->goBack();
|
||||
});
|
||||
this->addChild(backBtn);
|
||||
|
||||
|
||||
Button *loadFileBtn = Button::create("cocosui/animationbuttonnormal.png",
|
||||
"cocosui/animationbuttonpressed.png");
|
||||
loadFileBtn->setTitleText("Load FILE");
|
||||
loadFileBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
|
||||
loadFileBtn->getContentSize().width/2 + 10,50 ));
|
||||
loadFileBtn->addClickEventListener([=](Ref*){
|
||||
_webView->loadFile("Test.html");
|
||||
});
|
||||
this->addChild(loadFileBtn);
|
||||
|
||||
Button *loadHTMLBtn = Button::create("cocosui/animationbuttonnormal.png",
|
||||
"cocosui/animationbuttonpressed.png");
|
||||
loadHTMLBtn->setTitleText("Load HTML");
|
||||
loadHTMLBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
|
||||
loadHTMLBtn->getContentSize().width/2 + 10,0 ));
|
||||
loadHTMLBtn->addClickEventListener([=](Ref*){
|
||||
_webView->loadHTMLString("<body style=\"font-size:50px;\">Hello World</body>","text/html");
|
||||
});
|
||||
this->addChild(loadHTMLBtn);
|
||||
|
||||
|
||||
|
||||
|
||||
Button *evalJsBtn = Button::create("cocosui/animationbuttonnormal.png",
|
||||
"cocosui/animationbuttonpressed.png");
|
||||
evalJsBtn->setTitleText("Evaluate JS");
|
||||
evalJsBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
|
||||
evalJsBtn->getContentSize().width/2 + 10,-50 ));
|
||||
evalJsBtn->addClickEventListener([=](Ref*){
|
||||
_webView->evaluateJS("alert(\"hello\")");
|
||||
});
|
||||
this->addChild(evalJsBtn);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WebViewTest::onWebViewShouldStartLoading(experimental::ui::WebView *sender, std::string url)
|
||||
{
|
||||
CCLOG("onWebViewShouldStartLoading, url is %s", url.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WebViewTest::onWebViewDidFinishLoading(experimental::ui::WebView *sender, std::string url)
|
||||
{
|
||||
CCLOG("onWebViewDidFinishLoading, url is %s", url.c_str());
|
||||
|
||||
}
|
||||
|
||||
void WebViewTest::onWebViewDidFailLoading(experimental::ui::WebView *sender, std::string url)
|
||||
{
|
||||
CCLOG("onWebViewDidFailLoading, url is %s", url.c_str());
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 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.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __cocos2d_tests__UIWebViewTest__
|
||||
#define __cocos2d_tests__UIWebViewTest__
|
||||
|
||||
#include "../UIScene.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
class WebViewTest : public UIScene
|
||||
{
|
||||
public:
|
||||
WebViewTest();
|
||||
virtual ~WebViewTest();
|
||||
UI_SCENE_CREATE_FUNC(WebViewTest);
|
||||
|
||||
virtual bool init();
|
||||
bool onWebViewShouldStartLoading(experimental::ui::WebView *sender, std::string url);
|
||||
void onWebViewDidFinishLoading(experimental::ui::WebView *sender, std::string url);
|
||||
void onWebViewDidFailLoading(experimental::ui::WebView *sender, std::string url);
|
||||
|
||||
|
||||
private:
|
||||
cocos2d::experimental::ui::WebView *_webView;
|
||||
|
||||
};
|
||||
|
||||
#endif /* defined(__cocos2d_tests__UIWebViewTest__) */
|
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<body style="font-size:100px;">
|
||||
Hello World
|
||||
</body>
|
||||
</html>
|
|
@ -5,8 +5,7 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch
|
|||
APP_LDFLAGS := -latomic
|
||||
|
||||
|
||||
APP_DEBUG := $(strip $(NDK_DEBUG))
|
||||
ifeq ($(APP_DEBUG),1)
|
||||
ifeq ($(NDK_DEBUG),1)
|
||||
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
|
||||
APP_OPTIM := debug
|
||||
else
|
||||
|
|
|
@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch
|
|||
APP_LDFLAGS := -latomic
|
||||
|
||||
|
||||
APP_DEBUG := $(strip $(NDK_DEBUG))
|
||||
ifeq ($(APP_DEBUG),1)
|
||||
ifeq ($(NDK_DEBUG),1)
|
||||
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
|
||||
APP_OPTIM := debug
|
||||
else
|
||||
APP_CPPFLAGS += -DNDEBUG
|
||||
APP_OPTIM := release
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch
|
|||
APP_LDFLAGS := -latomic
|
||||
|
||||
|
||||
APP_DEBUG := $(strip $(NDK_DEBUG))
|
||||
ifeq ($(APP_DEBUG),1)
|
||||
ifeq ($(NDK_DEBUG),1)
|
||||
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
|
||||
APP_OPTIM := debug
|
||||
else
|
||||
APP_CPPFLAGS += -DNDEBUG
|
||||
APP_OPTIM := release
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -5,8 +5,7 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch
|
|||
APP_LDFLAGS := -latomic
|
||||
|
||||
|
||||
APP_DEBUG := $(strip $(NDK_DEBUG))
|
||||
ifeq ($(APP_DEBUG),1)
|
||||
ifeq ($(NDK_DEBUG),1)
|
||||
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
|
||||
APP_OPTIM := debug
|
||||
else
|
||||
|
|
|
@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch
|
|||
APP_LDFLAGS := -latomic
|
||||
|
||||
|
||||
APP_DEBUG := $(strip $(NDK_DEBUG))
|
||||
ifeq ($(APP_DEBUG),1)
|
||||
ifeq ($(NDK_DEBUG),1)
|
||||
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
|
||||
APP_OPTIM := debug
|
||||
else
|
||||
APP_CPPFLAGS += -DNDEBUG
|
||||
APP_OPTIM := release
|
||||
endif
|
||||
endif
|
||||
|
|
Loading…
Reference in New Issue