Commit 32fd6197 authored by mjs@apple.com's avatar mjs@apple.com

2010-12-09 Maciej Stachowiak <mjs@apple.com>

        Reviewed by Dan Bernstein.

        Implement "Use Selection for Find" in WebKit2
        https://bugs.webkit.org/show_bug.cgi?id=50737
        <rdar://problem/8564881>

        Implement a TakeFindStringFromSelection editor command. This is
        used solely to implement the "Use Selection for Find" menu command
        on Mac, and is not made available to script. On WebKit2, it is
        very convenient to reuse the editing machinery since this command
        is very similar to Copy.

        * editing/Editor.h:
        * editing/EditorCommand.cpp:
        (WebCore::executeTakeFindStringFromSelection): Call to a mac-only Editor function.
        (WebCore::enabledTakeFindStringFromSelection): Check using Editor::canCopyExcludingStandaloneImage
        (WebCore::createCommandMap): Add "TakeFindStringFromSelection" command.
        * editing/mac/EditorMac.mm:
        (WebCore::Editor::canCopyExcludingStandaloneImages): Helper function; we can't use Editor::canCopy
        since it would make no sense to enable "Use Selection for Find" when viewing a standalone image
        document.
        (WebCore::Editor::takeFindStringFromSelection): Implement by copying the selected text
        to the special Find pasteboard.
2010-12-09  Maciej Stachowiak  <mjs@apple.com>

        Reviewed by Dan Bernstein.

        Implement "Use Selection for Find" in WebKit2
        https://bugs.webkit.org/show_bug.cgi?id=50737
        <rdar://problem/8564881>
        
        * UIProcess/API/mac/WKView.mm: Add support for the takeFindStringFromSelection:
        selector as a command.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent fd8e006e
2010-12-09 Maciej Stachowiak <mjs@apple.com>
Reviewed by Dan Bernstein.
Implement "Use Selection for Find" in WebKit2
https://bugs.webkit.org/show_bug.cgi?id=50737
<rdar://problem/8564881>
Implement a TakeFindStringFromSelection editor command. This is
used solely to implement the "Use Selection for Find" menu command
on Mac, and is not made available to script. On WebKit2, it is
very convenient to reuse the editing machinery since this command
is very similar to Copy.
* editing/Editor.h:
* editing/EditorCommand.cpp:
(WebCore::executeTakeFindStringFromSelection): Call to a mac-only Editor function.
(WebCore::enabledTakeFindStringFromSelection): Check using Editor::canCopyExcludingStandaloneImage
(WebCore::createCommandMap): Add "TakeFindStringFromSelection" command.
* editing/mac/EditorMac.mm:
(WebCore::Editor::canCopyExcludingStandaloneImages): Helper function; we can't use Editor::canCopy
since it would make no sense to enable "Use Selection for Find" when viewing a standalone image
document.
(WebCore::Editor::takeFindStringFromSelection): Implement by copying the selected text
to the special Find pasteboard.
2010-12-09 Abhishek Arya <inferno@chromium.org>
Reviewed by Dimitri Glazkov.
......
......@@ -364,6 +364,8 @@ public:
#if PLATFORM(MAC)
NSDictionary* fontAttributesForSelectionStart() const;
NSWritingDirection baseWritingDirectionForSelectionStart() const;
bool canCopyExcludingStandaloneImages();
void takeFindStringFromSelection();
#endif
bool selectionStartHasSpellingMarkerFor(int from, int length) const;
......
......@@ -1011,6 +1011,14 @@ static bool executeSwapWithMark(Frame* frame, Event*, EditorCommandSource, const
return true;
}
#if PLATFORM(MAC)
static bool executeTakeFindStringFromSelection(Frame* frame, Event*, EditorCommandSource, const String&)
{
frame->editor()->takeFindStringFromSelection();
return true;
}
#endif
static bool executeToggleBold(Frame* frame, Event*, EditorCommandSource source, const String&)
{
return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontWeight, "normal", "bold");
......@@ -1229,6 +1237,13 @@ static bool enabledRedo(Frame* frame, Event*, EditorCommandSource)
return frame->editor()->canRedo();
}
#if PLATFORM(MAC)
static bool enabledTakeFindStringFromSelection(Frame* frame, Event*, EditorCommandSource)
{
return frame->editor()->canCopyExcludingStandaloneImages();
}
#endif
static bool enabledUndo(Frame* frame, Event*, EditorCommandSource)
{
return frame->editor()->canUndo();
......@@ -1491,6 +1506,9 @@ static const CommandMap& createCommandMap()
{ "Subscript", { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "Superscript", { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "SwapWithMark", { executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
#if PLATFORM(MAC)
{ "TakeFindStringFromSelection", { executeTakeFindStringFromSelection, supportedFromMenuOrKeyBinding, enabledTakeFindStringFromSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
#endif
{ "ToggleBold", { executeToggleBold, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "ToggleItalic", { executeToggleItalic, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "ToggleUnderline", { executeUnderline, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
......
......@@ -37,6 +37,7 @@
#import "Pasteboard.h"
#import "RenderBlock.h"
#import "RuntimeApplicationChecks.h"
#import "Sound.h"
namespace WebCore {
......@@ -187,4 +188,24 @@ NSWritingDirection Editor::baseWritingDirectionForSelectionStart() const
return result;
}
bool Editor::canCopyExcludingStandaloneImages()
{
SelectionController* selection = m_frame->selection();
return selection->isRange() && !selection->isInPasswordField();
}
void Editor::takeFindStringFromSelection()
{
if (!canCopyExcludingStandaloneImages()) {
systemBeep();
return;
}
NSString *nsSelectedText = m_frame->displayStringModifiedByEncoding(selectedText());
NSPasteboard *findPasteboard = [NSPasteboard pasteboardWithName:NSFindPboard];
[findPasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[findPasteboard setString:nsSelectedText forType:NSStringPboardType];
}
} // namespace WebCore
2010-12-09 Maciej Stachowiak <mjs@apple.com>
Reviewed by Dan Bernstein.
Implement "Use Selection for Find" in WebKit2
https://bugs.webkit.org/show_bug.cgi?id=50737
<rdar://problem/8564881>
* UIProcess/API/mac/WKView.mm: Add support for the takeFindStringFromSelection:
selector as a command.
2010-12-09 Brady Eidson <beidson@apple.com>
Reviewed by Maciej Stachowiak.
......@@ -273,6 +273,7 @@ WEBCORE_COMMAND(paste)
WEBCORE_COMMAND(delete)
WEBCORE_COMMAND(pasteAsPlainText)
WEBCORE_COMMAND(selectAll)
WEBCORE_COMMAND(takeFindStringFromSelection)
#undef WEBCORE_COMMAND
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment