40a84310396de782fd111ba1686aa4d7f6e6343c
[WebKit-https.git] / WebCore / editing / Editor.cpp
1 /*
2  * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3  * Copyright (C) 2007 Trolltech ASA
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
25  */
26
27 #include "config.h"
28 #include "Editor.h"
29
30 #include "AXObjectCache.h"
31 #include "ApplyStyleCommand.h"
32 #include "CSSComputedStyleDeclaration.h"
33 #include "CSSProperty.h"
34 #include "CSSPropertyNames.h"
35 #include "ClipboardEvent.h"
36 #include "DeleteButtonController.h"
37 #include "DeleteSelectionCommand.h"
38 #include "DocLoader.h"
39 #include "DocumentFragment.h"
40 #include "EditorClient.h"
41 #include "EventHandler.h"
42 #include "EventNames.h"
43 #include "FocusController.h"
44 #include "Frame.h"
45 #include "FrameView.h"
46 #include "HTMLInputElement.h"
47 #include "HTMLTextAreaElement.h"
48 #include "HitTestResult.h"
49 #include "IndentOutdentCommand.h"
50 #include "InsertListCommand.h"
51 #include "KeyboardEvent.h"
52 #include "ModifySelectionListLevel.h"
53 #include "Page.h"
54 #include "Pasteboard.h"
55 #include "RemoveFormatCommand.h"
56 #include "ReplaceSelectionCommand.h"
57 #include "Sound.h"
58 #include "Text.h"
59 #include "TextIterator.h"
60 #include "TypingCommand.h"
61 #include "htmlediting.h"
62 #include "markup.h"
63 #include "visible_units.h"
64
65 namespace WebCore {
66
67 using namespace std;
68 using namespace EventNames;
69 using namespace HTMLNames;
70
71 // When an event handler has moved the selection outside of a text control
72 // we should use the target control's selection for this editing operation.
73 Selection Editor::selectionForCommand(Event* event)
74 {
75     Selection selection = m_frame->selection()->selection();
76     if (!event)
77         return selection;
78     // If the target is a text control, and the current selection is outside of its shadow tree,
79     // then use the saved selection for that text control.
80     Node* target = event->target()->toNode();
81     Node* selectionStart = selection.start().node();
82     if (target && (!selectionStart || target->shadowAncestorNode() != selectionStart->shadowAncestorNode())) {
83         if (target->hasTagName(inputTag) && static_cast<HTMLInputElement*>(target)->isTextField())
84             return static_cast<HTMLInputElement*>(target)->selection();
85         if (target->hasTagName(textareaTag))
86             return static_cast<HTMLTextAreaElement*>(target)->selection();
87     }
88     return selection;
89 }
90
91 EditorClient* Editor::client() const
92 {
93     if (Page* page = m_frame->page())
94         return page->editorClient();
95     return 0;
96 }
97
98 void Editor::handleKeyboardEvent(KeyboardEvent* event)
99 {
100     if (EditorClient* c = client())
101         if (selectionForCommand(event).isContentEditable())
102             c->handleKeyboardEvent(event);
103 }
104
105 void Editor::handleInputMethodKeydown(KeyboardEvent* event)
106 {
107     if (EditorClient* c = client())
108         if (selectionForCommand(event).isContentEditable())
109             c->handleInputMethodKeydown(event);
110 }
111
112 bool Editor::canEdit() const
113 {
114     return m_frame->selection()->isContentEditable();
115 }
116
117 bool Editor::canEditRichly() const
118 {
119     return m_frame->selection()->isContentRichlyEditable();
120 }
121
122 // WinIE uses onbeforecut and onbeforepaste to enables the cut and paste menu items.  They
123 // also send onbeforecopy, apparently for symmetry, but it doesn't affect the menu items.
124 // We need to use onbeforecopy as a real menu enabler because we allow elements that are not
125 // normally selectable to implement copy/paste (like divs, or a document body).
126
127 bool Editor::canDHTMLCut()
128 {
129     return !m_frame->selection()->isInPasswordField() && !dispatchCPPEvent(beforecutEvent, ClipboardNumb);
130 }
131
132 bool Editor::canDHTMLCopy()
133 {
134     return !m_frame->selection()->isInPasswordField() && !dispatchCPPEvent(beforecopyEvent, ClipboardNumb);
135 }
136
137 bool Editor::canDHTMLPaste()
138 {
139     return !dispatchCPPEvent(beforepasteEvent, ClipboardNumb);
140 }
141
142 bool Editor::canCut() const
143 {
144     return canCopy() && canDelete();
145 }
146
147 static HTMLImageElement* imageElementFromImageDocument(Document* document)
148 {
149     if (!document)
150         return 0;
151     if (!document->isImageDocument())
152         return 0;
153     
154     HTMLElement* body = document->body();
155     if (!body)
156         return 0;
157     
158     Node* node = body->firstChild();
159     if (!node)
160         return 0;    
161     if (!node->hasTagName(imgTag))
162         return 0;
163     return static_cast<HTMLImageElement*>(node);
164 }
165
166 bool Editor::canCopy() const
167 {
168     if (imageElementFromImageDocument(m_frame->document()))
169         return true;
170     SelectionController* selection = m_frame->selection();
171     return selection->isRange() && !selection->isInPasswordField();
172 }
173
174 bool Editor::canPaste() const
175 {
176     return canEdit();
177 }
178
179 bool Editor::canDelete() const
180 {
181     SelectionController* selection = m_frame->selection();
182     return selection->isRange() && selection->isContentEditable();
183 }
184
185 bool Editor::canDeleteRange(Range* range) const
186 {
187     ExceptionCode ec = 0;
188     Node* startContainer = range->startContainer(ec);
189     Node* endContainer = range->endContainer(ec);
190     if (!startContainer || !endContainer)
191         return false;
192     
193     if (!startContainer->isContentEditable() || !endContainer->isContentEditable())
194         return false;
195     
196     if (range->collapsed(ec)) {
197         VisiblePosition start(startContainer, range->startOffset(ec), DOWNSTREAM);
198         VisiblePosition previous = start.previous();
199         // FIXME: We sometimes allow deletions at the start of editable roots, like when the caret is in an empty list item.
200         if (previous.isNull() || previous.deepEquivalent().node()->rootEditableElement() != startContainer->rootEditableElement())
201             return false;
202     }
203     return true;
204 }
205
206 bool Editor::smartInsertDeleteEnabled()
207 {   
208     return client() && client()->smartInsertDeleteEnabled();
209 }
210     
211 bool Editor::canSmartCopyOrDelete()
212 {
213     return client() && client()->smartInsertDeleteEnabled() && m_frame->selectionGranularity() == WordGranularity;
214 }
215
216 bool Editor::deleteWithDirection(SelectionController::EDirection direction, TextGranularity granularity, bool killRing, bool isTypingAction)
217 {
218     // Delete the selection, if there is one.
219     // If not, make a selection using the passed-in direction and granularity.
220
221     if (!canEdit())
222         return false;
223
224     if (m_frame->selection()->isRange()) {
225         if (killRing)
226             addToKillRing(selectedRange().get(), false);
227         if (isTypingAction) {
228             if (m_frame->document()) {
229                 TypingCommand::deleteKeyPressed(m_frame->document(), canSmartCopyOrDelete(), granularity);
230                 revealSelectionAfterEditingOperation();
231             }
232         } else {
233             deleteSelectionWithSmartDelete(canSmartCopyOrDelete());
234             // Implicitly calls revealSelectionAfterEditingOperation().
235         }
236     } else {
237         SelectionController selectionToDelete;
238         selectionToDelete.setSelection(m_frame->selection()->selection());
239         selectionToDelete.modify(SelectionController::EXTEND, direction, granularity);
240         if (killRing && selectionToDelete.isCaret() && granularity != CharacterGranularity)
241             selectionToDelete.modify(SelectionController::EXTEND, direction, CharacterGranularity);
242
243         RefPtr<Range> range = selectionToDelete.toRange();
244
245         if (killRing)
246             addToKillRing(range.get(), false);
247
248         if (!m_frame->selection()->setSelectedRange(range.get(), DOWNSTREAM, (granularity != CharacterGranularity)))
249             return true;
250
251         switch (direction) {
252             case SelectionController::FORWARD:
253             case SelectionController::RIGHT:
254                 if (m_frame->document())
255                     TypingCommand::forwardDeleteKeyPressed(m_frame->document(), false, granularity);
256                 break;
257             case SelectionController::BACKWARD:
258             case SelectionController::LEFT:
259                 if (m_frame->document())
260                     TypingCommand::deleteKeyPressed(m_frame->document(), false, granularity);
261                 break;
262         }
263         revealSelectionAfterEditingOperation();
264     }
265
266     // clear the "start new kill ring sequence" setting, because it was set to true
267     // when the selection was updated by deleting the range
268     if (killRing)
269         setStartNewKillRingSequence(false);
270
271     return true;
272 }
273
274 void Editor::deleteSelectionWithSmartDelete(bool smartDelete)
275 {
276     if (m_frame->selection()->isNone())
277         return;
278     
279     applyCommand(DeleteSelectionCommand::create(m_frame->document(), smartDelete));
280 }
281
282 void Editor::pasteAsPlainTextWithPasteboard(Pasteboard* pasteboard)
283 {
284     String text = pasteboard->plainText(m_frame);
285     if (client() && client()->shouldInsertText(text, selectedRange().get(), EditorInsertActionPasted))
286         replaceSelectionWithText(text, false, canSmartReplaceWithPasteboard(pasteboard));
287 }
288
289 void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText)
290 {
291     RefPtr<Range> range = selectedRange();
292     bool chosePlainText;
293     RefPtr<DocumentFragment> fragment = pasteboard->documentFragment(m_frame, range, allowPlainText, chosePlainText);
294     if (fragment && shouldInsertFragment(fragment, range, EditorInsertActionPasted))
295         replaceSelectionWithFragment(fragment, false, canSmartReplaceWithPasteboard(pasteboard), chosePlainText);
296 }
297
298 bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard)
299 {
300     return client() && client()->smartInsertDeleteEnabled() && pasteboard->canSmartReplace();
301 }
302
303 bool Editor::shouldInsertFragment(PassRefPtr<DocumentFragment> fragment, PassRefPtr<Range> replacingDOMRange, EditorInsertAction givenAction)
304 {
305     if (!client())
306         return false;
307         
308     Node* child = fragment->firstChild();
309     if (child && fragment->lastChild() == child && child->isCharacterDataNode())
310         return client()->shouldInsertText(static_cast<CharacterData*>(child)->data(), replacingDOMRange.get(), givenAction);
311
312     return client()->shouldInsertNode(fragment.get(), replacingDOMRange.get(), givenAction);
313 }
314
315 void Editor::replaceSelectionWithFragment(PassRefPtr<DocumentFragment> fragment, bool selectReplacement, bool smartReplace, bool matchStyle)
316 {
317     if (m_frame->selection()->isNone() || !fragment)
318         return;
319     
320     applyCommand(ReplaceSelectionCommand::create(m_frame->document(), fragment, selectReplacement, smartReplace, matchStyle));
321     revealSelectionAfterEditingOperation();
322 }
323
324 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement, bool smartReplace)
325 {
326     replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), text), selectReplacement, smartReplace, true); 
327 }
328
329 PassRefPtr<Range> Editor::selectedRange()
330 {
331     if (!m_frame)
332         return 0;
333     return m_frame->selection()->toRange();
334 }
335
336 bool Editor::shouldDeleteRange(Range* range) const
337 {
338     ExceptionCode ec;
339     if (!range || range->collapsed(ec))
340         return false;
341     
342     if (!canDeleteRange(range))
343         return false;
344
345     return client() && client()->shouldDeleteRange(range);
346 }
347
348 bool Editor::tryDHTMLCopy()
349 {   
350     if (m_frame->selection()->isInPasswordField())
351         return false;
352
353     // Must be done before oncopy adds types and data to the pboard,
354     // also done for security, as it erases data from the last copy/paste.
355     Pasteboard::generalPasteboard()->clear();
356
357     return !dispatchCPPEvent(copyEvent, ClipboardWritable);
358 }
359
360 bool Editor::tryDHTMLCut()
361 {
362     if (m_frame->selection()->isInPasswordField())
363         return false;
364
365     // Must be done before oncut adds types and data to the pboard,
366     // also done for security, as it erases data from the last copy/paste.
367     Pasteboard::generalPasteboard()->clear();
368
369     return !dispatchCPPEvent(cutEvent, ClipboardWritable);
370 }
371
372 bool Editor::tryDHTMLPaste()
373 {
374     return !dispatchCPPEvent(pasteEvent, ClipboardReadable);
375 }
376
377 void Editor::writeSelectionToPasteboard(Pasteboard* pasteboard)
378 {
379     pasteboard->writeSelection(selectedRange().get(), canSmartCopyOrDelete(), m_frame);
380 }
381
382 bool Editor::shouldInsertText(const String& text, Range* range, EditorInsertAction action) const
383 {
384     return client() && client()->shouldInsertText(text, range, action);
385 }
386
387 bool Editor::shouldShowDeleteInterface(HTMLElement* element) const
388 {
389     return client() && client()->shouldShowDeleteInterface(element);
390 }
391
392 void Editor::respondToChangedSelection(const Selection& oldSelection)
393 {
394     if (client())
395         client()->respondToChangedSelection();
396     m_deleteButtonController->respondToChangedSelection(oldSelection);
397 }
398
399 void Editor::respondToChangedContents(const Selection& endingSelection)
400 {
401     if (AXObjectCache::accessibilityEnabled()) {
402         Node* node = endingSelection.start().node();
403         if (node)
404             m_frame->document()->axObjectCache()->postNotification(node->renderer(), "AXValueChanged");
405     }
406     
407     if (client())
408         client()->respondToChangedContents();  
409 }
410
411 const SimpleFontData* Editor::fontForSelection(bool& hasMultipleFonts) const
412 {
413 #if !PLATFORM(QT)
414     hasMultipleFonts = false;
415
416     if (!m_frame->selection()->isRange()) {
417         Node* nodeToRemove;
418         RenderStyle* style = m_frame->styleForSelectionStart(nodeToRemove); // sets nodeToRemove
419
420         const SimpleFontData* result = 0;
421         if (style)
422             result = style->font().primaryFont();
423         
424         if (nodeToRemove) {
425             ExceptionCode ec;
426             nodeToRemove->remove(ec);
427             ASSERT(ec == 0);
428         }
429
430         return result;
431     }
432
433     const SimpleFontData* font = 0;
434
435     RefPtr<Range> range = m_frame->selection()->toRange();
436     Node* startNode = range->editingStartPosition().node();
437     if (startNode) {
438         Node* pastEnd = range->pastLastNode();
439         // In the loop below, n should eventually match pastEnd and not become nil, but we've seen at least one
440         // unreproducible case where this didn't happen, so check for nil also.
441         for (Node* n = startNode; n && n != pastEnd; n = n->traverseNextNode()) {
442             RenderObject *renderer = n->renderer();
443             if (!renderer)
444                 continue;
445             // FIXME: Are there any node types that have renderers, but that we should be skipping?
446             const SimpleFontData* f = renderer->style()->font().primaryFont();
447             if (!font)
448                 font = f;
449             else if (font != f) {
450                 hasMultipleFonts = true;
451                 break;
452             }
453         }
454     }
455
456     return font;
457 #else
458     return 0;
459 #endif
460 }
461
462 TriState Editor::selectionUnorderedListState() const
463 {
464     if (m_frame->selection()->isCaret()) {
465         if (enclosingNodeWithTag(m_frame->selection()->selection().start(), ulTag))
466             return TrueTriState;
467     } else if (m_frame->selection()->isRange()) {
468         Node* startNode = enclosingNodeWithTag(m_frame->selection()->selection().start(), ulTag);
469         Node* endNode = enclosingNodeWithTag(m_frame->selection()->selection().end(), ulTag);
470         if (startNode && endNode && startNode == endNode)
471             return TrueTriState;
472     }
473
474     return FalseTriState;
475 }
476
477 TriState Editor::selectionOrderedListState() const
478 {
479     if (m_frame->selection()->isCaret()) {
480         if (enclosingNodeWithTag(m_frame->selection()->selection().start(), olTag))
481             return TrueTriState;
482     } else if (m_frame->selection()->isRange()) {
483         Node* startNode = enclosingNodeWithTag(m_frame->selection()->selection().start(), olTag);
484         Node* endNode = enclosingNodeWithTag(m_frame->selection()->selection().end(), olTag);
485         if (startNode && endNode && startNode == endNode)
486             return TrueTriState;
487     }
488
489     return FalseTriState;
490 }
491
492 PassRefPtr<Node> Editor::insertOrderedList()
493 {
494     if (!canEditRichly())
495         return 0;
496         
497     RefPtr<Node> newList = InsertListCommand::insertList(m_frame->document(), InsertListCommand::OrderedList);
498     revealSelectionAfterEditingOperation();
499     return newList;
500 }
501
502 PassRefPtr<Node> Editor::insertUnorderedList()
503 {
504     if (!canEditRichly())
505         return 0;
506         
507     RefPtr<Node> newList = InsertListCommand::insertList(m_frame->document(), InsertListCommand::UnorderedList);
508     revealSelectionAfterEditingOperation();
509     return newList;
510 }
511
512 bool Editor::canIncreaseSelectionListLevel()
513 {
514     return canEditRichly() && IncreaseSelectionListLevelCommand::canIncreaseSelectionListLevel(m_frame->document());
515 }
516
517 bool Editor::canDecreaseSelectionListLevel()
518 {
519     return canEditRichly() && DecreaseSelectionListLevelCommand::canDecreaseSelectionListLevel(m_frame->document());
520 }
521
522 PassRefPtr<Node> Editor::increaseSelectionListLevel()
523 {
524     if (!canEditRichly() || m_frame->selection()->isNone())
525         return 0;
526     
527     RefPtr<Node> newList = IncreaseSelectionListLevelCommand::increaseSelectionListLevel(m_frame->document());
528     revealSelectionAfterEditingOperation();
529     return newList;
530 }
531
532 PassRefPtr<Node> Editor::increaseSelectionListLevelOrdered()
533 {
534     if (!canEditRichly() || m_frame->selection()->isNone())
535         return 0;
536     
537     PassRefPtr<Node> newList = IncreaseSelectionListLevelCommand::increaseSelectionListLevelOrdered(m_frame->document());
538     revealSelectionAfterEditingOperation();
539     return newList;
540 }
541
542 PassRefPtr<Node> Editor::increaseSelectionListLevelUnordered()
543 {
544     if (!canEditRichly() || m_frame->selection()->isNone())
545         return 0;
546     
547     PassRefPtr<Node> newList = IncreaseSelectionListLevelCommand::increaseSelectionListLevelUnordered(m_frame->document());
548     revealSelectionAfterEditingOperation();
549     return newList;
550 }
551
552 void Editor::decreaseSelectionListLevel()
553 {
554     if (!canEditRichly() || m_frame->selection()->isNone())
555         return;
556     
557     DecreaseSelectionListLevelCommand::decreaseSelectionListLevel(m_frame->document());
558     revealSelectionAfterEditingOperation();
559 }
560
561 void Editor::removeFormattingAndStyle()
562 {
563     applyCommand(RemoveFormatCommand::create(m_frame->document()));
564 }
565
566 void Editor::clearLastEditCommand() 
567 {
568     m_lastEditCommand.clear();
569 }
570
571 // Returns whether caller should continue with "the default processing", which is the same as 
572 // the event handler NOT setting the return value to false
573 bool Editor::dispatchCPPEvent(const AtomicString &eventType, ClipboardAccessPolicy policy)
574 {
575     Node* target = m_frame->selection()->start().element();
576     if (!target && m_frame->document())
577         target = m_frame->document()->body();
578     if (!target)
579         return true;
580     target = target->shadowAncestorNode();
581     
582     RefPtr<Clipboard> clipboard = newGeneralClipboard(policy);
583
584     ExceptionCode ec = 0;
585     RefPtr<Event> evt = ClipboardEvent::create(eventType, true, true, clipboard);
586     EventTargetNodeCast(target)->dispatchEvent(evt, ec, true);
587     bool noDefaultProcessing = evt->defaultPrevented();
588
589     // invalidate clipboard here for security
590     clipboard->setAccessPolicy(ClipboardNumb);
591     
592     return !noDefaultProcessing;
593 }
594
595 void Editor::applyStyle(CSSStyleDeclaration* style, EditAction editingAction)
596 {
597     switch (m_frame->selection()->state()) {
598         case Selection::NONE:
599             // do nothing
600             break;
601         case Selection::CARET:
602             m_frame->computeAndSetTypingStyle(style, editingAction);
603             break;
604         case Selection::RANGE:
605             if (m_frame->document() && style)
606                 applyCommand(ApplyStyleCommand::create(m_frame->document(), style, editingAction));
607             break;
608     }
609 }
610     
611 bool Editor::shouldApplyStyle(CSSStyleDeclaration* style, Range* range)
612 {   
613     return client()->shouldApplyStyle(style, range);
614 }
615     
616 void Editor::applyParagraphStyle(CSSStyleDeclaration* style, EditAction editingAction)
617 {
618     switch (m_frame->selection()->state()) {
619         case Selection::NONE:
620             // do nothing
621             break;
622         case Selection::CARET:
623         case Selection::RANGE:
624             if (m_frame->document() && style)
625                 applyCommand(ApplyStyleCommand::create(m_frame->document(), style, editingAction, ApplyStyleCommand::ForceBlockProperties));
626             break;
627     }
628 }
629
630 void Editor::applyStyleToSelection(CSSStyleDeclaration* style, EditAction editingAction)
631 {
632     if (!style || style->length() == 0 || !canEditRichly())
633         return;
634
635     if (client() && client()->shouldApplyStyle(style, m_frame->selection()->toRange().get()))
636         applyStyle(style, editingAction);
637 }
638
639 void Editor::applyParagraphStyleToSelection(CSSStyleDeclaration* style, EditAction editingAction)
640 {
641     if (!style || style->length() == 0 || !canEditRichly())
642         return;
643     
644     if (client() && client()->shouldApplyStyle(style, m_frame->selection()->toRange().get()))
645         applyParagraphStyle(style, editingAction);
646 }
647
648 bool Editor::clientIsEditable() const
649 {
650     return client() && client()->isEditable();
651 }
652
653 bool Editor::selectionStartHasStyle(CSSStyleDeclaration* style) const
654 {
655     Node* nodeToRemove;
656     RefPtr<CSSComputedStyleDeclaration> selectionStyle = m_frame->selectionComputedStyle(nodeToRemove);
657     if (!selectionStyle)
658         return false;
659     
660     RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
661     
662     bool match = true;
663     DeprecatedValueListConstIterator<CSSProperty> end;
664     for (DeprecatedValueListConstIterator<CSSProperty> it = mutableStyle->valuesIterator(); it != end; ++it) {
665         int propertyID = (*it).id();
666         if (!equalIgnoringCase(mutableStyle->getPropertyValue(propertyID), selectionStyle->getPropertyValue(propertyID))) {
667             match = false;
668             break;
669         }
670     }
671     
672     if (nodeToRemove) {
673         ExceptionCode ec = 0;
674         nodeToRemove->remove(ec);
675         ASSERT(ec == 0);
676     }
677     
678     return match;
679 }
680
681 static void updateState(CSSMutableStyleDeclaration* desiredStyle, CSSComputedStyleDeclaration* computedStyle, bool& atStart, TriState& state)
682 {
683     DeprecatedValueListConstIterator<CSSProperty> end;
684     for (DeprecatedValueListConstIterator<CSSProperty> it = desiredStyle->valuesIterator(); it != end; ++it) {
685         int propertyID = (*it).id();
686         String desiredProperty = desiredStyle->getPropertyValue(propertyID);
687         String computedProperty = computedStyle->getPropertyValue(propertyID);
688         TriState propertyState = equalIgnoringCase(desiredProperty, computedProperty)
689             ? TrueTriState : FalseTriState;
690         if (atStart) {
691             state = propertyState;
692             atStart = false;
693         } else if (state != propertyState) {
694             state = MixedTriState;
695             break;
696         }
697     }
698 }
699
700 TriState Editor::selectionHasStyle(CSSStyleDeclaration* style) const
701 {
702     bool atStart = true;
703     TriState state = FalseTriState;
704
705     RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
706
707     if (!m_frame->selection()->isRange()) {
708         Node* nodeToRemove;
709         RefPtr<CSSComputedStyleDeclaration> selectionStyle = m_frame->selectionComputedStyle(nodeToRemove);
710         if (!selectionStyle)
711             return FalseTriState;
712         updateState(mutableStyle.get(), selectionStyle.get(), atStart, state);
713         if (nodeToRemove) {
714             ExceptionCode ec = 0;
715             nodeToRemove->remove(ec);
716             ASSERT(ec == 0);
717         }
718     } else {
719         for (Node* node = m_frame->selection()->start().node(); node; node = node->traverseNextNode()) {
720             RefPtr<CSSComputedStyleDeclaration> nodeStyle = computedStyle(node);
721             if (nodeStyle)
722                 updateState(mutableStyle.get(), nodeStyle.get(), atStart, state);
723             if (state == MixedTriState)
724                 break;
725             if (node == m_frame->selection()->end().node())
726                 break;
727         }
728     }
729
730     return state;
731 }
732 void Editor::indent()
733 {
734     applyCommand(IndentOutdentCommand::create(m_frame->document(), IndentOutdentCommand::Indent));
735 }
736
737 void Editor::outdent()
738 {
739     applyCommand(IndentOutdentCommand::create(m_frame->document(), IndentOutdentCommand::Outdent));
740 }
741
742 static void dispatchEditableContentChangedEvents(const EditCommand& command)
743 {
744     Element* startRoot = command.startingRootEditableElement();
745     Element* endRoot = command.endingRootEditableElement();
746     ExceptionCode ec;
747     if (startRoot)
748         startRoot->dispatchEvent(Event::create(webkitEditableContentChangedEvent, false, false), ec, true);
749     if (endRoot && endRoot != startRoot)
750         endRoot->dispatchEvent(Event::create(webkitEditableContentChangedEvent, false, false), ec, true);
751 }
752
753 void Editor::appliedEditing(PassRefPtr<EditCommand> cmd)
754 {
755     dispatchEditableContentChangedEvents(*cmd);
756     
757     Selection newSelection(cmd->endingSelection());
758     // If there is no selection change, don't bother sending shouldChangeSelection, but still call setSelection,
759     // because there is work that it must do in this situation.
760     // The old selection can be invalid here and calling shouldChangeSelection can produce some strange calls.
761     // See <rdar://problem/5729315> Some shouldChangeSelectedDOMRange contain Ranges for selections that are no longer valid
762     // Don't clear the typing style or removedAnchor with this selection change.  We do those things elsewhere if necessary.
763     if (newSelection == m_frame->selection()->selection() || m_frame->shouldChangeSelection(newSelection))
764         m_frame->selection()->setSelection(newSelection, false, false);
765         
766     if (!cmd->preservesTypingStyle())
767         m_frame->setTypingStyle(0);
768     
769     // Command will be equal to last edit command only in the case of typing
770     if (m_lastEditCommand.get() == cmd)
771         ASSERT(cmd->isTypingCommand());
772     else {
773         // Only register a new undo command if the command passed in is
774         // different from the last command
775         m_lastEditCommand = cmd;
776         if (client())
777             client()->registerCommandForUndo(m_lastEditCommand);
778     }
779     respondToChangedContents(newSelection);    
780 }
781
782 void Editor::unappliedEditing(PassRefPtr<EditCommand> cmd)
783 {
784     dispatchEditableContentChangedEvents(*cmd);
785     
786     Selection newSelection(cmd->startingSelection());
787     // If there is no selection change, don't bother sending shouldChangeSelection, but still call setSelection,
788     // because there is work that it must do in this situation.
789     // The old selection can be invalid here and calling shouldChangeSelection can produce some strange calls.
790     // See <rdar://problem/5729315> Some shouldChangeSelectedDOMRange contain Ranges for selections that are no longer valid
791     if (newSelection == m_frame->selection()->selection() || m_frame->shouldChangeSelection(newSelection))
792         m_frame->selection()->setSelection(newSelection, true);
793     
794     m_lastEditCommand = 0;
795     if (client())
796         client()->registerCommandForRedo(cmd);
797     respondToChangedContents(newSelection);    
798 }
799
800 void Editor::reappliedEditing(PassRefPtr<EditCommand> cmd)
801 {
802     dispatchEditableContentChangedEvents(*cmd);
803     
804     Selection newSelection(cmd->endingSelection());
805     // If there is no selection change, don't bother sending shouldChangeSelection, but still call setSelection,
806     // because there is work that it must do in this situation.
807     // The old selection can be invalid here and calling shouldChangeSelection can produce some strange calls.
808     // See <rdar://problem/5729315> Some shouldChangeSelectedDOMRange contain Ranges for selections that are no longer valid
809     if (newSelection == m_frame->selection()->selection() || m_frame->shouldChangeSelection(newSelection))
810         m_frame->selection()->setSelection(newSelection, true);
811     
812     m_lastEditCommand = 0;
813     if (client())
814         client()->registerCommandForUndo(cmd);
815     respondToChangedContents(newSelection);    
816 }
817
818 Editor::Editor(Frame* frame)
819     : m_frame(frame)
820     , m_deleteButtonController(new DeleteButtonController(frame))
821     , m_ignoreCompositionSelectionChange(false)
822     , m_shouldStartNewKillRingSequence(false)
823
824 }
825
826 Editor::~Editor()
827 {
828 }
829
830 void Editor::clear()
831 {
832     m_compositionNode = 0;
833     m_customCompositionUnderlines.clear();
834 }
835
836 bool Editor::insertText(const String& text, Event* triggeringEvent)
837 {
838     return m_frame->eventHandler()->handleTextInputEvent(text, triggeringEvent);
839 }
840
841 bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectInsertedText, Event* triggeringEvent)
842 {
843     if (text.isEmpty())
844         return false;
845
846     Selection selection = selectionForCommand(triggeringEvent);
847     if (!selection.isContentEditable())
848         return false;
849     RefPtr<Range> range = selection.toRange();
850
851     if (!shouldInsertText(text, range.get(), EditorInsertActionTyped))
852         return true;
853
854     // Get the selection to use for the event that triggered this insertText.
855     // If the event handler changed the selection, we may want to use a different selection
856     // that is contained in the event target.
857     selection = selectionForCommand(triggeringEvent);
858     if (selection.isContentEditable()) {
859         if (Node* selectionStart = selection.start().node()) {
860             RefPtr<Document> document = selectionStart->document();
861             
862             // Insert the text
863             TypingCommand::insertText(document.get(), text, selection, selectInsertedText);
864
865             // Reveal the current selection 
866             if (Frame* editedFrame = document->frame())
867                 if (Page* page = editedFrame->page())
868                     page->focusController()->focusedOrMainFrame()->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
869         }
870     }
871
872     return true;
873 }
874
875 bool Editor::insertLineBreak()
876 {
877     if (!canEdit())
878         return false;
879
880     if (!shouldInsertText("\n", m_frame->selection()->toRange().get(), EditorInsertActionTyped))
881         return true;
882
883     TypingCommand::insertLineBreak(m_frame->document());
884     revealSelectionAfterEditingOperation();
885     return true;
886 }
887
888 bool Editor::insertParagraphSeparator()
889 {
890     if (!canEdit())
891         return false;
892
893     if (!canEditRichly())
894         return insertLineBreak();
895
896     if (!shouldInsertText("\n", m_frame->selection()->toRange().get(), EditorInsertActionTyped))
897         return true;
898
899     TypingCommand::insertParagraphSeparator(m_frame->document());
900     revealSelectionAfterEditingOperation();
901     return true;
902 }
903
904 void Editor::cut()
905 {
906     if (tryDHTMLCut())
907         return; // DHTML did the whole operation
908     if (!canCut()) {
909         systemBeep();
910         return;
911     }
912     RefPtr<Range> selection = selectedRange();
913     if (shouldDeleteRange(selection.get())) {
914         Pasteboard::generalPasteboard()->writeSelection(selection.get(), canSmartCopyOrDelete(), m_frame);
915         didWriteSelectionToPasteboard();
916         deleteSelectionWithSmartDelete(canSmartCopyOrDelete());
917     }
918 }
919
920 void Editor::copy()
921 {
922     if (tryDHTMLCopy())
923         return; // DHTML did the whole operation
924     if (!canCopy()) {
925         systemBeep();
926         return;
927     }
928     
929     Document* document = m_frame->document();
930     if (HTMLImageElement* imageElement = imageElementFromImageDocument(document))
931         Pasteboard::generalPasteboard()->writeImage(imageElement, document->url(), document->title());
932     else
933         Pasteboard::generalPasteboard()->writeSelection(selectedRange().get(), canSmartCopyOrDelete(), m_frame);
934     
935     didWriteSelectionToPasteboard();
936 }
937
938 #if !PLATFORM(MAC)
939
940 void Editor::paste()
941 {
942     ASSERT(m_frame->document());
943     if (tryDHTMLPaste())
944         return;     // DHTML did the whole operation
945     if (!canPaste())
946         return;
947     DocLoader* loader = m_frame->document()->docLoader();
948     loader->setAllowStaleResources(true);
949     if (m_frame->selection()->isContentRichlyEditable())
950         pasteWithPasteboard(Pasteboard::generalPasteboard(), true);
951     else
952         pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard());
953     loader->setAllowStaleResources(false);
954 }
955
956 #endif
957
958 void Editor::pasteAsPlainText()
959 {
960    if (!canPaste())
961         return;
962    pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard());
963 }
964
965 void Editor::performDelete()
966 {
967     if (!canDelete()) {
968         systemBeep();
969         return;
970     }
971
972     addToKillRing(selectedRange().get(), false);
973     deleteSelectionWithSmartDelete(canSmartCopyOrDelete());
974
975     // clear the "start new kill ring sequence" setting, because it was set to true
976     // when the selection was updated by deleting the range
977     setStartNewKillRingSequence(false);
978 }
979
980 void Editor::copyURL(const KURL& url, const String& title)
981 {
982     Pasteboard::generalPasteboard()->writeURL(url, title, m_frame);
983 }
984
985 void Editor::copyImage(const HitTestResult& result)
986 {
987     KURL url = result.absoluteLinkURL();
988     if (url.isEmpty())
989         url = result.absoluteImageURL();
990
991     Pasteboard::generalPasteboard()->writeImage(result.innerNonSharedNode(), url, result.altDisplayString());
992 }
993
994 bool Editor::isContinuousSpellCheckingEnabled()
995 {
996     return client() && client()->isContinuousSpellCheckingEnabled();
997 }
998
999 void Editor::toggleContinuousSpellChecking()
1000 {
1001     if (client())
1002         client()->toggleContinuousSpellChecking();
1003 }
1004
1005 bool Editor::isGrammarCheckingEnabled()
1006 {
1007     return client() && client()->isGrammarCheckingEnabled();
1008 }
1009
1010 void Editor::toggleGrammarChecking()
1011 {
1012     if (client())
1013         client()->toggleGrammarChecking();
1014 }
1015
1016 int Editor::spellCheckerDocumentTag()
1017 {
1018     return client() ? client()->spellCheckerDocumentTag() : 0;
1019 }
1020
1021 bool Editor::shouldEndEditing(Range* range)
1022 {
1023     return client() && client()->shouldEndEditing(range);
1024 }
1025
1026 bool Editor::shouldBeginEditing(Range* range)
1027 {
1028     return client() && client()->shouldBeginEditing(range);
1029 }
1030
1031 void Editor::clearUndoRedoOperations()
1032 {
1033     if (client())
1034         client()->clearUndoRedoOperations();
1035 }
1036
1037 bool Editor::canUndo()
1038 {
1039     return client() && client()->canUndo();
1040 }
1041
1042 void Editor::undo()
1043 {
1044     if (client())
1045         client()->undo();
1046 }
1047
1048 bool Editor::canRedo()
1049 {
1050     return client() && client()->canRedo();
1051 }
1052
1053 void Editor::redo()
1054 {
1055     if (client())
1056         client()->redo();
1057 }
1058
1059 void Editor::didBeginEditing()
1060 {
1061     if (client())
1062         client()->didBeginEditing();
1063 }
1064
1065 void Editor::didEndEditing()
1066 {
1067     if (client())
1068         client()->didEndEditing();
1069 }
1070
1071 void Editor::didWriteSelectionToPasteboard()
1072 {
1073     if (client())
1074         client()->didWriteSelectionToPasteboard();
1075 }
1076
1077 void Editor::toggleBold()
1078 {
1079     command("ToggleBold").execute();
1080 }
1081
1082 void Editor::toggleUnderline()
1083 {
1084     command("ToggleUnderline").execute();
1085 }
1086
1087 void Editor::setBaseWritingDirection(const String& direction)
1088 {
1089
1090     RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
1091     ExceptionCode ec;
1092     style->setProperty(CSSPropertyDirection, direction, false, ec);
1093     applyParagraphStyleToSelection(style.get(), EditActionSetWritingDirection);
1094 }
1095
1096 void Editor::selectComposition()
1097 {
1098     RefPtr<Range> range = compositionRange();
1099     if (!range)
1100         return;
1101     
1102     // The composition can start inside a composed character sequence, so we have to override checks.
1103     // See <http://bugs.webkit.org/show_bug.cgi?id=15781>
1104     Selection selection;
1105     selection.setWithoutValidation(range->startPosition(), range->endPosition());
1106     m_frame->selection()->setSelection(selection, false, false);
1107 }
1108
1109 void Editor::confirmComposition()
1110 {
1111     if (!m_compositionNode)
1112         return;
1113     confirmComposition(m_compositionNode->data().substring(m_compositionStart, m_compositionEnd - m_compositionStart), false);
1114 }
1115
1116 void Editor::confirmCompositionWithoutDisturbingSelection()
1117 {
1118     if (!m_compositionNode)
1119         return;
1120     confirmComposition(m_compositionNode->data().substring(m_compositionStart, m_compositionEnd - m_compositionStart), true);
1121 }
1122
1123 void Editor::confirmComposition(const String& text)
1124 {
1125     confirmComposition(text, false);
1126 }
1127
1128 void Editor::confirmComposition(const String& text, bool preserveSelection)
1129 {
1130     setIgnoreCompositionSelectionChange(true);
1131
1132     Selection oldSelection = m_frame->selection()->selection();
1133
1134     selectComposition();
1135
1136     if (m_frame->selection()->isNone()) {
1137         setIgnoreCompositionSelectionChange(false);
1138         return;
1139     }
1140     
1141     // If text is empty, then delete the old composition here.  If text is non-empty, InsertTextCommand::input
1142     // will delete the old composition with an optimized replace operation.
1143     if (text.isEmpty())
1144         TypingCommand::deleteSelection(m_frame->document(), false);
1145
1146     m_compositionNode = 0;
1147     m_customCompositionUnderlines.clear();
1148
1149     insertText(text, 0);
1150
1151     if (preserveSelection)
1152         m_frame->selection()->setSelection(oldSelection, false, false);
1153
1154     setIgnoreCompositionSelectionChange(false);
1155 }
1156
1157 void Editor::setComposition(const String& text, const Vector<CompositionUnderline>& underlines, unsigned selectionStart, unsigned selectionEnd)
1158 {
1159     setIgnoreCompositionSelectionChange(true);
1160
1161     selectComposition();
1162
1163     if (m_frame->selection()->isNone()) {
1164         setIgnoreCompositionSelectionChange(false);
1165         return;
1166     }
1167     
1168     // If text is empty, then delete the old composition here.  If text is non-empty, InsertTextCommand::input
1169     // will delete the old composition with an optimized replace operation.
1170     if (text.isEmpty())
1171         TypingCommand::deleteSelection(m_frame->document(), false);
1172
1173     m_compositionNode = 0;
1174     m_customCompositionUnderlines.clear();
1175
1176     if (!text.isEmpty()) {
1177         TypingCommand::insertText(m_frame->document(), text, true, true);
1178
1179         Node* baseNode = m_frame->selection()->base().node();
1180         unsigned baseOffset = m_frame->selection()->base().offset();
1181         Node* extentNode = m_frame->selection()->extent().node();
1182         unsigned extentOffset = m_frame->selection()->extent().offset();
1183
1184         if (baseNode && baseNode == extentNode && baseNode->isTextNode() && baseOffset + text.length() == extentOffset) {
1185             m_compositionNode = static_cast<Text*>(baseNode);
1186             m_compositionStart = baseOffset;
1187             m_compositionEnd = extentOffset;
1188             m_customCompositionUnderlines = underlines;
1189             size_t numUnderlines = m_customCompositionUnderlines.size();
1190             for (size_t i = 0; i < numUnderlines; ++i) {
1191                 m_customCompositionUnderlines[i].startOffset += baseOffset;
1192                 m_customCompositionUnderlines[i].endOffset += baseOffset;
1193             }
1194             if (baseNode->renderer())
1195                 baseNode->renderer()->repaint();
1196
1197             unsigned start = min(baseOffset + selectionStart, extentOffset);
1198             unsigned end = min(max(start, baseOffset + selectionEnd), extentOffset);
1199             RefPtr<Range> selectedRange = Range::create(baseNode->document(), baseNode, start, baseNode, end);                
1200             m_frame->selection()->setSelectedRange(selectedRange.get(), DOWNSTREAM, false);
1201         }
1202     }
1203
1204     setIgnoreCompositionSelectionChange(false);
1205 }
1206
1207 void Editor::ignoreSpelling()
1208 {
1209     if (!client())
1210         return;
1211
1212     String text = frame()->selectedText();
1213     ASSERT(text.length() != 0);
1214     client()->ignoreWordInSpellDocument(text);
1215 }
1216
1217 void Editor::learnSpelling()
1218 {
1219     if (!client())
1220         return;
1221
1222     String text = frame()->selectedText();
1223     ASSERT(text.length() != 0);
1224     client()->learnWord(text);
1225 }
1226
1227 static String findFirstMisspellingInRange(EditorClient* client, Range* searchRange, int& firstMisspellingOffset, bool markAll)
1228 {
1229     ASSERT_ARG(client, client);
1230     ASSERT_ARG(searchRange, searchRange);
1231     
1232     WordAwareIterator it(searchRange);
1233     firstMisspellingOffset = 0;
1234     
1235     String firstMisspelling;
1236     int currentChunkOffset = 0;
1237
1238     while (!it.atEnd()) {
1239         const UChar* chars = it.characters();
1240         int len = it.length();
1241         
1242         // Skip some work for one-space-char hunks
1243         if (!(len == 1 && chars[0] == ' ')) {
1244             
1245             int misspellingLocation = -1;
1246             int misspellingLength = 0;
1247             client->checkSpellingOfString(chars, len, &misspellingLocation, &misspellingLength);
1248
1249             // 5490627 shows that there was some code path here where the String constructor below crashes.
1250             // We don't know exactly what combination of bad input caused this, so we're making this much
1251             // more robust against bad input on release builds.
1252             ASSERT(misspellingLength >= 0);
1253             ASSERT(misspellingLocation >= -1);
1254             ASSERT(misspellingLength == 0 || misspellingLocation >= 0);
1255             ASSERT(misspellingLocation < len);
1256             ASSERT(misspellingLength <= len);
1257             ASSERT(misspellingLocation + misspellingLength <= len);
1258             
1259             if (misspellingLocation >= 0 && misspellingLength > 0 && misspellingLocation < len && misspellingLength <= len && misspellingLocation + misspellingLength <= len) {
1260                 
1261                 // Remember first-encountered misspelling and its offset
1262                 if (!firstMisspelling) {
1263                     firstMisspellingOffset = currentChunkOffset + misspellingLocation;
1264                     firstMisspelling = String(chars + misspellingLocation, misspellingLength);
1265                 }
1266                 
1267                 // Mark this instance if we're marking all instances. Otherwise bail out because we found the first one.
1268                 if (!markAll)
1269                     break;
1270                 
1271                 // Compute range of misspelled word
1272                 RefPtr<Range> misspellingRange = TextIterator::subrange(searchRange, currentChunkOffset + misspellingLocation, misspellingLength);
1273                 
1274                 // Store marker for misspelled word
1275                 ExceptionCode ec = 0;
1276                 misspellingRange->startContainer(ec)->document()->addMarker(misspellingRange.get(), DocumentMarker::Spelling);
1277                 ASSERT(ec == 0);
1278             }
1279         }
1280         
1281         currentChunkOffset += len;
1282         it.advance();
1283     }
1284     
1285     return firstMisspelling;
1286 }
1287
1288 #ifndef BUILDING_ON_TIGER
1289
1290 static PassRefPtr<Range> paragraphAlignedRangeForRange(Range* arbitraryRange, int& offsetIntoParagraphAlignedRange, String& paragraphString)
1291 {
1292     ASSERT_ARG(arbitraryRange, arbitraryRange);
1293     
1294     ExceptionCode ec = 0;
1295     
1296     // Expand range to paragraph boundaries
1297     RefPtr<Range> paragraphRange = arbitraryRange->cloneRange(ec);
1298     setStart(paragraphRange.get(), startOfParagraph(arbitraryRange->startPosition()));
1299     setEnd(paragraphRange.get(), endOfParagraph(arbitraryRange->endPosition()));
1300     
1301     // Compute offset from start of expanded range to start of original range
1302     RefPtr<Range> offsetAsRange = Range::create(paragraphRange->startContainer(ec)->document(), paragraphRange->startPosition(), arbitraryRange->startPosition());
1303     offsetIntoParagraphAlignedRange = TextIterator::rangeLength(offsetAsRange.get());
1304     
1305     // Fill in out parameter with string representing entire paragraph range.
1306     // Someday we might have a caller that doesn't use this, but for now all callers do.
1307     paragraphString = plainText(paragraphRange.get());
1308
1309     return paragraphRange;
1310 }
1311
1312 static int findFirstGrammarDetailInRange(const Vector<GrammarDetail>& grammarDetails, int badGrammarPhraseLocation, int badGrammarPhraseLength, Range *searchRange, int startOffset, int endOffset, bool markAll)
1313 {
1314     // Found some bad grammar. Find the earliest detail range that starts in our search range (if any).
1315     // Optionally add a DocumentMarker for each detail in the range.
1316     int earliestDetailLocationSoFar = -1;
1317     int earliestDetailIndex = -1;
1318     for (unsigned i = 0; i < grammarDetails.size(); i++) {
1319         const GrammarDetail* detail = &grammarDetails[i];
1320         ASSERT(detail->length > 0 && detail->location >= 0);
1321         
1322         int detailStartOffsetInParagraph = badGrammarPhraseLocation + detail->location;
1323         
1324         // Skip this detail if it starts before the original search range
1325         if (detailStartOffsetInParagraph < startOffset)
1326             continue;
1327         
1328         // Skip this detail if it starts after the original search range
1329         if (detailStartOffsetInParagraph >= endOffset)
1330             continue;
1331         
1332         if (markAll) {
1333             RefPtr<Range> badGrammarRange = TextIterator::subrange(searchRange, badGrammarPhraseLocation - startOffset + detail->location, detail->length);
1334             ExceptionCode ec = 0;
1335             badGrammarRange->startContainer(ec)->document()->addMarker(badGrammarRange.get(), DocumentMarker::Grammar, detail->userDescription);
1336             ASSERT(ec == 0);
1337         }
1338         
1339         // Remember this detail only if it's earlier than our current candidate (the details aren't in a guaranteed order)
1340         if (earliestDetailIndex < 0 || earliestDetailLocationSoFar > detail->location) {
1341             earliestDetailIndex = i;
1342             earliestDetailLocationSoFar = detail->location;
1343         }
1344     }
1345     
1346     return earliestDetailIndex;
1347 }
1348     
1349 static String findFirstBadGrammarInRange(EditorClient* client, Range* searchRange, GrammarDetail& outGrammarDetail, int& outGrammarPhraseOffset, bool markAll)
1350 {
1351     ASSERT_ARG(client, client);
1352     ASSERT_ARG(searchRange, searchRange);
1353     
1354     // Initialize out parameters; these will be updated if we find something to return.
1355     outGrammarDetail.location = -1;
1356     outGrammarDetail.length = 0;
1357     outGrammarDetail.guesses.clear();
1358     outGrammarDetail.userDescription = "";
1359     outGrammarPhraseOffset = 0;
1360     
1361     String firstBadGrammarPhrase;
1362
1363     // Expand the search range to encompass entire paragraphs, since grammar checking needs that much context.
1364     // Determine the character offset from the start of the paragraph to the start of the original search range,
1365     // since we will want to ignore results in this area.
1366     int searchRangeStartOffset;
1367     String paragraphString;
1368     RefPtr<Range> paragraphRange = paragraphAlignedRangeForRange(searchRange, searchRangeStartOffset, paragraphString);
1369         
1370     // Determine the character offset from the start of the paragraph to the end of the original search range, 
1371     // since we will want to ignore results in this area also.
1372     int searchRangeEndOffset = searchRangeStartOffset + TextIterator::rangeLength(searchRange);
1373         
1374     // Start checking from beginning of paragraph, but skip past results that occur before the start of the original search range.
1375     int startOffset = 0;
1376     while (startOffset < searchRangeEndOffset) {
1377         Vector<GrammarDetail> grammarDetails;
1378         int badGrammarPhraseLocation = -1;
1379         int badGrammarPhraseLength = 0;
1380         client->checkGrammarOfString(paragraphString.characters() + startOffset, paragraphString.length() - startOffset, grammarDetails, &badGrammarPhraseLocation, &badGrammarPhraseLength);
1381         
1382         if (badGrammarPhraseLength == 0) {
1383             ASSERT(badGrammarPhraseLocation == -1);
1384             return String();
1385         }
1386
1387         ASSERT(badGrammarPhraseLocation >= 0);
1388         badGrammarPhraseLocation += startOffset;
1389
1390         
1391         // Found some bad grammar. Find the earliest detail range that starts in our search range (if any).
1392         int badGrammarIndex = findFirstGrammarDetailInRange(grammarDetails, badGrammarPhraseLocation, badGrammarPhraseLength, searchRange, searchRangeStartOffset, searchRangeEndOffset, markAll);
1393         if (badGrammarIndex >= 0) {
1394             ASSERT(static_cast<unsigned>(badGrammarIndex) < grammarDetails.size());
1395             outGrammarDetail = grammarDetails[badGrammarIndex];
1396         }
1397
1398         // If we found a detail in range, then we have found the first bad phrase (unless we found one earlier but
1399         // kept going so we could mark all instances).
1400         if (badGrammarIndex >= 0 && firstBadGrammarPhrase.isEmpty()) {
1401             outGrammarPhraseOffset = badGrammarPhraseLocation - searchRangeStartOffset;
1402             firstBadGrammarPhrase = paragraphString.substring(badGrammarPhraseLocation, badGrammarPhraseLength);
1403             
1404             // Found one. We're done now, unless we're marking each instance.
1405             if (!markAll)
1406                 break;
1407         }
1408
1409         // These results were all between the start of the paragraph and the start of the search range; look
1410         // beyond this phrase.
1411         startOffset = badGrammarPhraseLocation + badGrammarPhraseLength;
1412     }
1413     
1414     return firstBadGrammarPhrase;
1415 }
1416     
1417 #endif /* not BUILDING_ON_TIGER */
1418
1419 void Editor::advanceToNextMisspelling(bool startBeforeSelection)
1420 {
1421     ExceptionCode ec = 0;
1422
1423     // The basic approach is to search in two phases - from the selection end to the end of the doc, and
1424     // then we wrap and search from the doc start to (approximately) where we started.
1425     
1426     // Start at the end of the selection, search to edge of document.  Starting at the selection end makes
1427     // repeated "check spelling" commands work.
1428     Selection selection(frame()->selection()->selection());
1429     RefPtr<Range> spellingSearchRange(rangeOfContents(frame()->document()));
1430     bool startedWithSelection = false;
1431     if (selection.start().node()) {
1432         startedWithSelection = true;
1433         if (startBeforeSelection) {
1434             VisiblePosition start(selection.visibleStart());
1435             // We match AppKit's rule: Start 1 character before the selection.
1436             VisiblePosition oneBeforeStart = start.previous();
1437             setStart(spellingSearchRange.get(), oneBeforeStart.isNotNull() ? oneBeforeStart : start);
1438         } else
1439             setStart(spellingSearchRange.get(), selection.visibleEnd());
1440     }
1441
1442     Position position = spellingSearchRange->startPosition();
1443     if (!isEditablePosition(position)) {
1444         // This shouldn't happen in very often because the Spelling menu items aren't enabled unless the
1445         // selection is editable.
1446         // This can happen in Mail for a mix of non-editable and editable content (like Stationary), 
1447         // when spell checking the whole document before sending the message.
1448         // In that case the document might not be editable, but there are editable pockets that need to be spell checked.
1449
1450         position = firstEditablePositionAfterPositionInRoot(position, frame()->document()->documentElement()).deepEquivalent();
1451         if (position.isNull())
1452             return;
1453         
1454         Position rangeCompliantPosition = rangeCompliantEquivalent(position);
1455         spellingSearchRange->setStart(rangeCompliantPosition.node(), rangeCompliantPosition.offset(), ec);
1456         startedWithSelection = false;   // won't need to wrap
1457     }
1458     
1459     // topNode defines the whole range we want to operate on 
1460     Node* topNode = highestEditableRoot(position);
1461     spellingSearchRange->setEnd(topNode, maxDeepOffset(topNode), ec);
1462
1463     // If spellingSearchRange starts in the middle of a word, advance to the next word so we start checking
1464     // at a word boundary. Going back by one char and then forward by a word does the trick.
1465     if (startedWithSelection) {
1466         VisiblePosition oneBeforeStart = startVisiblePosition(spellingSearchRange.get(), DOWNSTREAM).previous();
1467         if (oneBeforeStart.isNotNull()) {
1468             setStart(spellingSearchRange.get(), endOfWord(oneBeforeStart));
1469         } // else we were already at the start of the editable node
1470     }
1471     
1472     if (spellingSearchRange->collapsed(ec))
1473         return;       // nothing to search in
1474     
1475     // Get the spell checker if it is available
1476     if (!client())
1477         return;
1478         
1479     // We go to the end of our first range instead of the start of it, just to be sure
1480     // we don't get foiled by any word boundary problems at the start.  It means we might
1481     // do a tiny bit more searching.
1482     Node *searchEndNodeAfterWrap = spellingSearchRange->endContainer(ec);
1483     int searchEndOffsetAfterWrap = spellingSearchRange->endOffset(ec);
1484     
1485     int misspellingOffset;
1486     String misspelledWord = findFirstMisspellingInRange(client(), spellingSearchRange.get(), misspellingOffset, false);
1487     
1488     String badGrammarPhrase;
1489
1490 #ifndef BUILDING_ON_TIGER
1491     int grammarPhraseOffset = 0;
1492     GrammarDetail grammarDetail;
1493
1494     // Search for bad grammar that occurs prior to the next misspelled word (if any)
1495     RefPtr<Range> grammarSearchRange = spellingSearchRange->cloneRange(ec);
1496     if (!misspelledWord.isEmpty()) {
1497         // Stop looking at start of next misspelled word
1498         CharacterIterator chars(grammarSearchRange.get());
1499         chars.advance(misspellingOffset);
1500         grammarSearchRange->setEnd(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
1501     }
1502     
1503     if (isGrammarCheckingEnabled())
1504         badGrammarPhrase = findFirstBadGrammarInRange(client(), grammarSearchRange.get(), grammarDetail, grammarPhraseOffset, false);
1505 #endif
1506     
1507     // If we found neither bad grammar nor a misspelled word, wrap and try again (but don't bother if we started at the beginning of the
1508     // block rather than at a selection).
1509     if (startedWithSelection && !misspelledWord && !badGrammarPhrase) {
1510         spellingSearchRange->setStart(topNode, 0, ec);
1511         // going until the end of the very first chunk we tested is far enough
1512         spellingSearchRange->setEnd(searchEndNodeAfterWrap, searchEndOffsetAfterWrap, ec);
1513         
1514         misspelledWord = findFirstMisspellingInRange(client(), spellingSearchRange.get(), misspellingOffset, false);
1515
1516 #ifndef BUILDING_ON_TIGER
1517         grammarSearchRange = spellingSearchRange->cloneRange(ec);
1518         if (!misspelledWord.isEmpty()) {
1519             // Stop looking at start of next misspelled word
1520             CharacterIterator chars(grammarSearchRange.get());
1521             chars.advance(misspellingOffset);
1522             grammarSearchRange->setEnd(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
1523         }
1524         if (isGrammarCheckingEnabled())
1525             badGrammarPhrase = findFirstBadGrammarInRange(client(), grammarSearchRange.get(), grammarDetail, grammarPhraseOffset, false);
1526 #endif
1527     }
1528     
1529     if (!badGrammarPhrase.isEmpty()) {
1530 #ifdef BUILDING_ON_TIGER
1531         ASSERT_NOT_REACHED();
1532 #else
1533         // We found bad grammar. Since we only searched for bad grammar up to the first misspelled word, the bad grammar
1534         // takes precedence and we ignore any potential misspelled word. Select the grammar detail, update the spelling
1535         // panel, and store a marker so we draw the green squiggle later.
1536         
1537         ASSERT(badGrammarPhrase.length() > 0);
1538         ASSERT(grammarDetail.location != -1 && grammarDetail.length > 0);
1539         
1540         // FIXME 4859190: This gets confused with doubled punctuation at the end of a paragraph
1541         RefPtr<Range> badGrammarRange = TextIterator::subrange(grammarSearchRange.get(), grammarPhraseOffset + grammarDetail.location, grammarDetail.length);
1542         frame()->selection()->setSelection(Selection(badGrammarRange.get(), SEL_DEFAULT_AFFINITY));
1543         frame()->revealSelection();
1544         
1545         client()->updateSpellingUIWithGrammarString(badGrammarPhrase, grammarDetail);
1546         frame()->document()->addMarker(badGrammarRange.get(), DocumentMarker::Grammar, grammarDetail.userDescription);
1547 #endif        
1548     } else if (!misspelledWord.isEmpty()) {
1549         // We found a misspelling, but not any earlier bad grammar. Select the misspelling, update the spelling panel, and store
1550         // a marker so we draw the red squiggle later.
1551         
1552         RefPtr<Range> misspellingRange = TextIterator::subrange(spellingSearchRange.get(), misspellingOffset, misspelledWord.length());
1553         frame()->selection()->setSelection(Selection(misspellingRange.get(), DOWNSTREAM));
1554         frame()->revealSelection();
1555         
1556         client()->updateSpellingUIWithMisspelledWord(misspelledWord);
1557         frame()->document()->addMarker(misspellingRange.get(), DocumentMarker::Spelling);
1558     }
1559 }
1560
1561 bool Editor::isSelectionMisspelled()
1562 {
1563     String selectedString = frame()->selectedText();
1564     int length = selectedString.length();
1565     if (length == 0)
1566         return false;
1567
1568     if (!client())
1569         return false;
1570     
1571     int misspellingLocation = -1;
1572     int misspellingLength = 0;
1573     client()->checkSpellingOfString(selectedString.characters(), length, &misspellingLocation, &misspellingLength);
1574     
1575     // The selection only counts as misspelled if the selected text is exactly one misspelled word
1576     if (misspellingLength != length)
1577         return false;
1578     
1579     // Update the spelling panel to be displaying this error (whether or not the spelling panel is on screen).
1580     // This is necessary to make a subsequent call to [NSSpellChecker ignoreWord:inSpellDocumentWithTag:] work
1581     // correctly; that call behaves differently based on whether the spelling panel is displaying a misspelling
1582     // or a grammar error.
1583     client()->updateSpellingUIWithMisspelledWord(selectedString);
1584     
1585     return true;
1586 }
1587
1588 #ifndef BUILDING_ON_TIGER
1589 static bool isRangeUngrammatical(EditorClient* client, Range *range, Vector<String>& guessesVector)
1590 {
1591     if (!client)
1592         return false;
1593
1594     ExceptionCode ec;
1595     if (!range || range->collapsed(ec))
1596         return false;
1597     
1598     // Returns true only if the passed range exactly corresponds to a bad grammar detail range. This is analogous
1599     // to isSelectionMisspelled. It's not good enough for there to be some bad grammar somewhere in the range,
1600     // or overlapping the range; the ranges must exactly match.
1601     guessesVector.clear();
1602     int grammarPhraseOffset;
1603     
1604     GrammarDetail grammarDetail;
1605     String badGrammarPhrase = findFirstBadGrammarInRange(client, range, grammarDetail, grammarPhraseOffset, false);    
1606     
1607     // No bad grammar in these parts at all.
1608     if (badGrammarPhrase.isEmpty())
1609         return false;
1610     
1611     // Bad grammar, but phrase (e.g. sentence) starts beyond start of range.
1612     if (grammarPhraseOffset > 0)
1613         return false;
1614     
1615     ASSERT(grammarDetail.location >= 0 && grammarDetail.length > 0);
1616     
1617     // Bad grammar, but start of detail (e.g. ungrammatical word) doesn't match start of range
1618     if (grammarDetail.location + grammarPhraseOffset != 0)
1619         return false;
1620     
1621     // Bad grammar at start of range, but end of bad grammar is before or after end of range
1622     if (grammarDetail.length != TextIterator::rangeLength(range))
1623         return false;
1624     
1625     // Update the spelling panel to be displaying this error (whether or not the spelling panel is on screen).
1626     // This is necessary to make a subsequent call to [NSSpellChecker ignoreWord:inSpellDocumentWithTag:] work
1627     // correctly; that call behaves differently based on whether the spelling panel is displaying a misspelling
1628     // or a grammar error.
1629     client->updateSpellingUIWithGrammarString(badGrammarPhrase, grammarDetail);
1630     
1631     return true;
1632 }
1633 #endif
1634
1635 bool Editor::isSelectionUngrammatical()
1636 {
1637 #ifdef BUILDING_ON_TIGER
1638     return false;
1639 #else
1640     Vector<String> ignoredGuesses;
1641     return isRangeUngrammatical(client(), frame()->selection()->toRange().get(), ignoredGuesses);
1642 #endif
1643 }
1644
1645 Vector<String> Editor::guessesForUngrammaticalSelection()
1646 {
1647 #ifdef BUILDING_ON_TIGER
1648     return Vector<String>();
1649 #else
1650     Vector<String> guesses;
1651     // Ignore the result of isRangeUngrammatical; we just want the guesses, whether or not there are any
1652     isRangeUngrammatical(client(), frame()->selection()->toRange().get(), guesses);
1653     return guesses;
1654 #endif
1655 }
1656
1657 Vector<String> Editor::guessesForMisspelledSelection()
1658 {
1659     String selectedString = frame()->selectedText();
1660     ASSERT(selectedString.length() != 0);
1661
1662     Vector<String> guesses;
1663     if (client())
1664         client()->getGuessesForWord(selectedString, guesses);
1665     return guesses;
1666 }
1667
1668 void Editor::showSpellingGuessPanel()
1669 {
1670     if (!client()) {
1671         LOG_ERROR("No NSSpellChecker");
1672         return;
1673     }
1674
1675 #ifndef BUILDING_ON_TIGER
1676     // Post-Tiger, this menu item is a show/hide toggle, to match AppKit. Leave Tiger behavior alone
1677     // to match rest of OS X.
1678     if (client()->spellingUIIsShowing()) {
1679         client()->showSpellingUI(false);
1680         return;
1681     }
1682 #endif
1683     
1684     advanceToNextMisspelling(true);
1685     client()->showSpellingUI(true);
1686 }
1687
1688 bool Editor::spellingPanelIsShowing()
1689 {
1690     if (!client())
1691         return false;
1692     return client()->spellingUIIsShowing();
1693 }
1694
1695 void Editor::markMisspellingsAfterTypingToPosition(const VisiblePosition &p)
1696 {
1697     if (!isContinuousSpellCheckingEnabled())
1698         return;
1699     
1700     // Check spelling of one word
1701     markMisspellings(Selection(startOfWord(p, LeftWordIfOnBoundary), endOfWord(p, RightWordIfOnBoundary)));
1702     
1703     if (!isGrammarCheckingEnabled())
1704         return;
1705     
1706     // Check grammar of entire sentence
1707     markBadGrammar(Selection(startOfSentence(p), endOfSentence(p)));
1708 }
1709
1710 static void markAllMisspellingsInRange(EditorClient* client, Range* searchRange)
1711 {
1712     // Use the "markAll" feature of findFirstMisspellingInRange. Ignore the return value and the "out parameter";
1713     // all we need to do is mark every instance.
1714     int ignoredOffset;
1715     findFirstMisspellingInRange(client, searchRange, ignoredOffset, true);
1716 }
1717
1718 #ifndef BUILDING_ON_TIGER
1719 static void markAllBadGrammarInRange(EditorClient* client, Range* searchRange)
1720 {
1721     // Use the "markAll" feature of findFirstBadGrammarInRange. Ignore the return value and "out parameters"; all we need to
1722     // do is mark every instance.
1723     GrammarDetail ignoredGrammarDetail;
1724     int ignoredOffset;
1725     findFirstBadGrammarInRange(client, searchRange, ignoredGrammarDetail, ignoredOffset, true);
1726 }
1727 #endif
1728     
1729 static void markMisspellingsOrBadGrammar(Editor* editor, const Selection& selection, bool checkSpelling)
1730 {
1731     // This function is called with a selection already expanded to word boundaries.
1732     // Might be nice to assert that here.
1733     
1734     // This function is used only for as-you-type checking, so if that's off we do nothing. Note that
1735     // grammar checking can only be on if spell checking is also on.
1736     if (!editor->isContinuousSpellCheckingEnabled())
1737         return;
1738     
1739     RefPtr<Range> searchRange(selection.toRange());
1740     if (!searchRange)
1741         return;
1742     
1743     // If we're not in an editable node, bail.
1744     Node* editableNode = searchRange->startContainer();
1745     if (!editableNode || !editableNode->isContentEditable())
1746         return;
1747     
1748     // Get the spell checker if it is available
1749     if (!editor->client())
1750         return;
1751     
1752     if (checkSpelling)
1753         markAllMisspellingsInRange(editor->client(), searchRange.get());
1754     else {
1755 #ifdef BUILDING_ON_TIGER
1756         ASSERT_NOT_REACHED();
1757 #else
1758         if (editor->isGrammarCheckingEnabled())
1759             markAllBadGrammarInRange(editor->client(), searchRange.get());
1760 #endif
1761     }    
1762 }
1763
1764 void Editor::markMisspellings(const Selection& selection)
1765 {
1766     markMisspellingsOrBadGrammar(this, selection, true);
1767 }
1768     
1769 void Editor::markBadGrammar(const Selection& selection)
1770 {
1771 #ifndef BUILDING_ON_TIGER
1772     markMisspellingsOrBadGrammar(this, selection, false);
1773 #endif
1774 }
1775
1776 PassRefPtr<Range> Editor::rangeForPoint(const IntPoint& windowPoint)
1777 {
1778     Document* document = m_frame->documentAtPoint(windowPoint);
1779     if (!document)
1780         return 0;
1781     
1782     Frame* frame = document->frame();
1783     ASSERT(frame);
1784     FrameView* frameView = frame->view();
1785     if (!frameView)
1786         return 0;
1787     IntPoint framePoint = frameView->windowToContents(windowPoint);
1788     Selection selection(frame->visiblePositionForPoint(framePoint));
1789     return avoidIntersectionWithNode(selection.toRange().get(), deleteButtonController() ? deleteButtonController()->containerElement() : 0);
1790 }
1791
1792 void Editor::revealSelectionAfterEditingOperation()
1793 {
1794     if (m_ignoreCompositionSelectionChange)
1795         return;
1796
1797     m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
1798 }
1799
1800 void Editor::setIgnoreCompositionSelectionChange(bool ignore)
1801 {
1802     if (m_ignoreCompositionSelectionChange == ignore)
1803         return;
1804
1805     m_ignoreCompositionSelectionChange = ignore;
1806     if (!ignore)
1807         revealSelectionAfterEditingOperation();
1808 }
1809
1810 PassRefPtr<Range> Editor::compositionRange() const
1811 {
1812     if (!m_compositionNode)
1813         return 0;
1814     unsigned length = m_compositionNode->length();
1815     unsigned start = min(m_compositionStart, length);
1816     unsigned end = min(max(start, m_compositionEnd), length);
1817     if (start >= end)
1818         return 0;
1819     return Range::create(m_compositionNode->document(), m_compositionNode.get(), start, m_compositionNode.get(), end);
1820 }
1821
1822 bool Editor::getCompositionSelection(unsigned& selectionStart, unsigned& selectionEnd) const
1823 {
1824     if (!m_compositionNode)
1825         return false;
1826     Position start = m_frame->selection()->start();
1827     if (start.node() != m_compositionNode)
1828         return false;
1829     Position end = m_frame->selection()->end();
1830     if (end.node() != m_compositionNode)
1831         return false;
1832
1833     if (static_cast<unsigned>(start.offset()) < m_compositionStart)
1834         return false;
1835     if (static_cast<unsigned>(end.offset()) > m_compositionEnd)
1836         return false;
1837
1838     selectionStart = start.offset() - m_compositionStart;
1839     selectionEnd = start.offset() - m_compositionEnd;
1840     return true;
1841 }
1842
1843 void Editor::transpose()
1844 {
1845     if (!canEdit())
1846         return;
1847
1848      Selection selection = m_frame->selection()->selection();
1849      if (!selection.isCaret())
1850          return;
1851
1852     // Make a selection that goes back one character and forward two characters.
1853     VisiblePosition caret = selection.visibleStart();
1854     VisiblePosition next = isEndOfParagraph(caret) ? caret : caret.next();
1855     VisiblePosition previous = next.previous();
1856     if (next == previous)
1857         return;
1858     previous = previous.previous();
1859     if (!inSameParagraph(next, previous))
1860         return;
1861     RefPtr<Range> range = makeRange(previous, next);
1862     if (!range)
1863         return;
1864     Selection newSelection(range.get(), DOWNSTREAM);
1865
1866     // Transpose the two characters.
1867     String text = plainText(range.get());
1868     if (text.length() != 2)
1869         return;
1870     String transposed = text.right(1) + text.left(1);
1871
1872     // Select the two characters.
1873     if (newSelection != m_frame->selection()->selection()) {
1874         if (!m_frame->shouldChangeSelection(newSelection))
1875             return;
1876         m_frame->selection()->setSelection(newSelection);
1877     }
1878
1879     // Insert the transposed characters.
1880     if (!shouldInsertText(transposed, range.get(), EditorInsertActionTyped))
1881         return;
1882     replaceSelectionWithText(transposed, false, false);
1883 }
1884
1885 void Editor::addToKillRing(Range* range, bool prepend)
1886 {
1887     if (m_shouldStartNewKillRingSequence)
1888         startNewKillRingSequence();
1889
1890     String text = plainText(range);
1891     text.replace('\\', m_frame->backslashAsCurrencySymbol());
1892     if (prepend)
1893         prependToKillRing(text);
1894     else
1895         appendToKillRing(text);
1896     m_shouldStartNewKillRingSequence = false;
1897 }
1898
1899 #if !PLATFORM(MAC)
1900
1901 void Editor::appendToKillRing(const String&)
1902 {
1903 }
1904
1905 void Editor::prependToKillRing(const String&)
1906 {
1907 }
1908
1909 String Editor::yankFromKillRing()
1910 {
1911     return String();
1912 }
1913
1914 void Editor::startNewKillRingSequence()
1915 {
1916 }
1917
1918 void Editor::setKillRingToYankedState()
1919 {
1920 }
1921
1922 #endif
1923
1924 } // namespace WebCore