1 /* 2 * Copyright (c) 2024 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 PC_FOLD_SCREEN_CONTROLLER_H 17 #define PC_FOLD_SCREEN_CONTROLLER_H 18 19 #include <chrono> 20 #include "session/host/include/pc_fold_screen_manager.h" 21 22 namespace OHOS::Rosen { 23 24 class SceneSession; 25 using RectRecordsVector = 26 std::vector<std::pair<std::chrono::time_point<std::chrono::high_resolution_clock>, WSRect>>; 27 28 class PcFoldScreenController : public RefBase { 29 public: 30 PcFoldScreenController(wptr<SceneSession> weakSession, int32_t persistentId); 31 ~PcFoldScreenController(); 32 void OnConnect(); 33 bool IsHalfFolded(DisplayId displayId); 34 bool IsAllowThrowSlip(DisplayId displayId); 35 bool NeedFollowHandAnimation(); 36 void RecordStartMoveRect(const WSRect& rect, bool isStartFullScreen); 37 void RecordStartMoveRectDirectly(const WSRect& rect, ThrowSlipMode throwSlipMode, const WSRectF& velocity, 38 bool isStartFullScreen); 39 void ResetRecords(); 40 void RecordMoveRects(const WSRect& rect); 41 bool ThrowSlip(DisplayId displayId, WSRect& rect, int32_t topAvoidHeight, int32_t botAvoidHeight); 42 void ThrowSlipFloatingRectDirectly(WSRect& rect, const WSRect& floatingRect, 43 int32_t topAvoidHeight, int32_t botAvoidHeight); 44 bool IsThrowSlipDirectly() const; 45 bool IsStartFullScreen(); 46 void ResizeToFullScreen(WSRect& rect, int32_t topAvoidHeight, int32_t botAvoidHeight); 47 48 // animation parameters 49 RSAnimationTimingProtocol GetMovingTimingProtocol(); 50 RSAnimationTimingCurve GetMovingTimingCurve(); 51 RSAnimationTimingProtocol GetThrowSlipTimingProtocol(); 52 RSAnimationTimingCurve GetThrowSlipTimingCurve(); 53 54 void UpdateFullScreenWaterfallMode(bool isWaterfallMode); IsFullScreenWaterfallMode()55 bool IsFullScreenWaterfallMode() const { return isFullScreenWaterfallMode_; } 56 void SetFullScreenWaterfallMode(bool isFullScreenWaterfallMode); 57 void UpdateRect(); 58 void RegisterFullScreenWaterfallModeChangeCallback(std::function<void(bool isWaterfallMode)>&& func); 59 void UnregisterFullScreenWaterfallModeChangeCallback(); 60 void UpdateSupportEnterWaterfallMode(); 61 void MaskSupportEnterWaterfallMode(); 62 63 private: 64 int32_t GetPersistentId() const; 65 DisplayId GetDisplayId(); 66 int32_t GetTitleHeight() const; 67 WSRectF CalculateMovingVelocity(); 68 bool IsThrowSlipModeDirectly(ThrowSlipMode throwSlipMode) const; 69 void ThrowSlipHiSysEvent(const std::string& bundleName, ScreenSide startSide, 70 ThrowSlipWindowMode startWindowMode, ThrowSlipMode throwMode) const; 71 72 bool IsSupportEnterWaterfallMode(SuperFoldStatus status, bool hasSystemKeyboard) const; 73 void FoldStatusChangeForSupportEnterWaterfallMode( 74 DisplayId displayId, SuperFoldStatus status, SuperFoldStatus prevStatus); 75 void SystemKeyboardStatusChangeForSupportEnterWaterfallMode( 76 DisplayId displayId, bool hasSystemKeyboard); 77 78 wptr<SceneSession> weakSceneSession_ = nullptr; 79 int32_t persistentId_; 80 81 // use queue to calculate velocity 82 mutable std::mutex moveMutex_; 83 WSRect startMoveRect_; 84 bool isStartFullScreen_ { false }; 85 bool isStartWaterfallMode_ { false }; 86 RectRecordsVector movingRectRecords_; 87 ThrowSlipMode startThrowSlipMode_ { ThrowSlipMode::INVALID }; 88 WSRectF startVelocity_; 89 // Above guarded by moveMutex_ 90 91 std::shared_ptr<FoldScreenStatusChangeCallback> onFoldScreenStatusChangeCallback_; 92 std::shared_ptr<SystemKeyboardStatusChangeCallback> onSystemKeyboardStatusChangeCallback_; 93 94 /* 95 * Waterfall Mode 96 * accessed on SSM thread 97 */ 98 void ExecuteFullScreenWaterfallModeChangeCallback(); 99 bool isFullScreenWaterfallMode_ { false }; 100 bool lastSupportEnterWaterfallMode_ { false }; 101 bool supportEnterWaterfallMode_ { false }; 102 bool maskSupportEnterWaterfallMode_ { false }; 103 std::function<void(bool isWaterfallMode)> fullScreenWaterfallModeChangeCallback_ { nullptr }; 104 }; 105 } // namespace OHOS::Rosen 106 107 #endif // PC_FOLD_SCREEN_CONTROLLER_H