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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_TEXT_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_TEXT_COMPONENT_H 18 19 #include <string> 20 21 #include "base/memory/referenced.h" 22 #include "base/utils/macros.h" 23 #include "core/components/box/drag_drop_event.h" 24 #include "core/components/common/layout/constants.h" 25 #include "core/components/common/properties/alignment.h" 26 #include "core/components/common/properties/color.h" 27 #include "core/components/common/properties/shadow.h" 28 #include "core/components/common/properties/text_style.h" 29 #include "core/pipeline/base/component_group.h" 30 #include "core/components/declaration/text/text_declaration.h" 31 32 namespace OHOS::Ace { 33 34 // A component can show text. 35 class ACE_EXPORT TextComponent : public ComponentGroup { 36 DECLARE_ACE_TYPE(TextComponent, ComponentGroup); 37 38 public: 39 explicit TextComponent(const std::string& data); 40 ~TextComponent() override = default; 41 42 RefPtr<RenderNode> CreateRenderNode() override; 43 RefPtr<Element> CreateElement() override; 44 uint32_t Compare(const RefPtr<Component>& component) const override; 45 46 const std::string& GetData() const; 47 void SetData(const std::string& data); 48 49 const TextStyle& GetTextStyle() const; 50 void SetTextStyle(const TextStyle& textStyle); 51 52 const std::optional<TextAlign>& GetAlignment() const; 53 void SetAlignment(const TextAlign& alignment); 54 55 const Color& GetFocusColor() const; 56 void SetFocusColor(const Color& focusColor); 57 58 const CopyOptions& GetCopyOption() const; 59 void SetCopyOption(const CopyOptions& copyOption); 60 61 bool GetMaxWidthLayout() const; 62 void SetMaxWidthLayout(bool isMaxWidthLayout); 63 64 bool GetAutoMaxLines() const; 65 void SetAutoMaxLines(bool autoMaxLines); 66 67 bool IsChanged() const; 68 void SetIsChanged(bool isChanged); 69 70 void SetOnClick(const EventMarker& onClick); 71 72 const RefPtr<TextDeclaration>& GetDeclaration() const; 73 void SetDeclaration(const RefPtr<TextDeclaration>& declaration); 74 Dimension GetDeclarationHeight() const; 75 76 void SetRemoteMessageEvent(const EventMarker& eventId); 77 GetOnDragStartId()78 const OnDragFunc& GetOnDragStartId() const 79 { 80 return onDragStartId_; 81 } 82 SetOnDragStartId(const OnDragFunc & onDragStartId)83 void SetOnDragStartId(const OnDragFunc& onDragStartId) 84 { 85 onDragStartId_ = onDragStartId; 86 } 87 GetOnDragEnterId()88 const OnDropFunc& GetOnDragEnterId() const 89 { 90 return onDragEnterId_; 91 } 92 SetOnDragEnterId(const OnDropFunc & onDragEnterId)93 void SetOnDragEnterId(const OnDropFunc& onDragEnterId) 94 { 95 onDragEnterId_ = onDragEnterId; 96 } 97 GetOnDragMoveId()98 const OnDropFunc& GetOnDragMoveId() const 99 { 100 return onDragMoveId_; 101 } 102 SetOnDragMoveId(const OnDropFunc & onDragMoveId)103 void SetOnDragMoveId(const OnDropFunc& onDragMoveId) 104 { 105 onDragMoveId_ = onDragMoveId; 106 } 107 GetOnDragLeaveId()108 const OnDropFunc& GetOnDragLeaveId() const 109 { 110 return onDragLeaveId_; 111 } 112 SetOnDragLeaveId(const OnDropFunc & onDragLeaveId)113 void SetOnDragLeaveId(const OnDropFunc& onDragLeaveId) 114 { 115 onDragLeaveId_ = onDragLeaveId; 116 } 117 GetOnDropId()118 const OnDropFunc& GetOnDropId() const 119 { 120 return onDropId_; 121 } 122 SetOnDropId(const OnDropFunc & onDropId)123 void SetOnDropId(const OnDropFunc& onDropId) 124 { 125 onDropId_ = onDropId; 126 } 127 128 private: 129 std::optional<TextAlign> alignment_; 130 RefPtr<TextDeclaration> declaration_; 131 OnDragFunc onDragStartId_; 132 OnDropFunc onDragEnterId_; 133 OnDropFunc onDragMoveId_; 134 OnDropFunc onDragLeaveId_; 135 OnDropFunc onDropId_; 136 }; 137 138 } // namespace OHOS::Ace 139 140 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_TEXT_COMPONENT_H 141