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