• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     XCOMPONENT_CONTROLLER_LOAD_LIB_FAILED,
36 };
37 
38 enum class SurfaceCallbackMode : char {
39     DEFAULT = 0,
40     PIP,
41 };
42 
43 /**
44  * @class XComponentController
45  * XComponentController interface is used to control xcomponent.
46  * Xcomponent:XComponentController = 1:1
47  */
48 class ACE_EXPORT XComponentController {
49 public:
50     /**
51      * @brief Get xcomponentController from napiValue converted by jsXComponentController
52      *
53      */
54     static std::shared_ptr<XComponentController> GetXComponentControllerFromNapiValue(
55         napi_env env, napi_value napiValue);
56 
57     /**
58      * @brief set typedNode.XComponent's SurfaceCallbackMode
59      *
60      */
61     static XComponentControllerErrorCode SetSurfaceCallbackMode(
62         napi_env env, napi_value node, SurfaceCallbackMode mode);
63 
64     /**
65      * @brief set surface renderFit by surfaceId
66      * @param surfaceId index of the surface
67      * @param renderFitNumber numeric value of renderFit mode
68      * @param isRenderFitNewVersionEnabled enable render fit new version or not
69      */
70     static XComponentControllerErrorCode SetRenderFitBySurfaceId(
71         const std::string& surfaceId, int32_t renderFitNumber, bool isRenderFitNewVersionEnabled);
72 
73     /**
74      * @brief get surface renderFit by surfaceId
75      * @param surfaceId index of the surface
76      * @param renderFitNumber numeric value of renderFit mode
77      * @param isRenderFitNewVersionEnabled enable render fit new version or not
78      */
79     static XComponentControllerErrorCode GetRenderFitBySurfaceId(
80         const std::string& surfaceId, int32_t& renderFitNumber, bool& isRenderFitNewVersionEnabled);
81 
82     /**
83      * @brief get surface lock info by surfaceId
84      * @param surfaceId index of the surface
85      * @param isSurfaceLock the locking attribute of the surface
86      */
87     static XComponentControllerErrorCode GetSurfaceRotationBySurfaceId(
88         const std::string& surfaceId, bool& isSurfaceLock);
89 
90     XComponentController() = default;
91     virtual ~XComponentController() = default;
92 
93     /**
94      * @brief Get xcomponent's position releated to the window in which xcomponent is located
95      *
96      */
97     virtual XComponentControllerErrorCode GetGlobalPosition(float& offsetX, float& offsetY) = 0;
98 
99     /**
100      * @brief Get xcomponent's size
101      *
102      */
103     virtual XComponentControllerErrorCode GetSize(float& width, float& height) = 0;
104 
105     /**
106      * @brief move the controling right of showing & setting size and posiotion to the other xcomponentController,
107      * which cannot be repeated set more than once, unless calling reset before
108      * @param xcomponentController the other xcomponentController
109      */
110     virtual XComponentControllerErrorCode SetExtController(
111         std::shared_ptr<XComponentController> xcomponentController) = 0;
112 
113     /**
114      * @brief restore the controling right of showing & setting size and posiotion from the other xcomponentController
115      * which must be same as the controller set before
116      * @param xcomponentController the other xcomponentController
117      */
118     virtual XComponentControllerErrorCode ResetExtController(
119         std::shared_ptr<XComponentController> xcomponentController) = 0;
120 };
121 } // namespace OHOS::Ace
122 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_XCOMPONENT_CONTROLLER_INTERFACE_H
123