Commit aeeb7f1e authored by adele@apple.com's avatar adele@apple.com

Source/WebCore: Fix for <rdar://problem/9112694> REGRESSION (r79411): "Check...

Source/WebCore: Fix for <rdar://problem/9112694> REGRESSION (r79411): "Check grammar with spelling" context menu doesn't check as you type
https://bugs.webkit.org/show_bug.cgi?id=57173

Reviewed by Eric Seidel.

Test: editing/spelling/grammar.html

* WebCore.exp.in: Add symbol for new selectionStartHasMarkerFor method.
* editing/Editor.cpp:
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): Every use of paragraph is specific to spelling or grammar, 
 so to avoid confusion, we should explicitly use spellingParagraph or grammarParagraph.  In the case of this bug, 
 when we're consider ambiguous boundary characters (characters that could indicate word boundaries, but are used 
 in the middle of words too, like apostrophes), we should use the use the spellingParagraph since the spellingParagraph 
 is the only one operated on when this information is used.
 (WebCore::Editor::selectionStartHasMarkerFor): Changed from selectionStartHasSpellingMarkerFor so it can check for grammar as well as spelling.
* editing/Editor.h:

Source/WebKit/mac: Fix for <rdar://problem/9112694> REGRESSION (r79411): "Check grammar with spelling" context menu doesn't check as you type
https://bugs.webkit.org/show_bug.cgi?id=57173

Reviewed by Eric Seidel.

* WebView/WebFrame.mm:
(-[WebFrame hasSpellingMarker:length:]): Call new selectionStartHasMarkerFor method instead of selectionStartHasSpellingMarkerFor.
(-[WebFrame hasGrammarMarker:length:]): Call new selectionStartHasMarkerFor method.
* WebView/WebFramePrivate.h: Add hasGrammarMarker so grammar marking can be tested.

Tools: Testing support for <rdar://problem/9112694> REGRESSION (r79411): "Check grammar with spelling" context menu doesn't check as you type
https://bugs.webkit.org/show_bug.cgi?id=57173

Reviewed by Eric Seidel.

* DumpRenderTree/LayoutTestController.cpp:
(hasGrammarMarkerCallback): Added.
(LayoutTestController::staticFunctions): Added case for hasGrammarMarker.
* DumpRenderTree/LayoutTestController.h:
* DumpRenderTree/mac/DumpRenderTree.mm: (createWebViewAndOffscreenWindow): Call setGrammarCheckingEnabled.
* DumpRenderTree/mac/LayoutTestControllerMac.mm: (LayoutTestController::hasGrammarMarker): Added. Call new hasGrammarMarker method.

LayoutTests: Test for <rdar://problem/9112694> REGRESSION (r79411): "Check grammar with spelling" context menu doesn't check as you type
https://bugs.webkit.org/show_bug.cgi?id=57173

Reviewed by Eric Seidel.

* editing/spelling/grammar-expected.txt: Added.
* editing/spelling/grammar.html: Added.
* platform/gtk/Skipped:
* platform/mac-wk2/Skipped:
* platform/qt/Skipped:
* platform/win/Skipped:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@82159 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a8157865
2011-03-28 Adele Peterson <adele@apple.com>
Reviewed by Eric Seidel.
Test for <rdar://problem/9112694> REGRESSION (r79411): "Check grammar with spelling" context menu doesn't check as you type
https://bugs.webkit.org/show_bug.cgi?id=57173
* editing/spelling/grammar-expected.txt: Added.
* editing/spelling/grammar.html: Added.
* platform/gtk/Skipped:
* platform/mac-wk2/Skipped:
* platform/qt/Skipped:
* platform/win/Skipped:
2011-03-28 Dan Bernstein <mitz@apple.com>
Reviewed by Darin Adler.
......
You should see the text 'I have a issue'. 'a' should have a grammar suggestion marking.
PASS
<html>
<head>
<style>
.editing {
border: 2px solid red;
padding: 12px;
font-size: 24px;
}
</style>
<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
<script>
function log(msg) {
document.getElementById("console").innerHTML += (msg + "\n");
}
function editingTest() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
document.getElementById("root").focus();
document.execCommand("InsertText", false, "I have a issue.");
if (window.layoutTestController) {
if (layoutTestController.hasGrammarMarker(7, 1))
log("PASS");
else
log("FAIL");
document.getElementById("root").style.display = "none";
}
}
</script>
<title>Editing Test</title>
</head>
<body>
<div>You should see the text 'I have a issue'. 'a' should have a grammar suggestion marking.</div>
<div contenteditable id="root" class="editing">
</div>
<pre id="console"></pre>
<script>
editingTest();
</script>
</body>
</html>
......@@ -1347,6 +1347,9 @@ http/tests/inspector/network/network-size.html
# window.clientWidth and window.clientHeight do not include scrollbar allocation
fast/overflow/horizontal-scroll-after-back.html
# textInputController.hasGrammarMarker() is not implemented.
editing/spelling/grammar.html
# https://bugs.webkit.org/show_bug.cgi?id=57160
# [GTK] layoutTestController.overridePreference("WebKitDefaultFontSize"...) does not take into account screen DPI
fast/harness/override-preferences-2.html
......@@ -1889,6 +1889,9 @@ editing/spelling/spelling-attribute-change.html
editing/spelling/spelling-linebreak.html
editing/spelling/spelling-hasspellingmarker.html
# WebKitTestRunner needs layoutTestController.hasGrammarMarker
editing/spelling/grammar.html
# WebKitTestRunner needs layoutTestController.nodesFromRect
fast/dom/nodesFromRect-basic.html
fast/dom/nodesFromRect-inner-documents.html
......
......@@ -1268,6 +1268,9 @@ editing/input/setting-input-value-cancel-ime-composition.html
# textInputController.hasSpellingMarkers() is not implemented.
editing/spelling/spelling-hasspellingmarker.html
# textInputController.hasGrammarMarkers() is not implemented.
editing/spelling/grammar.html
# https://bugs.webkit.org/show_bug.cgi?id=45435
editing/spelling/spelling-backspace-between-lines.html
......
......@@ -970,6 +970,9 @@ fast/text/international/thai-cursor-position.html
fast/dom/tab-in-right-alignment.html
svg/text/caret-in-svg-text.xhtml
# textInputController.hasGrammarMarkers() is not implemented.
editing/spelling/grammar.html
# EditorClient::requestCheckingOfString() is not implemented
editing/spelling/spellcheck-paste.html
......
2011-03-28 Adele Peterson <adele@apple.com>
Reviewed by Eric Seidel.
Fix for <rdar://problem/9112694> REGRESSION (r79411): "Check grammar with spelling" context menu doesn't check as you type
https://bugs.webkit.org/show_bug.cgi?id=57173
Test: editing/spelling/grammar.html
* WebCore.exp.in: Add symbol for new selectionStartHasMarkerFor method.
* editing/Editor.cpp:
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): Every use of paragraph is specific to spelling or grammar,
so to avoid confusion, we should explicitly use spellingParagraph or grammarParagraph. In the case of this bug,
when we're consider ambiguous boundary characters (characters that could indicate word boundaries, but are used
in the middle of words too, like apostrophes), we should use the use the spellingParagraph since the spellingParagraph
is the only one operated on when this information is used.
(WebCore::Editor::selectionStartHasMarkerFor): Changed from selectionStartHasSpellingMarkerFor so it can check for grammar as well as spelling.
* editing/Editor.h:
2011-03-28 Dan Bernstein <mitz@apple.com>
Reviewed by Darin Adler.
......@@ -1218,7 +1218,7 @@ __ZNK7WebCore6Editor17shouldDeleteRangeEPNS_5RangeE
__ZNK7WebCore6Editor23getCompositionSelectionERjS1_
__ZNK7WebCore6Editor30applyEditingStyleToBodyElementEv
__ZNK7WebCore6Editor31fontAttributesForSelectionStartEv
__ZNK7WebCore6Editor34selectionStartHasSpellingMarkerForEii
__ZNK7WebCore6Editor26selectionStartHasMarkerForENS_14DocumentMarker10MarkerTypeEii
__ZNK7WebCore6Editor37baseWritingDirectionForSelectionStartEv
__ZNK7WebCore6Editor6canCutEv
__ZNK7WebCore6Editor7Command11isSupportedEv
......
......@@ -2239,7 +2239,6 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
TextCheckingParagraph spellingParagraph(spellingRange);
TextCheckingParagraph grammarParagraph(shouldMarkGrammar ? grammarRange : 0);
TextCheckingParagraph& paragraph = shouldMarkGrammar ? grammarParagraph : spellingParagraph;
if (shouldMarkGrammar ? (spellingParagraph.isRangeEmpty() && grammarParagraph.isEmpty()) : spellingParagraph.isEmpty())
return;
......@@ -2248,13 +2247,13 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
if (m_frame->selection()->selectionType() == VisibleSelection::CaretSelection) {
// Attempt to save the caret position so we can restore it later if needed
Position caretPosition = m_frame->selection()->end();
int offset = paragraph.offsetTo(caretPosition, ec);
int offset = spellingParagraph.offsetTo(caretPosition, ec);
if (!ec) {
selectionOffset = offset;
restoreSelectionAfterChange = true;
if (selectionOffset > 0 && (selectionOffset > paragraph.textLength() || paragraph.textCharAt(selectionOffset - 1) == newlineCharacter))
if (selectionOffset > 0 && (selectionOffset > spellingParagraph.textLength() || spellingParagraph.textCharAt(selectionOffset - 1) == newlineCharacter))
adjustSelectionForParagraphBoundaries = true;
if (selectionOffset > 0 && selectionOffset <= paragraph.textLength() && isAmbiguousBoundaryCharacter(paragraph.textCharAt(selectionOffset - 1)))
if (selectionOffset > 0 && selectionOffset <= spellingParagraph.textLength() && isAmbiguousBoundaryCharacter(spellingParagraph.textCharAt(selectionOffset - 1)))
ambiguousBoundaryOffset = selectionOffset - 1;
}
}
......@@ -2282,7 +2281,11 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
checkingTypes |= TextCheckingTypeCorrection;
#endif
}
textChecker()->checkTextOfParagraph(paragraph.textCharacters(), paragraph.textLength(), checkingTypes, results);
if (shouldMarkGrammar)
textChecker()->checkTextOfParagraph(grammarParagraph.textCharacters(), grammarParagraph.textLength(), checkingTypes, results);
else
textChecker()->checkTextOfParagraph(spellingParagraph.textCharacters(), spellingParagraph.textLength(), checkingTypes, results);
#if SUPPORT_AUTOCORRECTION_PANEL
// If this checking is only for showing correction panel, we shouldn't bother to mark misspellings.
......@@ -2341,7 +2344,7 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
// 2. The result doesn't end at an ambiguous boundary.
// (FIXME: this is required until 6853027 is fixed and text checking can do this for us
bool doReplacement = replacementLength > 0 && !resultEndsAtAmbiguousBoundary;
RefPtr<Range> rangeToReplace = paragraph.subrange(resultLocation, resultLength);
RefPtr<Range> rangeToReplace = spellingParagraph.subrange(resultLocation, resultLength);
VisibleSelection selectionToReplace(rangeToReplace.get(), DOWNSTREAM);
// adding links should be done only immediately after they are typed
......@@ -2426,7 +2429,7 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
if (result->type == TextCheckingTypeCorrection) {
// Add a marker so that corrections can easily be undone and won't be re-corrected.
RefPtr<Range> replacedRange = paragraph.subrange(resultLocation, replacementLength);
RefPtr<Range> replacedRange = spellingParagraph.subrange(resultLocation, replacementLength);
replacedRange->startContainer()->document()->markers()->addMarker(replacedRange.get(), DocumentMarker::Replacement, replacedString);
replacedRange->startContainer()->document()->markers()->addMarker(replacedRange.get(), DocumentMarker::CorrectionIndicator);
replacedRange->startContainer()->document()->markers()->addMarker(replacedRange.get(), DocumentMarker::SpellCheckingExemption);
......@@ -2437,9 +2440,9 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
if (selectionChanged) {
// Restore the caret position if we have made any replacements
paragraph.expandRangeToNextEnd();
if (restoreSelectionAfterChange && selectionOffset >= 0 && selectionOffset <= paragraph.rangeLength()) {
RefPtr<Range> selectionRange = paragraph.subrange(0, selectionOffset);
spellingParagraph.expandRangeToNextEnd();
if (restoreSelectionAfterChange && selectionOffset >= 0 && selectionOffset <= spellingParagraph.rangeLength()) {
RefPtr<Range> selectionRange = spellingParagraph.subrange(0, selectionOffset);
m_frame->selection()->moveTo(selectionRange->endPosition(), DOWNSTREAM);
if (adjustSelectionForParagraphBoundaries)
m_frame->selection()->modify(SelectionController::AlterationMove, DirectionForward, CharacterGranularity);
......@@ -3572,7 +3575,7 @@ static Node* findFirstMarkable(Node* node)
return 0;
}
bool Editor::selectionStartHasSpellingMarkerFor(int from, int length) const
bool Editor::selectionStartHasMarkerFor(DocumentMarker::MarkerType markerType, int from, int length) const
{
Node* node = findFirstMarkable(m_frame->selection()->start().deprecatedNode());
if (!node)
......@@ -3583,7 +3586,7 @@ bool Editor::selectionStartHasSpellingMarkerFor(int from, int length) const
Vector<DocumentMarker> markers = m_frame->document()->markers()->markersForNode(node);
for (size_t i = 0; i < markers.size(); ++i) {
DocumentMarker marker = markers[i];
if (marker.startOffset <= startOffset && endOffset <= marker.endOffset && marker.type == DocumentMarker::Spelling)
if (marker.startOffset <= startOffset && endOffset <= marker.endOffset && marker.type == markerType)
return true;
}
......
......@@ -380,7 +380,7 @@ public:
void readSelectionFromPasteboard(const String& pasteboardName);
#endif
bool selectionStartHasSpellingMarkerFor(int from, int length) const;
bool selectionStartHasMarkerFor(DocumentMarker::MarkerType, int from, int length) const;
void removeSpellAndCorrectionMarkersFromWordsToBeEdited(bool doNotRemoveIfSelectionAtWordBoundary);
private:
......
2011-03-28 Adele Peterson <adele@apple.com>
Reviewed by Eric Seidel.
Fix for <rdar://problem/9112694> REGRESSION (r79411): "Check grammar with spelling" context menu doesn't check as you type
https://bugs.webkit.org/show_bug.cgi?id=57173
* WebView/WebFrame.mm:
(-[WebFrame hasSpellingMarker:length:]): Call new selectionStartHasMarkerFor method instead of selectionStartHasSpellingMarkerFor.
(-[WebFrame hasGrammarMarker:length:]): Call new selectionStartHasMarkerFor method.
* WebView/WebFramePrivate.h: Add hasGrammarMarker so grammar marking can be tested.
2011-03-28 Alexey Proskuryakov <ap@apple.com>
Reviewed by Darin Adler.
......
......@@ -1310,10 +1310,18 @@ static inline WebDataSource *dataSource(DocumentLoader* loader)
- (BOOL)hasSpellingMarker:(int)from length:(int)length
{
Frame* coreFrame = _private->coreFrame;
Frame* coreFrame = core(self);
if (!coreFrame)
return NO;
return coreFrame->editor()->selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
}
- (BOOL)hasGrammarMarker:(int)from length:(int)length
{
Frame* coreFrame = core(self);
if (!coreFrame)
return NO;
return coreFrame->editor()->selectionStartHasSpellingMarkerFor(from, length);
return coreFrame->editor()->selectionStartHasMarkerFor(DocumentMarker::Grammar, from, length);
}
- (id)accessibilityRoot
......
......@@ -143,6 +143,8 @@ typedef enum {
// Returns whether there is a spelling marker in the specified range of the focused node.
- (BOOL)hasSpellingMarker:(int)location length:(int)length;
- (BOOL)hasGrammarMarker:(int)from length:(int)length;
// The top of the accessibility tree.
- (id)accessibilityRoot;
......
2011-03-28 Adele Peterson <adele@apple.com>
Reviewed by Eric Seidel.
Testing support for <rdar://problem/9112694> REGRESSION (r79411): "Check grammar with spelling" context menu doesn't check as you type
https://bugs.webkit.org/show_bug.cgi?id=57173
* DumpRenderTree/LayoutTestController.cpp:
(hasGrammarMarkerCallback): Added.
(LayoutTestController::staticFunctions): Added case for hasGrammarMarker.
* DumpRenderTree/LayoutTestController.h:
* DumpRenderTree/mac/DumpRenderTree.mm: (createWebViewAndOffscreenWindow): Call setGrammarCheckingEnabled.
* DumpRenderTree/mac/LayoutTestControllerMac.mm: (LayoutTestController::hasGrammarMarker): Added. Call new hasGrammarMarker method.
2011-03-28 Csaba Osztrogonác <ossy@webkit.org>
Reviewed by Benjamin Poulain.
......
......@@ -1963,6 +1963,19 @@ static JSValueRef hasSpellingMarkerCallback(JSContextRef context, JSObjectRef fu
return JSValueMakeBoolean(context, ok);
}
static JSValueRef hasGrammarMarkerCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount != 2)
return JSValueMakeUndefined(context);
int from = JSValueToNumber(context, arguments[0], 0);
int length = JSValueToNumber(context, arguments[1], 0);
LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
bool ok = controller->hasGrammarMarker(from, length);
return JSValueMakeBoolean(context, ok);
}
static JSValueRef markerTextForListItemCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
......@@ -2163,6 +2176,7 @@ JSStaticFunction* LayoutTestController::staticFunctions()
{ "originsWithApplicationCache", originsWithApplicationCacheCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "grantDesktopNotificationPermission", grantDesktopNotificationPermissionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "hasSpellingMarker", hasSpellingMarkerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "hasGrammarMarker", hasGrammarMarkerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "isCommandEnabled", isCommandEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "isPageBoxVisible", isPageBoxVisibleCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "keepWebHistory", keepWebHistoryCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
......
......@@ -295,6 +295,7 @@ public:
void abortModal();
bool hasSpellingMarker(int from, int length);
bool hasGrammarMarker(int from, int length);
void dumpConfigurationForViewport(int deviceDPI, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight);
......
......@@ -306,6 +306,7 @@ WebView *createWebViewAndOffscreenWindow()
[WebView registerURLSchemeAsLocal:@"feedsearch"];
[webView setContinuousSpellCheckingEnabled:YES];
[webView setGrammarCheckingEnabled:YES];
// To make things like certain NSViews, dragging, and plug-ins work, put the WebView a window, but put it off-screen so you don't see it.
// Put it at -10000, -10000 in "flipped coordinates", since WebCore and the DOM use flipped coordinates.
......
......@@ -1077,6 +1077,12 @@ bool LayoutTestController::hasSpellingMarker(int from, int length)
{
return [mainFrame hasSpellingMarker:from length:length];
}
bool LayoutTestController::hasGrammarMarker(int from, int length)
{
return [mainFrame hasGrammarMarker:from length:length];
}
void LayoutTestController::dumpConfigurationForViewport(int /*deviceDPI*/, int /*deviceWidth*/, int /*deviceHeight*/, int /*availableWidth*/, int /*availableHeight*/)
{
......
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