| 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 314 |
| 315 selectComposition(); | 315 selectComposition(); |
| 316 | 316 |
| 317 if (frame().selection().isNone()) | 317 if (frame().selection().isNone()) |
| 318 return; | 318 return; |
| 319 | 319 |
| 320 Element* target = frame().document()->focusedElement(); | 320 Element* target = frame().document()->focusedElement(); |
| 321 if (!target) | 321 if (!target) |
| 322 return; | 322 return; |
| 323 | 323 |
| 324 int selectionOffsetsStart = static_cast<int>(getSelectionOffsets().start()); |
| 325 int start = selectionOffsetsStart + selectionStart; |
| 326 int end = selectionOffsetsStart + selectionEnd; |
| 327 DCHECK_GE(start, 0); |
| 328 DCHECK_LE(start, end); |
| 329 |
| 324 // Dispatch an appropriate composition event to the focused node. | 330 // Dispatch an appropriate composition event to the focused node. |
| 325 // We check the composition status and choose an appropriate composition eve
nt since this | 331 // We check the composition status and choose an appropriate composition eve
nt since this |
| 326 // function is used for three purposes: | 332 // function is used for three purposes: |
| 327 // 1. Starting a new composition. | 333 // 1. Starting a new composition. |
| 328 // Send a compositionstart and a compositionupdate event when this functi
on creates | 334 // Send a compositionstart and a compositionupdate event when this functi
on creates |
| 329 // a new composition node, i.e. | 335 // a new composition node, i.e. |
| 330 // !hasComposition() && !text.isEmpty(). | 336 // !hasComposition() && !text.isEmpty(). |
| 331 // Sending a compositionupdate event at this time ensures that at least o
ne | 337 // Sending a compositionupdate event at this time ensures that at least o
ne |
| 332 // compositionupdate event is dispatched. | 338 // compositionupdate event is dispatched. |
| 333 // 2. Updating the existing composition node. | 339 // 2. Updating the existing composition node. |
| 334 // Send a compositionupdate event when this function updates the existing
composition | 340 // Send a compositionupdate event when this function updates the existing
composition |
| 335 // node, i.e. hasComposition() && !text.isEmpty(). | 341 // node, i.e. hasComposition() && !text.isEmpty(). |
| 336 // 3. Canceling the ongoing composition. | 342 // 3. Canceling the ongoing composition. |
| 337 // Send a compositionend event when function deletes the existing composi
tion node, i.e. | 343 // Send a compositionend event when function deletes the existing composi
tion node, i.e. |
| 338 // !hasComposition() && test.isEmpty(). | 344 // !hasComposition() && test.isEmpty(). |
| 339 if (text.isEmpty()) { | 345 if (text.isEmpty()) { |
| 340 if (hasComposition()) { | 346 if (hasComposition()) { |
| 341 confirmComposition(emptyString()); | 347 confirmComposition(emptyString()); |
| 342 return; | 348 } else { |
| 349 // It's weird to call |setComposition()| with empty text outside com
position, however some IME |
| 350 // (e.g. Japanese IBus-Anthy) did this, so we simply delete selectio
n without sending extra events. |
| 351 TypingCommand::deleteSelection(*frame().document(), TypingCommand::P
reventSpellChecking); |
| 343 } | 352 } |
| 344 // It's weird to call |setComposition()| with empty text outside composi
tion, however some IME | 353 |
| 345 // (e.g. Japanese IBus-Anthy) did this, so we simply delete selection wi
thout sending extra events. | 354 setEditableSelectionOffsets(PlainTextRange(start, end)); |
| 346 TypingCommand::deleteSelection(*frame().document(), TypingCommand::Preve
ntSpellChecking); | |
| 347 return; | 355 return; |
| 348 } | 356 } |
| 349 | 357 |
| 350 // We should send a 'compositionstart' event only when the given text is not
empty because this | 358 // We should send a 'compositionstart' event only when the given text is not
empty because this |
| 351 // function doesn't create a composition node when the text is empty. | 359 // function doesn't create a composition node when the text is empty. |
| 352 if (!hasComposition()) { | 360 if (!hasComposition()) { |
| 353 target->dispatchEvent(CompositionEvent::create(EventTypeNames::compositi
onstart, frame().domWindow(), frame().selectedText())); | 361 target->dispatchEvent(CompositionEvent::create(EventTypeNames::compositi
onstart, frame().domWindow(), frame().selectedText())); |
| 354 if (!frame().document()) | 362 if (!frame().document()) |
| 355 return; | 363 return; |
| 356 } | 364 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 383 m_isDirty = true; | 391 m_isDirty = true; |
| 384 m_hasComposition = true; | 392 m_hasComposition = true; |
| 385 if (!m_compositionRange) | 393 if (!m_compositionRange) |
| 386 m_compositionRange = Range::create(baseNode->document()); | 394 m_compositionRange = Range::create(baseNode->document()); |
| 387 m_compositionRange->setStart(baseNode, baseOffset); | 395 m_compositionRange->setStart(baseNode, baseOffset); |
| 388 m_compositionRange->setEnd(baseNode, extentOffset); | 396 m_compositionRange->setEnd(baseNode, extentOffset); |
| 389 | 397 |
| 390 if (baseNode->layoutObject()) | 398 if (baseNode->layoutObject()) |
| 391 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); | 399 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); |
| 392 | 400 |
| 393 // In case of exceeding the left boundary. | |
| 394 int selectionOffsetsStart = static_cast<int>(getSelectionOffsets().start()); | |
| 395 int start = std::max(selectionOffsetsStart + selectionStart, 0); | |
| 396 int end = std::max(selectionOffsetsStart + selectionEnd, start); | |
| 397 | |
| 398 Element* rootEditableElement = frame().selection().rootEditableElement(); | 401 Element* rootEditableElement = frame().selection().rootEditableElement(); |
| 399 if (!rootEditableElement) | 402 if (!rootEditableElement) |
| 400 return; | 403 return; |
| 401 | 404 |
| 402 // In case of exceeding the right boundary. | 405 const EphemeralRange& selectedRange = PlainTextRange(start, end).createRange
(*rootEditableElement); |
| 403 // If both |value1| and |value2| exceed right boundary, | |
| 404 // PlainTextRange(value1, value2)::createRange() will return a default | |
| 405 // value, which is [0,0]. In order to get the correct Position in that case, | |
| 406 // we should make sure |value1| is within range at least. | |
| 407 const EphemeralRange& startRange = PlainTextRange(0, start).createRange(*roo
tEditableElement); | |
| 408 const EphemeralRange& endRange = PlainTextRange(0, end).createRange(*rootEdi
tableElement); | |
| 409 | |
| 410 // TODO(yabinh): There should be a better way to create |startPosition| and | |
| 411 // |endPosition|. But for now, since we can't get |anchorNode| and |offset|, | |
| 412 // we can't create the 2 Position objects directly. So we use | |
| 413 // PlainTextRange::createRange as a workaround. | |
| 414 const Position& startPosition = startRange.endPosition(); | |
| 415 const Position& endPosition = endRange.endPosition(); | |
| 416 const EphemeralRange selectedRange(startPosition, endPosition); | |
| 417 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream
, SelectionDirectionalMode::NonDirectional, NotUserTriggered); | 406 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream
, SelectionDirectionalMode::NonDirectional, NotUserTriggered); |
| 418 | 407 |
| 419 if (underlines.isEmpty()) { | 408 if (underlines.isEmpty()) { |
| 420 frame().document()->markers().addCompositionMarker(m_compositionRange->s
tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh
eme::theme().platformDefaultCompositionBackgroundColor()); | 409 frame().document()->markers().addCompositionMarker(m_compositionRange->s
tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh
eme::theme().platformDefaultCompositionBackgroundColor()); |
| 421 return; | 410 return; |
| 422 } | 411 } |
| 423 for (const auto& underline : underlines) { | 412 for (const auto& underline : underlines) { |
| 424 unsigned underlineStart = baseOffset + underline.startOffset; | 413 unsigned underlineStart = baseOffset + underline.startOffset; |
| 425 unsigned underlineEnd = baseOffset + underline.endOffset; | 414 unsigned underlineEnd = baseOffset + underline.endOffset; |
| 426 EphemeralRange ephemeralLineRange = EphemeralRange(Position(baseNode, un
derlineStart), Position(baseNode, underlineEnd)); | 415 EphemeralRange ephemeralLineRange = EphemeralRange(Position(baseNode, un
derlineStart), Position(baseNode, underlineEnd)); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 TypingCommand::deleteSelection(*frame().document()); | 537 TypingCommand::deleteSelection(*frame().document()); |
| 549 } | 538 } |
| 550 | 539 |
| 551 DEFINE_TRACE(InputMethodController) | 540 DEFINE_TRACE(InputMethodController) |
| 552 { | 541 { |
| 553 visitor->trace(m_frame); | 542 visitor->trace(m_frame); |
| 554 visitor->trace(m_compositionRange); | 543 visitor->trace(m_compositionRange); |
| 555 } | 544 } |
| 556 | 545 |
| 557 } // namespace blink | 546 } // namespace blink |
| OLD | NEW |