WebView:
Filter:
Classes | GUI > Views

WebView : View : QObject : Object

Web page display and browser
Source: QWebView.sc
Subclasses: QWebView

Description

WebView displays web pages and provides all the standard browsing functionality.

Since the Qt WebEngine dependency is hefty and difficult to install on some systems, it is possible for sclang to have been built without WebView support (using the CMake flag -DSC_USE_QTWEBENGINE=OFF at compile). If so, attempting to invoke this class will throw an error.

Class Methods

WebView.clearCache

Clears the cache for all browser instances.

WebView.setUrlHandler(prefix, function)

Set or clear a function to handle a specific URL prefix (e.g. mail://)

Arguments:

prefix

URL prefix. For mail:///, use the string "mail" (do not append "://")

function

Function to execute when any WebView loads a URL with this prefix. First argument is the URL.

Inherited class methods

Undocumented class methods

WebView.prSetUrlHandler(prefix, function)

WebView.qtClass

Instance Methods

Navigation

.url

.url = url

Gets the current URL, or navigates to a new one. This is equivalent to entering a URL in a browser's URL box.

.navigate(url)

Navigate to a url. This is equivalent to clicking a link on a page - after a navigate call, back will return you to the previous page.

.back

Navigates to the previous page in history.

.forward

Navigates to the next page in history.

.findText(text, reversed: false, func)

Finds and selects the next instance of given text on the current page. When the given text changes, the search starts anew.

Arguments:

text

The text to find; a String.

reversed

Whether to search in reverse direction; a Boolean.

func

A function, called when the operation is finished. If the text was found this function is passed true, otherwise false.

.triggerPageAction(action, checked: true)

Trigger an action on the current page. Possible actions include: reload, select all, copy, undo, redo (see QWebPageAction)

Arguments:

action

A QWebPageAction.

checked

A Boolean to enable or disable the action (applies to only some actions).

Data

.setHtml(html, baseUrl: "sc:///")

Set the HTML displayed in the view.

Arguments:

html

A String.

baseUrl

A url. The browser will interpret this to be the current page location.

.setContent(data, mimeType: "text/html", baseUrl: "sc:///")

Set the raw content of a web view. This can be used to display binary data such as image / movie files.

Arguments:

data

An Int8Array containing data.

mimeType

A mime type, of the form e.g. "image/jpeg"

baseUrl

A url. The browser will interpret this to be the current page location.

.setAttribute(attribute, on)

Set a QWebAttribute for the view. Attributes can affect behavior such as caching, auto-loading images, file url access, etc.

Arguments:

attribute

A QWebAttribute.

on

A Boolean.

.testAttribute(attribute)

Check the enablement state of a QWebAttribute.

Arguments:

attribute

A QWebAttribute.

Returns:

A Boolean.

.resetAttribute(attribute)

Reset the enablement state of a QWebAttribute.

Arguments:

attribute

A QWebAttribute.

.toPlainText(func)

Convert the page to plain text.

Arguments:

func

A callback function. Called with the resulting plain text string when the operation is finished.

.toHtml(func)

Fetch the HTML of the current page.

Arguments:

func

A callback function. Called with the resulting HTML string when the operation is finished.

.title

The title of the current page.

Returns:

A String.

.requestedUrl

The requested url for the current page.

Returns:

A String.

.selectedText

The currently selected text.

Returns:

A String.

Behavior and appearance

.audioMuted

.audioMuted = muted

Get or set audio mute setting for the view;

Arguments:

muted

A Boolean.

.contentsSize

Get the size of the current content.

Returns:

A Point

.scrollPosition

.scrollPosition = point

Get or sets the scroll position of the current page.

Returns:

A Point

.hasSelection

Returns whether the page has a text selection.

Returns:

A Boolean.

.enterInterpretsSelection

.enterInterpretsSelection = b

Whether pressing Ctrl+Return or Ctrl+Enter while some text is selected should evaluate the selection as SuperCollider code.

Arguments:

b

A Boolean.

.setFontFamily(which, font)

Sets a specific font family to be used in place of a CSS-specified generic font family.

Arguments:

which

The CSS generic font family to assign a font to; one of QWebFontFamily

font

A font family name to be assigned to the generic family; a String.

.zoom

.zoom = zoom

Gets or sets the zoom level on a page.

Arguments:

zoom

A Number, where 1.0 is the default zoom.

.editable

.editable = b

Get or set whether the entire web page is editable.

Arguments:

b

A Boolean.

.pageBackgroundColor

.pageBackgroundColor = color

Get or set the default background color of web pages.

Arguments:

color

A Color.

Actions

.onAudioMutedChanged

.onAudioMutedChanged = func

Sets the object to be evaluated when the mute setting of the view has changed.

.onRecentlyAudibleChanged

.onRecentlyAudibleChanged = func

Sets the object to be evaluated when the page has started or stopped playing audio.

.onContentsSizeChanged

.onContentsSizeChanged = func

Sets the object to be evaluated when the contents size of the view has changed

.onScrollPositionChanged

.onScrollPositionChanged = func

Sets the object to be evaluated when the scroll position on a page has changed.

.onSelectionChanged

.onSelectionChanged = func

Sets the object to be evaluated when the text selection on a page has changed.

.onJavaScriptMsg

.onJavaScriptMsg = func

Sets the object to be evaluated when a javascript console message is posted.

.onLinkHovered

.onLinkHovered = func

Sets the object to be evaluated when a the mouse rolls over a link.

.onTitleChanged

.onTitleChanged = func

Sets the object to be evaluated when the title of the displayed page changes.

.onUrlChanged

.onUrlChanged = func

Sets the object to be evaluated when the url of the displayed page changes.

.onLoadProgress

.onLoadProgress = func

Sets the object to be evaluated with load progress updates.

.onLoadStarted

.onLoadStarted = func

Sets the object to be evaluated when a page load begins.

.onLoadFinished

.onLoadFinished = func

Sets the object to be evaluated when a page has loaded successfully, passing the view as the argument.

.onLoadFailed

.onLoadFailed = func

Sets the object to be evaluated when a page has failed to load, passing the view as the argument.

.overrideNavigation

.overrideNavigation = b

When true, page navigation requests will not be handled. Use in combination with onLinkActivated to provide custom navigation behavior.

.onLinkActivated

.onLinkActivated = func

Sets the object to be evaluated when the user triggers a link. Arguments are: a URL, a QWebPageNavigationType, a bool (page is opening in current view).

When this is set to other than nil, WebView will stop handling clicked links altogether. Setting this to nil will restore WebView link handling again. Note: for specialty behavior when clicking on links, it is much better to use setUrlHandler in most cases.

.onReloadTriggered

.onReloadTriggered = func

Sets the object to be evaluated whenever a page reload is requested, passing the view and the URL to be reloaded (as String) as the arguments.

JavaScript

.runJavaScript(javascript, func)

Evaluates the given JavaScript code in the context of the current page.

Arguments:

javascript

A String.

func

A function to be called when execution is complete, with the result as first argument.

NOTE: javascript code can correctly return Numbers, Strings and Arrays, but it can't currently pass javascript Objects to sclang. It is possible however to use JSON serialization to acheive this:

Inherited instance methods

Undocumented instance methods

.evaluateJavaScript(script)

From extension in /usr/share/SuperCollider/SCClassLibrary/deprecated/3.10/GUI/QWebView.sc

.html

.html = htmlString

From extension in /usr/share/SuperCollider/SCClassLibrary/deprecated/3.10/GUI/QWebView.sc

.onInterpret(code)

.onReload = func

From extension in /usr/share/SuperCollider/SCClassLibrary/deprecated/3.10/GUI/QWebView.sc

.onTerminated(status, code)

.plainText

From extension in /usr/share/SuperCollider/SCClassLibrary/deprecated/3.10/GUI/QWebView.sc

.prLoadFinished(ok)

.reload

.scrollDown(value)

.scrollUp(value)

.stop

Examples