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_IMPL_H 17 #define OHOS_ROSEN_WINDOW_IMPL_H 18 19 #include <map> 20 21 #include <ui_content.h> 22 23 #include "window.h" 24 #include "window_property.h" 25 26 namespace OHOS::AbilityRuntime { 27 class Context; 28 } 29 30 namespace OHOS { 31 namespace Rosen { 32 union ColorParam { 33 #if BIG_ENDIANNESS 34 struct { 35 uint8_t alpha; 36 uint8_t red; 37 uint8_t green; 38 uint8_t blue; 39 } argb; 40 #else 41 struct { 42 uint8_t blue; 43 uint8_t green; 44 uint8_t red; 45 uint8_t alpha; 46 } argb; 47 #endif 48 uint32_t value; 49 }; 50 51 class WindowImpl : public Window { 52 public: 53 explicit WindowImpl(const sptr<WindowOption>& option); 54 ~WindowImpl(); 55 static sptr<Window> Find(const std::string& id); 56 static sptr<Window> GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr); 57 static sptr<Window> GetTopWindowWithId(uint32_t mainWinId); 58 static std::vector<sptr<Window>> GetSubWindow(uint32_t parantId); 59 static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration); 60 virtual std::shared_ptr<RSSurfaceNode> GetSurfaceNode() const override; 61 virtual Rect GetRect() const override; 62 virtual Rect GetRequestRect() const override; 63 virtual WindowType GetType() const override; 64 virtual WindowMode GetMode() const override; 65 virtual float GetAlpha() const override; 66 virtual WindowState GetWindowState() const override; 67 virtual WMError SetFocusable(bool isFocusable) override; 68 virtual bool GetFocusable() const override; 69 virtual WMError SetTouchable(bool isTouchable) override; 70 virtual bool GetTouchable() const override; 71 virtual const std::string& GetWindowName() const override; 72 virtual uint32_t GetWindowId() const override; 73 virtual uint32_t GetWindowFlags() const override; 74 uint32_t GetRequestModeSupportInfo() const override; 75 bool IsMainHandlerAvailable() const override; 76 virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const override; 77 virtual bool IsFullScreen() const override; 78 virtual bool IsLayoutFullScreen() const override; 79 virtual WMError SetWindowType(WindowType type) override; 80 virtual WMError SetWindowMode(WindowMode mode) override; 81 virtual void SetAlpha(float alpha) override; 82 virtual void SetTransform(const Transform& trans) override; 83 virtual WMError AddWindowFlag(WindowFlag flag) override; 84 virtual WMError RemoveWindowFlag(WindowFlag flag) override; 85 virtual WMError SetWindowFlags(uint32_t flags) override; 86 virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override; 87 virtual WMError SetLayoutFullScreen(bool status) override; 88 virtual WMError SetFullScreen(bool status) override; 89 virtual const Transform& GetTransform() const override; 90 virtual WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) override; 91 virtual WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) override; 92 93 WMError Create(uint32_t parentId, 94 const std::shared_ptr<AbilityRuntime::Context>& context = nullptr); 95 virtual WMError Destroy() override; 96 virtual WMError Show(uint32_t reason = 0, bool withAnimation = false) override; 97 virtual WMError Hide(uint32_t reason = 0, bool withAnimation = false) override; 98 virtual WMError MoveTo(int32_t x, int32_t y) override; 99 virtual WMError Resize(uint32_t width, uint32_t height) override; 100 virtual WMError SetKeepScreenOn(bool keepScreenOn) override; 101 virtual bool IsKeepScreenOn() const override; 102 virtual WMError SetTurnScreenOn(bool turnScreenOn) override; 103 virtual bool IsTurnScreenOn() const override; 104 virtual WMError SetBackgroundColor(const std::string& color) override; 105 virtual WMError SetTransparent(bool isTransparent) override; 106 virtual bool IsTransparent() const override; 107 virtual WMError SetBrightness(float brightness) override; 108 virtual float GetBrightness() const override; 109 virtual WMError SetCallingWindow(uint32_t windowId) override; 110 virtual void SetPrivacyMode(bool isPrivacyMode) override; 111 virtual bool IsPrivacyMode() const override; 112 virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) override; 113 virtual void DisableAppWindowDecor() override; 114 virtual WMError BindDialogTarget(sptr<IRemoteObject> targetToken) override; 115 virtual void SetSnapshotSkip(bool isSkip) override; 116 117 // window effect 118 virtual WMError SetCornerRadius(float cornerRadius) override; 119 virtual WMError SetShadowRadius(float radius) override; 120 virtual WMError SetShadowColor(std::string color) override; 121 virtual void SetShadowOffsetX(float offsetX) override; 122 virtual void SetShadowOffsetY(float offsetY) override; 123 virtual WMError SetBlur(float radius) override; 124 virtual WMError SetBackdropBlur(float radius) override; 125 virtual WMError SetBackdropBlurStyle(WindowBlurStyle blurStyle) override; 126 127 virtual bool IsDecorEnable() const override; 128 virtual WMError Maximize() override; 129 virtual WMError Minimize() override; 130 virtual WMError Recover() override; 131 virtual WMError Close() override; 132 virtual void StartMove() override; 133 134 virtual WMError RequestFocus() const override; 135 virtual bool IsFocused() const override; 136 virtual void SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer) override; 137 138 virtual bool RegisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) override; 139 virtual bool RegisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) override; 140 virtual bool UnregisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) override; 141 virtual bool UnregisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) override; 142 virtual bool RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) override; 143 virtual bool UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) override; 144 virtual bool RegisterDragListener(const sptr<IWindowDragListener>& listener) override; 145 virtual bool UnregisterDragListener(const sptr<IWindowDragListener>& listener) override; 146 virtual bool RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override; 147 virtual bool UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override; 148 virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) override; 149 virtual bool RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override; 150 virtual bool UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override; 151 virtual bool RegisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) override; 152 virtual bool UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) override; 153 virtual bool RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener) override; 154 virtual bool RegisterScreenshotListener(const sptr<IScreenshotListener>& listener) override; 155 virtual bool UnregisterScreenshotListener(const sptr<IScreenshotListener>& listener) override; 156 virtual bool RegisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) override; 157 virtual bool UnregisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) override; 158 virtual void RegisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) override; 159 virtual void UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) override; 160 virtual void SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler) override; 161 virtual void SetRequestModeSupportInfo(uint32_t modeSupportInfo) override; 162 virtual void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) override; 163 virtual void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& inputEvent) override; 164 virtual void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override; 165 virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override; 166 void NotifyTouchDialogTarget() override; 167 168 virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, 169 NativeValue* storage, bool isdistributed, AppExecFwk::Ability* ability) override; 170 virtual std::string GetContentInfo() override; 171 virtual const std::shared_ptr<AbilityRuntime::Context> GetContext() const override; 172 virtual Ace::UIContent* GetUIContent() const override; 173 virtual void OnNewWant(const AAFwk::Want& want) override; 174 virtual void SetRequestedOrientation(Orientation) override; 175 virtual Orientation GetRequestedOrientation() override; 176 virtual void SetNeedRemoveWindowInputChannel(bool needRemoveWindowInputChannel) override; 177 virtual WMError SetTouchHotAreas(const std::vector<Rect>& rects) override; 178 virtual void GetRequestedTouchHotAreas(std::vector<Rect>& rects) const override; 179 virtual WMError SetAPPWindowLabel(const std::string& label) override; 180 virtual WMError SetAPPWindowIcon(const std::shared_ptr<Media::PixelMap>& icon) override; 181 182 // colorspace, gamut 183 virtual bool IsSupportWideGamut() override; 184 virtual void SetColorSpace(ColorSpace colorSpace) override; 185 virtual ColorSpace GetColorSpace() override; 186 187 virtual void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override; 188 virtual std::shared_ptr<Media::PixelMap> Snapshot() override; 189 virtual WMError NotifyMemoryLevel(int32_t level) const override; 190 virtual bool IsAllowHaveSystemSubWindow() override; 191 192 private: 193 static std::map<std::string, std::pair<uint32_t, sptr<Window>>> windowMap_; 194 static std::map<uint32_t, std::vector<sptr<WindowImpl>>> subWindowMap_; 195 sptr<WindowProperty> property_; 196 WindowState state_ { WindowState::STATE_INITIAL }; 197 std::string name_; 198 std::unique_ptr<Ace::UIContent> uiContent_; 199 }; 200 } // namespace Rosen 201 } // namespace OHOS 202 #endif // OHOS_ROSEN_WINDOW_IMPL_H 203