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

Side by Side Diff: Source/core/html/HTMLTextFormControlElement.cpp

Issue 1213483003: Get rid of redundant parameter PositionIsOffsetInAnchor from PositionAlgorithm constructor (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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) 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 280
281 return setSelectionRange(start, end, direction); 281 return setSelectionRange(start, end, direction);
282 } 282 }
283 283
284 static Position positionForIndex(HTMLElement* innerEditor, int index) 284 static Position positionForIndex(HTMLElement* innerEditor, int index)
285 { 285 {
286 ASSERT(index >= 0); 286 ASSERT(index >= 0);
287 if (index == 0) { 287 if (index == 0) {
288 Node* node = NodeTraversal::next(*innerEditor, innerEditor); 288 Node* node = NodeTraversal::next(*innerEditor, innerEditor);
289 if (node && node->isTextNode()) 289 if (node && node->isTextNode())
290 return Position(node, 0, Position::PositionIsOffsetInAnchor); 290 return Position(node, 0);
291 return Position(innerEditor, 0, Position::PositionIsOffsetInAnchor); 291 return Position(innerEditor, 0);
292 } 292 }
293 int remainingCharactersToMoveForward = index; 293 int remainingCharactersToMoveForward = index;
294 Node* lastBrOrText = innerEditor; 294 Node* lastBrOrText = innerEditor;
295 for (Node& node : NodeTraversal::descendantsOf(*innerEditor)) { 295 for (Node& node : NodeTraversal::descendantsOf(*innerEditor)) {
296 ASSERT(remainingCharactersToMoveForward >= 0); 296 ASSERT(remainingCharactersToMoveForward >= 0);
297 if (node.hasTagName(brTag)) { 297 if (node.hasTagName(brTag)) {
298 if (remainingCharactersToMoveForward == 0) 298 if (remainingCharactersToMoveForward == 0)
299 return positionBeforeNode(&node); 299 return positionBeforeNode(&node);
300 --remainingCharactersToMoveForward; 300 --remainingCharactersToMoveForward;
301 lastBrOrText = &node; 301 lastBrOrText = &node;
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 } 770 }
771 771
772 static Position innerNodePosition(const Position& innerPosition) 772 static Position innerNodePosition(const Position& innerPosition)
773 { 773 {
774 ASSERT(innerPosition.anchorType() != Position::PositionIsBeforeAnchor); 774 ASSERT(innerPosition.anchorType() != Position::PositionIsBeforeAnchor);
775 ASSERT(innerPosition.anchorType() != Position::PositionIsAfterAnchor); 775 ASSERT(innerPosition.anchorType() != Position::PositionIsAfterAnchor);
776 HTMLElement* element = toHTMLElement(innerPosition.anchorNode()); 776 HTMLElement* element = toHTMLElement(innerPosition.anchorNode());
777 ASSERT(element); 777 ASSERT(element);
778 RefPtrWillBeRawPtr<NodeList> childNodes = element->childNodes(); 778 RefPtrWillBeRawPtr<NodeList> childNodes = element->childNodes();
779 if (!childNodes->length()) 779 if (!childNodes->length())
780 return Position(element, 0, Position::PositionIsOffsetInAnchor); 780 return Position(element, 0);
781 781
782 unsigned offset = 0; 782 unsigned offset = 0;
783 783
784 switch (innerPosition.anchorType()) { 784 switch (innerPosition.anchorType()) {
785 case Position::PositionIsOffsetInAnchor: 785 case Position::PositionIsOffsetInAnchor:
786 offset = std::max(0, std::min(innerPosition.offsetInContainerNode(), sta tic_cast<int>(childNodes->length()))); 786 offset = std::max(0, std::min(innerPosition.offsetInContainerNode(), sta tic_cast<int>(childNodes->length())));
787 break; 787 break;
788 case Position::PositionIsAfterChildren: 788 case Position::PositionIsAfterChildren:
789 offset = childNodes->length(); 789 offset = childNodes->length();
790 break; 790 break;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 if (offset <= textNode->length() && textNode->data()[offset - 1] == '\n' ) { 933 if (offset <= textNode->length() && textNode->data()[offset - 1] == '\n' ) {
934 return Position(textNode, offset - 1); 934 return Position(textNode, offset - 1);
935 } 935 }
936 } 936 }
937 937
938 return position; 938 return position;
939 } 939 }
940 940
941 static inline Position startOfInnerText(const HTMLTextFormControlElement* textFo rmControl) 941 static inline Position startOfInnerText(const HTMLTextFormControlElement* textFo rmControl)
942 { 942 {
943 return Position(textFormControl->innerEditorElement(), 0, Position::Position IsOffsetInAnchor); 943 return Position(textFormControl->innerEditorElement(), 0);
944 } 944 }
945 945
946 Position HTMLTextFormControlElement::startOfSentence(const Position& position) 946 Position HTMLTextFormControlElement::startOfSentence(const Position& position)
947 { 947 {
948 HTMLTextFormControlElement* textFormControl = enclosingTextFormControl(posit ion); 948 HTMLTextFormControlElement* textFormControl = enclosingTextFormControl(posit ion);
949 ASSERT(textFormControl); 949 ASSERT(textFormControl);
950 950
951 HTMLElement* innerEditor = textFormControl->innerEditorElement(); 951 HTMLElement* innerEditor = textFormControl->innerEditorElement();
952 if (!innerEditor->childNodes()->length()) 952 if (!innerEditor->childNodes()->length())
953 return startOfInnerText(textFormControl); 953 return startOfInnerText(textFormControl);
(...skipping 15 matching lines...) Expand all
969 if (lastLineBreak != kNotFound) 969 if (lastLineBreak != kNotFound)
970 return Position(textNode, lastLineBreak + 1); 970 return Position(textNode, lastLineBreak + 1);
971 } 971 }
972 } 972 }
973 return startOfInnerText(textFormControl); 973 return startOfInnerText(textFormControl);
974 } 974 }
975 975
976 static Position endOfInnerText(const HTMLTextFormControlElement* textFormControl ) 976 static Position endOfInnerText(const HTMLTextFormControlElement* textFormControl )
977 { 977 {
978 HTMLElement* innerEditor = textFormControl->innerEditorElement(); 978 HTMLElement* innerEditor = textFormControl->innerEditorElement();
979 return Position(innerEditor, innerEditor->childNodes()->length(), Position:: PositionIsOffsetInAnchor); 979 return Position(innerEditor, innerEditor->childNodes()->length());
980 } 980 }
981 981
982 Position HTMLTextFormControlElement::endOfSentence(const Position& position) 982 Position HTMLTextFormControlElement::endOfSentence(const Position& position)
983 { 983 {
984 HTMLTextFormControlElement* textFormControl = enclosingTextFormControl(posit ion); 984 HTMLTextFormControlElement* textFormControl = enclosingTextFormControl(posit ion);
985 ASSERT(textFormControl); 985 ASSERT(textFormControl);
986 986
987 HTMLElement* innerEditor = textFormControl->innerEditorElement(); 987 HTMLElement* innerEditor = textFormControl->innerEditorElement();
988 if (innerEditor->childNodes()->length() == 0) 988 if (innerEditor->childNodes()->length() == 0)
989 return startOfInnerText(textFormControl); 989 return startOfInnerText(textFormControl);
(...skipping 19 matching lines...) Expand all
1009 } 1009 }
1010 1010
1011 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele ment& source) 1011 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele ment& source)
1012 { 1012 {
1013 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText FormControlElement&>(source); 1013 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText FormControlElement&>(source);
1014 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; 1014 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit;
1015 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); 1015 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source);
1016 } 1016 }
1017 1017
1018 } // namespace blink 1018 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/iterators/TextIteratorTest.cpp ('k') | Source/core/html/HTMLTextFormControlElementTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698