• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 JS_ACCESSIBILITY_EXTENSION_H
17 #define JS_ACCESSIBILITY_EXTENSION_H
18 
19 #include "accessibility_extension.h"
20 #include "js_runtime.h"
21 #include "native_reference.h"
22 #include "native_value.h"
23 
24 namespace OHOS {
25 namespace Accessibility {
26 class JsAccessibilityExtension : public AccessibilityExtension {
27 public:
28     JsAccessibilityExtension(AbilityRuntime::JsRuntime& jsRuntime);
29     virtual ~JsAccessibilityExtension() override;
30 
31     /**
32      * @brief Create JsAccessibilityExtension.
33      *
34      * @param runtime The runtime.
35      * @return The JsAccessibilityExtension instance.
36      */
37     static JsAccessibilityExtension* Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime);
38 
39     /**
40      * @brief Init the extension.
41      *
42      * @param record the extension record.
43      * @param application the application info.
44      * @param handler the extension handler.
45      * @param token the remote token.
46      */
47     void Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record,
48         const std::shared_ptr<AppExecFwk::OHOSApplication> &application,
49         std::shared_ptr<AppExecFwk::AbilityHandler> &handler,
50         const sptr<IRemoteObject> &token) override;
51 
52     /**
53      * @brief Called when this Accessibility extension is connected for the first time.
54      *
55      * You can override this function to implement your own processing logic.
56      *
57      * @param want Indicates the {@link Want} structure containing connection information
58      * about the Accessibility extension.
59      * @return Returns a pointer to the <b>sid</b> of the connected Accessibility extension.
60      */
61     sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override;
62 
63     /**
64      * @brief Called when your accessibility service is successfully connected to the OS.
65      * @param
66      * @return
67      */
68     void OnAbilityConnected() override;
69 
70     /**
71      * @brief Called when an accessibility event occurs.
72      * @param eventInfo The information of accessible event.
73      * @return
74      */
75     void OnAccessibilityEvent(const AccessibilityEventInfo& eventInfo) override;
76 
77     /**
78      * @brief Called when a key event occurs.
79      * @param keyEvent Indicates the key event to send.
80      * @return Returns true if the event has been consumed; returns false otherwise.
81      *         The event that has been consumed will not be sent to the application.
82      */
83     bool OnKeyPressEvent(const MMI::KeyEvent& keyEvent) override;
84 
85 private:
86     NativeValue* CallObjectMethod(const char* name, NativeValue * const * argv = nullptr, size_t argc = 0);
87 
88     void GetSrcPath(std::string &srcPath);
89 
90     AbilityRuntime::JsRuntime& jsRuntime_;
91     std::unique_ptr<NativeReference> jsObj_;
92 };
93 } // namespace Accessibility
94 } // namespace OHOS
95 
96 #endif  // JS_ACCESSIBILITY_EXTENSION_H