• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef OHOS_JS_WINDOW_UTILS_H
17 #define OHOS_JS_WINDOW_UTILS_H
18 #include <map>
19 #include "native_engine/native_engine.h"
20 #include "native_engine/native_value.h"
21 #include "window.h"
22 #include "window_manager.h"
23 #include "window_option.h"
24 #include "wm_common.h"
25 namespace OHOS {
26 namespace Rosen {
27 constexpr int32_t RGB_LENGTH = 6;
28 constexpr int32_t RGBA_LENGTH = 8;
29 enum class ApiWindowType : uint32_t {
30     TYPE_BASE,
31     TYPE_APP = TYPE_BASE,
32     TYPE_SYSTEM_ALERT,
33     TYPE_INPUT_METHOD,
34     TYPE_STATUS_BAR,
35     TYPE_PANEL,
36     TYPE_KEYGUARD,
37     TYPE_VOLUME_OVERLAY,
38     TYPE_NAVIGATION_BAR,
39     TYPE_FLOAT,
40     TYPE_END = TYPE_FLOAT,
41 };
42 
43 enum class LifeCycleEventType : uint32_t {
44     FOREGROUND = 1,
45     ACTIVE,
46     INACTIVE,
47     BACKGROUND,
48 };
49 
50 const std::map<WindowType, ApiWindowType> NATIVE_JS_TO_WINDOW_TYPE_MAP {
51     { WindowType::WINDOW_TYPE_APP_SUB_WINDOW,      ApiWindowType::TYPE_APP            },
52     { WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, ApiWindowType::TYPE_SYSTEM_ALERT   },
53     { WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT,  ApiWindowType::TYPE_INPUT_METHOD   },
54     { WindowType::WINDOW_TYPE_STATUS_BAR,          ApiWindowType::TYPE_STATUS_BAR     },
55     { WindowType::WINDOW_TYPE_PANEL,               ApiWindowType::TYPE_PANEL          },
56     { WindowType::WINDOW_TYPE_KEYGUARD,            ApiWindowType::TYPE_KEYGUARD       },
57     { WindowType::WINDOW_TYPE_VOLUME_OVERLAY,      ApiWindowType::TYPE_VOLUME_OVERLAY },
58     { WindowType::WINDOW_TYPE_NAVIGATION_BAR,      ApiWindowType::TYPE_NAVIGATION_BAR },
59     { WindowType::WINDOW_TYPE_FLOAT,               ApiWindowType::TYPE_FLOAT          },
60 };
61 const std::map<ApiWindowType, WindowType> JS_TO_NATIVE_WINDOW_TYPE_MAP {
62     { ApiWindowType::TYPE_APP,             WindowType::WINDOW_TYPE_APP_SUB_WINDOW     },
63     { ApiWindowType::TYPE_SYSTEM_ALERT,    WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW},
64     { ApiWindowType::TYPE_INPUT_METHOD,    WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT },
65     { ApiWindowType::TYPE_STATUS_BAR,      WindowType::WINDOW_TYPE_STATUS_BAR         },
66     { ApiWindowType::TYPE_PANEL,           WindowType::WINDOW_TYPE_PANEL              },
67     { ApiWindowType::TYPE_KEYGUARD,        WindowType::WINDOW_TYPE_KEYGUARD           },
68     { ApiWindowType::TYPE_VOLUME_OVERLAY,  WindowType::WINDOW_TYPE_VOLUME_OVERLAY     },
69     { ApiWindowType::TYPE_NAVIGATION_BAR,  WindowType::WINDOW_TYPE_NAVIGATION_BAR     },
70     { ApiWindowType::TYPE_FLOAT,           WindowType::WINDOW_TYPE_FLOAT              }
71 };
72 enum class ApiWindowMode : uint32_t {
73     UNDEFINED = 1,
74     FULLSCREEN,
75     PRIMARY,
76     SECONDARY,
77     FLOATING,
78     MODE_END = FLOATING
79 };
80 
81 const std::map<WindowMode, ApiWindowMode> NATIVE_TO_JS_WINDOW_MODE_MAP {
82     { WindowMode::WINDOW_MODE_UNDEFINED,       ApiWindowMode::UNDEFINED  },
83     { WindowMode::WINDOW_MODE_FULLSCREEN,      ApiWindowMode::FULLSCREEN },
84     { WindowMode::WINDOW_MODE_SPLIT_PRIMARY,   ApiWindowMode::PRIMARY    },
85     { WindowMode::WINDOW_MODE_SPLIT_SECONDARY, ApiWindowMode::SECONDARY  },
86     { WindowMode::WINDOW_MODE_FLOATING,        ApiWindowMode::FLOATING   },
87 };
88 
89 const std::map<ApiWindowMode, WindowMode> JS_TO_NATIVE_WINDOW_MODE_MAP {
90     {ApiWindowMode::UNDEFINED,  WindowMode::WINDOW_MODE_UNDEFINED       },
91     {ApiWindowMode::FULLSCREEN, WindowMode::WINDOW_MODE_FULLSCREEN      },
92     {ApiWindowMode::PRIMARY,    WindowMode::WINDOW_MODE_SPLIT_PRIMARY   },
93     {ApiWindowMode::SECONDARY,  WindowMode::WINDOW_MODE_SPLIT_SECONDARY },
94     {ApiWindowMode::FLOATING,   WindowMode::WINDOW_MODE_FLOATING        },
95 };
96 
97     NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect);
98     NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr<Window>& window);
99     bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject,
100         std::map<WindowType, SystemBarProperty>& properties, sptr<Window>& window);
101     bool GetSystemBarStatus(std::map<WindowType, SystemBarProperty>& systemBarProperties,
102         NativeEngine& engine, NativeCallbackInfo& info, sptr<Window>& window);
103     NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine,
104         const SystemBarRegionTints& tints);
105     NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea);
106     bool CheckCallingPermission(std::string permission);
107     NativeValue* WindowTypeInit(NativeEngine* engine);
108     NativeValue* AvoidAreaTypeInit(NativeEngine* engine);
109     NativeValue* WindowModeInit(NativeEngine* engine);
110     NativeValue* ColorSpaceInit(NativeEngine* engine);
111     NativeValue* WindowStageEventTypeInit(NativeEngine* engine);
112     bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability);
113 }
114 }
115 #endif