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/common/properties/shadow_config.h" 24 #include "core/components_ng/base/modifier.h" 25 #include "core/components_ng/pattern/pattern.h" 26 #include "core/components_ng/pattern/scroll/inner/scroll_bar.h" 27 #include "core/components_ng/pattern/scroll/inner/scroll_bar_overlay_modifier.h" 28 #include "core/components_ng/pattern/scroll/scroll_edge_effect.h" 29 #include "core/components_ng/pattern/text_drag/text_drag_pattern.h" 30 #include "core/components_ng/pattern/text_field/text_field_model.h" 31 #include "core/components_ng/pattern/text_field/text_field_paint_property.h" 32 #include "core/components_ng/property/property.h" 33 #include "core/components_ng/render/animation_utils.h" 34 #include "core/components_ng/render/drawing.h" 35 36 namespace OHOS::Ace::NG { 37 class TextFieldOverlayModifier : public ScrollBarOverlayModifier { 38 DECLARE_ACE_TYPE(TextFieldOverlayModifier, ScrollBarOverlayModifier); 39 40 public: 41 TextFieldOverlayModifier(const WeakPtr<OHOS::Ace::NG::Pattern>& pattern, WeakPtr<ScrollEdgeEffect>&& edgeEffect); 42 ~TextFieldOverlayModifier() override = default; 43 44 void onDraw(DrawingContext& context) override; 45 46 void SetCursorColor(Color& value); 47 void SetCursorWidth(float value); 48 void SetSelectedBackGroundColor(Color& value); 49 void SetCursorVisible(bool value); 50 void SetContentSize(SizeF& value); 51 void SetContentOffset(OffsetF& value); 52 void SetCursorOffset(const OffsetF& value); 53 void SetInputStyle(InputStyle& value); 54 void SetFrameSize(const SizeF& value); 55 void SetCurrentOffset(float value); 56 void PaintUnderline(RSCanvas& canvas) const; 57 void SetUnderlineColor(const Color& value); 58 void SetUnderlineWidth(float underlineWidth); 59 void SetRedrawFlag(int32_t value); 60 void SetScrollBar(const RefPtr<ScrollBar>& scrollBar); 61 void SetChangeSelectedRects(bool value); 62 void SetFirstHandleOffset(const OffsetF& offset); 63 void SetSecondHandleOffset(const OffsetF& offset); 64 void SetShowSelect(bool value); 65 SetTextRect(const RectF & textRect)66 void SetTextRect(const RectF& textRect) 67 { 68 textRect_ = textRect; 69 } 70 71 void SetShowPreviewTextDecoration(bool value); 72 void SetPreviewTextRects(bool value); 73 void SetPreviewTextDecorationColor(const Color& value); 74 void SetPreviewTextStyle(PreviewTextStyle style); 75 void ContentChange(); 76 77 private: 78 void PaintSelection(DrawingContext& context) const; 79 void PaintCursor(DrawingContext& context) const; 80 void PaintEdgeEffect(const SizeF& frameSize, RSCanvas& canvas); 81 void PaintScrollBar(DrawingContext& context); 82 void PaintMagnifier(DrawingContext& context); 83 bool GetMagnifierRect( 84 float& startX, float& startY, float& endX, float& endY, float& localOffsetX, float& cursorOffsetY); 85 std::vector<TextPoint> GetTextPoints(float startX, float startY, float endX, float endY, bool haveOffset = false); 86 std::shared_ptr<RSPath> GetPathByPoints(std::vector<TextPoint> points); 87 void PaintShadow(const RSPath& path, const Shadow& shadow, RSCanvas& canvas); 88 void GetFrameRectClip(RSRect& clipRect, std::vector<RSPoint>& clipRadius); 89 void PaintPreviewTextDecoration(DrawingContext& context) const; 90 91 bool needPaintSelect_ = false; 92 bool needPaintPreviewText = false; 93 PreviewTextStyle previewTextStyle_ = PreviewTextStyle::NORMAL; 94 WeakPtr<Pattern> pattern_; 95 WeakPtr<ScrollBar> scrollBar_; 96 WeakPtr<ScrollEdgeEffect> edgeEffect_; 97 RefPtr<AnimatablePropertyColor> cursorColor_; 98 RefPtr<AnimatablePropertyFloat> cursorWidth_; 99 RefPtr<AnimatablePropertyColor> selectedColor_; 100 RefPtr<PropertyOffsetF> cursorOffset_; 101 RefPtr<PropertyBool> cursorVisible_; 102 RefPtr<PropertyBool> showSelect_; 103 RefPtr<PropertySizeF> contentSize_; 104 RefPtr<PropertyOffsetF> contentOffset_; 105 RefPtr<PropertyOffsetF> firstHandleOffset_; 106 RefPtr<PropertyOffsetF> secondHandleOffset_; 107 RefPtr<PropertyFloat> currentOffset_; 108 RefPtr<PropertyFloat> underlineWidth_; 109 RefPtr<PropertyColor> underlineColor_; 110 InputStyle inputStyle_ = InputStyle::DEFAULT; 111 RefPtr<PropertySizeF> frameSize_; 112 RefPtr<PropertyBool> changeSelectedRects_; 113 RefPtr<PropertyBool> showPreviewText_; 114 RefPtr<PropertyBool> changePreviewTextRects_; 115 RefPtr<PropertyBool> contentChange_; 116 RefPtr<PropertyColor> previewTextDecorationColor_; 117 RectF textRect_; 118 ACE_DISALLOW_COPY_AND_MOVE(TextFieldOverlayModifier); 119 }; 120 } // namespace OHOS::Ace::NG 121 122 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_FIELD_TEXT_FIELD_OVERLAY_MODIFIER_H 123