1 /* 2 * Copyright (c) 2021-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 _NATIVE_INTERFACE_XCOMPONENT_IMPL_ 17 #define _NATIVE_INTERFACE_XCOMPONENT_IMPL_ 18 19 #include <string> 20 #include <unistd.h> 21 22 #include "base/memory/ace_type.h" 23 #include "interfaces/native/native_interface_xcomponent.h" 24 25 namespace OHOS::Ace { 26 class NativeXComponentImpl : public virtual AceType { 27 DECLARE_ACE_TYPE(NativeXComponentImpl, AceType); 28 29 public: NativeXComponentImpl()30 NativeXComponentImpl() {} 31 ~NativeXComponentImpl()32 ~NativeXComponentImpl() {} 33 SetXComponentId(const std::string & id)34 void SetXComponentId(const std::string& id) 35 { 36 xcomponetId_ = id; 37 } 38 GetXComponentId()39 const std::string& GetXComponentId() const 40 { 41 return xcomponetId_; 42 } 43 SetXComponentWidth(const int width)44 void SetXComponentWidth(const int width) 45 { 46 width_ = width; 47 } 48 GetXComponentWidth()49 int GetXComponentWidth() const 50 { 51 return width_; 52 } 53 SetXComponentHeight(const int height)54 void SetXComponentHeight(const int height) 55 { 56 height_ = height; 57 } 58 GetXComponentHeight()59 int GetXComponentHeight() const 60 { 61 return height_; 62 } 63 SetXComponentOffsetX(const double x)64 void SetXComponentOffsetX(const double x) 65 { 66 x_ = x; 67 } 68 GetXComponentOffsetX()69 double GetXComponentOffsetX() const 70 { 71 return x_; 72 } 73 SetXComponentOffsetY(const double y)74 void SetXComponentOffsetY(const double y) 75 { 76 y_ = y; 77 } 78 GetXComponentOffsetY()79 double GetXComponentOffsetY() const 80 { 81 return y_; 82 } 83 SetSurface(void * window)84 void SetSurface(void* window) 85 { 86 window_ = window; 87 } 88 GetSurface()89 const void* GetSurface() const 90 { 91 return window_; 92 } 93 SetCallback(OH_NativeXComponent_Callback * callback)94 void SetCallback(OH_NativeXComponent_Callback* callback) 95 { 96 callback_ = callback; 97 } 98 GetCallback()99 const OH_NativeXComponent_Callback* GetCallback() const 100 { 101 return callback_; 102 } 103 SetTouchEvent(const OH_NativeXComponent_TouchEvent touchEvent)104 void SetTouchEvent(const OH_NativeXComponent_TouchEvent touchEvent) 105 { 106 touchEvent_ = touchEvent; 107 } 108 GetTouchEvent()109 const OH_NativeXComponent_TouchEvent GetTouchEvent() const 110 { 111 return touchEvent_; 112 } 113 114 private: 115 std::string xcomponetId_; 116 void* window_ = nullptr; 117 int width_ = 0; 118 int height_ = 0; 119 double x_ = 0.0; 120 double y_ = 0.0; 121 OH_NativeXComponent_TouchEvent touchEvent_; 122 OH_NativeXComponent_Callback* callback_ = nullptr; 123 }; 124 } 125 126 struct OH_NativeXComponent { OH_NativeXComponentOH_NativeXComponent127 OH_NativeXComponent(OHOS::Ace::NativeXComponentImpl* xComponentImpl) : xcomponentImpl_(xComponentImpl) {} ~OH_NativeXComponentOH_NativeXComponent128 ~OH_NativeXComponent() {} 129 int32_t GetXComponentId(char* id, uint64_t* size); 130 int32_t GetNativeWindow(void** window); 131 int32_t GetXComponentSize(const void* window, uint64_t* width, uint64_t* height); 132 int32_t GetXComponentOffset(const void* window, double* x, double* y); 133 int32_t GetTouchEvent(const void* window, OH_NativeXComponent_TouchEvent* touchEvent); 134 int32_t RegisterCallback(OH_NativeXComponent_Callback* callback); 135 136 private: 137 OHOS::Ace::NativeXComponentImpl* xcomponentImpl_ = nullptr; 138 }; 139 140 #endif // _NATIVE_INTERFACE_XCOMPONENT_IMPL_