1 /* 2 * Copyright (c) 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_TEXT_FIELD_TEXT_FIELD_OVERLAY_MODIFIER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_FIELD_TEXT_FIELD_OVERLAY_MODIFIER_H 18 19 #include <cstdint> 20 21 #include "base/memory/ace_type.h" 22 #include "core/components/common/properties/color.h" 23 #include "core/components_ng/pattern/pattern.h" 24 #include "core/components_ng/pattern/scroll/inner/scroll_bar.h" 25 #include "core/components_ng/pattern/scroll/inner/scroll_bar_overlay_modifier.h" 26 #include "core/components_ng/pattern/scroll/scroll_edge_effect.h" 27 #include "core/components_ng/pattern/text_drag/text_drag_pattern.h" 28 #include "core/components_ng/pattern/text_field/text_field_paint_property.h" 29 30 namespace OHOS::Ace::NG { 31 class TextFieldOverlayModifier : public ScrollBarOverlayModifier { 32 DECLARE_ACE_TYPE(TextFieldOverlayModifier, ScrollBarOverlayModifier); 33 34 public: 35 TextFieldOverlayModifier(const WeakPtr<OHOS::Ace::NG::Pattern>& pattern, WeakPtr<ScrollEdgeEffect>&& edgeEffect); 36 ~TextFieldOverlayModifier() override = default; 37 38 void ModifierAttachProperty(); 39 40 void onDraw(DrawingContext& context) override; 41 42 void SetCursorColor(Color& value); 43 void SetCursorWidth(float value); 44 void SetSelectedBackGroundColor(Color& value); 45 void SetCursorVisible(bool value); 46 void SetContentSize(SizeF& value); 47 void SetContentOffset(OffsetF& value); 48 void SetCursorOffset(const OffsetF& value); 49 void SetFloatingCursorOffset(const OffsetF& value); 50 void SetFloatingCursorVisible(bool value); 51 void SetShowOriginCursor(bool value); 52 void SetInputStyle(InputStyle& value); 53 void SetFrameSize(const SizeF& value); 54 void SetCurrentOffset(float value); 55 void PaintUnderline(RSCanvas& canvas) const; 56 void SetUnderlineColor(const Color& value); 57 void SetUnderlineWidth(float underlineWidth); 58 void SetRedrawFlag(int32_t value); 59 void SetScrollBar(const RefPtr<ScrollBar>& scrollBar); 60 void SetChangeSelectedRects(bool value); 61 void SetFirstHandleOffset(const OffsetF& offset); 62 void SetSecondHandleOffset(const OffsetF& offset); 63 void SetShowSelect(bool value); 64 SetTextRect(const RectF & textRect)65 void SetTextRect(const RectF& textRect) 66 { 67 textRect_ = textRect; 68 } 69 70 void SetShowPreviewTextDecoration(bool value); 71 void SetPreviewTextRects(bool value); 72 void SetPreviewTextDecorationColor(const Color& value); 73 void SetPreviewTextStyle(PreviewTextStyle style); 74 void ContentChange(); 75 76 void StartFloatingCaretLand(const OffsetF& originCaretOffset); 77 GetFloatCaretLanding()78 bool GetFloatCaretLanding() const 79 { 80 return caretLanding_; 81 } 82 SetFloatCaretLanding(bool caretLanding)83 void SetFloatCaretLanding(bool caretLanding) 84 { 85 caretLanding_ = caretLanding; 86 } 87 88 void SetHoverColorAndRects(const std::vector<RoundRect>& hoverRects, uint32_t hoverColor); 89 void ClearHoverColorAndRects(); 90 91 private: 92 void PaintSelection(DrawingContext& context) const; 93 void PaintCursor(DrawingContext& context) const; 94 void PaintFloatingCursor(DrawingContext& context) const; 95 void PaintEdgeEffect(const SizeF& frameSize, RSCanvas& canvas); 96 void PaintScrollBar(DrawingContext& context); 97 void PaintMagnifier(DrawingContext& context); 98 bool GetMagnifierRect( 99 float& startX, float& startY, float& endX, float& endY, float& localOffsetX, float& cursorOffsetY); 100 std::vector<TextPoint> GetTextPoints(float startX, float startY, float endX, float endY, bool haveOffset = false); 101 std::shared_ptr<RSPath> GetPathByPoints(std::vector<TextPoint> points); 102 void PaintShadow(const RSPath& path, const Shadow& shadow, RSCanvas& canvas); 103 void GetFrameRectClip(RSRect& clipRect, std::vector<RSPoint>& clipRadius); 104 void PaintPreviewTextDecoration(DrawingContext& context) const; 105 106 bool caretLanding_ = false; 107 bool needPaintSelect_ = false; 108 bool needPaintPreviewText = false; 109 PreviewTextStyle previewTextStyle_ = PreviewTextStyle::NORMAL; 110 WeakPtr<Pattern> pattern_; 111 WeakPtr<ScrollBar> scrollBar_; 112 WeakPtr<ScrollEdgeEffect> edgeEffect_; 113 RefPtr<AnimatablePropertyColor> cursorColor_; 114 RefPtr<AnimatablePropertyFloat> cursorWidth_; 115 RefPtr<AnimatablePropertyColor> selectedColor_; 116 RefPtr<PropertyOffsetF> cursorOffset_; 117 RefPtr<PropertyBool> cursorVisible_; 118 RefPtr<PropertyBool> showSelect_; 119 RefPtr<PropertySizeF> contentSize_; 120 RefPtr<PropertyOffsetF> contentOffset_; 121 RefPtr<PropertyOffsetF> firstHandleOffset_; 122 RefPtr<PropertyOffsetF> secondHandleOffset_; 123 RefPtr<PropertyFloat> currentOffset_; 124 RefPtr<PropertyFloat> underlineWidth_; 125 RefPtr<PropertyColor> underlineColor_; 126 InputStyle inputStyle_ = InputStyle::DEFAULT; 127 RefPtr<PropertySizeF> frameSize_; 128 RefPtr<PropertyBool> changeSelectedRects_; 129 RefPtr<PropertyBool> showPreviewText_; 130 RefPtr<PropertyBool> changePreviewTextRects_; 131 RefPtr<PropertyBool> contentChange_; 132 RefPtr<PropertyColor> previewTextDecorationColor_; 133 RectF textRect_; 134 RefPtr<AnimatablePropertyOffsetF> floatingCursorOffset_; 135 RefPtr<PropertyBool> floatingCursorVisible_; 136 RefPtr<PropertyBool> showOriginCursor_; 137 std::vector<RoundRect> hoverRects_; 138 RefPtr<PropertyInt> hoverColor_; 139 140 ACE_DISALLOW_COPY_AND_MOVE(TextFieldOverlayModifier); 141 }; 142 } // namespace OHOS::Ace::NG 143 144 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_FIELD_TEXT_FIELD_OVERLAY_MODIFIER_H 145