1 /*
2  * Copyright (c) 2021-2022 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_RICHTEXT_RENDER_RICHTEXT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_RICHTEXT_RENDER_RICHTEXT_H
18 
19 #include "core/components/common/layout/constants.h"
20 #include "core/components/rich_text/resource/rich_text_delegate.h"
21 #include "core/components/rich_text/rich_text_component.h"
22 #include "core/pipeline/base/render_node.h"
23 
24 namespace OHOS::Ace {
25 
26 class RenderRichText : public RenderNode {
27     DECLARE_ACE_TYPE(RenderRichText, RenderNode);
28 
29 public:
30     static RefPtr<RenderNode> Create();
31 
32     RenderRichText();
33     ~RenderRichText() override = default;
34 
35     void Update(const RefPtr<Component>& component) override;
36     void PerformLayout() override;
37     void MarkNeedRender(bool overlay = false);
38     void OnGlobalPositionChanged() override;
39 
40     void UpdateLayoutParams(const int32_t width, const int32_t height, const int32_t contentHeight);
SetDelegate(const RefPtr<RichTextDelegate> & delegate)41     void SetDelegate(const RefPtr<RichTextDelegate>& delegate)
42     {
43         delegate_ = delegate;
44     }
45     void OnTouchTestHit(
46         const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override;
47 
48 private:
49     void CreateRealWeb(int32_t top, int32_t left, bool visible, bool reCreate = false);
50     void ProcessMove(double posY);
51 
52 protected:
53     RefPtr<RichTextDelegate> delegate_;
54 
55 private:
56     Size drawSize_;
57     int32_t webContentWidth_ = 0;
58     int32_t webContentHeight_ = 0;
59     bool hasCreateWeb_ = false;
60     bool isVisible_ = true;
61     bool initPositionSet_ = false;
62     RefPtr<RawRecognizer> touchRecognizer_;
63     RefPtr<DragRecognizer> dragRecognizer_;
64     bool canSelfScroll_ = false;
65     bool startSelfScroll_ = true;
66     double prevPos_ = 0.0f;
67     int32_t couldScrollLength_ = 0;
68     int32_t currentScrollLength_ = 0;
69 };
70 
71 } // namespace OHOS::Ace
72 
73 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_RICHTEXT_RENDER_RICHTEXT_H
74