/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ROSEN_WINDOW_IMPL_H #define OHOS_ROSEN_WINDOW_IMPL_H #include #include #include #include #include #include #include #include "input_transfer_station.h" #include "vsync_station.h" #include "window.h" #include "window_property.h" #include "wm_common_inner.h" #include "wm_common.h" namespace OHOS { namespace Rosen { class WindowImpl : public Window { #define CALL_LIFECYCLE_LISTENER(windowLifecycleCb, uiContentCb) \ do { \ for (auto& listener : lifecycleListeners_) { \ if (listener != nullptr) { \ listener->windowLifecycleCb(); \ } \ } \ if (uiContent_ != nullptr) { \ uiContent_->uiContentCb(); \ } \ } while (0) public: WindowImpl(const sptr& option); ~WindowImpl(); static sptr Find(const std::string& id); static sptr GetTopWindowWithContext(const std::shared_ptr& context = nullptr); static sptr GetTopWindowWithId(uint32_t mainWinId); static std::vector> GetSubWindow(uint32_t parantId); virtual std::shared_ptr GetSurfaceNode() const override; virtual Rect GetRect() const override; virtual WindowType GetType() const override; virtual WindowMode GetMode() const override; virtual WindowBlurLevel GetWindowBackgroundBlur() const override; virtual float GetAlpha() const override; virtual bool GetShowState() const override; virtual bool GetFocusable() const override; virtual bool GetTouchable() const override; virtual const std::string& GetWindowName() const override; virtual uint32_t GetWindowId() const override; virtual uint32_t GetWindowFlags() const override; virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const override; virtual bool IsFullScreen() const override; virtual bool IsLayoutFullScreen() const override; virtual WMError SetWindowType(WindowType type) override; virtual WMError SetWindowMode(WindowMode mode) override; virtual WMError SetWindowBackgroundBlur(WindowBlurLevel level) override; virtual WMError SetAlpha(float alpha) override; virtual WMError AddWindowFlag(WindowFlag flag) override; virtual WMError RemoveWindowFlag(WindowFlag flag) override; virtual WMError SetWindowFlags(uint32_t flags) override; virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override; virtual WMError SetLayoutFullScreen(bool status) override; virtual WMError SetFullScreen(bool status) override; virtual WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) override; WMError Create(const std::string& parentName, const std::shared_ptr& context = nullptr); virtual WMError Destroy() override; virtual WMError Show() override; virtual WMError Hide() override; virtual WMError MoveTo(int32_t x, int32_t y) override; virtual WMError Resize(uint32_t width, uint32_t height) override; virtual bool IsDecorEnable() const override; virtual WMError Maximize() override; virtual WMError Minimize() override; virtual WMError Recover() override; virtual WMError Close() override; virtual void StartMove() override; virtual WMError RequestFocus() const override; virtual void AddInputEventListener(std::shared_ptr& inputEventListener) override; virtual void RegisterLifeCycleListener(sptr& listener) override; virtual void RegisterWindowChangeListener(sptr& listener) override; virtual void UnregisterLifeCycleListener(sptr& listener) override; virtual void UnregisterWindowChangeListener(sptr& listener) override; virtual void RegisterAvoidAreaChangeListener(sptr& listener) override; virtual void UnregisterAvoidAreaChangeListener() override; virtual void RegisterDragListener(sptr& listener) override; virtual void UnregisterDragListener(sptr& listener) override; virtual void RegisterDisplayMoveListener(sptr& listener) override; virtual void UnregisterDisplayMoveListener(sptr& listener) override; void UpdateRect(const struct Rect& rect, WindowSizeChangeReason reason); void UpdateMode(WindowMode mode); virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) override; virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) override; virtual void RequestFrame() override; void UpdateFocusStatus(bool focused); virtual void UpdateConfiguration(const std::shared_ptr& configuration) override; void UpdateAvoidArea(const std::vector& avoidAreas); void UpdateWindowState(WindowState state); void UpdateDragEvent(const PointInfo& point, DragEvent event); void UpdateDisplayId(DisplayId from, DisplayId to); virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) override; virtual std::string GetContentInfo() override; virtual const std::shared_ptr GetContext() const override; // colorspace, gamut virtual bool IsSupportWideGamut() override; virtual void SetColorSpace(ColorSpace colorSpace) override; virtual ColorSpace GetColorSpace() override; virtual void DumpInfo(const std::vector& params, std::vector& info) override; private: inline void NotifyAfterForeground() const { CALL_LIFECYCLE_LISTENER(AfterForeground, Foreground); } inline void NotifyAfterBackground() const { CALL_LIFECYCLE_LISTENER(AfterBackground, Background); } inline void NotifyAfterFocused() const { CALL_LIFECYCLE_LISTENER(AfterFocused, Focus); } inline void NotifyAfterUnfocused() const { CALL_LIFECYCLE_LISTENER(AfterUnfocused, UnFocus); } inline void NotifyBeforeDestroy() const { if (uiContent_ != nullptr) { uiContent_->Destroy(); } } void SetDefaultOption(); // for api7 bool IsWindowValid() const; void OnVsync(int64_t timeStamp); static sptr FindTopWindow(uint32_t topWinId); WMError Drag(const Rect& rect); void ConsumeMoveOrDragEvent(std::shared_ptr& pointerEvent); void HandleDragEvent(int32_t posX, int32_t posY, int32_t pointId); void HandleMoveEvent(int32_t posX, int32_t posY, int32_t pointId); void ReadyToMoveOrDragWindow(int32_t globalX, int32_t globalY, int32_t pointId, const Rect& rect); void EndMoveOrDragWindow(int32_t pointId); bool IsPointerEventConsumed(); void AdjustWindowAnimationFlag(); void MapFloatingWindowToAppIfNeeded(); // colorspace, gamut using ColorSpaceConvertMap = struct { ColorSpace colorSpace; SurfaceColorGamut sufaceColorGamut; }; static const ColorSpaceConvertMap colorSpaceConvertMap[]; static ColorSpace GetColorSpaceFromSurfaceGamut(SurfaceColorGamut surfaceColorGamut); static SurfaceColorGamut GetSurfaceGamutFromColorSpace(ColorSpace colorSpace); std::shared_ptr callback_ = std::make_shared(VsyncStation::VsyncCallback()); static std::map>> windowMap_; static std::map>> subWindowMap_; static std::map>> appFloatingWindowMap_; sptr property_; WindowState state_ { WindowState::STATE_INITIAL }; std::vector> lifecycleListeners_; std::vector> windowChangeListeners_; sptr avoidAreaChangeListener_; std::vector> windowDragListeners_; std::vector> displayMoveListeners_; std::shared_ptr surfaceNode_; std::string name_; std::unique_ptr uiContent_; std::shared_ptr abilityContext_; // give up when context offer getToken std::shared_ptr context_; std::recursive_mutex mutex_; const float SYSTEM_ALARM_WINDOW_WIDTH_RATIO = 0.8; const float SYSTEM_ALARM_WINDOW_HEIGHT_RATIO = 0.3; int32_t startPointPosX_ = 0; int32_t startPointPosY_ = 0; int32_t startPointerId_ = 0; bool startDragFlag_ = false; bool startMoveFlag_ = false; bool pointEventStarted_ = false; Rect startPointRect_ = { 0, 0, 0, 0 }; }; } } #endif // OHOS_ROSEN_WINDOW_IMPL_H