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_DIV_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_DIV_H 18 19 #include "base/utils/macros.h" 20 #include "core/components/flex/flex_component.h" 21 #include "core/components/grid_layout/grid_layout_component.h" 22 #include "core/components/grid_layout/grid_layout_item_component.h" 23 #include "core/components/scroll/scroll_component.h" 24 #include "core/components/theme/card_theme.h" 25 #include "core/components/wrap/wrap_component.h" 26 #include "frameworks/bridge/common/dom/dom_node.h" 27 28 namespace OHOS::Ace::Framework { 29 30 class DOMDiv : public DOMNode { 31 DECLARE_ACE_TYPE(DOMDiv, DOMNode); 32 33 public: 34 DOMDiv(NodeId nodeId, const std::string& nodeName); 35 ~DOMDiv() override = default; 36 GetFlexDirection()37 FlexDirection GetFlexDirection() const 38 { 39 return flexDirection_; 40 }; 41 GetScrollComponent()42 const RefPtr<ScrollComponent>& GetScrollComponent() const override 43 { 44 return scroll_; 45 } 46 47 RefPtr<Component> GetSpecializedComponent() override; 48 void AdjustSpecialParamInLiteMode() override; 49 50 protected: 51 void OnMounted(const RefPtr<DOMNode>& parentNode) override; 52 void OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot) override; 53 void OnChildNodeRemoved(const RefPtr<DOMNode>& child) override; 54 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 55 void PrepareSpecializedComponent() override; 56 void CompositeComponents() override; 57 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 58 bool AddSpecializedEvent(int32_t pageId, const std::string& event) override; 59 60 RefPtr<FlexComponent> flexChild_; 61 RefPtr<WrapComponent> wrapChild_; 62 std::string direction_ { DOM_FLEX_ROW }; 63 64 private: 65 enum class AxisAlign { 66 START = 0, 67 CENTER = 1, 68 END = 2, 69 }; 70 71 static Alignment ComputeFlexAlign(FlexAlign flexMainAlign, FlexAlign flexCrossAlign, bool isColumn, bool isRtl); 72 void CreateOrUpdateGrid(); 73 void CreateOrUpdateGridItem(); 74 void CreateOrUpdateFlex(); 75 void CreateOrUpdateWrap(); 76 void SetBoxWidthFlex(bool isHorizontal) const; 77 void SetRootBoxHeight() const; 78 void SetFlexHeight(FlexAlign flexMainAlign); 79 void SetCardThemeAttrs(); 80 void InitScrollBar(); 81 void SetSpecializedOverflow(); 82 83 bool isFlexWrap_ = false; 84 std::string justifyContent_ { DOM_JUSTIFY_CONTENT_START }; 85 std::string alignItems_ { DOM_ALIGN_ITEMS_STRETCH }; 86 std::string alignContent_ { DOM_ALIGN_CONTENT_START }; 87 88 // Wrap's variables 89 double spacing_ = 0.0; 90 double contentSpacing_ = 0.0; 91 92 // flex properties. 93 FlexDirection flexDirection_ = FlexDirection::ROW; 94 TextDirection textDirection_ = TextDirection::LTR; 95 96 // for grid layout 97 std::string columnsArgs_; 98 std::string rowsArgs_; 99 Dimension columnGap_ = 0.0_px; 100 Dimension rowGap_ = 0.0_px; 101 102 // for grid layout item 103 int32_t columnStart_ = -1; 104 int32_t columnEnd_ = -1; 105 int32_t rowStart_ = -1; 106 int32_t rowEnd_ = -1; 107 108 // for scroll reaching the edge event 109 EventMarker onReachStart_; 110 EventMarker onReachEnd_; 111 EventMarker onReachTop_; 112 EventMarker onReachBottom_; 113 114 RefPtr<ScrollComponent> scroll_; 115 RefPtr<GridLayoutComponent> grid_; 116 RefPtr<GridLayoutItemComponent> gridItem_; 117 RefPtr<CardTheme> cardTheme_; 118 bool isCardBlur_ = false; 119 bool isCard_ = false; 120 }; 121 122 } // namespace OHOS::Ace::Framework 123 124 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_DIV_H 125