1 /* 2 * Copyright (c) 2024 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_LAYOUTMANAGER_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_LAYOUTMANAGER_H 18 19 #include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h" 20 #include "frameworks/core/components/common/properties/text_layout_info.h" 21 #include "frameworks/core/components_ng/pattern/text/layout_info_interface.h" 22 23 namespace OHOS::Ace::Framework { 24 25 struct NapiMap { 26 napi_value instance; 27 napi_value setFunction; 28 }; 29 30 class JSLayoutManager : public Referenced { 31 public: 32 JSLayoutManager() = default; 33 ~JSLayoutManager() override = default; 34 35 static void JSBind(BindingTarget globalObj); 36 Constructor(const JSCallbackInfo & args)37 static void Constructor(const JSCallbackInfo& args) 38 { 39 auto jsLayoutManager = Referenced::MakeRefPtr<JSLayoutManager>(); 40 jsLayoutManager->IncRefCount(); 41 args.SetReturnValue(Referenced::RawPtr(jsLayoutManager)); 42 } 43 Destructor(JSLayoutManager * jsLayoutManager)44 static void Destructor(JSLayoutManager* jsLayoutManager) 45 { 46 if (jsLayoutManager) { 47 jsLayoutManager->DecRefCount(); 48 } 49 } 50 SetLayoutInfoInterface(const WeakPtr<OHOS::Ace::NG::LayoutInfoInterface> & layoutInfoInterface)51 void SetLayoutInfoInterface(const WeakPtr<OHOS::Ace::NG::LayoutInfoInterface>& layoutInfoInterface) 52 { 53 layoutInfoInterface_ = layoutInfoInterface; 54 } 55 56 void GetLineCount(const JSCallbackInfo& args); 57 58 void GetRectsForRange(const JSCallbackInfo& args); 59 60 void GetGlyphPositionAtCoordinate(const JSCallbackInfo& args); 61 62 void DidExceedMaxLines(const JSCallbackInfo& args); 63 64 void GetLineMetrics(const JSCallbackInfo& info); 65 66 Local<panda::ObjectRef> CreateJSRunMetrics(const std::map<size_t, RunMetrics>& mapRunMetrics, 67 const JSCallbackInfo& args); 68 69 Local<panda::ObjectRef> CreateJSFontMetrics(const FontMetrics& fontMetrics, const JSCallbackInfo& args); 70 71 Local<panda::ObjectRef> CreateJSTextStyleResult(const TextStyle& textStyle, const JSCallbackInfo& args); 72 73 private: 74 WeakPtr<OHOS::Ace::NG::LayoutInfoInterface> layoutInfoInterface_; 75 }; 76 } // namespace OHOS::Ace::Framework 77 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_LAYOUTMANAGER_H