• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_QUICKJS_ANIMATION_BRIDGE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_QUICKJS_ANIMATION_BRIDGE_H
18 
19 #include <map>
20 #include <string>
21 
22 #include "frameworks/bridge/common/dom/dom_node.h"
23 #include "frameworks/bridge/js_frontend/engine/common/base_animation_bridge.h"
24 #include "frameworks/bridge/js_frontend/engine/quickjs/qjs_utils.h"
25 #include "frameworks/bridge/js_frontend/frontend_delegate.h"
26 #include "frameworks/bridge/js_frontend/js_command.h"
27 
28 namespace OHOS::Ace::Framework {
29 
30 class JsAcePage;
31 
32 class AnimationBridgeUtils {
33 public:
34     static JSValue CreateAnimationContext(JSContext* ctx, int32_t pageId, NodeId nodeId);
35     static JSValue JsAnimationPlay(JSContext* ctx, JSValueConst value, int32_t argc, JSValueConst* argv);
36     static JSValue JsAnimationFinish(JSContext* ctx, JSValueConst value, int32_t argc, JSValueConst* argv);
37     static JSValue JsAnimationPause(JSContext* ctx, JSValueConst value, int32_t argc, JSValueConst* argv);
38     static JSValue JsAnimationCancel(JSContext* ctx, JSValueConst value, int32_t argc, JSValueConst* argv);
39     static JSValue JsAnimationReverse(JSContext* ctx, JSValueConst value, int32_t argc, JSValueConst* argv);
40     static JSValue JsAnimationPlayStateGet(JSContext* ctx, JSValueConst value);
41     static JSValue JsAnimationStartTimeGet(JSContext* ctx, JSValueConst value);
42     static JSValue JsAnimationPendingGet(JSContext* ctx, JSValueConst value);
43     static JSValue JsAnimationPlayStateSet(JSContext* ctx, JSValueConst value, JSValueConst proto);
44     static JSValue JsAnimationStartTimeSet(JSContext* ctx, JSValueConst value, JSValueConst startTime);
45     static JSValue JsAnimationPendingSet(JSContext* ctx, JSValueConst value, JSValueConst pending);
46 };
47 
48 class AnimationBridge : public BaseAnimationBridge {
49     DECLARE_ACE_TYPE(AnimationBridge, BaseAnimationBridge)
50 
51 public:
52     AnimationBridge(JSContext* ctx, JSValue animationContext, NodeId nodeId);
53     ~AnimationBridge() override;
54     void OnJsEngineDestroy() override;
GetJsObject()55     JSValue GetJsObject()
56     {
57         return animationContext_;
58     }
59 
60     void JsCreateAnimation(const RefPtr<JsAcePage>& page, const std::string& param);
61     void SetPlayStateCallbacks(RefPtr<Animator>& animator);
62     void SetPlayStateCallbacksWithListenerId(RefPtr<Animator>& animator);
63 
64 private:
65     JSContext* ctx_ = nullptr;
66     JSValue animationContext_;
67     NodeId nodeId_ = -1;
68     IdType finishListenerId_ = 0;
69     IdType idleListenerId_ = 0;
70 };
71 
72 class AnimationBridgeTaskCreate : public AnimationBridgeTask {
73     DECLARE_ACE_TYPE(AnimationBridgeTaskCreate, AnimationBridgeTask)
74 public:
75     AnimationBridgeTaskCreate(const RefPtr<AnimationBridge>& animationBridge, std::string param);
76     ~AnimationBridgeTaskCreate() override = default;
77     void AnimationBridgeTaskFunc(const RefPtr<JsAcePage>& page, NodeId nodeId) override;
78 
79 private:
80     RefPtr<AnimationBridge> animationBridge_;
81     std::string param_;
82 };
83 
84 class AnimationBridgeTaskOperation : public AnimationBridgeTask {
DECLARE_ACE_TYPE(AnimationBridgeTaskOperation,AnimationBridgeTask)85     DECLARE_ACE_TYPE(AnimationBridgeTaskOperation, AnimationBridgeTask)
86 public:
87     explicit AnimationBridgeTaskOperation(AnimationOperation operation) : operation_(operation) {};
88     ~AnimationBridgeTaskOperation() override = default;
89     void AnimationBridgeTaskFunc(const RefPtr<JsAcePage>& page, NodeId nodeId) override;
90 
91 private:
92     AnimationOperation operation_ = AnimationOperation::NONE;
93 };
94 
95 class AnimationBridgeTaskStartTime : public AnimationBridgeTask {
DECLARE_ACE_TYPE(AnimationBridgeTaskStartTime,AnimationBridgeTask)96     DECLARE_ACE_TYPE(AnimationBridgeTaskStartTime, AnimationBridgeTask)
97 public:
98     explicit AnimationBridgeTaskStartTime(int32_t startTime) : startTime_(startTime) {}
99     ~AnimationBridgeTaskStartTime() override = default;
100     void AnimationBridgeTaskFunc(const RefPtr<JsAcePage>& page, NodeId nodeId) override;
101 
102 private:
103     int32_t startTime_;
104 };
105 
106 } // namespace OHOS::Ace::Framework
107 
108 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_QUICKJS_ANIMATION_BRIDGE_H
109