WebEditingDelegate Protocol Reference

(informal protocol)

Framework
/System/Library/Frameworks/WebKit.framework
Availability
Available in OS X v10.3.9 and later.
Companion guide
Declared in
WebEditingDelegate.h

Overview

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.

Tasks

Controlling Editing Behavior

Responding to Notifications

Performing Commands

Getting the Undo Manager

Instance Methods

undoManagerForWebView:

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

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

The web view that the user is editing.

Return Value

The undo manager.

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webView:doCommandBySelector:

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

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

The web view that the user is editing.

command

The command to perform.

Return Value

YES if the receiver will perform command; otherwise, NO.

Discussion

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

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webView:shouldApplyStyle:toElementsInDOMRange:

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

- (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

YES if the user should be allowed to apply the style to the content range; otherwise, NO.

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webView:shouldBeginEditingInDOMRange:

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

- (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 YES.

Return Value

YES if the user is allowed to edit webView; otherwise, NO.

Discussion

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

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webView:shouldChangeSelectedDOMRange:toDOMRange:affinity:stillSelecting:

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

- (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

YES if the user is still selecting; otherwise, NO.

Return Value

YES if the user is allowed to change the selected range; otherwise, NO.

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webView:shouldChangeTypingStyle:toStyle:

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

- (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

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

Discussion

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

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webView:shouldDeleteDOMRange:

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

- (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

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

Discussion

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

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webView:shouldEndEditingInDOMRange:

Returns whether the user should be allowed to end editing.

- (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

YES if the user should be allowed to end editing webView; otherwise, NO. If this method returnsYES, 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.

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webView:shouldInsertNode:replacingDOMRange:givenAction:

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

- (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

YES if the user should be allowed to insert node in webView; otherwise, NO.

Discussion

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

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webView:shouldInsertText:replacingDOMRange:givenAction:

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

- (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

YES if the user should be allowed to insert text in webView; otherwise, NO.

Discussion

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

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webViewDidBeginEditing:

Sent by the default notification center when the user begins editing the web view.

- (void)webViewDidBeginEditing:(NSNotification *)notification
Parameters
notification

Always set to WebViewDidBeginEditingNotification. You can retrieve the WebView object by sending object to notification.

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webViewDidChange:

Sent by the default notification center when the user changes content in the web view.

- (void)webViewDidChange:(NSNotification *)notification
Parameters
notification

Always set to WebViewDidChangeNotification. You can retrieve the WebView object by sending object to notification.

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webViewDidChangeSelection:

Sent by the default notification center when the user changes the selection in the web view.

- (void)webViewDidChangeSelection:(NSNotification *)notification
Parameters
notification

Always set to WebViewDidChangeSelectionNotification. You can retrieve the WebView object by sending object to notification.

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webViewDidChangeTypingStyle:

Sent by the default notification center when the user changes the typing style in the web view.

- (void)webViewDidChangeTypingStyle:(NSNotification *)notification
Parameters
notification

Always set to WebViewDidChangeTypingStyleNotification. You can retrieve the WebView object by sending object to notification.

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

webViewDidEndEditing:

Sent by the default notification center when the user stops editing the web view.

- (void)webViewDidEndEditing:(NSNotification *)notification
Parameters
notification

Always set to WebViewDidEndEditingNotification. You can retrieve the WebView object by sending object to notification.

Availability
  • Available in OS X v10.3.9 and later.
Declared In
WebEditingDelegate.h

Constants

WebViewInsertAction

The type of user action that initiated a delegate message.

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

Indicates the user inserted content by typing.

Available in OS X v10.3 and later.

Declared in WebEditingDelegate.h.

WebViewInsertActionPasted

Indicates the user inserted content by pasting.

Available in OS X v10.3 and later.

Declared in WebEditingDelegate.h.

WebViewInsertActionDropped

Indicates the user inserted content by dropping.

Available in OS X v10.3 and later.

Declared in WebEditingDelegate.h.

Discussion

These constants are described in WebEditingDelegate.

Availability
  • Available in OS X v10.3.9 and later.