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_SELECT_POPUP_RENDER_SELECT_POPUP_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SELECT_POPUP_RENDER_SELECT_POPUP_H 18 19 #include <vector> 20 21 #include "base/geometry/offset.h" 22 #include "core/components/box/render_box.h" 23 #include "core/components/option/render_option.h" 24 #include "core/components/positioned/render_positioned.h" 25 #include "core/components/root/render_root.h" 26 #include "core/components/scroll/render_scroll.h" 27 #include "core/components/select_popup/select_popup_component.h" 28 #include "core/components/slider/render_slider.h" 29 #include "core/gestures/click_recognizer.h" 30 #include "core/gestures/drag_recognizer.h" 31 #include "core/gestures/long_press_recognizer.h" 32 #include "core/gestures/raw_recognizer.h" 33 #include "core/pipeline/base/constants.h" 34 #include "core/pipeline/base/render_node.h" 35 36 namespace OHOS::Ace { 37 38 class RenderSelectPopup : public RenderNode { 39 DECLARE_ACE_TYPE(RenderSelectPopup, RenderNode); 40 41 public: 42 static RefPtr<RenderNode> Create(); 43 44 RenderSelectPopup(); 45 ~RenderSelectPopup() override = default; 46 47 void Update(const RefPtr<Component>& component) override; 48 void PerformLayout() override; 49 void OnPaintFinish() override; 50 UpdateRenders()51 void UpdateRenders() 52 { 53 ClearReferenceRenders(); 54 GetReferenceRenders(); 55 } 56 GetSelectPopupComponent()57 RefPtr<SelectPopupComponent> GetSelectPopupComponent() 58 { 59 return selectPopup_; 60 } 61 SetIsWattingForAnimationStart(bool isWattingForAnimationStart)62 void SetIsWattingForAnimationStart(bool isWattingForAnimationStart) 63 { 64 isWattingForAnimationStart_ = isWattingForAnimationStart; 65 } 66 67 bool HandleMouseEvent(const MouseEvent& event) override; 68 69 void ProcessTouchDown(const TouchEventInfo& info); 70 void ProcessTouchUp(const TouchEventInfo& info); 71 72 protected: 73 bool isFullScreen_ = true; 74 bool isWattingForAnimationStart_ = false; 75 Color tvBackColor_; 76 Offset globalRightBottom_; 77 Offset childPosition_; 78 LayoutParam childLayoutParam_; 79 RefPtr<RenderScroll> renderScroll_; 80 std::vector<RefPtr<RenderOption>> renderOptions_; 81 Dimension optionInterval_; 82 Dimension rrectSize_; 83 84 bool isContextMenu_ = false; 85 private: 86 void AdjustTvChildVerticalLayout(const Size& size, double& y, double& height); 87 void AdjustTvChildHorizontalLayout(const Size& size, double& x, double& width); 88 void AdjustChildVerticalLayout(const Size& size, double& y, double& height); 89 void AdjustChildHorizontalLayout(const Size& size, double& x, double& width); 90 void AdjustChildLayout(Size& size); 91 92 void CreateAnimation(); 93 void CreatePopupAnimation(bool isMenu); 94 95 void OnTouchTestHit( 96 const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; 97 void HandleRawEvent(const Offset& clickPosition); 98 99 void GetReferenceRenders(); 100 void GetReferenceRenders(const RefPtr<RenderNode>& render); 101 void ClearReferenceRenders(); 102 103 bool ScreenDirectionSwitched(); 104 105 RefPtr<RawRecognizer> rawDetector_; 106 RefPtr<FreeDragRecognizer> dragDetector_; 107 RefPtr<LongPressRecognizer> longPressDetector_; 108 RefPtr<ClickRecognizer> clickDetector_; 109 std::size_t optionSize_ = SELECT_DEFAULT_OPTION_SIZE; 110 RefPtr<SelectPopupComponent> selectPopup_; 111 Offset selectLeftTop_; 112 Offset selectRightBottom_; 113 114 TouchRegion touchRegion_; 115 Dimension minWidth_; 116 Dimension verticalSpacing_; 117 Dimension horizontalSpacing_; 118 Dimension contentSpacing_; 119 120 bool screenHorizontal_ = false; 121 bool screenVertical_ = false; 122 bool animationCreated_ = false; 123 124 double normalPadding_ = 0.0; 125 RefPtr<SelectTheme> theme_; 126 127 RefPtr<RenderNode> renderRoot_; 128 RefPtr<RenderPositioned> renderPositioned_; 129 RefPtr<RenderBox> renderTitleBox_; 130 Offset firstFingerDownOffset_; 131 Offset firstFingerUpOffset_; 132 }; 133 134 } // namespace OHOS::Ace 135 136 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SELECT_POPUP_RENDER_SELECT_POPUP_H 137