• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_drag/rich_editor_drag_overlay_modifier.h"
23 #include "core/components_ng/pattern/rich_editor_drag/rich_editor_drag_paint_method.h"
24 #include "core/components_ng/pattern/text/text_pattern.h"
25 #include "core/components_ng/pattern/text_drag/text_drag_overlay_modifier.h"
26 #include "core/components_ng/pattern/text_drag/text_drag_pattern.h"
27 #include "core/components_ng/render/drawing.h"
28 
29 namespace OHOS::Ace::NG {
30 class RichEditorDragPattern : public TextDragPattern {
31     DECLARE_ACE_TYPE(RichEditorDragPattern, TextDragPattern);
32 
33 public:
RichEditorDragPattern(const RefPtr<TextPattern> & hostPattern)34     explicit RichEditorDragPattern(const RefPtr<TextPattern>& hostPattern) : hostPattern_(hostPattern) {};
35     ~RichEditorDragPattern() override = default;
36 
37     static RefPtr<FrameNode> CreateDragNode(
38         const RefPtr<FrameNode>& hostNode, std::list<RefPtr<FrameNode>>& imageChildren);
39 
CreateNodePaintMethod()40     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
41     {
42         if (!overlayModifier_) {
43             overlayModifier_ = AceType::MakeRefPtr<RichEditorDragOverlayModifier>(WeakClaim(this), hostPattern_);
44         }
45 
46         if (!contentModifier_) {
47             contentModifier_ = AceType::MakeRefPtr<RichEditorDragContentModifier>();
48         }
49         auto pattern = hostPattern_.Upgrade();
50         if (pattern) {
51             contentModifier_->SetIsCustomFont(pattern->GetIsCustomFont());
52         }
53 
54         return MakeRefPtr<RichEditorDragPaintMethod>(WeakClaim(this), overlayModifier_, contentModifier_);
55     }
56 
Initialize(const TextDragData & data)57     void Initialize(const TextDragData& data)
58     {
59         textDragData_ = data;
60     }
61 
62 private:
63     static RefPtr<FrameNode> CreateDragNode(const RefPtr<FrameNode>& hostNode);
64 
65     WeakPtr<TextPattern> hostPattern_;
66     RefPtr<RichEditorDragContentModifier> contentModifier_;
67 
68     ACE_DISALLOW_COPY_AND_MOVE(RichEditorDragPattern);
69 };
70 } // namespace OHOS::Ace::NG
71 
72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RICH_EDITOR_DRAG_RICH_EDITOR_DRAG_PATTERN_H
73