1 /* 2 * Copyright (c) 2021-2023 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_JS_VIEW_JS_UTILS_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_UTILS_H 18 19 #include "napi/native_api.h" 20 #include "native_engine/native_engine.h" 21 22 #include "base/image/drawing_color_filter.h" 23 #include "base/image/drawing_lattice.h" 24 #include "core/components_ng/pattern/navigation/navigation_options.h" 25 #include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h" 26 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" 27 28 #if !defined(PREVIEW) 29 namespace OHOS::Rosen { 30 class RSNode; 31 } 32 33 namespace OHOS::Ace { 34 class WantWrap; 35 } 36 #endif 37 38 namespace OHOS::Rosen { 39 class VisualEffect; 40 class Filter; 41 class BrightnessBlender; 42 } 43 44 namespace OHOS::Ace::Framework { 45 class ScopeRAII { 46 public: ScopeRAII(napi_env env)47 explicit ScopeRAII(napi_env env) : env_(env) 48 { 49 napi_open_handle_scope(env_, &scope_); 50 } ~ScopeRAII()51 ~ScopeRAII() 52 { 53 napi_close_handle_scope(env_, scope_); 54 }; 55 private: 56 napi_env env_; 57 napi_handle_scope scope_; 58 }; 59 #if !defined(PREVIEW) 60 const std::shared_ptr<Rosen::RSNode> CreateRSNodeFromNapiValue(JSRef<JSVal> obj); 61 RefPtr<OHOS::Ace::WantWrap> CreateWantWrapFromNapiValue(JSRef<JSVal> obj); 62 #endif 63 64 #ifdef PIXEL_MAP_SUPPORTED 65 JSRef<JSVal> ConvertPixmap(const RefPtr<PixelMap>& pixelMap); 66 napi_value ConvertPixmapNapi(const RefPtr<PixelMap>& pixelMap); 67 bool GetPixelMapListFromAnimatedDrawable(JSRef<JSVal> obj, std::vector<RefPtr<PixelMap>>& pixelMaps, 68 int32_t& duration, int32_t& iterations); 69 #endif 70 71 const Rosen::VisualEffect* CreateRSEffectFromNapiValue(JSRef<JSVal> obj); 72 const Rosen::Filter* CreateRSFilterFromNapiValue(JSRef<JSVal> obj); 73 const Rosen::BrightnessBlender* CreateRSBrightnessBlenderFromNapiValue(JSRef<JSVal> obj); 74 std::optional<NG::BorderRadiusProperty> HandleDifferentRadius(JsiRef<JSVal> args); 75 std::optional<NG::BorderRadiusProperty> ParseBorderRadiusAttr(JsiRef<JSVal> args); 76 bool IsDisableEventVersion(); 77 void ParseTextShadowFromShadowObject(const JSRef<JSVal>& shadowObject, std::vector<Shadow>& shadows); 78 bool IsDrawable(const JSRef<JSVal>& jsValue); 79 RefPtr<PixelMap> GetDrawablePixmap(JSRef<JSVal> obj); 80 RefPtr<PixelMap> CreatePixelMapFromNapiValue(const JSRef<JSVal>& obj, NativeEngine* localNativeEngine = nullptr); 81 RefPtr<DrawingColorFilter> CreateDrawingColorFilter(JSRef<JSVal> obj); 82 RefPtr<DrawingLattice> CreateDrawingLattice(JSRef<JSVal> obj); 83 bool CheckRegexValid(const std::string& pattern); 84 napi_env GetCurrentEnv(); 85 } // namespace OHOS::Ace::Framework 86 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_UTILS_H 87