1 /*
2 * Copyright (c) 2023-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 #include "js_runtime_utils.h"
17 #include "picture_in_picture_option.h"
18
19 namespace OHOS {
20 namespace Rosen {
PipOption()21 PipOption::PipOption()
22 {
23 }
24
ClearNapiRefs(napi_env env)25 void PipOption::ClearNapiRefs(napi_env env)
26 {
27 if (customNodeController_) {
28 napi_delete_reference(env, customNodeController_);
29 customNodeController_ = nullptr;
30 }
31 if (typeNode_) {
32 napi_delete_reference(env, typeNode_);
33 typeNode_ = nullptr;
34 }
35 if (storage_) {
36 napi_delete_reference(env, storage_);
37 storage_ = nullptr;
38 }
39 }
40
SetContext(void * contextPtr)41 void PipOption::SetContext(void* contextPtr)
42 {
43 contextPtr_ = contextPtr;
44 }
45
SetNavigationId(const std::string & navigationId)46 void PipOption::SetNavigationId(const std::string& navigationId)
47 {
48 navigationId_ = navigationId;
49 }
50
SetPipTemplate(uint32_t templateType)51 void PipOption::SetPipTemplate(uint32_t templateType)
52 {
53 templateType_ = templateType;
54 }
55
SetPiPControlStatus(PiPControlType controlType,PiPControlStatus status)56 void PipOption::SetPiPControlStatus(PiPControlType controlType, PiPControlStatus status)
57 {
58 for (auto& controlStatusInfo : pipControlStatusInfoList_) {
59 if (controlType == controlStatusInfo.controlType) {
60 controlStatusInfo.status = status;
61 return;
62 }
63 }
64 PiPControlStatusInfo newPiPControlStatusInfo {controlType, status};
65 pipControlStatusInfoList_.push_back(newPiPControlStatusInfo);
66 }
67
SetPiPControlEnabled(PiPControlType controlType,PiPControlStatus enabled)68 void PipOption::SetPiPControlEnabled(PiPControlType controlType, PiPControlStatus enabled)
69 {
70 for (auto& controlEnableInfo : pipControlEnableInfoList_) {
71 if (controlType == controlEnableInfo.controlType) {
72 controlEnableInfo.enabled = enabled;
73 return;
74 }
75 }
76 PiPControlEnableInfo newPiPControlEnableInfo {controlType, enabled};
77 pipControlEnableInfoList_.push_back(newPiPControlEnableInfo);
78 }
79
SetContentSize(uint32_t width,uint32_t height)80 void PipOption::SetContentSize(uint32_t width, uint32_t height)
81 {
82 contentWidth_ = width;
83 contentHeight_ = height;
84 }
85
SetControlGroup(std::vector<std::uint32_t> controlGroup)86 void PipOption::SetControlGroup(std::vector<std::uint32_t> controlGroup)
87 {
88 controlGroup_ = controlGroup;
89 }
90
SetNodeControllerRef(napi_ref ref)91 void PipOption::SetNodeControllerRef(napi_ref ref)
92 {
93 customNodeController_ = ref;
94 }
95
SetStorageRef(napi_ref ref)96 void PipOption::SetStorageRef(napi_ref ref)
97 {
98 storage_ = ref;
99 }
100
GetNodeControllerRef() const101 napi_ref PipOption::GetNodeControllerRef() const
102 {
103 return customNodeController_;
104 }
105
GetStorageRef() const106 napi_ref PipOption::GetStorageRef() const
107 {
108 return storage_;
109 }
110
SetTypeNodeRef(napi_ref ref)111 void PipOption::SetTypeNodeRef(napi_ref ref)
112 {
113 typeNode_ = ref;
114 }
115
GetTypeNodeRef() const116 napi_ref PipOption::GetTypeNodeRef() const
117 {
118 return typeNode_;
119 }
120
RegisterPipContentListenerWithType(const std::string & type,std::shared_ptr<NativeReference> updateNodeCallbackRef)121 void PipOption::RegisterPipContentListenerWithType(const std::string& type,
122 std::shared_ptr<NativeReference> updateNodeCallbackRef)
123 {
124 pipContentlistenerMap_[type] = updateNodeCallbackRef;
125 }
126
UnRegisterPipContentListenerWithType(const std::string & type)127 void PipOption::UnRegisterPipContentListenerWithType(const std::string& type)
128 {
129 pipContentlistenerMap_.erase(type);
130 }
131
GetPipContentCallbackRef(const std::string & type)132 std::shared_ptr<NativeReference> PipOption::GetPipContentCallbackRef(const std::string& type)
133 {
134 auto iter = pipContentlistenerMap_.find(type);
135 if (iter == pipContentlistenerMap_.end()) {
136 return nullptr;
137 }
138 return iter->second;
139 }
140
GetContext() const141 void* PipOption::GetContext() const
142 {
143 return contextPtr_;
144 }
145
GetNavigationId() const146 std::string PipOption::GetNavigationId() const
147 {
148 return navigationId_;
149 }
150
GetPipTemplate()151 uint32_t PipOption::GetPipTemplate()
152 {
153 return templateType_;
154 }
155
GetContentSize(uint32_t & width,uint32_t & height)156 void PipOption::GetContentSize(uint32_t& width, uint32_t& height)
157 {
158 width = contentWidth_;
159 height = contentHeight_;
160 }
161
GetControlGroup()162 std::vector<std::uint32_t> PipOption::GetControlGroup()
163 {
164 return controlGroup_;
165 }
166
GetControlStatus()167 std::vector<PiPControlStatusInfo> PipOption::GetControlStatus()
168 {
169 return pipControlStatusInfoList_;
170 }
171
GetControlEnable()172 std::vector<PiPControlEnableInfo> PipOption::GetControlEnable()
173 {
174 return pipControlEnableInfoList_;
175 }
176
SetXComponentController(std::shared_ptr<XComponentController> xComponentController)177 void PipOption::SetXComponentController(std::shared_ptr<XComponentController> xComponentController)
178 {
179 xComponentController_ = xComponentController;
180 }
181
GetXComponentController()182 std::shared_ptr<XComponentController> PipOption::GetXComponentController()
183 {
184 return xComponentController_;
185 }
186
SetTypeNodeEnabled(bool enable)187 void PipOption::SetTypeNodeEnabled(bool enable)
188 {
189 useTypeNode_ = enable;
190 }
191
IsTypeNodeEnabled() const192 bool PipOption::IsTypeNodeEnabled() const
193 {
194 return useTypeNode_;
195 }
196 } // namespace Rosen
197 } // namespace OHOS