• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PLATFORM_ACCESSIBILITY_CHILD_TREE_CALLBACK_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PLATFORM_ACCESSIBILITY_CHILD_TREE_CALLBACK_H
18 
19 #include "core/accessibility/accessibility_manager.h"
20 #include "core/components_ng/pattern/ui_extension/platform_accessibility_base.h"
21 
22 namespace OHOS::Ace::NG {
23 
24 class PlatformAccessibilityChildTreeCallback : public AccessibilityChildTreeCallback {
25 public:
PlatformAccessibilityChildTreeCallback(const WeakPtr<PlatformAccessibilityBase> & weakPattern,int64_t accessibilityId)26     PlatformAccessibilityChildTreeCallback(
27         const WeakPtr<PlatformAccessibilityBase> &weakPattern, int64_t accessibilityId)
28         : AccessibilityChildTreeCallback(accessibilityId), weakPattern_(weakPattern)
29     {}
30 
31     ~PlatformAccessibilityChildTreeCallback() override = default;
32 
OnRegister(uint32_t windowId,int32_t treeId)33     bool OnRegister(uint32_t windowId, int32_t treeId) override
34     {
35         auto pattern = weakPattern_.Upgrade();
36         CHECK_NULL_RETURN(pattern, false);
37         if (isReg_) {
38             return true;
39         }
40         pattern->OnAccessibilityChildTreeRegister(windowId, treeId, GetAccessibilityId());
41         isReg_ = true;
42         return true;
43     }
44 
OnDeregister()45     bool OnDeregister() override
46     {
47         auto pattern = weakPattern_.Upgrade();
48         CHECK_NULL_RETURN(pattern, false);
49         if (!isReg_) {
50             return true;
51         }
52         pattern->OnAccessibilityChildTreeDeregister();
53         isReg_ = false;
54         return true;
55     }
56 
OnSetChildTree(int32_t childWindowId,int32_t childTreeId)57     bool OnSetChildTree(int32_t childWindowId, int32_t childTreeId) override
58     {
59         auto pattern = weakPattern_.Upgrade();
60         CHECK_NULL_RETURN(pattern, false);
61         pattern->OnSetAccessibilityChildTree(childWindowId, childTreeId);
62         return true;
63     }
64 
OnDumpChildInfo(const std::vector<std::string> & params,std::vector<std::string> & info)65     bool OnDumpChildInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override
66     {
67         auto pattern = weakPattern_.Upgrade();
68         CHECK_NULL_RETURN(pattern, false);
69         pattern->OnAccessibilityDumpChildInfo(params, info);
70         return true;
71     }
72 
OnClearRegisterFlag()73     void OnClearRegisterFlag() override
74     {
75         isReg_ = false;
76     }
77 
78 private:
79     bool isReg_ = false;
80     WeakPtr<PlatformAccessibilityBase> weakPattern_;
81 };
82 
83 } // namespace OHOS::Ace::NG
84 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PLATFORM_ACCESSIBILITY_CHILD_TREE_CALLBACK_H