1 /* 2 * Copyright (c) 2021-2022 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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_DRAG_FUNCTION_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_DRAG_FUNCTION_H 18 19 #include "frameworks/bridge/declarative_frontend/engine/bindings.h" 20 #include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" 21 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" 22 23 namespace OHOS::Ace::Framework { 24 class JsDragFunction : public JsFunction { 25 DECLARE_ACE_TYPE(JsDragFunction, JsFunction); 26 27 public: JsDragFunction(const JSRef<JSFunc> & jsFunction)28 explicit JsDragFunction(const JSRef<JSFunc>& jsFunction) : JsFunction(JSRef<JSObject>(), jsFunction) {} 29 static void JSBind(BindingTarget globalObj); 30 ~JsDragFunction()31 ~JsDragFunction() override {}; 32 void Execute(); 33 JSRef<JSVal> Execute(const RefPtr<DragEvent>& info); 34 JSRef<JSVal> ItemDragStartExecute(const ItemDragInfo& info, int32_t itemIndex); 35 void ItemDragEnterExecute(const ItemDragInfo& info); 36 void ItemDragMoveExecute(const ItemDragInfo& info, int32_t itemIndex, int32_t insertIndex); 37 void ItemDragLeaveExecute(const ItemDragInfo& info, int32_t itemIndex); 38 void ItemDropExecute(const ItemDragInfo& info, int32_t itemIndex, int32_t insertIndex, bool isSuccess); 39 void PreDragExecute(const PreDragStatus preDragStatus); 40 JSRef<JSVal> Execute(const RefPtr<DragEvent>& info, const std::string& extraParams); 41 JSRef<JSVal> DragSpringLoadingExecute(const RefPtr<DragSpringLoadingContext>& info); 42 43 private: 44 JSRef<JSObject> CreateDragEvent(const RefPtr<DragEvent>& info); 45 JSRef<JSObject> CreateSpringLoadingContext(const RefPtr<DragSpringLoadingContext>& info); 46 JSRef<JSObject> CreatePasteData(const RefPtr<PasteData>& info); 47 JSRef<JSObject> CreateItemDragInfo(const ItemDragInfo& info); 48 }; 49 50 class JsDragEvent : public Referenced { 51 public: 52 static void JSBind(BindingTarget globalObj); 53 void SetJsPasteData(const JSRef<JSObject>& jsPasteData); 54 void GetJsPasteData(const JSCallbackInfo& args); 55 void GetScreenX(const JSCallbackInfo& args); 56 void GetScreenY(const JSCallbackInfo& args); 57 void GetGlobalDisplayX(const JSCallbackInfo& args); 58 void GetGlobalDisplayY(const JSCallbackInfo& args); 59 void GetDisplayId(const JSCallbackInfo& args); 60 void GetX(const JSCallbackInfo& args); 61 void GetY(const JSCallbackInfo& args); 62 void GetDragSource(const JSCallbackInfo& args); 63 void IsRemote(const JSCallbackInfo& args); 64 void GetDescription(const JSCallbackInfo& args); 65 void SetDescription(const JSCallbackInfo& args); 66 void GetVelocityX(const JSCallbackInfo& args); 67 void GetVelocityY(const JSCallbackInfo& args); 68 void GetModifierKeyState(const JSCallbackInfo& args); 69 void ExecuteDropAnimation(const JSCallbackInfo& args); 70 void GetVelocity(const JSCallbackInfo& args); 71 void SetData(const JSCallbackInfo& args); 72 void GetData(const JSCallbackInfo& args); 73 void GetSummary(const JSCallbackInfo& args); 74 void SetResult(const JSCallbackInfo& args); 75 void GetResult(const JSCallbackInfo& args); 76 void GetPreviewRect(const JSCallbackInfo& args); 77 void SetUseCustomDropAnimation(const JSCallbackInfo& args); 78 void GetUseCustomDropAnimation(const JSCallbackInfo& args); 79 void SetDragInfo(const JSCallbackInfo& args); 80 void GetDragInfo(const JSCallbackInfo& args); 81 void SetDragBehavior(const JSCallbackInfo& args); 82 void GetDragBehavior(const JSCallbackInfo& args); SetDragEvent(const RefPtr<DragEvent> & dragEvent)83 void SetDragEvent(const RefPtr<DragEvent>& dragEvent) 84 { 85 dragEvent_ = dragEvent; 86 } 87 GetDragEvent()88 RefPtr<DragEvent> GetDragEvent() const 89 { 90 return dragEvent_; 91 } 92 void StartDataLoading(const JSCallbackInfo& args); 93 void EnableInternalDropAnimation(const JSCallbackInfo& args); 94 void SetDataLoadParams(const JSCallbackInfo& args); 95 // use for ArkTs1.2 96 int64_t GetDragEventPointer(); 97 static JSRef<JSObject> CreateDragEvent(void* dragEventPtr); 98 99 private: 100 static void Constructor(const JSCallbackInfo& args); 101 static void Destructor(JsDragEvent* dragEvent); 102 JSRef<JSObject> CreateRectangle(const Rect& info); 103 104 RefPtr<DragEvent> dragEvent_; 105 JSRef<JSObject> jsPasteData_; 106 }; 107 108 class JsDragSpringLoadingContext : public Referenced { 109 public: 110 static void JSBind(BindingTarget globalObj); 111 void GetState(const JSCallbackInfo& args); 112 void SetState(const JSCallbackInfo& args); 113 void GetCurrentNotifySequence(const JSCallbackInfo& args); 114 void SetCurrentNotifySequence(const JSCallbackInfo& args); 115 void GetDragInfos(const JSCallbackInfo& args); 116 void SetDragInfos(const JSCallbackInfo& args); 117 void GetCurrentConfig(const JSCallbackInfo& args); 118 void SetCurrentConfig(const JSCallbackInfo& args); 119 void Abort(const JSCallbackInfo& args); 120 void UpdateConfiguration(const JSCallbackInfo& args); GetDragSpringLoadingConfiguration()121 const RefPtr<NG::DragSpringLoadingConfiguration>& GetDragSpringLoadingConfiguration() 122 { 123 return context_->GetDragSpringLoadingConfiguration(); 124 } SetDragSpringLoadingConfiguration(const RefPtr<NG::DragSpringLoadingConfiguration> & dragSpringLoadingConfiguration)125 void SetDragSpringLoadingConfiguration(const RefPtr<NG::DragSpringLoadingConfiguration>& dragSpringLoadingConfiguration) 126 { 127 context_->SetDragSpringLoadingConfiguration(dragSpringLoadingConfiguration); 128 } SetContext(const RefPtr<DragSpringLoadingContext> & context)129 void SetContext(const RefPtr<DragSpringLoadingContext>& context) 130 { 131 context_ = context; 132 } 133 GetContext()134 RefPtr<DragSpringLoadingContext> GetContext() const 135 { 136 return context_; 137 } 138 139 private: 140 static void Constructor(const JSCallbackInfo& args); 141 static void Destructor(JsDragSpringLoadingContext* springLoadingContext); 142 143 RefPtr<DragSpringLoadingContext> context_; 144 }; 145 } // namespace OHOS::Ace::Framework 146 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_DRAG_FUNCTION_H 147