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