Changeset 90885 in webkit
- Timestamp:
- Jul 12, 2011 9:23:03 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r90882 r90885 1 2011-07-12 Ryosuke Niwa <rniwa@webkit.org> 2 3 Move RenderTextControl::indexForVisiblePosition to HTMLTextFormControlElement 4 https://bugs.webkit.org/show_bug.cgi?id=64403 5 6 Reviewed by Hajime Morita. 7 8 Moved indexForVisiblePosition from RenderTextControl to HTMLTextFormControlElement. 9 10 Also replaced the call to RenderTextControl::isSelectableElement by a call to enclosingTextFormControl 11 (moved from htmlediting to HTMLTextFormControlElement) because we are only interested in checking 12 whether the given position is inside the current text form control or not. 13 14 In addition, modernized the code in indexForVisiblePosition by calling parentAnchoredEquivalent on the 15 given position and replacing calls to deprecateNode and deprecatedEditingOffset by calls to containerNode 16 and offsetInContainer. 17 18 * accessibility/AccessibilityRenderObject.cpp: 19 (WebCore::AccessibilityRenderObject::indexForVisiblePosition): Calls indexForVisiblePosition. 20 * editing/htmlediting.cpp: Removed enclosingTextFromControl. 21 * editing/htmlediting.h: Removed enclosingTextFromControl. 22 * html/HTMLTextFormControlElement.cpp: 23 (WebCore::HTMLTextFormControlElement::indexForVisiblePosition): Moved from RenderTextControl. 24 (WebCore::HTMLTextFormControlElement::computeSelectionStart): Calls indexForVisiblePosition. 25 (WebCore::HTMLTextFormControlElement::computeSelectionEnd): Calls indexForVisiblePosition. 26 (WebCore::enclosingTextFormControl): Moved from htmlediting.cpp 27 * html/HTMLTextFormControlElement.h: 28 * rendering/RenderTextControl.cpp: 29 * rendering/RenderTextControl.h: 30 1 31 2011-07-12 Julien Chaffraix <jchaffraix@webkit.org> 2 32 -
trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
r90775 r90885 2496 2496 if (isNativeTextControl()) { 2497 2497 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement(); 2498 return RenderTextControl::indexForVisiblePosition(textControl->innerTextElement(),pos);2498 return textControl->indexForVisiblePosition(pos); 2499 2499 } 2500 2500 -
trunk/Source/WebCore/editing/htmlediting.cpp
r90849 r90885 857 857 return isTabSpanTextNode(node) ? node->parentNode() : 0; 858 858 } 859 860 HTMLTextFormControlElement* enclosingTextFormControl(const Position& position)861 {862 ASSERT(position.isNull() || position.anchorType() == Position::PositionIsOffsetInAnchor863 || position.containerNode() || !position.anchorNode()->shadowAncestorNode());864 Node* container = position.containerNode();865 if (!container)866 return 0;867 Node* ancestor = container->shadowAncestorNode();868 return ancestor != container ? toTextFormControl(ancestor) : 0;869 }870 859 871 860 Position positionOutsideTabSpan(const Position& pos) -
trunk/Source/WebCore/editing/htmlediting.h
r90098 r90885 219 219 Element* editableRootForPosition(const Position&); 220 220 Element* unsplittableElementForPosition(const Position&); 221 HTMLTextFormControlElement* enclosingTextFormControl(const Position&);222 221 223 222 // Boolean functions on Element -
trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp
r90849 r90885 38 38 #include "RenderTheme.h" 39 39 #include "ScriptEventListener.h" 40 #include "TextIterator.h" 40 41 #include <wtf/Vector.h> 41 42 … … 214 215 } 215 216 217 int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& pos) const 218 { 219 Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent(); 220 if (enclosingTextFormControl(indexPosition) != this) 221 return 0; 222 ExceptionCode ec = 0; 223 RefPtr<Range> range = Range::create(indexPosition.document()); 224 range->setStart(innerTextElement(), 0, ec); 225 ASSERT(!ec); 226 range->setEnd(indexPosition.containerNode(), indexPosition.offsetInContainerNode(), ec); 227 ASSERT(!ec); 228 return TextIterator::rangeLength(range.get()); 229 } 230 216 231 int HTMLTextFormControlElement::selectionStart() const 217 232 { … … 230 245 return 0; 231 246 232 return RenderTextControl::indexForVisiblePosition(innerTextElement(),frame->selection()->start());247 return indexForVisiblePosition(frame->selection()->start()); 233 248 } 234 249 … … 248 263 return 0; 249 264 250 return RenderTextControl::indexForVisiblePosition(innerTextElement(),frame->selection()->end());265 return indexForVisiblePosition(frame->selection()->end()); 251 266 } 252 267 … … 334 349 } 335 350 351 HTMLTextFormControlElement* enclosingTextFormControl(const Position& position) 352 { 353 ASSERT(position.isNull() || position.anchorType() == Position::PositionIsOffsetInAnchor 354 || position.containerNode() || !position.anchorNode()->shadowAncestorNode()); 355 Node* container = position.containerNode(); 356 if (!container) 357 return 0; 358 Node* ancestor = container->shadowAncestorNode(); 359 return ancestor != container ? toTextFormControl(ancestor) : 0; 360 } 361 336 362 } // namespace Webcore -
trunk/Source/WebCore/html/HTMLTextFormControlElement.h
r90849 r90885 29 29 namespace WebCore { 30 30 31 class Position; 31 32 class RenderTextControl; 33 class VisiblePosition; 32 34 33 35 class HTMLTextFormControlElement : public HTMLFormControlElementWithState { … … 45 47 bool placeholderShouldBeVisible() const; 46 48 49 int indexForVisiblePosition(const VisiblePosition&) const; 47 50 int selectionStart() const; 48 51 int selectionEnd() const; … … 116 119 } 117 120 121 HTMLTextFormControlElement* enclosingTextFormControl(const Position&); 122 118 123 } // namespace 119 124 -
trunk/Source/WebCore/rendering/RenderTextControl.cpp
r90775 r90885 30 30 #include "FrameSelection.h" 31 31 #include "HTMLBRElement.h" 32 #include "HTMLFormControlElement.h"33 32 #include "HTMLInputElement.h" 34 33 #include "HTMLNames.h" … … 39 38 #include "ScrollbarTheme.h" 40 39 #include "Text.h" 41 #include "TextControlInnerElements.h"42 40 #include "TextIterator.h" 43 41 #include <wtf/text/StringBuilder.h> … … 184 182 } 185 183 186 bool RenderTextControl::isSelectableElement(HTMLElement* innerText, Node* node)187 {188 if (!node || !innerText)189 return false;190 191 if (node->rootEditableElement() == innerText)192 return true;193 194 if (!innerText->contains(node))195 return false;196 197 Node* shadowAncestor = node->shadowAncestorNode();198 return shadowAncestor && (shadowAncestor->hasTagName(textareaTag)199 || (shadowAncestor->hasTagName(inputTag) && static_cast<HTMLInputElement*>(shadowAncestor)->isTextField()));200 }201 202 184 VisiblePosition RenderTextControl::visiblePositionForIndex(int index) const 203 185 { … … 211 193 it.advance(index - 1); 212 194 return VisiblePosition(it.range()->endPosition(), UPSTREAM); 213 }214 215 int RenderTextControl::indexForVisiblePosition(HTMLElement* innerTextElement, const VisiblePosition& pos)216 {217 Position indexPosition = pos.deepEquivalent();218 if (!RenderTextControl::isSelectableElement(innerTextElement, indexPosition.deprecatedNode()))219 return 0;220 ExceptionCode ec = 0;221 RefPtr<Range> range = Range::create(indexPosition.document());222 range->setStart(innerTextElement, 0, ec);223 ASSERT(!ec);224 range->setEnd(indexPosition.deprecatedNode(), indexPosition.deprecatedEditingOffset(), ec);225 ASSERT(!ec);226 return TextIterator::rangeLength(range.get());227 195 } 228 196 -
trunk/Source/WebCore/rendering/RenderTextControl.h
r90791 r90885 28 28 29 29 class HTMLTextFormControlElement; 30 class VisibleSelection;31 class TextControlInnerElement;32 class TextControlInnerTextElement;33 30 34 31 class RenderTextControl : public RenderBlock { … … 47 44 48 45 VisiblePosition visiblePositionForIndex(int index) const; 49 static int indexForVisiblePosition(HTMLElement*, const VisiblePosition&);50 46 51 47 void updatePlaceholderVisibility(bool, bool);
Note: See TracChangeset
for help on using the changeset viewer.