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 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 } | 1010 } |
1011 | 1011 |
1012 bool Editor::isContinuousSpellCheckingEnabled() const | 1012 bool Editor::isContinuousSpellCheckingEnabled() const |
1013 { | 1013 { |
1014 return client().isContinuousSpellCheckingEnabled(); | 1014 return client().isContinuousSpellCheckingEnabled(); |
1015 } | 1015 } |
1016 | 1016 |
1017 void Editor::toggleContinuousSpellChecking() | 1017 void Editor::toggleContinuousSpellChecking() |
1018 { | 1018 { |
1019 client().toggleContinuousSpellChecking(); | 1019 client().toggleContinuousSpellChecking(); |
| 1020 if (!isContinuousSpellCheckingEnabled()) |
| 1021 m_editablesSpellCheckedOnFocus.clear(); |
1020 } | 1022 } |
1021 | 1023 |
1022 bool Editor::isGrammarCheckingEnabled() | 1024 bool Editor::isGrammarCheckingEnabled() |
1023 { | 1025 { |
1024 return client().isGrammarCheckingEnabled(); | 1026 return client().isGrammarCheckingEnabled(); |
1025 } | 1027 } |
1026 | 1028 |
1027 bool Editor::shouldEndEditing(Range* range) | 1029 bool Editor::shouldEndEditing(Range* range) |
1028 { | 1030 { |
1029 return client().shouldEndEditing(range); | 1031 return client().shouldEndEditing(range); |
(...skipping 22 matching lines...) Expand all Loading... |
1052 bool Editor::canRedo() | 1054 bool Editor::canRedo() |
1053 { | 1055 { |
1054 return client().canRedo(); | 1056 return client().canRedo(); |
1055 } | 1057 } |
1056 | 1058 |
1057 void Editor::redo() | 1059 void Editor::redo() |
1058 { | 1060 { |
1059 client().redo(); | 1061 client().redo(); |
1060 } | 1062 } |
1061 | 1063 |
1062 void Editor::didBeginEditing() | 1064 void Editor::elementDidBeginEditing(Element* element) |
1063 { | 1065 { |
| 1066 if (isContinuousSpellCheckingEnabled() && unifiedTextCheckerEnabled()) { |
| 1067 // This could be called for textareas, text fields and contenteditables. |
| 1068 // Markers from text fields are cleared on blur so text fields have to b
e spell cheked on each focus as opposed |
| 1069 // to textareas and contenteditables which should be spell checked on th
e first focus only. |
| 1070 // This is also why text fields are not put into m_editablesSpellChecked
OnFocus. |
| 1071 // For textareas HTMLTextFormControlElement is put into m_editablesSpell
CheckedOnFocus but spell checking |
| 1072 // is performed on its inner text element (the latter also applies to te
xt fields). For contenteditables |
| 1073 // the passed in element is put into m_editablesSpellCheckedOnFocus (it'
s the root editable element). |
| 1074 bool isTextField = false; |
| 1075 HTMLTextFormControlElement* enclosingHTMLTextFormControlElement = 0; |
| 1076 if (!isHTMLTextFormControlElement(element)) |
| 1077 enclosingHTMLTextFormControlElement = enclosingTextFormControl(first
PositionInNode(element)); |
| 1078 element = enclosingHTMLTextFormControlElement ? enclosingHTMLTextFormCon
trolElement : element; |
| 1079 Element* parent = element; |
| 1080 if (isHTMLTextFormControlElement(element)) { |
| 1081 HTMLTextFormControlElement* textControl = toHTMLTextFormControlEleme
nt(element); |
| 1082 parent = textControl; |
| 1083 element = textControl->innerTextElement(); |
| 1084 isTextField = textControl->hasTagName(inputTag) && toHTMLInputElemen
t(textControl)->isTextField(); |
| 1085 } |
| 1086 |
| 1087 if (isTextField || !m_editablesSpellCheckedOnFocus.contains(parent)) { |
| 1088 VisibleSelection selection = VisibleSelection::selectionFromContents
OfNode(element); |
| 1089 markMisspellingsAndBadGrammar(selection); |
| 1090 if (!isTextField) |
| 1091 m_editablesSpellCheckedOnFocus.append(parent); |
| 1092 } |
| 1093 } |
| 1094 } |
| 1095 |
| 1096 void Editor::didBeginEditing(Element* rootEditableElement) |
| 1097 { |
| 1098 elementDidBeginEditing(rootEditableElement); |
1064 client().didBeginEditing(); | 1099 client().didBeginEditing(); |
1065 } | 1100 } |
1066 | 1101 |
1067 void Editor::didEndEditing() | 1102 void Editor::didEndEditing(Element*) |
1068 { | 1103 { |
1069 client().didEndEditing(); | 1104 client().didEndEditing(); |
1070 } | 1105 } |
1071 | 1106 |
1072 void Editor::setBaseWritingDirection(WritingDirection direction) | 1107 void Editor::setBaseWritingDirection(WritingDirection direction) |
1073 { | 1108 { |
1074 Node* focusedElement = frame()->document()->focusedElement(); | 1109 Node* focusedElement = frame()->document()->focusedElement(); |
1075 if (focusedElement && isHTMLTextFormControlElement(focusedElement)) { | 1110 if (focusedElement && isHTMLTextFormControlElement(focusedElement)) { |
1076 if (direction == NaturalWritingDirection) | 1111 if (direction == NaturalWritingDirection) |
1077 return; | 1112 return; |
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 | 1895 |
1861 // Handle block styles, substracting these from the typing style. | 1896 // Handle block styles, substracting these from the typing style. |
1862 RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperti
es(); | 1897 RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperti
es(); |
1863 if (!blockStyle->isEmpty()) | 1898 if (!blockStyle->isEmpty()) |
1864 applyCommand(ApplyStyleCommand::create(m_frame->document(), blockStyle.g
et(), editingAction)); | 1899 applyCommand(ApplyStyleCommand::create(m_frame->document(), blockStyle.g
et(), editingAction)); |
1865 | 1900 |
1866 // Set the remaining style as the typing style. | 1901 // Set the remaining style as the typing style. |
1867 m_frame->selection()->setTypingStyle(typingStyle); | 1902 m_frame->selection()->setTypingStyle(typingStyle); |
1868 } | 1903 } |
1869 | 1904 |
1870 | 1905 void Editor::textAreaOrTextFieldDidBeginEditing(Element* e) |
1871 void Editor::textFieldDidBeginEditing(Element* e) | |
1872 { | 1906 { |
1873 if (isContinuousSpellCheckingEnabled()) { | 1907 elementDidBeginEditing(e); |
1874 Element* element = toHTMLTextFormControlElement(e)->innerTextElement(); | |
1875 VisibleSelection selection = VisibleSelection::selectionFromContentsOfNo
de(element); | |
1876 markMisspellingsAndBadGrammar(selection); | |
1877 } | |
1878 } | 1908 } |
1879 | 1909 |
1880 void Editor::textFieldDidEndEditing(Element* e) | 1910 void Editor::textFieldDidEndEditing(Element* e) |
1881 { | 1911 { |
1882 // Remove markers when deactivating a selection in an <input type="text"/>. | 1912 // Remove markers when deactivating a selection in an <input type="text"/>. |
1883 // Prevent new ones from appearing too. | 1913 // Prevent new ones from appearing too. |
1884 m_spellCheckRequester->cancelCheck(); | 1914 m_spellCheckRequester->cancelCheck(); |
1885 HTMLTextFormControlElement* textFormControlElement = toHTMLTextFormControlEl
ement(e); | 1915 HTMLTextFormControlElement* textFormControlElement = toHTMLTextFormControlEl
ement(e); |
1886 HTMLElement* innerText = textFormControlElement->innerTextElement(); | 1916 HTMLElement* innerText = textFormControlElement->innerTextElement(); |
1887 DocumentMarker::MarkerTypes markerTypes(DocumentMarker::Spelling); | 1917 DocumentMarker::MarkerTypes markerTypes(DocumentMarker::Spelling); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2174 return WebCore::unifiedTextCheckerEnabled(m_frame); | 2204 return WebCore::unifiedTextCheckerEnabled(m_frame); |
2175 } | 2205 } |
2176 | 2206 |
2177 void Editor::toggleOverwriteModeEnabled() | 2207 void Editor::toggleOverwriteModeEnabled() |
2178 { | 2208 { |
2179 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 2209 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
2180 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); | 2210 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); |
2181 }; | 2211 }; |
2182 | 2212 |
2183 } // namespace WebCore | 2213 } // namespace WebCore |
OLD | NEW |