mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-21 04:25:28 -04:00
49486f0153
Signed-off-by: laiguizhong <laiguizhong@huawei.com> Change-Id: Ia303d155a0d30da4736e96b009125f40d4c3837a
60 lines
2.3 KiB
C++
60 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
#include "js_window_utils.h"
|
|
#include "js_runtime_utils.h"
|
|
#include "window_manager_hilog.h"
|
|
namespace OHOS {
|
|
namespace Rosen {
|
|
using namespace AbilityRuntime;
|
|
namespace {
|
|
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowUtils"};
|
|
}
|
|
|
|
static NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect& rect)
|
|
{
|
|
NativeValue* objValue = engine.CreateObject();
|
|
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
|
if (object == nullptr) {
|
|
WLOGFE("Failed to convert rect to jsObject");
|
|
return engine.CreateUndefined();
|
|
}
|
|
object->SetProperty("left", CreateJsValue(engine, rect.posX_));
|
|
object->SetProperty("top", CreateJsValue(engine, rect.posY_));
|
|
object->SetProperty("width", CreateJsValue(engine, rect.width_));
|
|
object->SetProperty("height", CreateJsValue(engine, rect.height_));
|
|
return objValue;
|
|
}
|
|
|
|
NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr<Window>& window)
|
|
{
|
|
WLOGFI("JsWindow::CreateJsWindowPropertiesObject is called");
|
|
NativeValue* objValue = engine.CreateObject();
|
|
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
|
if (object == nullptr) {
|
|
WLOGFE("Failed to convert windowProperties to jsObject");
|
|
return nullptr;
|
|
}
|
|
|
|
Rect rect = window->GetRect();
|
|
NativeValue* rectObj = GetRectAndConvertToJsValue(engine, rect);
|
|
if (rectObj == nullptr) {
|
|
WLOGFE("GetRect failed!");
|
|
}
|
|
object->SetProperty("windowRect", rectObj);
|
|
object->SetProperty("type", CreateJsValue(engine, window->GetType()));
|
|
return objValue;
|
|
}
|
|
} // namespace Rosen
|
|
} // namespace OHOS
|