From b7541ed45d0176f6b83c2602bd64eecccfd429d7 Mon Sep 17 00:00:00 2001 From: jiangkuaixue Date: Wed, 7 Dec 2022 17:09:13 +0800 Subject: [PATCH] add webview interface Signed-off-by: jiangkuaixue --- api/@internal/component/ets/web.d.ts | 153 ++++++++++++++++++++++++ api/@ohos.web.webview.d.ts | 167 +++++++++++++++++++++++++++ 2 files changed, 320 insertions(+) diff --git a/api/@internal/component/ets/web.d.ts b/api/@internal/component/ets/web.d.ts index 7e9c44e0d6..1353476cfc 100644 --- a/api/@internal/component/ets/web.d.ts +++ b/api/@internal/component/ets/web.d.ts @@ -590,6 +590,30 @@ declare class PermissionRequest { grant(resources: Array): void; } +/** + * Defines the onDataResubmission callback, related to {@link onDataResubmission} method. + * @since 9 + */ +declare class DataResubmissionHandler { + /** + * Constructor. + * @since 9 + */ + constructor(); + + /** + * Resend related form data. + * @since 9 + */ + resend(): void; + + /** + * Do not resend related form data. + * @since 9 + */ + cancel(): void; +} + /** * Defines the onWindowNew callback, related to {@link onWindowNew} method. * @since 9 @@ -808,6 +832,14 @@ declare class WebResourceRequest { * @since 8 */ isRedirect(): boolean; + + /** + * Get request mothod. + * @returns Return the request method. + * + * @since 9 + */ + getRequestMethod(): string; } @@ -1925,6 +1957,127 @@ declare class WebAttribute extends CommonMethod { * @since 9 */ multiWindowAccess(multiWindow: boolean): WebAttribute; + + /** + * Key events notify the application before the WebView consumes them. + * @param event Key event info. + * + * @returns True if the application consumes key events else false. + * @since 9 + */ + onInterceptKeyEvent(callback: (event: KeyEvent) => boolean): WebAttribute; + + /** + * Set the font of webview standard font library. The default font is "sans serif". + * @param family Standard font set series. + * + * @since 9 + */ + webStandardFont(family: string): WebAttribute; + + /** + * Set the font of webview serif font library. The default font is "serif". + * @param family Serif font set series. + * + * @since 9 + */ + webSerifFont(family: string): WebAttribute; + + /** + * Set the font of webview sans serif font library. The default font is "sans-serif". + * @param family Sans serif font set series. + * + * @since 9 + */ + webSansSerifFont(family: string): WebAttribute; + + /** + * Set the font of webview fixed font library. The default font is "monospace". + * @param family Fixed font set series. + * + * @since 9 + */ + webFixedFont(family: string): WebAttribute; + + /** + * Set the font of webview fantasy font library. The default font is "fantasy". + * @param family fantasy font set series. + * + * @since 9 + */ + webFantasyFont(family: string): WebAttribute; + + /** + * Set the font of webview cursive font library. The default font is "cursive". + * @param family Cursive font set series. + * + * @since 9 + */ + webCursiveFont(family: string): WebAttribute; + + /** + * Set the default fixed font value of webview. The default value is 13, ranging from 1 to 72. + * @param size Font size. + * + * @since 9 + */ + defaultFixedFontSize(size: number): WebAttribute; + + /** + * Set the default font value of webview. The default value is 16, ranging from 1 to 72. + * @param size Font size. + * + * @since 9 + */ + defaultFontSize(size: number): WebAttribute; + + /** + * Set the minimum value of webview font. The default value is 8, and the values are 1 to 72. + * @param size Font size. + * + * @since 9 + */ + minFontSize(size: number): WebAttribute; + + /** + * Whether web component can load resource from network. + * @param block {@code true} means it can't load resource from network; {@code false} otherwise. + * + * @since 9 + */ + blockNetwork(block: boolean): WebAttribute; + + /** + * Triggered when the application receive the url of an apple-touch-icon. + * @param callback The triggered callback when the application receive an new url of an + * apple-touch-icon. + * @since 9 + */ + onTouchIconUrlReceived(callback: (event: {url: string, + precomposed: boolean}) => void): WebAttribute; + + /** + * Triggered when the application receive a new favicon for the current web page. + * @param callback The triggered callback when the application receive a new favicon for the + * current web page. + * @since 9 + */ + onFaviconReceived(callback: (event: {favicon: PixelMap}) => void): WebAttribute; + + /** + * Triggered when previous page will no longer be drawn and next page begin to draw. + * @param callback The triggered callback when previous page will no longer be drawn and next + * page begin to draw. + * @since 9 + */ + onPageVisible(callback: (event: {url: string}) => void): WebAttribute; + + /** + * Triggered when the form could be resubmitted. + * @param callback The triggered callback to decision whether resend form data or not. + * @since 9 + */ + onDataResubmitted(callback: (event: {handler: DataResubmissionHandler}) => void): WebAttribute; } declare const Web: WebInterface; diff --git a/api/@ohos.web.webview.d.ts b/api/@ohos.web.webview.d.ts index 164a1ef752..fdc5d77fd5 100644 --- a/api/@ohos.web.webview.d.ts +++ b/api/@ohos.web.webview.d.ts @@ -17,6 +17,7 @@ import {AsyncCallback} from "./basic"; import {Resource} from 'GlobalResource'; +import image from "./@ohos.multimedia.image"; /** * This module provides the capability to manage web modules. @@ -479,6 +480,75 @@ declare namespace webview { onMessageEvent(callback: (result: string) => void): void; } + /** + * Provides information for history item in BackForwardList. + * @name HistoryItem + * @since 9 + * @syscap SystemCapability.Web.Webview.Core + */ + interface HistoryItem { + /** + * Pixelmap of icon. + * + * @since 9 + */ + icon: image.PixelMap; + + /** + * Url of this history item. + * + * @since 9 + */ + historyUrl: string; + + /** + * Original request url of this history item. + * + * @since 9 + */ + historyRawUrl: string; + + /** + * Title of this history item. + * + * @since 9 + */ + title: string; + } + + /** + * Provides back and forward history list information method. related to {@link HistoryItem}. + * @name BackForwardList + * @since 9 + * @syscap SystemCapability.Web.Webview.Core + */ + interface BackForwardList { + /** + * Current index in BackForwardList. + * + * @since 9 + */ + currentIndex: number; + + /** + * Size of in BackForwardList. + * + * @since 9 + */ + size: number; + + /** + * Get history entry at given index. + * + * @param { number } index Index of back forward list entry. + * @throws { BusinessError } 401 - Invalid input parameter. + * @returns { HistoryItem } HistroyItem at given index in back forward list. + * + * @since 9 + */ + getItemAtIndex(index: number): HistoryItem; + } + /** * Provides methods for controlling the web controller. * @@ -906,6 +976,103 @@ declare namespace webview { * @since 9 */ getUrl(): string; + + /** + * Scroll the contents of this Webview up by half the view size. + * + * @param { boolean } top - Jump to the top of the page if true. + * @throws { BusinessError } 401 - Invalid input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associated with a Web component. + * + * @since 9 + */ + pageUp(top:boolean): void; + + /** + * Scroll the contents of this Webview down by half the view size. + * + * @param { boolean } bottom - Jump to the bottom of the page if true. + * @throws { BusinessError } 401 - Invalid input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associated with a Web component. + * + * @since 9 + */ + pageDown(bottom:boolean): void; + + /** + * Gets the original url of current Web page. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associated with a Web component. + * @returns { string } Return the the original url of the current page. + * + * @since 9 + */ + getOriginalUrl(): string; + + /** + * Gets the original url of current Web page. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associated with a Web component. + * @returns { string } Return the the original url of the current page. + * + * @since 9 + */ + getFavicon(): image.PixelMap; + + /** + * Put network state for web. Which is used to set window.navigator.isOnline property in + * JavaScript. + * + * @throws { BusinessError } 401 - Invalid input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associated with a Web component. + * + * @param { boolean } enable - Whether enable window.navigator.isOnline. + * @since 9 + */ + setNetworkAvailable(enable: boolean): void; + + /** + * Query if current document has image. + * + * @param { AsyncCallback } callback - Called after query image has finished. + * @throws { BusinessError } 401 - Invalid input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associated with a Web component. + * @returns { Promise } A promise resolved after query image has finished. + * + * @since 9 + */ + hasImage(): Promise; + hasImage(callback: AsyncCallback): void; + + /** + * Get back forward stack list from current webview. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associated with a Web component. + * @returns { BackForwardList } Back forward list for current webview. + * + * @since 9 + */ + getBackForwardEntries(): BackForwardList; + + /** + * Remove resource cache in application. So this method will Remove all cache for all webviews in the + * same application. + * + * @param { boolean } clearRom - Remove cache in both rom and ram if true. Otherwise only clear cache + * in ram. + * @throws { BusinessError } 401 - Invalid input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associated with a Web component. + * @since 9 + */ + removeCache(clearRom: boolean): void; } } -- Gitee