2 * Copyright (c) 2020 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/integration-api/debug.h>
20 #include "dali-toolkit/devel-api/controls/web-view/web-view.h"
28 class WebViewController : public ConnectionTracker
31 WebViewController(Application& application)
32 : mApplication(application),
35 // Connect to the Application's Init signal
36 mApplication.InitSignal().Connect(this, &WebViewController::Create);
41 // Nothing to do here;
44 const char* GetNextUrl()
46 static const unsigned int kUrlSize = 3;
47 static const char* kUrls[kUrlSize] = {
48 "https://webkit.org/blog-files/3d-transforms/poster-circle.html",
49 "https://www.amazon.com",
50 "https://www.google.com"};
51 mUrlPointer %= kUrlSize;
52 return kUrls[mUrlPointer++];
55 // The Init signal is received once (only) during the Application lifetime
56 void Create(Application& application)
58 // Get a handle to the window
59 Window window = application.GetWindow();
60 window.SetBackgroundColor(Vector4(0.2, 0.6, 1, 1));
62 float width = window.GetSize().GetWidth();
63 float height = window.GetSize().GetHeight();
64 float fontSize = width * 0.02f;
66 mWebView = Toolkit::WebView::New("ko-KR", "Asia/Seoul");
67 mWebView.SetProperty(Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER);
68 mWebView.SetProperty(Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER);
69 mWebView.SetProperty(Actor::Property::POSITION, Vector2(0, 0));
70 mWebView.SetProperty(Actor::Property::SIZE, Vector2(width, height));
71 mWebView.PageLoadStartedSignal().Connect(this, &WebViewController::OnPageLoadStarted);
72 mWebView.PageLoadFinishedSignal().Connect(this, &WebViewController::OnPageLoadFinished);
74 std::string url = GetNextUrl();
75 mWebView.LoadUrl(url);
78 mAddressLabel = Toolkit::TextLabel::New(url);
79 mAddressLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
80 mAddressLabel.SetProperty(Toolkit::TextLabel::Property::POINT_SIZE, fontSize);
81 mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE);
82 mAddressLabel.SetBackgroundColor(Vector4(0, 0, 0, 0.5f));
83 mAddressLabel.TouchedSignal().Connect(this, &WebViewController::OnTouchText);
84 window.Add(mAddressLabel);
86 // Respond to key events
87 window.KeyEventSignal().Connect(this, &WebViewController::OnKeyEvent);
88 Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor(mWebView);
91 void OnPageLoadStarted(Toolkit::WebView view, const std::string& url)
93 mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, "Loading");
96 void OnPageLoadFinished(Toolkit::WebView view, const std::string& url)
98 mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, url.c_str());
101 bool OnTouchText(Actor actor, const TouchEvent& touch)
103 if(touch.GetState(0) == PointState::UP)
105 std::string url = GetNextUrl();
106 mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, "Waiting");
107 mWebView.LoadUrl(url);
113 void OnKeyEvent(const KeyEvent& event)
115 if(event.GetState() == KeyEvent::DOWN)
117 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
125 Application& mApplication;
126 Toolkit::WebView mWebView;
127 Toolkit::TextLabel mAddressLabel;
128 unsigned int mUrlPointer;
131 int DALI_EXPORT_API main(int argc, char** argv)
133 Application application = Application::New(&argc, &argv);
134 WebViewController test(application);
135 application.MainLoop();