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_H 17 #define OHOS_ROSEN_WINDOW_H 18 19 #include <refbase.h> 20 #include <parcel.h> 21 22 #include "wm_common.h" 23 #include "window_option.h" 24 25 class NativeValue; 26 class NativeEngine; 27 namespace OHOS::MMI { 28 struct IInputEventConsumer; 29 class PointerEvent; 30 class KeyEvent; 31 } 32 namespace OHOS::AppExecFwk { 33 class Configuration; 34 class Ability; 35 } 36 37 namespace OHOS::AbilityRuntime { 38 class AbilityContext; 39 class Context; 40 } 41 42 namespace OHOS::Ace { 43 class UIContent; 44 } 45 46 namespace OHOS { 47 namespace Rosen { 48 using NotifyNativeWinDestroyFunc = std::function<void(std::string windowName)>; 49 class RSSurfaceNode; 50 51 class IWindowLifeCycle : virtual public RefBase { 52 public: 53 virtual void AfterForeground() = 0; 54 virtual void AfterBackground() = 0; 55 virtual void AfterFocused() = 0; 56 virtual void AfterUnfocused() = 0; AfterActive()57 virtual void AfterActive() {} AfterInactive()58 virtual void AfterInactive() {} 59 }; 60 61 class IWindowChangeListener : virtual public RefBase { 62 public: 63 virtual void OnSizeChange(Rect rect, WindowSizeChangeReason reason) = 0; 64 virtual void OnModeChange(WindowMode mode) = 0; 65 }; 66 67 class IAvoidAreaChangedListener : virtual public RefBase { 68 public: 69 virtual void OnAvoidAreaChanged(std::vector<Rect> avoidAreas) = 0; 70 }; 71 72 class IWindowDragListener : virtual public RefBase { 73 public: 74 virtual void OnDrag(int32_t x, int32_t y, DragEvent event) = 0; 75 }; 76 77 class IDisplayMoveListener : virtual public RefBase { 78 public: 79 virtual void OnDisplayMove(DisplayId from, DisplayId to) = 0; 80 }; 81 82 class OccupiedAreaChangeInfo : public Parcelable { 83 public: 84 OccupiedAreaChangeInfo() = default; OccupiedAreaChangeInfo(OccupiedAreaType type,Rect rect)85 OccupiedAreaChangeInfo(OccupiedAreaType type, Rect rect) : type_(type), rect_(rect) {}; 86 ~OccupiedAreaChangeInfo() = default; 87 88 virtual bool Marshalling(Parcel& parcel) const override; 89 static OccupiedAreaChangeInfo* Unmarshalling(Parcel& parcel); 90 91 OccupiedAreaType type_ = OccupiedAreaType::TYPE_INPUT; 92 Rect rect_ = { 0, 0, 0, 0 }; 93 }; 94 95 class IOccupiedAreaChangeListener : virtual public RefBase { 96 public: 97 virtual void OnSizeChange(const sptr<OccupiedAreaChangeInfo>& info) = 0; 98 }; 99 100 class IAceAbilityHandler : virtual public RefBase { 101 public: 102 virtual void SetBackgroundColor(uint32_t color) = 0; 103 virtual uint32_t GetBackgroundColor() = 0; 104 }; 105 106 class Window : public RefBase { 107 public: 108 static sptr<Window> Create(const std::string& windowName, 109 sptr<WindowOption>& option, const std::shared_ptr<AbilityRuntime::Context>& context = nullptr); 110 static sptr<Window> Find(const std::string& windowName); 111 static sptr<Window> GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr); 112 static sptr<Window> GetTopWindowWithId(uint32_t mainWinId); 113 static std::vector<sptr<Window>> GetSubWindow(uint32_t parentId); 114 virtual std::shared_ptr<RSSurfaceNode> GetSurfaceNode() const = 0; 115 virtual const std::shared_ptr<AbilityRuntime::Context> GetContext() const = 0; 116 virtual Rect GetRect() const = 0; 117 virtual WindowType GetType() const = 0; 118 virtual WindowMode GetMode() const = 0; 119 virtual WindowBlurLevel GetWindowBackgroundBlur() const = 0; 120 virtual float GetAlpha() const = 0; 121 virtual const std::string& GetWindowName() const = 0; 122 virtual uint32_t GetWindowId() const = 0; 123 virtual uint32_t GetWindowFlags() const = 0; 124 virtual bool GetShowState() const = 0; 125 virtual WMError SetFocusable(bool isFocusable) = 0; 126 virtual bool GetFocusable() const = 0; 127 virtual WMError SetTouchable(bool isTouchable) = 0; 128 virtual bool GetTouchable() const = 0; 129 virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const = 0; 130 virtual bool IsFullScreen() const = 0; 131 virtual bool IsLayoutFullScreen() const = 0; 132 virtual WMError SetWindowType(WindowType type) = 0; 133 virtual WMError SetWindowMode(WindowMode mode) = 0; 134 virtual WMError SetWindowBackgroundBlur(WindowBlurLevel level) = 0; 135 virtual WMError SetAlpha(float alpha) = 0; 136 virtual WMError AddWindowFlag(WindowFlag flag) = 0; 137 virtual WMError RemoveWindowFlag(WindowFlag flag) = 0; 138 virtual WMError SetWindowFlags(uint32_t flags) = 0; 139 virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) = 0; 140 virtual WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) = 0; 141 virtual WMError SetLayoutFullScreen(bool status) = 0; 142 virtual WMError SetFullScreen(bool status) = 0; 143 virtual WMError Destroy() = 0; 144 virtual WMError Show(uint32_t reason = 0) = 0; 145 virtual WMError Hide(uint32_t reason = 0) = 0; 146 147 virtual WMError MoveTo(int32_t x, int32_t y) = 0; 148 virtual WMError Resize(uint32_t width, uint32_t height) = 0; 149 virtual WMError SetKeepScreenOn(bool keepScreenOn) = 0; 150 virtual bool IsKeepScreenOn() const = 0; 151 virtual WMError SetTurnScreenOn(bool turnScreenOn) = 0; 152 virtual bool IsTurnScreenOn() const = 0; 153 virtual WMError SetBackgroundColor(const std::string& color) = 0; 154 virtual WMError SetTransparent(bool isTransparent) = 0; 155 virtual bool IsTransparent() const = 0; 156 virtual WMError SetBrightness(float brightness) = 0; 157 virtual float GetBrightness() const = 0; 158 virtual WMError SetCallingWindow(uint32_t windowId) = 0; 159 virtual void SetPrivacyMode(bool isPrivacyMode) = 0; 160 virtual bool IsPrivacyMode() const = 0; 161 162 virtual WMError RequestFocus() const = 0; 163 // AddInputEventListener is for api 7 164 virtual void AddInputEventListener(const std::shared_ptr<MMI::IInputEventConsumer>& inputEventListener) = 0; 165 virtual void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) = 0; 166 virtual void ConsumePointerEvent(std::shared_ptr<MMI::PointerEvent>& inputEvent) = 0; 167 virtual void RequestFrame() = 0; 168 virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) = 0; 169 170 virtual void RegisterLifeCycleListener(sptr<IWindowLifeCycle>& listener) = 0; 171 virtual void RegisterWindowChangeListener(sptr<IWindowChangeListener>& listener) = 0; 172 virtual void UnregisterLifeCycleListener(sptr<IWindowLifeCycle>& listener) = 0; 173 virtual void UnregisterWindowChangeListener(sptr<IWindowChangeListener>& listener) = 0; 174 virtual void RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) = 0; 175 virtual void UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) = 0; 176 virtual void RegisterDragListener(const sptr<IWindowDragListener>& listener) = 0; 177 virtual void UnregisterDragListener(const sptr<IWindowDragListener>& listener) = 0; 178 virtual void RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0; 179 virtual void UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0; 180 virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) = 0; 181 virtual void RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) = 0; 182 virtual void UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) = 0; 183 virtual void SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler) = 0; 184 virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, 185 NativeValue* storage, bool isdistributed = false, AppExecFwk::Ability* ability = nullptr) = 0; 186 virtual std::string GetContentInfo() = 0; 187 virtual Ace::UIContent* GetUIContent() const = 0; 188 virtual void SetRequestedOrientation(Orientation) = 0; 189 virtual Orientation GetRequestedOrientation() = 0; 190 191 virtual bool IsDecorEnable() const = 0; 192 virtual WMError Maximize() = 0; 193 virtual WMError Minimize() = 0; 194 virtual WMError Recover() = 0; 195 virtual WMError Close() = 0; 196 virtual void StartMove() = 0; 197 198 // colorspace, gamut 199 virtual bool IsSupportWideGamut() = 0; 200 virtual void SetColorSpace(ColorSpace colorSpace) = 0; 201 virtual ColorSpace GetColorSpace() = 0; 202 203 virtual void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) = 0; 204 }; 205 } 206 } 207 #endif // OHOS_ROSEN_WINDOW_H 208