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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 m_customCompositionUnderlines.clear(); | 88 m_customCompositionUnderlines.clear(); |
89 } | 89 } |
90 | 90 |
91 bool InputMethodController::insertTextForConfirmedComposition(const String& text
) | 91 bool InputMethodController::insertTextForConfirmedComposition(const String& text
) |
92 { | 92 { |
93 return m_frame.eventHandler().handleTextInputEvent(text, 0, TextEventInputCo
mposition); | 93 return m_frame.eventHandler().handleTextInputEvent(text, 0, TextEventInputCo
mposition); |
94 } | 94 } |
95 | 95 |
96 void InputMethodController::selectComposition() const | 96 void InputMethodController::selectComposition() const |
97 { | 97 { |
98 RefPtr<Range> range = compositionRange(); | 98 RefPtrWillBeRawPtr<Range> range = compositionRange(); |
99 if (!range) | 99 if (!range) |
100 return; | 100 return; |
101 | 101 |
102 // The composition can start inside a composed character sequence, so we hav
e to override checks. | 102 // The composition can start inside a composed character sequence, so we hav
e to override checks. |
103 // See <http://bugs.webkit.org/show_bug.cgi?id=15781> | 103 // See <http://bugs.webkit.org/show_bug.cgi?id=15781> |
104 VisibleSelection selection; | 104 VisibleSelection selection; |
105 selection.setWithoutValidation(range->startPosition(), range->endPosition())
; | 105 selection.setWithoutValidation(range->startPosition(), range->endPosition())
; |
106 m_frame.selection().setSelection(selection, 0); | 106 m_frame.selection().setSelection(selection, 0); |
107 } | 107 } |
108 | 108 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 size_t numUnderlines = m_customCompositionUnderlines.size(); | 302 size_t numUnderlines = m_customCompositionUnderlines.size(); |
303 for (size_t i = 0; i < numUnderlines; ++i) { | 303 for (size_t i = 0; i < numUnderlines; ++i) { |
304 m_customCompositionUnderlines[i].startOffset += baseOffset; | 304 m_customCompositionUnderlines[i].startOffset += baseOffset; |
305 m_customCompositionUnderlines[i].endOffset += baseOffset; | 305 m_customCompositionUnderlines[i].endOffset += baseOffset; |
306 } | 306 } |
307 if (baseNode->renderer()) | 307 if (baseNode->renderer()) |
308 baseNode->renderer()->repaint(); | 308 baseNode->renderer()->repaint(); |
309 | 309 |
310 unsigned start = std::min(baseOffset + selectionStart, extentOffset)
; | 310 unsigned start = std::min(baseOffset + selectionStart, extentOffset)
; |
311 unsigned end = std::min(std::max(start, baseOffset + selectionEnd),
extentOffset); | 311 unsigned end = std::min(std::max(start, baseOffset + selectionEnd),
extentOffset); |
312 RefPtr<Range> selectedRange = Range::create(baseNode->document(), ba
seNode, start, baseNode, end); | 312 RefPtrWillBeRawPtr<Range> selectedRange = Range::create(baseNode->do
cument(), baseNode, start, baseNode, end); |
313 m_frame.selection().setSelectedRange(selectedRange.get(), DOWNSTREAM
, static_cast<FrameSelection::SetSelectionOption>(0)); | 313 m_frame.selection().setSelectedRange(selectedRange.get(), DOWNSTREAM
, static_cast<FrameSelection::SetSelectionOption>(0)); |
314 } | 314 } |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 void InputMethodController::setCompositionFromExistingText(const Vector<Composit
ionUnderline>& underlines, unsigned compositionStart, unsigned compositionEnd) | 318 void InputMethodController::setCompositionFromExistingText(const Vector<Composit
ionUnderline>& underlines, unsigned compositionStart, unsigned compositionEnd) |
319 { | 319 { |
320 Node* editable = m_frame.selection().rootEditableElement(); | 320 Node* editable = m_frame.selection().rootEditableElement(); |
321 Position base = m_frame.selection().base().downstream(); | 321 Position base = m_frame.selection().base().downstream(); |
322 Node* baseNode = base.anchorNode(); | 322 Node* baseNode = base.anchorNode(); |
(...skipping 19 matching lines...) Expand all Loading... |
342 baseNode->renderer()->repaint(); | 342 baseNode->renderer()->repaint(); |
343 return; | 343 return; |
344 } | 344 } |
345 | 345 |
346 Editor::RevealSelectionScope revealSelectionScope(&editor()); | 346 Editor::RevealSelectionScope revealSelectionScope(&editor()); |
347 SelectionOffsetsScope selectionOffsetsScope(this); | 347 SelectionOffsetsScope selectionOffsetsScope(this); |
348 setSelectionOffsets(PlainTextRange(compositionStart, compositionEnd)); | 348 setSelectionOffsets(PlainTextRange(compositionStart, compositionEnd)); |
349 setComposition(m_frame.selectedText(), underlines, 0, 0); | 349 setComposition(m_frame.selectedText(), underlines, 0, 0); |
350 } | 350 } |
351 | 351 |
352 PassRefPtr<Range> InputMethodController::compositionRange() const | 352 PassRefPtrWillBeRawPtr<Range> InputMethodController::compositionRange() const |
353 { | 353 { |
354 if (!hasComposition()) | 354 if (!hasComposition()) |
355 return nullptr; | 355 return nullptr; |
356 unsigned length = m_compositionNode->length(); | 356 unsigned length = m_compositionNode->length(); |
357 unsigned start = std::min(m_compositionStart, length); | 357 unsigned start = std::min(m_compositionStart, length); |
358 unsigned end = std::min(std::max(start, m_compositionEnd), length); | 358 unsigned end = std::min(std::max(start, m_compositionEnd), length); |
359 if (start >= end) | 359 if (start >= end) |
360 return nullptr; | 360 return nullptr; |
361 return Range::create(m_compositionNode->document(), m_compositionNode.get(),
start, m_compositionNode.get(), end); | 361 return Range::create(m_compositionNode->document(), m_compositionNode.get(),
start, m_compositionNode.get(), end); |
362 } | 362 } |
363 | 363 |
364 PlainTextRange InputMethodController::getSelectionOffsets() const | 364 PlainTextRange InputMethodController::getSelectionOffsets() const |
365 { | 365 { |
366 RefPtr<Range> range = m_frame.selection().selection().firstRange(); | 366 RefPtrWillBeRawPtr<Range> range = m_frame.selection().selection().firstRange
(); |
367 if (!range) | 367 if (!range) |
368 return PlainTextRange(); | 368 return PlainTextRange(); |
369 Node* editable = m_frame.selection().rootEditableElementOrTreeScopeRootNode(
); | 369 Node* editable = m_frame.selection().rootEditableElementOrTreeScopeRootNode(
); |
370 ASSERT(editable); | 370 ASSERT(editable); |
371 return PlainTextRange::create(*editable, *range.get()); | 371 return PlainTextRange::create(*editable, *range.get()); |
372 } | 372 } |
373 | 373 |
374 bool InputMethodController::setSelectionOffsets(const PlainTextRange& selectionO
ffsets) | 374 bool InputMethodController::setSelectionOffsets(const PlainTextRange& selectionO
ffsets) |
375 { | 375 { |
376 if (selectionOffsets.isNull()) | 376 if (selectionOffsets.isNull()) |
377 return false; | 377 return false; |
378 Element* rootEditableElement = m_frame.selection().rootEditableElement(); | 378 Element* rootEditableElement = m_frame.selection().rootEditableElement(); |
379 if (!rootEditableElement) | 379 if (!rootEditableElement) |
380 return false; | 380 return false; |
381 | 381 |
382 RefPtr<Range> range = selectionOffsets.createRange(*rootEditableElement); | 382 RefPtrWillBeRawPtr<Range> range = selectionOffsets.createRange(*rootEditable
Element); |
383 if (!range) | 383 if (!range) |
384 return false; | 384 return false; |
385 | 385 |
386 return m_frame.selection().setSelectedRange(range.get(), VP_DEFAULT_AFFINITY
, FrameSelection::CloseTyping); | 386 return m_frame.selection().setSelectedRange(range.get(), VP_DEFAULT_AFFINITY
, FrameSelection::CloseTyping); |
387 } | 387 } |
388 | 388 |
389 bool InputMethodController::setEditableSelectionOffsets(const PlainTextRange& se
lectionOffsets) | 389 bool InputMethodController::setEditableSelectionOffsets(const PlainTextRange& se
lectionOffsets) |
390 { | 390 { |
391 if (!editor().canEdit()) | 391 if (!editor().canEdit()) |
392 return false; | 392 return false; |
393 return setSelectionOffsets(selectionOffsets); | 393 return setSelectionOffsets(selectionOffsets); |
394 } | 394 } |
395 | 395 |
396 void InputMethodController::extendSelectionAndDelete(int before, int after) | 396 void InputMethodController::extendSelectionAndDelete(int before, int after) |
397 { | 397 { |
398 if (!editor().canEdit()) | 398 if (!editor().canEdit()) |
399 return; | 399 return; |
400 PlainTextRange selectionOffsets(getSelectionOffsets()); | 400 PlainTextRange selectionOffsets(getSelectionOffsets()); |
401 if (selectionOffsets.isNull()) | 401 if (selectionOffsets.isNull()) |
402 return; | 402 return; |
403 setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(selectionOffset
s.start()) - before, 0), selectionOffsets.end() + after)); | 403 setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(selectionOffset
s.start()) - before, 0), selectionOffsets.end() + after)); |
404 TypingCommand::deleteSelection(*m_frame.document()); | 404 TypingCommand::deleteSelection(*m_frame.document()); |
405 } | 405 } |
406 | 406 |
407 } // namespace WebCore | 407 } // namespace WebCore |
OLD | NEW |