| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 return m_compositionNode && m_compositionNode->isContentEditable(); | 77 return m_compositionNode && m_compositionNode->isContentEditable(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 inline Editor& InputMethodController::editor() const | 80 inline Editor& InputMethodController::editor() const |
| 81 { | 81 { |
| 82 return m_frame.editor(); | 82 return m_frame.editor(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void InputMethodController::clear() | 85 void InputMethodController::clear() |
| 86 { | 86 { |
| 87 m_compositionNode = 0; | 87 m_compositionNode = nullptr; |
| 88 m_customCompositionUnderlines.clear(); | 88 m_customCompositionUnderlines.clear(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool InputMethodController::insertTextForConfirmedComposition(const String& text
) | 91 bool InputMethodController::insertTextForConfirmedComposition(const String& text
) |
| 92 { | 92 { |
| 93 return m_frame.eventHandler().handleTextInputEvent(text, 0, TextEventInputCo
mposition); | 93 return m_frame.eventHandler().handleTextInputEvent(text, 0, TextEventInputCo
mposition); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void InputMethodController::selectComposition() const | 96 void InputMethodController::selectComposition() const |
| 97 { | 97 { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 target->dispatchEvent(event, IGNORE_EXCEPTION); | 204 target->dispatchEvent(event, IGNORE_EXCEPTION); |
| 205 } | 205 } |
| 206 | 206 |
| 207 // If text is empty, then delete the old composition here. If text is non-em
pty, InsertTextCommand::input | 207 // If text is empty, then delete the old composition here. If text is non-em
pty, InsertTextCommand::input |
| 208 // will delete the old composition with an optimized replace operation. | 208 // will delete the old composition with an optimized replace operation. |
| 209 if (text.isEmpty() && mode != CancelComposition) { | 209 if (text.isEmpty() && mode != CancelComposition) { |
| 210 ASSERT(m_frame.document()); | 210 ASSERT(m_frame.document()); |
| 211 TypingCommand::deleteSelection(*m_frame.document(), 0); | 211 TypingCommand::deleteSelection(*m_frame.document(), 0); |
| 212 } | 212 } |
| 213 | 213 |
| 214 m_compositionNode = 0; | 214 m_compositionNode = nullptr; |
| 215 m_customCompositionUnderlines.clear(); | 215 m_customCompositionUnderlines.clear(); |
| 216 | 216 |
| 217 insertTextForConfirmedComposition(text); | 217 insertTextForConfirmedComposition(text); |
| 218 | 218 |
| 219 if (mode == CancelComposition) { | 219 if (mode == CancelComposition) { |
| 220 // An open typing command that disagrees about current selection would c
ause issues with typing later on. | 220 // An open typing command that disagrees about current selection would c
ause issues with typing later on. |
| 221 TypingCommand::closeTyping(&m_frame); | 221 TypingCommand::closeTyping(&m_frame); |
| 222 } | 222 } |
| 223 | 223 |
| 224 return true; | 224 return true; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 target->dispatchEvent(event, IGNORE_EXCEPTION); | 272 target->dispatchEvent(event, IGNORE_EXCEPTION); |
| 273 } | 273 } |
| 274 | 274 |
| 275 // If text is empty, then delete the old composition here. If text is non-em
pty, InsertTextCommand::input | 275 // If text is empty, then delete the old composition here. If text is non-em
pty, InsertTextCommand::input |
| 276 // will delete the old composition with an optimized replace operation. | 276 // will delete the old composition with an optimized replace operation. |
| 277 if (text.isEmpty()) { | 277 if (text.isEmpty()) { |
| 278 ASSERT(m_frame.document()); | 278 ASSERT(m_frame.document()); |
| 279 TypingCommand::deleteSelection(*m_frame.document(), TypingCommand::Preve
ntSpellChecking); | 279 TypingCommand::deleteSelection(*m_frame.document(), TypingCommand::Preve
ntSpellChecking); |
| 280 } | 280 } |
| 281 | 281 |
| 282 m_compositionNode = 0; | 282 m_compositionNode = nullptr; |
| 283 m_customCompositionUnderlines.clear(); | 283 m_customCompositionUnderlines.clear(); |
| 284 | 284 |
| 285 if (!text.isEmpty()) { | 285 if (!text.isEmpty()) { |
| 286 ASSERT(m_frame.document()); | 286 ASSERT(m_frame.document()); |
| 287 TypingCommand::insertText(*m_frame.document(), text, TypingCommand::Sele
ctInsertedText | TypingCommand::PreventSpellChecking, TypingCommand::TextComposi
tionUpdate); | 287 TypingCommand::insertText(*m_frame.document(), text, TypingCommand::Sele
ctInsertedText | TypingCommand::PreventSpellChecking, TypingCommand::TextComposi
tionUpdate); |
| 288 | 288 |
| 289 // Find out what node has the composition now. | 289 // Find out what node has the composition now. |
| 290 Position base = m_frame.selection().base().downstream(); | 290 Position base = m_frame.selection().base().downstream(); |
| 291 Position extent = m_frame.selection().extent(); | 291 Position extent = m_frame.selection().extent(); |
| 292 Node* baseNode = base.deprecatedNode(); | 292 Node* baseNode = base.deprecatedNode(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 314 } | 314 } |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 void InputMethodController::setCompositionFromExistingText(const Vector<Composit
ionUnderline>& underlines, unsigned compositionStart, unsigned compositionEnd) | 318 void InputMethodController::setCompositionFromExistingText(const Vector<Composit
ionUnderline>& underlines, unsigned compositionStart, unsigned compositionEnd) |
| 319 { | 319 { |
| 320 Node* editable = m_frame.selection().rootEditableElement(); | 320 Node* editable = m_frame.selection().rootEditableElement(); |
| 321 Position base = m_frame.selection().base().downstream(); | 321 Position base = m_frame.selection().base().downstream(); |
| 322 Node* baseNode = base.anchorNode(); | 322 Node* baseNode = base.anchorNode(); |
| 323 if (editable->firstChild() == baseNode && editable->lastChild() == baseNode
&& baseNode->isTextNode()) { | 323 if (editable->firstChild() == baseNode && editable->lastChild() == baseNode
&& baseNode->isTextNode()) { |
| 324 m_compositionNode = 0; | 324 m_compositionNode = nullptr; |
| 325 m_customCompositionUnderlines.clear(); | 325 m_customCompositionUnderlines.clear(); |
| 326 | 326 |
| 327 if (base.anchorType() != Position::PositionIsOffsetInAnchor) | 327 if (base.anchorType() != Position::PositionIsOffsetInAnchor) |
| 328 return; | 328 return; |
| 329 if (!baseNode || baseNode != m_frame.selection().extent().anchorNode()) | 329 if (!baseNode || baseNode != m_frame.selection().extent().anchorNode()) |
| 330 return; | 330 return; |
| 331 | 331 |
| 332 m_compositionNode = toText(baseNode); | 332 m_compositionNode = toText(baseNode); |
| 333 m_compositionStart = compositionStart; | 333 m_compositionStart = compositionStart; |
| 334 m_compositionEnd = compositionEnd; | 334 m_compositionEnd = compositionEnd; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 345 | 345 |
| 346 Editor::RevealSelectionScope revealSelectionScope(&editor()); | 346 Editor::RevealSelectionScope revealSelectionScope(&editor()); |
| 347 SelectionOffsetsScope selectionOffsetsScope(this); | 347 SelectionOffsetsScope selectionOffsetsScope(this); |
| 348 setSelectionOffsets(PlainTextRange(compositionStart, compositionEnd)); | 348 setSelectionOffsets(PlainTextRange(compositionStart, compositionEnd)); |
| 349 setComposition(m_frame.selectedText(), underlines, 0, 0); | 349 setComposition(m_frame.selectedText(), underlines, 0, 0); |
| 350 } | 350 } |
| 351 | 351 |
| 352 PassRefPtr<Range> InputMethodController::compositionRange() const | 352 PassRefPtr<Range> InputMethodController::compositionRange() const |
| 353 { | 353 { |
| 354 if (!hasComposition()) | 354 if (!hasComposition()) |
| 355 return 0; | 355 return nullptr; |
| 356 unsigned length = m_compositionNode->length(); | 356 unsigned length = m_compositionNode->length(); |
| 357 unsigned start = std::min(m_compositionStart, length); | 357 unsigned start = std::min(m_compositionStart, length); |
| 358 unsigned end = std::min(std::max(start, m_compositionEnd), length); | 358 unsigned end = std::min(std::max(start, m_compositionEnd), length); |
| 359 if (start >= end) | 359 if (start >= end) |
| 360 return 0; | 360 return nullptr; |
| 361 return Range::create(m_compositionNode->document(), m_compositionNode.get(),
start, m_compositionNode.get(), end); | 361 return Range::create(m_compositionNode->document(), m_compositionNode.get(),
start, m_compositionNode.get(), end); |
| 362 } | 362 } |
| 363 | 363 |
| 364 PlainTextRange InputMethodController::getSelectionOffsets() const | 364 PlainTextRange InputMethodController::getSelectionOffsets() const |
| 365 { | 365 { |
| 366 RefPtr<Range> range = m_frame.selection().selection().firstRange(); | 366 RefPtr<Range> range = m_frame.selection().selection().firstRange(); |
| 367 if (!range) | 367 if (!range) |
| 368 return PlainTextRange(); | 368 return PlainTextRange(); |
| 369 Node* editable = m_frame.selection().rootEditableElementOrTreeScopeRootNode(
); | 369 Node* editable = m_frame.selection().rootEditableElementOrTreeScopeRootNode(
); |
| 370 ASSERT(editable); | 370 ASSERT(editable); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 398 if (!editor().canEdit()) | 398 if (!editor().canEdit()) |
| 399 return; | 399 return; |
| 400 PlainTextRange selectionOffsets(getSelectionOffsets()); | 400 PlainTextRange selectionOffsets(getSelectionOffsets()); |
| 401 if (selectionOffsets.isNull()) | 401 if (selectionOffsets.isNull()) |
| 402 return; | 402 return; |
| 403 setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(selectionOffset
s.start()) - before, 0), selectionOffsets.end() + after)); | 403 setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(selectionOffset
s.start()) - before, 0), selectionOffsets.end() + after)); |
| 404 TypingCommand::deleteSelection(*m_frame.document()); | 404 TypingCommand::deleteSelection(*m_frame.document()); |
| 405 } | 405 } |
| 406 | 406 |
| 407 } // namespace WebCore | 407 } // namespace WebCore |
| OLD | NEW |