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, const WSRectF& velocity, bool isStartFullScreen); 38 void ResetRecords(); 39 void RecordMoveRects(const WSRect& rect); 40 bool ThrowSlip(DisplayId displayId, WSRect& rect, int32_t topAvoidHeight, int32_t botAvoidHeight); 41 void ThrowSlipFloatingRectDirectly(WSRect& rect, const WSRect& floatingRect, 42 int32_t topAvoidHeight, int32_t botAvoidHeight); 43 bool IsThrowSlipDirectly() const; 44 bool IsStartFullScreen(); 45 void ResizeToFullScreen(WSRect& rect, int32_t topAvoidHeight, int32_t botAvoidHeight); 46 47 // animation parameters 48 RSAnimationTimingProtocol GetMovingTimingProtocol(); 49 RSAnimationTimingCurve GetMovingTimingCurve(); 50 RSAnimationTimingProtocol GetThrowSlipTimingProtocol(); 51 RSAnimationTimingCurve GetThrowSlipTimingCurve(); 52 53 void UpdateFullScreenWaterfallMode(bool isWaterfallMode); IsFullScreenWaterfallMode()54 bool IsFullScreenWaterfallMode() const { return isFullScreenWaterfallMode_; } 55 void UpdateRect(); 56 void RegisterFullScreenWaterfallModeChangeCallback(std::function<void(bool isWaterfallMode)>&& func); 57 void UnregisterFullScreenWaterfallModeChangeCallback(); 58 void UpdateSupportEnterWaterfallMode(); 59 void MaskSupportEnterWaterfallMode(); 60 61 private: 62 int32_t GetPersistentId() const; 63 DisplayId GetDisplayId(); 64 int32_t GetTitleHeight() const; 65 WSRectF CalculateMovingVelocity(); 66 void ThrowSlipHiSysEvent(const std::string& bundleName, ScreenSide startSide, 67 ThrowSlipWindowMode startWindowMode, ThrowSlipMode throwMode) const; 68 69 bool IsSupportEnterWaterfallMode(SuperFoldStatus status, bool hasSystemKeyboard) const; 70 void FoldStatusChangeForFullScreenWaterfallMode( 71 DisplayId displayId, SuperFoldStatus status, SuperFoldStatus prevStatus); 72 void FoldStatusChangeForSupportEnterWaterfallMode( 73 DisplayId displayId, SuperFoldStatus status, SuperFoldStatus prevStatus); 74 void SystemKeyboardStatusChangeForFullScreenWaterfallMode( 75 DisplayId displayId, bool hasSystemKeyboard); 76 void SystemKeyboardStatusChangeForSupportEnterWaterfallMode( 77 DisplayId displayId, bool hasSystemKeyboard); 78 79 wptr<SceneSession> weakSceneSession_ = nullptr; 80 int32_t persistentId_; 81 82 // use queue to calculate velocity 83 mutable std::mutex moveMutex_; 84 WSRect startMoveRect_; 85 bool isStartFullScreen_ { false }; 86 bool isStartWaterfallMode_ { false }; 87 RectRecordsVector movingRectRecords_; 88 bool isStartDirectly_ { false }; 89 WSRectF startVelocity_; 90 // Above guarded by moveMutex_ 91 92 std::shared_ptr<FoldScreenStatusChangeCallback> onFoldScreenStatusChangeCallback_; 93 std::shared_ptr<SystemKeyboardStatusChangeCallback> onSystemKeyboardStatusChangeCallback_; 94 95 /* 96 * Waterfall Mode 97 * accessed on SSM thread 98 */ 99 void ExecuteFullScreenWaterfallModeChangeCallback(); 100 bool isFullScreenWaterfallMode_ { false }; 101 bool lastSupportEnterWaterfallMode_ { false }; 102 bool supportEnterWaterfallMode_ { false }; 103 bool maskSupportEnterWaterfallMode_ { false }; 104 std::function<void(bool isWaterfallMode)> fullScreenWaterfallModeChangeCallback_ { nullptr }; 105 }; 106 } // namespace OHOS::Rosen 107 108 #endif // PC_FOLD_SCREEN_CONTROLLER_H