OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 unsigned newSelectionEnd = selectionEnd(); | 284 unsigned newSelectionEnd = selectionEnd(); |
285 | 285 |
286 start = std::min(start, textLength); | 286 start = std::min(start, textLength); |
287 end = std::min(end, textLength); | 287 end = std::min(end, textLength); |
288 | 288 |
289 if (start < end) | 289 if (start < end) |
290 text.replace(start, end - start, replacement); | 290 text.replace(start, end - start, replacement); |
291 else | 291 else |
292 text.insert(replacement, start); | 292 text.insert(replacement, start); |
293 | 293 |
294 setValue(text, TextFieldEventBehavior::DispatchNoEvent); | 294 setValue(text, TextFieldEventBehavior::DispatchNoEvent, |
| 295 TextControlSetValueSelection::kDoNotSet); |
295 | 296 |
296 if (selectionMode == "select") { | 297 if (selectionMode == "select") { |
297 newSelectionStart = start; | 298 newSelectionStart = start; |
298 newSelectionEnd = start + replacementLength; | 299 newSelectionEnd = start + replacementLength; |
299 } else if (selectionMode == "start") { | 300 } else if (selectionMode == "start") { |
300 newSelectionStart = newSelectionEnd = start; | 301 newSelectionStart = newSelectionEnd = start; |
301 } else if (selectionMode == "end") { | 302 } else if (selectionMode == "end") { |
302 newSelectionStart = newSelectionEnd = start + replacementLength; | 303 newSelectionStart = newSelectionEnd = start + replacementLength; |
303 } else { | 304 } else { |
304 DCHECK_EQ(selectionMode, "preserve"); | 305 DCHECK_EQ(selectionMode, "preserve"); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 TextFieldSelectionDirection direction) { | 404 TextFieldSelectionDirection direction) { |
404 if (openShadowRoot() || !isTextControl()) | 405 if (openShadowRoot() || !isTextControl()) |
405 return false; | 406 return false; |
406 const unsigned editorValueLength = innerEditorValue().length(); | 407 const unsigned editorValueLength = innerEditorValue().length(); |
407 end = std::min(end, editorValueLength); | 408 end = std::min(end, editorValueLength); |
408 start = std::min(start, end); | 409 start = std::min(start, end); |
409 LocalFrame* frame = document().frame(); | 410 LocalFrame* frame = document().frame(); |
410 if (direction == SelectionHasNoDirection && frame && | 411 if (direction == SelectionHasNoDirection && frame && |
411 frame->editor().behavior().shouldConsiderSelectionAsDirectional()) | 412 frame->editor().behavior().shouldConsiderSelectionAsDirectional()) |
412 direction = SelectionHasForwardDirection; | 413 direction = SelectionHasForwardDirection; |
413 cacheSelection(start, end, direction); | 414 bool didChange = cacheSelection(start, end, direction); |
414 | 415 |
415 if (document().focusedElement() != this) | 416 if (document().focusedElement() != this) |
416 return true; | 417 return didChange; |
417 | 418 |
418 HTMLElement* innerEditor = innerEditorElement(); | 419 HTMLElement* innerEditor = innerEditorElement(); |
419 if (!frame || !innerEditor) | 420 if (!frame || !innerEditor) |
420 return true; | 421 return didChange; |
421 | 422 |
422 Position startPosition = positionForIndex(innerEditor, start); | 423 Position startPosition = positionForIndex(innerEditor, start); |
423 Position endPosition = | 424 Position endPosition = |
424 start == end ? startPosition : positionForIndex(innerEditor, end); | 425 start == end ? startPosition : positionForIndex(innerEditor, end); |
425 | 426 |
426 DCHECK_EQ(start, indexForPosition(innerEditor, startPosition)); | 427 DCHECK_EQ(start, indexForPosition(innerEditor, startPosition)); |
427 DCHECK_EQ(end, indexForPosition(innerEditor, endPosition)); | 428 DCHECK_EQ(end, indexForPosition(innerEditor, endPosition)); |
428 | 429 |
429 #if DCHECK_IS_ON() | 430 #if DCHECK_IS_ON() |
430 // startPosition and endPosition can be null position for example when | 431 // startPosition and endPosition can be null position for example when |
431 // "-webkit-user-select: none" style attribute is specified. | 432 // "-webkit-user-select: none" style attribute is specified. |
432 if (startPosition.isNotNull() && endPosition.isNotNull()) { | 433 if (startPosition.isNotNull() && endPosition.isNotNull()) { |
433 DCHECK_EQ(startPosition.anchorNode()->ownerShadowHost(), this); | 434 DCHECK_EQ(startPosition.anchorNode()->ownerShadowHost(), this); |
434 DCHECK_EQ(endPosition.anchorNode()->ownerShadowHost(), this); | 435 DCHECK_EQ(endPosition.anchorNode()->ownerShadowHost(), this); |
435 } | 436 } |
436 #endif // DCHECK_IS_ON() | 437 #endif // DCHECK_IS_ON() |
437 frame->selection().setSelection( | 438 frame->selection().setSelection( |
438 SelectionInDOMTree::Builder() | 439 SelectionInDOMTree::Builder() |
439 .collapse(direction == SelectionHasBackwardDirection ? endPosition | 440 .collapse(direction == SelectionHasBackwardDirection ? endPosition |
440 : startPosition) | 441 : startPosition) |
441 .extend(direction == SelectionHasBackwardDirection ? startPosition | 442 .extend(direction == SelectionHasBackwardDirection ? startPosition |
442 : endPosition) | 443 : endPosition) |
443 .setIsDirectional(direction != SelectionHasNoDirection) | 444 .setIsDirectional(direction != SelectionHasNoDirection) |
444 .build(), | 445 .build(), |
445 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | | 446 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | |
446 FrameSelection::DoNotSetFocus); | 447 FrameSelection::DoNotSetFocus); |
447 return true; | 448 return didChange; |
| 449 } |
| 450 |
| 451 bool TextControlElement::cacheSelection(unsigned start, |
| 452 unsigned end, |
| 453 TextFieldSelectionDirection direction) { |
| 454 DCHECK_LE(start, end); |
| 455 bool didChange = m_cachedSelectionStart != start || |
| 456 m_cachedSelectionEnd != end || |
| 457 m_cachedSelectionDirection != direction; |
| 458 m_cachedSelectionStart = start; |
| 459 m_cachedSelectionEnd = end; |
| 460 m_cachedSelectionDirection = direction; |
| 461 return didChange; |
448 } | 462 } |
449 | 463 |
450 VisiblePosition TextControlElement::visiblePositionForIndex(int index) const { | 464 VisiblePosition TextControlElement::visiblePositionForIndex(int index) const { |
451 if (index <= 0) | 465 if (index <= 0) |
452 return VisiblePosition::firstPositionInNode(innerEditorElement()); | 466 return VisiblePosition::firstPositionInNode(innerEditorElement()); |
453 Position start, end; | 467 Position start, end; |
454 bool selected = Range::selectNodeContents(innerEditorElement(), start, end); | 468 bool selected = Range::selectNodeContents(innerEditorElement(), start, end); |
455 if (!selected) | 469 if (!selected) |
456 return VisiblePosition(); | 470 return VisiblePosition(); |
457 CharacterIterator it(start, end); | 471 CharacterIterator it(start, end); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 return; | 739 return; |
726 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree(); | 740 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree(); |
727 if (selection.selectionTypeWithLegacyGranularity() != RangeSelection) | 741 if (selection.selectionTypeWithLegacyGranularity() != RangeSelection) |
728 return; | 742 return; |
729 dispatchEvent(Event::createBubble(EventTypeNames::select)); | 743 dispatchEvent(Event::createBubble(EventTypeNames::select)); |
730 } | 744 } |
731 | 745 |
732 void TextControlElement::scheduleSelectEvent() { | 746 void TextControlElement::scheduleSelectEvent() { |
733 Event* event = Event::createBubble(EventTypeNames::select); | 747 Event* event = Event::createBubble(EventTypeNames::select); |
734 event->setTarget(this); | 748 event->setTarget(this); |
735 document().enqueueUniqueAnimationFrameEvent(event); | 749 document().enqueueAnimationFrameEvent(event); |
736 } | 750 } |
737 | 751 |
738 void TextControlElement::parseAttribute( | 752 void TextControlElement::parseAttribute( |
739 const AttributeModificationParams& params) { | 753 const AttributeModificationParams& params) { |
740 if (params.name == autocapitalizeAttr) | 754 if (params.name == autocapitalizeAttr) |
741 UseCounter::count(document(), UseCounter::AutocapitalizeAttribute); | 755 UseCounter::count(document(), UseCounter::AutocapitalizeAttribute); |
742 | 756 |
743 if (params.name == placeholderAttr) { | 757 if (params.name == placeholderAttr) { |
744 updatePlaceholderText(); | 758 updatePlaceholderText(); |
745 updatePlaceholderVisibility(); | 759 updatePlaceholderVisibility(); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 | 949 |
936 void TextControlElement::copyNonAttributePropertiesFromElement( | 950 void TextControlElement::copyNonAttributePropertiesFromElement( |
937 const Element& source) { | 951 const Element& source) { |
938 const TextControlElement& sourceElement = | 952 const TextControlElement& sourceElement = |
939 static_cast<const TextControlElement&>(source); | 953 static_cast<const TextControlElement&>(source); |
940 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; | 954 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; |
941 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); | 955 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); |
942 } | 956 } |
943 | 957 |
944 } // namespace blink | 958 } // namespace blink |
OLD | NEW |