• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_PREVIEW_MENU_CONTROLLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_PREVIEW_MENU_CONTROLLER_H
18 
19 #include "ui/base/referenced.h"
20 
21 #include "core/components_ng/base/frame_node.h"
22 #include "core/components_ng/pattern/flex/flex_layout_property.h"
23 #include "core/components_ng/pattern/image/image_layout_property.h"
24 #include "core/components_ng/pattern/text/text_layout_property.h"
25 #include "core/components_ng/pattern/text/text_pattern.h"
26 #include "core/components_ng/property/menu_property.h"
27 
28 namespace OHOS::Ace::NG {
29 using AIPreviewMenuErrorCallback =
30     std::function<void(int32_t code, const std::string& name, const std::string& message)>;
31 class PreviewMenuController : public virtual AceType {
32     DECLARE_ACE_TYPE(PreviewMenuController, AceType);
33 
34 public:
35     PreviewMenuController(const WeakPtr<TextPattern>& pattern);
36     virtual ~PreviewMenuController() = default;
37     void BindContextMenu(const RefPtr<FrameNode>& targetNode, bool isShow = true);
ClosePreviewMenu()38     void ClosePreviewMenu()
39     {
40         isShow_ = false;
41     }
42 
IsPreviewMenuShow()43     bool IsPreviewMenuShow()
44     {
45         return isShow_;
46     }
47 
48     static void CreatePreviewMenu(TextDataDetectType type, const std::string& content,
49         std::function<void()> disappearCallback = nullptr, std::map<std::string, std::string> AIparams = {},
50         std::function<void()> aiSpanClickCallabck = nullptr);
51 
52 private:
53     void CreateAIEntityMenu();
54     static void CreateContactErrorNode(
55         const RefPtr<FrameNode>& previewNode, const std::string& content, std::function<void()>&& disappearCallback);
56     static void CreateURLAndAddressNode(const RefPtr<FrameNode>& previewNode, const std::string& content,
57         TextDataDetectType type, std::function<void()>&& aiSpanClickCallabck);
58     static void CreateURLAndAddressContentNode(const RefPtr<FrameNode>& previewNode,
59         const RefPtr<FrameNode>& contentNode, const std::string& content, TextDataDetectType type);
60     static void CreateLinkingErrorNode(
61         const RefPtr<FrameNode>& previewNode, TextDataDetectType type, std::function<void()>&& disappearCallback);
62     static RefPtr<FrameNode> CreateLinkingPreviewNode();
63     static RefPtr<FrameNode> CreateContactAndAddressPreviewNode(TextDataDetectType type);
64     static void UpdateImageAndTitleNodeProperty(const RefPtr<ImageLayoutProperty>& imageLayoutProperty,
65         const RefPtr<TextLayoutProperty>& textLayoutProperty, TextDataDetectType type, const std::string& content);
66     static void UpdateLinkNodeProperty(const RefPtr<TextLayoutProperty>& textLayoutProperty, TextDataDetectType type);
67     static RefPtr<FrameNode> CreatePreview(TextDataDetectType type);
68     static void MountErrorNode(const RefPtr<FrameNode>& previewNode, TextDataDetectType type,
69         const std::string& content, std::function<void()> disappearCallback, std::function<void()> aiSpanClickCallabck);
70     static void MountUIExtensionNode(const RefPtr<FrameNode>& previewNode, const std::string& content,
71         std::function<void()>&& disappearCallback, TextDataDetectType type,
72         const std::map<std::string, std::string>& AIparams);
73     static AIPreviewMenuErrorCallback GetErrorCallback(const RefPtr<FrameNode>& previewNode, TextDataDetectType type,
74         const std::string& content, std::function<void()>&& disappearCallback);
75     std::function<void()> GetDisappearCallback();
76     static std::function<void()> GetLinkingCallback(const std::string& appName);
77     static void CreateWantConfig(TextDataDetectType type, std::string& bundleName, std::string& abilityName,
78         std::map<std::string, std::string>& params, const std::map<std::string, std::string>& AIparams);
79     static void PreviewNodeClickCallback(TextDataDetectType type, const RefPtr<FrameNode>& previewNode,
80         const std::map<std::string, std::string>& AIparams);
81     static Dimension GetPreviewMaxHeight(const RefPtr<FrameNode>& frameNode);
82 
83     MenuParam menuParam_;
84     std::function<void()> menuBuilder_ = nullptr;
85     std::function<void()> previewBuilder_ = nullptr;
86 
87     WeakPtr<TextPattern> pattern_;
88     bool isShow_ = false;
89     ACE_DISALLOW_COPY_AND_MOVE(PreviewMenuController);
90 };
91 
92 } // namespace OHOS::Ace::NG
93 
94 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_PREVIEW_MENU_CONTROLLER_H