Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: third_party/WebKit/Source/core/editing/InputMethodController.cpp

Issue 2802953002: Avoid duplicate functions/code in core/editing: computeDistance (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 return; 536 return;
537 537
538 // An open typing command that disagrees about current selection would cause 538 // An open typing command that disagrees about current selection would cause
539 // issues with typing later on. 539 // issues with typing later on.
540 TypingCommand::closeTyping(m_frame); 540 TypingCommand::closeTyping(m_frame);
541 541
542 // No DOM update after 'compositionend'. 542 // No DOM update after 'compositionend'.
543 dispatchCompositionEndEvent(frame(), emptyString); 543 dispatchCompositionEndEvent(frame(), emptyString);
544 } 544 }
545 545
546 // If current position is at grapheme boundary, return 0; otherwise, return the
547 // distance to its nearest left grapheme boundary.
548 static size_t computeDistanceToLeftGraphemeBoundary(const Position& position) {
549 const Position& adjustedPosition = previousPositionOf(
550 nextPositionOf(position, PositionMoveType::GraphemeCluster),
551 PositionMoveType::GraphemeCluster);
552 DCHECK_EQ(position.anchorNode(), adjustedPosition.anchorNode());
553 DCHECK_GE(position.computeOffsetInContainerNode(),
554 adjustedPosition.computeOffsetInContainerNode());
555 return static_cast<size_t>(position.computeOffsetInContainerNode() -
556 adjustedPosition.computeOffsetInContainerNode());
557 }
558
559 // If current position is at grapheme boundary, return 0; otherwise, return the
560 // distance to its nearest right grapheme boundary.
561 static size_t computeDistanceToRightGraphemeBoundary(const Position& position) {
562 const Position& adjustedPosition = nextPositionOf(
563 previousPositionOf(position, PositionMoveType::GraphemeCluster),
564 PositionMoveType::GraphemeCluster);
565 DCHECK_EQ(position.anchorNode(), adjustedPosition.anchorNode());
566 DCHECK_GE(adjustedPosition.computeOffsetInContainerNode(),
567 position.computeOffsetInContainerNode());
568 return static_cast<size_t>(adjustedPosition.computeOffsetInContainerNode() -
569 position.computeOffsetInContainerNode());
570 }
571
572 void InputMethodController::setComposition( 546 void InputMethodController::setComposition(
573 const String& text, 547 const String& text,
574 const Vector<CompositionUnderline>& underlines, 548 const Vector<CompositionUnderline>& underlines,
575 int selectionStart, 549 int selectionStart,
576 int selectionEnd) { 550 int selectionEnd) {
577 Editor::RevealSelectionScope revealSelectionScope(&editor()); 551 Editor::RevealSelectionScope revealSelectionScope(&editor());
578 552
579 // Updates styles before setting selection for composition to prevent 553 // Updates styles before setting selection for composition to prevent
580 // inserting the previous composition text into text nodes oddly. 554 // inserting the previous composition text into text nodes oddly.
581 // See https://bugs.webkit.org/show_bug.cgi?id=46868 555 // See https://bugs.webkit.org/show_bug.cgi?id=46868
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 finishComposingText(KeepSelection); 1216 finishComposingText(KeepSelection);
1243 } 1217 }
1244 1218
1245 DEFINE_TRACE(InputMethodController) { 1219 DEFINE_TRACE(InputMethodController) {
1246 visitor->trace(m_frame); 1220 visitor->trace(m_frame);
1247 visitor->trace(m_compositionRange); 1221 visitor->trace(m_compositionRange);
1248 SynchronousMutationObserver::trace(visitor); 1222 SynchronousMutationObserver::trace(visitor);
1249 } 1223 }
1250 1224
1251 } // namespace blink 1225 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698