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/pipeline/base/sole_child_element.h"
17
18 #include "core/components_v2/list/list_item_component.h"
19
20 namespace OHOS::Ace {
21
Create()22 RefPtr<Element> SoleChildElement::Create()
23 {
24 return AceType::MakeRefPtr<SoleChildElement>();
25 }
26
PerformBuild()27 void SoleChildElement::PerformBuild()
28 {
29 RefPtr<SoleChildComponent> component = AceType::DynamicCast<SoleChildComponent>(component_);
30 if (!component) {
31 LOGW("Should be sole child component, but %s", AceType::TypeName(component_));
32 return;
33 }
34 const auto& child = children_.empty() ? nullptr : children_.front();
35 UpdateChild(child, component->GetChild());
36 }
37
38 // special handling for noGridItem, ListItem
39 // whose 'wrapping' component are descendants, not ancestors
LocalizedUpdateWithItemComponent(const RefPtr<Component> & innerMostWrappingComponent,const RefPtr<Component> & mainComponent)40 void SoleChildElement::LocalizedUpdateWithItemComponent(
41 const RefPtr<Component>& innerMostWrappingComponent, const RefPtr<Component>& mainComponent)
42 {
43 ACE_DCHECK(((AceType::DynamicCast<V2::ListItemComponent>(mainComponent) != nullptr) ||
44 (AceType::DynamicCast<GridLayoutItemComponent>(mainComponent) != nullptr)) &&
45 CanUpdate(mainComponent));
46
47 RefPtr<Element> updateElement = AceType::Claim(this);
48 auto updateComponent = mainComponent;
49
50 for (;;) {
51 updateElement->SetNewComponent(updateComponent);
52 updateElement->LocalizedUpdate(); // virtual
53 updateElement->SetNewComponent(nullptr);
54
55 updateElement = updateElement->GetFirstChild();
56 auto sc = AceType::DynamicCast<SingleChild>(updateComponent);
57 if ((updateElement == nullptr) || (sc == nullptr) || (sc->GetChild() == nullptr)) {
58 break;
59 }
60 updateComponent = sc->GetChild();
61 }
62 }
63
64 } // namespace OHOS::Ace
65