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/pipeline_ng/pipeline_context.h"
19
20 namespace OHOS::Rosen {
21 // defined in js_window_utils.cpp
22 void ConvertJSSystemBarStyleToSystemBarProperties(napi_env env, napi_value jsObject,
23 std::map<WindowType, SystemBarProperty>& properties, std::map<WindowType, SystemBarPropertyFlag>& propertyFlags);
24 }
25
26 namespace {
GetStatusBarContentColor( const std::map<OHOS::Rosen::WindowType, OHOS::Rosen::SystemBarProperty>& properties)27 std::string GetStatusBarContentColor(
28 const std::map<OHOS::Rosen::WindowType, OHOS::Rosen::SystemBarProperty>& properties)
29 {
30 auto it = properties.find(OHOS::Rosen::WindowType::WINDOW_TYPE_STATUS_BAR);
31 if (it == properties.end()) {
32 return "None";
33 }
34 return OHOS::Ace::Color(it->second.contentColor_).ToString();
35 }
36
GetStatusBarContentColorFlag( const std::map<OHOS::Rosen::WindowType, OHOS::Rosen::SystemBarPropertyFlag>& propertyFlags)37 std::string GetStatusBarContentColorFlag(
38 const std::map<OHOS::Rosen::WindowType, OHOS::Rosen::SystemBarPropertyFlag>& propertyFlags)
39 {
40 auto it = propertyFlags.find(OHOS::Rosen::WindowType::WINDOW_TYPE_STATUS_BAR);
41 if (it == propertyFlags.end()) {
42 return "None";
43 }
44 return it->second.contentColorFlag ? "true" : "false";
45 }
46 }
47
48 namespace OHOS::Ace {
CreateStyleFromJsObj(void* env, void* value)49 RefPtr<SystemBarStyle> SystemBarStyle::CreateStyleFromJsObj(void* env, void* value)
50 {
51 auto style = AceType::MakeRefPtr<SystemBarStyleOhos>();
52 CHECK_NULL_RETURN(style, nullptr);
53 Rosen::ConvertJSSystemBarStyleToSystemBarProperties(
54 reinterpret_cast<napi_env>(env), reinterpret_cast<napi_value>(value),
55 style->properties_, style->propertyFlags_);
56 TAG_LOGD(AceLogTag::ACE_NAVIGATION, "style from JsObj, color: %{public}s, flag: %{public}s",
57 GetStatusBarContentColor(style->properties_).c_str(),
58 GetStatusBarContentColorFlag(style->propertyFlags_).c_str());
59 return style;
60 }
61
GetCurrentSystemBarStyle(const sptr<Rosen::Window>& window)62 RefPtr<SystemBarStyleOhos> SystemBarStyleOhos::GetCurrentSystemBarStyle(const sptr<Rosen::Window>& window)
63 {
64 CHECK_NULL_RETURN(window, nullptr);
65 auto style = AceType::MakeRefPtr<SystemBarStyleOhos>();
66 CHECK_NULL_RETURN(style, nullptr);
67 window->GetSystemBarProperties(style->properties_);
68 Rosen::SystemBarPropertyFlag flag;
69 flag.contentColorFlag = true;
70 style->propertyFlags_.emplace(Rosen::WindowType::WINDOW_TYPE_STATUS_BAR, flag);
71 TAG_LOGI(AceLogTag::ACE_NAVIGATION, "current system bar style, color: %{public}s, flag: %{public}s",
72 GetStatusBarContentColor(style->properties_).c_str(),
73 GetStatusBarContentColorFlag(style->propertyFlags_).c_str());
74 return style;
75 }
76
SetSystemBarStyle(const sptr<Rosen::Window>& window, const RefPtr<SystemBarStyle>& style)77 void SystemBarStyleOhos::SetSystemBarStyle(const sptr<Rosen::Window>& window, const RefPtr<SystemBarStyle>& style)
78 {
79 CHECK_NULL_VOID(window);
80 auto tempStyle = AceType::DynamicCast<SystemBarStyleOhos>(style);
81 CHECK_NULL_VOID(tempStyle);
82 window->SetSystemBarProperties(tempStyle->properties_, tempStyle->propertyFlags_);
83 TAG_LOGI(AceLogTag::ACE_NAVIGATION, "set system bar style, color: %{public}s, flag: %{public}s",
84 GetStatusBarContentColor(tempStyle->properties_).c_str(),
85 GetStatusBarContentColorFlag(tempStyle->propertyFlags_).c_str());
86 }
87 } // namespace OHOS::Ace