WebView
supports, through WebEditingDelegate
a delegation mechanism for implementing custom behavior for the various actions that WebView
(or private WebHTMLView
) WebHTMLView
. When an action such as:
-(void)changeAttributes:(id)sender
received in WebHTMLView
, it is passed to the delegate method:
-(BOOL)webView:(WebView *)webView doCommandBySelector:(SEL)command
Unfortunately, the mechanism does not provide a 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 the sender
called by the receiver, for example, convertAttributes:
or convertFont:
In the case of changeFont
it turns out that a call to [[NSFontManager sharedFontManager] convertFont:]
is sufficient, since coincidentally this is what the sender is.
In the case of changeAttributes
, in particular when changing strikethrough, the sender may be the private class " NSFontEffectsBox
", which presumably corresponds to the subsection of the font panel, which is responsible for changing the crossed out / etc settings.
Unfortunately, calling [[NSFontManager sharedFontManager] convertAttributes:]
does NOT receive the expected attribute changes. This leaves the delegate who is interested in implementing this method largely in the hologram:
WebKit does not pass the sender, so the delegate cannot make the contract call [sender convertAttributes:]
.
The call to changeAttributes:
sent to the private WebKit class, WebHTMLView
, which cannot be subclassed, for example, to configure the behavior of changeAttributes:
The sender for calling changeAttributes:
NSFontEffectsBox
is a private class and cannot be accessed, for example. like [NSFontEffectsBox sharedFontEffectsBox]
.
In short: the developer does not make sense to significantly redefine the behavior of changeAttributes:
for WebView
.
Any ideas?
fonts cocoa webkit
danielpunkass
source share