• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 WINDOW_EXTENSION_CONNECTION_H
17 #define WINDOW_EXTENSION_CONNECTION_H
18 
19 #include <string>
20 #include <element_name.h>
21 #include <i_input_event_consumer.h>
22 #include <input_manager.h>
23 #include <key_event.h>
24 #include <pointer_event.h>
25 #include <memory>
26 
27 #include "wm_common.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace {
32 const std::string RECT_FORM_KEY_POS_X = "ext_pos_x";
33 const std::string RECT_FORM_KEY_POS_Y = "ext_pos_y";
34 const std::string RECT_FORM_KEY_HEIGHT = "ext_pos_heigh";
35 const std::string RECT_FORM_KEY_WIDTH = "ext_pos_width";
36 const std::string WINDOW_ID = "ext_window_id";
37 }
38 
39 class RSSurfaceNode;
40 class ExtensionSession;
41 /**
42  * @class IWindowExtensionCallback
43  *
44  * @brief Callback of window extension.
45  */
46 class IWindowExtensionCallback : virtual public RefBase {
47 public:
48     /**
49      * @brief Window ready to connect.
50      *
51      * @param rsSurfaceNode Surface node from RS.
52      */
53     virtual void OnWindowReady(const std::shared_ptr<RSSurfaceNode>& rsSurfaceNode) = 0;
54 
55     /**
56      * @brief Callback when window extension disconnected.
57      */
58     virtual void OnExtensionDisconnected() = 0;
59 
60     /**
61      * @brief Callback when receive key event.
62      *
63      * @param event Keyboard event.
64      */
65     virtual void OnKeyEvent(const std::shared_ptr<MMI::KeyEvent>& event) = 0;
66 
67     /**
68      * @brief Callback when receive pointer event.
69      *
70      * @param event Pointer event.
71      */
72     virtual void OnPointerEvent(const std::shared_ptr<MMI::PointerEvent>& event) = 0;
73 
74     /**
75      * @brief Callback when press back button.
76      */
77     virtual void OnBackPress() = 0;
78 };
79 
80 /**
81  * @class WindowExtensionConnection
82  *
83  * @brief Connection for window extension.
84  */
85 class WindowExtensionConnection : public RefBase {
86 public:
87     /**
88      * @brief Constructor for WindowExtensionConnection.
89      */
90     WindowExtensionConnection();
91 
92     /**
93      * @brief Deconstructor for WindowExtensionConnection.
94      */
95     ~WindowExtensionConnection();
96 
97     /**
98      * @brief Deconstructor for WindowExtensionConnection.
99      *
100      * @param element Element name.
101      * @param rect Rect of window extension.
102      * @param uid User id.
103      * @param windowId Window id.
104      * @param callback Callback for window extension.
105      * @return ERR_OK means connect success, others means connect failed.
106      */
107     int ConnectExtension(const AppExecFwk::ElementName& element, const Rect& rect,
108         uint32_t uid, uint32_t windowId, const sptr<IWindowExtensionCallback>& callback) const;
109 
110     /**
111      * @brief Deconstructor for WindowExtensionConnection.
112      *
113      * @param element Element name.
114      * @param rect Rect of window extension.
115      * @param uid User id.
116      * @param windowId Window id.
117      * @param callback Callback for window extension.
118      * @param extensionSession session for extension
119      * @return ERR_OK means connect success, others means connect failed.
120      */
121     int ConnectExtension(const AppExecFwk::ElementName& element, const Rect& rect,
122         uint32_t uid, uint32_t windowId, const sptr<IWindowExtensionCallback>& callback,
123         const sptr<ExtensionSession>& extensionSession) const;
124 
125     /**
126      * @brief Disconnect window extension.
127      */
128     void DisconnectExtension() const;
129 
130     /**
131      * @brief Show window extension.
132      */
133     void Show() const;
134 
135     /**
136      * @brief Hide window extension.
137      */
138     void Hide() const;
139 
140     /**
141      * @brief Request focus of window extension.
142      */
143     void RequestFocus() const;
144 
145     /**
146      * @brief Set bounds of window extension.
147      *
148      * @param rect Window extension rect.
149      */
150     void SetBounds(const Rect& rect) const;
151 private:
152     class Impl;
153     sptr<Impl> pImpl_;
154 };
155 } // namespace Rosen
156 } // namespace OHOS
157 #endif // WINDOW_EXTENSION_CONNECTION_H