1 /* 2 * Copyright (c) 2021-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 USE_ROSEN_DRAWING 17 #include "include/core/SkPath.h" 18 #endif 19 20 #include "base/geometry/dimension.h" 21 #include "core/components/bubble/bubble_component.h" 22 #include "core/components/common/properties/edge.h" 23 #include "core/components/slider/render_slider.h" 24 #include "core/gestures/raw_recognizer.h" 25 #include "core/pipeline/base/render_node.h" 26 27 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BUBBLE_RENDER_BUBBLE_H 28 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BUBBLE_RENDER_BUBBLE_H 29 30 namespace OHOS::Ace { 31 namespace { 32 33 constexpr Dimension BEZIER_WIDTH_HALF = 16.0_vp; 34 constexpr Dimension BEZIER_HORIZON_OFFSET_FIRST = 1.3_vp; 35 constexpr Dimension BEZIER_HORIZON_OFFSET_SECOND = 3.2_vp; 36 constexpr Dimension BEZIER_HORIZON_OFFSET_THIRD = 6.6_vp; 37 constexpr Dimension BEZIER_HORIZON_OFFSET_FOURTH = 16.0_vp; 38 constexpr Dimension BEZIER_VERTICAL_OFFSET_FIRST = 0.1_vp; 39 constexpr Dimension BEZIER_VERTICAL_OFFSET_SECOND = 3.0_vp; 40 constexpr Dimension BEZIER_VERTICAL_OFFSET_THIRD = 8.0_vp; 41 42 } // namespace 43 44 class RenderBubble : public RenderNode { 45 DECLARE_ACE_TYPE(RenderBubble, RenderNode); 46 47 public: 48 ~RenderBubble() override = default; 49 50 static RefPtr<RenderNode> Create(); 51 void Update(const RefPtr<Component>& component) override; 52 void PerformLayout() override; 53 bool PopBubble(); 54 void FirePopEvent(); 55 bool HandleMouseEvent(const MouseEvent& event) override; 56 double GetArrowOffset(const Placement& placement); 57 void OnPaintFinish() override; 58 59 protected: 60 enum class ErrorPositionType { 61 NORMAL = 0, 62 TOP_LEFT_ERROR, 63 BOTTOM_RIGHT_ERROR, 64 }; 65 66 RenderBubble(); 67 68 void OnHiddenChanged(bool hidden) override; 69 void OnTouchTestHit( 70 const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; 71 72 void HandleTouch(const Offset& clickPosition); 73 Offset GetChildPosition(const Size& childSize); 74 Offset GetPositionWithPlacement(const Size& childSize, const Offset& topPosition, const Offset& bottomPosition, 75 const Offset& topArrowPosition, const Offset& bottomArrowPosition); 76 Offset FitToScreen(const Offset& fitPosition, const Size& childSize); 77 ErrorPositionType GetErrorPositionType(const Offset& childOffset, const Size& childSize); 78 void UpdateAccessibilityInfo(Size size, Offset offset); 79 void InitAccessibilityEventListener(); 80 #ifndef USE_ROSEN_DRAWING 81 void BuildCornerPath(SkPath& path, Placement placement, double radius); 82 void BuildTopLinePath(SkPath& path, double arrowOffset, double radius); 83 void BuildRightLinePath(SkPath& path, double arrowOffset, double radius); 84 void BuildBottomLinePath(SkPath& path, double arrowOffset, double radius); 85 void BuildLeftLinePath(SkPath& path, double arrowOffset, double radius); 86 void BuildCompletePath(SkPath& path); 87 #else 88 void BuildCornerPath(RSPath& path, Placement placement, double radius); 89 void BuildTopLinePath(RSPath& path, double arrowOffset, double radius); 90 void BuildRightLinePath(RSPath& path, double arrowOffset, double radius); 91 void BuildBottomLinePath(RSPath& path, double arrowOffset, double radius); 92 void BuildLeftLinePath(RSPath& path, double arrowOffset, double radius); 93 void BuildCompletePath(RSPath& path); 94 #endif 95 96 static const Dimension BUBBLE_SPACING; 97 98 bool isShow_ = true; 99 bool enableArrow_ = true; 100 // Is there has enough space for showing arrow. 101 bool showTopArrow_ = true; 102 bool showBottomArrow_ = true; 103 bool showCustomArrow_ = false; 104 bool useCustom_ = false; 105 bool isShowInSubWindow_ = false; 106 Edge padding_; 107 Edge margin_; 108 Border border_; 109 Size childSize_; 110 Size targetSize_; 111 Offset childOffset_; 112 Offset targetOffset_; 113 Offset arrowPosition_; 114 Dimension arrowOffset_; 115 Color maskColor_; 116 Color backgroundColor_; 117 Placement placement_ = Placement::BOTTOM; 118 Placement arrowPlacement_ = Placement::TOP; 119 ComposeId targetId_; 120 std::function<void(const std::string&)> onVisibilityChange_; 121 RefPtr<RawRecognizer> rawDetector_; 122 RefPtr<BubbleComponent> bubbleComponent_; 123 WeakPtr<StackElement> weakStack_; 124 Dimension targetSpace_; 125 126 private: 127 void InitArrowState(); 128 // Get size and position of target by targetId. 129 void InitTargetSizeAndPosition(); 130 void UpdateCustomChildPosition(); 131 void GenerateChildPosition(const Size& childSize); 132 void UpdateTouchRegion(); 133 void InitEdgeSize(Edge& edge); 134 void InitArrowTopAndBottomPosition(Offset& topArrowPosition, Offset& bottomArrowPosition, Offset& topPosition, 135 Offset& bottomPosition, const Size& childSize); 136 void UpdateArrowOffset(const RefPtr<BubbleComponent>& bubble, const Placement& placement); 137 TouchRegion touchRegion_; 138 }; 139 140 } // namespace OHOS::Ace 141 142 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BUBBLE_RENDER_BUBBLE_H 143