增加VirtualPixelRatio, 热区计算移动到layout

Signed-off-by: huandong <huandong1@huawei.com>
Change-Id: If397c747352872bfc8dbbb3438745a56d82a419a
This commit is contained in:
huandong
2022-02-16 22:01:05 +08:00
parent 170ca3691e
commit 685a4db2de
19 changed files with 215 additions and 102 deletions
-7
View File
@@ -138,14 +138,7 @@ struct PointInfo {
namespace {
constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF;
constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000;
constexpr float DEFAULT_SPLIT_RATIO = 0.5;
constexpr uint32_t DIVIDER_WIDTH = 8;
constexpr uint32_t INVALID_WINDOW_ID = 0;
constexpr uint32_t HOTZONE = 40;
constexpr uint32_t MIN_VERTICAL_FLOATING_WIDTH = 240;
constexpr uint32_t MIN_VERTICAL_FLOATING_HEIGHT = 426;
constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 426;
constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 426;
}
struct SystemBarProperty {
+9 -5
View File
@@ -17,6 +17,7 @@
#define OHOS_WM_INCLUDE_WM_HELPER_H
#include <wm_common.h>
#include <wm_common_inner.h>
namespace OHOS {
namespace Rosen {
@@ -79,15 +80,18 @@ public:
return (r.posX_ == 0 && r.posY_ == 0 && r.width_ == 0 && r.height_ == 0);
}
static Rect GetFixedWindowRectByMinRect(const Rect& oriDstRect, const Rect& lastRect, bool isVertical)
static Rect GetFixedWindowRectByMinRect(const Rect& oriDstRect, const Rect& lastRect, bool isVertical,
float virtualPixelRatio)
{
uint32_t minVerticalFloatingW = static_cast<uint32_t>(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio);
uint32_t minVerticalFloatingH = static_cast<uint32_t>(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio);
Rect dstRect = oriDstRect;
if (isVertical) {
dstRect.width_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, oriDstRect.width_);
dstRect.height_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, oriDstRect.height_);
dstRect.width_ = std::max(minVerticalFloatingW, oriDstRect.width_);
dstRect.height_ = std::max(minVerticalFloatingH, oriDstRect.height_);
} else {
dstRect.width_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, oriDstRect.width_);
dstRect.height_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, oriDstRect.height_);
dstRect.width_ = std::max(minVerticalFloatingH, oriDstRect.width_);
dstRect.height_ = std::max(minVerticalFloatingW, oriDstRect.height_);
}
// limit position by fixed width or height
+12
View File
@@ -44,6 +44,18 @@ enum class WindowUpdateReason : uint32_t {
UPDATE_TYPE,
UPDATE_OTHER_PROPS,
};
namespace {
constexpr float DEFAULT_SPLIT_RATIO = 0.5;
constexpr uint32_t DIVIDER_WIDTH = 8;
constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 48;
constexpr uint32_t WINDOW_FRAME_WIDTH = 4;
constexpr uint32_t HOTZONE = 40;
constexpr uint32_t DIV_HOTZONE = 20;
constexpr uint32_t MIN_VERTICAL_FLOATING_WIDTH = 240;
constexpr uint32_t MIN_VERTICAL_FLOATING_HEIGHT = 426;
constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 426;
constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 426;
}
}
}
#endif // OHOS_ROSEN_WM_COMMON_INNER_H
+9 -5
View File
@@ -32,6 +32,7 @@ public:
DisplayId displayId_ = 0;
std::vector<sptr<Window>> activeWindows_;
static vector<Rect> fullScreenExpecteds_;
static inline float virtualPixelRatio_ = 0.0;
};
vector<Rect> WindowLayoutTest::fullScreenExpecteds_;
@@ -47,6 +48,9 @@ void WindowLayoutTest::SetUpTestCase()
}
Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()};
utils::InitByDisplayRect(displayRect);
virtualPixelRatio_ = WindowTestUtils::GetVirtualPixelRatio(0);
// calc expected rects
Rect expected = { // 0. only statusBar
0,
@@ -110,7 +114,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow02, Function | MediumTest | Level3)
activeWindows_.push_back(window);
ASSERT_EQ(WMError::WM_OK, window->Show());
ASSERT_TRUE(utils::RectEqualTo(window, utils::GetFloatingLimitedRect(utils::customAppRect_)));
ASSERT_TRUE(utils::RectEqualTo(window, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_)));
ASSERT_EQ(WMError::WM_OK, window->Hide());
}
@@ -140,12 +144,12 @@ HWTEST_F(WindowLayoutTest, LayoutWindow04, Function | MediumTest | Level3)
activeWindows_.push_back(statBar);
ASSERT_EQ(WMError::WM_OK, appWin->Show());
ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_)));
ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_)));
ASSERT_EQ(WMError::WM_OK, statBar->Show());
ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_)));
ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_)));
ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_));
ASSERT_EQ(WMError::WM_OK, statBar->Hide());
ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_)));
ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_)));
}
/**
@@ -277,7 +281,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow09, Function | MediumTest | Level3)
ASSERT_EQ(WMError::WM_OK, window->Resize(2u, 2u)); // 2: custom min size
Rect finalExcept = { expect.posX_, expect.posY_, 2u, 2u}; // 2: custom min size
finalExcept = utils::GetFloatingLimitedRect(finalExcept);
finalExcept = utils::GetFloatingLimitedRect(finalExcept, virtualPixelRatio_);
ASSERT_TRUE(utils::RectEqualTo(window, finalExcept));
ASSERT_EQ(WMError::WM_OK, window->Hide());
}
+34 -28
View File
@@ -18,6 +18,7 @@
#include "pointer_event.h"
#include "window_helper.h"
#include "window_test_utils.h"
#include "wm_common_inner.h"
using namespace testing;
using namespace testing::ext;
@@ -54,6 +55,8 @@ private:
static inline Rect startPointRect_ = {0, 0, 0, 0};
static inline Rect expectRect_ = {0, 0, 0, 0};
static inline sptr<Window> window_ = nullptr;
static inline float virtualPixelRatio_ = 0.0;
static inline uint32_t hotZone_ = 0;
};
void WindowMoveDragTest::SetUpTestCase()
@@ -83,6 +86,9 @@ void WindowMoveDragTest::SetUp()
Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()};
utils::InitByDisplayRect(displayRect);
virtualPixelRatio_ = WindowTestUtils::GetVirtualPixelRatio(0);
hotZone_ = static_cast<uint32_t>(HOTZONE * virtualPixelRatio_);
winInfo_ = {
.name = "Floating",
.rect = {0, 0, 0, 0},
@@ -174,7 +180,7 @@ void WindowMoveDragTest::CalExpectRects()
}
}
bool isVertical = (utils::displayRect_.width_ < utils::displayRect_.height_) ? true : false;
expectRect_ = WindowHelper::GetFixedWindowRectByMinRect(oriRect, startPointRect_, isVertical);
expectRect_ = WindowHelper::GetFixedWindowRectByMinRect(oriRect, startPointRect_, isVertical, virtualPixelRatio_);
}
namespace {
@@ -188,10 +194,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow01, Function | MediumTest | Level3)
{
ASSERT_EQ(WMError::WM_OK, window_->Show());
startPointRect_ = window_->GetRect();
startPointX_ = startPointRect_.posX_ - HOTZONE * POINT_HOTZONE_RATIO;
startPointX_ = startPointRect_.posX_ - hotZone_ * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ + startPointRect_.height_ * POINT_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + hotZone_ * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO;
DoMoveOrDrag();
ASSERT_EQ(WMError::WM_OK, window_->Hide());
}
@@ -206,11 +212,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow02, Function | MediumTest | Level3)
{
ASSERT_EQ(WMError::WM_OK, window_->Show());
startPointRect_ = window_->GetRect();
startPointX_ = startPointRect_.posX_ - HOTZONE * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ - HOTZONE * POINT_HOTZONE_RATIO;
startPointX_ = startPointRect_.posX_ - hotZone_ * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ - hotZone_ * POINT_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + hotZone_ * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO;
DoMoveOrDrag();
ASSERT_EQ(WMError::WM_OK, window_->Hide());
}
@@ -225,11 +231,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow03, Function | MediumTest | Level3)
{
ASSERT_EQ(WMError::WM_OK, window_->Show());
startPointRect_ = window_->GetRect();
startPointX_ = startPointRect_.posX_ - HOTZONE * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * POINT_HOTZONE_RATIO;
startPointX_ = startPointRect_.posX_ - hotZone_ * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * POINT_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + hotZone_ * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO;
DoMoveOrDrag();
ASSERT_EQ(WMError::WM_OK, window_->Hide());
}
@@ -244,10 +250,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow04, Function | MediumTest | Level3)
{
ASSERT_EQ(WMError::WM_OK, window_->Show());
startPointRect_ = window_->GetRect();
startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * POINT_HOTZONE_RATIO;
startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ + startPointRect_.height_ * POINT_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + startPointRect_.height_ * DRAG_HOTZONE_RATIO;
DoMoveOrDrag();
ASSERT_EQ(WMError::WM_OK, window_->Hide());
@@ -263,11 +269,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow05, Function | MediumTest | Level3)
{
ASSERT_EQ(WMError::WM_OK, window_->Show());
startPointRect_ = window_->GetRect();
startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ - HOTZONE * POINT_HOTZONE_RATIO;
startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ - hotZone_ * POINT_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO;
DoMoveOrDrag();
ASSERT_EQ(WMError::WM_OK, window_->Hide());
}
@@ -282,11 +288,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow06, Function | MediumTest | Level3)
{
ASSERT_EQ(WMError::WM_OK, window_->Show());
startPointRect_ = window_->GetRect();
startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * POINT_HOTZONE_RATIO;
startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * POINT_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO;
DoMoveOrDrag();
ASSERT_EQ(WMError::WM_OK, window_->Hide());
}
@@ -302,10 +308,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow07, Function | MediumTest | Level3)
ASSERT_EQ(WMError::WM_OK, window_->Show());
startPointRect_ = window_->GetRect();
startPointX_ = startPointRect_.posX_ + startPointRect_.width_ * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ - HOTZONE * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ - hotZone_ * POINT_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ - HOTZONE * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ - hotZone_ * DRAG_HOTZONE_RATIO;
DoMoveOrDrag();
ASSERT_EQ(WMError::WM_OK, window_->Hide());
}
@@ -321,10 +327,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow08, Function | MediumTest | Level3)
ASSERT_EQ(WMError::WM_OK, window_->Show());
startPointRect_ = window_->GetRect();
startPointX_ = startPointRect_.posX_ + startPointRect_.width_ * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * POINT_HOTZONE_RATIO;
startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * POINT_HOTZONE_RATIO;
pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO;
DoMoveOrDrag();
ASSERT_EQ(WMError::WM_OK, window_->Hide());
}
@@ -343,7 +349,7 @@ HWTEST_F(WindowMoveDragTest, DragWindow09, Function | MediumTest | Level3)
startPointY_ = startPointRect_.posY_ + 1;
pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO;
DoMoveOrDrag();
ASSERT_EQ(WMError::WM_OK, window_->Hide());
}
@@ -362,7 +368,7 @@ HWTEST_F(WindowMoveDragTest, DragWindow10, Function | MediumTest | Level3)
startPointY_ = startPointRect_.posY_ + 1;
pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO;
pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO;
window_->StartMove();
hasStartMove_ = true;
DoMoveOrDrag();
+36 -12
View File
@@ -15,6 +15,7 @@
#include "window_test_utils.h"
#include <ability_context.h>
#include "wm_common_inner.h"
namespace OHOS {
namespace Rosen {
namespace {
@@ -123,13 +124,18 @@ Rect WindowTestUtils::GetDefaultFoatingRect(const sptr<Window>& window)
return resRect;
}
Rect WindowTestUtils::GetLimitedDecoRect(const Rect& rect)
Rect WindowTestUtils::GetLimitedDecoRect(const Rect& rect, float virtualPixelRatio)
{
constexpr uint32_t winFrameH = 52u;
constexpr uint32_t winFrameW = 8u;
constexpr uint32_t windowTitleBarHeight = 48;
constexpr uint32_t windowFrameWidth = 4;
uint32_t winFrameH = static_cast<uint32_t>((windowTitleBarHeight + windowFrameWidth) * virtualPixelRatio);
uint32_t winFrameW = static_cast<uint32_t>((windowFrameWidth + windowFrameWidth) * virtualPixelRatio);
uint32_t minVerticalFloatingW = static_cast<uint32_t>(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio);
uint32_t minVerticalFloatingH = static_cast<uint32_t>(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio);
bool vertical = displayRect_.width_ < displayRect_.height_;
uint32_t minFloatingW = vertical ? MIN_VERTICAL_FLOATING_WIDTH : MIN_VERTICAL_FLOATING_HEIGHT;
uint32_t minFloatingH = vertical ? MIN_VERTICAL_FLOATING_HEIGHT : MIN_VERTICAL_FLOATING_WIDTH;
uint32_t minFloatingW = vertical ? minVerticalFloatingW : minVerticalFloatingH;
uint32_t minFloatingH = vertical ? minVerticalFloatingH : minVerticalFloatingW;
Rect resRect = {
rect.posX_,
rect.posY_,
@@ -139,11 +145,14 @@ Rect WindowTestUtils::GetLimitedDecoRect(const Rect& rect)
return resRect;
}
Rect WindowTestUtils::GetFloatingLimitedRect(const Rect& rect)
Rect WindowTestUtils::GetFloatingLimitedRect(const Rect& rect, float virtualPixelRatio)
{
uint32_t minVerticalFloatingW = static_cast<uint32_t>(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio);
uint32_t minVerticalFloatingH = static_cast<uint32_t>(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio);
bool vertical = displayRect_.width_ < displayRect_.height_;
uint32_t minFloatingW = vertical ? MIN_VERTICAL_FLOATING_WIDTH : MIN_VERTICAL_FLOATING_HEIGHT;
uint32_t minFloatingH = vertical ? MIN_VERTICAL_FLOATING_HEIGHT : MIN_VERTICAL_FLOATING_WIDTH;
uint32_t minFloatingW = vertical ? minVerticalFloatingW : minVerticalFloatingH;
uint32_t minFloatingH = vertical ? minVerticalFloatingH : minVerticalFloatingW;
Rect resRect = {
rect.posX_,
rect.posY_,
@@ -257,18 +266,21 @@ void WindowTestUtils::InitSplitRects()
displayRect_ = displayRect;
limitDisplayRect_ = displayRect;
float virtualPixelRatio = WindowTestUtils::GetVirtualPixelRatio(0);
uint32_t dividerWidth = static_cast<uint32_t>(DIVIDER_WIDTH * virtualPixelRatio);
if (displayRect_.width_ < displayRect_.height_) {
isVerticalDisplay_ = true;
}
if (isVerticalDisplay_) {
splitRects_.dividerRect = { 0,
static_cast<uint32_t>((displayRect_.height_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO),
static_cast<uint32_t>((displayRect_.height_ - dividerWidth) * DEFAULT_SPLIT_RATIO),
displayRect_.width_,
DIVIDER_WIDTH, };
dividerWidth, };
} else {
splitRects_.dividerRect = { static_cast<uint32_t>((displayRect_.width_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO),
splitRects_.dividerRect = { static_cast<uint32_t>((displayRect_.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO),
0,
DIVIDER_WIDTH,
dividerWidth,
displayRect_.height_ };
}
}
@@ -374,5 +386,17 @@ void WindowTestUtils::UpdateLimitSplitRect(Rect& limitSplitRect)
curLimitRect.posY_ + curLimitRect.height_) -
limitSplitRect.posY_;
}
float WindowTestUtils::GetVirtualPixelRatio(DisplayId displayId)
{
auto display = DisplayManager::GetInstance().GetDisplayById(displayId);
if (display == nullptr) {
WLOGFE("GetVirtualPixel fail. Get display fail. displayId:%{public}" PRIu64", vpr:%{public}f", displayId, 0.0);
return 0.0;
}
float virtualPixelRatio = display->GetVirtualPixelRatio();
WLOGFI("GetVirtualPixel success. displayId:%{public}" PRIu64", vpr:%{public}f", displayId, virtualPixelRatio);
return virtualPixelRatio;
}
} // namespace ROSEN
} // namespace OHOS
+3 -2
View File
@@ -66,9 +66,10 @@ public:
static void UpdateSplitRects(const sptr<Window>& window);
static bool RectEqualToRect(const Rect& l, const Rect& r);
static Rect GetDefaultFoatingRect(const sptr<Window>& window);
static Rect GetLimitedDecoRect(const Rect& rect);
static Rect GetFloatingLimitedRect(const Rect& rect);
static Rect GetLimitedDecoRect(const Rect& rect, float virtualPixelRatio);
static Rect GetFloatingLimitedRect(const Rect& rect, float virtualPixelRatio);
static void InitTileWindowRects(const sptr<Window>& window);
static float GetVirtualPixelRatio(DisplayId displayId);
private:
void UpdateLimitDisplayRect(Rect& avoidRect);
+1
View File
@@ -75,6 +75,7 @@ ohos_shared_library("libwms") {
":window_divider_image",
"//foundation/ace/ace_engine/build/external_config/flutter/skia:ace_skia_ohos",
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
"//foundation/windowmanager/dm:libdm",
"//foundation/windowmanager/dmserver:libdms",
"//foundation/windowmanager/utils:libwmutil",
"//foundation/windowmanager/wm:libwm",
+2
View File
@@ -50,6 +50,7 @@ public:
virtual void UpdateWindowNode(sptr<WindowNode>& node);
virtual void UpdateLayoutRect(sptr<WindowNode>& node) = 0;
void UpdateDefaultFoatingRect();
float GetVirtualPixelRatio() const;
protected:
const Rect& displayRect_;
@@ -66,6 +67,7 @@ protected:
void UpdateLimitRect(const sptr<WindowNode>& node, Rect& limitRect);
virtual void LayoutWindowNode(sptr<WindowNode>& node);
AvoidPosType GetAvoidPosType(const Rect& rect);
void CalcAndSetNodeHotZone(Rect layoutOutRect, sptr<WindowNode>& node);
void LimitWindowSize(const sptr<WindowNode>& node, const Rect& displayRect, Rect& winRect);
void SetRectForFloating(const sptr<WindowNode>& node);
Rect ComputeDecoratedWindowRect(const Rect& winRect);
+2
View File
@@ -42,6 +42,7 @@ public:
void SetDisplayId(DisplayId displayId);
void SetLayoutRect(const Rect& rect);
void SetHotZoneRect(const Rect& rect);
void SetWindowRect(const Rect& rect);
void SetWindowProperty(const sptr<WindowProperty>& property);
void SetSystemBarProperty(WindowType type, const SystemBarProperty& property);
@@ -81,6 +82,7 @@ private:
sptr<WindowProperty> property_;
sptr<IWindow> windowToken_;
Rect layoutRect_ { 0, 0, 0, 0 };
Rect hotZoneRect_ { 0, 0, 0, 0 };
int32_t callingPid_;
int32_t callingUid_;
WindowSizeChangeReason windowSizeChangeReason_ {WindowSizeChangeReason::UNDEFINED};
+1
View File
@@ -66,6 +66,7 @@ public:
sptr<WindowNode> GetBelowAppWindowNode() const;
sptr<WindowNode> GetAppWindowNode() const;
sptr<WindowNode> GetAboveAppWindowNode() const;
float GetVirtualPixelRatio() const;
private:
void AssignZOrder(sptr<WindowNode>& node);
+1
View File
@@ -62,6 +62,7 @@ public:
void NotifyDisplayDestory(DisplayId displayId);
void NotifySystemBarTints();
WMError RaiseZOrderForAppWindow(sptr<WindowNode>& node);
float GetVirtualPixelRatio(DisplayId displayId) const;
private:
void OnRemoteDied(const sptr<IRemoteObject>& remoteObject);
+4 -3
View File
@@ -140,8 +140,9 @@ WMError WindowController::ResizeRect(uint32_t windowId, const Rect& rect, Window
} else if (reason == WindowSizeChangeReason::DRAG) {
if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) {
// fix rect in case of moving window when dragging
newRect = WindowHelper::GetFixedWindowRectByMinRect(rect,
property->GetWindowRect(), windowRoot_->isVerticalDisplay(node));
float virtualPixelRatio = windowRoot_->GetVirtualPixelRatio(node->GetDisplayId());
newRect = WindowHelper::GetFixedWindowRectByMinRect(rect, property->GetWindowRect(),
windowRoot_->isVerticalDisplay(node), virtualPixelRatio);
} else {
newRect = rect;
}
@@ -274,7 +275,7 @@ void WindowController::ProcessDisplayChange(DisplayId displayId, DisplayStateCha
WLOGFE("get display failed displayId:%{public}" PRId64 "", displayId);
return;
}
switch (type) {
case DisplayStateChangeType::UPDATE_ROTATION: {
windowRoot_->NotifyDisplayChange(abstractDisplay);
+60 -11
View File
@@ -14,16 +14,16 @@
*/
#include "window_layout_policy.h"
#include "display_manager.h"
#include "window_helper.h"
#include "window_manager_hilog.h"
#include "wm_common_inner.h"
#include "wm_trace.h"
namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowLayoutPolicy"};
constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 48;
constexpr uint32_t WINDOW_FRAME_WIDTH = 4;
}
WindowLayoutPolicy::WindowLayoutPolicy(const Rect& displayRect, const uint64_t& screenId,
sptr<WindowNode>& belowAppNode, sptr<WindowNode>& appNode, sptr<WindowNode>& aboveAppNode)
@@ -115,11 +115,14 @@ void WindowLayoutPolicy::UpdateDefaultFoatingRect()
void WindowLayoutPolicy::SetRectForFloating(const sptr<WindowNode>& node)
{
float virtualPixelRatio = GetVirtualPixelRatio();
uint32_t winFrameW = static_cast<uint32_t>(WINDOW_FRAME_WIDTH * virtualPixelRatio);
uint32_t winTitleBarH = static_cast<uint32_t>(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio);
// deduct decor size
Rect rect = defaultFloatingRect_;
if (node->GetWindowProperty()->GetDecorEnable()) {
rect.width_ -= (WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH);
rect.height_ -= (WINDOW_TITLE_BAR_HEIGHT + WINDOW_FRAME_WIDTH);
rect.width_ -= (winFrameW + winFrameW);
rect.height_ -= (winTitleBarH + winFrameW);
}
node->SetWindowRect(rect);
@@ -174,11 +177,15 @@ void WindowLayoutPolicy::UpdateFloatingLayoutRect(Rect& limitRect, Rect& winRect
Rect WindowLayoutPolicy::ComputeDecoratedWindowRect(const Rect& winRect)
{
float virtualPixelRatio = GetVirtualPixelRatio();
uint32_t winFrameW = static_cast<uint32_t>(WINDOW_FRAME_WIDTH * virtualPixelRatio);
uint32_t winTitleBarH = static_cast<uint32_t>(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio);
Rect rect;
rect.posX_ = winRect.posX_;
rect.posY_ = winRect.posY_;
rect.width_ = winRect.width_ + WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH;
rect.height_ = winRect.height_ + WINDOW_TITLE_BAR_HEIGHT + WINDOW_FRAME_WIDTH;
rect.width_ = winRect.width_ + winFrameW + winFrameW;
rect.height_ = winRect.height_ + winTitleBarH + winFrameW;
return rect;
}
@@ -221,14 +228,44 @@ void WindowLayoutPolicy::UpdateLayoutRect(sptr<WindowNode>& node)
LimitWindowSize(node, displayRect, winRect);
node->SetLayoutRect(winRect);
CalcAndSetNodeHotZone(winRect, node);
if (!(lastRect == winRect)) {
node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason());
node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_);
}
}
void WindowLayoutPolicy::CalcAndSetNodeHotZone(Rect layoutOutRect, sptr<WindowNode>& node)
{
Rect rect = layoutOutRect;
float virtualPixelRatio = GetVirtualPixelRatio();
uint32_t hotZone = static_cast<uint32_t>(HOTZONE * virtualPixelRatio);
uint32_t divHotZone = static_cast<uint32_t>(DIV_HOTZONE * virtualPixelRatio);
if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
if (rect.width_ < rect.height_) {
rect.posX_ -= divHotZone;
rect.width_ += (divHotZone + divHotZone);
} else {
rect.posY_ -= divHotZone;
rect.height_ += (divHotZone + divHotZone);
}
} else if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) {
rect.posX_ -= hotZone;
rect.posY_ -= hotZone;
rect.width_ += (hotZone + hotZone);
rect.height_ += (hotZone + hotZone);
}
node->SetHotZoneRect(rect);
}
void WindowLayoutPolicy::LimitWindowSize(const sptr<WindowNode>& node, const Rect& displayRect, Rect& winRect)
{
float virtualPixelRatio = GetVirtualPixelRatio();
uint32_t minVerticalFloatingW = static_cast<uint32_t>(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio);
uint32_t minVerticalFloatingH = static_cast<uint32_t>(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio);
uint32_t windowTitleBarH = static_cast<uint32_t>(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio);
WindowType windowType = node->GetWindowType();
WindowMode windowMode = node->GetWindowMode();
bool isVertical = (displayRect.height_ > displayRect.width_) ? true : false;
@@ -238,16 +275,16 @@ void WindowLayoutPolicy::LimitWindowSize(const sptr<WindowNode>& node, const Rec
}
if ((windowMode == WindowMode::WINDOW_MODE_FLOATING) && !WindowHelper::IsSystemWindow(windowType)) {
if (isVertical) {
winRect.width_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, winRect.width_);
winRect.height_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, winRect.height_);
winRect.width_ = std::max(minVerticalFloatingW, winRect.width_);
winRect.height_ = std::max(minVerticalFloatingH, winRect.height_);
} else {
winRect.width_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, winRect.width_);
winRect.height_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, winRect.height_);
winRect.width_ = std::max(minVerticalFloatingH, winRect.width_);
winRect.height_ = std::max(minVerticalFloatingW, winRect.height_);
}
}
if (WindowHelper::IsMainFloatingWindow(windowType, windowMode)) {
winRect.posY_ = std::max(limitRect_.posY_, winRect.posY_);
winRect.posY_ = std::min(limitRect_.posY_ + static_cast<int32_t>(limitRect_.height_ - WINDOW_TITLE_BAR_HEIGHT),
winRect.posY_ = std::min(limitRect_.posY_ + static_cast<int32_t>(limitRect_.height_ - windowTitleBarH),
winRect.posY_);
}
}
@@ -314,5 +351,17 @@ void WindowLayoutPolicy::UpdateLimitRect(const sptr<WindowNode>& node, Rect& lim
void WindowLayoutPolicy::Reset()
{
}
float WindowLayoutPolicy::GetVirtualPixelRatio() const
{
auto display = DisplayManager::GetInstance().GetDisplayById(screenId_);
if (display == nullptr) {
WLOGFE("GetVirtualPixel fail. Get display fail. displayId:%{public}" PRIu64", use Default vpr:1.0", screenId_);
return 1.0; // Use DefaultVPR 1.0
}
float virtualPixelRatio = display->GetVirtualPixelRatio();
WLOGFI("GetVirtualPixel success. displayId:%{public}" PRIu64", vpr:%{public}f", screenId_, virtualPixelRatio);
return virtualPixelRatio;
}
}
}
+21 -12
View File
@@ -17,6 +17,7 @@
#include "window_helper.h"
#include "window_inner_manager.h"
#include "window_manager_hilog.h"
#include "wm_common_inner.h"
#include "wm_trace.h"
namespace OHOS {
@@ -130,19 +131,23 @@ static bool IsLayoutChanged(const Rect& l, const Rect& r)
void WindowLayoutPolicyCascade::LimitMoveBounds(Rect& rect)
{
float virtualPixelRatio = GetVirtualPixelRatio();
uint32_t minHorizontalSplitW = static_cast<uint32_t>(MIN_HORIZONTAL_SPLIT_WIDTH * virtualPixelRatio);
uint32_t minVerticalSplitH = static_cast<uint32_t>(MIN_VERTICAL_SPLIT_HEIGHT * virtualPixelRatio);
if (rect.width_ < rect.height_) {
if (rect.posX_ < (limitRect_.posX_ + static_cast<int32_t>(MIN_HORIZONTAL_SPLIT_WIDTH))) {
rect.posX_ = limitRect_.posX_ + static_cast<int32_t>(MIN_HORIZONTAL_SPLIT_WIDTH);
if (rect.posX_ < (limitRect_.posX_ + static_cast<int32_t>(minHorizontalSplitW))) {
rect.posX_ = limitRect_.posX_ + static_cast<int32_t>(minHorizontalSplitW);
} else if (rect.posX_ >
(limitRect_.posX_ + limitRect_.width_ - static_cast<int32_t>(MIN_HORIZONTAL_SPLIT_WIDTH))) {
rect.posX_ = limitRect_.posX_ + static_cast<int32_t>(limitRect_.width_ - MIN_HORIZONTAL_SPLIT_WIDTH);
(limitRect_.posX_ + limitRect_.width_ - static_cast<int32_t>(minHorizontalSplitW))) {
rect.posX_ = limitRect_.posX_ + static_cast<int32_t>(limitRect_.width_ - minHorizontalSplitW);
}
} else {
if (rect.posY_ < (limitRect_.posY_ + static_cast<int32_t>(MIN_VERTICAL_SPLIT_HEIGHT))) {
rect.posY_ = limitRect_.posY_ + static_cast<int32_t>(MIN_VERTICAL_SPLIT_HEIGHT);
if (rect.posY_ < (limitRect_.posY_ + static_cast<int32_t>(minVerticalSplitH))) {
rect.posY_ = limitRect_.posY_ + static_cast<int32_t>(minVerticalSplitH);
} else if (rect.posY_ >
(limitRect_.posY_ + static_cast<int32_t>(limitRect_.height_ - MIN_VERTICAL_SPLIT_HEIGHT))) {
rect.posY_ = limitRect_.posY_ + static_cast<int32_t>(limitRect_.height_ - MIN_VERTICAL_SPLIT_HEIGHT);
(limitRect_.posY_ + static_cast<int32_t>(limitRect_.height_ - minVerticalSplitH))) {
rect.posY_ = limitRect_.posY_ + static_cast<int32_t>(limitRect_.height_ - minVerticalSplitH);
}
}
}
@@ -215,6 +220,7 @@ void WindowLayoutPolicyCascade::UpdateLayoutRect(sptr<WindowNode>& node)
}
node->SetLayoutRect(winRect);
CalcAndSetNodeHotZone(winRect, node);
if (IsLayoutChanged(lastRect, winRect)) {
node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason());
node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_);
@@ -265,12 +271,15 @@ void WindowLayoutPolicyCascade::UpdateSplitLimitRect(const Rect& limitRect, Rect
void WindowLayoutPolicyCascade::InitSplitRects()
{
float virtualPixelRatio = GetVirtualPixelRatio();
uint32_t dividerWidth = static_cast<uint32_t>(DIVIDER_WIDTH * virtualPixelRatio);
if (!IsVertical()) {
dividerRect_ = { static_cast<uint32_t>((displayRect_.width_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), 0,
DIVIDER_WIDTH, displayRect_.height_ };
dividerRect_ = { static_cast<uint32_t>((displayRect_.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO), 0,
dividerWidth, displayRect_.height_ };
} else {
dividerRect_ = { 0, static_cast<uint32_t>((displayRect_.height_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO),
displayRect_.width_, DIVIDER_WIDTH };
dividerRect_ = { 0, static_cast<uint32_t>((displayRect_.height_ - dividerWidth) * DEFAULT_SPLIT_RATIO),
displayRect_.width_, dividerWidth };
}
WLOGFI("init dividerRect :[%{public}d, %{public}d, %{public}u, %{public}u]",
dividerRect_.posX_, dividerRect_.posY_, dividerRect_.width_, dividerRect_.height_);
@@ -99,6 +99,7 @@ void WindowLayoutPolicyTile::LayoutForegroundNodeQueue()
Rect lastRect = node->GetLayoutRect();
Rect winRect = node->GetWindowProperty()->GetWindowRect();
node->SetLayoutRect(winRect);
CalcAndSetNodeHotZone(winRect, node);
if (!(lastRect == winRect)) {
node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason());
node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_);
@@ -204,6 +205,7 @@ void WindowLayoutPolicyTile::UpdateLayoutRect(sptr<WindowNode>& node)
}
LimitWindowSize(node, displayRect, winRect);
node->SetLayoutRect(winRect);
CalcAndSetNodeHotZone(winRect, node);
if (!(lastRect == winRect)) {
node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason());
node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_);
+6 -17
View File
@@ -32,6 +32,11 @@ void WindowNode::SetLayoutRect(const Rect& rect)
layoutRect_ = rect;
}
void WindowNode::SetHotZoneRect(const Rect& rect)
{
hotZoneRect_ = rect;
}
void WindowNode::SetWindowRect(const Rect& rect)
{
property_->SetWindowRect(rect);
@@ -128,23 +133,7 @@ const Rect& WindowNode::GetLayoutRect() const
Rect WindowNode::GetHotZoneRect() const
{
Rect rect = layoutRect_;
if (GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
const int32_t divHotZone = 20;
if (rect.width_ < rect.height_) {
rect.posX_ -= divHotZone;
rect.width_ += (divHotZone + divHotZone);
} else {
rect.posY_ -= divHotZone;
rect.height_ += (divHotZone + divHotZone);
}
} else if (WindowHelper::IsMainFloatingWindow(GetWindowType(), GetWindowMode())) {
rect.posX_ -= HOTZONE;
rect.posY_ -= HOTZONE;
rect.width_ += (HOTZONE + HOTZONE);
rect.height_ += (HOTZONE + HOTZONE);
}
return rect;
return hotZoneRect_;
}
WindowType WindowNode::GetWindowType() const
+6
View File
@@ -29,6 +29,7 @@
#include "window_manager_agent_controller.h"
#include "window_manager_hilog.h"
#include "wm_common.h"
#include "wm_common_inner.h"
#include "wm_trace.h"
namespace OHOS {
@@ -1061,6 +1062,11 @@ sptr<WindowNode> WindowNodeContainer::GetAboveAppWindowNode() const
return aboveAppWindowNode_;
}
float WindowNodeContainer::GetVirtualPixelRatio() const
{
return layoutPolicy_->GetVirtualPixelRatio();
}
namespace {
const char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_animation";
}
+6
View File
@@ -477,5 +477,11 @@ void WindowRoot::NotifyDisplayDestory(DisplayId expandDisplayId)
defaultDisplaycontainer->MoveWindowNode(expandDisplaycontainer);
NotifyDisplayRemoved(expandDisplayId);
}
float WindowRoot::GetVirtualPixelRatio(DisplayId displayId) const
{
auto container = const_cast<WindowRoot*>(this)->GetOrCreateWindowNodeContainer(displayId);
return container->GetVirtualPixelRatio();
}
}
}