1 /*
2  * Copyright (c) 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_CONTAINER_MODAL_CONTAINER_MODAL_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CONTAINER_MODAL_CONTAINER_MODAL_COMPONENT_H
18 
19 #include "core/components/button/button_component.h"
20 #include "core/components/flex/flex_component.h"
21 #include "core/components/image/image_component.h"
22 #include "core/components/text/text_component.h"
23 #include "core/pipeline/base/sole_child_component.h"
24 
25 namespace OHOS::Ace {
26 
27 class ContainerModalComponent : public SoleChildComponent {
28     DECLARE_ACE_TYPE(ContainerModalComponent, SoleChildComponent);
29 
30 public:
ContainerModalComponent(const WeakPtr<PipelineContext> & context)31     explicit ContainerModalComponent(const WeakPtr<PipelineContext>& context)
32     {
33         context_ = context;
34         auto pipelineContext = context_.Upgrade();
35         if (pipelineContext) {
36             isDeclarative_ = pipelineContext->GetIsDeclarative();
37         }
38     }
39 
40     ~ContainerModalComponent() override = default;
41     static RefPtr<Component> Create(const WeakPtr<PipelineContext>& context, const RefPtr<Component>& child);
42     RefPtr<Element> CreateElement() override;
43     RefPtr<RenderNode> CreateRenderNode() override;
44     void BuildInnerChild();
45     std::list<RefPtr<Component>> BuildTitleChildren(bool isFloating, bool isFocus = true, bool isFullWindow = true);
46 
GetTitleIcon()47     RefPtr<ImageComponent> GetTitleIcon() const
48     {
49         return titleIcon_;
50     }
51 
GetTitleLabel()52     RefPtr<TextComponent> GetTitleLabel() const
53     {
54         return titleLabel_;
55     }
56 
SetTitleButtonHide(bool hideSplit,bool hideMaximize,bool hideMinimize,bool hideClose)57     void SetTitleButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose)
58     {
59         hideSplit_ = hideSplit;
60         hideMaximize_ = hideMaximize;
61         hideMinimize_ = hideMinimize;
62         hideClose_ = hideClose;
63     }
64 
GetSplitButtonHide()65     bool GetSplitButtonHide() const
66     {
67         return hideSplit_;
68     }
69 
70 private:
71     RefPtr<Component> BuildTitle();
72     RefPtr<Component> BuildFloatingTitle();
73     RefPtr<Component> BuildContent();
74     RefPtr<Component> BuildControlButton(
75         InternalResource::ResourceId icon, std::function<void()>&& clickCallback, bool isFocus, bool isFloating);
76     void CreateAccessibilityNode(const std::string& tag, int32_t nodeId, int32_t parentNodeId);
77     static RefPtr<Component> SetPadding(
78         const RefPtr<Component>& component, const Dimension& leftPadding, const Dimension& rightPadding);
79 
80     WeakPtr<PipelineContext> context_;
81     RefPtr<ImageComponent> titleIcon_;
82     RefPtr<TextComponent> titleLabel_;
83     bool isDeclarative_ = true;
84     bool hideSplit_ = false;
85     bool hideMaximize_ = false;
86     bool hideMinimize_ = false;
87     bool hideClose_ = false;
88 };
89 
90 } // namespace OHOS::Ace
91 
92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CONTAINER_MODAL_CONTAINER_MODAL_COMPONENT_H
93