• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_LAYOUT_CONTROLLER_H
17 #define OHOS_ROSEN_LAYOUT_CONTROLLER_H
18 
19 #include <mutex>
20 #include <refbase.h>
21 #include <struct_multimodal.h>
22 
23 #include "common/include/window_session_property.h"
24 #include "interfaces/include/ws_common.h"
25 #include "wm_common.h"
26 
27 namespace OHOS::Rosen {
28 using GetSystemConfigFunc = std::function<SystemSessionConfig()>;
29 
30 class LayoutController : public RefBase {
31 public:
32     LayoutController(const sptr<WindowSessionProperty>& property);
33     ~LayoutController() = default;
34 
SetSessionRect(const WSRect & rect)35     void SetSessionRect(const WSRect& rect) { winRect_ = rect; }
36     bool SetSessionGlobalRect(const WSRect& rect);
37     void SetClientRect(const WSRect& rect);
GetSessionRect()38     WSRect GetSessionRect() const { return winRect_; }
39     WSRect GetSessionGlobalRect() const;
40     WSRect GetClientRect() const;
41     void GetGlobalScaledRect(Rect& globalScaledRect);
42     WSRect ConvertRelativeRectToGlobal(const WSRect& relativeRect, DisplayId currentDisplayId) const;
43     WSRect ConvertGlobalRectToRelative(const WSRect& globalRect, DisplayId targetDisplayId) const;
44     int32_t GetSessionPersistentId() const;
45     bool AdjustRectByAspectRatio(WSRect& rect, bool isDecorEnable);
GetAspectRatio()46     float GetAspectRatio() const { return aspectRatio_; }
SetAspectRatio(float ratio)47     void SetAspectRatio(float ratio) { aspectRatio_ = ratio; }
GetScaleX()48     float GetScaleX() const { return scaleX_; }
GetScaleY()49     float GetScaleY() const { return scaleY_; }
GetPivotX()50     float GetPivotX() const { return pivotX_; }
GetPivotY()51     float GetPivotY() const { return pivotY_; }
UpdateSizeChangeReason(SizeChangeReason reason)52     void UpdateSizeChangeReason(SizeChangeReason reason) { reason_ = reason; }
GetSizeChangeReason()53     SizeChangeReason GetSizeChangeReason() const { return reason_; }
54     void SetScale(float scaleX, float scaleY, float pivotX, float pivotY);
55     void SetClientScale(float scaleX, float scaleY, float pivotX, float pivotY);
56     bool IsTransformNeedUpdate(float scaleX, float scaleY, float pivotX, float pivotY);
57     void SetSystemConfigFunc(GetSystemConfigFunc&& func);
58 
59 private:
60     float scaleX_ = 1.0f;
61     float scaleY_ = 1.0f;
62     float pivotX_ = 0.0f;
63     float pivotY_ = 0.0f;
64     float clientScaleX_ = 1.0f;
65     float clientScaleY_ = 1.0f;
66     float clientPivotX_ = 0.0f;
67     float clientPivotY_ = 0.0f;
68     WSRect winRect_;
69     WSRect clientRect_;     // rect saved when prelayout or notify client to update rect
70     mutable std::mutex globalRectMutex_;
71     WSRect globalRect_;     // globalRect include translate
72     SizeChangeReason reason_ = SizeChangeReason::UNDEFINED;
73     float aspectRatio_ = 0.0f;
74     sptr<WindowSessionProperty> sessionProperty_;
75     GetSystemConfigFunc getSystemConfigFunc_;
76 
77     void AdjustRectByLimits(WindowLimits limits, float ratio, bool isDecor, float vpr, WSRect& rect);
78 };
79 } // namespace OHOS::Rosen
80 #endif // OHOS_ROSEN_LAYOUT_CONTROLLER_H
81