未验证 提交 baadba72 编写于 作者: O openharmony_ci 提交者: Gitee

!5902 翻译完成 4515 :接口修改+示例代码修改

Merge pull request !5902 from ester.zhou/TR-4515
# Pasteboard
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> **NOTE**<br>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
......@@ -48,9 +48,9 @@ Creates a **PasteData** object for plain text.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("content");
```
```js
var pasteData = pasteboard.createPlainTextData("content");
```
## pasteboard.createHtmlData<sup>7+</sup>
......@@ -75,10 +75,10 @@ Creates a **PasteData** object for HTML text.
**Example**
```js
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var pasteData = pasteboard.createHtmlData(html);
```
```js
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var pasteData = pasteboard.createHtmlData(html);
```
## pasteboard.createWantData<sup>7+</sup>
......@@ -103,13 +103,13 @@ Creates a **PasteData** object for Want text.
**Example**
```js
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
var pasteData = pasteboard.createWantData(object);
```
```js
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
var pasteData = pasteboard.createWantData(object);
```
## pasteboard.createUriData<sup>7+</sup>
......@@ -134,9 +134,9 @@ Creates a **PasteData** object for URI text.
**Example**
```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
```
```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
```
## pasteboard.createPlainTextRecord<sup>7+</sup>
......@@ -161,9 +161,9 @@ Creates a **PasteDataRecord** object of the plain text type.
**Example**
```js
var record = pasteboard.createPlainTextRecord("hello");
```
```js
var record = pasteboard.createPlainTextRecord("hello");
```
## pasteboard.createHtmlTextRecord<sup>7+</sup>
......@@ -188,10 +188,10 @@ Creates a **PasteDataRecord** object of the HTML text type.
**Example**
```js
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var record = pasteboard.createHtmlTextRecord(html);
```
```js
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var record = pasteboard.createHtmlTextRecord(html);
```
## pasteboard.createWantRecord<sup>7+</sup>
......@@ -216,13 +216,13 @@ Creates a **PasteDataRecord** object of the Want text type.
**Example**
```js
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
var record = pasteboard.createWantRecord(object);
```
```js
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
var record = pasteboard.createWantRecord(object);
```
## pasteboard.createUriRecord<sup>7+</sup>
......@@ -247,9 +247,9 @@ Creates a **PasteDataRecord** object of the URI text type.
**Example**
```js
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
```
```js
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
```
## PasteDataProperty<sup>7+</sup>
......@@ -279,7 +279,7 @@ A data record is an abstract definition of the content on the pasteboard. The pa
| Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- |
| htmlText<sup>7+</sup> | string | Yes | No | HTML text. |
| want<sup>7+</sup> | [Want](js-apis-featureAbility.md#want) | Yes | No | Want text. |
| want<sup>7+</sup> | [Want](js-apis-application-Want.md) | Yes | No | Want text. |
| mimeType<sup>7+</sup> | string | Yes | No | Data type. |
| plainText<sup>7+</sup> | string | Yes | No | Plain text. |
| uri<sup>7+</sup> | string | Yes | No | URI text. |
......@@ -301,14 +301,14 @@ Forcibly converts the content in this **PasteData** object to the plain text. Th
**Example**
```js
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
record.convertToText().then((data) => {
console.info('convertToText success data : ' + JSON.stringify(data));
}).catch((error) => {
console.error('convertToText failed because ' + JSON.stringify(error));
});
```
```js
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
record.convertToText().then((data) => {
console.info('convertToText success data : ' + JSON.stringify(data));
}).catch((error) => {
console.error('convertToText failed because ' + JSON.stringify(error));
});
```
### convertToText<sup>7+</sup>
......@@ -327,16 +327,16 @@ Forcibly converts the content in this **PasteData** object to the plain text. Th
**Example**
```js
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
record.convertToText((err, data) => {
if (err) {
console.error('convertToText failed because ' + JSON.stringify(err));
return;
}
console.info('convertToText success data : ' + JSON.stringify(data));
});
```
```js
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
record.convertToText((err, data) => {
if (err) {
console.error('convertToText failed because ' + JSON.stringify(err));
return;
}
console.info('convertToText success data : ' + JSON.stringify(data));
});
```
## PasteData
......@@ -366,10 +366,10 @@ Obtains the plain text of the primary record.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var plainText = pasteData.getPrimaryText();
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var plainText = pasteData.getPrimaryText();
```
### getPrimaryHtml<sup>7+</sup>
......@@ -388,11 +388,11 @@ Obtains the HTML text of the primary record.
**Example**
```js
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var pasteData = pasteboard.createHtmlData(html);
var htmlText = pasteData.getPrimaryHtml();
```
```js
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var pasteData = pasteboard.createHtmlData(html);
var htmlText = pasteData.getPrimaryHtml();
```
### getPrimaryWant<sup>7+</sup>
......@@ -411,14 +411,14 @@ Obtains the **Want** object of the primary record.
**Example**
```js
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
var pasteData = pasteboard.createWantData(object);
var want = pasteData.getPrimaryWant();
```
```js
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
var pasteData = pasteboard.createWantData(object);
var want = pasteData.getPrimaryWant();
```
### getPrimaryUri<sup>7+</sup>
......@@ -437,10 +437,10 @@ Obtains the URI text of the primary record.
**Example**
```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
var uri = pasteData.getPrimaryUri();
```
```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
var uri = pasteData.getPrimaryUri();
```
### addTextRecord<sup>7+</sup>
......@@ -485,11 +485,11 @@ The pasteboard supports a maximum number of 128 data records.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
pasteData.addHtmlRecord(html);
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
pasteData.addHtmlRecord(html);
```
### addWantRecord<sup>7+</sup>
......@@ -506,18 +506,18 @@ The pasteboard supports a maximum number of 128 data records.
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#want) | Yes | Want object. |
| want | [Want](js-apis-application-Want.md) | Yes | Want object. |
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
pasteData.addWantRecord(object);
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
pasteData.addWantRecord(object);
```
### addUriRecord<sup>7+</sup>
......@@ -538,10 +538,10 @@ The pasteboard supports a maximum number of 128 data records.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
pasteData.addUriRecord("dataability:///com.example.myapplication1?user.txt");
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
pasteData.addUriRecord("dataability:///com.example.myapplication1?user.txt");
```
### addRecord<sup>7+</sup>
......@@ -562,14 +562,14 @@ The pasteboard supports a maximum number of 128 data records.
**Example**
```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
var textRecord = pasteboard.createPlainTextRecord("hello");
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var htmlRecord = pasteboard.createHtmlTextRecord(html);
pasteData.addRecord(textRecord);
pasteData.addRecord(htmlRecord);
```
```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
var textRecord = pasteboard.createPlainTextRecord("hello");
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var htmlRecord = pasteboard.createHtmlTextRecord(html);
pasteData.addRecord(textRecord);
pasteData.addRecord(htmlRecord);
```
### getMimeTypes<sup>7+</sup>
......@@ -588,10 +588,10 @@ Obtains **mimeTypes** in [PasteDataProperty](#pastedataproperty7) from this past
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var types = pasteData.getMimeTypes();
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var types = pasteData.getMimeTypes();
```
### getPrimaryMimeType<sup>7+</sup>
......@@ -610,10 +610,10 @@ Obtains the data type of the primary record.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var type = pasteData.getPrimaryMimeType();
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var type = pasteData.getPrimaryMimeType();
```
### getProperty<sup>7+</sup>
......@@ -632,10 +632,10 @@ Obtains the property description object.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var property = pasteData.getProperty();
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var property = pasteData.getProperty();
```
### getRecordAt<sup>7+</sup>
......@@ -660,10 +660,10 @@ Obtains the record with the specified index.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var record = pasteData.getRecordAt(0);
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var record = pasteData.getRecordAt(0);
```
### getRecordCount<sup>7+</sup>
......@@ -682,10 +682,10 @@ Obtains the number of data records in this pasteboard.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var count = pasteData.getRecordCount();
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var count = pasteData.getRecordCount();
```
### getTag<sup>7+</sup>
......@@ -704,10 +704,10 @@ Obtains the user-defined tag content. If the tag content is not set, null is ret
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var tag = pasteData.getTag();
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var tag = pasteData.getTag();
```
### hasMimeType<sup>7+</sup>
......@@ -732,10 +732,10 @@ Checks whether the content of this pasteboard contains the specified data type.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var hasType = pasteData.hasMimeType(pasteboard.MIMETYPE_TEXT_PLAIN);
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var hasType = pasteData.hasMimeType(pasteboard.MIMETYPE_TEXT_PLAIN);
```
### removeRecordAt<sup>7+</sup>
......@@ -760,10 +760,10 @@ Removes the data record with a specified index from this pasteboard.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var isRemove = pasteData.removeRecordAt(0);
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var isRemove = pasteData.removeRecordAt(0);
```
### replaceRecordAt<sup>7+</sup>
......@@ -789,11 +789,11 @@ Replaces the data record with a specified index in this pasteboard.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
var isReplace = pasteData.replaceRecordAt(0, record);
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
var isReplace = pasteData.replaceRecordAt(0, record);
```
## pasteboard.getSystemPasteboard
......@@ -812,9 +812,9 @@ Obtains the system pasteboard.
**Example**
```js
var systemPasteboard = pasteboard.getSystemPasteboard();
```
```js
var systemPasteboard = pasteboard.getSystemPasteboard();
```
## SystemPasteboard
......@@ -843,17 +843,17 @@ Writes data to a pasteboard. This API uses an asynchronous callback to return th
**Example**
```js
var pasteData = pasteboard.createPlainTextData("content");
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setPasteData(pasteData, (error, data) => {
if (error) {
console.error('Failed to setPasteData. Cause: ' + error.message);
return;
}
console.info('setPasteData successfully.');
});
```
```js
var pasteData = pasteboard.createPlainTextData("content");
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setPasteData(pasteData, (error, data) => {
if (error) {
console.error('Failed to setPasteData. Cause: ' + error.message);
return;
}
console.info('setPasteData successfully.');
});
```
### setPasteData
......@@ -878,15 +878,15 @@ Writes data to a pasteboard. This API uses a promise to return the result.
**Example**
```js
var pasteData = pasteboard.createPlainTextData("content");
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setPasteData(pasteData).then((data) => {
console.info('setPasteData success.');
}).catch((error) => {
console.error('Failed to setPasteData. Cause: ' + error.message);
});
```
```js
var pasteData = pasteboard.createPlainTextData("content");
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setPasteData(pasteData).then((data) => {
console.info('setPasteData success.');
}).catch((error) => {
console.error('Failed to setPasteData. Cause: ' + error.message);
});
```
### getPasteData
......@@ -905,16 +905,16 @@ Reads the system pasteboard content. This API uses an asynchronous callback to r
**Example**
```js
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getPasteData((error, pasteData) => {
if (error) {
console.error('Failed to getPasteData. Cause: ' + error.message);
return;
}
var text = pasteData.getPrimaryText();
});
```
```js
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getPasteData((error, pasteData) => {
if (error) {
console.error('Failed to getPasteData. Cause: ' + error.message);
return;
}
var text = pasteData.getPrimaryText();
});
```
### getPasteData
......@@ -933,14 +933,14 @@ Reads the system pasteboard content. This API uses a promise to return the resul
**Example**
```js
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getPasteData().then((pasteData) => {
var text = pasteData.getPrimaryText();
}).catch((error) => {
console.error('Failed to getPasteData. Cause: ' + error.message);
})
```
```js
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getPasteData().then((pasteData) => {
var text = pasteData.getPrimaryText();
}).catch((error) => {
console.error('Failed to getPasteData. Cause: ' + error.message);
})
```
### on('update')<sup>7+</sup>
......@@ -960,18 +960,18 @@ Subscribes to the content change event of the system pasteboard. If the pasteboa
**Example**
```js
var systemPasteboard = pasteboard.getSystemPasteboard();
var listener = ()=>{
console.info('The system pasteboard has changed');
};
systemPasteboard.on('update', listener);
```
```js
var systemPasteboard = pasteboard.getSystemPasteboard();
var listener = () => {
console.info('The system pasteboard has changed');
};
systemPasteboard.on('update', listener);
```
### off('update')<sup>7+</sup>
off(type: 'update', callback? : () =&gt;void ): void
off(type: 'update', callback?: () =&gt;void ): void
Unsubscribes from the system pasteboard content change event.
......@@ -986,9 +986,12 @@ Unsubscribes from the system pasteboard content change event.
**Example**
```js
systemPasteboard.off('update', listener);
```
```js
let listener = () => {
console.info('The system pasteboard has changed');
};
systemPasteboard.off('update', listener);
```
### hasPasteData<sup>7+</sup>
......@@ -1007,15 +1010,15 @@ Checks whether the system pasteboard contains content. This API uses an asynchro
**Example**
```js
systemPasteboard.hasPasteData((err, data) => {
if (err) {
console.error('failed to hasPasteData because ' + JSON.stringify(err));
return;
}
console.info('success hasPasteData : ' + JSON.stringify(data));
});
```
```js
systemPasteboard.hasPasteData((err, data) => {
if (err) {
console.error('failed to hasPasteData because ' + JSON.stringify(err));
return;
}
console.info('success hasPasteData : ' + JSON.stringify(data));
});
```
### hasPasteData<sup>7+</sup>
......@@ -1059,15 +1062,15 @@ Clears the system pasteboard content. This API uses an asynchronous callback to
**Example**
```js
systemPasteboard.clear((err, data) => {
if (err) {
console.error('failed to clear because ' + JSON.stringify(err));
return;
}
console.info('success clear');
});
```
```js
systemPasteboard.clear((err, data) => {
if (err) {
console.error('failed to clear because ' + JSON.stringify(err));
return;
}
console.info('success clear');
});
```
### clear<sup>7+</sup>
......@@ -1086,10 +1089,10 @@ Clears the system pasteboard content. This API uses a promise to return the resu
**Example**
```js
systemPasteboard.clear().then((data) => {
console.info('success clear');
}).catch((error) => {
console.error('failed to clear because ' + JSON.stringify(error));
});
```
\ No newline at end of file
```js
systemPasteboard.clear().then((data) => {
console.info('success clear');
}).catch((error) => {
console.error('failed to clear because ' + JSON.stringify(error));
});
```
......@@ -436,36 +436,36 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a
```js
// The source type is string.
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
return;
}
console.log(`success to setWallpaper.`);
});
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
return;
}
console.log(`success to setWallpaper.`);
});
// The source type is image.PixelMap.
import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = {
"desiredSize": {
"height": 3648,
"width": 2736
}
};
imageSource.createPixelMap(opts).then((pixelMap) => {
wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
return;
}
console.log(`success to setWallpaper.`);
});
}).catch((error) => {
console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
});
```
import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = {
"desiredSize": {
"height": 3648,
"width": 2736
}
};
imageSource.createPixelMap(opts).then((pixelMap) => {
wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
return;
}
console.log(`success to setWallpaper.`);
});
}).catch((error) => {
console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
});
```
## wallpaper.setWallpaper
......@@ -495,32 +495,32 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr
```js
// The source type is string.
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to setWallpaper.`);
}).catch((error) => {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
});
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to setWallpaper.`);
}).catch((error) => {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
});
// The source type is image.PixelMap.
import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = {
"desiredSize": {
"height": 3648,
"width": 2736
}
};
imageSource.createPixelMap(opts).then((pixelMap) => {
wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to setWallpaper.`);
}).catch((error) => {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
});
}).catch((error) => {
console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
});
```
import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = {
"desiredSize": {
"height": 3648,
"width": 2736
}
};
imageSource.createPixelMap(opts).then((pixelMap) => {
wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to setWallpaper.`);
}).catch((error) => {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
});
}).catch((error) => {
console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
});
```
## wallpaper.getFile<sup>8+</sup>
......@@ -557,7 +557,7 @@ getFile(wallpaperType: WallpaperType): Promise&lt;number&gt;
Obtains the wallpaper of the specified type. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_WALLPAPER and ohos.permission.READ_USER_STORAGE
**Required permissions**: ohos.permission.SET_WALLPAPER and ohos.permission.READ_USER_STORAGE
**System capability**: SystemCapability.MiscServices.Wallpaper
......@@ -604,7 +604,7 @@ Obtains the pixel image for the wallpaper of the specified type. This API uses a
**Example**
```js
wallpaper.getPixelMap(WALLPAPER_SYSTEM, function (err, data) {
wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (err, data) {
console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem err : ' + JSON.stringify(err));
console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem data : ' + JSON.stringify(data));
});
......@@ -663,12 +663,12 @@ Subscribes to the wallpaper color change event.
**Example**
```js
let listener = (colors, wallpaperType) => {
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange', listener);
```
```js
let listener = (colors, wallpaperType) => {
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange', listener);
```
## wallpaper.off('colorChange')
......@@ -688,11 +688,11 @@ Unsubscribes from the wallpaper color change event.
**Example**
```js
let listener = (colors, wallpaperType) => {
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange', listener);
```js
let listener = (colors, wallpaperType) => {
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange', listener);
// Unsubscribe from the listener.
wallpaper.off('colorChange', listener);
//Unsubscribe from all subscriptions of the colorChange type.
......
# Web
>![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> **NOTE**<br>
>This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
The **<Web\>** component can be used to display web pages.
......@@ -10,144 +10,202 @@ ohos.permission.INTERNET, required only for accessing online web pages.
## Child Components
None
Not supported
## APIs
- Web\(options: { src: string, controller?: WebController }\)
Table 1 Parameters of options
Table 1 options
| Name | Type | Mandatory | Default Value | Description |
| ---------- | ------------------------------- | --------- | ------------- | ------------------------------- |
| src | string | Yes | - | Address of a web page resource. |
| controller | [WebController](#webcontroller) | No | - | Controller. |
| Name | Type | Mandatory | Default Value | Description |
| ---------- | ------------------------------- | ---- | ---- | ------- |
| src | string | Yes | - | Address of a web page resource.|
| controller | [WebController](#webcontroller) | No | - | Controller. |
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> **NOTE**<br>
>
> - Transition animation is not supported.
> - Multi-instance is not supported.
> - Only local audio and video are supported for playback.
## Attributes
| Name | Type | Default Value | Description |
| ----------------- | ---------------------------------------- | -------------- | ---------------------------------------- |
| domStorageAccess | boolean | false | Whether to enable the DOM Storage API permission. By default, the permission is disabled. |
| fileAccess | boolean | true | Whether to enable in-application rawfile access through [$rawfile(filepath/filename)](../../ui/ts-application-resource-access.md). By default, this feature is enabled. |
| imageAccess | boolean | true | Whether to enable automatic image loading. By default, this feature is enabled. |
| javaScriptProxy | { <br> object: object, <br> name: string, <br> methodList: Array\<string\>, <br> controller: WebController <br>} | - | JavaScript object to be injected into the window. Methods of this object can be invoked in the window. The parameters in this attribute cannot be updated.<br> **object** indicates the object to be registered. Methods can be declared, but not attributes. The parameters and return value can only be of the string, number, or Boolean type.<br> **name** indicates the name of the object to be registered, which is the same as that invoked in the window. After registration, the window can use this name to access the JavaScript object at the application side.<br> **methodList** indicates the methods of the JavaScript object to be registered at the application side.<br> **controller** indicates the controller. |
| javaScriptAccess | boolean | true | Whether JavaScript scripts can be executed. By default, JavaScript scripts can be executed. |
| mixedMode | MixedMode | MixedMode.None | Whether to enable loading of HTTP and HTTPS hybrid content can be loaded. By default, this feature is disabled. |
| onlineImageAccess | boolean | true | Whether to enable access to online images through HTTP and HTTPS. By default, this feature is enabled. |
| zoomAccess | boolean | true | Whether to enable zoom gestures. By default, zoom gestures are enabled. |
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
| Name | Type | Default Value | Description |
| ------------------ | ---------------------------------------- | ----------------- | ---------------------------------------- |
| domStorageAccess | boolean | false | Whether to enable the DOM Storage API permission. By default, the permission is disabled.|
| fileAccess | boolean | false | Whether to enable in-application rawfile access through [$rawfile(filepath/filename)](../../ui/ts-application-resource-access.md#referencing-resources). By default, this feature is enabled.|
| fileFromUrlAccess | boolean | true | Whether to allow JavaScript scripts on web pages to access the content in [$rawfile(filepath/filename)](../../ui/ts-application-resource-access.md#referencing-resources). By default, this feature is disabled.|
| imageAccess | boolean | true | Whether to enable automatic image loading. By default, this feature is enabled. |
| javaScriptProxy | { <br> object: object, <br> name: string, <br> methodList: Array\<string\>, <br> controller: WebController <br>} | - | JavaScript object to be injected into the window. Methods of this object can be invoked in the window. The parameters in this attribute cannot be updated.<br> **object** indicates the object to be registered. Methods can be declared, but not attributes. The parameters and return value can only be of the string, number, or Boolean type.<br> **name** indicates the name of the object to be registered, which is the same as that invoked in the window. After registration, the window can use this name to access the JavaScript object at the application side.<br> **methodList** indicates the methods of the JavaScript object to be registered at the application side.<br> **controller** indicates the controller.|
| javaScriptAccess | boolean | true | Whether JavaScript scripts can be executed. By default, JavaScript scripts can be executed. |
| mixedMode | [MixedMode](#mixedmode) | MixedMode.None | Whether to enable loading of HTTP and HTTPS hybrid content can be loaded. By default, this feature is disabled.|
| onlineImageAccess | boolean | true | Whether to enable access to online images through HTTP and HTTPS. By default, this feature is enabled.|
| zoomAccess | boolean | true | Whether to enable zoom gestures. By default, zoom gestures are enabled. |
| overviewModeAccess | boolean | true | Whether to use the overview mode to load web pages. By default, this mode is used. |
| databaseAccess | boolean | false | Whether to enable database access. By default, this feature is disabled. |
| cacheMode | [CacheMode](#cachemode) | CacheMode.Default | Cache mode. |
| textZoomAtio | number | 100 | Text zoom ratio of the page. The default value is **100**, which indicates 100%. |
| userAgent | string | - | User agent. |
> **NOTE**<br>
>
> Only the following universal attributes are supported: [width](ts-universal-attributes-size.md#Attributes), [height](ts-universal-attributes-size.md#Attributes), [padding](ts-universal-attributes-size.md#Attributes), [margin](ts-universal-attributes-size.md#Attributes), and [border](ts-universal-attributes-border.md#Attributes).
- <span id="MixedMode">MixedMode</span>
| Name | Description |
| ---------- | ---------------------------------------- |
| All | HTTP and HTTPS hybrid content can be loaded. This means that all insecure content can be loaded. |
| Compatible | HTTP and HTTPS hybrid content can be loaded in compatibility mode. This means that some insecure content may be loaded. |
| None | HTTP and HTTPS hybrid content cannot be loaded. |
## Events
Universal events are not supported.
The universal events are not supported.
| Name | Description |
| ---------------------------------------- | ---------------------------------------- |
| onAlert(callback: (event?: { url: string; message: string; result: [JsResult](#jsresult) }) => boolean) | <p>Triggered when **alert()** is invoked to display an alert dialog box on the web page.<br>If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can invoke the system dialog box capability (allows only the confirm operation) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.<br>**url**: URL of the web page where the dialog box is displayed.<br>**message**: information displayed in the dialog box.<br>**JsResult**: notifies the **\<Web>** component of the user's operation.</p> |
| onBeforeUnload(callback: (event?: { url: string; message: string; result: [JsResult](#jsresult) }) => boolean) | <p>Triggered when the current page is about to exit after the user refreshes or closes the page.<br>If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can invoke the system dialog box capability (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.<br>**url**: URL of the web page where the dialog box is displayed.<br>**message**: information displayed in the dialog box.<br>**JsResult**: notifies the **\<Web>** component of the user's operation.</p> |
| onConfirm(callback: (event?: { url: string; message: string; result: [JsResult](#jsresult) }) => boolean) | <p>Triggered when **confirm()** is invoked to display a confirmation dialog box on the web page.<br>If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can invoke the system dialog box capability (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.<br>**url**: URL of the web page where the dialog box is displayed.<br>**message**: information displayed in the dialog box.<br>**JsResult**: notifies the **\<Web>** component of the user's operation.</p> |
| Name | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| onAlert(callback: (event?: { url: string; message: string; result: [JsResult](#jsresult) }) => boolean) | <p>Triggered when **alert()** is invoked to display an alert dialog box on the web page.<br>If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows only the confirm operation) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.<br>**url**: URL of the web page where the dialog box is displayed.<br>**message**: information displayed in the dialog box.<br>**JsResult**: the user's operation.</p> |
| onBeforeUnload(callback: (event?: { url: string; message: string; result: [JsResult](#jsresult) }) => boolean) | <p>Triggered when the current page is about to exit after the user refreshes or closes the page.<br>If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.<br>**url**: URL of the web page where the dialog box is displayed.<br>**message**: information displayed in the dialog box.<br>**JsResult**: the user's operation.</p> |
| onConfirm(callback: (event?: { url: string; message: string; result: [JsResult](#jsresult) }) => boolean) | <p>Triggered when **confirm()** is invoked by the web page.<br>If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.<br>**url**: URL of the web page where the dialog box is displayed.<br>**message**: information displayed in the dialog box.<br>**JsResult**: the user's operation.</p> |
| onConsole(callback: (event?: { message: [ConsoleMessage](#consolemessage) }) => boolean) | <p>Triggered when the host application is notified of a JavaScript console message.<br>**message**: console message.</p> |
| onDownloadStart(callback: (event?: { url: string, userAgent: string, contentDisposition: string, mimetype: string, contentLength: number }) => void) | <p>Triggered when a download task starts on the web page.<br>**url**: URL for the download task.<br>**userAgent**: name of the user agent (UA) for the download task.<br>**contentDisposition**: Content-Disposition response header returned by the server, which may be empty.<br>**mimetype**: content media type (MIME) returned by the server.<br>**contentLength**: length of the file returned by the server.</p> |
| onErrorReceive(callback: (event?: { request: [WebResourceRequest](#webresourceerror), error: [WebResourceError](#webresourceerror) }) => void) | <p>Triggered when an error occurs during web page loading.<br>For better results, simplify the implementation logic in the callback.<br>**request**: encapsulation of a web page request.<br>**error**: encapsulation of a web page resource loading error.</p> |
| onHttpErrorReceive(callback: (event?: { request: [WebResourceRequest](#webresourceerror), response: [WebResourceResponse](#webresourceresponse) }) => void) | <p>Triggered when an HTTP error (the response code is greater than or equal to 400) occurs during web page resource loading.<br>**request**: encapsulation of a web page request.<br>**response**: encapsulation of a web page response.</p> |
| onPageBegin(callback: (event?: { url: string }) => void) | <p>Triggered when the web page starts to be loaded. This API is triggered only for the main frame content, and not for the iframe or frameset content.<br>**url**: URL of the page.</p> |
| onPageEnd(callback: (event?: { url: string }) => void) | <p>Triggered when the web page loading is complete. This API is triggered only for the main frame content.<br>**url**: URL of the page.</p> |
| onPageBegin(callback: (event?: { url: string }) => void) | <p>Triggered when the web page starts to be loaded. This API is triggered only for the main frame content, and not for the iframe or frameset content.<br>**url**: URL of the page.</p> |
| onPageEnd(callback: (event?: { url: string }) => void) | <p>Triggered when the web page loading is complete. This API is triggered only for the main frame content.<br>**url**: URL of the page.</p> |
| onProgressChange(callback: (event?: { newProgress: number }) => void) | <p>Triggered when the web page loading progress changes.<br>**newProgress**: new loading progress. The value is an integer ranging from 0 to 100.</p> |
| onTitleReceive(callback: (event?: { title: string }) => void) | <p>Triggered when the document title of the web page is changed.<br>**title**: document title.</p> |
| onRefreshAccessedHistory(callback: (event?: { url: string, isRefreshed: boolean }) => void) | <p>Triggered when loading of the web page is complete. This callback function is used by an application to update the historical link it accessed.<br>**url**: URL to be accessed.<br>**isRefreshed**: whether the page is reloaded. The value **true** means that the page is reloaded, and **false** means that the page is newly loaded.</p> |
| onRenderExited(callback: (event?: { renderExitReason: [RenderExitReason](#renderexitreason) }) => void) | <p>Triggered when the rendering process exits abnormally.<br>**renderExitReason**: cause for the abnormal exit of the rendering process.</p> |
| onShowFileSelector(callback: (event?: { result: [FileSelectorResult](#fileselectorresult), fileSelector: [FileSelectorParam](#fileselectorparam) }) => void) | <p>Triggered to process an HTML form whose input type is **file**, in response to the tapping of the **Select File** button.<br>**result**: file selection result to be sent to the web component.<br>**fileSelector**: information about the file selector.</p> |
| onUrlLoadIntercept(callback: (event?: { data:string \| [WebResourceRequest](#webresourcerequest) }) => boolean) | <p>Triggered before the **\<Web>** component loads the URL to determine whether to block the access. The callback returns **true** if the access is blocked, and **false** otherwise.<br>**data**: URL information.</p> |
### ConsoleMessage
- APIs
| Name | Description |
| ------------------------------- | ---------------------------------------- |
| getLineNumber(): number | Obtains the number of rows in the **ConsoleMessage**. |
| getMessage(): string | Obtains the log information of the **ConsoleMessage**. |
| getMessageLevel(): MessageLevel | Obtains the log information level of the **ConsoleMessage**. |
| getSourceId(): string | Obtains the path and name of the web page source file. |
| Name | Description |
| ------------------------------- | ---------------------- |
| getLineNumber(): number | Obtains the number of rows in the **ConsoleMessage**. |
| getMessage(): string | Obtains the log information of the **ConsoleMessage**.|
| getMessageLevel(): MessageLevel | Obtains the log information level of the **ConsoleMessage**.|
| getSourceId(): string | Obtains the path and name of the web page source file. |
- MessageLevel enums
| Name | Description |
| ----- | :----------------- |
| Debug | Debug level. |
| Error | Error level. |
| Info | Information level. |
| Log | Log level. |
| Warn | Warning level. |
| Name | Description |
| ----- | :---- |
| Debug | Debug level.|
| Error | Error level.|
| Info | Information level.|
| Log | Log level.|
| Warn | Warning level. |
### JsResult
Represents the result returned to the **\<Web>** component to indicate the operation performed in the dialog box.
Provides the result returned to the **\<Web>** component to indicate the user operation performed in the dialog box.
- APIs
| Name | Description |
| --------------------- | ---------------------------------------- |
| handleCancel(): void | <p>Notifies the **\<Web>** component that the user touches the Cancel button in the dialog box.</p> |
| handleConfirm(): void | <p>Notifies the **\<Web>** component that the user touches the Confirm button in the dialog box.</p> |
| Name | Description |
| --------------------- | ----------------------- |
| handleCancel(): void | <p>The user's cancel operation in the dialog box.</p> |
| handleConfirm(): void | <p>The user's confirm operation in the dialog box.</p> |
### WebResourceError
- APIs
| Name | Description |
| ---------------------- | ---------------------------------------- |
| Name | Description |
| ---------------------- | ------------ |
| getErrorCode(): number | Obtains the error code for resource loading. |
| getErrorInfo(): string | Obtains error information about resource loading. |
| getErrorInfo(): string | Obtains error information about resource loading.|
### WebResourceRequest
- APIs
| Name | Description |
| ---------------------------------------- | ---------------------------------------- |
| getRequestHeader(): Array\<[Header](#header)\> | Obtains the information about the resource request header. |
| getRequestUrl(): string | Obtains the URL of the resource request. |
| isMainFrame(): boolean | Checks whether the resource request is in the main frame. |
| isRedirect(): boolean | Checks whether the resource request is redirected by the server. |
| isRequestGesture(): boolean | Checks whether the resource request is associated with a gesture (for example, a tap). |
| Name | Description |
| ---------------------------------------- | -------------------- |
| getRequestHeader(): Array\<[Header](#header)\> | Obtains the information about the resource request header. |
| getRequestUrl(): string | Obtains the URL of the resource request. |
| isMainFrame(): boolean | Checks whether the resource request is in the main frame. |
| isRedirect(): boolean | Checks whether the resource request is redirected by the server. |
| isRequestGesture(): boolean | Checks whether the resource request is associated with a gesture (for example, a tap).|
### Header
Describes the request/response header object returned by the **\<Web>** component.
Describes the request/response header returned by the **\<Web>** component.
- Parameters
| Name | Type | Description |
| ----------- | ------ | ------------------------------------- |
| headerKey | string | Key of the request/response header. |
| headerValue | string | Value of the request/response header. |
| Name | Type | Description |
| ----------- | ------ | ------------- |
| headerKey | string | Key of the request/response header. |
| headerValue | string | Value of the request/response header.|
### WebResourceResponse
- APIs
| Name | Description |
| ---------------------------------------- | ---------------------------------------- |
| getReasonMessage(): string | Obtains the status code description of the resource response. |
| getResponseCode(): number | Obtains the status code of the resource response. |
| getResponseData(): string | Obtains the data in the resource response. |
| getResponseEncoding(): string | Obtains the encoding of the resource response. |
| getResponseHeader(): Array\<[Header](#header)\> | Obtains the resource response header. |
| getResponseMimeType(): string | Obtains the media (MIME) type of the resource response. |
| Name | Description |
| ---------------------------------------- | ------------------ |
| getReasonMessage(): string | Obtains the status code description of the resource response. |
| getResponseCode(): number | Obtains the status code of the resource response. |
| getResponseData(): string | Obtains the data in the resource response. |
| getResponseEncoding(): string | Obtains the encoding of the resource response. |
| getResponseHeader(): Array\<[Header](#header)\> | Obtains the resource response header. |
| getResponseMimeType(): string | Obtains the media (MIME) type of the resource response.|
### RenderExitReason
Explains why the rendering process exits.
| Name | Description |
| -------------------------- | ----------------- |
| ProcessAbnormalTermination | The rendering process exits abnormally. |
| ProcessWasKilled | The rendering process receives a SIGKILL message or is manually terminated.|
| ProcessCrashed | The rendering process crashes due to a segmentation error or other errors. |
| ProcessOom | The program memory is running low. |
| ProcessExitUnknown | Other reason. |
### MixedMode
| Name | Description |
| ---------- | ---------------------------------- |
| All | HTTP and HTTPS hybrid content can be loaded. This means that all insecure content can be loaded.|
| Compatible | HTTP and HTTPS hybrid content can be loaded in compatibility mode. This means that some insecure content may be loaded. |
| None | HTTP and HTTPS hybrid content cannot be loaded. |
### CacheMode
| Name | Description |
| ------- | ------------------------------------ |
| Default | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.|
| None | The cache is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet. |
| Online | The cache is not used to load the resources. All resources are obtained from the Internet. |
| Only | The cache alone is used to load the resources. |
### FileSelectorResult
Notifies the **\<Web>** component of the file selection result.
- APIs
| Name | Description |
| ---------------------------------------------- | ------------------------------------------------------------ |
| handleFileList(fileList: Array\<string>): void | Instructs the **\<Web>** component to select a file.<br>**fileList**: list of files to operate. |
### FileSelectorParam
- APIs
| Name | Description |
| -------------------------------- | ------------ |
| getTitle(): string | Obtains the title of the file selector. |
| getMode(): FileSelectorMode | Obtains the mode of the file selector. |
| getAcceptType(): Array\<string\> | Obtains the file filtering type. |
| isCapture(): boolean | Checks whether multimedia capabilities are invoked.|
### FileSelectorMode
| Name | Description |
| -------------------- | ---------- |
| FileOpenMode | Open and upload a file. |
| FileOpenMultipleMode | Open and upload multiple files. |
| FileOpenFolderMode | Open and upload a folder.|
| FileSaveMode | Save a file. |
## WebController
......@@ -179,15 +237,15 @@ Indicates whether a specific number of steps forward or backward can be performe
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| ---- | ------ | --------- | ------------- | ---------------------------------------- |
| step | number | Yes | - | Number of the steps to take. A positive number means to going forward, and a negative number means to going backward. |
| Name | Type | Mandatory | Default Value | Description |
| ---- | ------ | ---- | ---- | --------------------- |
| step | number | Yes | - | Number of the steps to take. A positive number means to going forward, and a negative number means to going backward.|
- Return value
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Whether to go forward or backward from the current page. |
| Type | Description |
| ------- | --------- |
| boolean | Whether to go forward or backward from the current page.|
### backward
......@@ -203,9 +261,9 @@ Deletes a specific application JavaScript object that is registered with the win
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| ---- | ------ | --------- | ------------- | ---------------------------------------- |
| name | string | Yes | - | Name of the registered JavaScript object, which can be used to invoke the corresponding object on the application side from the web side. |
| Name | Type | Mandatory | Default Value | Description |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
| name | string | Yes | - | Name of the registered JavaScript object, which can be used to invoke the corresponding object on the application side from the web side.|
### forward
......@@ -221,16 +279,15 @@ Obtains the element type of the area being clicked.
- HitTestType enums
| Name | Description |
| ------------- | ---------------------------------------- |
| EditText | Editable area. |
| Email | Email address. |
| HttpAnchor | Hyperlink where **src** is **http**. |
| HttpAnchorImg | Image with a hyperlink, where **src** is **http**. |
| Img | HTML::img tag. |
| Map | Geographical address. |
| PhoneNumber | Phone number. |
| Unknown | Unknown content. |
| Name | Description |
| ------------- | ------------------------ |
| EditText | Editable area. |
| Email | Email address. |
| HttpAnchor | Hyperlink where **src** is **http**. |
| HttpAnchorImg | Image with a hyperlink, where **src** is **http**.|
| Img | HTML::img tag. |
| Map | Geographical address. |
| Unknown | Unknown content. |
### loadData
......@@ -244,13 +301,13 @@ If **baseUrl** is set to an HTTP or HTTPS URL, the encoded string will be proces
- options
| Name | Type | Mandatory | Default Value | Description |
| ---------- | ------ | --------- | ------------- | ---------------------------------------- |
| data | string | Yes | - | Character string obtained after being Base64 or URL encoded. |
| mimeType | string | Yes | - | Media type (MIME). |
| encoding | string | Yes | - | Encoding type, which can be Base64 or URL. |
| baseUrl | string | No | - | URL (HTTP/HTTPS/data compliant), which is assigned by the **\<Web>** component to **window.origin**. |
| historyUrl | string | No | - | Historical record URL. If this parameter is not empty, it can be managed in historical records to implement page going backward and forward. This parameter is invalid when **baseUrl** is left empty. |
| Name | Type | Mandatory | Default Value | Description |
| ---------- | ------ | ---- | ---- | ---------------------------------------- |
| data | string | Yes | - | Character string obtained after being Base64 or URL encoded. |
| mimeType | string | Yes | - | Media type (MIME). |
| encoding | string | Yes | - | Encoding type, which can be Base64 or URL. |
| baseUrl | string | No | - | URL (HTTP/HTTPS/data compliant), which is assigned by the **\<Web>** component to **window.origin**.|
| historyUrl | string | No | - | Historical record URL. If this parameter is not empty, it can be managed in historical records to implement page going backward and forward. This parameter is invalid when **baseUrl** is left empty.|
### loadUrl
......@@ -260,14 +317,14 @@ Loads a URL using the specified HTTP header.
The object injected through **loadUrl** is valid only in the current document. It will be invalid on a new page navigated to through **loadUrl**.
Objects injected through **registerJavaScriptProxy** are still valid on a new page navigated to through **loadUrl**.
The object injected through **registerJavaScriptProxy** is still valid on a new page navigated to through **loadUrl**.
- options
| Name | Type | Mandatory | Default Value | Description |
| ------- | -------------------------- | --------- | ------------- | ---------------------------------------- |
| url | string | Yes | - | URL to load. |
| headers | Array\<[Header](#header)\> | No | [] | Additional HTTP request header of the URL. |
| Name | Type | Mandatory | Default Value | Description |
| ------- | ------------------------------ | ---- | ---- | -------------- |
| url | string | Yes | - | URL to load. |
| headers | Array\<[Header](#header)\> | No | [] | Additional HTTP request header of the URL.|
### onActive
......@@ -295,24 +352,24 @@ Injects a JavaScript object into the window and invokes the methods of the objec
- options
| Name | Type | Mandatory | Default Value | Description |
| ---------- | --------------- | --------- | ------------- | ---------------------------------------- |
| object | object | Yes | - | Application-side JavaScript object to be registered. Methods can be declared, but not attributes. The parameters and return value can only be of the string, number, or Boolean type. |
| name | string | Yes | - | Name of the object to be registered, which is the same as that invoked in the window. After registration, the window can use this name to access the JavaScript object at the application side. |
| methodList | Array\<string\> | Yes | - | Methods of the JavaScript object to be registered at the application side. |
| Name | Type | Mandatory | Default Value | Description |
| ---------- | --------------- | ---- | ---- | ---------------------------------------- |
| object | object | Yes | - | Application-side JavaScript object to be registered. Methods can be declared, but not attributes. The parameters and return value can only be of the string, number, or Boolean type.|
| name | string | Yes | - | Name of the object to be registered, which is the same as that invoked in the window. After registration, the window can use this name to access the JavaScript object at the application side.|
| methodList | Array\<string\> | Yes | - | Methods of the JavaScript object to be registered at the application side. |
### runJavaScript
runJavaScript(options: { script: string, callback?: (result: string) => void }): void
Asynchronously executes a JavaScript script. This API uses a callback to return the script execution result.**runJavaScript** can be invoked only after **loadUrl** is executed. For example, it can be executed in **onPageEnd**.
Asynchronously executes a JavaScript script. This API uses a callback to return the script execution result. **runJavaScript** can be invoked only after **loadUrl** is executed. For example, it can be executed in **onPageEnd**.
- options
| Name | Type | Mandatory | Default Value | Description |
| -------- | ------------------------ | --------- | ------------- | ---------------------------------------- |
| script | string | Yes | - | JavaScript script. |
| callback | (result: string) => void | No | - | Callback used to return the result. Returns **null** if the JavaScript script fails to be executed or no value is returned. |
| Name | Type | Mandatory | Default Value | Description |
| -------- | ------------------------ | ---- | ---- | ---------------------------------------- |
| script | string | Yes | - | JavaScript script. |
| callback | (result: string) => void | No | - | Callback used to return the result. Returns **null** if the JavaScript script fails to be executed or no value is returned.|
### stop
......@@ -320,9 +377,50 @@ stop(): void
Stops page loading.
### clearHistory
clearHistory(): void
Clears the browsing history.
### getCookieManager
getCookieManager(): WebCookie
Obtains the cookie management object of the **\<Web>** component.
- Return value
| Type | Description |
| --------- | ---------------------------------------- |
| WebCookie | Cookie management object. For details, see [WebCookie](#webcookie).|
## WebCookie
Manages behavior of cookies in **\<Web>** components. All **\<Web>** components in an application share a **WebCookie**. You can use the **getCookieManager** API in **controller** to obtain the **WebCookie** for subsequent cookie management.
### setCookie
setCookie(url: string, value: string): boolean
Sets the cookie. This API is synchronous.
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ----------------- |
| url | string | Yes | - | URL of the cookie to set.|
| value | string | Yes | - | Value of the cookie to set. |
- Return value
| Type | Description |
| ------- | ------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
### saveCookieSync
saveCookieSync(): boolean
Saves this cookie in the memory to the disk. This API is synchronous.
- Return value
| Type | Description |
| ------- | -------------------- |
| boolean | Returns the operation result.|
## Example
```
```ts
// webComponent.ets
@Entry
@Component
......@@ -344,7 +442,7 @@ struct WebComponent {
}
}
```
```
```html
<!-- index.html -->
<!DOCTYPE html>
<html>
......
# XComponent
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> **NOTE**<br>
> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
The **\<XComponent>** can accept and display the EGL/OpenGLES and media data input.
......@@ -19,20 +19,20 @@
- Name
| Name | Type | Mandatory| Description |
| ----------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| id | string | Yes | Unique ID of the component. The value can contain a maximum of 128 characters. |
| type | string | Yes | Type of the component. The options are as follows:<br>-**surface**: The content of this component is displayed individually, without being combined with that of other components.<br>-**component**: The content of this component is displayed after having been combined with that of other components.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| libraryname | string | No | Name of the dynamic library generated after compilation at the application native layer. |
| Name | Type | Mandatory | Description |
| ----------- | --------------------------------------- | --------- | ------------------------------------------------------------ |
| id | string | Yes | Unique ID of the component. The value can contain a maximum of 128 characters. |
| type | string | Yes | Type of the component. The options are as follows:<br>- **surface**: The content of this component is displayed individually, without being combined with that of other components.<br>- **component**: The content of this component is displayed after having been combined with that of other components. |
| libraryname | string | No | Name of the dynamic library generated after compilation at the application native layer. |
| controller | [XComponentController](#XComponentController) | No | Controller bound to the component, which can be used to invoke methods of the component. |
## Events
| Name | Description |
| Name | Description |
| ------------------------------- | ------------------------ |
| onLoad(context?: object) => void | Triggered when the plug-in is loaded.|
| onDestroy() => void | Triggered when the plug-in is destroyed.|
| onLoad(context?: object) => void | Triggered when the plug-in is loaded. |
| onDestroy() => void | Triggered when the plug-in is destroyed. |
## XComponentController
......@@ -52,9 +52,9 @@ Obtains the ID of the surface held by the **\<XComponent>**. The ID can be used
- Return value
| Type | Description |
| Type | Description |
| ------ | --------------------------- |
| string | ID of the surface held by the **\<XComponent>**.|
| string | ID of the surface held by the **\<XComponent>**. |
### setXComponentSurfaceSize
......@@ -64,10 +64,10 @@ Sets the width and height of the surface held by the **\<XComponent>**.
- Parameters
| Name | Type| Mandatory| Default Value| Description |
| Name | Type | Mandatory | Default Value | Description |
| ------------- | -------- | ---- | ------ | ----------------------------- |
| surfaceWidth | number | Yes | - | Width of the surface held by the **\<XComponent>**.|
| surfaceHeight | number | Yes | - | Height of the surface held by the **\<XComponent>**.|
| surfaceWidth | number | Yes | - | Width of the surface held by the **\<XComponent>**. |
| surfaceHeight | number | Yes | - | Height of the surface held by the **\<XComponent>**. |
### getXComponentContext
......@@ -85,7 +85,8 @@ Obtains the context of an **\<XComponent>** object.
Provide a surface-type **\<XComponent>** to support capabilities such as camera preview.
```
```ts
// xxx.ets
import camera from '@ohos.multimedia.camera';
@Entry
@Component
......
# Gesture Binding Methods
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> **NOTE**<br>
> This method is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
......@@ -16,7 +16,7 @@ None
Use the following attributes to bind gesture recognition to a component. When a gesture is recognized, the event callback is invoked to notify the component.
| Name | Type | Default Value | Description |
| Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- |
| gesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture to recognize.<br/>**gesture** specifies the type of the gesture to bind, and **mask** specifies the event response setting. |
| priorityGesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture to preferentially recognize.<br/>**gesture** specifies the type of the gesture to bind, and **mask** specifies the event response setting.<br/>> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>> - By default, the child component takes precedence over the parent component in gesture recognition. When **priorityGesture** is configured for the parent component, the parent component takes precedence over the child component in gesture recognition. |
......@@ -24,14 +24,14 @@ Use the following attributes to bind gesture recognition to a component. When a
- GestureMask enums
| Name | Description |
| Name | Description |
| -------- | -------- |
| Normal | The gestures of child components are not masked and are recognized based on the default gesture recognition sequence. |
| IgnoreInternal | The gestures of child components are masked. Only the gestures of the current component are recognized.<br/>> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>> However, the built-in gestures of the child components are not masked. For example, when the child component is a **&lt;List&gt;** component, the built-in sliding gestures can still be triggered. |
- Gesture types
| Name | Description |
| Name | Description |
| -------- | -------- |
| TapGesture | Tap gesture, which can be a single-tap or multi-tap gesture. |
| LongPressGesture | Long press gesture. |
......@@ -46,12 +46,12 @@ Use the following attributes to bind gesture recognition to a component. When a
The component uses the **gesture** method to bind the gesture object and uses the events provided in this object to respond to the gesture operation. For example, the **onAction** event of the **TapGesture** object can be used to respond to a click event. For details about the event definition, see the section of each gesture object.
- TapGesture events
| Name | Description |
| Name | Description |
| -------- | -------- |
| onAction((event?: GestureEvent) =&gt; void) | Callback invoked when a tap gesture is recognized. |
- GestureEvent attributes
| Name | Type | Description |
| Name | Type | Description |
| -------- | -------- | -------- |
| timestamp | number | Timestamp of the event. |
| target<sup>8+</sup> | EventTarget | Object that triggers the gesture event. |
......@@ -60,7 +60,7 @@ The component uses the **gesture** method to bind the gesture object and uses th
## Example
```
```ts
@Entry
@Component
struct GestureSettingsExample {
......@@ -81,7 +81,7 @@ struct GestureSettingsExample {
TapGesture()
.onAction((event: GestureEvent) => {
this.value = 'priorityGesture onAction' + '\ncomponent globalPos:('
+ event.target.area.globalPos.x + ',' + event.target.area.globalPos.y + ')\nwidth:'
+ event.target.area.globalPosition.x + ',' + event.target.area.globalPosition.y + ')\nwidth:'
+ event.target.area.width + '\nheight:' + event.target.area.height
}), GestureMask.IgnoreInternal
)
......@@ -90,4 +90,4 @@ struct GestureSettingsExample {
}
```
![en-us_image_0000001256858411](figures/en-us_image_0000001256858411.gif)
![en-us_image_0000001256858411](figures/en-us_image_0000001256858411.gif)
\ No newline at end of file
# Click Event
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> This method is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
> **NOTE**
> This event is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
## Required Permissions
......@@ -54,7 +54,8 @@ None
## Example
```
```ts
// xxx.ets
@Entry
@Component
struct ClickExample {
......@@ -66,7 +67,7 @@ struct ClickExample {
.onClick((event: ClickEvent) => {
console.info(this.text = 'Click Point:' + '\n screenX:' + event.screenX + '\n screenY:' + event.screenY
+ '\n x:' + event.x + '\n y:' + event.y + '\ntarget:' + '\n component globalPos:('
+ event.target.area.globalPos.x + ',' + event.target.area.globalPos.y + ')\n width:'
+ event.target.area.globalPosition.x + ',' + event.target.area.globalPosition.y + ')\n width:'
+ event.target.area.width + '\n height:' + event.target.area.height)
})
Text(this.text).padding(15)
......
# Touch Event
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> This method is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
> **NOTE**
> This event is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
## Required Permissions
......@@ -26,7 +26,7 @@ None
| touches | Array&lt;TouchObject&gt; | All finger information. |
| changedTouches | Array&lt;TouchObject&gt; | Finger information changed. |
| timestamp | number | Timestamp of the event. |
| target<sup>8+</sup> | EventTarget | Target of the event. |
| target<sup>8+</sup> | [EventTarget](ts-universal-events-click.md) | Target of the event. |
- APIs
| API | Description |
......@@ -57,7 +57,8 @@ None
## Example
```
```ts
// xxx.ets
@Entry
@Component
struct TouchExample {
......@@ -79,7 +80,7 @@ struct TouchExample {
}
console.info(this.text = 'TouchType:' + this.eventType + '\nDistance between touch point and touch element:\nx: '
+ event.touches[0].x + '\n' + 'y: ' + event.touches[0].y + '\ncomponent globalPos:('
+ event.target.area.globalPos.x + ',' + event.target.area.globalPos.y + ')\nwidth:'
+ event.target.area.globalPosition.x + ',' + event.target.area.globalPosition.y + ')\nwidth:'
+ event.target.area.width + '\nheight:' + event.target.area.height)
})
Text(this.text)
......
......@@ -10,8 +10,8 @@ Custom components decorated by @Preview can be previewed in the Previewer of Dev
Example of using @Preview:
```
// Display only Hello Component1 on the preview. The content under MyComponent is displayed on the real device.
@Entry
@Component
struct MyComponent {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册