The app:
I have a Mac app in the Mac App Store with an embedded WebView
. The WebView contains a contenteditable
DIV acting as a rich text editor.
Goal:
I'd like to change the foreground and background color of the selected text inside the WebView via the NSColorWell
→ NSColorPanel
mechanism.
Problem:
When I click on a color in the NSColorPanel
, NSColorPanel
automatically invokes changeColor:
on the first responder.
The first responder happens to be a private WebKit class representing my contenteditable DIV: WebHTMLView
.
The above mechanism ALWAYS changes the foreground color of the selected text. I need a way to decide if the foreground OR background color should be changed.
Ideal solution:
It would be great if NSColorPanel
and NSColorWell
could be configured to not automatically call changeColor:
on the first responder and let my code handle the color change.
Tried and failed:
- Setting
usesFontPanel = false
is not an option, because it is aWebView
, not aNSTextView
- Tried solutions suggested here: NSButton subclass as colorwell & preventing NSColorPanel from touching the first responder
- Subclassing WebView doesn't help, first responder is a private WebKit class
- Temporarily switching first responder results in flickering (not acceptable)
- App must be Mac App Store compatible
To intercept
changeColor:
, seteditingDelegate
of the web view and implementWebEditingDelegate
methodwebView:doCommandBySelector:
.for example: