2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit/dali-toolkit.h>
19 #include "dali-toolkit/devel-api/controls/web-view/web-view.h"
20 #include <dali/integration-api/debug.h>
29 class WebViewController : public ConnectionTracker
33 WebViewController( Application& application )
34 : mApplication( application )
37 // Connect to the Application's Init signal
38 mApplication.InitSignal().Connect( this, &WebViewController::Create );
43 // Nothing to do here;
46 const char* GetNextUrl()
48 static const unsigned int kUrlSize = 3;
49 static const char* kUrls[kUrlSize] = {
50 "https://webkit.org/blog-files/3d-transforms/poster-circle.html",
51 "https://www.amazon.com",
52 "https://www.google.com"
54 mUrlPointer %= kUrlSize;
55 return kUrls[mUrlPointer++];
58 // The Init signal is received once (only) during the Application lifetime
59 void Create( Application& application )
61 // Get a handle to the stage
62 Stage stage = Stage::GetCurrent();
63 stage.SetBackgroundColor( Vector4(0.2, 0.6, 1, 1) );
65 float width = stage.GetSize().width;
66 float height = stage.GetSize().height;
67 float fontSize = width * 0.02f;
69 mWebView = Toolkit::WebView::New( "ko-KR", "Asia/Seoul" );
70 mWebView.SetParentOrigin( Dali::ParentOrigin::CENTER );
71 mWebView.SetAnchorPoint( Dali::AnchorPoint::CENTER );
72 mWebView.SetPosition( 0, 0 );
73 mWebView.SetSize( width, height );
74 mWebView.PageLoadStartedSignal().Connect( this, &WebViewController::OnPageLoadStarted );
75 mWebView.PageLoadFinishedSignal().Connect( this, &WebViewController::OnPageLoadFinished );
77 std::string url = GetNextUrl();
78 mWebView.LoadUrl( url );
81 mAddressLabel = Toolkit::TextLabel::New( url );
82 mAddressLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
83 mAddressLabel.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, fontSize );
84 mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
85 mAddressLabel.SetBackgroundColor( Vector4( 0, 0, 0, 0.5f ) );
86 mAddressLabel.TouchedSignal().Connect( this, &WebViewController::OnTouchText );
87 stage.Add( mAddressLabel );
89 // Respond to key events
90 stage.KeyEventSignal().Connect( this, &WebViewController::OnKeyEvent );
91 Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( mWebView );
94 void OnPageLoadStarted( Toolkit::WebView view, const std::string& url )
96 mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, "Loading" );
99 void OnPageLoadFinished( Toolkit::WebView view, const std::string& url )
101 mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, url.c_str() );
104 bool OnTouchText( Actor actor, const TouchEvent& event )
106 if ( event.GetPoint( 0 ).state == TouchPoint::Up )
108 std::string url = GetNextUrl();
109 mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, "Waiting" );
110 mWebView.LoadUrl( url );
116 void OnKeyEvent( const KeyEvent& event )
118 if( event.state == KeyEvent::Down )
120 if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
128 Application& mApplication;
129 Toolkit::WebView mWebView;
130 Toolkit::TextLabel mAddressLabel;
131 unsigned int mUrlPointer;
134 int DALI_EXPORT_API main( int argc, char **argv )
136 Application application = Application::New( &argc, &argv );
137 WebViewController test( application );
138 application.MainLoop();