WebCore/ChangeLog

 12010-12-09 Maciej Stachowiak <mjs@apple.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Implement "Use Selection for Find" in WebKit2
 6 https://bugs.webkit.org/show_bug.cgi?id=50737
 7
 8 Implement a TakeFindStringFromSelection editor command. This is
 9 used solely to implement the "Use Selection for Find" menu command
 10 on Mac, and is not made available to script. On WebKit2, it is
 11 very convenient to reuse the editing machinery since this command
 12 is very similar to Copy.
 13
 14 * editing/Editor.h:
 15 * editing/EditorCommand.cpp:
 16 (WebCore::executeTakeFindStringFromSelection): Call to a mac-only Editor function.
 17 (WebCore::enabledTakeFindStringFromSelection): Check using Editor::canCopyExcludingStandaloneImage
 18 (WebCore::createCommandMap): Add "TakeFindStringFromSelection" command.
 19 * editing/mac/EditorMac.mm:
 20 (WebCore::Editor::canCopyExcludingStandaloneImages): Helper function; we can't use Editor::canCopy
 21 since it would make no sense to enable "Use Selection for Find" when viewing a standalone image
 22 document.
 23 (WebCore::Editor::takeFindStringFromSelection): Implement by copying the selected text
 24 to the special Find pasteboard.
 25
1262010-12-08 Erik Arvidsson <arv@chromium.org>
227
328 Reviewed by Darin Adler.
73596

WebCore/editing/Editor.h

@@public:
364364#if PLATFORM(MAC)
365365 NSDictionary* fontAttributesForSelectionStart() const;
366366 NSWritingDirection baseWritingDirectionForSelectionStart() const;
 367 bool canCopyExcludingStandaloneImages();
 368 void takeFindStringFromSelection();
367369#endif
368370
369371 bool selectionStartHasSpellingMarkerFor(int from, int length) const;
73583

WebCore/editing/EditorCommand.cpp

@@static bool executeSwapWithMark(Frame* f
10111011 return true;
10121012}
10131013
 1014#if PLATFORM(MAC)
 1015static bool executeTakeFindStringFromSelection(Frame* frame, Event*, EditorCommandSource, const String&)
 1016{
 1017 frame->editor()->takeFindStringFromSelection();
 1018 return true;
 1019}
 1020#endif
 1021
10141022static bool executeToggleBold(Frame* frame, Event*, EditorCommandSource source, const String&)
10151023{
10161024 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontWeight, "normal", "bold");

@@static bool enabledRedo(Frame* frame, Ev
12291237 return frame->editor()->canRedo();
12301238}
12311239
 1240#if PLATFORM(MAC)
 1241static bool enabledTakeFindStringFromSelection(Frame* frame, Event*, EditorCommandSource)
 1242{
 1243 return frame->editor()->canCopyExcludingStandaloneImages();
 1244}
 1245#endif
 1246
12321247static bool enabledUndo(Frame* frame, Event*, EditorCommandSource)
12331248{
12341249 return frame->editor()->canUndo();

@@static const CommandMap& createCommandMa
14911506 { "Subscript", { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
14921507 { "Superscript", { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
14931508 { "SwapWithMark", { executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
 1509#if PLATFORM(MAC)
 1510 { "TakeFindStringFromSelection", { executeTakeFindStringFromSelection, supportedFromMenuOrKeyBinding, enabledCopy, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
 1511#endif
14941512 { "ToggleBold", { executeToggleBold, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
14951513 { "ToggleItalic", { executeToggleItalic, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
14961514 { "ToggleUnderline", { executeUnderline, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
73583

WebCore/editing/mac/EditorMac.mm

3737#import "Pasteboard.h"
3838#import "RenderBlock.h"
3939#import "RuntimeApplicationChecks.h"
 40#import "Sound.h"
4041
4142namespace WebCore {
4243

@@NSWritingDirection Editor::baseWritingDi
187188 return result;
188189}
189190
 191bool Editor::canCopyExcludingStandaloneImages()
 192{
 193 SelectionController* selection = m_frame->selection();
 194 return selection->isRange() && !selection->isInPasswordField();
 195}
 196
 197void Editor::takeFindStringFromSelection()
 198{
 199 if (!canCopyExcludingStandaloneImages()) {
 200 systemBeep();
 201 return;
 202 }
 203
 204 NSString* nsSelectedText = m_frame->displayStringModifiedByEncoding(selectedText());
 205
 206 NSPasteboard *findPasteboard = [NSPasteboard pasteboardWithName:NSFindPboard];
 207 [findPasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
 208 [findPasteboard setString:nsSelectedText forType:NSStringPboardType];
 209}
 210
190211} // namespace WebCore
73583

WebKit2/ChangeLog

 12010-12-09 Maciej Stachowiak <mjs@apple.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Implement "Use Selection for Find" in WebKit2
 6 https://bugs.webkit.org/show_bug.cgi?id=50737
 7
 8 * UIProcess/API/mac/WKView.mm: Add support for the takeFindStringFromSelection:
 9 selector as a command.
 10
1112010-12-08 Sam Weinig <sam@webkit.org>
212
313 Reviewed by Geoffrey "Error" Garen.
73596

WebKit2/UIProcess/API/mac/WKView.mm

@@WEBCORE_COMMAND(paste)
273273WEBCORE_COMMAND(delete)
274274WEBCORE_COMMAND(pasteAsPlainText)
275275WEBCORE_COMMAND(selectAll)
 276WEBCORE_COMMAND(takeFindStringFromSelection)
276277
277278#undef WEBCORE_COMMAND
278279
73583