[WRTjs] Enable WRTjs
[platform/framework/web/chromium-efl.git] / wrt / src / browser / basic_splash_screen.cc
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "wrt/src/browser/basic_splash_screen.h"
18
19 #include "wrt/src/browser/basic_splash_screen_off_screen.h"
20 #include "wrt/src/browser/basic_splash_screen_on_screen.h"
21 #include "wrt/src/browser/wrt_native_window.h"
22
23 namespace wrt {
24
25 // static
26 SplashScreen* BasicSplashScreen::Create(
27     std::unique_ptr<SplashScreenDelegate> delegate) {
28   if (WRTNativeWindow::UseOnscreenRendering())
29     return new BasicSplashScreenOnScreen(std::move(delegate));
30   else
31     return new BasicSplashScreenOffScreen(std::move(delegate));
32 }
33
34 BasicSplashScreen::BasicSplashScreen(
35     std::unique_ptr<SplashScreenDelegate> delegate)
36     : delegate_(std::move(delegate)) {}
37
38 wgt::parse::ReadyWhen BasicSplashScreen::GetReadyWhen() {
39   auto& app_data = ApplicationData::GetInstance();
40   return app_data.launch_screen_info().ready_when();
41 }
42
43 BasicSplashScreen::SplashScreenData* BasicSplashScreen::GetSplashScreenData() {
44   auto orientation = wgt::parse::ScreenOrientation::AUTO;
45   if (delegate_)
46     orientation = delegate_->GetScreenOrientation();
47
48   auto& app_data = ApplicationData::GetInstance();
49   auto& screen_info = app_data.launch_screen_info();
50   auto* splash_screen_data = screen_info.GetLaunchScreenData(orientation);
51   // get default images if fail to get LANDSCAPE/PORTRAIT images
52   if (!splash_screen_data || splash_screen_data->images.empty()) {
53     splash_screen_data =
54         screen_info.GetLaunchScreenData(wgt::parse::ScreenOrientation::AUTO);
55   }
56
57   return splash_screen_data;
58 }
59
60 gfx::Insets BasicSplashScreen::ParseImageBorder(
61     const std::vector<std::string>& borders,
62     std::vector<BorderOption>* border_options) {
63   std::map<std::string, BorderOption> scaling_string;
64   scaling_string["repeat"] = BorderOption::REPEAT;
65   scaling_string["stretch"] = BorderOption::STRETCH;
66   scaling_string["round"] = BorderOption::ROUND;
67
68   std::vector<int> border_values;
69   for (const auto& border : borders) {
70     std::string::size_type px_index = border.find("px");
71     if (px_index != std::string::npos) {
72       std::string border_value(border.begin(), border.begin() + px_index);
73       border_values.push_back(std::atoi(border_value.c_str()));
74     }
75     for (const auto& border_string_val : scaling_string) {
76       std::string::size_type index = border.find(border_string_val.first);
77       if (index != std::string::npos) {
78         border_options->push_back(border_string_val.second);
79       }
80     }
81   }
82
83   LOG(INFO) << "Image border values:";
84   for (const auto& border_value : border_values)
85     LOG(INFO) << border_value;
86   LOG(INFO) << "Image border scaling values:";
87   for (const auto& border_option : *border_options)
88     LOG(INFO) << static_cast<int>(border_option);
89
90   if (border_values.empty() || border_options->empty())
91     return gfx::Insets();
92
93   switch (border_values.size()) {
94     case 2:
95       return gfx::Insets::VH(border_values[0], border_values[1]);
96     case 4:
97       return gfx::Insets::TLBR(border_values[0], border_values[3],
98                                border_values[2], border_values[1]);
99     default:
100       return gfx::Insets(border_values[0]);
101   }
102 }
103
104 std::string BasicSplashScreen::GetImagePath(
105     SplashScreenData* splash_screen_data) {
106   std::string raw_image_path = splash_screen_data->images.front().first;
107   std::string image_path;
108   if (delegate_)
109     image_path = delegate_->ConvertAliasPath(raw_image_path);
110
111   if (image_path.empty()) {
112     auto app_path = ApplicationData::GetInstance().application_path();
113     image_path = app_path + raw_image_path;
114   }
115
116   LOG(INFO) << "image_path: " << image_path;
117   return image_path;
118 }
119
120 }  // namespace wrt