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_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_BAR_COMPONENT_BASE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_BAR_COMPONENT_BASE_H
18 
19 #include "core/components/button/button_component.h"
20 #include "core/components/image/image_component.h"
21 #include "core/components/navigation_bar/navigation_bar_theme.h"
22 #include "core/components/text/text_component.h"
23 #include "core/pipeline/base/component.h"
24 
25 namespace OHOS::Ace {
26 
27 class PaddingComponent;
28 class ComposedComponent;
29 class NavigationBarTheme;
30 class EventMarker;
31 
32 class NavigationBarComponentBase {
33 public:
34     NavigationBarComponentBase() = default;
35     virtual ~NavigationBarComponentBase() = default;
36 protected:
37     struct IconImage {
IconImageIconImage38         IconImage(InternalResource::ResourceId resourceId, const Dimension& width, const Dimension& height)
39             : resourceId(resourceId), width(width), height(height),
40               image(AceType::MakeRefPtr<ImageComponent>(resourceId))
41         {
42             image->SetWidth(width);
43             image->SetHeight(height);
44         };
45         IconImage(const std::string& src, const Dimension& width, const Dimension& height,
46             std::optional<Color> imageFill = std::nullopt)
47             : src(src), width(width), height(height), image(AceType::MakeRefPtr<ImageComponent>(src))
48         {
49             image->SetWidth(width);
50             image->SetHeight(height);
51             image->SetImageFill(imageFill);
52         };
53         ~IconImage() = default;
54 
55         InternalResource::ResourceId resourceId = InternalResource::ResourceId::NO_ID;
56         std::string src;
57         Dimension width;
58         Dimension height;
59         RefPtr<ImageComponent> image;
60     };
61 
62     RefPtr<ButtonComponent> BuildIconButton(const RefPtr<NavigationBarTheme>& theme, const Dimension& width,
63         const Dimension& height, const IconImage& icon, const EventMarker& clickMarker = EventMarker());
64     RefPtr<TextComponent> BuildTitleText(
65         const std::string& value, const Color& color, const Dimension& fontSize, const FontWeight& fontWeight);
66     RefPtr<PaddingComponent> BuildPadding(double size, bool isVertical = false);
67     RefPtr<ComposedComponent> GenerateAccessibilityComposed(
68         int32_t parentId, const std::string& name, const RefPtr<Component>& child);
69 
70     WeakPtr<PipelineContext> context_;
71 };
72 } // namespace OHOS::Ace
73 
74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_BAR_COMPONENT_BASE_H
75