• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "core/components_v2/inspector/search_composed_element.h"
17 
18 #include "core/components/search/search_element.h"
19 
20 #include "base/log/dump_log.h"
21 
22 namespace OHOS::Ace::V2 {
23 
24 const std::unordered_map<std::string, std::function<std::string(const SearchComposedElement&)>> CREATE_JSON_MAP {
__anonb40db07a0102(const SearchComposedElement& inspector) 25     { "icon", [](const SearchComposedElement& inspector) { return inspector.GetIcon(); } },
__anonb40db07a0202(const SearchComposedElement& inspector) 26     { "searchButton", [](const SearchComposedElement& inspector) { return inspector.GetSearchButton(); } },
__anonb40db07a0302(const SearchComposedElement& inspector) 27     { "placeholderColor", [](const SearchComposedElement& inspector) { return inspector.GetColor(); } }
28 };
29 
Dump(void)30 void SearchComposedElement::Dump(void)
31 {
32     InspectorComposedElement::Dump();
33     DumpLog::GetInstance().AddDesc(std::string("search_composed_element"));
34     DumpLog::GetInstance().AddDesc(
35         std::string("icon: ").append(GetIcon()));
36     DumpLog::GetInstance().AddDesc(
37         std::string("searchButton: ").append(GetSearchButton()));
38 }
39 
ToJsonObject() const40 std::unique_ptr<OHOS::Ace::JsonValue> SearchComposedElement::ToJsonObject() const
41 {
42     auto resultJson = InspectorComposedElement::ToJsonObject();
43     for (const auto& value : CREATE_JSON_MAP) {
44         resultJson->Put(value.first.c_str(), value.second(*this).c_str());
45     }
46     return resultJson;
47 }
48 
GetIcon(void) const49 std::string SearchComposedElement::GetIcon(void) const
50 {
51     auto renderSearch = GetRenderSearch();
52     std::string icon = renderSearch ? renderSearch->GetSearchComponent()->GetCloseIconSrc() : "";
53     return icon;
54 }
55 
GetSearchButton(void) const56 std::string SearchComposedElement::GetSearchButton(void) const
57 {
58     auto renderSearch = GetRenderSearch();
59     std::string searchButton = renderSearch ? renderSearch->GetSearchComponent()->GetSearchText() : "";
60     return searchButton;
61 }
62 
GetColor(void) const63 std::string SearchComposedElement::GetColor(void) const
64 {
65     auto renderSearch = GetRenderSearch();
66     if (!renderSearch) {
67         return "";
68     }
69     auto component = renderSearch->GetSearchComponent();
70     if (!component) {
71         return "";
72     }
73     auto textFieldComponent = AceType::DynamicCast<TextFieldComponent>(component->GetChild());
74     if (!textFieldComponent) {
75         return "";
76     }
77     return textFieldComponent->GetPlaceholderColor().ColorToString();
78 }
79 
GetRenderSearch() const80 OHOS::Ace::RefPtr<OHOS::Ace::RenderSearch> SearchComposedElement::GetRenderSearch() const
81 {
82     auto node = GetInspectorNode(SearchElement::TypeId());
83     if (node) {
84         return AceType::DynamicCast<RenderSearch>(node);
85     }
86     return nullptr;
87 }
88 
89 } // namespace OHOS::Ace::V2
90