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 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
29namespace OHOS {
30namespace Rosen {
31namespace {
32const std::string RECT_FORM_KEY_POS_X = "ext_pos_x";
33const std::string RECT_FORM_KEY_POS_Y = "ext_pos_y";
34const std::string RECT_FORM_KEY_HEIGHT = "ext_pos_heigh";
35const std::string RECT_FORM_KEY_WIDTH = "ext_pos_width";
36const std::string WINDOW_ID = "ext_window_id";
37}
38
39class RSSurfaceNode;
40class ExtensionSession;
41/**
42 * @class IWindowExtensionCallback
43 *
44 * @brief Callback of window extension.
45 */
46class IWindowExtensionCallback : virtual public RefBase {
47public:
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     * @brief Callback when window extension disconnected.
56     */
57    virtual void OnExtensionDisconnected() = 0;
58    /**
59     * @brief Callback when receive key event.
60     *
61     * @param event Keyboard event.
62     */
63    virtual void OnKeyEvent(const std::shared_ptr<MMI::KeyEvent>& event) = 0;
64    /**
65     * @brief Callback when receive pointer event.
66     *
67     * @param event Pointer event.
68     */
69    virtual void OnPointerEvent(const std::shared_ptr<MMI::PointerEvent>& event) = 0;
70    /**
71     * @brief Callback when press back button.
72     */
73    virtual void OnBackPress() = 0;
74};
75
76/**
77 * @class WindowExtensionConnection
78 *
79 * @brief Connection for window extension.
80 */
81class WindowExtensionConnection : public RefBase {
82public:
83    /**
84     * @brief Constructor for WindowExtensionConnection.
85     */
86    WindowExtensionConnection();
87    /**
88     * @brief Deconstructor for WindowExtensionConnection.
89     */
90    ~WindowExtensionConnection();
91    /**
92     * @brief Deconstructor for WindowExtensionConnection.
93     *
94     * @param element Element name.
95     * @param rect Rect of window extension.
96     * @param uid User id.
97     * @param windowId Window id.
98     * @param callback Callback for window extension.
99     * @return ERR_OK means connect success, others means connect failed.
100     */
101    int ConnectExtension(const AppExecFwk::ElementName& element, const Rect& rect,
102        uint32_t uid, uint32_t windowId, const sptr<IWindowExtensionCallback>& callback) const;
103    /**
104     * @brief Deconstructor for WindowExtensionConnection.
105     *
106     * @param element Element name.
107     * @param rect Rect of window extension.
108     * @param uid User id.
109     * @param windowId Window id.
110     * @param callback Callback for window extension.
111     * @param extensionSession session for extension
112     * @return ERR_OK means connect success, others means connect failed.
113     */
114    int ConnectExtension(const AppExecFwk::ElementName& element, const Rect& rect,
115        uint32_t uid, uint32_t windowId, const sptr<IWindowExtensionCallback>& callback,
116        const sptr<ExtensionSession>& extensionSession) const;
117    /**
118     * @brief Disconnect window extension.
119     */
120    void DisconnectExtension() const;
121    /**
122     * @brief Show window extension.
123     */
124    void Show() const;
125    /**
126     * @brief Hide window extension.
127     */
128    void Hide() const;
129    /**
130     * @brief Request focus of window extension.
131     */
132    void RequestFocus() const;
133    /**
134     * @brief Set bounds of window extension.
135     *
136     * @param rect Window extension rect.
137     */
138    void SetBounds(const Rect& rect) const;
139private:
140    class Impl;
141    sptr<Impl> pImpl_;
142};
143} // namespace Rosen
144} // namespace OHOS
145#endif // WINDOW_EXTENSION_CONNECTION_H