mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-22 21:16:40 -04:00
limit floating window size and position
Signed-off-by: l00574490 <liuqi149@huawei.com> Change-Id: I9549cc12313ddab148d4ceb3104bff0d33a42138
This commit is contained in:
@@ -85,12 +85,13 @@ 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 GetFixedWindowRectByLimitSize(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;
|
||||
// fix minimum size
|
||||
if (isVertical) {
|
||||
dstRect.width_ = std::max(minVerticalFloatingW, oriDstRect.width_);
|
||||
dstRect.height_ = std::max(minVerticalFloatingH, oriDstRect.height_);
|
||||
@@ -99,6 +100,10 @@ public:
|
||||
dstRect.height_ = std::max(minVerticalFloatingW, oriDstRect.height_);
|
||||
}
|
||||
|
||||
// fix maximum size
|
||||
dstRect.width_ = std::min(static_cast<uint32_t>(MAX_FLOATING_SIZE * virtualPixelRatio), dstRect.width_);
|
||||
dstRect.height_ = std::min(static_cast<uint32_t>(MAX_FLOATING_SIZE * virtualPixelRatio), dstRect.height_);
|
||||
|
||||
// limit position by fixed width or height
|
||||
if (oriDstRect.posX_ != lastRect.posX_) {
|
||||
dstRect.posX_ = oriDstRect.posX_ + static_cast<int32_t>(oriDstRect.width_) -
|
||||
@@ -111,6 +116,38 @@ public:
|
||||
return dstRect;
|
||||
}
|
||||
|
||||
static Rect GetFixedWindowRectByLimitPosition(const Rect& oriDstRect, const Rect& lastRect,
|
||||
float virtualPixelRatio, const Rect& displayLimitRect)
|
||||
{
|
||||
Rect dstRect = oriDstRect;
|
||||
uint32_t windowTitleBarH = static_cast<uint32_t>(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio);
|
||||
// minimum (x + width)
|
||||
if (dstRect.posX_ < (displayLimitRect.posX_ + static_cast<int32_t>(windowTitleBarH - oriDstRect.width_))) {
|
||||
if (oriDstRect.width_ != lastRect.width_) {
|
||||
dstRect.width_ = static_cast<uint32_t>(displayLimitRect.posX_ - oriDstRect.posX_) + windowTitleBarH;
|
||||
}
|
||||
}
|
||||
// maximum position x
|
||||
if (dstRect.posX_ > (displayLimitRect.posX_ +
|
||||
static_cast<int32_t>(displayLimitRect.width_ - windowTitleBarH))) {
|
||||
dstRect.posX_ = displayLimitRect.posX_ + static_cast<int32_t>(displayLimitRect.width_ - windowTitleBarH);
|
||||
if (oriDstRect.width_ != lastRect.width_) {
|
||||
dstRect.width_ = lastRect.width_;
|
||||
}
|
||||
}
|
||||
// minimum position y
|
||||
dstRect.posY_ = std::max(displayLimitRect.posY_, oriDstRect.posY_);
|
||||
// maximum position y
|
||||
if (dstRect.posY_ > (displayLimitRect.posY_ +
|
||||
static_cast<int32_t>(displayLimitRect.height_ - windowTitleBarH))) {
|
||||
dstRect.posY_ = displayLimitRect.posY_ + static_cast<int32_t>(displayLimitRect.height_ - windowTitleBarH);
|
||||
if (oriDstRect.height_ != lastRect.height_) {
|
||||
dstRect.height_ = lastRect.height_;
|
||||
}
|
||||
}
|
||||
return dstRect;
|
||||
}
|
||||
|
||||
static bool IsPointInTargetRect(int32_t pointPosX, int32_t pointPosY, const Rect& targetRect)
|
||||
{
|
||||
if ((pointPosX > targetRect.posX_) &&
|
||||
|
||||
@@ -66,6 +66,7 @@ namespace {
|
||||
constexpr uint32_t MIN_VERTICAL_FLOATING_HEIGHT = 320;
|
||||
constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 426;
|
||||
constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 426;
|
||||
constexpr uint32_t MAX_FLOATING_SIZE = 2560;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ void WindowMoveDragTest::CalExpectRects()
|
||||
}
|
||||
}
|
||||
bool isVertical = (utils::displayRect_.width_ < utils::displayRect_.height_) ? true : false;
|
||||
expectRect_ = WindowHelper::GetFixedWindowRectByMinRect(oriRect, startPointRect_, isVertical, virtualPixelRatio_);
|
||||
expectRect_ = WindowHelper::GetFixedWindowRectByLimitSize(oriRect, startPointRect_, isVertical, virtualPixelRatio_);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
virtual void UpdateLayoutRect(sptr<WindowNode>& node) = 0;
|
||||
void UpdateDefaultFoatingRect();
|
||||
float GetVirtualPixelRatio() const;
|
||||
Rect GetDisplayLimitRect() const;
|
||||
|
||||
protected:
|
||||
const Rect& displayRect_;
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
uint64_t GetScreenId() const;
|
||||
DisplayId GetDisplayId() const;
|
||||
Rect GetDisplayRect() const;
|
||||
Rect GetDisplayLimitRect() const;
|
||||
std::unordered_map<WindowType, SystemBarProperty> GetExpectImmersiveProperty() const;
|
||||
void UpdateWindowStatus(const sptr<WindowNode>& windowId, WindowUpdateType type) const;
|
||||
void UpdateDisplayRect(uint32_t width, uint32_t height);
|
||||
|
||||
@@ -66,6 +66,7 @@ public:
|
||||
void FocusFaultDetection() const;
|
||||
WMError DumpWindowTree(std::vector<std::string> &windowTreeInfos, WindowDumpType type);
|
||||
float GetVirtualPixelRatio(DisplayId displayId) const;
|
||||
Rect GetDisplayLimitRect(DisplayId displayId) const;
|
||||
|
||||
private:
|
||||
void OnRemoteDied(const sptr<IRemoteObject>& remoteObject);
|
||||
|
||||
@@ -148,8 +148,11 @@ WMError WindowController::ResizeRect(uint32_t windowId, const Rect& rect, Window
|
||||
if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) {
|
||||
// fix rect in case of moving window when dragging
|
||||
float virtualPixelRatio = windowRoot_->GetVirtualPixelRatio(node->GetDisplayId());
|
||||
newRect = WindowHelper::GetFixedWindowRectByMinRect(rect, property->GetWindowRect(),
|
||||
Rect displayLimitRect = windowRoot_->GetDisplayLimitRect(node->GetDisplayId());
|
||||
newRect = WindowHelper::GetFixedWindowRectByLimitSize(rect, lastRect,
|
||||
windowRoot_->isVerticalDisplay(node), virtualPixelRatio);
|
||||
newRect = WindowHelper::GetFixedWindowRectByLimitPosition(newRect, lastRect,
|
||||
virtualPixelRatio, displayLimitRect);
|
||||
} else {
|
||||
newRect = rect;
|
||||
}
|
||||
|
||||
@@ -269,19 +269,33 @@ void WindowLayoutPolicy::LimitWindowSize(const sptr<WindowNode>& node, const Rec
|
||||
WindowType windowType = node->GetWindowType();
|
||||
WindowMode windowMode = node->GetWindowMode();
|
||||
bool isVertical = (displayRect.height_ > displayRect.width_) ? true : false;
|
||||
if ((windowMode == WindowMode::WINDOW_MODE_FLOATING) && !WindowHelper::IsSystemWindow(windowType)) {
|
||||
if (isVertical) {
|
||||
winRect.width_ = std::max(minVerticalFloatingW, winRect.width_);
|
||||
winRect.height_ = std::max(minVerticalFloatingH, winRect.height_);
|
||||
} else {
|
||||
winRect.width_ = std::max(minVerticalFloatingH, winRect.width_);
|
||||
winRect.height_ = std::max(minVerticalFloatingW, winRect.height_);
|
||||
|
||||
if (windowMode == WindowMode::WINDOW_MODE_FLOATING) {
|
||||
// limit minimum size of floating (not system type) window
|
||||
if (!WindowHelper::IsSystemWindow(windowType)) {
|
||||
if (isVertical) {
|
||||
winRect.width_ = std::max(minVerticalFloatingW, winRect.width_);
|
||||
winRect.height_ = std::max(minVerticalFloatingH, winRect.height_);
|
||||
} else {
|
||||
winRect.width_ = std::max(minVerticalFloatingH, winRect.width_);
|
||||
winRect.height_ = std::max(minVerticalFloatingW, winRect.height_);
|
||||
}
|
||||
}
|
||||
// limit maximum size of all floating window
|
||||
winRect.width_ = std::min(static_cast<uint32_t>(MAX_FLOATING_SIZE * virtualPixelRatio), winRect.width_);
|
||||
winRect.height_ = std::min(static_cast<uint32_t>(MAX_FLOATING_SIZE * virtualPixelRatio), winRect.height_);
|
||||
}
|
||||
|
||||
// limit position of the main floating window(window which support dragging)
|
||||
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_ - windowTitleBarH),
|
||||
winRect.posY_);
|
||||
|
||||
winRect.posX_ = std::max(limitRect_.posX_ + static_cast<int32_t>(windowTitleBarH - winRect.width_),
|
||||
winRect.posX_);
|
||||
winRect.posX_ = std::min(limitRect_.posX_ + static_cast<int32_t>(limitRect_.width_ - windowTitleBarH),
|
||||
winRect.posX_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,5 +374,10 @@ float WindowLayoutPolicy::GetVirtualPixelRatio() const
|
||||
WLOGFI("GetVirtualPixel success. displayId:%{public}" PRIu64", vpr:%{public}f", screenId_, virtualPixelRatio);
|
||||
return virtualPixelRatio;
|
||||
}
|
||||
|
||||
Rect WindowLayoutPolicy::GetDisplayLimitRect() const
|
||||
{
|
||||
return limitRect_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -700,6 +700,11 @@ Rect WindowNodeContainer::GetDisplayRect() const
|
||||
return displayRect_;
|
||||
}
|
||||
|
||||
Rect WindowNodeContainer::GetDisplayLimitRect() const
|
||||
{
|
||||
return layoutPolicy_->GetDisplayLimitRect();
|
||||
}
|
||||
|
||||
bool WindowNodeContainer::isVerticalDisplay() const
|
||||
{
|
||||
return displayRect_.width_ < displayRect_.height_;
|
||||
|
||||
@@ -599,5 +599,11 @@ float WindowRoot::GetVirtualPixelRatio(DisplayId displayId) const
|
||||
auto container = const_cast<WindowRoot*>(this)->GetOrCreateWindowNodeContainer(displayId);
|
||||
return container->GetVirtualPixelRatio();
|
||||
}
|
||||
|
||||
Rect WindowRoot::GetDisplayLimitRect(DisplayId displayId) const
|
||||
{
|
||||
auto container = const_cast<WindowRoot*>(this)->GetOrCreateWindowNodeContainer(displayId);
|
||||
return container->GetDisplayLimitRect();
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user