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_STACK_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_STACK_H 18 19 #include "base/utils/macros.h" 20 #include "core/components/common/properties/alignment.h" 21 #include "core/components/stack/stack_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 DOMStack final : public DOMNode { 28 DECLARE_ACE_TYPE(DOMStack, DOMNode); 29 30 public: 31 DOMStack(NodeId nodeId, const std::string& nodeName); 32 ~DOMStack() override = default; 33 GetSpecializedComponent()34 RefPtr<Component> GetSpecializedComponent() override 35 { 36 return stackChild_; 37 } 38 GetScrollComponent()39 const RefPtr<ScrollComponent>& GetScrollComponent() const override 40 { 41 return scroll_; 42 } 43 44 protected: 45 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 46 void PrepareSpecializedComponent() override; 47 void OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot) override; 48 void OnChildNodeRemoved(const RefPtr<DOMNode>& child) override; 49 void CompositeComponents() override; 50 51 private: 52 bool GetAxisOffset(const std::pair<std::string, std::string>& style); 53 void InitScrollBar(); 54 55 enum AxisAlign { 56 START = 0, 57 CENTER = 1, 58 END = 2, 59 }; 60 61 // Nine patched table 62 const Alignment AlignArray[3][3] { { Alignment::TOP_LEFT, Alignment::TOP_CENTER, Alignment::TOP_RIGHT }, 63 { Alignment::CENTER_LEFT, Alignment::CENTER, Alignment::CENTER_RIGHT }, 64 { Alignment::BOTTOM_LEFT, Alignment::BOTTOM_CENTER, Alignment::BOTTOM_RIGHT } }; 65 66 uint8_t mainAxisAlign_ { 0 }; 67 uint8_t crossAxisAlign_ { 0 }; 68 FlexDirection direction_ { FlexDirection::ROW }; 69 70 RefPtr<ScrollComponent> scroll_; 71 RefPtr<StackComponent> stackChild_; 72 StackFit stackFit_ { StackFit::KEEP }; 73 Alignment alignment_ { Alignment::CENTER }; 74 }; 75 76 } // namespace OHOS::Ace::Framework 77 78 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_STACK_H 79