1 /* 2 * Copyright (c) 2022-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_PATTERN_RICH_EDITOR_DRAG_RICH_EDITOR_DRAG_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RICH_EDITOR_DRAG_RICH_EDITOR_DRAG_PATTERN_H 18 19 #include "base/memory/referenced.h" 20 #include "core/components_ng/pattern/rich_editor/paragraph_manager.h" 21 #include "core/components_ng/pattern/rich_editor/rich_editor_pattern.h" 22 #include "core/components_ng/pattern/rich_editor/rich_editor_theme.h" 23 #include "core/components_ng/pattern/rich_editor_drag/rich_editor_drag_info.h" 24 #include "core/components_ng/pattern/rich_editor_drag/rich_editor_drag_overlay_modifier.h" 25 #include "core/components_ng/pattern/rich_editor_drag/rich_editor_drag_paint_method.h" 26 #include "core/components_ng/pattern/text/text_pattern.h" 27 #include "core/components_ng/pattern/text_drag/text_drag_overlay_modifier.h" 28 #include "core/components_ng/pattern/text_drag/text_drag_pattern.h" 29 #include "core/components_ng/render/drawing_forward.h" 30 31 namespace OHOS::Ace::NG { 32 class RichEditorDragPattern : public TextDragPattern { 33 DECLARE_ACE_TYPE(RichEditorDragPattern, TextDragPattern); 34 35 public: RichEditorDragPattern(const RefPtr<TextPattern> & hostPattern,const std::shared_ptr<RichEditorDragInfo> info)36 explicit RichEditorDragPattern(const RefPtr<TextPattern>& hostPattern, 37 const std::shared_ptr<RichEditorDragInfo> info) : info_(info), hostPattern_(hostPattern) {}; 38 ~RichEditorDragPattern() override = default; 39 40 static RefPtr<FrameNode> CreateDragNode( 41 const RefPtr<FrameNode>& hostNode, std::list<RefPtr<FrameNode>>& imageChildren); 42 43 static RefPtr<FrameNode> CreateDragNode( 44 const RefPtr<FrameNode>& hostNode, std::list<RefPtr<FrameNode>>& imageChildren, const RichEditorDragInfo& info); 45 CreateNodePaintMethod()46 RefPtr<NodePaintMethod> CreateNodePaintMethod() override 47 { 48 if (!overlayModifier_) { 49 overlayModifier_ = AceType::MakeRefPtr<RichEditorDragOverlayModifier>(WeakClaim(this), hostPattern_); 50 } 51 52 if (!contentModifier_) { 53 contentModifier_ = AceType::MakeRefPtr<RichEditorDragContentModifier>(); 54 } 55 auto pattern = hostPattern_.Upgrade(); 56 if (pattern) { 57 contentModifier_->SetIsCustomFont(pattern->GetIsCustomFont()); 58 } 59 60 return MakeRefPtr<RichEditorDragPaintMethod>(WeakClaim(this), overlayModifier_, contentModifier_, *info_); 61 } 62 Initialize(const TextDragData & data)63 void Initialize(const TextDragData& data) 64 { 65 textDragData_ = data; 66 } 67 GetDragCornerRadius()68 Dimension GetDragCornerRadius() override 69 { 70 auto pipeline = PipelineContext::GetCurrentContext(); 71 CHECK_NULL_RETURN(pipeline, TEXT_DRAG_RADIUS); 72 auto richEditorTheme = pipeline->GetTheme<RichEditorTheme>(); 73 CHECK_NULL_RETURN(richEditorTheme, TEXT_DRAG_RADIUS); 74 return richEditorTheme->GetDragCornerRadius(); 75 } 76 77 protected: 78 std::shared_ptr<RichEditorDragInfo> info_; 79 80 private: 81 static RefPtr<FrameNode> CreateDragNode(const RefPtr<FrameNode>& hostNode, const RichEditorDragInfo& info); 82 83 WeakPtr<TextPattern> hostPattern_; 84 RefPtr<RichEditorDragContentModifier> contentModifier_; 85 86 ACE_DISALLOW_COPY_AND_MOVE(RichEditorDragPattern); 87 }; 88 } // namespace OHOS::Ace::NG 89 90 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RICH_EDITOR_DRAG_RICH_EDITOR_DRAG_PATTERN_H 91