• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "core/components/bubble/bubble_component.h"
17 #include "core/components/common/properties/edge.h"
18 #include "core/components/slider/render_slider.h"
19 #include "core/gestures/raw_recognizer.h"
20 #include "core/pipeline/base/render_node.h"
21 
22 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BUBBLE_RENDER_BUBBLE_H
23 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BUBBLE_RENDER_BUBBLE_H
24 
25 namespace OHOS::Ace {
26 
27 class RenderBubble : public RenderNode {
28     DECLARE_ACE_TYPE(RenderBubble, RenderNode);
29 
30 public:
31     ~RenderBubble() override = default;
32 
33     static RefPtr<RenderNode> Create();
34     void Update(const RefPtr<Component>& component) override;
35     void PerformLayout() override;
36     bool PopBubble();
37     void FirePopEvent();
38     bool HandleMouseEvent(const MouseEvent& event) override;
39 
40 protected:
41     enum class ErrorPositionType {
42         NORMAL = 0,
43         TOP_LEFT_ERROR,
44         BOTTOM_RIGHT_ERROR,
45     };
46 
47     RenderBubble();
48 
49     void OnHiddenChanged(bool hidden) override;
50     void OnTouchTestHit(
51         const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override;
52 
UpdateBorderRadius()53     virtual void UpdateBorderRadius() {};
54     void HandleTouch();
55     Offset GetChildPosition(const Size& childSize);
56     Offset GetPositionWithPlacement(const Size& childSize, const Offset& topPosition, const Offset& bottomPosition,
57         const Offset& topArrowPosition, const Offset& bottomArrowPosition);
58     Offset FitToScreen(const Offset& fitPosition, const Size& childSize);
59     ErrorPositionType GetErrorPositionType(const Offset& childOffset, const Size& childSize);
60     void UpdateAccessibilityInfo(Size size, Offset offset);
61     void InitAccessibilityEventListener();
62 
63     static const Dimension BUBBLE_SPACING;
64 
65     bool isShow_ = true;
66     bool enableArrow_ = true;
67     // Is there has enough space for showing arrow.
68     bool showTopArrow_ = true;
69     bool showBottomArrow_ = true;
70     bool useCustom_ = false;
71     Edge padding_;
72     Edge margin_;
73     Border border_;
74     Size childSize_;
75     Size targetSize_;
76     Offset childOffset_;
77     Offset targetOffset_;
78     Offset arrowPosition_;
79     Dimension arrowOffset_;
80     Color maskColor_;
81     Color backgroundColor_;
82     Placement placement_ = Placement::BOTTOM;
83     Placement arrowPlacement_ = Placement::TOP;
84     ComposeId targetId_;
85     std::function<void(const std::string&)> onVisibilityChange_;
86     RefPtr<RawRecognizer> rawDetector_;
87     RefPtr<BubbleComponent> bubbleComponent_;
88     WeakPtr<StackElement> weakStack_;
89 
90 private:
91     void InitArrowState();
92     // Get size and position of target by targetId.
93     void InitTargetSizeAndPosition();
94 };
95 
96 } // namespace OHOS::Ace
97 
98 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BUBBLE_RENDER_BUBBLE_H
99