mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-19 17:08:11 -04:00
自由窗口默认Rect计算及最小值限制
Change-Id: I0a078d56e998a2f0c232f15d60574f718c62ccc5 Signed-off-by: huandong <huandong1@huawei.com>
This commit is contained in:
@@ -64,6 +64,11 @@ public:
|
||||
mode == WindowMode::WINDOW_MODE_PIP;
|
||||
}
|
||||
|
||||
static inline bool IsEmptyRect(const Rect& r)
|
||||
{
|
||||
return (r.posX_ == 0 && r.posY_ == 0 && r.width_ == 0 && r.height_ == 0);
|
||||
}
|
||||
|
||||
WindowHelper() = default;
|
||||
~WindowHelper() = default;
|
||||
};
|
||||
|
||||
@@ -213,11 +213,6 @@ WMError WindowImpl::SetUIContent(const std::string& contentInfo,
|
||||
WLOGFE("fail to SetUIContent id: %{public}d", property_->GetWindowId());
|
||||
return WMError::WM_ERROR_NULLPTR;
|
||||
}
|
||||
if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
|
||||
property_->SetDecorEnable(true);
|
||||
} else {
|
||||
property_->SetDecorEnable(false);
|
||||
}
|
||||
if (isdistributed) {
|
||||
uiContent_->Restore(this, contentInfo, storage);
|
||||
} else {
|
||||
@@ -281,6 +276,12 @@ WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr<
|
||||
}
|
||||
}
|
||||
|
||||
if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
|
||||
property_->SetDecorEnable(true);
|
||||
} else {
|
||||
property_->SetDecorEnable(false);
|
||||
}
|
||||
|
||||
sptr<WindowImpl> window(this);
|
||||
sptr<IWindow> windowAgent(new WindowAgent(window));
|
||||
uint32_t windowId = 0;
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
void UpdateWindowNode(sptr<WindowNode>& node);
|
||||
void UpdateLayoutRect(sptr<WindowNode>& node);
|
||||
Rect GetDependDisplayRects() const;
|
||||
void UpdateDefaultFoatingRect();
|
||||
|
||||
private:
|
||||
LayoutDependRects dependRects;
|
||||
@@ -78,6 +79,9 @@ private:
|
||||
Rect& GetLimitRect(const WindowMode mode);
|
||||
Rect& GetDisplayRect(const WindowMode mode);
|
||||
void LimitMoveBounds(Rect& rect);
|
||||
void LimitWindowSize(const sptr<WindowNode>& node, const Rect& displayRect, Rect& winRect);
|
||||
void SetRectForFloating(const sptr<WindowNode>& node);
|
||||
Rect defaultFloatingRect_ = { 0, 0, 0, 0 };
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
|
||||
void SetDisplayId(int32_t displayId);
|
||||
void SetLayoutRect(const Rect& rect);
|
||||
void SetWindowRect(const Rect& rect);
|
||||
void SetWindowProperty(const sptr<WindowProperty>& property);
|
||||
void SetSystemBarProperty(WindowType type, const SystemBarProperty& property);
|
||||
void SetWindowMode(WindowMode mode);
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowLayoutPolicy"};
|
||||
constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 48;
|
||||
constexpr uint32_t WINDOW_FRAME_WIDTH = 4;
|
||||
constexpr uint32_t MIN_VERTICAL_FLOATING_WIDTH = 360;
|
||||
constexpr uint32_t MIN_VERTICAL_FLOATING_HEIGHT = 480;
|
||||
}
|
||||
|
||||
WindowLayoutPolicy::WindowLayoutPolicy(const sptr<WindowNode>& belowAppNode,
|
||||
@@ -42,6 +44,7 @@ void WindowLayoutPolicy::UpdateDisplayInfo(const Rect& primaryRect,
|
||||
dependRects.secRect_ = secondaryRect;
|
||||
dependRects.fullRect_ = displayRect;
|
||||
InitLimitRects();
|
||||
UpdateDefaultFoatingRect();
|
||||
}
|
||||
|
||||
void WindowLayoutPolicy::LayoutWindowTree()
|
||||
@@ -78,9 +81,48 @@ void WindowLayoutPolicy::LayoutWindowNode(sptr<WindowNode>& node)
|
||||
void WindowLayoutPolicy::AddWindowNode(sptr<WindowNode>& node)
|
||||
{
|
||||
WM_FUNCTION_TRACE();
|
||||
if (WindowHelper::IsEmptyRect(node->GetWindowProperty()->GetWindowRect())) {
|
||||
SetRectForFloating(node);
|
||||
}
|
||||
UpdateWindowNode(node); // currently, update and add do the same process
|
||||
}
|
||||
|
||||
void WindowLayoutPolicy::UpdateDefaultFoatingRect()
|
||||
{
|
||||
constexpr uint32_t half = 2;
|
||||
constexpr float ratio = 0.75; // 0.75: default height/width ratio
|
||||
|
||||
// calculate default H and w
|
||||
Rect displayRect = GetDisplayRect(WindowMode::WINDOW_MODE_FLOATING);
|
||||
uint32_t defaultW = static_cast<uint32_t>(displayRect.width_ * ratio);
|
||||
uint32_t defaultH = static_cast<uint32_t>(displayRect.height_ * ratio);
|
||||
|
||||
// calculate default x and y
|
||||
Rect limitRect = GetLimitRect(WindowMode::WINDOW_MODE_FLOATING);
|
||||
Rect resRect = {0, 0, defaultW, defaultH};
|
||||
if (defaultW <= limitRect.width_ && defaultH <= limitRect.height_) {
|
||||
int32_t centerPosX = limitRect.posX_ + static_cast<int32_t>(limitRect.width_ / half);
|
||||
resRect.posX_ = centerPosX - static_cast<int32_t>(defaultW / half);
|
||||
|
||||
int32_t centerPosY = limitRect.posY_ + static_cast<int32_t>(limitRect.height_ / half);
|
||||
resRect.posY_ = centerPosY - static_cast<int32_t>(defaultH / half);
|
||||
}
|
||||
|
||||
defaultFloatingRect_ = resRect;
|
||||
}
|
||||
|
||||
void WindowLayoutPolicy::SetRectForFloating(const sptr<WindowNode>& node)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
node->SetWindowRect(rect);
|
||||
}
|
||||
|
||||
void WindowLayoutPolicy::RemoveWindowNode(sptr<WindowNode>& node)
|
||||
{
|
||||
WM_FUNCTION_TRACE();
|
||||
@@ -158,6 +200,7 @@ void WindowLayoutPolicy::UpdateLayoutRect(sptr<WindowNode>& node)
|
||||
auto type = node->GetWindowType();
|
||||
auto mode = node->GetWindowMode();
|
||||
auto flags = node->GetWindowFlags();
|
||||
auto decorEnbale = node->GetWindowProperty()->GetDecorEnable();
|
||||
bool needAvoid = (flags & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_NEED_AVOID));
|
||||
bool parentLimit = (flags & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT));
|
||||
bool subWindow = WindowHelper::IsSubWindow(type);
|
||||
@@ -168,9 +211,9 @@ void WindowLayoutPolicy::UpdateLayoutRect(sptr<WindowNode>& node)
|
||||
Rect limitRect = displayRect;
|
||||
Rect winRect = node->GetWindowProperty()->GetWindowRect();
|
||||
|
||||
WLOGFI("Id:%{public}d, avoid:%{public}d parLimit:%{public}d floating:%{public}d, sub:%{public}d," \
|
||||
"type:%{public}d, requestRect:[%{public}d, %{public}d, %{public}d, %{public}d]",
|
||||
node->GetWindowId(), needAvoid, parentLimit, floatingWindow, subWindow,
|
||||
WLOGFI("Id:%{public}d, avoid:%{public}d parLimit:%{public}d floating:%{public}d, sub:%{public}d, " \
|
||||
"deco:%{public}d, type:%{public}d, requestRect:[%{public}d, %{public}d, %{public}d, %{public}d]",
|
||||
node->GetWindowId(), needAvoid, parentLimit, floatingWindow, subWindow, decorEnbale,
|
||||
static_cast<uint32_t>(type), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_);
|
||||
if (needAvoid) {
|
||||
limitRect = GetLimitRect(mode);
|
||||
@@ -188,10 +231,7 @@ void WindowLayoutPolicy::UpdateLayoutRect(sptr<WindowNode>& node)
|
||||
}
|
||||
}
|
||||
// Limit window to the maximum window size
|
||||
winRect.width_ = std::min(displayRect.width_, winRect.width_);
|
||||
winRect.height_ = std::min(displayRect.height_, winRect.height_);
|
||||
winRect.width_ = std::max(1u, winRect.width_);
|
||||
winRect.height_ = std::max(1u, winRect.height_);
|
||||
LimitWindowSize(node, displayRect, winRect);
|
||||
|
||||
if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
|
||||
LimitMoveBounds(winRect);
|
||||
@@ -204,6 +244,28 @@ void WindowLayoutPolicy::UpdateLayoutRect(sptr<WindowNode>& node)
|
||||
}
|
||||
}
|
||||
|
||||
void WindowLayoutPolicy::LimitWindowSize(const sptr<WindowNode>& node, const Rect& displayRect, Rect& winRect)
|
||||
{
|
||||
bool floatingWindow = (node->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING);
|
||||
|
||||
winRect.width_ = std::min(displayRect.width_, winRect.width_);
|
||||
winRect.height_ = std::min(displayRect.height_, winRect.height_);
|
||||
bool isVertical = (displayRect.height_ > displayRect.width_) ? true : false;
|
||||
WindowType windowType = node->GetWindowProperty()->GetWindowType();
|
||||
if (floatingWindow && !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_);
|
||||
} else {
|
||||
winRect.width_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, winRect.width_);
|
||||
winRect.height_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, winRect.height_);
|
||||
}
|
||||
} else {
|
||||
winRect.width_ = std::max(1u, winRect.width_);
|
||||
winRect.height_ = std::max(1u, winRect.height_);
|
||||
}
|
||||
}
|
||||
|
||||
AvoidPosType WindowLayoutPolicy::GetAvoidPosType(const Rect& rect)
|
||||
{
|
||||
if (rect.width_ >= rect.height_) {
|
||||
|
||||
@@ -28,6 +28,11 @@ void WindowNode::SetLayoutRect(const Rect& rect)
|
||||
layoutRect_ = rect;
|
||||
}
|
||||
|
||||
void WindowNode::SetWindowRect(const Rect& rect)
|
||||
{
|
||||
property_->SetWindowRect(rect);
|
||||
}
|
||||
|
||||
void WindowNode::SetWindowProperty(const sptr<WindowProperty>& property)
|
||||
{
|
||||
property_ = property;
|
||||
|
||||
@@ -602,6 +602,7 @@ std::vector<Rect> WindowNodeContainer::GetAvoidAreaByType(AvoidAreaType avoidAre
|
||||
|
||||
void WindowNodeContainer::OnAvoidAreaChange(const std::vector<Rect>& avoidArea)
|
||||
{
|
||||
layoutPolicy_->UpdateDefaultFoatingRect();
|
||||
for (auto& node : appWindowNode_->children_) {
|
||||
if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && node->GetWindowToken() != nullptr) {
|
||||
// notify client
|
||||
|
||||
Reference in New Issue
Block a user