add setWindowLayoutMode

Signed-off-by: leafly2021 <figo.yefei@huawei.com>
Change-Id: If7acbcfb1022a1195e0c6702f5727ccacd44cc0c
This commit is contained in:
leafly2021
2022-02-10 10:16:30 +08:00
parent e078f963e2
commit ed11c19532
5 changed files with 60 additions and 2 deletions
+1
View File
@@ -79,6 +79,7 @@ public:
void RegisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener);
void UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener);
void MinimizeAllAppWindows(DisplayId displayId);
void SetWindowLayoutMode(WindowLayoutMode mode, DisplayId displayId);
private:
WindowManager();
+2 -2
View File
@@ -202,7 +202,7 @@ declare namespace window {
* @systemapi Hide this for inner system use.
* @since 8
*/
function setWindowLayoutMode(mode: WindowLayoutMode, callback: AsyncCallback<void>): void;
function setWindowLayoutMode(mode: WindowLayoutMode, displayId: number, callback: AsyncCallback<void>): void;
/**
* Set the layout mode of a window.
@@ -211,7 +211,7 @@ declare namespace window {
* @systemapi Hide this for inner system use.
* @since 8
*/
function setWindowLayoutMode(mode: WindowLayoutMode): Promise<void>;
function setWindowLayoutMode(mode: WindowLayoutMode, displayId: number): Promise<void>;
/**
* register the callback of systemBarTintChange
@@ -71,6 +71,12 @@ NativeValue* JsWindowManager::GetTopWindow(NativeEngine* engine, NativeCallbackI
return (me != nullptr) ? me->OnGetTopWindow(*engine, *info) : nullptr;
}
NativeValue* JsWindowManager::SetWindowLayoutMode(NativeEngine* engine, NativeCallbackInfo* info)
{
JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
return (me != nullptr) ? me->OnSetWindowLayoutMode(*engine, *info) : nullptr;
}
static bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability)
{
napi_value global;
@@ -477,6 +483,48 @@ NativeValue* JsWindowManager::OnGetTopWindow(NativeEngine& engine, NativeCallbac
return result;
}
NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindowManager::OnSetWindowLayoutMode is called");
WMError errCode = WMError::WM_OK;
if (info.argc < ARGC_TWO) {
WLOGFE("JsWindowManager::OnSetWindowLayoutMode params too small");
errCode = WMError::WM_ERROR_INVALID_PARAM;
}
WindowLayoutMode winLayoutMode = WindowLayoutMode::CASCADE;
int64_t displayId = 0;
if (errCode == WMError::WM_OK) {
NativeNumber* nativeMode = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
if (nativeMode == nullptr) {
WLOGFE("Failed to convert parameter to windowLayoutMode");
errCode = WMError::WM_ERROR_INVALID_PARAM;
} else {
winLayoutMode = static_cast<WindowLayoutMode>(static_cast<uint32_t>(*nativeMode));
}
if (!ConvertFromJsValue(engine, info.argv[1], displayId)) {
WLOGFE("Failed to convert parameter to displayId");
errCode = WMError::WM_ERROR_INVALID_PARAM;
}
}
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
if (errCode != WMError::WM_OK) {
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
return;
}
SingletonContainer::Get<WindowManager>().SetWindowLayoutMode(winLayoutMode,
static_cast<uint64_t>(displayId));
task.Resolve(engine, engine.CreateUndefined());
WLOGFI("JsWindowManager::OnSetWindowLayoutMode success");
};
NativeValue* lastParam = (info.argc < ARGC_THREE) ? nullptr : info.argv[INDEX_TWO];
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj)
{
@@ -502,6 +550,7 @@ NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj)
BindNativeFunction(*engine, *object, "off", JsWindowManager::UnregisterWindowMangerCallback);
BindNativeFunction(*engine, *object, "getTopWindow", JsWindowManager::GetTopWindow);
BindNativeFunction(*engine, *object, "minimizeAll", JsWindowManager::MinimizeAll);
BindNativeFunction(*engine, *object, "setWindowLayoutMode", JsWindowManager::SetWindowLayoutMode);
return engine->CreateUndefined();
}
} // namespace Rosen
@@ -36,6 +36,7 @@ public:
static NativeValue* RegisterWindowManagerCallback(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* UnregisterWindowMangerCallback(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* GetTopWindow(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetWindowLayoutMode(NativeEngine* engine, NativeCallbackInfo* info);
private:
bool GetNativeContext(NativeValue* nativeContext);
@@ -50,6 +51,7 @@ private:
NativeValue* OnRegisterWindowMangerCallback(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnUnregisterWindowManagerCallback(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnGetTopWindow(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetWindowLayoutMode(NativeEngine& engine, NativeCallbackInfo& info);
std::weak_ptr<AbilityRuntime::Context> context_;
std::map<std::string, std::map<std::unique_ptr<NativeReference>, sptr<JsWindowListener>>> jsCbMap_;
std::mutex mtx_;
+6
View File
@@ -209,6 +209,12 @@ void WindowManager::MinimizeAllAppWindows(DisplayId displayId)
WLOGFI("displayId %{public}" PRIu64"", displayId);
SingletonContainer::Get<WindowAdapter>().MinimizeAllAppWindows(displayId);
}
void WindowManager::SetWindowLayoutMode(WindowLayoutMode mode, DisplayId displayId)
{
WLOGFI("set window layout mode: %{public}d, displayId %{public}" PRIu64"", mode, displayId);
}
void WindowManager::RegisterWindowUpdateListener(const sptr<IWindowUpdateListener> &listener)
{
if (listener == nullptr) {