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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_RICH_EDITOR_SELECTION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_RICH_EDITOR_SELECTION_H 18 19 #include <list> 20 21 #include "base/geometry/offset.h" 22 #include "base/image/pixel_map.h" 23 #include "base/memory/ace_type.h" 24 #include "core/common/resource/resource_object.h" 25 #include "core/components/common/properties/text_style.h" 26 #include "core/event/ace_events.h" 27 #include "core/event/axis_event.h" 28 namespace OHOS::Ace { 29 enum GetSpansMethod : int32_t { 30 GETSPANS, 31 ONSELECT, 32 }; 33 34 enum RichEditorImageSize : int32_t { 35 SIZEWIDTH, 36 SIZEHEIGHT, 37 }; 38 39 enum RichEditorSpanRange : int32_t { 40 RANGESTART, 41 RANGEEND, 42 }; 43 44 enum SelectSpanType : int32_t { 45 TYPESPAN, 46 TYPEIMAGE, 47 TYPESYMBOLSPAN, 48 }; 49 50 enum RichEditorLeadingRange : int32_t { 51 LEADING_START, 52 LEADING_END, 53 }; 54 55 struct SpanPosition { 56 int32_t spanIndex = 0; 57 int32_t spanRange[2] = { 0, 0 }; 58 }; 59 60 struct SymbolSpanStyle { 61 double fontSize = 0.0; 62 std::string symbolColor; 63 int32_t fontWeight = 0; 64 uint32_t renderingStrategy; 65 uint32_t effectStrategy; 66 }; 67 68 struct TextStyleResult { 69 std::string fontColor; 70 double fontSize = 0.0; 71 int32_t fontStyle = 0; 72 int32_t fontWeight = 0; 73 std::string fontFamily; 74 int32_t decorationType = 0; 75 std::string decorationColor; 76 int32_t textAlign = 0; 77 float leadingMarginSize[2] = { 0.0, 0.0 }; 78 }; 79 80 struct ImageStyleResult { 81 double size[2] = { 0.0, 0.0 }; 82 int32_t verticalAlign = 0; 83 int32_t objectFit = 0; 84 std::string borderRadius; 85 std::string margin; 86 }; 87 88 struct ResultObject { 89 SpanPosition spanPosition; 90 SelectSpanType type = SelectSpanType::TYPESPAN; 91 int32_t offsetInSpan[2] = { 0, 0 }; 92 std::string valueString; 93 RefPtr<PixelMap> valuePixelMap; 94 TextStyleResult textStyle; 95 ImageStyleResult imageStyle; 96 SymbolSpanStyle symbolSpanStyle; 97 RefPtr<ResourceObject> valueResource; 98 bool isDraggable = true; 99 }; 100 101 struct Selection { 102 int32_t selection[2] = { 0, 0 }; 103 std::list<ResultObject> resultObjects; 104 }; 105 106 class SelectionInfo : public BaseEventInfo { 107 DECLARE_RELATIONSHIP_OF_CLASSES(SelectionInfo, BaseEventInfo); 108 109 public: SelectionInfo()110 SelectionInfo() : BaseEventInfo("SelectionInfo") {} 111 112 ~SelectionInfo() = default; 113 GetSelection()114 Selection GetSelection() const 115 { 116 return selection_; 117 } 118 SetSelectionStart(int32_t start)119 void SetSelectionStart(int32_t start) 120 { 121 selection_.selection[RichEditorSpanRange::RANGESTART] = start; 122 } 123 SetSelectionEnd(int32_t end)124 void SetSelectionEnd(int32_t end) 125 { 126 selection_.selection[RichEditorSpanRange::RANGEEND] = end; 127 } 128 SetResultObjectList(const std::list<ResultObject> & resultObjectList)129 void SetResultObjectList(const std::list<ResultObject>& resultObjectList) 130 { 131 for (auto& resultObject : resultObjectList) { 132 selection_.resultObjects.emplace_back(resultObject); 133 } 134 } 135 136 private: 137 Selection selection_; 138 }; 139 140 class SelectionRangeInfo : public BaseEventInfo { 141 DECLARE_RELATIONSHIP_OF_CLASSES(SelectionRangeInfo, BaseEventInfo); 142 143 public: SelectionRangeInfo(int32_t start,int32_t end)144 SelectionRangeInfo(int32_t start, int32_t end) : BaseEventInfo("SelectionRangeInfo"), start_(start), end_(end) {}; 145 146 ~SelectionRangeInfo() = default; 147 148 int32_t start_; 149 150 int32_t end_; 151 }; 152 153 struct ParagraphInfo { 154 // style 155 RefPtr<PixelMap> leadingMarginPixmap; 156 float leadingMarginSize[2] = { 0.0, 0.0 }; 157 int32_t textAlign = 0; 158 159 std::pair<int32_t, int32_t> range; 160 }; 161 } // namespace OHOS::Ace 162 163 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_RICH_EDITOR_SELECTION_H 164