Review修改, Avoidarea异常用例补充,用例异常修复

Signed-off-by: huandong <huandong1@huawei.com>
Change-Id: I807dfafcb12b3cf727fb96d0fe5022b5875f2759
This commit is contained in:
huandong
2022-03-03 20:32:36 +08:00
parent b8060c9fc0
commit 4433f2e067
13 changed files with 195 additions and 169 deletions
+19
View File
@@ -128,6 +128,25 @@ public:
(reason < WindowUpdateReason::NEED_SWITCH_CASCADE_END);
}
static AvoidPosType GetAvoidPosType(const Rect& rect, uint32_t displayWidth, uint32_t displayHeight)
{
if (rect.width_ == displayWidth) {
if (rect.posY_ == 0) {
return AvoidPosType::AVOID_POS_TOP;
} else {
return AvoidPosType::AVOID_POS_BOTTOM;
}
} else if (rect.height_ == displayHeight) {
if (rect.posX_ == 0) {
return AvoidPosType::AVOID_POS_LEFT;
} else {
return AvoidPosType::AVOID_POS_RIGHT;
}
}
return AvoidPosType::AVOID_POS_UNKNOWN;
}
WindowHelper() = default;
~WindowHelper() = default;
};
+9
View File
@@ -46,6 +46,15 @@ enum class WindowUpdateReason : uint32_t {
NEED_SWITCH_CASCADE_END,
UPDATE_OTHER_PROPS,
};
enum class AvoidPosType : uint32_t {
AVOID_POS_LEFT,
AVOID_POS_TOP,
AVOID_POS_RIGHT,
AVOID_POS_BOTTOM,
AVOID_POS_UNKNOWN
};
namespace {
constexpr float DEFAULT_SPLIT_RATIO = 0.5;
constexpr uint32_t DIVIDER_WIDTH = 8;
@@ -363,6 +363,7 @@ HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest01, Function | MediumTest |
ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.rightRect));
ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.topRect));
ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.bottomRect));
ASSERT_EQ(WMError::WM_OK, win->Hide());
}
/**
@@ -388,6 +389,8 @@ HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest02, Function | MediumTest |
WMError ret = win->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, avoidarea);
ASSERT_EQ(WMError::WM_OK, ret);
ASSERT_TRUE(utils::RectEqualTo(left, avoidarea.leftRect));
ASSERT_EQ(WMError::WM_OK, left->Hide());
ASSERT_EQ(WMError::WM_OK, win->Hide());
}
/**
@@ -414,6 +417,8 @@ HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest03, Function | MediumTest |
WMError ret = win->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, avoidarea);
ASSERT_EQ(WMError::WM_OK, ret);
ASSERT_TRUE(utils::RectEqualTo(top, avoidarea.topRect));
ASSERT_EQ(WMError::WM_OK, top->Hide());
ASSERT_EQ(WMError::WM_OK, win->Hide());
}
/**
@@ -456,6 +461,8 @@ HWTEST_F(WindowImmersiveTest, OnAvoidAreaChangedTest01, Function | MediumTest |
ASSERT_TRUE(utils::RectEqualToRect(bigTopRect, avoidArea2[1]));
window->UnregisterAvoidAreaChangeListener(thisListener);
ASSERT_EQ(WMError::WM_OK, top->Hide());
ASSERT_EQ(WMError::WM_OK, window->Hide());
}
/**
@@ -494,6 +501,7 @@ HWTEST_F(WindowImmersiveTest, OnAvoidAreaChangedTest02, Function | MediumTest |
ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidArea2[0])); // 0: left Rect
window->UnregisterAvoidAreaChangeListener(thisListener);
ASSERT_EQ(WMError::WM_OK, window->Hide());
}
}
} // namespace Rosen
+29
View File
@@ -90,6 +90,35 @@ void WindowLayoutTest::TearDown()
}
namespace {
/**
* @tc.name: LayoutWindow01
* @tc.desc: One FLOATING APP Window with on custom rect
* @tc.type: FUNC
*/
HWTEST_F(WindowLayoutTest, LayoutWindow01, Function | MediumTest | Level3)
{
WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE, displayId_);
WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE, displayId_);
WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE, displayId_);
WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE, displayId_);
utils::TestWindowInfo info = {
.name = "main",
.rect = {0, 0, 0, 0},
.type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
.mode = WindowMode::WINDOW_MODE_FLOATING,
.needAvoid = true,
.parentLimit = false,
.parentName = "",
};
const sptr<Window>& window = utils::CreateTestWindow(info);
activeWindows_.push_back(window);
Rect expect = utils::GetDefaultFoatingRect(window);
ASSERT_EQ(WMError::WM_OK, window->Show());
ASSERT_TRUE(utils::RectEqualTo(window, expect));
ASSERT_EQ(WMError::WM_OK, window->Hide());
}
/**
* @tc.name: LayoutWindow02
* @tc.desc: One FLOATING APP Window
+9 -13
View File
@@ -15,6 +15,7 @@
#include "window_test_utils.h"
#include <ability_context.h>
#include "window_helper.h"
#include "wm_common_inner.h"
namespace OHOS {
namespace Rosen {
@@ -254,20 +255,15 @@ bool WindowTestUtils::RectEqualToRect(const Rect& l, const Rect& r)
AvoidPosType WindowTestUtils::GetAvoidPosType(const Rect& rect)
{
if (rect.width_ >= rect.height_) {
if (rect.posY_ == 0) {
return AvoidPosType::AVOID_POS_TOP;
} else {
return AvoidPosType::AVOID_POS_BOTTOM;
}
} else {
if (rect.posX_ == 0) {
return AvoidPosType::AVOID_POS_LEFT;
} else {
return AvoidPosType::AVOID_POS_RIGHT;
}
auto display = DisplayManager::GetInstance().GetDisplayById(0);
if (display == nullptr) {
WLOGFE("GetAvoidPosType fail. Get display fail. displayId: 0");
return AvoidPosType::AVOID_POS_UNKNOWN;
}
return AvoidPosType::AVOID_POS_UNKNOWN;
uint32_t displayWidth = display->GetWidth();
uint32_t displayHeight = display->GetHeight();
return WindowHelper::GetAvoidPosType(rect, displayWidth, displayHeight);
}
bool WindowTestUtils::InitSplitRects()
+43 -37
View File
@@ -90,7 +90,7 @@ namespace {
*/
HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode01, Function | SmallTest | Level2)
{
auto avoidAreaController = new AvoidAreaController(nullptr);
auto avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node = new WindowNode();
sptr<WindowProperty> property = new WindowProperty();
@@ -108,7 +108,7 @@ HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode01, Function | SmallTest | Leve
*/
HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode02, Function | SmallTest | Level2)
{
auto avoidAreaController = new AvoidAreaController(nullptr);
auto avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node = new WindowNode();
sptr<WindowProperty> property = new WindowProperty();
@@ -125,7 +125,7 @@ HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode02, Function | SmallTest | Leve
*/
HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode03, Function | SmallTest | Level2)
{
auto avoidAreaController = new AvoidAreaController(nullptr);
auto avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node = new WindowNode();
sptr<WindowProperty> property = new WindowProperty();
@@ -142,7 +142,7 @@ HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode03, Function | SmallTest | Leve
*/
HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode04, Function | SmallTest | Level2)
{
auto avoidAreaController = new AvoidAreaController(nullptr);
auto avoidAreaController = new AvoidAreaController(0, nullptr);
ASSERT_EQ(false, avoidAreaController->IsAvoidAreaNode(nullptr));
}
@@ -162,8 +162,8 @@ HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode01, Function | SmallTest | Lev
node->SetWindowProperty(property);
node->SetLayoutRect(topAvoidRect_);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node));
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_ADD));
}
/**
@@ -173,7 +173,7 @@ HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode01, Function | SmallTest | Lev
*/
HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode02, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node1 = new WindowNode();
sptr<WindowProperty> property1 = new WindowProperty();
@@ -182,7 +182,7 @@ HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode02, Function | SmallTest | Lev
property1->SetWindowRect(topAvoidRect_);
node1->SetWindowProperty(property1);
node1->SetLayoutRect(topAvoidRect_);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node1));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node1, AvoidControlType::AVOID_NODE_ADD));
sptr<WindowNode> node2 = new WindowNode();
sptr<WindowProperty> property2 = new WindowProperty();
@@ -190,7 +190,8 @@ HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode02, Function | SmallTest | Lev
property2->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
node2->SetWindowProperty(property2);
node2->SetLayoutRect(topAvoidRect_);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->AddAvoidAreaNode(node2));
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM,
avoidAreaController->AvoidControl(node2, AvoidControlType::AVOID_NODE_ADD));
}
/**
@@ -200,7 +201,7 @@ HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode02, Function | SmallTest | Lev
*/
HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode03, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node1 = new WindowNode();
sptr<WindowProperty> property1 = new WindowProperty();
@@ -208,7 +209,7 @@ HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode03, Function | SmallTest | Lev
property1->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
node1->SetWindowProperty(property1);
node1->SetLayoutRect(topAvoidRect_);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node1));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node1, AvoidControlType::AVOID_NODE_ADD));
sptr<WindowNode> node2 = new WindowNode();
sptr<WindowProperty> property2 = new WindowProperty();
@@ -216,7 +217,7 @@ HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode03, Function | SmallTest | Lev
property2->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
node2->SetWindowProperty(property2);
node2->SetLayoutRect(leftAvoidRect_);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node2));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node2, AvoidControlType::AVOID_NODE_ADD));
}
/**
@@ -226,8 +227,9 @@ HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode03, Function | SmallTest | Lev
*/
HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode04, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->AddAvoidAreaNode(nullptr));
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM,
avoidAreaController->AvoidControl(nullptr, AvoidControlType::AVOID_NODE_ADD));
}
/**
@@ -237,7 +239,7 @@ HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode04, Function | SmallTest | Lev
*/
HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode01, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node1 = new WindowNode();
sptr<WindowProperty> property1 = new WindowProperty();
@@ -245,9 +247,9 @@ HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode01, Function | SmallTest |
property1->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
node1->SetWindowProperty(property1);
node1->SetLayoutRect(leftAvoidRect_);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node1));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node1, AvoidControlType::AVOID_NODE_ADD));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->RemoveAvoidAreaNode(node1));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node1, AvoidControlType::AVOID_NODE_REMOVE));
}
/**
@@ -257,7 +259,7 @@ HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode01, Function | SmallTest |
*/
HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode02, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node = new WindowNode();
sptr<WindowProperty> property = new WindowProperty();
@@ -265,7 +267,8 @@ HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode02, Function | SmallTest |
property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
node->SetLayoutRect(topAvoidRect_);
node->SetWindowProperty(property);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->RemoveAvoidAreaNode(node));
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM,
avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_REMOVE));
}
/**
@@ -275,8 +278,9 @@ HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode02, Function | SmallTest |
*/
HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode03, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->RemoveAvoidAreaNode(nullptr));
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM,
avoidAreaController->AvoidControl(nullptr, AvoidControlType::AVOID_NODE_REMOVE));
}
/**
@@ -286,7 +290,7 @@ HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode03, Function | SmallTest |
*/
HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode01, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node = new WindowNode();
sptr<WindowProperty> property = new WindowProperty();
@@ -294,10 +298,10 @@ HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode01, Function | SmallTest |
property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
node->SetWindowProperty(property);
node->SetLayoutRect(topAvoidRect_);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_ADD));
property->SetWindowRect(leftAvoidRect_);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->UpdateAvoidAreaNode(node));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_UPDATE));
}
/**
@@ -307,7 +311,7 @@ HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode01, Function | SmallTest |
*/
HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode02, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node = new WindowNode();
sptr<WindowProperty> property = new WindowProperty();
@@ -316,7 +320,8 @@ HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode02, Function | SmallTest |
node->SetWindowProperty(property);
node->SetLayoutRect(topAvoidRect_);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->UpdateAvoidAreaNode(node));
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM,
avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_UPDATE));
}
/**
@@ -326,8 +331,9 @@ HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode02, Function | SmallTest |
*/
HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode03, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->UpdateAvoidAreaNode(nullptr));
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM,
avoidAreaController->AvoidControl(nullptr, AvoidControlType::AVOID_NODE_UPDATE));
}
/**
@@ -337,7 +343,7 @@ HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode03, Function | SmallTest |
*/
HWTEST_F(AvoidAreaControllerTest, GetAvoidArea01, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
std::vector<Rect> avoidArea = avoidAreaController->GetAvoidArea();
ASSERT_EQ(4u, static_cast<uint32_t>(avoidArea.size()));
@@ -354,7 +360,7 @@ HWTEST_F(AvoidAreaControllerTest, GetAvoidArea01, Function | SmallTest | Level2)
*/
HWTEST_F(AvoidAreaControllerTest, GetAvoidArea02, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node = new WindowNode();
sptr<WindowProperty> property = new WindowProperty();
@@ -362,7 +368,7 @@ HWTEST_F(AvoidAreaControllerTest, GetAvoidArea02, Function | SmallTest | Level2)
property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
node->SetWindowProperty(property);
node->SetLayoutRect(topAvoidRect_);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_ADD));
std::vector<Rect> avoidArea = avoidAreaController->GetAvoidArea();
ASSERT_EQ(4u, static_cast<uint32_t>(avoidArea.size()));
@@ -379,7 +385,7 @@ HWTEST_F(AvoidAreaControllerTest, GetAvoidArea02, Function | SmallTest | Level2)
*/
HWTEST_F(AvoidAreaControllerTest, GetAvoidArea03, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node = new WindowNode();
sptr<WindowProperty> property = new WindowProperty();
@@ -387,10 +393,10 @@ HWTEST_F(AvoidAreaControllerTest, GetAvoidArea03, Function | SmallTest | Level2)
property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
node->SetWindowProperty(property);
node->SetLayoutRect(topAvoidRect_);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_ADD));
node->SetLayoutRect(leftAvoidRect_);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->UpdateAvoidAreaNode(node));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_UPDATE));
std::vector<Rect> avoidArea = avoidAreaController->GetAvoidArea();
ASSERT_EQ(4u, static_cast<uint32_t>(avoidArea.size()));
@@ -407,7 +413,7 @@ HWTEST_F(AvoidAreaControllerTest, GetAvoidArea03, Function | SmallTest | Level2)
*/
HWTEST_F(AvoidAreaControllerTest, GetAvoidAreaByType01, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
std::vector<Rect> avoidArea = avoidAreaController->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT);
ASSERT_EQ(4u, static_cast<uint32_t>(avoidArea.size()));
@@ -424,7 +430,7 @@ HWTEST_F(AvoidAreaControllerTest, GetAvoidAreaByType01, Function | SmallTest | L
*/
HWTEST_F(AvoidAreaControllerTest, GetAvoidAreaByType02, Function | SmallTest | Level2)
{
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(nullptr);
sptr<AvoidAreaController> avoidAreaController = new AvoidAreaController(0, nullptr);
sptr<WindowNode> node = new WindowNode();
sptr<WindowProperty> property = new WindowProperty();
@@ -432,7 +438,7 @@ HWTEST_F(AvoidAreaControllerTest, GetAvoidAreaByType02, Function | SmallTest | L
property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
node->SetWindowProperty(property);
node->SetLayoutRect(topAvoidRect_);
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node));
ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_ADD));
std::vector<Rect> avoidArea = avoidAreaController->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM);
+11 -10
View File
@@ -23,37 +23,38 @@
#include "window_node.h"
#include "wm_common.h"
#include "wm_common_inner.h"
namespace OHOS {
namespace Rosen {
enum class AvoidPos : uint32_t {
AVOID_POS_LEFT,
AVOID_POS_TOP,
AVOID_POS_RIGHT,
AVOID_POS_BOTTOM,
AVOID_POS_UNKNOWN,
enum class AvoidControlType : uint32_t {
AVOID_NODE_ADD,
AVOID_NODE_UPDATE,
AVOID_NODE_REMOVE,
AVOID_NODE_UNKNOWN,
};
using UpdateAvoidAreaFunc = std::function<void (std::vector<Rect>& avoidArea)>;
class AvoidAreaController : public RefBase {
public:
AvoidAreaController(UpdateAvoidAreaFunc callback): updateAvoidAreaCallBack_(callback) {};
AvoidAreaController(DisplayId displayId, UpdateAvoidAreaFunc callback)
: displayId_(displayId), updateAvoidAreaCallBack_(callback) {};
~AvoidAreaController() = default;
WMError AddAvoidAreaNode(const sptr<WindowNode>& node);
WMError RemoveAvoidAreaNode(const sptr<WindowNode>& node);
WMError UpdateAvoidAreaNode(const sptr<WindowNode>& node);
WMError AvoidControl(const sptr<WindowNode>& node, AvoidControlType type);
bool IsAvoidAreaNode(const sptr<WindowNode>& node) const;
std::vector<Rect> GetAvoidArea() const;
std::vector<Rect> GetAvoidAreaByType(AvoidAreaType avoidAreaType) const;
private:
DisplayId displayId_ = 0;
std::map<uint32_t, sptr<WindowNode>> avoidNodes_; // key: windowId
UpdateAvoidAreaFunc updateAvoidAreaCallBack_;
void UseCallbackNotifyAvoidAreaChanged(std::vector<Rect>& avoidArea) const;
void DumpAvoidArea(const std::vector<Rect>& avoidArea) const;
AvoidPosType GetAvoidPosType(const Rect& rect) const;
};
}
}
-8
View File
@@ -25,14 +25,6 @@
namespace OHOS {
namespace Rosen {
enum class AvoidPosType : uint32_t {
AVOID_POS_TOP,
AVOID_POS_BOTTOM,
AVOID_POS_LEFT,
AVOID_POS_RIGHT,
AVOID_POS_UNKNOWN
};
class WindowLayoutPolicy : public RefBase {
public:
WindowLayoutPolicy() = delete;
+37 -74
View File
@@ -14,6 +14,7 @@
*/
#include "avoid_area_controller.h"
#include "display_manager_service_inner.h"
#include "window_helper.h"
#include "window_manager_hilog.h"
#include "wm_trace.h"
@@ -41,95 +42,57 @@ bool AvoidAreaController::IsAvoidAreaNode(const sptr<WindowNode>& node) const
return true;
}
static AvoidPos GetAvoidPosType(const Rect& rect)
AvoidPosType AvoidAreaController::GetAvoidPosType(const Rect& rect) const
{
if (rect.width_ >= rect.height_) {
if (rect.posY_ == 0) {
return AvoidPos::AVOID_POS_TOP;
} else {
return AvoidPos::AVOID_POS_BOTTOM;
}
} else {
if (rect.posX_ == 0) {
return AvoidPos::AVOID_POS_LEFT;
} else {
return AvoidPos::AVOID_POS_RIGHT;
}
auto display = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId_);
if (display == nullptr) {
WLOGFE("GetAvoidPosType fail. Get display fail. displayId:%{public}" PRIu64"", displayId_);
return AvoidPosType::AVOID_POS_UNKNOWN;
}
return AvoidPos::AVOID_POS_UNKNOWN;
uint32_t displayWidth = display->GetWidth();
uint32_t displayHeight = display->GetHeight();
return WindowHelper::GetAvoidPosType(rect, displayWidth, displayHeight);
}
WMError AvoidAreaController::AddAvoidAreaNode(const sptr<WindowNode>& node)
WMError AvoidAreaController::AvoidControl(const sptr<WindowNode>& node, AvoidControlType type)
{
WM_FUNCTION_TRACE();
if (!IsAvoidAreaNode(node)) {
WLOGFE("AddAvoidAreaNode check param Failed.");
WLOGFE("AvoidControl check param Failed. Type: %{public}u", type);
return WMError::WM_ERROR_INVALID_PARAM;
}
uint32_t windowId = node->GetWindowId();
auto iter = avoidNodes_.find(windowId);
if (iter != avoidNodes_.end()) {
WLOGFE("windowId: %{public}d is added.AddAvoidAreaNode Failed", windowId);
// do not add a exist node(the same id)
if (type == AvoidControlType::AVOID_NODE_ADD && iter != avoidNodes_.end()) {
WLOGFE("WinId:%{public}d is added. AvoidControl Add Failed. Type: %{public}u", windowId, type);
return WMError::WM_ERROR_INVALID_PARAM;
}
// do not update or removew a unexist node
if (type != AvoidControlType::AVOID_NODE_ADD && iter == avoidNodes_.end()) {
WLOGFE("WinId:%{public}d not exist. AvoidControl Update or Remove Failed. Type: %{public}u", windowId, type);
return WMError::WM_ERROR_INVALID_PARAM;
}
// add
avoidNodes_[windowId] = node;
WLOGFI("AvoidArea, WindowId:%{public}d add. And the windowType is %{public}d", windowId, node->GetWindowType());
// get all Area info and notify windowcontainer
std::vector<Rect> avoidAreas = GetAvoidArea();
DumpAvoidArea(avoidAreas);
UseCallbackNotifyAvoidAreaChanged(avoidAreas);
return WMError::WM_OK;
}
WMError AvoidAreaController::RemoveAvoidAreaNode(const sptr<WindowNode>& node)
{
WM_FUNCTION_TRACE();
if (!IsAvoidAreaNode(node)) {
WLOGFE("RemoveAvoidAreaNode check param Failed.");
return WMError::WM_ERROR_INVALID_PARAM;
switch (type) {
case AvoidControlType::AVOID_NODE_ADD:
avoidNodes_[windowId] = node;
WLOGFI("WinId:%{public}d add. And the windowType is %{public}d", windowId, node->GetWindowType());
break;
case AvoidControlType::AVOID_NODE_UPDATE:
avoidNodes_[windowId] = node;
WLOGFI("WinId:%{public}d update. And the windowType is %{public}d", windowId, node->GetWindowType());
break;
case AvoidControlType::AVOID_NODE_REMOVE:
avoidNodes_.erase(iter);
WLOGFI("WinId:%{public}d remove. And the windowType is %{public}d", windowId, node->GetWindowType());
break;
default:
WLOGFE("invalid AvoidControlType: %{public}u", type);
return WMError::WM_ERROR_INVALID_PARAM;
}
uint32_t windowId = node->GetWindowId();
auto iter = avoidNodes_.find(windowId);
if (iter == avoidNodes_.end()) {
WLOGFE("windowId: %{public}d not exist. RemoveAvoidAreaNode Failed.", windowId);
return WMError::WM_ERROR_INVALID_PARAM;
}
// remove
avoidNodes_.erase(iter);
WLOGFI("AvoidArea, WindowId:%{public}d remove. And the windowType is %{public}d", windowId, node->GetWindowType());
// get all Area info and notify windowcontainer
std::vector<Rect> avoidAreas = GetAvoidArea();
DumpAvoidArea(avoidAreas);
UseCallbackNotifyAvoidAreaChanged(avoidAreas);
return WMError::WM_OK;
}
WMError AvoidAreaController::UpdateAvoidAreaNode(const sptr<WindowNode>& node)
{
WM_FUNCTION_TRACE();
if (!IsAvoidAreaNode(node)) {
WLOGFE("UpdateAvoidAreaNode check param Failed.");
return WMError::WM_ERROR_INVALID_PARAM;
}
uint32_t windowId = node->GetWindowId();
auto iter = avoidNodes_.find(windowId);
if (iter == avoidNodes_.end()) {
WLOGFE("windowId: %{public}d not exist. UpdateAvoidAreaNode Failed.", windowId);
return WMError::WM_ERROR_INVALID_PARAM;
}
// update
avoidNodes_[windowId] = node;
WLOGFI("AvoidArea, WindowId:%{public}d Update. And the windowType is %{public}d", windowId, node->GetWindowType());
// get all Area info and notify windowcontainer
std::vector<Rect> avoidAreas = GetAvoidArea();
DumpAvoidArea(avoidAreas);
@@ -143,7 +106,7 @@ std::vector<Rect> AvoidAreaController::GetAvoidArea() const
for (auto iter = avoidNodes_.begin(); iter != avoidNodes_.end(); ++iter) {
Rect curRect = iter->second->GetLayoutRect();
auto curPos = GetAvoidPosType(curRect);
if (curPos == AvoidPos::AVOID_POS_UNKNOWN) {
if (curPos == AvoidPosType::AVOID_POS_UNKNOWN) {
WLOGFE("GetAvoidArea AVOID_POS_UNKNOWN Rect: x : %{public}d, y: %{public}d, w: %{public}u h: %{public}u",
static_cast<uint32_t>(curRect.posX_), static_cast<uint32_t>(curRect.posY_),
static_cast<uint32_t>(curRect.width_), static_cast<uint32_t>(curRect.height_));
+10 -15
View File
@@ -14,7 +14,7 @@
*/
#include "window_layout_policy.h"
#include "display_manager.h"
#include "display_manager_service_inner.h"
#include "window_helper.h"
#include "window_manager_hilog.h"
#include "wm_common_inner.h"
@@ -287,20 +287,15 @@ void WindowLayoutPolicy::LimitWindowSize(const sptr<WindowNode>& node, const Rec
AvoidPosType WindowLayoutPolicy::GetAvoidPosType(const Rect& rect)
{
if (rect.width_ >= rect.height_) {
if (rect.posY_ == 0) {
return AvoidPosType::AVOID_POS_TOP;
} else {
return AvoidPosType::AVOID_POS_BOTTOM;
}
} else {
if (rect.posX_ == 0) {
return AvoidPosType::AVOID_POS_LEFT;
} else {
return AvoidPosType::AVOID_POS_RIGHT;
}
auto display = DisplayManagerServiceInner::GetInstance().GetDisplayById(screenId_);
if (display == nullptr) {
WLOGFE("GetAvoidPosType fail. Get display fail. displayId:%{public}" PRIu64"", screenId_);
return AvoidPosType::AVOID_POS_UNKNOWN;
}
return AvoidPosType::AVOID_POS_UNKNOWN;
uint32_t displayWidth = display->GetWidth();
uint32_t displayHeight = display->GetHeight();
return WindowHelper::GetAvoidPosType(rect, displayWidth, displayHeight);
}
void WindowLayoutPolicy::UpdateLimitRect(const sptr<WindowNode>& node, Rect& limitRect)
@@ -350,7 +345,7 @@ void WindowLayoutPolicy::Reset()
float WindowLayoutPolicy::GetVirtualPixelRatio() const
{
auto display = DisplayManager::GetInstance().GetDisplayById(screenId_);
auto display = DisplayManagerServiceInner::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
+10 -6
View File
@@ -388,15 +388,19 @@ Rect WindowLayoutPolicyCascade::GetCurCascadeRect(const sptr<WindowNode>& node)
Rect WindowLayoutPolicyCascade::StepCascadeRect(Rect rect) const
{
float virtualPixelRatio = GetVirtualPixelRatio();
uint32_t cascadeWidth = static_cast<uint32_t>(WINDOW_CASCADE_WIDTH * virtualPixelRatio);
uint32_t cascadeHeight = static_cast<uint32_t>(WINDOW_CASCADE_HEIGHT * virtualPixelRatio);
Rect cascadeRect = {0, 0, 0, 0};
cascadeRect.width_ = rect.width_;
cascadeRect.height_ = rect.height_;
cascadeRect.posX_ = (rect.posX_ + WINDOW_CASCADE_WIDTH >= limitRect_.posX_) &&
(rect.posX_ + rect.width_ + WINDOW_CASCADE_WIDTH <= (limitRect_.width_ + limitRect_.posX_)) ?
(rect.posX_ + WINDOW_CASCADE_WIDTH) : limitRect_.posX_;
cascadeRect.posY_ = (rect.posY_ + WINDOW_CASCADE_HEIGHT >= limitRect_.posY_) &&
(rect.posY_ + rect.height_ + WINDOW_CASCADE_HEIGHT <= (limitRect_.height_ + limitRect_.posY_)) ?
(rect.posY_ + WINDOW_CASCADE_HEIGHT) : limitRect_.posY_;
cascadeRect.posX_ = (rect.posX_ + cascadeWidth >= limitRect_.posX_) &&
(rect.posX_ + rect.width_ + cascadeWidth <= (limitRect_.width_ + limitRect_.posX_)) ?
(rect.posX_ + cascadeWidth) : limitRect_.posX_;
cascadeRect.posY_ = (rect.posY_ + cascadeHeight >= limitRect_.posY_) &&
(rect.posY_ + rect.height_ + cascadeHeight <= (limitRect_.height_ + limitRect_.posY_)) ?
(rect.posY_ + cascadeHeight) : limitRect_.posY_;
WLOGFI("step cascadeRect :[%{public}d, %{public}d, %{public}d, %{public}d]",
cascadeRect.posX_, cascadeRect.posY_, cascadeRect.width_, cascadeRect.height_);
return cascadeRect;
+6 -2
View File
@@ -56,6 +56,10 @@ void WindowLayoutPolicyTile::InitTileWindowRects()
{
constexpr uint32_t edgeInterval = 48;
constexpr uint32_t midInterval = 24;
float virtualPixelRatio = GetVirtualPixelRatio();
uint32_t edgeIntervalVp = static_cast<uint32_t>(edgeInterval * virtualPixelRatio);
uint32_t midIntervalVp = static_cast<uint32_t>(midInterval * virtualPixelRatio);
constexpr float ratio = 0.75; // 0.75: default height/width ratio
constexpr float edgeRatio = 0.125;
constexpr int half = 2;
@@ -68,10 +72,10 @@ void WindowLayoutPolicyTile::InitTileWindowRects()
std::vector<Rect> single = {{ x, y, w, h }};
presetRects_.emplace_back(single);
for (uint32_t num = 2; num <= maxTileWinNum_; num++) { // start calc preset with 2 windows
w = (limitRect_.width_ - edgeInterval * half - midInterval * (num - 1)) / num;
w = (limitRect_.width_ - edgeIntervalVp * half - midIntervalVp * (num - 1)) / num;
std::vector<Rect> curLevel;
for (uint32_t i = 0; i < num; i++) {
int curX = limitRect_.posX_ + edgeInterval + i * (w + midInterval);
int curX = limitRect_.posX_ + edgeIntervalVp + i * (w + midIntervalVp);
Rect curRect = { curX, y, w, h };
WLOGFI("presetRects: level %{public}d, id %{public}d, [%{public}d %{public}d %{public}d %{public}d]",
num, i, curX, y, w, h);
+4 -4
View File
@@ -60,7 +60,7 @@ WindowNodeContainer::WindowNodeContainer(DisplayId displayId, uint32_t width, ui
layoutPolicy_ = layoutPolicys_[WindowLayoutMode::CASCADE];
layoutPolicy_->Launch();
UpdateAvoidAreaFunc func = std::bind(&WindowNodeContainer::OnAvoidAreaChange, this, std::placeholders::_1);
avoidController_ = new AvoidAreaController(func);
avoidController_ = new AvoidAreaController(displayId, func);
wmRecorderPtr_ = new WindowManagerRecorder();
}
@@ -133,7 +133,7 @@ WMError WindowNodeContainer::AddWindowNode(sptr<WindowNode>& node, sptr<WindowNo
AssignZOrder();
layoutPolicy_->AddWindowNode(node);
if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) {
avoidController_->AddAvoidAreaNode(node);
avoidController_->AvoidControl(node, AvoidControlType::AVOID_NODE_ADD);
NotifyIfSystemBarRegionChanged();
} else {
NotifyIfSystemBarTintChanged();
@@ -158,7 +158,7 @@ WMError WindowNodeContainer::UpdateWindowNode(sptr<WindowNode>& node, WindowUpda
}
layoutPolicy_->UpdateWindowNode(node);
if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) {
avoidController_->UpdateAvoidAreaNode(node);
avoidController_->AvoidControl(node, AvoidControlType::AVOID_NODE_UPDATE);
NotifyIfSystemBarRegionChanged();
} else {
NotifyIfSystemBarTintChanged();
@@ -289,7 +289,7 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr<WindowNode>& node)
UpdateRSTree(node, false);
layoutPolicy_->RemoveWindowNode(node);
if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) {
avoidController_->RemoveAvoidAreaNode(node);
avoidController_->AvoidControl(node, AvoidControlType::AVOID_NODE_REMOVE);
NotifyIfSystemBarRegionChanged();
} else {
NotifyIfSystemBarTintChanged();