/* * Copyright (c) 2023 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_SESSION_IMPL_H #define OHOS_ROSEN_WINDOW_SESSION_IMPL_H #include #include #include #include #include #include #include #include #include "display_manager.h" #include "singleton_container.h" #include "common/include/window_session_property.h" #include "interfaces/include/ws_common_inner.h" #include "session/container/include/zidl/session_stage_stub.h" #include "session/host/include/zidl/session_interface.h" #include "window.h" #include "window_option.h" #include "wm_common.h" namespace OHOS { namespace Rosen { namespace { template using EnableIfSame = typename std::enable_if, Ret>::type; } class WindowSessionImpl : public Window, public virtual SessionStageStub { public: explicit WindowSessionImpl(const sptr& option); ~WindowSessionImpl(); static sptr Find(const std::string& name); static std::vector> GetSubWindow(int parentId); // inherits from window virtual WMError Create(const std::shared_ptr& context, const sptr& iSession); WMError Show(uint32_t reason = 0, bool withAnimation = false) override; WMError Hide(uint32_t reason = 0, bool withAnimation = false, bool isFromInnerkits = true) override; WMError Destroy() override; virtual WMError Destroy(bool needClearListener); WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed, AppExecFwk::Ability* ability) override; std::shared_ptr GetSurfaceNode() const override; const std::shared_ptr GetContext() const override; Rect GetRequestRect() const override; WindowType GetType() const override; const std::string& GetWindowName() const override; WindowState GetWindowState() const override; WindowState GetRequestWindowState() const; WMError SetFocusable(bool isFocusable) override; WMError SetTouchable(bool isTouchable) override; WMError SetResizeByDragEnabled(bool dragEnabled) override; WMError SetRaiseByClickEnabled(bool raiseEnabled) override; WMError SetWindowType(WindowType type) override; WMError SetBrightness(float brightness) override; virtual float GetBrightness() const override; void SetRequestedOrientation(Orientation orientation) override; bool GetTouchable() const override; uint32_t GetWindowId() const override; Rect GetRect() const override; bool GetFocusable() const override; std::string GetContentInfo() override; Ace::UIContent* GetUIContent() const override; void OnNewWant(const AAFwk::Want& want) override; WMError SetAPPWindowLabel(const std::string& label) override; WMError SetAPPWindowIcon(const std::shared_ptr& icon) override; void RequestVsync(const std::shared_ptr& vsyncCallback) override; int64_t GetVSyncPeriod() override; // inherits from session stage WSError SetActive(bool active) override; WSError UpdateRect(const WSRect& rect, SizeChangeReason reason) override; WSError UpdateFocus(bool focus) override; WSError UpdateWindowMode(WindowMode mode) override; WSError HandleBackEvent() override { return WSError::WS_OK; } WMError SetWindowGravity(WindowGravity gravity, uint32_t percent) override; WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override; void NotifyPointerEvent(const std::shared_ptr& pointerEvent) override; void NotifyKeyEvent(const std::shared_ptr& keyEvent, bool& isConsumed) override; void NotifyOccupiedAreaChangeInfo(sptr info) override; WMError RegisterLifeCycleListener(const sptr& listener) override; WMError UnregisterLifeCycleListener(const sptr& listener) override; WMError RegisterWindowChangeListener(const sptr& listener) override; WMError UnregisterWindowChangeListener(const sptr& listener) override; WMError RegisterAvoidAreaChangeListener(sptr& listener) override; WMError UnregisterAvoidAreaChangeListener(sptr& listener) override; void RegisterDialogDeathRecipientListener(const sptr& listener) override; void UnregisterDialogDeathRecipientListener(const sptr& listener) override; WMError RegisterDialogTargetTouchListener(const sptr& listener) override; WMError UnregisterDialogTargetTouchListener(const sptr& listener) override; WMError RegisterOccupiedAreaChangeListener(const sptr& listener) override; WMError UnregisterOccupiedAreaChangeListener(const sptr& listener) override; WMError RegisterTouchOutsideListener(const sptr& listener) override; WMError UnregisterTouchOutsideListener(const sptr& listener) override; void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) override; WMError RegisterScreenshotListener(const sptr& listener) override; WMError UnregisterScreenshotListener(const sptr& listener) override; void SetAceAbilityHandler(const sptr& handler) override; void SetInputEventConsumer(const std::shared_ptr& inputEventConsumer) override; WMError SetBackgroundColor(const std::string& color) override; int32_t GetParentId() const; int32_t GetPersistentId() const override; sptr GetProperty() const; SystemSessionConfig GetSystemSessionConfig() const; sptr GetHostSession() const; int32_t GetFloatingWindowParentId(); void NotifyAfterForeground(bool needNotifyListeners = true, bool needNotifyUiContent = true); void NotifyAfterBackground(bool needNotifyListeners = true, bool needNotifyUiContent = true); void NotifyForegroundFailed(WMError ret); void NotifyBackgroundFailed(WMError ret); WSError MarkProcessed(int32_t eventId) override; void UpdateWindowSizeLimits(); void UpdateTitleButtonVisibility(); WSError NotifyDestroy() override; void NotifyAvoidAreaChange(const sptr& avoidArea, AvoidAreaType type); WSError UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) override; void NotifyTouchDialogTarget() override; void NotifyScreenshot() override; void DumpSessionElementInfo(const std::vector& params) override; // colorspace, gamut virtual bool IsSupportWideGamut() override; virtual void SetColorSpace(ColorSpace colorSpace) override; virtual ColorSpace GetColorSpace() override; WSError NotifyTouchOutside() override; WindowState state_ { WindowState::STATE_INITIAL }; WindowState requestState_ { WindowState::STATE_INITIAL }; protected: WMError Connect(); bool IsWindowSessionInvalid() const; void NotifyAfterActive(); void NotifyAfterInactive(); void NotifyBeforeDestroy(std::string windowName); void ClearListenersById(int32_t persistentId); WMError WindowSessionCreateCheck(); void UpdateDecorEnable(bool needNotify = false); void NotifyModeChange(WindowMode mode, bool hasDeco = true); WMError UpdateProperty(WSPropertyChangeAction action); WMError SetBackgroundColor(uint32_t color); uint32_t GetBackgroundColor() const; virtual WMError SetLayoutFullScreenByApiVersion(bool status); void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason); sptr hostSession_; std::unique_ptr uiContent_; std::shared_ptr context_; std::shared_ptr surfaceNode_; sptr property_; SystemSessionConfig windowSystemConfig_; NotifyNativeWinDestroyFunc notifyNativeFunc_; std::recursive_mutex mutex_; static std::map>> windowSessionMap_; static std::map>> subWindowSessionMap_; bool isSystembarPropertiesSet_ = false; bool isIgnoreSafeAreaNeedNotify_ = false; bool isIgnoreSafeArea_ = false; std::shared_ptr handler_ = nullptr; private: //Trans between colorGamut and colorSpace static ColorSpace GetColorSpaceFromSurfaceGamut(GraphicColorGamut colorGamut); static GraphicColorGamut GetSurfaceGamutFromColorSpace(ColorSpace colorSpace); static std::unordered_map colorSpaceConvertMap; template WMError RegisterListener(std::vector>& holder, const sptr& listener); template WMError UnregisterListener(std::vector>& holder, const sptr& listener); template EnableIfSame>> GetListeners(); template EnableIfSame>> GetListeners(); template EnableIfSame>> GetListeners(); template EnableIfSame>> GetListeners(); template EnableIfSame>> GetListeners(); template EnableIfSame>> GetListeners(); template EnableIfSame>> GetListeners(); template EnableIfSame>> GetListeners(); template void ClearUselessListeners(std::map& listeners, int32_t persistentId); RSSurfaceNode::SharedPtr CreateSurfaceNode(std::string name, WindowType type); void NotifyAfterFocused(); void NotifyAfterUnfocused(bool needNotifyUiContent = true); void NotifySizeChange(Rect rect, WindowSizeChangeReason reason); bool IsKeyboardEvent(const std::shared_ptr& keyEvent) const; static std::recursive_mutex globalMutex_; static std::map>> lifecycleListeners_; static std::map>> windowChangeListeners_; static std::map>> avoidAreaChangeListeners_; static std::map>> dialogDeathRecipientListeners_; static std::map>> dialogTargetTouchListener_; static std::map>> occupiedAreaChangeListeners_; static std::map>> screenshotListeners_; std::shared_ptr inputEventConsumer_; static std::map>> touchOutsideListeners_; // FA only sptr aceAbilityHandler_; WindowSizeChangeReason lastSizeChangeReason_ = WindowSizeChangeReason::END; bool postTaskDone_ = false; }; } // namespace Rosen } // namespace OHOS #endif // OHOS_ROSEN_WINDOW_SESSION_IMPL_H