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 #ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_LIST_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_LIST_H 18 19 #include "base/utils/macros.h" 20 #include "core/components/indexer/indexer_list_component.h" 21 #include "core/components/list/list_component.h" 22 #include "frameworks/bridge/common/dom/dom_node.h" 23 #include "frameworks/bridge/common/dom/dom_type.h" 24 25 namespace OHOS::Ace::Framework { 26 27 class ACE_EXPORT DOMList final : public DOMNode { 28 DECLARE_ACE_TYPE(DOMList, DOMNode); 29 30 public: 31 DOMList(NodeId nodeId, const std::string& nodeName); 32 ~DOMList() override = default; 33 34 void CallSpecializedMethod(const std::string& method, const std::string& args) override; 35 void OnPageLoadFinish() override; 36 void OnScrollBy(double dx, double dy, bool isSmooth) override; 37 Offset GetCurrentOffset() const; 38 void ScrollToMethod(int32_t index); 39 GetSpecializedComponent()40 RefPtr<Component> GetSpecializedComponent() override 41 { 42 if (indexer_) { 43 return indexerComponent_; 44 } else { 45 return listComponent_; 46 } 47 } 48 GetDirection()49 FlexDirection GetDirection() const 50 { 51 return flexDirection_; 52 } 53 GetItemScale()54 bool GetItemScale() const 55 { 56 return itemScale_; 57 } 58 GetItemOpacity()59 bool GetItemOpacity() const 60 { 61 return itemOpacity_; 62 } 63 NeedVibrate()64 bool NeedVibrate() const 65 { 66 return scrollVibrate_; 67 } 68 NeedRotationVibrate()69 bool NeedRotationVibrate() const 70 { 71 return rotationVibrate_; 72 } 73 GetItemCenter()74 bool GetItemCenter() const 75 { 76 return itemCenter_; 77 } 78 NeedDivider()79 bool NeedDivider() const 80 { 81 return needDivider_; 82 } 83 GetDividerHeight()84 const Dimension& GetDividerHeight() const 85 { 86 return dividerHeight_; 87 } 88 GetDividerLength()89 const Dimension& GetDividerLength() const 90 { 91 return dividerLength_; 92 } 93 GetDividerOrigin()94 const Dimension& GetDividerOrigin() const 95 { 96 return dividerOrigin_; 97 } 98 GetDividerColor()99 Color GetDividerColor() const 100 { 101 return dividerColor_; 102 } 103 104 void AdjustSpecialParamInLiteMode() override; 105 SetOnRotate(const EventMarker & eventMarker)106 void SetOnRotate(const EventMarker& eventMarker) 107 { 108 listComponent_->SetOnRotateId(eventMarker); 109 } 110 111 protected: 112 void OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot) override; 113 void OnChildNodeRemoved(const RefPtr<DOMNode>& child) override; 114 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 115 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 116 bool AddSpecializedEvent(int32_t pageId, const std::string& event) override; 117 void PrepareSpecializedComponent() override; 118 void ResetInitializedStyle() override; 119 void OnMounted(const RefPtr<DOMNode>& parentNode) override; 120 GetRotateId()121 const EventMarker& GetRotateId() 122 { 123 static EventMarker defaultMarker; 124 auto& crownEvent = static_cast<CommonCrownEvent&>(declaration_->GetEvent(EventTag::COMMON_CROWN_EVENT)); 125 return crownEvent.IsValid() ? crownEvent.rotate.eventMarker : defaultMarker; 126 } 127 128 private: 129 void CreateOrUpdateList(); 130 131 void CreateOrUpdateIndexer(); 132 133 RefPtr<AccessibilityNode> GetAccessibilityNode(); 134 void UpdateAccessibilityOrder(); 135 void UpdateAccessibilityByVisible(); 136 137 void SetScrollBar(); 138 139 void SetChildActive(); 140 141 void ExpandGroup(const std::string& groupId, bool expand = true); 142 void ScrollByMethod(double x, double y, bool isSmooth); 143 void ScrollArrowMethod(bool reverse, bool isSmooth); 144 void ScrollToEdgeMethod(const std::string& method, const std::string& args); 145 void ScrollPageMethod(const std::string& method, const std::string& args); 146 147 void ParseIndexer(const std::string& indexerAlphabet); 148 bool SupportChainAnimation() const; 149 150 void InitScrollBarWithSpecializedStyle(); 151 152 // List columns default value is 1 153 int32_t listColumns_ = 1; 154 int32_t cachedCount_ = 0; 155 bool itemScale_ = true; 156 bool itemOpacity_ = false; 157 bool itemCenter_ = false; 158 bool centerLayout_ = false; 159 bool scrollVibrate_ = true; 160 bool rotationVibrate_ = false; 161 bool scrollPage_ = false; 162 bool chainAnimation_ = false; 163 SpringChainProperty chainProperty_; 164 bool useDefaultOverSpringProperty_ = true; 165 double overStiffness_ = 0.0; 166 double overDamping_ = 0.0; 167 bool updateEffect_ = false; 168 double scrollDistance_ = 0.0; 169 bool accessibilityDisabled_ = false; 170 Dimension itemExtent_; 171 std::pair<bool, Dimension> scrollbarWidth_; 172 std::pair<bool, Color> scrollbarColor_; 173 std::pair<bool, Dimension> scrollbarPositionX_; 174 std::pair<bool, Dimension> scrollbarPositionY_; 175 176 EventMarker onRequestItem_; 177 178 bool indexer_ = false; 179 180 // first:value second:tag whether user defined 181 std::pair<bool, bool> circleMode_ = { false, false }; 182 std::pair<bool, bool> bubble_ = { true, false }; 183 std::pair<bool, bool> multiLanguage_ = { false, false }; 184 185 std::vector<std::string> indexerAlphabet_; 186 bool needUpdateIds_ = false; 187 188 // list divider 189 bool needDivider_ = false; 190 Dimension dividerHeight_ = DIVIDER_DEFAULT_HEIGHT; 191 Dimension dividerLength_; 192 Dimension dividerOrigin_; 193 Color dividerColor_ = Color::TRANSPARENT; 194 195 EventMarker onScroll_; 196 EventMarker onScrollTop_; 197 EventMarker onScrollBottom_; 198 EventMarker onScrollEnd_; 199 EventMarker onScrollTouchUp_; 200 EventMarker onIndexerChange_; 201 FlexDirection flexDirection_ { FlexDirection::COLUMN }; 202 FlexAlign crossAxisAlign_ { FlexAlign::STRETCH }; 203 EdgeEffect edgeEffect_ = EdgeEffect::SPRING; 204 DisplayMode displayMode_ = DisplayMode::OFF; 205 ShapeMode shapeMode_ = ShapeMode::DEFAULT; 206 Color fadeColor_ = Color::GRAY; 207 Color backgroundColor_ = Color::TRANSPARENT; 208 std::string selectedItem_; 209 210 RefPtr<ScrollBar> scrollBar_; 211 212 int32_t beginIndex_ = LIST_PARAM_INVAID; 213 int32_t endIndex_ = LIST_PARAM_INVAID; 214 int32_t repeatedLength_ = 0; 215 int32_t indexOffset_ = 0; 216 217 int32_t initialIndex_ = 0; 218 double initialOffset_ = 0.0; 219 220 RefPtr<ListComponent> listComponent_; 221 RefPtr<IndexerListComponent> indexerComponent_; 222 }; 223 224 } // namespace OHOS::Ace::Framework 225 226 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_LIST_H 227