Mac Developer Library

Developer

WebKit Framework Reference WebEditingDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

WebViewEditingDelegate

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import WebKit

Objective-C

@import WebKit;

Availability


Available in OS X v10.3.9 and later.

You use WebEditingDelegate to control or augment the editing behavior of a WebView object. Objects conforming to the WebEditingDelegate informal protocol may receive should messages before or did messages after an editing action. Typically, you implement an editing delegate if you want to change the default editing behavior.

  • Returns whether the user should be allowed to apply a style to a range of content.

    Declaration

    Swift

    func webView(_ webView: WebView!, shouldApplyStyle style: DOMCSSStyleDeclaration!, toElementsInDOMRange range: DOMRange!) -> Bool

    Objective-C

    - (BOOL)webView:(WebView *)webView shouldApplyStyle:(DOMCSSStyleDeclaration *)style toElementsInDOMRange:(DOMRange *)range

    Parameters

    webView

    The web view that the user is editing.

    style

    The style to apply.

    range

    The range of the content.

    Return Value

    YEStrue if the user should be allowed to apply the style to the content range; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns whether the user is allowed to edit a range of content in a web view.

    Declaration

    Swift

    func webView(_ webView: WebView!, shouldBeginEditingInDOMRange range: DOMRange!) -> Bool

    Objective-C

    - (BOOL)webView:(WebView *)webView shouldBeginEditingInDOMRange:(DOMRange *)range

    Parameters

    webView

    The web view that the user is editing.

    range

    The section of the begin-editing request; used to determine if editing is allowed. Typically, range is not the current selection but may becomes the current selection if this method returns YEStrue.

    Return Value

    YEStrue if the user is allowed to edit webView; otherwise, NOfalse.

    Discussion

    This method is invoked when a web view attempts to become the first responder or when the user drops an object on it.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns whether the user should be allowed to change the selected range.

    Declaration

    Swift

    func webView(_ webView: WebView!, shouldChangeSelectedDOMRange currentRange: DOMRange!, toDOMRange proposedRange: DOMRange!, affinity selectionAffinity: NSSelectionAffinity, stillSelecting flag: Bool) -> Bool

    Objective-C

    - (BOOL)webView:(WebView *)webView shouldChangeSelectedDOMRange:(DOMRange *)currentRange toDOMRange:(DOMRange *)proposedRange affinity:(NSSelectionAffinity)selectionAffinity stillSelecting:(BOOL)flag

    Parameters

    webView

    The web view that the user is editing.

    currentRange

    The old range the user wants to change.

    proposedRange

    The new range the user wants to select.

    selectionAffinity

    The direction of the selection.

    flag

    YEStrue if the user is still selecting; otherwise, NOfalse.

    Return Value

    YEStrue if the user is allowed to change the selected range; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns whether the user should be allowed to change the typing style in a web view.

    Declaration

    Swift

    func webView(_ webView: WebView!, shouldChangeTypingStyle currentStyle: DOMCSSStyleDeclaration!, toStyle proposedStyle: DOMCSSStyleDeclaration!) -> Bool

    Objective-C

    - (BOOL)webView:(WebView *)webView shouldChangeTypingStyle:(DOMCSSStyleDeclaration *)currentStyle toStyle:(DOMCSSStyleDeclaration *)proposedStyle

    Parameters

    webView

    The web view that the user is editing.

    currentStyle

    The old style the user wants to change.

    proposedStyle

    The new style the user wants to set.

    Return Value

    YEStrue if the user should be allowed to change the typing style in webView to proposedStyle; otherwise, NOfalse.

    Discussion

    You can implement this method to take some other action—for example, set the typing style to a different style—and return NOfalse .

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns whether the user should be allowed to delete a range of content.

    Declaration

    Swift

    func webView(_ webView: WebView!, shouldDeleteDOMRange range: DOMRange!) -> Bool

    Objective-C

    - (BOOL)webView:(WebView *)webView shouldDeleteDOMRange:(DOMRange *)range

    Parameters

    webView

    The web view that the user is editing.

    range

    The range of the content to delete.

    Return Value

    YEStrue if the user should be allowed to delete the content specified by range; otherwise, NOfalse.

    Discussion

    This method may perform an alternate action—for example, delete a different range—and return NOfalse.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns whether the user should be allowed to end editing.

    Declaration

    Swift

    func webView(_ webView: WebView!, shouldEndEditingInDOMRange range: DOMRange!) -> Bool

    Objective-C

    - (BOOL)webView:(WebView *)webView shouldEndEditingInDOMRange:(DOMRange *)range

    Parameters

    webView

    The web view that the user is editing.

    range

    Typically, the current selection, although it might not be. Use the range parameter to help determine whether the user can end editing.

    Return Value

    YEStrue if the user should be allowed to end editing webView; otherwise, NOfalse. If this method returnsYEStrue, webView ends editing and resigns as the first responder.

    Discussion

    This method is invoked when a web view attempts to resign as the first responder.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns whether the user should be allowed to insert a node in place of a range of content.

    Declaration

    Swift

    func webView(_ webView: WebView!, shouldInsertNode node: DOMNode!, replacingDOMRange range: DOMRange!, givenAction action: WebViewInsertAction) -> Bool

    Objective-C

    - (BOOL)webView:(WebView *)webView shouldInsertNode:(DOMNode *)node replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action

    Parameters

    webView

    The web view that the user is editing.

    node

    The content to insert.

    range

    The portion of the content that is replaced with node.

    action

    Indicates the type of user action that initiated the insertion.

    Return Value

    YEStrue if the user should be allowed to insert node in webView; otherwise, NOfalse.

    Discussion

    This method may perform an alternate action—for example, insert a different node—and return NOfalse.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns whether a user should be allowed to insert text in place of a range of content.

    Declaration

    Swift

    func webView(_ webView: WebView!, shouldInsertText text: String!, replacingDOMRange range: DOMRange!, givenAction action: WebViewInsertAction) -> Bool

    Objective-C

    - (BOOL)webView:(WebView *)webView shouldInsertText:(NSString *)text replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action

    Parameters

    webView

    The web view that the user is editing.

    text

    The text to insert.

    range

    The portion of the document that will be replaced with text.

    action

    Indicates the type of user action that initiated the insertion.

    Return Value

    YEStrue if the user should be allowed to insert text in webView; otherwise, NOfalse.

    Discussion

    This method may perform an alternate action—for example, insert different text—and return NOfalse.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns whether the receiver performs a command instead of the web view.

    Declaration

    Swift

    func webView(_ webView: WebView!, doCommandBySelector command: Selector) -> Bool

    Objective-C

    - (BOOL)webView:(WebView *)webView doCommandBySelector:(SEL)command

    Parameters

    webView

    The web view that the user is editing.

    command

    The command to perform.

    Return Value

    YEStrue if the receiver will perform command; otherwise, NOfalse.

    Discussion

    Implement this method if you want to perform command instead of letting the web view perform command.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns the undo manager to be used by a web view.

    Declaration

    Swift

    func undoManagerForWebView(_ webView: WebView!) -> NSUndoManager!

    Objective-C

    - (NSUndoManager *)undoManagerForWebView:(WebView *)webView

    Parameters

    webView

    The web view that the user is editing.

    Return Value

    The undo manager.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • The type of user action that initiated a delegate message.

    Declaration

    Swift

    enum WebViewInsertAction : Int { case Typed case Pasted case Dropped }

    Objective-C

    typedef enum { WebViewInsertActionTyped, WebViewInsertActionPasted, WebViewInsertActionDropped, } WebViewInsertAction;

    Constants

    • Typed

      WebViewInsertActionTyped

      Indicates the user inserted content by typing.

      Available in OS X v10.3 and later.

    • Pasted

      WebViewInsertActionPasted

      Indicates the user inserted content by pasting.

      Available in OS X v10.3 and later.

    • Dropped

      WebViewInsertActionDropped

      Indicates the user inserted content by dropping.

      Available in OS X v10.3 and later.

    Discussion

    These constants are described in WebEditingDelegate.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.