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_V8_V8_SCROLL_VIEW_BRIDGE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_V8_V8_SCROLL_VIEW_BRIDGE_H 18 19 #include "frameworks/bridge/js_frontend/engine/v8/v8_engine.h" 20 21 namespace OHOS::Ace::Framework { 22 23 class V8ComponentApiBridge : virtual public AceType { 24 DECLARE_ACE_TYPE(V8ComponentApiBridge, AceType) 25 26 public: 27 static v8::Local<v8::Object> JsGetScrollOffset(v8::Isolate* isolate, NodeId nodeId); 28 29 static v8::Local<v8::Object> JsGetBoundingRect(v8::Isolate* isolate, NodeId nodeId); 30 31 static void JsScrollTo( 32 const v8::FunctionCallbackInfo<v8::Value>& args, const std::string& arguments, NodeId nodeId); 33 34 static v8::Local<v8::Object> JsAddVisibleListener( 35 const v8::FunctionCallbackInfo<v8::Value>& args, const std::string& arguments, NodeId nodeId); 36 37 static void JsVisibleListenerOn(const v8::FunctionCallbackInfo<v8::Value>& args); 38 static void JsVisibleListenerOff(const v8::FunctionCallbackInfo<v8::Value>& args); 39 }; 40 41 class VisibleListenerCallback : virtual public AceType { DECLARE_ACE_TYPE(VisibleListenerCallback,AceType)42 DECLARE_ACE_TYPE(VisibleListenerCallback, AceType) 43 public: 44 VisibleListenerCallback( 45 const v8::Local<v8::Context>& ctx, v8::Isolate* instance, v8::Local<v8::Function> callback, NodeId nodeId) 46 : instance_(instance), nodeId_(nodeId) 47 { 48 listenCallback_.Reset(instance_, callback); 49 ctx_.Reset(instance_, ctx); 50 } 51 52 ~VisibleListenerCallback() override = default; 53 GetJsObject()54 v8::Local<v8::Function> GetJsObject() 55 { 56 return listenCallback_.Get(instance_); 57 } 58 GetContext()59 v8::Local<v8::Context> GetContext() const 60 { 61 return ctx_.Get(instance_); 62 } 63 GetNodeId()64 NodeId GetNodeId() const 65 { 66 return nodeId_; 67 } 68 69 private: 70 v8::Persistent<v8::Context> ctx_; 71 v8::Isolate* instance_ = nullptr; 72 v8::Persistent<v8::Function> listenCallback_; 73 NodeId nodeId_ = -1; 74 }; 75 76 } // namespace OHOS::Ace::Framework 77 78 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_V8_V8_SCROLL_VIEW_BRIDGE_H 79