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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_XCOMPONENT_CONTROLLER_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_XCOMPONENT_CONTROLLER_H
18 
19 #include "base/memory/referenced.h"
20 #include "bridge/declarative_frontend/engine/bindings.h"
21 #include "core/components_ng/pattern/xcomponent/inner_xcomponent_controller.h"
22 
23 namespace OHOS::Ace::Framework {
24 class JSXComponentController : public Referenced {
25 public:
26     JSXComponentController() = default;
27     ~JSXComponentController() override = default;
28 
29     static void JSBind(BindingTarget globalObj);
30     static void Constructor(const JSCallbackInfo& args);
31     static void Destructor(JSXComponentController* xcomponentController);
32 
33     void GetSurfaceId(const JSCallbackInfo& args);
34     void SetSurfaceConfig(const JSCallbackInfo& args);
35 
GetXComponentContext(const JSCallbackInfo & args)36     void GetXComponentContext(const JSCallbackInfo& args)
37     {
38         args.SetReturnValue(renderContext_.Lock());
39     }
40 
SetXComponentContext(const JSRef<JSVal> & renderContext)41     void SetXComponentContext(const JSRef<JSVal>& renderContext)
42     {
43         renderContext_ = renderContext;
44     }
45 
46     void GetXComponentSurfaceRect(const JSCallbackInfo& args);
47 
48     void SetXComponentSurfaceRect(const JSCallbackInfo& args);
49 
GetController()50     std::shared_ptr<InnerXComponentController> GetController() const
51     {
52         return xcomponentController_;
53     }
54 
SetController(const std::shared_ptr<InnerXComponentController> & xcomponentController)55     void SetController(const std::shared_ptr<InnerXComponentController>& xcomponentController)
56     {
57         xcomponentController_ = xcomponentController;
58     }
59 
SetInstanceId(int32_t id)60     void SetInstanceId(int32_t id)
61     {
62         instanceId_ = id;
63     }
64 
65     void StartImageAnalyzer(const JSCallbackInfo& args);
66     void StopImageAnalyzer(const JSCallbackInfo& args);
67 
68     void SetXComponentSurfaceRotation(const JSCallbackInfo& args);
69     void GetXComponentSurfaceRotation(const JSCallbackInfo& args);
70 
71 private:
72     int32_t instanceId_ = INSTANCE_ID_UNDEFINED;
73     std::shared_ptr<InnerXComponentController> xcomponentController_;
74     JSWeak<JSVal> renderContext_;
75     bool isImageAnalyzing_ = false;
76     ACE_DISALLOW_COPY_AND_MOVE(JSXComponentController);
77 };
78 } // namespace OHOS::Ace::Framework
79 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_XCOMPONENT_CONTROLLER_H