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...) 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 | |
yosin_UTC9
2016/06/15 05:34:41
Could you add DCHECK_XX() to validate |start| and
yosin_UTC9
2016/06/15 19:00:21
I mean
DCHECK_GE(selctionStart, 0);
DCHECK_LE(sel
| |
324 // Dispatch an appropriate composition event to the focused node. | 328 // Dispatch an appropriate composition event to the focused node. |
325 // We check the composition status and choose an appropriate composition eve nt since this | 329 // We check the composition status and choose an appropriate composition eve nt since this |
326 // function is used for three purposes: | 330 // function is used for three purposes: |
327 // 1. Starting a new composition. | 331 // 1. Starting a new composition. |
328 // Send a compositionstart and a compositionupdate event when this functi on creates | 332 // Send a compositionstart and a compositionupdate event when this functi on creates |
329 // a new composition node, i.e. | 333 // a new composition node, i.e. |
330 // !hasComposition() && !text.isEmpty(). | 334 // !hasComposition() && !text.isEmpty(). |
331 // Sending a compositionupdate event at this time ensures that at least o ne | 335 // Sending a compositionupdate event at this time ensures that at least o ne |
332 // compositionupdate event is dispatched. | 336 // compositionupdate event is dispatched. |
333 // 2. Updating the existing composition node. | 337 // 2. Updating the existing composition node. |
334 // Send a compositionupdate event when this function updates the existing composition | 338 // Send a compositionupdate event when this function updates the existing composition |
335 // node, i.e. hasComposition() && !text.isEmpty(). | 339 // node, i.e. hasComposition() && !text.isEmpty(). |
336 // 3. Canceling the ongoing composition. | 340 // 3. Canceling the ongoing composition. |
337 // Send a compositionend event when function deletes the existing composi tion node, i.e. | 341 // Send a compositionend event when function deletes the existing composi tion node, i.e. |
338 // !hasComposition() && test.isEmpty(). | 342 // !hasComposition() && test.isEmpty(). |
339 if (text.isEmpty()) { | 343 if (text.isEmpty()) { |
340 if (hasComposition()) { | 344 if (hasComposition()) { |
341 confirmComposition(emptyString()); | 345 confirmComposition(emptyString()); |
342 return; | 346 } else { |
347 // It's weird to call |setComposition()| with empty text outside com position, however some IME | |
348 // (e.g. Japanese IBus-Anthy) did this, so we simply delete selectio n without sending extra events. | |
349 TypingCommand::deleteSelection(*frame().document(), TypingCommand::P reventSpellChecking); | |
343 } | 350 } |
344 // It's weird to call |setComposition()| with empty text outside composi tion, however some IME | 351 |
345 // (e.g. Japanese IBus-Anthy) did this, so we simply delete selection wi thout sending extra events. | 352 setEditableSelectionOffsets(PlainTextRange(start, end)); |
346 TypingCommand::deleteSelection(*frame().document(), TypingCommand::Preve ntSpellChecking); | |
347 return; | 353 return; |
348 } | 354 } |
349 | 355 |
350 // We should send a 'compositionstart' event only when the given text is not empty because this | 356 // 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. | 357 // function doesn't create a composition node when the text is empty. |
352 if (!hasComposition()) { | 358 if (!hasComposition()) { |
353 target->dispatchEvent(CompositionEvent::create(EventTypeNames::compositi onstart, frame().domWindow(), frame().selectedText())); | 359 target->dispatchEvent(CompositionEvent::create(EventTypeNames::compositi onstart, frame().domWindow(), frame().selectedText())); |
354 if (!frame().document()) | 360 if (!frame().document()) |
355 return; | 361 return; |
356 } | 362 } |
(...skipping 26 matching lines...) Loading... | |
383 m_isDirty = true; | 389 m_isDirty = true; |
384 m_hasComposition = true; | 390 m_hasComposition = true; |
385 if (!m_compositionRange) | 391 if (!m_compositionRange) |
386 m_compositionRange = Range::create(baseNode->document()); | 392 m_compositionRange = Range::create(baseNode->document()); |
387 m_compositionRange->setStart(baseNode, baseOffset); | 393 m_compositionRange->setStart(baseNode, baseOffset); |
388 m_compositionRange->setEnd(baseNode, extentOffset); | 394 m_compositionRange->setEnd(baseNode, extentOffset); |
389 | 395 |
390 if (baseNode->layoutObject()) | 396 if (baseNode->layoutObject()) |
391 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); | 397 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); |
392 | 398 |
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(); | 399 Element* rootEditableElement = frame().selection().rootEditableElement(); |
399 if (!rootEditableElement) | 400 if (!rootEditableElement) |
400 return; | 401 return; |
401 | 402 |
402 // In case of exceeding the right boundary. | 403 const EphemeralRange selectedRange = PlainTextRange(start, end).createRange( *rootEditableElement); |
yosin_UTC9
2016/06/15 05:34:41
s/const EphemeralRange/const EphmeralRange&/
to av
| |
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); | 404 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream , SelectionDirectionalMode::NonDirectional, NotUserTriggered); |
418 | 405 |
419 if (underlines.isEmpty()) { | 406 if (underlines.isEmpty()) { |
420 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor()); | 407 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor()); |
421 return; | 408 return; |
422 } | 409 } |
423 for (const auto& underline : underlines) { | 410 for (const auto& underline : underlines) { |
424 unsigned underlineStart = baseOffset + underline.startOffset; | 411 unsigned underlineStart = baseOffset + underline.startOffset; |
425 unsigned underlineEnd = baseOffset + underline.endOffset; | 412 unsigned underlineEnd = baseOffset + underline.endOffset; |
426 EphemeralRange ephemeralLineRange = EphemeralRange(Position(baseNode, un derlineStart), Position(baseNode, underlineEnd)); | 413 EphemeralRange ephemeralLineRange = EphemeralRange(Position(baseNode, un derlineStart), Position(baseNode, underlineEnd)); |
(...skipping 121 matching lines...) Loading... | |
548 TypingCommand::deleteSelection(*frame().document()); | 535 TypingCommand::deleteSelection(*frame().document()); |
549 } | 536 } |
550 | 537 |
551 DEFINE_TRACE(InputMethodController) | 538 DEFINE_TRACE(InputMethodController) |
552 { | 539 { |
553 visitor->trace(m_frame); | 540 visitor->trace(m_frame); |
554 visitor->trace(m_compositionRange); | 541 visitor->trace(m_compositionRange); |
555 } | 542 } |
556 | 543 |
557 } // namespace blink | 544 } // namespace blink |
OLD | NEW |