1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "adapter/ohos/osal/system_bar_style_ohos.h"
17
18 #include "core/components/common/properties/color.h"
19 #include "core/pipeline/container_window_manager.h"
20 #include "core/pipeline_ng/pipeline_context.h"
21
22 namespace OHOS::Rosen {
23 // defined in js_window_utils.cpp
24 void ConvertJSSystemBarStyleToSystemBarProperties(napi_env env, napi_value jsObject,
25 std::map<WindowType, SystemBarProperty>& properties, std::map<WindowType, SystemBarPropertyFlag>& propertyFlags);
26 }
27
28 namespace {
GetStatusBarContentColor(const std::map<OHOS::Rosen::WindowType,OHOS::Rosen::SystemBarProperty> & properties)29 std::string GetStatusBarContentColor(
30 const std::map<OHOS::Rosen::WindowType, OHOS::Rosen::SystemBarProperty>& properties)
31 {
32 auto it = properties.find(OHOS::Rosen::WindowType::WINDOW_TYPE_STATUS_BAR);
33 if (it == properties.end()) {
34 return "None";
35 }
36 return OHOS::Ace::Color(it->second.contentColor_).ToString();
37 }
38
GetStatusBarContentColorFlag(const std::map<OHOS::Rosen::WindowType,OHOS::Rosen::SystemBarPropertyFlag> & propertyFlags)39 std::string GetStatusBarContentColorFlag(
40 const std::map<OHOS::Rosen::WindowType, OHOS::Rosen::SystemBarPropertyFlag>& propertyFlags)
41 {
42 auto it = propertyFlags.find(OHOS::Rosen::WindowType::WINDOW_TYPE_STATUS_BAR);
43 if (it == propertyFlags.end()) {
44 return "None";
45 }
46 return it->second.contentColorFlag ? "true" : "false";
47 }
48 }
49
50 namespace OHOS::Ace {
CreateStyleFromJsObj(void * env,void * value)51 RefPtr<SystemBarStyle> SystemBarStyle::CreateStyleFromJsObj(void* env, void* value)
52 {
53 auto style = AceType::MakeRefPtr<SystemBarStyleOhos>();
54 CHECK_NULL_RETURN(style, nullptr);
55 Rosen::ConvertJSSystemBarStyleToSystemBarProperties(
56 reinterpret_cast<napi_env>(env), reinterpret_cast<napi_value>(value),
57 style->properties_, style->propertyFlags_);
58 TAG_LOGD(AceLogTag::ACE_NAVIGATION, "style from JsObj, color: %{public}s, flag: %{public}s",
59 GetStatusBarContentColor(style->properties_).c_str(),
60 GetStatusBarContentColorFlag(style->propertyFlags_).c_str());
61 return style;
62 }
63
GetCurrentSystemBarStyle(const sptr<Rosen::Window> & window)64 RefPtr<SystemBarStyleOhos> SystemBarStyleOhos::GetCurrentSystemBarStyle(const sptr<Rosen::Window>& window)
65 {
66 CHECK_NULL_RETURN(window, nullptr);
67 auto style = AceType::MakeRefPtr<SystemBarStyleOhos>();
68 CHECK_NULL_RETURN(style, nullptr);
69 window->GetSystemBarProperties(style->properties_);
70 Rosen::SystemBarPropertyFlag flag;
71 flag.contentColorFlag = true;
72 style->propertyFlags_.emplace(Rosen::WindowType::WINDOW_TYPE_STATUS_BAR, flag);
73 TAG_LOGI(AceLogTag::ACE_NAVIGATION, "current system bar style, color: %{public}s, flag: %{public}s",
74 GetStatusBarContentColor(style->properties_).c_str(),
75 GetStatusBarContentColorFlag(style->propertyFlags_).c_str());
76 return style;
77 }
78
SetSystemBarStyle(const sptr<Rosen::Window> & window,const RefPtr<SystemBarStyle> & style)79 void SystemBarStyleOhos::SetSystemBarStyle(const sptr<Rosen::Window>& window, const RefPtr<SystemBarStyle>& style)
80 {
81 CHECK_NULL_VOID(window);
82 auto tempStyle = AceType::DynamicCast<SystemBarStyleOhos>(style);
83 CHECK_NULL_VOID(tempStyle);
84 window->SetSystemBarProperties(tempStyle->properties_, tempStyle->propertyFlags_);
85 TAG_LOGI(AceLogTag::ACE_NAVIGATION, "set system bar style, color: %{public}s, flag: %{public}s",
86 GetStatusBarContentColor(tempStyle->properties_).c_str(),
87 GetStatusBarContentColorFlag(tempStyle->propertyFlags_).c_str());
88 }
89 } // namespace OHOS::Ace