• 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 #include "frameworks/bridge/js_frontend/engine/jsi/jsi_image_animator_bridge.h"
17 
18 #include "frameworks/bridge/common/dom/dom_image_animator.h"
19 #include "frameworks/bridge/js_frontend/engine/jsi/jsi_engine.h"
20 
21 namespace OHOS::Ace::Framework {
22 
JsGetState(const shared_ptr<JsRuntime> & runtime,NodeId nodeId)23 shared_ptr<JsValue> JsiImageAnimatorBridge::JsGetState(const shared_ptr<JsRuntime>& runtime, NodeId nodeId)
24 {
25     if (!runtime) {
26         LOGE("JsGetState failed. runtime is null.");
27         return nullptr;
28     }
29     auto engine = static_cast<JsiEngineInstance*>(runtime->GetEmbedderData());
30     if (!engine) {
31         LOGE("JsGetState failed. engine is null.");
32         return runtime->NewUndefined();
33     }
34     auto page = engine->GetRunningPage();
35     if (!page) {
36         LOGE("JsGetState failed. page is null.");
37         return runtime->NewUndefined();
38     }
39     const char* state = "";
40     auto task = [nodeId, page, &state]() {
41         auto domDoc = page->GetDomDocument();
42         if (!domDoc) {
43             return;
44         }
45         auto domImageAnimator = AceType::DynamicCast<DOMImageAnimator>(domDoc->GetDOMNodeById(nodeId));
46         if (!domImageAnimator) {
47             return;
48         }
49         state = domImageAnimator->GetState();
50     };
51     auto delegate = engine->GetFrontendDelegate();
52     if (!delegate) {
53         LOGE("JsGetCurrentOffset failed. delegate is null.");
54         return runtime->NewUndefined();
55     }
56     delegate->PostSyncTaskToPage(task);
57     return runtime->NewString(state);
58 }
59 
60 } // namespace OHOS::Ace::Framework
61