| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 115     VisibleSelection selection; | 115     VisibleSelection selection; | 
| 116     selection.setWithoutValidation(range.startPosition(), range.endPosition()); | 116     selection.setWithoutValidation(range.startPosition(), range.endPosition()); | 
| 117     frame().selection().setSelection(selection, 0); | 117     frame().selection().setSelection(selection, 0); | 
| 118 } | 118 } | 
| 119 | 119 | 
| 120 bool InputMethodController::confirmComposition() | 120 bool InputMethodController::confirmComposition() | 
| 121 { | 121 { | 
| 122     return confirmComposition(composingText()); | 122     return confirmComposition(composingText()); | 
| 123 } | 123 } | 
| 124 | 124 | 
| 125 static void dispatchCompositionEndEvent(LocalFrame& frame, const String& text) | 125 static void dispatchCompositionEvent(LocalFrame& frame, const AtomicString& type
     , const String& text) | 
| 126 { | 126 { | 
| 127     // We should send this event before sending a TextEvent as written in | 127     // We should send this event before sending a TextEvent as written in | 
| 128     // Section 6.2.2 and 6.2.3 of the DOM Event specification. | 128     // Section 6.2.2 and 6.2.3 of the DOM Event specification. | 
| 129     Element* target = frame.document()->focusedElement(); | 129     Element* target = frame.document()->focusedElement(); | 
| 130     if (!target) | 130     if (!target) | 
| 131         return; | 131         return; | 
| 132 | 132 | 
| 133     RefPtrWillBeRawPtr<CompositionEvent> event = | 133     RefPtrWillBeRawPtr<CompositionEvent> event = | 
| 134         CompositionEvent::create(EventTypeNames::compositionend, frame.domWindow
     (), text); | 134         CompositionEvent::create(type, frame.domWindow(), text); | 
| 135     target->dispatchEvent(event); | 135     target->dispatchEvent(event); | 
| 136 } | 136 } | 
| 137 | 137 | 
| 138 bool InputMethodController::confirmComposition(const String& text) | 138 bool InputMethodController::confirmComposition(const String& text) | 
| 139 { | 139 { | 
| 140     if (!hasComposition()) | 140     if (!hasComposition()) | 
| 141         return false; | 141         return false; | 
| 142 | 142 | 
| 143     Editor::RevealSelectionScope revealSelectionScope(&editor()); | 143     Editor::RevealSelectionScope revealSelectionScope(&editor()); | 
| 144 | 144 | 
| 145     // If the composition was set from existing text and didn't change, then | 145     // If the composition was set from existing text and didn't change, then | 
| 146     // there's nothing to do here (and we should avoid doing anything as that | 146     // there's nothing to do here (and we should avoid doing anything as that | 
| 147     // may clobber multi-node styled text). | 147     // may clobber multi-node styled text). | 
| 148     if (!m_isDirty && composingText() == text) { | 148     if (!m_isDirty && composingText() == text) { | 
| 149         clear(); | 149         clear(); | 
| 150         return true; | 150         return true; | 
| 151     } | 151     } | 
| 152 | 152 | 
| 153     // Select the text that will be deleted or replaced. | 153     // Select the text that will be deleted or replaced. | 
| 154     selectComposition(); | 154     selectComposition(); | 
| 155 | 155 | 
| 156     if (frame().selection().isNone()) | 156     if (frame().selection().isNone()) | 
| 157         return false; | 157         return false; | 
| 158 | 158 | 
| 159     dispatchCompositionEndEvent(frame(), text); | 159     dispatchCompositionEvent(frame(), EventTypeNames::compositionend, text); | 
| 160 | 160 | 
| 161     if (!frame().document()) | 161     if (!frame().document()) | 
| 162         return false; | 162         return false; | 
| 163 | 163 | 
| 164     // If text is empty, then delete the old composition here. If text is | 164     // If text is empty, then delete the old composition here. If text is | 
| 165     // non-empty, InsertTextCommand::input will delete the old composition with | 165     // non-empty, InsertTextCommand::input will delete the old composition with | 
| 166     // an optimized replace operation. | 166     // an optimized replace operation. | 
| 167     if (text.isEmpty()) | 167     if (text.isEmpty()) | 
| 168         TypingCommand::deleteSelection(*frame().document(), 0); | 168         TypingCommand::deleteSelection(*frame().document(), 0); | 
| 169 | 169 | 
| 170     clear(); | 170     clear(); | 
| 171 | 171 | 
| 172     insertTextForConfirmedComposition(text); | 172     insertTextForConfirmedComposition(text); | 
| 173 | 173 | 
| 174     return true; | 174     return true; | 
| 175 } | 175 } | 
| 176 | 176 | 
| 177 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C
     onfirmCompositionBehavior confirmBehavior) | 177 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C
     onfirmCompositionBehavior confirmBehavior) | 
| 178 { | 178 { | 
| 179     if (!hasComposition()) { | 179     if (!hasComposition()) { | 
| 180         if (!text.length()) | 180         if (!text.length()) | 
| 181             return false; | 181             return false; | 
|  | 182         dispatchCompositionEvent(frame(), EventTypeNames::compositionstart, fram
     e().selectedText()); | 
|  | 183         dispatchCompositionEvent(frame(), EventTypeNames::compositionend, text); | 
| 182         editor().insertText(text, 0); | 184         editor().insertText(text, 0); | 
| 183         return true; | 185         return true; | 
| 184     } | 186     } | 
| 185 | 187 | 
| 186     if (text.length()) { | 188     if (text.length()) { | 
| 187         confirmComposition(text); | 189         confirmComposition(text); | 
| 188         return true; | 190         return true; | 
| 189     } | 191     } | 
| 190 | 192 | 
| 191     if (confirmBehavior != KeepSelection) | 193     if (confirmBehavior != KeepSelection) | 
| 192         return confirmComposition(); | 194         return confirmComposition(); | 
| 193 | 195 | 
| 194     SelectionOffsetsScope selectionOffsetsScope(this); | 196     SelectionOffsetsScope selectionOffsetsScope(this); | 
| 195     return confirmComposition(); | 197     return confirmComposition(); | 
| 196 } | 198 } | 
| 197 | 199 | 
| 198 void InputMethodController::cancelComposition() | 200 void InputMethodController::cancelComposition() | 
| 199 { | 201 { | 
| 200     if (!hasComposition()) | 202     if (!hasComposition()) | 
| 201         return; | 203         return; | 
| 202 | 204 | 
| 203     Editor::RevealSelectionScope revealSelectionScope(&editor()); | 205     Editor::RevealSelectionScope revealSelectionScope(&editor()); | 
| 204 | 206 | 
| 205     if (frame().selection().isNone()) | 207     if (frame().selection().isNone()) | 
| 206         return; | 208         return; | 
| 207 | 209 | 
| 208     dispatchCompositionEndEvent(frame(), emptyString()); | 210     dispatchCompositionEvent(frame(), EventTypeNames::compositionend, emptyStrin
     g()); | 
| 209     clear(); | 211     clear(); | 
| 210     insertTextForConfirmedComposition(emptyString()); | 212     insertTextForConfirmedComposition(emptyString()); | 
| 211 | 213 | 
| 212     // An open typing command that disagrees about current selection would cause | 214     // An open typing command that disagrees about current selection would cause | 
| 213     // issues with typing later on. | 215     // issues with typing later on. | 
| 214     TypingCommand::closeTyping(m_frame); | 216     TypingCommand::closeTyping(m_frame); | 
| 215 } | 217 } | 
| 216 | 218 | 
| 217 void InputMethodController::cancelCompositionIfSelectionIsInvalid() | 219 void InputMethodController::cancelCompositionIfSelectionIsInvalid() | 
| 218 { | 220 { | 
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 453     TypingCommand::deleteSelection(*frame().document()); | 455     TypingCommand::deleteSelection(*frame().document()); | 
| 454 } | 456 } | 
| 455 | 457 | 
| 456 DEFINE_TRACE(InputMethodController) | 458 DEFINE_TRACE(InputMethodController) | 
| 457 { | 459 { | 
| 458     visitor->trace(m_frame); | 460     visitor->trace(m_frame); | 
| 459     visitor->trace(m_compositionRange); | 461     visitor->trace(m_compositionRange); | 
| 460 } | 462 } | 
| 461 | 463 | 
| 462 } // namespace blink | 464 } // namespace blink | 
| OLD | NEW | 
|---|