OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 using namespace Unicode; | 89 using namespace Unicode; |
90 | 90 |
91 namespace { | 91 namespace { |
92 | 92 |
93 bool isSelectionInTextField(const VisibleSelection& selection) | 93 bool isSelectionInTextField(const VisibleSelection& selection) |
94 { | 94 { |
95 HTMLTextFormControlElement* textControl = enclosingTextFormControl(selection .start()); | 95 HTMLTextFormControlElement* textControl = enclosingTextFormControl(selection .start()); |
96 return textControl && textControl->hasTagName(inputTag) && toHTMLInputElemen t(textControl)->isTextField(); | 96 return textControl && textControl->hasTagName(inputTag) && toHTMLInputElemen t(textControl)->isTextField(); |
97 } | 97 } |
98 | 98 |
99 // Spell checks whole contents of a editable element (<input="text"/>, <textarea > or contenteditable) | |
100 // This gets called when any editable element gets focused. | |
101 void elementDidBeginEditing(Element* element) | |
102 { | |
103 if (Frame* frame = element->document()->frame()) { | |
104 if (frame->editor()->isContinuousSpellCheckingEnabled()) { | |
105 VisibleSelection selection = VisibleSelection::selectionFromContents OfNode(element); | |
106 frame->editor()->markMisspellingsAndBadGrammar(selection); | |
tony
2013/08/02 17:01:17
Is it really OK to check all of a contentEditable
| |
107 } | |
108 } | |
109 } | |
110 | |
99 } // namespace | 111 } // namespace |
100 | 112 |
101 // When an event handler has moved the selection outside of a text control | 113 // When an event handler has moved the selection outside of a text control |
102 // we should use the target control's selection for this editing operation. | 114 // we should use the target control's selection for this editing operation. |
103 VisibleSelection Editor::selectionForCommand(Event* event) | 115 VisibleSelection Editor::selectionForCommand(Event* event) |
104 { | 116 { |
105 VisibleSelection selection = m_frame->selection()->selection(); | 117 VisibleSelection selection = m_frame->selection()->selection(); |
106 if (!event) | 118 if (!event) |
107 return selection; | 119 return selection; |
108 // If the target is a text control, and the current selection is outside of its shadow tree, | 120 // If the target is a text control, and the current selection is outside of its shadow tree, |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1054 { | 1066 { |
1055 return client() && client()->canRedo(); | 1067 return client() && client()->canRedo(); |
1056 } | 1068 } |
1057 | 1069 |
1058 void Editor::redo() | 1070 void Editor::redo() |
1059 { | 1071 { |
1060 if (client()) | 1072 if (client()) |
1061 client()->redo(); | 1073 client()->redo(); |
1062 } | 1074 } |
1063 | 1075 |
1064 void Editor::didBeginEditing() | 1076 void Editor::didBeginEditing(Element* rootEditableElement) |
1065 { | 1077 { |
1078 elementDidBeginEditing(rootEditableElement); | |
1079 | |
1066 if (client()) | 1080 if (client()) |
1067 client()->didBeginEditing(); | 1081 client()->didBeginEditing(); |
1068 } | 1082 } |
1069 | 1083 |
1070 void Editor::didEndEditing() | 1084 void Editor::didEndEditing(Element*) |
1071 { | 1085 { |
1072 if (client()) | 1086 if (client()) |
1073 client()->didEndEditing(); | 1087 client()->didEndEditing(); |
1074 } | 1088 } |
1075 | 1089 |
1076 void Editor::setBaseWritingDirection(WritingDirection direction) | 1090 void Editor::setBaseWritingDirection(WritingDirection direction) |
1077 { | 1091 { |
1078 Node* focusedElement = frame()->document()->focusedElement(); | 1092 Node* focusedElement = frame()->document()->focusedElement(); |
1079 if (focusedElement && isHTMLTextFormControlElement(focusedElement)) { | 1093 if (focusedElement && isHTMLTextFormControlElement(focusedElement)) { |
1080 if (direction == NaturalWritingDirection) | 1094 if (direction == NaturalWritingDirection) |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2079 | 2093 |
2080 // Handle block styles, substracting these from the typing style. | 2094 // Handle block styles, substracting these from the typing style. |
2081 RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperti es(); | 2095 RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperti es(); |
2082 if (!blockStyle->isEmpty()) | 2096 if (!blockStyle->isEmpty()) |
2083 applyCommand(ApplyStyleCommand::create(m_frame->document(), blockStyle.g et(), editingAction)); | 2097 applyCommand(ApplyStyleCommand::create(m_frame->document(), blockStyle.g et(), editingAction)); |
2084 | 2098 |
2085 // Set the remaining style as the typing style. | 2099 // Set the remaining style as the typing style. |
2086 m_frame->selection()->setTypingStyle(typingStyle); | 2100 m_frame->selection()->setTypingStyle(typingStyle); |
2087 } | 2101 } |
2088 | 2102 |
2103 void Editor::textAreaDidBeginEditing(Element* e) | |
2104 { | |
2105 elementDidBeginEditing(toHTMLTextFormControlElement(e)->innerTextElement()); | |
2106 } | |
2089 | 2107 |
2090 void Editor::textFieldDidBeginEditing(Element* e) | 2108 void Editor::textFieldDidBeginEditing(Element* e) |
2091 { | 2109 { |
2092 if (isContinuousSpellCheckingEnabled()) { | 2110 elementDidBeginEditing(toHTMLTextFormControlElement(e)->innerTextElement()); |
tony
2013/08/02 17:01:17
textFieldDidBeginEditing and textAreaDidBeginEditi
| |
2093 Element* element = toHTMLTextFormControlElement(e)->innerTextElement(); | |
2094 VisibleSelection selection = VisibleSelection::selectionFromContentsOfNo de(element); | |
2095 markMisspellingsAndBadGrammar(selection); | |
2096 } | |
2097 } | 2111 } |
2098 | 2112 |
2099 void Editor::textFieldDidEndEditing(Element* e) | 2113 void Editor::textFieldDidEndEditing(Element* e) |
2100 { | 2114 { |
2101 // Remove markers when deactivating a selection in an <input type="text"/>. | 2115 // Remove markers when deactivating a selection in an <input type="text"/>. |
2102 // Prevent new ones from appearing too. | 2116 // Prevent new ones from appearing too. |
2103 m_spellChecker->cancelCheck(); | 2117 m_spellChecker->cancelCheck(); |
2104 HTMLTextFormControlElement* textFormControlElement = toHTMLTextFormControlEl ement(e); | 2118 HTMLTextFormControlElement* textFormControlElement = toHTMLTextFormControlEl ement(e); |
2105 HTMLElement* innerText = textFormControlElement->innerTextElement(); | 2119 HTMLElement* innerText = textFormControlElement->innerTextElement(); |
2106 DocumentMarker::MarkerTypes markerTypes(DocumentMarker::Spelling); | 2120 DocumentMarker::MarkerTypes markerTypes(DocumentMarker::Spelling); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2378 return WebCore::unifiedTextCheckerEnabled(m_frame); | 2392 return WebCore::unifiedTextCheckerEnabled(m_frame); |
2379 } | 2393 } |
2380 | 2394 |
2381 void Editor::toggleOverwriteModeEnabled() | 2395 void Editor::toggleOverwriteModeEnabled() |
2382 { | 2396 { |
2383 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 2397 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
2384 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); | 2398 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); |
2385 }; | 2399 }; |
2386 | 2400 |
2387 } // namespace WebCore | 2401 } // namespace WebCore |
OLD | NEW |