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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 244 |
245 // No DOM update after 'compositionend'. | 245 // No DOM update after 'compositionend'. |
246 dispatchCompositionEndEvent(frame(), composing); | 246 dispatchCompositionEndEvent(frame(), composing); |
247 | 247 |
248 return result; | 248 return result; |
249 } | 249 } |
250 | 250 |
251 return replaceCompositionAndMoveCaret(composingText(), 0); | 251 return replaceCompositionAndMoveCaret(composingText(), 0); |
252 } | 252 } |
253 | 253 |
254 bool InputMethodController::commitText(const String& text, | 254 bool InputMethodController::commitText( |
255 int relativeCaretPosition) { | 255 const String& text, |
| 256 const Vector<CompositionUnderline>& underlines, |
| 257 int relativeCaretPosition) { |
256 if (hasComposition()) | 258 if (hasComposition()) |
257 return replaceCompositionAndMoveCaret(text, relativeCaretPosition); | 259 return replaceCompositionAndMoveCaret(text, relativeCaretPosition); |
258 | 260 |
259 // We should do nothing in this case, because: | 261 // We should do nothing in this case, because: |
260 // 1. No need to insert text when text is empty. | 262 // 1. No need to insert text when text is empty. |
261 // 2. Shouldn't move caret when relativeCaretPosition == 0 to avoid | 263 // 2. Shouldn't move caret when relativeCaretPosition == 0 to avoid |
262 // duplicate selection change event. | 264 // duplicate selection change event. |
263 if (!text.length() && !relativeCaretPosition) | 265 if (!text.length() && !relativeCaretPosition) |
264 return false; | 266 return false; |
265 return insertTextAndMoveCaret(text, relativeCaretPosition); | 267 |
| 268 if (!insertTextAndMoveCaret(text, relativeCaretPosition)) |
| 269 return false; |
| 270 |
| 271 Position base = mostForwardCaretPosition(frame().selection().base()); |
| 272 Node* baseNode = base.anchorNode(); |
| 273 |
| 274 if (!baseNode || !baseNode->isTextNode()) |
| 275 return true; |
| 276 |
| 277 unsigned baseOffset = base.computeOffsetInContainerNode(); |
| 278 |
| 279 for (const auto& underline : underlines) { |
| 280 unsigned underlineStart = baseOffset + underline.startOffset(); |
| 281 unsigned underlineEnd = baseOffset + underline.endOffset(); |
| 282 |
| 283 EphemeralRange ephemeralLineRange = EphemeralRange( |
| 284 Position(baseNode, underlineStart), Position(baseNode, underlineEnd)); |
| 285 if (ephemeralLineRange.isNull()) |
| 286 continue; |
| 287 document().markers().addCompositionMarker( |
| 288 ephemeralLineRange.startPosition(), ephemeralLineRange.endPosition(), |
| 289 underline.color(), underline.thick(), underline.backgroundColor()); |
| 290 } |
| 291 |
| 292 return true; |
266 } | 293 } |
267 | 294 |
268 bool InputMethodController::replaceComposition(const String& text) { | 295 bool InputMethodController::replaceComposition(const String& text) { |
269 if (!hasComposition()) | 296 if (!hasComposition()) |
270 return false; | 297 return false; |
271 | 298 |
272 // If the composition was set from existing text and didn't change, then | 299 // If the composition was set from existing text and didn't change, then |
273 // there's nothing to do here (and we should avoid doing anything as that | 300 // there's nothing to do here (and we should avoid doing anything as that |
274 // may clobber multi-node styled text). | 301 // may clobber multi-node styled text). |
275 if (!m_isDirty && composingText() == text) { | 302 if (!m_isDirty && composingText() == text) { |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 frame().chromeClient().resetInputMethod(); | 1226 frame().chromeClient().resetInputMethod(); |
1200 } | 1227 } |
1201 | 1228 |
1202 DEFINE_TRACE(InputMethodController) { | 1229 DEFINE_TRACE(InputMethodController) { |
1203 visitor->trace(m_frame); | 1230 visitor->trace(m_frame); |
1204 visitor->trace(m_compositionRange); | 1231 visitor->trace(m_compositionRange); |
1205 SynchronousMutationObserver::trace(visitor); | 1232 SynchronousMutationObserver::trace(visitor); |
1206 } | 1233 } |
1207 | 1234 |
1208 } // namespace blink | 1235 } // namespace blink |
OLD | NEW |