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 "frameworks/bridge/common/dom/dom_proxy.h"
17 
18 namespace OHOS::Ace::Framework {
19 
Mount(int32_t slot)20 void DOMProxy::Mount(int32_t slot)
21 {
22     auto parentNode = parentNode_.Upgrade();
23     if (!parentNode) {
24         return;
25     }
26     rootComponent_->SetChild(boxComponent_);
27     rootComponent_->MarkNeedUpdate();
28 
29     parentNode->AddNode(AceType::Claim(this), slot);
30     OnMounted(parentNode);
31 }
32 
SetShowAttr(const std::string & showValue)33 void DOMProxy::SetShowAttr(const std::string& showValue)
34 {
35     auto targetNode = targetNode_.Upgrade();
36     if (!targetNode) {
37         return;
38     }
39     auto targetDeclaration = targetNode->GetDeclaration();
40     if (targetDeclaration) {
41         targetDeclaration->SetHasDisplayStyle(true);
42     }
43     targetNode->SetShowAttr(showValue);
44     targetNode->GetRootComponent()->SetUpdateType(UpdateType::ALL);
45     targetNode->GenerateComponentNode();
46     auto pipeline = pipelineContext_.Upgrade();
47     if (pipeline) {
48         pipeline->ScheduleUpdate(targetNode->GetRootComponent());
49     }
50 }
51 
ConnectWith(const WeakPtr<DOMNode> & target)52 void DOMProxy::ConnectWith(const WeakPtr<DOMNode>& target)
53 {
54     targetNode_ = target;
55 }
56 
UpdateStyleWithChildren()57 void DOMProxy::UpdateStyleWithChildren()
58 {
59     auto target = targetNode_.Upgrade();
60     if (!target) {
61         return;
62     }
63     target->UpdateStyleWithChildren();
64 }
65 
SetIsIgnored(bool ignore)66 void DOMProxy::SetIsIgnored(bool ignore)
67 {
68     if (boxComponent_) {
69         boxComponent_->SetIsIgnored(ignore);
70     }
71 }
72 
73 } // namespace OHOS::Ace::Framework
74