• 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/related_node.h"
17 
18 #include "core/pipeline/base/render_node.h"
19 
20 namespace OHOS::Ace {
21 namespace {
22 
23 constexpr int32_t MAX_DEEP_SEARCH = 10;
24 
25 }
26 
InitRelatedParent(const WeakPtr<RenderNode> & weakParent)27 void RelatedChild::InitRelatedParent(const WeakPtr<RenderNode>& weakParent)
28 {
29     int32_t searchDeep = 0;
30     auto parent = weakParent.Upgrade();
31     while (searchDeep++ < MAX_DEEP_SEARCH && parent) {
32         auto relatedContainer = AceType::DynamicCast<RelatedContainer>(parent);
33         if (relatedContainer) {
34             LOGD("has related container parent");
35             relatedParent_ = AceType::WeakClaim(AceType::RawPtr(relatedContainer));
36             return;
37         } else {
38             parent = parent->GetParent().Upgrade();
39         }
40     }
41 }
42 
RelatedEventStart()43 void RelatedChild::RelatedEventStart()
44 {
45     if (!IsRelatedEventEnable()) {
46         return;
47     }
48     auto parent = relatedParent_.Upgrade();
49     parent->OnRelatedStart();
50 }
51 
RelatedScrollEventPrepare(const Offset & delta)52 bool RelatedChild::RelatedScrollEventPrepare(const Offset& delta)
53 {
54     if (!IsRelatedEventEnable()) {
55         return false;
56     }
57     auto parent = relatedParent_.Upgrade();
58     Offset consumed;
59     parent->OnRelatedPreScroll(delta, consumed);
60     if (!NearZero(consumed.GetY())) {
61         return true;
62     }
63     return false;
64 }
65 
RelatedScrollEventDoing(const Offset & delta)66 bool RelatedChild::RelatedScrollEventDoing(const Offset& delta)
67 {
68     if (!IsRelatedEventEnable()) {
69         return false;
70     }
71     auto parent = relatedParent_.Upgrade();
72     Offset consumed;
73     parent->OnRelatedScroll(delta, consumed);
74     if (!NearZero(consumed.GetY())) {
75         return true;
76     }
77     return false;
78 }
79 
RelatedEventEnd()80 void RelatedChild::RelatedEventEnd()
81 {
82     if (!IsRelatedEventEnable()) {
83         return;
84     }
85     auto parent = relatedParent_.Upgrade();
86     parent->OnRelatedEnd();
87 }
88 
89 } // namespace OHOS::Ace
90