• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_ROSEN_ROOT_SCENE_H
17 #define OHOS_ROSEN_ROOT_SCENE_H
18 
19 #include <mutex>
20 
21 #include "vsync_station.h"
22 #include "window.h"
23 #include "window_helper.h"
24 #include "ws_common.h"
25 
26 typedef struct napi_env__* napi_env;
27 typedef struct napi_value__* napi_value;
28 namespace OHOS::AppExecFwk {
29 class EventHandler;
30 class LauncherService;
31 } // namespace OHOS::AppExecFwk
32 
33 namespace OHOS::Ace {
34 class UIContent;
35 } // namespace OHOS::Ace
36 
37 namespace OHOS {
38 namespace Rosen {
39 class RSNode;
40 using GetSessionAvoidAreaByTypeCallback = std::function<AvoidArea(AvoidAreaType)>;
41 using UpdateRootSceneRectCallback = std::function<void(const Rect& rect)>;
42 using UpdateRootSceneAvoidAreaCallback = std::function<void()>;
43 using NotifyWatchFocusActiveChangeCallback = std::function<void(bool isFocusActive)>;
44 
45 class RootScene : public Window {
46 public:
47     RootScene();
48     virtual ~RootScene();
49 
50     void LoadContent(const std::string& contentUrl, napi_env env, napi_value storage,
51         AbilityRuntime::Context* context);
52     void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason);
53     static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration,
54         const std::vector<std::shared_ptr<AbilityRuntime::Context>>& ignoreWindowContexts = {});
55     void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
56     void UpdateConfigurationForSpecified(const std::shared_ptr<AppExecFwk::Configuration>& configuration,
57         const std::shared_ptr<Global::Resource::ResourceManager>& resourceManager) override;
58 
59     void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override;
60     int64_t GetVSyncPeriod() override;
61     void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType = 0) override;
62 
63     /*
64      * Window Immersive
65      */
66     bool IsLastFrameLayoutFinished();
67     void OnFlushUIParams();
68     WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea, const Rect& rect = Rect::EMPTY_RECT,
69         int32_t apiVersion = API_VERSION_INVALID) override;
70     void RegisterGetSessionAvoidAreaByTypeCallback(GetSessionAvoidAreaByTypeCallback&& callback);
71     void RegisterUpdateRootSceneRectCallback(UpdateRootSceneRectCallback&& callback);
72     WMError RegisterAvoidAreaChangeListener(const sptr<IAvoidAreaChangedListener>& listener) override;
73     WMError UnregisterAvoidAreaChangeListener(const sptr<IAvoidAreaChangedListener>& listener) override;
74     void NotifyAvoidAreaChangeForRoot(const sptr<AvoidArea>& avoidArea, AvoidAreaType type);
75     void RegisterUpdateRootSceneAvoidAreaCallback(UpdateRootSceneAvoidAreaCallback&& callback);
GetClassType()76     std::string GetClassType() const override { return "RootScene"; }
IsSystemWindow()77     bool IsSystemWindow() const override { return WindowHelper::IsSystemWindow(GetType()); }
IsAppWindow()78     bool IsAppWindow() const override { return WindowHelper::IsAppWindow(GetType()); }
79     void GetExtensionConfig(AAFwk::WantParams& want) const override;
80 
81     /*
82      * Keyboard Window
83      */
84     WMError RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override;
85     WMError UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override;
86     void NotifyOccupiedAreaChangeForRoot(const sptr<OccupiedAreaChangeInfo>& info);
87 
88     /*
89      * watch
90      */
91     void RegisterNotifyWatchFocusActiveChangeCallback(NotifyWatchFocusActiveChangeCallback&& callback);
92 
GetContext()93     const std::shared_ptr<AbilityRuntime::Context> GetContext() const override { return context_.lock(); }
94 
95     void OnBundleUpdated(const std::string& bundleName);
96     static void SetOnConfigurationUpdatedCallback(
97         const std::function<void(const std::shared_ptr<AppExecFwk::Configuration>&)>& callback);
98     void SetFrameLayoutFinishCallback(std::function<void()>&& callback);
99 
SetDisplayDensity(float density)100     void SetDisplayDensity(float density) { density_ = density; }
101 
SetDisplayId(DisplayId displayId)102     void SetDisplayId(DisplayId displayId) { displayId_ = displayId; }
103 
GetDisplayId()104     DisplayId GetDisplayId() const override { return displayId_; }
105 
106     void SetDisplayOrientation(int32_t orientation);
107 
GetDisplayDensity()108     float GetDisplayDensity() { return density_; }
109 
GetWindowState()110     WindowState GetWindowState() const override { return WindowState::STATE_SHOWN; }
111 
GetType()112     WindowType GetType() const override { return type_; }
113 
GetWindowName()114     const std::string& GetWindowName() const override { return name_; }
115 
GetWindowId()116     uint32_t GetWindowId() const override { return 1; } // 1 for root
117 
GetUIContent()118     Ace::UIContent* GetUIContent() const override { return uiContent_.get(); }
119 
120     void SetUiDvsyncSwitch(bool dvsyncSwitch) override;
121 
122     /*
123      * Window Layout
124      */
125     std::shared_ptr<Rosen::RSNode> GetRSNodeByStringID(const std::string& stringId);
126     void SetTopWindowBoundaryByID(const std::string& stringId);
127 
128     /*
129      * Window Property
130      */
131     static void UpdateConfigurationSyncForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
132     void UpdateConfigurationSync(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
133 
134     static sptr<RootScene> staticRootScene_;
135 
136 private:
137     void RegisterInputEventListener();
138 
139     std::unique_ptr<Ace::UIContent> uiContent_;
140     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
141     sptr<AppExecFwk::LauncherService> launcherService_;
142     float density_ = 1.0f;
143     DisplayId displayId_ = DISPLAY_ID_INVALID;
144     int32_t orientation_ = 0;
145     WindowType type_ = WindowType::WINDOW_TYPE_SCENE_BOARD;
146     std::string name_ = "EntryView";
147 
148     static std::function<void(const std::shared_ptr<AppExecFwk::Configuration>&)> configurationUpdatedCallback_;
149     std::function<void()> frameLayoutFinishCb_ = nullptr;
150     std::shared_ptr<VsyncStation> vsyncStation_ = nullptr;
151     std::weak_ptr<AbilityRuntime::Context> context_;
152     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
153 
154     /*
155      * Window Immersive
156      */
157     GetSessionAvoidAreaByTypeCallback getSessionAvoidAreaByTypeCallback_ = nullptr;
158     UpdateRootSceneRectCallback updateRootSceneRectCallback_ = nullptr;
159     UpdateRootSceneAvoidAreaCallback updateRootSceneAvoidAreaCallback_ = nullptr;
160     mutable std::mutex mutex_;
161     std::unordered_set<sptr<IAvoidAreaChangedListener>, SptrHash<IAvoidAreaChangedListener>> avoidAreaChangeListeners_;
162 
163     /*
164      * Keyboard Window
165      */
166     mutable std::mutex occupiedAreaMutex_;
167     std::unordered_set<sptr<IOccupiedAreaChangeListener>, SptrHash<IOccupiedAreaChangeListener>>
168         occupiedAreaChangeListeners_;
169 
170     /*
171      * watch
172      */
173     NotifyWatchFocusActiveChangeCallback notifyWatchFocusActiveChangeCallback_ = nullptr;
174 };
175 } // namespace Rosen
176 } // namespace OHOS
177 
178 #endif // OHOS_ROSEN_ROOT_SCENE_H
179