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

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

Issue 2916493002: Make SelectionState enum class (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/LayoutSelection.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 Element* const root_editable_element = 921 Element* const root_editable_element =
922 GetFrame() 922 GetFrame()
923 .Selection() 923 .Selection()
924 .ComputeVisibleSelectionInDOMTreeDeprecated() 924 .ComputeVisibleSelectionInDOMTreeDeprecated()
925 .RootEditableElement(); 925 .RootEditableElement();
926 if (!root_editable_element) 926 if (!root_editable_element)
927 return; 927 return;
928 int selection_start = static_cast<int>(selection_offsets.Start()); 928 int selection_start = static_cast<int>(selection_offsets.Start());
929 int selection_end = static_cast<int>(selection_offsets.end()); 929 int selection_end = static_cast<int>(selection_offsets.end());
930 930
931 // Select the text to be deleted before selectionStart. 931 // Select the text to be deleted before SelectionState::kStart.
932 if (before > 0 && selection_start > 0) { 932 if (before > 0 && selection_start > 0) {
933 // In case of exceeding the left boundary. 933 // In case of exceeding the left boundary.
934 const int start = std::max(selection_start - before, 0); 934 const int start = std::max(selection_start - before, 0);
935 935
936 const EphemeralRange& range = 936 const EphemeralRange& range =
937 PlainTextRange(0, start).CreateRange(*root_editable_element); 937 PlainTextRange(0, start).CreateRange(*root_editable_element);
938 if (range.IsNull()) 938 if (range.IsNull())
939 return; 939 return;
940 const Position& position = range.EndPosition(); 940 const Position& position = range.EndPosition();
941 941
942 // Adjust the start of selection for multi-code text(a grapheme cluster 942 // Adjust the start of selection for multi-code text(a grapheme cluster
943 // contains more than one code point). TODO(yabinh): Adjustment should be 943 // contains more than one code point). TODO(yabinh): Adjustment should be
944 // based on code point instead of grapheme cluster. 944 // based on code point instead of grapheme cluster.
945 const size_t diff = ComputeDistanceToLeftGraphemeBoundary(position); 945 const size_t diff = ComputeDistanceToLeftGraphemeBoundary(position);
946 const int adjusted_start = start - static_cast<int>(diff); 946 const int adjusted_start = start - static_cast<int>(diff);
947 if (!SetSelectionOffsets(PlainTextRange(adjusted_start, selection_start))) 947 if (!SetSelectionOffsets(PlainTextRange(adjusted_start, selection_start)))
948 return; 948 return;
949 TypingCommand::DeleteSelection(GetDocument()); 949 TypingCommand::DeleteSelection(GetDocument());
950 950
951 selection_end = selection_end - (selection_start - adjusted_start); 951 selection_end = selection_end - (selection_start - adjusted_start);
952 selection_start = adjusted_start; 952 selection_start = adjusted_start;
953 } 953 }
954 954
955 // Select the text to be deleted after selectionEnd. 955 // Select the text to be deleted after SelectionState::kEnd.
956 if (after > 0) { 956 if (after > 0) {
957 // Adjust the deleted range in case of exceeding the right boundary. 957 // Adjust the deleted range in case of exceeding the right boundary.
958 const PlainTextRange range(0, selection_end + after); 958 const PlainTextRange range(0, selection_end + after);
959 if (range.IsNull()) 959 if (range.IsNull())
960 return; 960 return;
961 const EphemeralRange& valid_range = 961 const EphemeralRange& valid_range =
962 range.CreateRange(*root_editable_element); 962 range.CreateRange(*root_editable_element);
963 if (valid_range.IsNull()) 963 if (valid_range.IsNull())
964 return; 964 return;
965 const int end = 965 const int end =
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 FinishComposingText(kKeepSelection); 1235 FinishComposingText(kKeepSelection);
1236 } 1236 }
1237 1237
1238 DEFINE_TRACE(InputMethodController) { 1238 DEFINE_TRACE(InputMethodController) {
1239 visitor->Trace(frame_); 1239 visitor->Trace(frame_);
1240 visitor->Trace(composition_range_); 1240 visitor->Trace(composition_range_);
1241 SynchronousMutationObserver::Trace(visitor); 1241 SynchronousMutationObserver::Trace(visitor);
1242 } 1242 }
1243 1243
1244 } // namespace blink 1244 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/LayoutSelection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698