1/* 2 * Copyright (c) 2025 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 16import pip from '@ohos.pip'; 17 18const TAG: string = 'WebPiPContent'; 19 20@Entry 21@Component 22struct WebPiPContent { 23 private xComponentController: XComponentController = new XComponentController(); 24 xComponentId: string = 'webPipContent'; 25 xComponentType: XComponentType = XComponentType.SURFACE; 26 27 build() { 28 Stack() { 29 this.buildXComponent(); 30 } 31 .size({ width: '100%', height: '100%' }); 32 } 33 34 @Builder 35 buildXComponent() { 36 XComponent({ id: this.xComponentId, type: this.xComponentType, controller: this.xComponentController }) 37 .onLoad(() => { 38 try { 39 pip.initWebXComponentController(this.xComponentController, 40 this.xComponentController.getXComponentSurfaceId()); 41 console.debug(TAG, 'WebXComponent onLoad done'); 42 } catch (error) { 43 console.error(TAG, 'WebXComponent onLoad failed'); 44 } 45 }) 46 .size({ width: '100%', height: '100%' }) 47 .backgroundColor(Color.Transparent); 48 } 49}