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>
28 class WebViewController : public ConnectionTracker
32 WebViewController( Application& application )
33 : mApplication( application )
36 // Connect to the Application's Init signal
37 mApplication.InitSignal().Connect( this, &WebViewController::Create );
42 // Nothing to do here;
45 const char* GetNextUrl()
47 static const unsigned int kUrlSize = 3;
48 static const char* kUrls[kUrlSize] = {
49 "https://webkit.org/blog-files/3d-transforms/poster-circle.html",
50 "https://www.amazon.com",
51 "https://www.google.com"
53 mUrlPointer %= kUrlSize;
54 return kUrls[mUrlPointer++];
57 // The Init signal is received once (only) during the Application lifetime
58 void Create( Application& application )
60 // Get a handle to the stage
61 Stage stage = Stage::GetCurrent();
62 stage.SetBackgroundColor( Vector4(0.2, 0.6, 1, 1) );
64 float width = stage.GetSize().width;
65 float height = stage.GetSize().height;
66 float fontSize = width * 0.02f;
68 mWebView = Toolkit::WebView::New( "ko-KR", "Asia/Seoul" );
69 mWebView.SetProperty( Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER );
70 mWebView.SetProperty( Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER );
71 mWebView.SetPosition( 0, 0 );
72 mWebView.SetSize( width, height );
73 mWebView.PageLoadStartedSignal().Connect( this, &WebViewController::OnPageLoadStarted );
74 mWebView.PageLoadFinishedSignal().Connect( this, &WebViewController::OnPageLoadFinished );
76 std::string url = GetNextUrl();
77 mWebView.LoadUrl( url );
80 mAddressLabel = Toolkit::TextLabel::New( url );
81 mAddressLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
82 mAddressLabel.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, fontSize );
83 mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
84 mAddressLabel.SetBackgroundColor( Vector4( 0, 0, 0, 0.5f ) );
85 mAddressLabel.TouchedSignal().Connect( this, &WebViewController::OnTouchText );
86 stage.Add( mAddressLabel );
88 // Respond to key events
89 stage.KeyEventSignal().Connect( this, &WebViewController::OnKeyEvent );
90 Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( mWebView );
93 void OnPageLoadStarted( Toolkit::WebView view, const std::string& url )
95 mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, "Loading" );
98 void OnPageLoadFinished( Toolkit::WebView view, const std::string& url )
100 mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, url.c_str() );
103 bool OnTouchText( Actor actor, const TouchEvent& event )
105 if ( event.GetPoint( 0 ).state == TouchPoint::Up )
107 std::string url = GetNextUrl();
108 mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, "Waiting" );
109 mWebView.LoadUrl( url );
115 void OnKeyEvent( const KeyEvent& event )
117 if( event.state == KeyEvent::Down )
119 if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
127 Application& mApplication;
128 Toolkit::WebView mWebView;
129 Toolkit::TextLabel mAddressLabel;
130 unsigned int mUrlPointer;
133 int DALI_EXPORT_API main( int argc, char **argv )
135 Application application = Application::New( &argc, &argv );
136 WebViewController test( application );
137 application.MainLoop();