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

Side by Side Diff: third_party/WebKit/Source/core/html/TextControlElement.cpp

Issue 2727923002: Make TextControlElement::indexForVisiblePosition() not to use temporary Range (Closed)
Patch Set: 2017-03-02T16:16:45 Created 3 years, 9 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 | no next file » | 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) 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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 return VisiblePosition::firstPositionInNode(innerEditorElement()); 452 return VisiblePosition::firstPositionInNode(innerEditorElement());
453 Position start, end; 453 Position start, end;
454 bool selected = Range::selectNodeContents(innerEditorElement(), start, end); 454 bool selected = Range::selectNodeContents(innerEditorElement(), start, end);
455 if (!selected) 455 if (!selected)
456 return VisiblePosition(); 456 return VisiblePosition();
457 CharacterIterator it(start, end); 457 CharacterIterator it(start, end);
458 it.advance(index - 1); 458 it.advance(index - 1);
459 return createVisiblePosition(it.endPosition(), TextAffinity::Upstream); 459 return createVisiblePosition(it.endPosition(), TextAffinity::Upstream);
460 } 460 }
461 461
462 // TODO(yosin): We should move |TextControlElement::indexForVisiblePosition()|
463 // to "AXLayoutObject.cpp" since this funciton is used only there.
462 int TextControlElement::indexForVisiblePosition( 464 int TextControlElement::indexForVisiblePosition(
463 const VisiblePosition& pos) const { 465 const VisiblePosition& pos) const {
464 Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent(); 466 Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent();
465 if (enclosingTextControl(indexPosition) != this) 467 if (enclosingTextControl(indexPosition) != this)
466 return 0; 468 return 0;
467 DCHECK(indexPosition.document()); 469 DCHECK(indexPosition.isConnected()) << indexPosition;
468 Range* range = Range::create(*indexPosition.document()); 470 return TextIterator::rangeLength(Position(innerEditorElement(), 0),
469 range->setStart(innerEditorElement(), 0, ASSERT_NO_EXCEPTION); 471 indexPosition);
470 range->setEnd(indexPosition.computeContainerNode(),
471 indexPosition.offsetInContainerNode(), ASSERT_NO_EXCEPTION);
472 return TextIterator::rangeLength(range->startPosition(),
473 range->endPosition());
474 } 472 }
475 473
476 unsigned TextControlElement::selectionStart() const { 474 unsigned TextControlElement::selectionStart() const {
477 if (!isTextControl()) 475 if (!isTextControl())
478 return 0; 476 return 0;
479 if (document().focusedElement() != this) 477 if (document().focusedElement() != this)
480 return m_cachedSelectionStart; 478 return m_cachedSelectionStart;
481 479
482 return computeSelectionStart(); 480 return computeSelectionStart();
483 } 481 }
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 935
938 void TextControlElement::copyNonAttributePropertiesFromElement( 936 void TextControlElement::copyNonAttributePropertiesFromElement(
939 const Element& source) { 937 const Element& source) {
940 const TextControlElement& sourceElement = 938 const TextControlElement& sourceElement =
941 static_cast<const TextControlElement&>(source); 939 static_cast<const TextControlElement&>(source);
942 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; 940 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit;
943 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); 941 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source);
944 } 942 }
945 943
946 } // namespace blink 944 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698