Add property named drawableRect in windowProperties

Signed-off-by: tian-xun <tianxun3@huawei.com>
This commit is contained in:
tian-xun 2023-11-29 21:49:39 +08:00
parent d982295db7
commit f7b7b2a9d1
4 changed files with 31 additions and 9 deletions

View File

@ -1389,7 +1389,14 @@ napi_value JsWindow::OnGetProperties(napi_env env, napi_callback_info info)
WLOGFE("window is nullptr or get invalid param");
return;
}
auto objValue = CreateJsWindowPropertiesObject(env, weakWindow);
Rect drawableRect = g_emptyRect;
auto uicontent = weakWindow->GetUIContent();
if (uicontent == nullptr) {
WLOGFW("uicontent is nullptr");
} else {
uicontent->GetAppPaintSize(drawableRect);
}
auto objValue = CreateJsWindowPropertiesObject(env, weakWindow, drawableRect);
if (objValue != nullptr) {
task.Resolve(env, objValue);
} else {
@ -1415,7 +1422,14 @@ napi_value JsWindow::OnGetWindowPropertiesSync(napi_env env, napi_callback_info
WLOGFE("window is nullptr or get invalid param");
return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY);
}
auto objValue = CreateJsWindowPropertiesObject(env, window);
Rect drawableRect = g_emptyRect;
auto uicontent = window->GetUIContent();
if (uicontent == nullptr) {
WLOGFW("uicontent is nullptr");
} else {
uicontent->GetAppPaintSize(drawableRect);
}
auto objValue = CreateJsWindowPropertiesObject(env, window, drawableRect);
WLOGI("Window [%{public}u, %{public}s] get properties end",
window->GetWindowId(), window->GetWindowName().c_str());
if (objValue != nullptr) {

View File

@ -419,7 +419,7 @@ napi_value GetRectAndConvertToJsValue(napi_env env, const Rect& rect)
return objValue;
}
napi_value CreateJsWindowPropertiesObject(napi_env env, sptr<Window>& window)
napi_value CreateJsWindowPropertiesObject(napi_env env, sptr<Window>& window, const Rect& drawableRect)
{
WLOGI("CreateJsWindowPropertiesObject");
napi_value objValue = nullptr;
@ -429,12 +429,19 @@ napi_value CreateJsWindowPropertiesObject(napi_env env, sptr<Window>& window)
return nullptr;
}
Rect rect = window->GetRect();
napi_value rectObj = GetRectAndConvertToJsValue(env, rect);
if (rectObj == nullptr) {
WLOGFE("GetRect failed!");
Rect windowRect = window->GetRect();
napi_value windowRectObj = GetRectAndConvertToJsValue(env, windowRect);
if (windowRectObj == nullptr) {
WLOGFE("GetWindowRect failed!");
}
napi_set_named_property(env, objValue, "windowRect", rectObj);
napi_set_named_property(env, objValue, "windowRect", windowRectObj);
napi_value drawableRectObj = GetRectAndConvertToJsValue(env, drawableRect);
if (drawableRectObj == nullptr) {
WLOGFE("GetDrawableRect failed!");
}
napi_set_named_property(env, objValue, "drawableRect", drawableRectObj);
WindowType type = window->GetType();
if (NATIVE_JS_TO_WINDOW_TYPE_MAP.count(type) != 0) {
napi_set_named_property(env, objValue, "type", CreateJsValue(env, NATIVE_JS_TO_WINDOW_TYPE_MAP.at(type)));

View File

@ -173,7 +173,7 @@ struct SystemBarPropertyFlag {
};
napi_value GetRectAndConvertToJsValue(napi_env env, const Rect& rect);
napi_value CreateJsWindowPropertiesObject(napi_env env, sptr<Window>& window);
napi_value CreateJsWindowPropertiesObject(napi_env env, sptr<Window>& window, const Rect& drawableRect);
bool SetSystemBarPropertiesFromJs(napi_env env, napi_value jsObject,
std::map<WindowType, SystemBarProperty>& properties, std::map<WindowType, SystemBarPropertyFlag>& propertyFlags,
sptr<Window>& window);

View File

@ -87,6 +87,7 @@ public:
MOCK_METHOD4(
FocusMoveSearch, void(int32_t elementId, int32_t direction, int32_t baseParent,
Accessibility::AccessibilityElementInfo &output));
MOCK_METHOD1(GetAppPaintSize, void(OHOS::Rosen::Rect& drawableRect));
};
} // namespace Ace
} // namespace OHOS