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

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

Issue 1325563002: Avoid style clobbering in setCompositionFromExistingText. (2nd land) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Delete CompositionUnderlinesRangeFilter (it's now dead code) Created 5 years, 3 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 11 matching lines...) Expand all
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/editing/InputMethodController.h" 28 #include "core/editing/InputMethodController.h"
29 29
30 #include "core/dom/Document.h" 30 #include "core/dom/Document.h"
31 #include "core/dom/Element.h" 31 #include "core/dom/Element.h"
32 #include "core/dom/Range.h"
33 #include "core/dom/Text.h" 32 #include "core/dom/Text.h"
33 #include "core/editing/EditingUtilities.h"
34 #include "core/editing/Editor.h" 34 #include "core/editing/Editor.h"
35 #include "core/editing/commands/TypingCommand.h" 35 #include "core/editing/commands/TypingCommand.h"
36 #include "core/editing/markers/DocumentMarkerController.h"
36 #include "core/events/CompositionEvent.h" 37 #include "core/events/CompositionEvent.h"
37 #include "core/frame/LocalFrame.h" 38 #include "core/frame/LocalFrame.h"
38 #include "core/html/HTMLTextAreaElement.h" 39 #include "core/html/HTMLTextAreaElement.h"
39 #include "core/input/EventHandler.h" 40 #include "core/input/EventHandler.h"
40 #include "core/layout/LayoutObject.h" 41 #include "core/layout/LayoutObject.h"
42 #include "core/layout/LayoutTheme.h"
41 #include "core/page/ChromeClient.h" 43 #include "core/page/ChromeClient.h"
42 44
43 namespace blink { 45 namespace blink {
44 46
45 InputMethodController::SelectionOffsetsScope::SelectionOffsetsScope(InputMethodC ontroller* inputMethodController) 47 InputMethodController::SelectionOffsetsScope::SelectionOffsetsScope(InputMethodC ontroller* inputMethodController)
46 : m_inputMethodController(inputMethodController) 48 : m_inputMethodController(inputMethodController)
47 , m_offsets(inputMethodController->getSelectionOffsets()) 49 , m_offsets(inputMethodController->getSelectionOffsets())
48 { 50 {
49 } 51 }
50 52
51 InputMethodController::SelectionOffsetsScope::~SelectionOffsetsScope() 53 InputMethodController::SelectionOffsetsScope::~SelectionOffsetsScope()
52 { 54 {
53 m_inputMethodController->setSelectionOffsets(m_offsets); 55 m_inputMethodController->setSelectionOffsets(m_offsets);
54 } 56 }
55 57
56 // ---------------------------- 58 // ----------------------------
57 59
58 PassOwnPtrWillBeRawPtr<InputMethodController> InputMethodController::create(Loca lFrame& frame) 60 PassOwnPtrWillBeRawPtr<InputMethodController> InputMethodController::create(Loca lFrame& frame)
59 { 61 {
60 return adoptPtrWillBeNoop(new InputMethodController(frame)); 62 return adoptPtrWillBeNoop(new InputMethodController(frame));
61 } 63 }
62 64
63 InputMethodController::InputMethodController(LocalFrame& frame) 65 InputMethodController::InputMethodController(LocalFrame& frame)
64 : m_frame(&frame) 66 : m_frame(&frame)
65 , m_compositionStart(0) 67 , m_isDirty(false)
66 , m_compositionEnd(0) 68 , m_hasComposition(false)
67 { 69 {
68 } 70 }
69 71
70 InputMethodController::~InputMethodController() 72 InputMethodController::~InputMethodController()
71 { 73 {
72 } 74 }
73 75
74 bool InputMethodController::hasComposition() const 76 bool InputMethodController::hasComposition() const
75 { 77 {
76 return m_compositionNode && m_compositionNode->isContentEditable(); 78 return m_hasComposition;
77 } 79 }
78 80
79 inline Editor& InputMethodController::editor() const 81 inline Editor& InputMethodController::editor() const
80 { 82 {
81 return frame().editor(); 83 return frame().editor();
82 } 84 }
83 85
84 void InputMethodController::clear() 86 void InputMethodController::clear()
85 { 87 {
86 m_compositionNode = nullptr; 88 m_hasComposition = false;
87 m_customCompositionUnderlines.clear(); 89 if (m_compositionRange) {
90 m_compositionRange->setStart(frame().document(), 0);
91 m_compositionRange->collapse(true);
92 }
93 frame().document()->markers().removeMarkers(DocumentMarker::Composition);
94 m_isDirty = false;
88 } 95 }
89 96
90 bool InputMethodController::insertTextForConfirmedComposition(const String& text ) 97 bool InputMethodController::insertTextForConfirmedComposition(const String& text )
91 { 98 {
92 return frame().eventHandler().handleTextInputEvent(text, 0, TextEventInputCo mposition); 99 return frame().eventHandler().handleTextInputEvent(text, 0, TextEventInputCo mposition);
93 } 100 }
94 101
95 void InputMethodController::selectComposition() const 102 void InputMethodController::selectComposition() const
96 { 103 {
97 const EphemeralRange range = compositionEphemeralRange(); 104 const EphemeralRange range = compositionEphemeralRange();
98 if (range.isNull()) 105 if (range.isNull())
99 return; 106 return;
100 107
101 // The composition can start inside a composed character sequence, so we hav e to override checks. 108 // The composition can start inside a composed character sequence, so we hav e to override checks.
102 // See <http://bugs.webkit.org/show_bug.cgi?id=15781> 109 // See <http://bugs.webkit.org/show_bug.cgi?id=15781>
103 VisibleSelection selection; 110 VisibleSelection selection;
104 selection.setWithoutValidation(range.startPosition(), range.endPosition()); 111 selection.setWithoutValidation(range.startPosition(), range.endPosition());
105 frame().selection().setSelection(selection, 0); 112 frame().selection().setSelection(selection, 0);
106 } 113 }
107 114
108 bool InputMethodController::confirmComposition() 115 bool InputMethodController::confirmComposition()
109 { 116 {
110 if (!hasComposition()) 117 if (!hasComposition())
111 return false; 118 return false;
112 return finishComposition(m_compositionNode->data().substring(m_compositionSt art, m_compositionEnd - m_compositionStart), ConfirmComposition); 119 return confirmComposition(plainText(compositionEphemeralRange()));
113 } 120 }
114 121
115 bool InputMethodController::confirmComposition(const String& text) 122 bool InputMethodController::confirmComposition(const String& text)
116 { 123 {
117 return finishComposition(text, ConfirmComposition); 124 return finishComposition(text, ConfirmComposition);
118 } 125 }
119 126
120 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior) 127 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior)
121 { 128 {
122 if (!hasComposition()) { 129 if (!hasComposition()) {
(...skipping 19 matching lines...) Expand all
142 { 149 {
143 finishComposition(emptyString(), CancelComposition); 150 finishComposition(emptyString(), CancelComposition);
144 } 151 }
145 152
146 void InputMethodController::cancelCompositionIfSelectionIsInvalid() 153 void InputMethodController::cancelCompositionIfSelectionIsInvalid()
147 { 154 {
148 if (!hasComposition() || editor().preventRevealSelection()) 155 if (!hasComposition() || editor().preventRevealSelection())
149 return; 156 return;
150 157
151 // Check if selection start and selection end are valid. 158 // Check if selection start and selection end are valid.
152 Position start = frame().selection().start(); 159 FrameSelection& selection = frame().selection();
153 Position end = frame().selection().end(); 160 if (!selection.isNone() && !m_compositionRange->collapsed()) {
154 if (start.computeContainerNode() == m_compositionNode 161 Position start = selection.start();
yosin_UTC9 2015/09/10 09:42:28 Please remove unused local variable |start|.
aelias_OOO_until_Jul13 2015/09/10 19:59:29 Done.
155 && end.computeContainerNode() == m_compositionNode 162 Position end = selection.end();
yosin_UTC9 2015/09/10 09:42:28 Please remove unused local variable |end|.
156 && static_cast<unsigned>(start.computeOffsetInContainerNode()) >= m_comp ositionStart 163 if (selection.start().compareTo(m_compositionRange->startPosition()) >= 0
157 && static_cast<unsigned>(end.computeOffsetInContainerNode()) <= m_compos itionEnd) 164 && selection.end().compareTo(m_compositionRange->endPosition()) <= 0 )
158 return; 165 return;
166 }
159 167
160 cancelComposition(); 168 cancelComposition();
161 frame().chromeClient().didCancelCompositionOnSelectionChange(); 169 frame().chromeClient().didCancelCompositionOnSelectionChange();
162 } 170 }
163 171
164 bool InputMethodController::finishComposition(const String& text, FinishComposit ionMode mode) 172 bool InputMethodController::finishComposition(const String& text, FinishComposit ionMode mode)
165 { 173 {
166 if (!hasComposition()) 174 if (!hasComposition())
167 return false; 175 return false;
168 176
(...skipping 10 matching lines...) Expand all
179 return false; 187 return false;
180 188
181 // Dispatch a compositionend event to the focused node. 189 // Dispatch a compositionend event to the focused node.
182 // We should send this event before sending a TextEvent as written in Sectio n 6.2.2 and 6.2.3 of 190 // We should send this event before sending a TextEvent as written in Sectio n 6.2.2 and 6.2.3 of
183 // the DOM Event specification. 191 // the DOM Event specification.
184 if (Element* target = frame().document()->focusedElement()) { 192 if (Element* target = frame().document()->focusedElement()) {
185 RefPtrWillBeRawPtr<CompositionEvent> event = CompositionEvent::create(Ev entTypeNames::compositionend, frame().domWindow(), text); 193 RefPtrWillBeRawPtr<CompositionEvent> event = CompositionEvent::create(Ev entTypeNames::compositionend, frame().domWindow(), text);
186 target->dispatchEvent(event); 194 target->dispatchEvent(event);
187 } 195 }
188 196
197 bool dirty = m_isDirty || plainText(compositionEphemeralRange()) != text;
198
189 // If text is empty, then delete the old composition here. If text is non-em pty, InsertTextCommand::input 199 // If text is empty, then delete the old composition here. If text is non-em pty, InsertTextCommand::input
190 // will delete the old composition with an optimized replace operation. 200 // will delete the old composition with an optimized replace operation.
191 if (text.isEmpty() && mode != CancelComposition) { 201 if (text.isEmpty() && mode != CancelComposition && dirty) {
192 ASSERT(frame().document()); 202 ASSERT(frame().document());
193 TypingCommand::deleteSelection(*frame().document(), 0); 203 TypingCommand::deleteSelection(*frame().document(), 0);
194 } 204 }
195 205
196 m_compositionNode = nullptr; 206 clear();
197 m_customCompositionUnderlines.clear();
198 207
199 insertTextForConfirmedComposition(text); 208 if (dirty)
209 insertTextForConfirmedComposition(text);
200 210
201 if (mode == CancelComposition) { 211 if (mode == CancelComposition) {
202 // An open typing command that disagrees about current selection would c ause issues with typing later on. 212 // An open typing command that disagrees about current selection would c ause issues with typing later on.
203 TypingCommand::closeTyping(m_frame); 213 TypingCommand::closeTyping(m_frame);
204 } 214 }
205 215
206 return true; 216 return true;
207 } 217 }
208 218
209 void InputMethodController::setComposition(const String& text, const Vector<Comp ositionUnderline>& underlines, unsigned selectionStart, unsigned selectionEnd) 219 void InputMethodController::setComposition(const String& text, const Vector<Comp ositionUnderline>& underlines, unsigned selectionStart, unsigned selectionEnd)
(...skipping 10 matching lines...) Expand all
220 if (frame().selection().isNone()) 230 if (frame().selection().isNone())
221 return; 231 return;
222 232
223 if (Element* target = frame().document()->focusedElement()) { 233 if (Element* target = frame().document()->focusedElement()) {
224 // Dispatch an appropriate composition event to the focused node. 234 // Dispatch an appropriate composition event to the focused node.
225 // We check the composition status and choose an appropriate composition event since this 235 // We check the composition status and choose an appropriate composition event since this
226 // function is used for three purposes: 236 // function is used for three purposes:
227 // 1. Starting a new composition. 237 // 1. Starting a new composition.
228 // Send a compositionstart and a compositionupdate event when this fu nction creates 238 // Send a compositionstart and a compositionupdate event when this fu nction creates
229 // a new composition node, i.e. 239 // a new composition node, i.e.
230 // m_compositionNode == 0 && !text.isEmpty(). 240 // !hasComposition() && !text.isEmpty().
231 // Sending a compositionupdate event at this time ensures that at lea st one 241 // Sending a compositionupdate event at this time ensures that at lea st one
232 // compositionupdate event is dispatched. 242 // compositionupdate event is dispatched.
233 // 2. Updating the existing composition node. 243 // 2. Updating the existing composition node.
234 // Send a compositionupdate event when this function updates the exis ting composition 244 // Send a compositionupdate event when this function updates the exis ting composition
235 // node, i.e. m_compositionNode != 0 && !text.isEmpty(). 245 // node, i.e. hasComposition() && !text.isEmpty().
236 // 3. Canceling the ongoing composition. 246 // 3. Canceling the ongoing composition.
237 // Send a compositionend event when function deletes the existing com position node, i.e. 247 // Send a compositionend event when function deletes the existing com position node, i.e.
238 // m_compositionNode != 0 && test.isEmpty(). 248 // !hasComposition() && test.isEmpty().
239 RefPtrWillBeRawPtr<CompositionEvent> event = nullptr; 249 RefPtrWillBeRawPtr<CompositionEvent> event = nullptr;
240 if (!hasComposition()) { 250 if (!hasComposition()) {
241 // We should send a compositionstart event only when the given text is not empty because this 251 // We should send a compositionstart event only when the given text is not empty because this
242 // function doesn't create a composition node when the text is empty . 252 // function doesn't create a composition node when the text is empty .
243 if (!text.isEmpty()) { 253 if (!text.isEmpty()) {
244 target->dispatchEvent(CompositionEvent::create(EventTypeNames::c ompositionstart, frame().domWindow(), frame().selectedText())); 254 target->dispatchEvent(CompositionEvent::create(EventTypeNames::c ompositionstart, frame().domWindow(), frame().selectedText()));
245 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text); 255 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text);
246 } 256 }
247 } else { 257 } else {
248 if (!text.isEmpty()) 258 if (!text.isEmpty())
249 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text); 259 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text);
250 else 260 else
251 event = CompositionEvent::create(EventTypeNames::compositionend, frame().domWindow(), text); 261 event = CompositionEvent::create(EventTypeNames::compositionend, frame().domWindow(), text);
252 } 262 }
253 if (event.get()) 263 if (event.get())
254 target->dispatchEvent(event); 264 target->dispatchEvent(event);
255 } 265 }
256 266
257 // If text is empty, then delete the old composition here. If text is non-em pty, InsertTextCommand::input 267 // If text is empty, then delete the old composition here. If text is non-em pty, InsertTextCommand::input
258 // will delete the old composition with an optimized replace operation. 268 // will delete the old composition with an optimized replace operation.
259 if (text.isEmpty()) { 269 if (text.isEmpty()) {
260 ASSERT(frame().document()); 270 ASSERT(frame().document());
261 TypingCommand::deleteSelection(*frame().document(), TypingCommand::Preve ntSpellChecking); 271 TypingCommand::deleteSelection(*frame().document(), TypingCommand::Preve ntSpellChecking);
262 } 272 }
263 273
264 m_compositionNode = nullptr; 274 clear();
265 m_customCompositionUnderlines.clear();
266 275
267 if (text.isEmpty()) 276 if (text.isEmpty())
268 return; 277 return;
269 ASSERT(frame().document()); 278 ASSERT(frame().document());
270 TypingCommand::insertText(*frame().document(), text, TypingCommand::SelectIn sertedText | TypingCommand::PreventSpellChecking, TypingCommand::TextComposition Update); 279 TypingCommand::insertText(*frame().document(), text, TypingCommand::SelectIn sertedText | TypingCommand::PreventSpellChecking, TypingCommand::TextComposition Update);
271 280
272 // Find out what node has the composition now. 281 // Find out what node has the composition now.
273 Position base = mostForwardCaretPosition(frame().selection().base()); 282 Position base = mostForwardCaretPosition(frame().selection().base());
274 Node* baseNode = base.anchorNode(); 283 Node* baseNode = base.anchorNode();
275 if (!baseNode || !baseNode->isTextNode()) 284 if (!baseNode || !baseNode->isTextNode())
276 return; 285 return;
277 286
278 Position extent = frame().selection().extent(); 287 Position extent = frame().selection().extent();
279 Node* extentNode = extent.anchorNode(); 288 Node* extentNode = extent.anchorNode();
280 if (baseNode != extentNode) 289 if (baseNode != extentNode)
281 return; 290 return;
282 291
283 unsigned extentOffset = extent.computeOffsetInContainerNode(); 292 unsigned extentOffset = extent.computeOffsetInContainerNode();
284 unsigned baseOffset = base.computeOffsetInContainerNode(); 293 unsigned baseOffset = base.computeOffsetInContainerNode();
285 if (baseOffset + text.length() != extentOffset) 294 if (baseOffset + text.length() != extentOffset)
286 return; 295 return;
287 296
288 m_compositionNode = toText(baseNode); 297 m_isDirty = true;
289 m_compositionStart = baseOffset; 298 m_hasComposition = true;
290 m_compositionEnd = extentOffset; 299 if (!m_compositionRange)
291 m_customCompositionUnderlines = underlines; 300 m_compositionRange = Range::create(baseNode->document());
292 for (auto& underline : m_customCompositionUnderlines) { 301 m_compositionRange->setStart(baseNode, baseOffset);
293 underline.startOffset += baseOffset; 302 m_compositionRange->setEnd(baseNode, extentOffset);
294 underline.endOffset += baseOffset; 303
295 }
296 if (baseNode->layoutObject()) 304 if (baseNode->layoutObject())
297 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); 305 baseNode->layoutObject()->setShouldDoFullPaintInvalidation();
298 306
299 unsigned start = std::min(baseOffset + selectionStart, extentOffset); 307 unsigned start = std::min(baseOffset + selectionStart, extentOffset);
300 unsigned end = std::min(std::max(start, baseOffset + selectionEnd), extentOf fset); 308 unsigned end = std::min(std::max(start, baseOffset + selectionEnd), extentOf fset);
301 RefPtrWillBeRawPtr<Range> selectedRange = Range::create(baseNode->document() , baseNode, start, baseNode, end); 309 RefPtrWillBeRawPtr<Range> selectedRange = Range::create(baseNode->document() , baseNode, start, baseNode, end);
302 frame().selection().setSelectedRange(selectedRange.get(), TextAffinity::Down stream, FrameSelection::NonDirectional, NotUserTriggered); 310 frame().selection().setSelectedRange(selectedRange.get(), TextAffinity::Down stream, FrameSelection::NonDirectional, NotUserTriggered);
311
312 if (underlines.isEmpty()) {
313 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor());
314 return;
315 }
316 for (const auto& underline : underlines) {
317 unsigned underlineStart = baseOffset + underline.startOffset;
318 unsigned underlineEnd = baseOffset + underline.endOffset;
319 EphemeralRange ephemeralLineRange = EphemeralRange(Position(baseNode, un derlineStart), Position(baseNode, underlineEnd));
320 if (ephemeralLineRange.isNull())
321 continue;
322 frame().document()->markers().addCompositionMarker(ephemeralLineRange.st artPosition(), ephemeralLineRange.endPosition(), underline.color, underline.thic k, underline.backgroundColor);
323 }
303 } 324 }
304 325
305 void InputMethodController::setCompositionFromExistingText(const Vector<Composit ionUnderline>& underlines, unsigned compositionStart, unsigned compositionEnd) 326 void InputMethodController::setCompositionFromExistingText(const Vector<Composit ionUnderline>& underlines, unsigned compositionStart, unsigned compositionEnd)
306 { 327 {
307 Element* editable = frame().selection().rootEditableElement(); 328 Element* editable = frame().selection().rootEditableElement();
308 Position base = mostForwardCaretPosition(frame().selection().base()); 329 if (!editable)
309 Node* baseNode = base.anchorNode(); 330 return;
310 if (baseNode && editable->firstChild() == baseNode && editable->lastChild() == baseNode && baseNode->isTextNode()) {
311 m_compositionNode = nullptr;
312 m_customCompositionUnderlines.clear();
313 331
314 if (!base.isOffsetInAnchor()) 332 const EphemeralRange range = PlainTextRange(compositionStart, compositionEnd ).createRange(*editable);
315 return; 333 if (range.isNull())
316 if (baseNode != frame().selection().extent().anchorNode()) 334 return;
317 return;
318 335
319 m_compositionNode = toText(baseNode); 336 const Position start = range.startPosition();
320 const EphemeralRange range = PlainTextRange(compositionStart, compositio nEnd).createRange(*editable); 337 if (editableRootForPosition(start) != editable)
321 if (range.isNull()) 338 return;
322 return;
323 339
324 m_compositionStart = range.startPosition().computeOffsetInContainerNode( ); 340 const Position end = range.endPosition();
325 m_compositionEnd = range.endPosition().computeOffsetInContainerNode(); 341 if (editableRootForPosition(end) != editable)
326 m_customCompositionUnderlines = underlines;
327 size_t numUnderlines = m_customCompositionUnderlines.size();
328 for (size_t i = 0; i < numUnderlines; ++i) {
329 m_customCompositionUnderlines[i].startOffset += m_compositionStart;
330 m_customCompositionUnderlines[i].endOffset += m_compositionStart;
331 }
332 if (baseNode->layoutObject())
333 baseNode->layoutObject()->setShouldDoFullPaintInvalidation();
334 return; 342 return;
343
344 clear();
345
346 for (const auto& underline : underlines) {
347 unsigned underlineStart = compositionStart + underline.startOffset;
348 unsigned underlineEnd = compositionStart + underline.endOffset;
349 EphemeralRange ephemeralLineRange = PlainTextRange(underlineStart, under lineEnd).createRange(*editable);
350 if (ephemeralLineRange.isNull())
351 continue;
352 frame().document()->markers().addCompositionMarker(ephemeralLineRange.st artPosition(), ephemeralLineRange.endPosition(), underline.color, underline.thic k, underline.backgroundColor);
335 } 353 }
336 354
337 Editor::RevealSelectionScope revealSelectionScope(&editor()); 355 m_hasComposition = true;
338 SelectionOffsetsScope selectionOffsetsScope(this); 356 if (!m_compositionRange)
339 setSelectionOffsets(PlainTextRange(compositionStart, compositionEnd)); 357 m_compositionRange = Range::create(range.document());
340 setComposition(frame().selectedText(), underlines, 0, 0); 358 m_compositionRange->setStart(range.startPosition());
359 m_compositionRange->setEnd(range.endPosition());
341 } 360 }
342 361
343 EphemeralRange InputMethodController::compositionEphemeralRange() const 362 EphemeralRange InputMethodController::compositionEphemeralRange() const
344 { 363 {
345 if (!hasComposition()) 364 if (!hasComposition())
346 return EphemeralRange(); 365 return EphemeralRange();
347 unsigned length = m_compositionNode->length(); 366 return EphemeralRange(m_compositionRange.get());
348 unsigned start = std::min(m_compositionStart, length);
349 unsigned end = std::min(std::max(start, m_compositionEnd), length);
350 if (start >= end)
351 return EphemeralRange();
352 return EphemeralRange(Position(m_compositionNode.get(), start), Position(m_c ompositionNode.get(), end));
353 } 367 }
354 368
355 PassRefPtrWillBeRawPtr<Range> InputMethodController::compositionRange() const 369 PassRefPtrWillBeRawPtr<Range> InputMethodController::compositionRange() const
yosin_UTC9 2015/09/10 09:42:28 It seems we should return raw pointer |Range*|.
aelias_OOO_until_Jul13 2015/09/10 19:59:28 Looks like I can't, because this is used for WebRa
356 { 370 {
357 return createRange(compositionEphemeralRange()); 371 return hasComposition() ? m_compositionRange : nullptr;
358 } 372 }
359 373
360 PlainTextRange InputMethodController::getSelectionOffsets() const 374 PlainTextRange InputMethodController::getSelectionOffsets() const
361 { 375 {
362 RefPtrWillBeRawPtr<Range> range = firstRangeOf(frame().selection().selection ()); 376 RefPtrWillBeRawPtr<Range> range = firstRangeOf(frame().selection().selection ());
363 if (!range) 377 if (!range)
364 return PlainTextRange(); 378 return PlainTextRange();
365 ContainerNode* editable = frame().selection().rootEditableElementOrTreeScope RootNode(); 379 ContainerNode* editable = frame().selection().rootEditableElementOrTreeScope RootNode();
366 ASSERT(editable); 380 ASSERT(editable);
367 return PlainTextRange::create(*editable, *range.get()); 381 return PlainTextRange::create(*editable, *range.get());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (before == 0) 429 if (before == 0)
416 break; 430 break;
417 ++before; 431 ++before;
418 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); 432 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start()));
419 TypingCommand::deleteSelection(*frame().document()); 433 TypingCommand::deleteSelection(*frame().document());
420 } 434 }
421 435
422 DEFINE_TRACE(InputMethodController) 436 DEFINE_TRACE(InputMethodController)
423 { 437 {
424 visitor->trace(m_frame); 438 visitor->trace(m_frame);
425 visitor->trace(m_compositionNode); 439 visitor->trace(m_compositionRange);
426 } 440 }
427 441
428 } // namespace blink 442 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/InputMethodController.h ('k') | Source/core/editing/markers/DocumentMarker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698