1 /*
2  * Copyright (c) 2023 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/components_ng/event/response_ctrl.h"
17 
18 #include "base/log/log.h"
19 #include "base/log/log_wrapper.h"
20 #include "core/components_ng/base/frame_node.h"
21 
22 namespace OHOS::Ace::NG {
ShouldResponse(const WeakPtr<NG::FrameNode> & frameNode)23 bool ResponseCtrl::ShouldResponse(const WeakPtr<NG::FrameNode>& frameNode)
24 {
25     if (state_ != MonopolizeState::ON) {
26         return true;
27     }
28     return frameNode == firstResponseNode_;
29 }
30 
TrySetFirstResponse(const WeakPtr<NG::FrameNode> & frameNode)31 void ResponseCtrl::TrySetFirstResponse(const WeakPtr<NG::FrameNode>& frameNode)
32 {
33     if (state_ != MonopolizeState::INIT) {
34         return;
35     }
36     auto node = frameNode.Upgrade();
37     if (node) {
38         state_ = node->GetMonopolizeEvents() ? MonopolizeState::ON : MonopolizeState::OFF;
39         firstResponseNode_ = frameNode;
40         if (state_ == MonopolizeState::ON) {
41             TAG_LOGI(
42                 AceLogTag::ACE_GESTURE, "monopolize on by node id:" SEC_PLD(%{public}d) ", tag:%s",
43                     SEC_PARAM(node->GetId()), node->GetTag().c_str());
44         }
45     }
46 }
47 
Reset()48 void ResponseCtrl::Reset()
49 {
50     if (state_ == MonopolizeState::ON) {
51         TAG_LOGI(AceLogTag::ACE_GESTURE, "monopolize reset from on");
52     }
53     state_ = MonopolizeState::INIT;
54     firstResponseNode_.Reset();
55 }
56 } // namespace OHOS::Ace::NG
57