WebView
supports, through the WebEditingDelegate
, a mechanism for the delegate to implement custom behavior for a variety of actions the WebView
(or the private WebHTMLView
) receives. When an action such as:
-(void)changeAttributes:(id)sender
is received in WebHTMLView
, it is passed through to the delegate method:
-(BOOL)webView:(WebView *)webView doCommandBySelector:(SEL)command
Unfortunately, the mechanism does not provide for conveyance of the "sender
" in the original action method.
For the vast majority of actions, the sender is unimportant, but for changeAttributes, and changeFont, for example, the contract requires that "sender
" be called by the recipient in order to e.g. convertAttributes:
or convertFont:
.
For the changeFont
case, it turns out that calling [[NSFontManager sharedFontManager] convertFont:]
is sufficient, as coincidentally this is what the sender is.
In the changeAttributes
case, in particular when strikethrough is changed, the sender may be a private class "NSFontEffectsBox
" which presumably corresponds to the subsection of the font panel that is responsible for changing strikethrough/etc settings.
Unfortunately, calling [[NSFontManager sharedFontManager] convertAttributes:]
does NOT obtain the expected attribute changes. This leaves a delegate who is interested in implementing this method meaningfully in a bit of a conundrum:
WebKit does not convey the sender, so the delegate can't make the contractual
[sender convertAttributes:]
call.The
changeAttributes:
call is sent to a private WebKit class,WebHTMLView
, which cannot be subclassed to, e.g., customize the behavior ofchangeAttributes:
.The sender for the
changeAttributes:
call,NSFontEffectsBox
, is a private class and cannot be accessed e.g. as[NSFontEffectsBox sharedFontEffectsBox]
.
In short: there appears to be no way for a developer to meaningfully override the behavior of changeAttributes:
for a WebView
.
Any ideas?