• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
CreateStyleFromColor(const uint32_t colorValue)62 RefPtr<SystemBarStyle> SystemBarStyle::CreateStyleFromColor(const uint32_t colorValue)
63 {
64     auto style = AceType::MakeRefPtr<SystemBarStyleOhos>();
65     CHECK_NULL_RETURN(style, nullptr);
66     Rosen::SystemBarPropertyFlag flag;
67     flag.contentColorFlag = true;
68     style->propertyFlags_.emplace(Rosen::WindowType::WINDOW_TYPE_STATUS_BAR, flag);
69     Rosen::SystemBarProperty property;
70     property.contentColor_ = colorValue;
71     style->properties_.emplace(Rosen::WindowType::WINDOW_TYPE_STATUS_BAR, property);
72     TAG_LOGI(AceLogTag::ACE_NAVIGATION, "style from Color, color: %{public}s, flag: %{public}s",
73         GetStatusBarContentColor(style->properties_).c_str(),
74         GetStatusBarContentColorFlag(style->propertyFlags_).c_str());
75     return style;
76 }
77 
GetCurrentSystemBarStyle(const sptr<Rosen::Window> & window)78 RefPtr<SystemBarStyleOhos> SystemBarStyleOhos::GetCurrentSystemBarStyle(const sptr<Rosen::Window>& window)
79 {
80     CHECK_NULL_RETURN(window, nullptr);
81     auto style = AceType::MakeRefPtr<SystemBarStyleOhos>();
82     CHECK_NULL_RETURN(style, nullptr);
83     window->GetSystemBarProperties(style->properties_);
84     Rosen::SystemBarPropertyFlag flag;
85     flag.contentColorFlag = true;
86     style->propertyFlags_.emplace(Rosen::WindowType::WINDOW_TYPE_STATUS_BAR, flag);
87     TAG_LOGI(AceLogTag::ACE_NAVIGATION, "current system bar style, color: %{public}s, flag: %{public}s",
88         GetStatusBarContentColor(style->properties_).c_str(),
89         GetStatusBarContentColorFlag(style->propertyFlags_).c_str());
90     return style;
91 }
92 
SetSystemBarStyle(const sptr<Rosen::Window> & window,const RefPtr<SystemBarStyle> & style)93 void SystemBarStyleOhos::SetSystemBarStyle(const sptr<Rosen::Window>& window, const RefPtr<SystemBarStyle>& style)
94 {
95     CHECK_NULL_VOID(window);
96     auto tempStyle = AceType::DynamicCast<SystemBarStyleOhos>(style);
97     CHECK_NULL_VOID(tempStyle);
98     window->SetSystemBarProperties(tempStyle->properties_, tempStyle->propertyFlags_);
99     TAG_LOGI(AceLogTag::ACE_NAVIGATION, "set system bar style, color: %{public}s, flag: %{public}s",
100         GetStatusBarContentColor(tempStyle->properties_).c_str(),
101         GetStatusBarContentColorFlag(tempStyle->propertyFlags_).c_str());
102 }
103 } // namespace OHOS::Ace