• 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_ROSEN_WINDOW_CONTROLLER_H
17 #define OHOS_ROSEN_WINDOW_CONTROLLER_H
18 
19 #include <refbase.h>
20 #include "input_window_monitor.h"
21 #include "zidl/window_manager_agent_interface.h"
22 #include "window_root.h"
23 #include "wm_common.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class WindowController : public RefBase {
28 public:
WindowController(sptr<WindowRoot> & root,sptr<InputWindowMonitor> inputWindowMonitor)29     WindowController(sptr<WindowRoot>& root, sptr<InputWindowMonitor> inputWindowMonitor) : windowRoot_(root),
30         inputWindowMonitor_(inputWindowMonitor) {}
31     ~WindowController() = default;
32 
33     WMError CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
34         const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId);
35     WMError AddWindowNode(sptr<WindowProperty>& property);
36     WMError RemoveWindowNode(uint32_t windowId);
37     WMError DestroyWindow(uint32_t windowId, bool onlySelf);
38     WMError RequestFocus(uint32_t windowId);
39     WMError SaveAbilityToken(const sptr<IRemoteObject>& abilityToken, uint32_t windowId);
40     WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level);
41     WMError SetAlpha(uint32_t windowId, float alpha);
42     std::vector<Rect> GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType);
43     WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId);
44     void NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type);
45     WMError ProcessPointDown(uint32_t windowId, bool isStartDrag);
46     WMError ProcessPointUp(uint32_t windowId);
47     void MinimizeAllAppWindows(DisplayId displayId);
48     WMError MaxmizeWindow(uint32_t windowId);
49     WMError SetWindowLayoutMode(DisplayId displayId, WindowLayoutMode mode);
50     WMError UpdateProperty(sptr<WindowProperty>& property, PropertyChangeAction action);
51     void NotifySystemBarTints();
52 
53 private:
54     uint32_t GenWindowId();
55     void FlushWindowInfo(uint32_t windowId);
56     void FlushWindowInfoWithDisplayId(DisplayId displayId);
57     void UpdateWindowAnimation(const sptr<WindowNode>& node);
58     void ProcessDisplayChange(DisplayId displayId, DisplayStateChangeType type);
59     void StopBootAnimationIfNeed(WindowType type) const;
60     WMError SetWindowType(uint32_t windowId, WindowType type);
61     WMError SetWindowFlags(uint32_t windowId, uint32_t flags);
62     WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property);
63     WMError ResizeRect(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason);
64     WMError SetWindowMode(uint32_t windowId, WindowMode dstMode);
65     void ReSizeSystemBarPropertySizeIfNeed(sptr<WindowNode> node);
66     void HandleTurnScreenOn(const sptr<WindowNode>& node);
67 
68     sptr<WindowRoot> windowRoot_;
69     sptr<InputWindowMonitor> inputWindowMonitor_;
70     std::atomic<uint32_t> windowId_ { INVALID_WINDOW_ID };
71     // Remove 'sysBarWinId_' after SystemUI resize 'systembar'
72     std::unordered_map<WindowType, uint32_t> sysBarWinId_ {
73         { WindowType::WINDOW_TYPE_STATUS_BAR,     INVALID_WINDOW_ID },
74         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, INVALID_WINDOW_ID },
75     };
76     std::unordered_map<WindowType, std::map<uint32_t, std::map<uint32_t, Rect>>> systemBarRect_;
77     std::unordered_map<DisplayId, sptr<DisplayInfo>> curDisplayInfo_;
78     constexpr static float SYSTEM_BAR_HEIGHT_RATIO = 0.08;
79 };
80 }
81 }
82 #endif // OHOS_ROSEN_WINDOW_CONTROLLER_H
83