mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-19 17:08:11 -04:00
add animation property config
Signed-off-by: chyyy0213 <chenhaiying3@huawei.com> Change-Id: I867f7189636ae398753848bd4f09bcb10317602b Signed-off-by: chyyy0213 <chenhaiying3@huawei.com>
This commit is contained in:
@@ -169,7 +169,9 @@ public:
|
||||
virtual WMError SetWindowType(WindowType type) = 0;
|
||||
virtual WMError SetWindowMode(WindowMode mode) = 0;
|
||||
virtual WMError SetWindowBackgroundBlur(WindowBlurLevel level) = 0;
|
||||
virtual WMError SetAlpha(float alpha) = 0;
|
||||
virtual void SetAlpha(float alpha) = 0;
|
||||
virtual void SetTransform(const Transform& trans) = 0;
|
||||
virtual Transform GetTransform() const = 0;
|
||||
virtual WMError AddWindowFlag(WindowFlag flag) = 0;
|
||||
virtual WMError RemoveWindowFlag(WindowFlag flag) = 0;
|
||||
virtual WMError SetWindowFlags(uint32_t flags) = 0;
|
||||
@@ -178,8 +180,8 @@ public:
|
||||
virtual WMError SetLayoutFullScreen(bool status) = 0;
|
||||
virtual WMError SetFullScreen(bool status) = 0;
|
||||
virtual WMError Destroy() = 0;
|
||||
virtual WMError Show(uint32_t reason = 0) = 0;
|
||||
virtual WMError Hide(uint32_t reason = 0) = 0;
|
||||
virtual WMError Show(uint32_t reason = 0, bool isCustomAnimation = false) = 0;
|
||||
virtual WMError Hide(uint32_t reason = 0, bool isCustomAnimation = false) = 0;
|
||||
|
||||
virtual WMError MoveTo(int32_t x, int32_t y) = 0;
|
||||
virtual WMError Resize(uint32_t width, uint32_t height) = 0;
|
||||
|
||||
@@ -33,7 +33,6 @@ public:
|
||||
void SetWindowType(WindowType type);
|
||||
void SetWindowMode(WindowMode mode);
|
||||
void SetWindowBackgroundBlur(WindowBlurLevel level);
|
||||
void SetAlpha(float alpha);
|
||||
void SetFocusable(bool isFocusable);
|
||||
void SetTouchable(bool isTouchable);
|
||||
void SetDisplayId(DisplayId displayId);
|
||||
@@ -58,7 +57,6 @@ public:
|
||||
WindowType GetWindowType() const;
|
||||
WindowMode GetWindowMode() const;
|
||||
WindowBlurLevel GetWindowBackgroundBlur() const;
|
||||
float GetAlpha() const;
|
||||
bool GetFocusable() const;
|
||||
bool GetTouchable() const;
|
||||
DisplayId GetDisplayId() const;
|
||||
@@ -75,7 +73,6 @@ private:
|
||||
WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
|
||||
WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN };
|
||||
WindowBlurLevel level_ { WindowBlurLevel::WINDOW_BLUR_OFF };
|
||||
float alpha_ { 1.0f };
|
||||
bool focusable_ { true };
|
||||
bool touchable_ { true };
|
||||
DisplayId displayId_ { 0 };
|
||||
|
||||
@@ -172,6 +172,25 @@ namespace {
|
||||
constexpr int32_t INVALID_UID = -1;
|
||||
}
|
||||
|
||||
class Transform {
|
||||
public:
|
||||
Transform()
|
||||
: pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), rotationX_(0.f), rotationY_(0.f), rotationZ_(0.f),
|
||||
translateX_(0.f), translateY_(0.f), translateZ_(0.f)
|
||||
{}
|
||||
~Transform() {}
|
||||
float pivotX_;
|
||||
float pivotY_;
|
||||
float scaleX_;
|
||||
float scaleY_;
|
||||
float rotationX_;
|
||||
float rotationY_;
|
||||
float rotationZ_;
|
||||
float translateX_;
|
||||
float translateY_;
|
||||
float translateZ_;
|
||||
};
|
||||
|
||||
struct SystemBarProperty {
|
||||
bool enable_;
|
||||
uint32_t backgroundColor_;
|
||||
|
||||
@@ -50,6 +50,7 @@ ohos_shared_library("window_native_kit") {
|
||||
|
||||
configs = [ ":window_native_kit_config" ]
|
||||
deps = [
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
"//foundation/windowmanager/wmserver:libwms",
|
||||
|
||||
+107
-3
@@ -91,6 +91,82 @@ declare namespace window {
|
||||
*/
|
||||
TYPE_KEYBOARD
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the scale Transition Options of window
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @since 9
|
||||
* @systemapi
|
||||
*/
|
||||
declare interface ScaleOptions {
|
||||
/**
|
||||
* The scale param of x direction. Default is 1.f
|
||||
*/
|
||||
x?: number;
|
||||
/**
|
||||
* The scale param of y direction. Default is 1.f
|
||||
*/
|
||||
y?: number;
|
||||
/**
|
||||
* The scale param of pivot point of x. Default is 0.5f, Interval is 0.f - 1.f
|
||||
*/
|
||||
pivotX?: number;
|
||||
/**
|
||||
* The scale param of pivot point of y. Default is 0.5f, Interval is 0.f - 1.f
|
||||
*/
|
||||
pivotY?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the rotate Transition Options of window
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @since 9
|
||||
* @systemapi
|
||||
*/
|
||||
declare interface RotateOptions {
|
||||
/**
|
||||
* The rotate degree of x direction. Default value is 0.f
|
||||
*/
|
||||
x?: number;
|
||||
/**
|
||||
* The rotate degree of y direction. Default value is 0.f
|
||||
*/
|
||||
y?: number;
|
||||
/**
|
||||
* The rotate degree of z direction. Default value is 0.f
|
||||
*/
|
||||
z?: number;
|
||||
/**
|
||||
* The param of pivot point of x. Default is 0.5f, Interval is 0.f - 1.f
|
||||
*/
|
||||
pivotX?: number;
|
||||
/**
|
||||
* The param of pivot point of y. Default is 0.5f, Interval is 0.f - 1.f
|
||||
*/
|
||||
pivotY?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the translate Transition Options of window
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @since 9
|
||||
* @systemapi
|
||||
*/
|
||||
declare interface TranslateOptions {
|
||||
/**
|
||||
* The translate pixel param of x direction. Default is 0.f
|
||||
*/
|
||||
x?: number;
|
||||
/**
|
||||
* The translate pixel param of y direction. Default is 0.f
|
||||
*/
|
||||
y?: number;
|
||||
/**
|
||||
* The translate pixel param of z direction. Default is 0.f
|
||||
*/
|
||||
z?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the window mode of an application
|
||||
* @systemapi Hide this for inner system use.
|
||||
@@ -961,7 +1037,7 @@ declare namespace window {
|
||||
* @since 9
|
||||
*/
|
||||
setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void;
|
||||
|
||||
|
||||
/**
|
||||
* disable window decoration. It must be called before loadContent.
|
||||
* @systemapi
|
||||
@@ -985,7 +1061,7 @@ declare namespace window {
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void;
|
||||
setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void;
|
||||
|
||||
/**
|
||||
* set the flag of the window is forbidden to move in split screen mode
|
||||
@@ -994,7 +1070,35 @@ declare namespace window {
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setForbidSplitMove(isForbidSplitMove: boolean): Promise<void>;
|
||||
setForbidSplitMove(isForbidSplitMove: boolean): Promise<void>;
|
||||
/**
|
||||
* Sets opacity of window
|
||||
* @param opacity Interval is 0.f-1.f.
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setOpacitySync(opacity: number): void;
|
||||
/**
|
||||
* Sets scale options of window.
|
||||
* @param scaleOptions scale param of window.
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setScaleSync(scaleOptions: ScaleOptions): void;
|
||||
/**
|
||||
* Sets rotate options of window.
|
||||
* @param rotateOptions rotate param of window.
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setRotateSync(rotateOptions: RotateOptions): void;
|
||||
/**
|
||||
* Sets whether is transparent or not.
|
||||
* @param translateOptions translate param of window.
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setTranslateSync(translateOptions: TranslateOptions): void;
|
||||
}
|
||||
|
||||
enum WindowStageEventType {
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
|
||||
#include "js_window.h"
|
||||
#include <new>
|
||||
#include <ui/rs_surface_node.h>
|
||||
#include "js_window_utils.h"
|
||||
#include "window.h"
|
||||
#include "window_helper.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "window_option.h"
|
||||
namespace OHOS {
|
||||
@@ -29,24 +31,28 @@ namespace {
|
||||
|
||||
static thread_local std::map<std::string, std::shared_ptr<NativeReference>> g_jsWindowMap;
|
||||
std::recursive_mutex g_mutex;
|
||||
static int ctorCnt = 0;
|
||||
static int dtorCnt = 0;
|
||||
static int finalizerCnt = 0;
|
||||
JsWindow::JsWindow(const sptr<Window>& window)
|
||||
: windowToken_(window), registerManager_(std::make_unique<JsWindowRegisterManager>())
|
||||
{
|
||||
NotifyNativeWinDestroyFunc func = [](std::string windowName) {
|
||||
std::lock_guard<std::recursive_mutex> lock(g_mutex);
|
||||
if (windowName.empty() || g_jsWindowMap.count(windowName) == 0) {
|
||||
WLOGE("[NAPI]Can not find window %{public}s ", windowName.c_str());
|
||||
WLOGFE("[NAPI]Can not find window %{public}s ", windowName.c_str());
|
||||
return;
|
||||
}
|
||||
g_jsWindowMap.erase(windowName);
|
||||
WLOGE("[NAPI]Destroy window %{public}s in js window", windowName.c_str());
|
||||
WLOGFI("[NAPI]Destroy window %{public}s in js window", windowName.c_str());
|
||||
};
|
||||
windowToken_->RegisterWindowDestroyedListener(func);
|
||||
WLOGFI("[NAPI] JsWindow constructor Count: %{public}d", ++ctorCnt);
|
||||
}
|
||||
|
||||
JsWindow::~JsWindow()
|
||||
{
|
||||
WLOGFI("[NAPI]~JsWindow");
|
||||
WLOGFI("[NAPI]~JsWindow deconstructor Count:%{public}d", ++dtorCnt);
|
||||
windowToken_ = nullptr;
|
||||
}
|
||||
|
||||
@@ -60,7 +66,7 @@ std::string JsWindow::GetWindowName()
|
||||
|
||||
void JsWindow::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
WLOGFI("[NAPI]Finalizer");
|
||||
WLOGFI("[NAPI]Finalizer Count:%{public}d", ++finalizerCnt);
|
||||
auto jsWin = std::unique_ptr<JsWindow>(static_cast<JsWindow*>(data));
|
||||
if (jsWin == nullptr) {
|
||||
WLOGFE("[NAPI]jsWin is nullptr");
|
||||
@@ -313,6 +319,34 @@ NativeValue* JsWindow::SetForbidSplitMove(NativeEngine* engine, NativeCallbackIn
|
||||
return (me != nullptr) ? me->OnSetForbidSplitMove(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::SetOpacitySync(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("[NAPI]SetOpacitySync");
|
||||
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetOpacitySync(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::SetScaleSync(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("[NAPI]SetScaleSync");
|
||||
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetScaleSync(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::SetRotateSync(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("[NAPI]SetRotateSync");
|
||||
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetRotateSync(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::SetTranslateSync(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("[NAPI]SetTranslateSync");
|
||||
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetTranslateSync(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WMError errCode = WMError::WM_OK;
|
||||
@@ -1643,6 +1677,199 @@ NativeValue* JsWindow::OnSetForbidSplitMove(NativeEngine& engine, NativeCallback
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnSetOpacitySync(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
if (info.argc != 1 || windowToken_ == nullptr) {
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
|
||||
WLOGFE("[NAPI]SetOpacitySync is not allowed since window is not system window");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
|
||||
if (nativeVal == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to convert parameter to alpha");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
float alpha = static_cast<double>(*nativeVal);
|
||||
windowToken_->SetAlpha(alpha);
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetOpacitySync end, alpha = %{public}f",
|
||||
windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), alpha);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
bool JsWindow::ParseScaleOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans)
|
||||
{
|
||||
auto surfaceNode = windowToken_->GetSurfaceNode();
|
||||
if (surfaceNode == nullptr) {
|
||||
WLOGFE("[NAPI] surfaceNode is nullptr");
|
||||
return false;
|
||||
}
|
||||
double data = 0.0f;
|
||||
if (ParseJsDoubleValue(jsObject, engine, "pivotX", data)) {
|
||||
surfaceNode->SetPivotX(data);
|
||||
trans.pivotX_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "pivotY", data)) {
|
||||
surfaceNode->SetPivotY(data);
|
||||
trans.pivotY_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "x", data)) {
|
||||
surfaceNode->SetScaleX(data);
|
||||
trans.scaleX_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "y", data)) {
|
||||
surfaceNode->SetScaleY(data);
|
||||
trans.scaleY_ = data;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnSetScaleSync(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
if (info.argc != 1 || windowToken_ == nullptr) {
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
|
||||
WLOGFE("[NAPI]SetScaleSync is not allowed since window is not system window");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
|
||||
if (nativeObj == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to convert object to ScaleOptions");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
auto trans = windowToken_->GetTransform();
|
||||
if (!ParseScaleOption(engine, nativeObj, trans)) {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
windowToken_->SetTransform(trans);
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetScaleSync end",
|
||||
windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str());
|
||||
WLOGFI("[NAPI]scaleX = %{public}f, scaleY = %{public}f, pivotX = %{public}f pivotY = %{public}f",
|
||||
trans.scaleX_, trans.scaleY_, trans.pivotX_, trans.pivotY_);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
bool JsWindow::ParseRotateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans)
|
||||
{
|
||||
auto surfaceNode = windowToken_->GetSurfaceNode();
|
||||
if (surfaceNode == nullptr) {
|
||||
WLOGFE("[NAPI] surfaceNode is nullptr");
|
||||
return false;
|
||||
}
|
||||
double data = 0.0f;
|
||||
if (ParseJsDoubleValue(jsObject, engine, "pivotX", data)) {
|
||||
surfaceNode->SetPivotX(data);
|
||||
trans.pivotX_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "pivotY", data)) {
|
||||
surfaceNode->SetPivotY(data);
|
||||
trans.pivotY_ = data;
|
||||
}
|
||||
double coeff = 0.5 * 3.14 / 180; // 0.5 means half; 3.14 means pi; 180 means degree
|
||||
if (ParseJsDoubleValue(jsObject, engine, "x", data)) {
|
||||
float w = std::cos(data * coeff);
|
||||
float x = std::sin(data * coeff);
|
||||
surfaceNode->SetRotation(Quaternion(x, 0, 0, w));
|
||||
trans.rotationX_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "y", data)) {
|
||||
float w = std::cos(data * coeff);
|
||||
float y = std::sin(data * coeff);
|
||||
surfaceNode->SetRotation(Quaternion(0, y, 0, w));
|
||||
trans.rotationY_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "z", data)) {
|
||||
float w = std::cos(data * coeff);
|
||||
float z = std::sin(data * coeff);
|
||||
surfaceNode->SetRotation(Quaternion(0, 0, z, w));
|
||||
trans.rotationZ_ = data;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnSetRotateSync(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
if (info.argc != 1 || windowToken_ == nullptr) {
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
|
||||
WLOGFE("[NAPI]SetRotateSync is not allowed since window is not system window");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
|
||||
if (nativeObj == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to convert object to RotateOptions");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
// cannot use sync task since next transform base on current transform
|
||||
auto trans = windowToken_->GetTransform();
|
||||
if (!ParseRotateOption(engine, nativeObj, trans)) {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
windowToken_->SetTransform(trans);
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetRotateSync end",
|
||||
windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str());
|
||||
WLOGFI("[NAPI]rotateX = %{public}f, rotateY = %{public}f," \
|
||||
"rotateZ = %{public}f pivotX = %{public}f pivotY = %{public}f",
|
||||
trans.rotationX_, trans.rotationY_, trans.rotationZ_, trans.pivotX_, trans.pivotY_);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
bool JsWindow::ParseTranslateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans)
|
||||
{
|
||||
auto surfaceNode = windowToken_->GetSurfaceNode();
|
||||
if (surfaceNode == nullptr) {
|
||||
WLOGFE("[NAPI] surfaceNode is nullptr");
|
||||
return false;
|
||||
}
|
||||
double data = 0.0f;
|
||||
if (ParseJsDoubleValue(jsObject, engine, "x", data)) {
|
||||
surfaceNode->SetTranslateX(data);
|
||||
trans.translateX_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "y", data)) {
|
||||
surfaceNode->SetTranslateY(data);
|
||||
trans.translateY_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "z", data)) {
|
||||
surfaceNode->SetTranslateZ(data);
|
||||
trans.translateZ_ = data;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnSetTranslateSync(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
if (info.argc != 1 || windowToken_ == nullptr) {
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
|
||||
WLOGFE("[NAPI]SetTranslateSync is not allowed since window is not system window");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
|
||||
if (nativeObj == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to convert object to TranslateOptions");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
auto trans = windowToken_->GetTransform();
|
||||
if (!ParseTranslateOption(engine, nativeObj, trans)) {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
windowToken_->SetTransform(trans);
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetRotateSync end," \
|
||||
"translateX = %{public}f, translateY = %{public}f, translateZ = %{public}f",
|
||||
windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(),
|
||||
trans.translateX_, trans.translateY_, trans.translateZ_);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
std::shared_ptr<NativeReference> FindJsWindowObject(std::string windowName)
|
||||
{
|
||||
WLOGFI("[NAPI]Try to find window %{public}s in g_jsWindowMap", windowName.c_str());
|
||||
@@ -1716,6 +1943,10 @@ void BindFunctions(NativeEngine& engine, NativeObject* object)
|
||||
BindNativeFunction(engine, *object, "dump", JsWindow::Dump);
|
||||
BindNativeFunction(engine, *object, "setForbidSplitMove", JsWindow::SetForbidSplitMove);
|
||||
BindNativeFunction(engine, *object, "setPreferredOrientation", JsWindow::SetPreferredOrientation);
|
||||
BindNativeFunction(engine, *object, "setOpacitySync", JsWindow::SetOpacitySync);
|
||||
BindNativeFunction(engine, *object, "setScaleSync", JsWindow::SetScaleSync);
|
||||
BindNativeFunction(engine, *object, "setRotateSync", JsWindow::SetRotateSync);
|
||||
BindNativeFunction(engine, *object, "setTranslateSync", JsWindow::SetTranslateSync);
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -69,8 +69,16 @@ public:
|
||||
static NativeValue* Dump(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* SetForbidSplitMove(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
|
||||
// animation config
|
||||
static NativeValue* SetOpacitySync(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* SetScaleSync(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* SetRotateSync(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* SetTranslateSync(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
private:
|
||||
std::string GetWindowName();
|
||||
bool ParseScaleOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans);
|
||||
bool ParseRotateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans);
|
||||
bool ParseTranslateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans);
|
||||
NativeValue* OnShow(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnDestroy(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnHide(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
@@ -108,6 +116,11 @@ private:
|
||||
NativeValue* OnDump(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnSetForbidSplitMove(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
|
||||
// animation Config
|
||||
NativeValue* OnSetOpacitySync(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnSetScaleSync(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnSetRotateSync(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnSetTranslateSync(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
sptr<Window> windowToken_ = nullptr;
|
||||
std::unique_ptr<JsWindowRegisterManager> registerManager_ = nullptr;
|
||||
};
|
||||
|
||||
@@ -484,5 +484,20 @@ bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParseJsDoubleValue(NativeObject* jsObject, NativeEngine& engine, const std::string& name, double data)
|
||||
{
|
||||
NativeValue* value = jsObject->GetProperty(name.c_str());
|
||||
if (value->TypeOf() != NATIVE_UNDEFINED) {
|
||||
if (!ConvertFromJsValue(engine, value, data)) {
|
||||
WLOGFE("[NAPI]Failed to convert parameter to scale %{public}s", name.c_str());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
WLOGFI("[NAPI]no property with: %{public}s", name.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -165,6 +165,7 @@ const std::map<ApiOrientation, Orientation> JS_TO_NATIVE_ORIENTATION_MAP {
|
||||
NativeValue* WindowStageEventTypeInit(NativeEngine* engine);
|
||||
NativeValue* WindowLayoutModeInit(NativeEngine* engine);
|
||||
bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability);
|
||||
bool ParseJsDoubleValue(NativeObject* jsObject, NativeEngine& engine, const std::string& name, double data);
|
||||
template<class T>
|
||||
inline bool ConvertNativeValueToVector(NativeEngine& engine, NativeValue* nativeValue, std::vector<T>& out)
|
||||
{
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
#include <refbase.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "parcel.h"
|
||||
|
||||
#include <parcel.h>
|
||||
#include "class_var_definition.h"
|
||||
#include "dm_common.h"
|
||||
#include "wm_common.h"
|
||||
@@ -74,6 +73,7 @@ public:
|
||||
void SetTouchHotAreas(const std::vector<Rect>& rects);
|
||||
void SetAccessTokenId(uint32_t accessTokenId);
|
||||
WindowSizeChangeReason GetWindowSizeChangeReason() const;
|
||||
void SetTransform(const Transform& trans);
|
||||
|
||||
const std::string& GetWindowName() const;
|
||||
Rect GetRequestRect() const;
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
const Rect& GetOriginRect() const;
|
||||
void GetTouchHotAreas(std::vector<Rect>& rects) const;
|
||||
uint32_t GetAccessTokenId() const;
|
||||
|
||||
Transform GetTransform() const;
|
||||
virtual bool Marshalling(Parcel& parcel) const override;
|
||||
static WindowProperty* Unmarshalling(Parcel& parcel);
|
||||
|
||||
@@ -120,7 +120,8 @@ private:
|
||||
static void MapUnmarshalling(Parcel& parcel, WindowProperty* property);
|
||||
bool MarshallingTouchHotAreas(Parcel& parcel) const;
|
||||
static void UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty* property);
|
||||
|
||||
bool MarshallingTransform(Parcel& parcel) const;
|
||||
static void UnmarshallingTransform(Parcel& parcel, WindowProperty* property);
|
||||
std::string windowName_;
|
||||
Rect requestRect_ { 0, 0, 0, 0 }; // window rect requested by the client (without decoration size)
|
||||
Rect windowRect_ { 0, 0, 0, 0 }; // actual window rect
|
||||
@@ -158,7 +159,9 @@ private:
|
||||
DragType dragType_ = DragType::DRAG_UNDEFINED;
|
||||
std::vector<Rect> touchHotAreas_; // coordinates relative to window.
|
||||
uint32_t accessTokenId_ { 0 };
|
||||
Transform trans_;
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(bool, CustomAnimation, isCustomAnimation, false);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ enum class PropertyChangeAction : uint32_t {
|
||||
ACTION_UPDATE_SET_BRIGHTNESS = 1 << 10,
|
||||
ACTION_UPDATE_MODE_SUPPORT_INFO = 1 << 11,
|
||||
ACTION_UPDATE_TOUCH_HOT_AREA = 1 << 12,
|
||||
ACTION_UPDATE_TRANSFORM_PROPERTY = 1 << 13,
|
||||
};
|
||||
|
||||
struct ModeChangeHotZonesConfig {
|
||||
|
||||
@@ -103,6 +103,11 @@ void WindowProperty::SetAlpha(float alpha)
|
||||
alpha_ = alpha;
|
||||
}
|
||||
|
||||
void WindowProperty::SetTransform(const Transform& trans)
|
||||
{
|
||||
trans_ = trans;
|
||||
}
|
||||
|
||||
void WindowProperty::SetBrightness(float brightness)
|
||||
{
|
||||
brightness_ = brightness;
|
||||
@@ -270,6 +275,11 @@ float WindowProperty::GetAlpha() const
|
||||
return alpha_;
|
||||
}
|
||||
|
||||
Transform WindowProperty::GetTransform() const
|
||||
{
|
||||
return trans_;
|
||||
}
|
||||
|
||||
float WindowProperty::GetBrightness() const
|
||||
{
|
||||
return brightness_;
|
||||
@@ -407,7 +417,6 @@ bool WindowProperty::MapMarshalling(Parcel& parcel) const
|
||||
|
||||
void WindowProperty::MapUnmarshalling(Parcel& parcel, WindowProperty* property)
|
||||
{
|
||||
std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap;
|
||||
uint32_t size = parcel.ReadUint32();
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
WindowType type = static_cast<WindowType>(parcel.ReadUint32());
|
||||
@@ -440,6 +449,31 @@ void WindowProperty::UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty*
|
||||
}
|
||||
}
|
||||
|
||||
bool WindowProperty::MarshallingTransform(Parcel& parcel) const
|
||||
{
|
||||
return parcel.WriteFloat(trans_.pivotX_) && parcel.WriteFloat(trans_.pivotY_) &&
|
||||
parcel.WriteFloat(trans_.scaleX_) && parcel.WriteFloat(trans_.scaleY_) &&
|
||||
parcel.WriteFloat(trans_.rotationX_) && parcel.WriteFloat(trans_.rotationY_) &&
|
||||
parcel.WriteFloat(trans_.rotationZ_) && parcel.WriteFloat(trans_.translateX_) &&
|
||||
parcel.WriteFloat(trans_.translateY_) && parcel.WriteFloat(trans_.translateZ_);
|
||||
}
|
||||
|
||||
void WindowProperty::UnmarshallingTransform(Parcel& parcel, WindowProperty* property)
|
||||
{
|
||||
Transform trans;
|
||||
trans.pivotX_ = parcel.ReadFloat();
|
||||
trans.pivotY_ = parcel.ReadFloat();
|
||||
trans.scaleX_ = parcel.ReadFloat();
|
||||
trans.scaleY_ = parcel.ReadFloat();
|
||||
trans.rotationX_ = parcel.ReadFloat();
|
||||
trans.rotationY_ = parcel.ReadFloat();
|
||||
trans.rotationZ_ = parcel.ReadFloat();
|
||||
trans.translateX_ = parcel.ReadFloat();
|
||||
trans.translateY_ = parcel.ReadFloat();
|
||||
trans.translateZ_ = parcel.ReadFloat();
|
||||
property->SetTransform(trans);
|
||||
}
|
||||
|
||||
bool WindowProperty::Marshalling(Parcel& parcel) const
|
||||
{
|
||||
return parcel.WriteString(windowName_) && parcel.WriteInt32(windowRect_.posX_) &&
|
||||
@@ -460,7 +494,8 @@ bool WindowProperty::Marshalling(Parcel& parcel) const
|
||||
parcel.WriteBool(turnScreenOn_) && parcel.WriteBool(keepScreenOn_) &&
|
||||
parcel.WriteUint32(modeSupportInfo_) && parcel.WriteUint32(static_cast<uint32_t>(dragType_)) &&
|
||||
parcel.WriteUint32(originRect_.width_) && parcel.WriteUint32(originRect_.height_) &&
|
||||
parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel) && parcel.WriteUint32(accessTokenId_);
|
||||
parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel) && parcel.WriteUint32(accessTokenId_) &&
|
||||
parcel.WriteBool(isCustomAnimation_) && MarshallingTransform(parcel);
|
||||
}
|
||||
|
||||
WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel)
|
||||
@@ -509,6 +544,8 @@ WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel)
|
||||
property->SetStretchable(parcel.ReadBool());
|
||||
UnmarshallingTouchHotAreas(parcel, property);
|
||||
property->SetAccessTokenId(parcel.ReadUint32());
|
||||
property->SetCustomAnimation(parcel.ReadBool());
|
||||
UnmarshallingTransform(parcel, property);
|
||||
return property;
|
||||
}
|
||||
|
||||
@@ -560,6 +597,9 @@ bool WindowProperty::Write(Parcel& parcel, PropertyChangeAction action)
|
||||
case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA:
|
||||
ret &= MarshallingTouchHotAreas(parcel);
|
||||
break;
|
||||
case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY:
|
||||
ret &= MarshallingTransform(parcel);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -613,6 +653,9 @@ void WindowProperty::Read(Parcel& parcel, PropertyChangeAction action)
|
||||
case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA:
|
||||
UnmarshallingTouchHotAreas(parcel, this);
|
||||
break;
|
||||
case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY:
|
||||
UnmarshallingTransform(parcel, this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -655,6 +698,8 @@ void WindowProperty::CopyFrom(const sptr<WindowProperty>& property)
|
||||
isStretchable_ = property->isStretchable_;
|
||||
touchHotAreas_ = property->touchHotAreas_;
|
||||
accessTokenId_ = property->accessTokenId_;
|
||||
isCustomAnimation_ = property->isCustomAnimation_;
|
||||
trans_ = property->trans_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ public:
|
||||
virtual WMError RequestFocus(uint32_t windowId);
|
||||
virtual WMError GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, AvoidArea& avoidRect);
|
||||
virtual WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level);
|
||||
virtual WMError SetAlpha(uint32_t windowId, float alpha);
|
||||
virtual WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId);
|
||||
virtual void ProcessPointDown(uint32_t windowId, bool isStartDrag = false);
|
||||
virtual void ProcessPointUp(uint32_t windowId);
|
||||
|
||||
@@ -127,13 +127,15 @@ public:
|
||||
virtual WMError SetWindowType(WindowType type) override;
|
||||
virtual WMError SetWindowMode(WindowMode mode) override;
|
||||
virtual WMError SetWindowBackgroundBlur(WindowBlurLevel level) override;
|
||||
virtual WMError SetAlpha(float alpha) override;
|
||||
virtual void SetAlpha(float alpha) override;
|
||||
virtual void SetTransform(const Transform& trans) override;
|
||||
virtual WMError AddWindowFlag(WindowFlag flag) override;
|
||||
virtual WMError RemoveWindowFlag(WindowFlag flag) override;
|
||||
virtual WMError SetWindowFlags(uint32_t flags) override;
|
||||
virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override;
|
||||
virtual WMError SetLayoutFullScreen(bool status) override;
|
||||
virtual WMError SetFullScreen(bool status) override;
|
||||
virtual Transform GetTransform() const override;
|
||||
inline void SetWindowState(WindowState state)
|
||||
{
|
||||
state_ = state;
|
||||
@@ -143,8 +145,8 @@ public:
|
||||
WMError Create(const std::string& parentName,
|
||||
const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
|
||||
virtual WMError Destroy() override;
|
||||
virtual WMError Show(uint32_t reason = 0) override;
|
||||
virtual WMError Hide(uint32_t reason = 0) override;
|
||||
virtual WMError Show(uint32_t reason = 0, bool isCustomAnimation = false) override;
|
||||
virtual WMError Hide(uint32_t reason = 0, bool isCustomAnimation = false) override;
|
||||
virtual WMError MoveTo(int32_t x, int32_t y) override;
|
||||
virtual WMError Resize(uint32_t width, uint32_t height) override;
|
||||
virtual WMError SetKeepScreenOn(bool keepScreenOn) override;
|
||||
|
||||
@@ -113,13 +113,6 @@ WMError WindowAdapter::SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLeve
|
||||
return windowManagerServiceProxy_->SetWindowBackgroundBlur(windowId, level);
|
||||
}
|
||||
|
||||
WMError WindowAdapter::SetAlpha(uint32_t windowId, float alpha)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
|
||||
|
||||
return windowManagerServiceProxy_->SetAlpha(windowId, alpha);
|
||||
}
|
||||
|
||||
void WindowAdapter::ProcessPointDown(uint32_t windowId, bool isStartDrag)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN();
|
||||
|
||||
+28
-8
@@ -48,7 +48,8 @@ const WindowImpl::ColorSpaceConvertMap WindowImpl::colorSpaceConvertMap[] = {
|
||||
std::map<std::string, std::pair<uint32_t, sptr<Window>>> WindowImpl::windowMap_;
|
||||
std::map<uint32_t, std::vector<sptr<WindowImpl>>> WindowImpl::subWindowMap_;
|
||||
std::map<uint32_t, std::vector<sptr<WindowImpl>>> WindowImpl::appFloatingWindowMap_;
|
||||
|
||||
static int ctorCnt = 0;
|
||||
static int dtorCnt = 0;
|
||||
WindowImpl::WindowImpl(const sptr<WindowOption>& option)
|
||||
{
|
||||
property_ = new (std::nothrow) WindowProperty();
|
||||
@@ -57,7 +58,6 @@ WindowImpl::WindowImpl(const sptr<WindowOption>& option)
|
||||
property_->SetWindowType(option->GetWindowType());
|
||||
property_->SetWindowMode(option->GetWindowMode());
|
||||
property_->SetWindowBackgroundBlur(option->GetWindowBackgroundBlur());
|
||||
property_->SetAlpha(option->GetAlpha());
|
||||
property_->SetFullScreen(option->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN);
|
||||
property_->SetFocusable(option->GetFocusable());
|
||||
property_->SetTouchable(option->GetTouchable());
|
||||
@@ -81,6 +81,7 @@ WindowImpl::WindowImpl(const sptr<WindowOption>& option)
|
||||
struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
|
||||
rsSurfaceNodeConfig.SurfaceNodeName = property_->GetWindowName();
|
||||
surfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig);
|
||||
WLOGFI("WindowImpl constructor Count: %{public}d name: %{public}s", ++ctorCnt, property_->GetWindowName().c_str());
|
||||
}
|
||||
|
||||
void WindowImpl::InitListenerHandler()
|
||||
@@ -104,7 +105,8 @@ WindowImpl::~WindowImpl()
|
||||
if (eventHandler_ != nullptr) {
|
||||
eventHandler_.reset();
|
||||
}
|
||||
WLOGFI("windowName: %{public}s, windowId: %{public}d", GetWindowName().c_str(), GetWindowId());
|
||||
WLOGFI("windowName: %{public}s, windowId: %{public}d, dtorCnt: %{public}d, surfaceNode:%{public}d",
|
||||
GetWindowName().c_str(), GetWindowId(), ++dtorCnt, static_cast<uint32_t>(surfaceNode_.use_count()));
|
||||
Destroy();
|
||||
}
|
||||
|
||||
@@ -364,14 +366,29 @@ WMError WindowImpl::SetWindowBackgroundBlur(WindowBlurLevel level)
|
||||
return SingletonContainer::Get<WindowAdapter>().SetWindowBackgroundBlur(property_->GetWindowId(), level);
|
||||
}
|
||||
|
||||
WMError WindowImpl::SetAlpha(float alpha)
|
||||
void WindowImpl::SetAlpha(float alpha)
|
||||
{
|
||||
WLOGFI("[Client] Window %{public}u alpha %{public}f", property_->GetWindowId(), alpha);
|
||||
if (!IsWindowValid()) {
|
||||
return WMError::WM_ERROR_INVALID_WINDOW;
|
||||
return;
|
||||
}
|
||||
property_->SetAlpha(alpha);
|
||||
return SingletonContainer::Get<WindowAdapter>().SetAlpha(property_->GetWindowId(), alpha);
|
||||
surfaceNode_->SetAlpha(alpha);
|
||||
}
|
||||
|
||||
void WindowImpl::SetTransform(const Transform& trans)
|
||||
{
|
||||
WLOGFI("[Client] Window %{public}u SetTransform", property_->GetWindowId());
|
||||
if (!IsWindowValid()) {
|
||||
return;
|
||||
}
|
||||
property_->SetTransform(trans);
|
||||
UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY);
|
||||
}
|
||||
|
||||
Transform WindowImpl::GetTransform() const
|
||||
{
|
||||
return property_->GetTransform();
|
||||
}
|
||||
|
||||
WMError WindowImpl::AddWindowFlag(WindowFlag flag)
|
||||
@@ -833,7 +850,7 @@ WMError WindowImpl::Destroy(bool needNotifyServer)
|
||||
return ret;
|
||||
}
|
||||
|
||||
WMError WindowImpl::Show(uint32_t reason)
|
||||
WMError WindowImpl::Show(uint32_t reason, bool isCustomAnimation)
|
||||
{
|
||||
WLOGFI("[Client] Window [name:%{public}s, id:%{public}u] Show, reason:%{public}u",
|
||||
name_.c_str(), property_->GetWindowId(), reason);
|
||||
@@ -864,6 +881,8 @@ WMError WindowImpl::Show(uint32_t reason)
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
SetDefaultOption();
|
||||
// set true success when transitionController exist; set false when complete transition
|
||||
property_->SetCustomAnimation(isCustomAnimation);
|
||||
WMError ret = SingletonContainer::Get<WindowAdapter>().AddWindow(property_);
|
||||
RecordLifeCycleExceptionEvent(LifeCycleEvent::SHOW_EVENT, ret);
|
||||
if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) {
|
||||
@@ -876,7 +895,7 @@ WMError WindowImpl::Show(uint32_t reason)
|
||||
return ret;
|
||||
}
|
||||
|
||||
WMError WindowImpl::Hide(uint32_t reason)
|
||||
WMError WindowImpl::Hide(uint32_t reason, bool isCustomAnimation)
|
||||
{
|
||||
WLOGFI("[Client] Window [name:%{public}s, id:%{public}u] Hide", name_.c_str(), property_->GetWindowId());
|
||||
if (!IsWindowValid()) {
|
||||
@@ -892,6 +911,7 @@ WMError WindowImpl::Hide(uint32_t reason)
|
||||
WLOGFI("window is already hidden id: %{public}u", property_->GetWindowId());
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
property_->SetCustomAnimation(isCustomAnimation);
|
||||
WMError ret = SingletonContainer::Get<WindowAdapter>().RemoveWindow(property_->GetWindowId());
|
||||
RecordLifeCycleExceptionEvent(LifeCycleEvent::HIDE_EVENT, ret);
|
||||
if (ret != WMError::WM_OK) {
|
||||
|
||||
@@ -50,11 +50,6 @@ void WindowOption::SetWindowBackgroundBlur(WindowBlurLevel level)
|
||||
level_ = level;
|
||||
}
|
||||
|
||||
void WindowOption::SetAlpha(float alpha)
|
||||
{
|
||||
alpha_ = alpha;
|
||||
}
|
||||
|
||||
void WindowOption::SetFocusable(bool isFocusable)
|
||||
{
|
||||
focusable_ = isFocusable;
|
||||
@@ -122,11 +117,6 @@ WindowBlurLevel WindowOption::GetWindowBackgroundBlur() const
|
||||
return level_;
|
||||
}
|
||||
|
||||
float WindowOption::GetAlpha() const
|
||||
{
|
||||
return alpha_;
|
||||
}
|
||||
|
||||
bool WindowOption::GetFocusable() const
|
||||
{
|
||||
return focusable_;
|
||||
|
||||
@@ -77,9 +77,6 @@ size_t InitWindowOption1(WindowOption &windowOption, const uint8_t *data, size_t
|
||||
uint32_t level;
|
||||
startPos += GetObject<uint32_t>(level, data + startPos, size - startPos);
|
||||
windowOption.SetWindowBackgroundBlur(static_cast<WindowBlurLevel>(level));
|
||||
float alpha;
|
||||
startPos += GetObject<float>(alpha, data + startPos, size - startPos);
|
||||
windowOption.SetAlpha(alpha);
|
||||
bool focusable;
|
||||
startPos += GetObject<bool>(focusable, data + startPos, size - startPos);
|
||||
windowOption.SetFocusable(focusable);
|
||||
|
||||
@@ -80,7 +80,7 @@ HWTEST_F(WindowEffectTest, WindowEffect02, Function | MediumTest | Level3)
|
||||
{
|
||||
const sptr<Window>& window = utils::CreateTestWindow(fullScreenAppInfo_);
|
||||
|
||||
ASSERT_EQ(WMError::WM_OK, window->SetAlpha(1.0f));
|
||||
window->SetAlpha(1.0f);
|
||||
ASSERT_EQ(1.0f, window->GetAlpha());
|
||||
|
||||
window->Destroy();
|
||||
|
||||
@@ -30,7 +30,6 @@ public:
|
||||
MOCK_METHOD0(ClearWindowAdapter, void());
|
||||
MOCK_METHOD1(DestroyWindow, WMError(uint32_t windowId));
|
||||
MOCK_METHOD2(SetWindowBackgroundBlur, WMError(uint32_t windowId, WindowBlurLevel level));
|
||||
MOCK_METHOD2(SetAlpha, WMError(uint32_t windowId, float alpha));
|
||||
MOCK_METHOD2(UpdateProperty, WMError(sptr<WindowProperty>& windowProperty, PropertyChangeAction action));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -57,26 +57,10 @@ HWTEST_F(WindowEffectTest, WindowEffect01, Function | SmallTest | Level2)
|
||||
|
||||
/**
|
||||
* @tc.name: WindowEffect02
|
||||
* @tc.desc: windowOption: set window alpha/ get window alpha
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowEffectTest, WindowEffect02, Function | SmallTest | Level2)
|
||||
{
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetAlpha(0.0f);
|
||||
ASSERT_EQ(0.0f, option->GetAlpha());
|
||||
option->SetAlpha(0.5f);
|
||||
ASSERT_EQ(0.5f, option->GetAlpha());
|
||||
option->SetAlpha(1.0f);
|
||||
ASSERT_EQ(1.0f, option->GetAlpha());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: WindowEffect03
|
||||
* @tc.desc: WindowImp: Create window with no default option, get and check Property
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowEffectTest, WindowEffect03, Function | SmallTest | Level2)
|
||||
HWTEST_F(WindowEffectTest, WindowEffect02, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
@@ -92,20 +76,18 @@ HWTEST_F(WindowEffectTest, WindowEffect03, Function | SmallTest | Level2)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: WindowEffect04
|
||||
* @tc.name: WindowEffect03
|
||||
* @tc.desc: Create window with no default option, get and check Property
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowEffectTest, WindowEffect04, Function | SmallTest | Level2)
|
||||
HWTEST_F(WindowEffectTest, WindowEffect03, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetAlpha(0.1f);
|
||||
|
||||
sptr<WindowImpl> window = new WindowImpl(option);
|
||||
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
|
||||
ASSERT_EQ(WMError::WM_OK, window->Create(""));
|
||||
|
||||
window->SetAlpha(0.1f);
|
||||
ASSERT_EQ(0.1f, window->GetAlpha());
|
||||
|
||||
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
|
||||
@@ -113,11 +95,11 @@ HWTEST_F(WindowEffectTest, WindowEffect04, Function | SmallTest | Level2)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: WindowEffect05
|
||||
* @tc.name: WindowEffect04
|
||||
* @tc.desc: set window effect parameters throw window, and check parameters.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowEffectTest, WindowEffect05, Function | SmallTest | Level2)
|
||||
HWTEST_F(WindowEffectTest, WindowEffect04, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
@@ -135,32 +117,11 @@ HWTEST_F(WindowEffectTest, WindowEffect05, Function | SmallTest | Level2)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: WindowEffect06
|
||||
* @tc.desc: set window effect parameters throw window, and check parameters.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowEffectTest, WindowEffect06, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
sptr<WindowImpl> window = new WindowImpl(option);
|
||||
|
||||
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
|
||||
ASSERT_EQ(WMError::WM_OK, window->Create(""));
|
||||
EXPECT_CALL(m->Mock(), SetAlpha(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
|
||||
ASSERT_EQ(WMError::WM_OK, window->SetAlpha(0.1f));
|
||||
ASSERT_EQ(0.1f, window->GetAlpha());
|
||||
|
||||
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
|
||||
window->Destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: WindowEffect07
|
||||
* @tc.name: WindowEffect05
|
||||
* @tc.desc: WindowImp: Create window with default option, get and check Property
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowEffectTest, WindowEffect07, Function | SmallTest | Level2)
|
||||
HWTEST_F(WindowEffectTest, WindowEffect05, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
|
||||
@@ -77,7 +77,6 @@ public:
|
||||
WMError DestroyWindow(uint32_t windowId, bool onlySelf = false) override;
|
||||
WMError RequestFocus(uint32_t windowId) override;
|
||||
WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level) override;
|
||||
WMError SetAlpha(uint32_t windowId, float alpha) override;
|
||||
AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) override;
|
||||
void ProcessPointDown(uint32_t windowId, bool isStartDrag) override;
|
||||
void ProcessPointUp(uint32_t windowId) override;
|
||||
|
||||
@@ -54,7 +54,6 @@ public:
|
||||
void SetSystemBarProperty(WindowType type, const SystemBarProperty& property);
|
||||
void SetWindowMode(WindowMode mode);
|
||||
void SetWindowBackgroundBlur(WindowBlurLevel level);
|
||||
void SetAlpha(float alpha);
|
||||
void SetBrightness(float brightness);
|
||||
void SetFocusable(bool focusable);
|
||||
void SetTouchable(bool touchable);
|
||||
@@ -85,7 +84,6 @@ public:
|
||||
WindowType GetWindowType() const;
|
||||
WindowMode GetWindowMode() const;
|
||||
WindowBlurLevel GetWindowBackgroundBlur() const;
|
||||
float GetAlpha() const;
|
||||
float GetBrightness() const;
|
||||
bool IsTurnScreenOn() const;
|
||||
bool IsKeepScreenOn() const;
|
||||
@@ -106,6 +104,7 @@ public:
|
||||
void GetTouchHotAreas(std::vector<Rect>& rects) const;
|
||||
uint32_t GetAccessTokenId() const;
|
||||
|
||||
bool EnableDefaultAnimation(bool propertyEnabled, bool animationPlayed);
|
||||
sptr<WindowNode> parent_;
|
||||
std::vector<sptr<WindowNode>> children_;
|
||||
std::shared_ptr<RSSurfaceNode> surfaceNode_;
|
||||
|
||||
@@ -69,7 +69,6 @@ public:
|
||||
virtual WMError DestroyWindow(uint32_t windowId, bool onlySelf = false) = 0;
|
||||
virtual WMError RequestFocus(uint32_t windowId) = 0;
|
||||
virtual WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level) = 0;
|
||||
virtual WMError SetAlpha(uint32_t windowId, float alpha) = 0;
|
||||
virtual AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) = 0;
|
||||
virtual WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) = 0;
|
||||
virtual void ProcessPointDown(uint32_t windowId, bool isStartDrag) = 0;
|
||||
|
||||
@@ -37,7 +37,6 @@ public:
|
||||
WMError DestroyWindow(uint32_t windowId, bool onlySelf = false) override;
|
||||
WMError RequestFocus(uint32_t windowId) override;
|
||||
WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level) override;
|
||||
WMError SetAlpha(uint32_t windowId, float alpha) override;
|
||||
AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) override;
|
||||
WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override;
|
||||
void ProcessPointDown(uint32_t windowId, bool isStartDrag) override;
|
||||
|
||||
@@ -397,21 +397,6 @@ WMError WindowController::SetWindowBackgroundBlur(uint32_t windowId, WindowBlurL
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
|
||||
WMError WindowController::SetAlpha(uint32_t windowId, float dstAlpha)
|
||||
{
|
||||
auto node = windowRoot_->GetWindowNode(windowId);
|
||||
if (node == nullptr) {
|
||||
WLOGFE("could not find window");
|
||||
return WMError::WM_ERROR_NULLPTR;
|
||||
}
|
||||
|
||||
WLOGFI("WindowEffect WindowController SetAlpha alpha: %{public}f", dstAlpha);
|
||||
node->SetAlpha(dstAlpha);
|
||||
|
||||
FlushWindowInfo(windowId);
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
|
||||
void WindowController::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
|
||||
const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
|
||||
{
|
||||
@@ -847,6 +832,7 @@ WMError WindowController::UpdateProperty(sptr<WindowProperty>& property, Propert
|
||||
property->GetTouchHotAreas(rects);
|
||||
return UpdateTouchHotAreas(node, rects);
|
||||
}
|
||||
case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -455,13 +455,6 @@ WMError WindowManagerService::SetWindowBackgroundBlur(uint32_t windowId, WindowB
|
||||
}).get();
|
||||
}
|
||||
|
||||
WMError WindowManagerService::SetAlpha(uint32_t windowId, float alpha)
|
||||
{
|
||||
return wmsTaskLooper_->ScheduleTask([this, windowId, alpha]() {
|
||||
return windowController_->SetAlpha(windowId, alpha);
|
||||
}).get();
|
||||
}
|
||||
|
||||
AvoidArea WindowManagerService::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType)
|
||||
{
|
||||
return wmsTaskLooper_->ScheduleTask([this, windowId, avoidAreaType]() {
|
||||
@@ -613,6 +606,12 @@ WMError WindowManagerService::UpdateProperty(sptr<WindowProperty>& windowPropert
|
||||
WLOGFE("property is invalid");
|
||||
return WMError::WM_ERROR_NULLPTR;
|
||||
}
|
||||
if (action == PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY) {
|
||||
wmsTaskLooper_->PostTask([this, windowProperty, action]() mutable {
|
||||
windowController_->UpdateProperty(windowProperty, action);
|
||||
});
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
return wmsTaskLooper_->ScheduleTask([this, &windowProperty, action]() {
|
||||
WM_SCOPED_TRACE("wms:UpdateProperty");
|
||||
WMError res = windowController_->UpdateProperty(windowProperty, action);
|
||||
|
||||
@@ -100,13 +100,6 @@ void WindowNode::SetWindowBackgroundBlur(WindowBlurLevel level)
|
||||
surfaceNode_->SetBackgroundFilter(RSFilter::CreateBlurFilter(blurRadiusX, blurRadiusY));
|
||||
}
|
||||
|
||||
void WindowNode::SetAlpha(float alpha)
|
||||
{
|
||||
property_->SetAlpha(alpha);
|
||||
WLOGFI("WindowEffect WinodwNode SetAlpha alpha:%{public}f", alpha);
|
||||
surfaceNode_->SetAlpha(alpha);
|
||||
}
|
||||
|
||||
void WindowNode::SetBrightness(float brightness)
|
||||
{
|
||||
property_->SetBrightness(brightness);
|
||||
@@ -273,9 +266,9 @@ WindowBlurLevel WindowNode::GetWindowBackgroundBlur() const
|
||||
return property_->GetWindowBackgroundBlur();
|
||||
}
|
||||
|
||||
float WindowNode::GetAlpha() const
|
||||
bool WindowNode::EnableDefaultAnimation(bool propertyEnabled, bool animationPlayed)
|
||||
{
|
||||
return property_->GetAlpha();
|
||||
return (propertyEnabled && (!animationPlayed) && (!property_->GetCustomAnimation()) && (!isAppCrash_));
|
||||
}
|
||||
|
||||
float WindowNode::GetBrightness() const
|
||||
|
||||
@@ -387,6 +387,10 @@ void WindowNodeContainer::UpdateWindowTree(sptr<WindowNode>& node)
|
||||
bool WindowNodeContainer::UpdateRSTree(sptr<WindowNode>& node, DisplayId displayId, bool isAdd, bool animationPlayed)
|
||||
{
|
||||
WM_FUNCTION_TRACE();
|
||||
if (node->GetWindowProperty()->GetCustomAnimation()) {
|
||||
WLOGFI("not need to update RsTree since SystemWindowAnimation is playing");
|
||||
return false;
|
||||
}
|
||||
if (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_COMPONENT) {
|
||||
WLOGFI("WINDOW_TYPE_APP_COMPONENT not need to update RsTree");
|
||||
return true;
|
||||
@@ -413,7 +417,7 @@ bool WindowNodeContainer::UpdateRSTree(sptr<WindowNode>& node, DisplayId display
|
||||
}
|
||||
};
|
||||
|
||||
if (IsWindowAnimationEnabled && !animationPlayed && !node->isAppCrash_) {
|
||||
if (node->EnableDefaultAnimation(IsWindowAnimationEnabled, animationPlayed)) {
|
||||
WLOGFI("add or remove window with animation");
|
||||
// default transition duration: 350ms
|
||||
static const RSAnimationTimingProtocol timingProtocol(350);
|
||||
|
||||
@@ -187,32 +187,6 @@ WMError WindowManagerProxy::SetWindowBackgroundBlur(uint32_t windowId, WindowBlu
|
||||
return static_cast<WMError>(ret);
|
||||
}
|
||||
|
||||
WMError WindowManagerProxy::SetAlpha(uint32_t windowId, float alpha)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("WriteInterfaceToken failed");
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
if (!data.WriteUint32(windowId)) {
|
||||
WLOGFE("Write windowId failed");
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
if (!data.WriteFloat(alpha)) {
|
||||
WLOGFE("Write alpha failed");
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_ALPHA),
|
||||
data, reply, option) != ERR_NONE) {
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
|
||||
int32_t ret = reply.ReadInt32();
|
||||
return static_cast<WMError>(ret);
|
||||
}
|
||||
|
||||
AvoidArea WindowManagerProxy::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type)
|
||||
{
|
||||
MessageParcel data;
|
||||
|
||||
@@ -81,13 +81,6 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M
|
||||
reply.WriteInt32(static_cast<int32_t>(errCode));
|
||||
break;
|
||||
}
|
||||
case WindowManagerMessage::TRANS_ID_SET_ALPHA: {
|
||||
uint32_t windowId = data.ReadUint32();
|
||||
float alpha = data.ReadFloat();
|
||||
WMError errCode = SetAlpha(windowId, alpha);
|
||||
reply.WriteInt32(static_cast<int32_t>(errCode));
|
||||
break;
|
||||
}
|
||||
case WindowManagerMessage::TRANS_ID_GET_AVOID_AREA: {
|
||||
uint32_t windowId = data.ReadUint32();
|
||||
AvoidAreaType avoidAreaType = static_cast<AvoidAreaType>(data.ReadUint32());
|
||||
|
||||
Reference in New Issue
Block a user