| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 frame.eventHandler().handleTextInputEvent(text, 0, TextEventInputComposi
tion); | 111 frame.eventHandler().handleTextInputEvent(text, 0, TextEventInputComposi
tion); |
| 112 break; | 112 break; |
| 113 default: | 113 default: |
| 114 NOTREACHED(); | 114 NOTREACHED(); |
| 115 } | 115 } |
| 116 // TODO(chongz): Fire 'input' event. | 116 // TODO(chongz): Fire 'input' event. |
| 117 } | 117 } |
| 118 | 118 |
| 119 } // anonymous namespace | 119 } // anonymous namespace |
| 120 | 120 |
| 121 InputMethodController::SelectionOffsetsScope::SelectionOffsetsScope(InputMethodC
ontroller* inputMethodController) | |
| 122 : m_inputMethodController(inputMethodController) | |
| 123 , m_offsets(inputMethodController->getSelectionOffsets()) | |
| 124 { | |
| 125 } | |
| 126 | |
| 127 InputMethodController::SelectionOffsetsScope::~SelectionOffsetsScope() | |
| 128 { | |
| 129 m_inputMethodController->setSelectionOffsets(m_offsets); | |
| 130 } | |
| 131 | |
| 132 // ---------------------------- | |
| 133 | |
| 134 InputMethodController* InputMethodController::create(LocalFrame& frame) | 121 InputMethodController* InputMethodController::create(LocalFrame& frame) |
| 135 { | 122 { |
| 136 return new InputMethodController(frame); | 123 return new InputMethodController(frame); |
| 137 } | 124 } |
| 138 | 125 |
| 139 InputMethodController::InputMethodController(LocalFrame& frame) | 126 InputMethodController::InputMethodController(LocalFrame& frame) |
| 140 : m_frame(&frame) | 127 : m_frame(&frame) |
| 141 , m_isDirty(false) | 128 , m_isDirty(false) |
| 142 , m_hasComposition(false) | 129 , m_hasComposition(false) |
| 143 { | 130 { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 234 } |
| 248 | 235 |
| 249 if (text.length()) { | 236 if (text.length()) { |
| 250 confirmComposition(text); | 237 confirmComposition(text); |
| 251 return true; | 238 return true; |
| 252 } | 239 } |
| 253 | 240 |
| 254 if (confirmBehavior == DoNotKeepSelection) | 241 if (confirmBehavior == DoNotKeepSelection) |
| 255 return confirmComposition(composingText(), DoNotKeepSelection); | 242 return confirmComposition(composingText(), DoNotKeepSelection); |
| 256 | 243 |
| 257 SelectionOffsetsScope selectionOffsetsScope(this); | 244 PlainTextRange oldOffsets = getSelectionOffsets(); |
| 258 return confirmComposition(); | 245 bool result = confirmComposition(); |
| 246 |
| 247 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 248 // needs to be audited. see http://crbug.com/590369 for more details. |
| 249 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 250 |
| 251 setSelectionOffsets(oldOffsets); |
| 252 return result; |
| 259 } | 253 } |
| 260 | 254 |
| 261 void InputMethodController::cancelComposition() | 255 void InputMethodController::cancelComposition() |
| 262 { | 256 { |
| 263 if (!hasComposition()) | 257 if (!hasComposition()) |
| 264 return; | 258 return; |
| 265 | 259 |
| 266 Editor::RevealSelectionScope revealSelectionScope(&editor()); | 260 Editor::RevealSelectionScope revealSelectionScope(&editor()); |
| 267 | 261 |
| 268 if (frame().selection().isNone()) | 262 if (frame().selection().isNone()) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 // !hasComposition() && test.isEmpty(). | 341 // !hasComposition() && test.isEmpty(). |
| 348 if (text.isEmpty()) { | 342 if (text.isEmpty()) { |
| 349 if (hasComposition()) { | 343 if (hasComposition()) { |
| 350 confirmComposition(emptyString()); | 344 confirmComposition(emptyString()); |
| 351 } else { | 345 } else { |
| 352 // It's weird to call |setComposition()| with empty text outside com
position, however some IME | 346 // It's weird to call |setComposition()| with empty text outside com
position, however some IME |
| 353 // (e.g. Japanese IBus-Anthy) did this, so we simply delete selectio
n without sending extra events. | 347 // (e.g. Japanese IBus-Anthy) did this, so we simply delete selectio
n without sending extra events. |
| 354 TypingCommand::deleteSelection(*frame().document(), TypingCommand::P
reventSpellChecking); | 348 TypingCommand::deleteSelection(*frame().document(), TypingCommand::P
reventSpellChecking); |
| 355 } | 349 } |
| 356 | 350 |
| 351 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesh
eets |
| 352 // needs to be audited. see http://crbug.com/590369 for more details. |
| 353 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 354 |
| 357 setEditableSelectionOffsets(selectedRange); | 355 setEditableSelectionOffsets(selectedRange); |
| 358 return; | 356 return; |
| 359 } | 357 } |
| 360 | 358 |
| 361 // We should send a 'compositionstart' event only when the given text is not
empty because this | 359 // We should send a 'compositionstart' event only when the given text is not
empty because this |
| 362 // function doesn't create a composition node when the text is empty. | 360 // function doesn't create a composition node when the text is empty. |
| 363 if (!hasComposition()) { | 361 if (!hasComposition()) { |
| 364 target->dispatchEvent(CompositionEvent::create(EventTypeNames::compositi
onstart, frame().domWindow(), frame().selectedText())); | 362 target->dispatchEvent(CompositionEvent::create(EventTypeNames::compositi
onstart, frame().domWindow(), frame().selectedText())); |
| 365 if (!frame().document()) | 363 if (!frame().document()) |
| 366 return; | 364 return; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 m_isDirty = true; | 396 m_isDirty = true; |
| 399 m_hasComposition = true; | 397 m_hasComposition = true; |
| 400 if (!m_compositionRange) | 398 if (!m_compositionRange) |
| 401 m_compositionRange = Range::create(baseNode->document()); | 399 m_compositionRange = Range::create(baseNode->document()); |
| 402 m_compositionRange->setStart(baseNode, baseOffset); | 400 m_compositionRange->setStart(baseNode, baseOffset); |
| 403 m_compositionRange->setEnd(baseNode, extentOffset); | 401 m_compositionRange->setEnd(baseNode, extentOffset); |
| 404 | 402 |
| 405 if (baseNode->layoutObject()) | 403 if (baseNode->layoutObject()) |
| 406 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); | 404 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); |
| 407 | 405 |
| 406 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 407 // needs to be audited. see http://crbug.com/590369 for more details. |
| 408 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 409 |
| 408 // We shouldn't close typing in the middle of setComposition. | 410 // We shouldn't close typing in the middle of setComposition. |
| 409 setEditableSelectionOffsets(selectedRange, NotUserTriggered); | 411 setEditableSelectionOffsets(selectedRange, NotUserTriggered); |
| 410 | 412 |
| 411 if (underlines.isEmpty()) { | 413 if (underlines.isEmpty()) { |
| 412 frame().document()->markers().addCompositionMarker(m_compositionRange->s
tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh
eme::theme().platformDefaultCompositionBackgroundColor()); | 414 frame().document()->markers().addCompositionMarker(m_compositionRange->s
tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh
eme::theme().platformDefaultCompositionBackgroundColor()); |
| 413 return; | 415 return; |
| 414 } | 416 } |
| 415 for (const auto& underline : underlines) { | 417 for (const auto& underline : underlines) { |
| 416 unsigned underlineStart = baseOffset + underline.startOffset; | 418 unsigned underlineStart = baseOffset + underline.startOffset; |
| 417 unsigned underlineEnd = baseOffset + underline.endOffset; | 419 unsigned underlineEnd = baseOffset + underline.endOffset; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 } | 491 } |
| 490 | 492 |
| 491 bool InputMethodController::setSelectionOffsets(const PlainTextRange& selectionO
ffsets, FrameSelection::SetSelectionOptions options) | 493 bool InputMethodController::setSelectionOffsets(const PlainTextRange& selectionO
ffsets, FrameSelection::SetSelectionOptions options) |
| 492 { | 494 { |
| 493 if (selectionOffsets.isNull()) | 495 if (selectionOffsets.isNull()) |
| 494 return false; | 496 return false; |
| 495 Element* rootEditableElement = frame().selection().rootEditableElement(); | 497 Element* rootEditableElement = frame().selection().rootEditableElement(); |
| 496 if (!rootEditableElement) | 498 if (!rootEditableElement) |
| 497 return false; | 499 return false; |
| 498 | 500 |
| 499 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets n
eeds to be audited. | 501 DCHECK(!rootEditableElement->document().needsLayoutTreeUpdate()); |
| 500 // see http://crbug.com/590369 for more details. | |
| 501 rootEditableElement->document().updateStyleAndLayoutIgnorePendingStylesheets
(); | |
| 502 | 502 |
| 503 const EphemeralRange range = selectionOffsets.createRange(*rootEditableEleme
nt); | 503 const EphemeralRange range = selectionOffsets.createRange(*rootEditableEleme
nt); |
| 504 if (range.isNull()) | 504 if (range.isNull()) |
| 505 return false; | 505 return false; |
| 506 | 506 |
| 507 return frame().selection().setSelectedRange(range, VP_DEFAULT_AFFINITY, Sele
ctionDirectionalMode::NonDirectional, options); | 507 return frame().selection().setSelectedRange(range, VP_DEFAULT_AFFINITY, Sele
ctionDirectionalMode::NonDirectional, options); |
| 508 } | 508 } |
| 509 | 509 |
| 510 bool InputMethodController::setEditableSelectionOffsets(const PlainTextRange& se
lectionOffsets, FrameSelection::SetSelectionOptions options) | 510 bool InputMethodController::setEditableSelectionOffsets(const PlainTextRange& se
lectionOffsets, FrameSelection::SetSelectionOptions options) |
| 511 { | 511 { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 TypingCommand::deleteSelection(*frame().document()); | 578 TypingCommand::deleteSelection(*frame().document()); |
| 579 } | 579 } |
| 580 | 580 |
| 581 DEFINE_TRACE(InputMethodController) | 581 DEFINE_TRACE(InputMethodController) |
| 582 { | 582 { |
| 583 visitor->trace(m_frame); | 583 visitor->trace(m_frame); |
| 584 visitor->trace(m_compositionRange); | 584 visitor->trace(m_compositionRange); |
| 585 } | 585 } |
| 586 | 586 |
| 587 } // namespace blink | 587 } // namespace blink |
| OLD | NEW |