• 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     RefPtr<Element> updateElement = AceType::Claim(this);
52     auto updateComponent = mainComponent;
53 
54     for (;;) {
55         updateElement->SetNewComponent(updateComponent);
56         updateElement->LocalizedUpdate(); // virtual
57         updateElement->SetNewComponent(nullptr);
58 
59         updateElement = updateElement->GetFirstChild();
60         auto sc = AceType::DynamicCast<SingleChild>(updateComponent);
61         if ((updateElement == nullptr) || (sc == nullptr) || (sc->GetChild() == nullptr)) {
62             break;
63         }
64         updateComponent = sc->GetChild();
65     }
66 }
67 
68 } // namespace OHOS::Ace
69