mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-19 17:08:11 -04:00
fix screen js enum usages
Signed-off-by: zengqingyu <zengqingyu3@huawei.com> Change-Id: I6f62aeb489e3fd53e19cc38e791596e098aacb35
This commit is contained in:
@@ -33,6 +33,15 @@ public:
|
||||
private:
|
||||
sptr<Display> display_ = nullptr;
|
||||
};
|
||||
enum class DisplayStateMode : uint32_t {
|
||||
STATE_UNKNOWN = 0,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_DOZE,
|
||||
STATE_DOZE_SUSPEND,
|
||||
STATE_VR,
|
||||
STATE_ON_SUSPEND
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -328,6 +328,36 @@ NativeValue* CreateJsDisplayArrayObject(NativeEngine& engine, std::vector<sptr<D
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* InitDisplayState(NativeEngine* engine)
|
||||
{
|
||||
WLOGFI("JsDisplayManager::InitDisplayState called");
|
||||
|
||||
if (engine == nullptr) {
|
||||
WLOGFE("engine is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine->CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to get object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
object->SetProperty("STATE_UNKNOWN", CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_UNKNOWN)));
|
||||
object->SetProperty("STATE_OFF", CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_OFF)));
|
||||
object->SetProperty("STATE_ON", CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_ON)));
|
||||
object->SetProperty("STATE_DOZE",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_DOZE)));
|
||||
object->SetProperty("STATE_DOZE_SUSPEND",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_DOZE_SUSPEND)));
|
||||
object->SetProperty("STATE_VR",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_VR)));
|
||||
object->SetProperty("STATE_ON_SUSPEND",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_ON_SUSPEND)));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue* JsDisplayManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
{
|
||||
WLOGFI("JsDisplayManagerInit is called");
|
||||
@@ -346,6 +376,8 @@ NativeValue* JsDisplayManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
std::unique_ptr<JsDisplayManager> jsDisplayManager = std::make_unique<JsDisplayManager>(engine);
|
||||
object->SetNativePointer(jsDisplayManager.release(), JsDisplayManager::Finalizer, nullptr);
|
||||
|
||||
object->SetProperty("DisplayState", InitDisplayState(engine));
|
||||
|
||||
BindNativeFunction(*engine, *object, "getDefaultDisplay", JsDisplayManager::GetDefaultDisplay);
|
||||
BindNativeFunction(*engine, *object, "getDefaultDisplaySync", JsDisplayManager::GetDefaultDisplaySync);
|
||||
BindNativeFunction(*engine, *object, "getAllDisplay", JsDisplayManager::GetAllDisplay);
|
||||
|
||||
@@ -684,6 +684,37 @@ NativeValue* OnSetScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo&
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* InitScreenOrientation(NativeEngine* engine)
|
||||
{
|
||||
WLOGFI("JsScreenManager::InitScreenOrientation called");
|
||||
|
||||
if (engine == nullptr) {
|
||||
WLOGFE("engine is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine->CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to get object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
object->SetProperty("UNSPECIFIED", CreateJsValue(*engine, static_cast<int32_t>(Orientation::UNSPECIFIED)));
|
||||
object->SetProperty("VERTICAL", CreateJsValue(*engine, static_cast<int32_t>(Orientation::VERTICAL)));
|
||||
object->SetProperty("HORIZONTAL", CreateJsValue(*engine, static_cast<int32_t>(Orientation::HORIZONTAL)));
|
||||
object->SetProperty("REVERSE_VERTICAL",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(Orientation::REVERSE_VERTICAL)));
|
||||
object->SetProperty("REVERSE_HORIZONTAL",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(Orientation::REVERSE_HORIZONTAL)));
|
||||
object->SetProperty("SENSOR", CreateJsValue(*engine, static_cast<int32_t>(Orientation::SENSOR)));
|
||||
object->SetProperty("SENSOR_VERTICAL",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(Orientation::SENSOR_VERTICAL)));
|
||||
object->SetProperty("SENSOR_HORIZONTAL",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(Orientation::SENSOR_HORIZONTAL)));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
{
|
||||
WLOGFI("JsScreenManagerInit is called");
|
||||
@@ -702,6 +733,8 @@ NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
std::unique_ptr<JsScreenManager> jsScreenManager = std::make_unique<JsScreenManager>(engine);
|
||||
object->SetNativePointer(jsScreenManager.release(), JsScreenManager::Finalizer, nullptr);
|
||||
|
||||
object->SetProperty("Orientation", InitScreenOrientation(engine));
|
||||
|
||||
BindNativeFunction(*engine, *object, "getAllScreens", JsScreenManager::GetAllScreens);
|
||||
BindNativeFunction(*engine, *object, "on", JsScreenManager::RegisterScreenManagerCallback);
|
||||
BindNativeFunction(*engine, *object, "off", JsScreenManager::UnregisterScreenMangerCallback);
|
||||
|
||||
Reference in New Issue
Block a user