• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h"
20 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
21 
22 #include "napi/native_api.h"
23 #include "native_engine/native_engine.h"
24 
25 #if !defined(PREVIEW)
26 namespace OHOS::Rosen {
27 class RSNode;
28 }
29 
30 namespace OHOS::Ace {
31 class WantWrap;
32 }
33 #endif
34 
35 namespace OHOS::Ace::Framework {
36 class ScopeRAII {
37 public:
ScopeRAII(napi_env env)38     explicit ScopeRAII(napi_env env) : env_(env)
39     {
40         napi_open_handle_scope(env_, &scope_);
41     }
~ScopeRAII()42     ~ScopeRAII()
43     {
44         napi_close_handle_scope(env_, scope_);
45     };
46 private:
47     napi_env env_;
48     napi_handle_scope scope_;
49 };
50 #if !defined(PREVIEW)
51 const std::shared_ptr<Rosen::RSNode> CreateRSNodeFromNapiValue(JSRef<JSVal> obj);
52 RefPtr<OHOS::Ace::WantWrap> CreateWantWrapFromNapiValue(JSRef<JSVal> obj);
53 #endif
54 
55 #ifdef PIXEL_MAP_SUPPORTED
56 JSRef<JSVal> ConvertPixmap(const RefPtr<PixelMap>& pixelMap);
57 napi_value ConvertPixmapNapi(const RefPtr<PixelMap>& pixelMap);
58 #endif
59 
60 bool IsDisableEventVersion();
61 void ParseTextShadowFromShadowObject(const JSRef<JSVal>& shadowObject, std::vector<Shadow>& shadows);
62 bool IsDrawable(const JSRef<JSVal>& jsValue);
63 RefPtr<PixelMap> GetDrawablePixmap(JSRef<JSVal> obj);
64 RefPtr<PixelMap> CreatePixelMapFromNapiValue(JSRef<JSVal> obj);
65 bool CheckRegexValid(const std::string& pattern);
66 } // namespace OHOS::Ace::Framework
67 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_UTILS_H
68