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 #ifndef FOUNDATION_ACE_INTERFACE_INNERKITS_XCOMPONENT_CONTROLLER_INTERFACE_H
17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_XCOMPONENT_CONTROLLER_INTERFACE_H
18 
19 #include <memory>
20 
21 typedef struct napi_value__* napi_value;
22 typedef struct napi_env__* napi_env;
23 
24 namespace OHOS::Ace {
25 #ifndef ACE_EXPORT
26 #define ACE_EXPORT __attribute__((visibility("default")))
27 #endif
28 
29 enum XComponentControllerErrorCode {
30     XCOMPONENT_CONTROLLER_NO_ERROR = 0,
31     XCOMPONENT_CONTROLLER_BAD_PARAMETER,
32     XCOMPONENT_CONTROLLER_TYPE_ERROR,
33     XCOMPONENT_CONTROLLER_REPEAT_SET,
34     XCOMPONENT_CONTROLLER_RESET_ERROR,
35 };
36 
37 enum class SurfaceCallbackMode : char {
38     DEFAULT = 0,
39     PIP,
40 };
41 
42 /**
43  * @class XComponentController
44  * XComponentController interface is used to control xcomponent.
45  * Xcomponent:XComponentController = 1:1
46  */
47 class ACE_EXPORT XComponentController {
48 public:
49     /**
50      * @brief Get xcomponentController from napiValue converted by jsXComponentController
51      *
52      */
53     static std::shared_ptr<XComponentController> GetXComponentControllerFromNapiValue(
54         napi_env env, napi_value napiValue);
55 
56     /**
57      * @brief set typedNode.XComponent's SurfaceCallbackMode
58      *
59      */
60     static XComponentControllerErrorCode SetSurfaceCallbackMode(
61         napi_env env, napi_value node, SurfaceCallbackMode mode);
62 
63     XComponentController() = default;
64     virtual ~XComponentController() = default;
65 
66     /**
67      * @brief Get xcomponent's position releated to the window in which xcomponent is located
68      *
69      */
70     virtual XComponentControllerErrorCode GetGlobalPosition(float& offsetX, float& offsetY) = 0;
71 
72     /**
73      * @brief Get xcomponent's size
74      *
75      */
76     virtual XComponentControllerErrorCode GetSize(float& width, float& height) = 0;
77 
78     /**
79      * @brief move the controling right of showing & setting size and posiotion to the other xcomponentController,
80      * which cannot be repeated set more than once, unless calling reset before
81      * @param xcomponentController the other xcomponentController
82      */
83     virtual XComponentControllerErrorCode SetExtController(
84         std::shared_ptr<XComponentController> xcomponentController) = 0;
85 
86     /**
87      * @brief restore the controling right of showing & setting size and posiotion from the other xcomponentController
88      * which must be same as the controller set before
89      * @param xcomponentController the other xcomponentController
90      */
91     virtual XComponentControllerErrorCode ResetExtController(
92         std::shared_ptr<XComponentController> xcomponentController) = 0;
93 };
94 } // namespace OHOS::Ace
95 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_XCOMPONENT_CONTROLLER_INTERFACE_H
96