2 * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
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.
17 #include "wrt/src/browser/basic_splash_screen_on_screen.h"
19 #include "wrt/src/browser/wrt_native_widget.h"
23 BasicSplashScreenOnScreen::BasicSplashScreenOnScreen(
24 std::unique_ptr<SplashScreenDelegate> delegate)
25 : BasicSplashScreen(std::move(delegate)),
26 widget_delegate_(new SplashScreenWidgetDelegate) {}
28 void BasicSplashScreenOnScreen::Init() {
29 auto* host = widget_delegate_->host();
30 auto* widget = widget_delegate_->widget();
31 gfx::Rect bounds = host->GetBoundsInPixels();
33 views::Widget::InitParams params;
34 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
35 params.bounds = bounds;
36 params.delegate = widget_delegate_.get();
37 params.type = views::Widget::InitParams::TYPE_WINDOW;
38 params.native_widget = new WRTNativeWidget(widget, host);
39 params.parent = host->window();
41 widget->Init(std::move(params));
43 auto* splash_screen_data = GetSplashScreenData();
45 static_cast<WRTFrameView*>(widget->non_client_view()->frame_view());
47 if (splash_screen_data->background_color) {
48 frame_view->SetBackgroundColor(
49 SkColorSetRGB(splash_screen_data->background_color->red,
50 splash_screen_data->background_color->green,
51 splash_screen_data->background_color->blue));
54 auto app_path = ApplicationData::GetInstance().application_path();
55 if (!splash_screen_data->background_images.empty()) {
56 std::vector<BorderOption> border_options;
57 auto insets = ParseImageBorder(
58 splash_screen_data->image_border, &border_options);
59 if (!insets.IsEmpty()) {
60 const std::string& border_image_path =
61 app_path + splash_screen_data->background_images.front().first;
62 frame_view->SetImageBorder(base::FilePath(border_image_path), insets);
66 if (!splash_screen_data->images.empty())
67 frame_view->SetImage(base::FilePath(GetImagePath(splash_screen_data)));
69 frame_view->ShowWidgetWhenReady();
72 void BasicSplashScreenOnScreen::Hide() {
73 widget_delegate_.reset();