1 /*
2  * Copyright (c) 2021-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 #include <unordered_map>
16 
17 #include "core/components_v2/inspector/blank_composed_element.h"
18 
19 #include "base/log/dump_log.h"
20 
21 namespace OHOS::Ace::V2 {
22 
23 namespace {
24 
25 const std::unordered_map<std::string, std::function<std::string(const BlankComposedElement&)>> CREATE_JSON_MAP {
__anon7ac10f040202(const BlankComposedElement& inspector) 26     { "min", [](const BlankComposedElement& inspector) { return inspector.GetMin(); } },
__anon7ac10f040302(const BlankComposedElement& inspector) 27     { "color", [](const BlankComposedElement& inspector) { return inspector.GetColor(); } }
28 };
29 
30 }
31 
Dump()32 void BlankComposedElement::Dump()
33 {
34     DumpLog::GetInstance().AddDesc(std::string("blank_composed_element"));
35     DumpLog::GetInstance().AddDesc(std::string("min: ").append(GetMin()));
36     DumpLog::GetInstance().AddDesc(std::string("color: ").append(GetColor()));
37 }
38 
ToJsonObject() const39 std::unique_ptr<JsonValue> BlankComposedElement::ToJsonObject() const
40 {
41     auto resultJson = JsonUtil::Create(true);
42     for (const auto& value : CREATE_JSON_MAP) {
43         resultJson->Put(value.first.c_str(), value.second(*this).c_str());
44     }
45     return resultJson;
46 }
47 
GetMin() const48 std::string BlankComposedElement::GetMin() const
49 {
50     auto renderFlexItem = GetRenderFlexItem();
51     auto min = renderFlexItem ? renderFlexItem->GetFlexBasis().ToString() : "0.0";
52     return min;
53 }
54 
GetColor() const55 std::string BlankComposedElement::GetColor() const
56 {
57     std::string color = GetBackgroundColor();
58     if (color.empty() || color == "NONE") {
59         color = "0x00000000";
60     }
61     return color;
62 }
63 
GetRenderFlexItem() const64 RefPtr<RenderFlexItem> BlankComposedElement::GetRenderFlexItem() const
65 {
66     auto node = GetInspectorNode(FlexItemElement::TypeId());
67     if (node) {
68         return AceType::DynamicCast<RenderFlexItem>(node);
69     }
70     return nullptr;
71 }
72 
73 } // namespace OHOS::Ace::V2