| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 newSelection.setIsDirectional(direction != SelectionHasNoDirection); | 304 newSelection.setIsDirectional(direction != SelectionHasNoDirection); |
| 305 | 305 |
| 306 if (Frame* frame = document().frame()) | 306 if (Frame* frame = document().frame()) |
| 307 frame->selection().setSelection(newSelection); | 307 frame->selection().setSelection(newSelection); |
| 308 } | 308 } |
| 309 | 309 |
| 310 VisiblePosition HTMLTextFormControlElement::visiblePositionForIndex(int index) c
onst | 310 VisiblePosition HTMLTextFormControlElement::visiblePositionForIndex(int index) c
onst |
| 311 { | 311 { |
| 312 if (index <= 0) | 312 if (index <= 0) |
| 313 return VisiblePosition(firstPositionInNode(innerTextElement()), DOWNSTRE
AM); | 313 return VisiblePosition(firstPositionInNode(innerTextElement()), DOWNSTRE
AM); |
| 314 RefPtr<Range> range = Range::create(&document()); | 314 RefPtr<Range> range = Range::create(document()); |
| 315 range->selectNodeContents(innerTextElement(), ASSERT_NO_EXCEPTION); | 315 range->selectNodeContents(innerTextElement(), ASSERT_NO_EXCEPTION); |
| 316 CharacterIterator it(range.get()); | 316 CharacterIterator it(range.get()); |
| 317 it.advance(index - 1); | 317 it.advance(index - 1); |
| 318 return VisiblePosition(it.range()->endPosition(), UPSTREAM); | 318 return VisiblePosition(it.range()->endPosition(), UPSTREAM); |
| 319 } | 319 } |
| 320 | 320 |
| 321 int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& p
os) const | 321 int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& p
os) const |
| 322 { | 322 { |
| 323 Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent(); | 323 Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent(); |
| 324 if (enclosingTextFormControl(indexPosition) != this) | 324 if (enclosingTextFormControl(indexPosition) != this) |
| 325 return 0; | 325 return 0; |
| 326 RefPtr<Range> range = Range::create(indexPosition.document()); | 326 ASSERT(indexPosition.document()); |
| 327 RefPtr<Range> range = Range::create(*indexPosition.document()); |
| 327 range->setStart(innerTextElement(), 0, ASSERT_NO_EXCEPTION); | 328 range->setStart(innerTextElement(), 0, ASSERT_NO_EXCEPTION); |
| 328 range->setEnd(indexPosition.containerNode(), indexPosition.offsetInContainer
Node(), ASSERT_NO_EXCEPTION); | 329 range->setEnd(indexPosition.containerNode(), indexPosition.offsetInContainer
Node(), ASSERT_NO_EXCEPTION); |
| 329 return TextIterator::rangeLength(range.get()); | 330 return TextIterator::rangeLength(range.get()); |
| 330 } | 331 } |
| 331 | 332 |
| 332 int HTMLTextFormControlElement::selectionStart() const | 333 int HTMLTextFormControlElement::selectionStart() const |
| 333 { | 334 { |
| 334 if (!isTextFormControl()) | 335 if (!isTextFormControl()) |
| 335 return 0; | 336 return 0; |
| 336 if (document().focusedElement() != this && hasCachedSelection()) | 337 if (document().focusedElement() != this && hasCachedSelection()) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 427 |
| 427 int start = m_cachedSelectionStart; | 428 int start = m_cachedSelectionStart; |
| 428 int end = m_cachedSelectionEnd; | 429 int end = m_cachedSelectionEnd; |
| 429 | 430 |
| 430 ASSERT(start <= end); | 431 ASSERT(start <= end); |
| 431 HTMLElement* innerText = innerTextElement(); | 432 HTMLElement* innerText = innerTextElement(); |
| 432 if (!innerText) | 433 if (!innerText) |
| 433 return 0; | 434 return 0; |
| 434 | 435 |
| 435 if (!innerText->firstChild()) | 436 if (!innerText->firstChild()) |
| 436 return Range::create(&document(), innerText, 0, innerText, 0); | 437 return Range::create(document(), innerText, 0, innerText, 0); |
| 437 | 438 |
| 438 int offset = 0; | 439 int offset = 0; |
| 439 Node* startNode = 0; | 440 Node* startNode = 0; |
| 440 Node* endNode = 0; | 441 Node* endNode = 0; |
| 441 for (Node* node = innerText->firstChild(); node; node = NodeTraversal::next(
node, innerText)) { | 442 for (Node* node = innerText->firstChild(); node; node = NodeTraversal::next(
node, innerText)) { |
| 442 ASSERT(!node->firstChild()); | 443 ASSERT(!node->firstChild()); |
| 443 ASSERT(node->isTextNode() || node->hasTagName(brTag)); | 444 ASSERT(node->isTextNode() || node->hasTagName(brTag)); |
| 444 int length = node->isTextNode() ? lastOffsetInNode(node) : 1; | 445 int length = node->isTextNode() ? lastOffsetInNode(node) : 1; |
| 445 | 446 |
| 446 if (offset <= start && start <= offset + length) | 447 if (offset <= start && start <= offset + length) |
| 447 setContainerAndOffsetForRange(node, start - offset, startNode, start
); | 448 setContainerAndOffsetForRange(node, start - offset, startNode, start
); |
| 448 | 449 |
| 449 if (offset <= end && end <= offset + length) { | 450 if (offset <= end && end <= offset + length) { |
| 450 setContainerAndOffsetForRange(node, end - offset, endNode, end); | 451 setContainerAndOffsetForRange(node, end - offset, endNode, end); |
| 451 break; | 452 break; |
| 452 } | 453 } |
| 453 | 454 |
| 454 offset += length; | 455 offset += length; |
| 455 } | 456 } |
| 456 | 457 |
| 457 if (!startNode || !endNode) | 458 if (!startNode || !endNode) |
| 458 return 0; | 459 return 0; |
| 459 | 460 |
| 460 return Range::create(&document(), startNode, start, endNode, end); | 461 return Range::create(document(), startNode, start, endNode, end); |
| 461 } | 462 } |
| 462 | 463 |
| 463 void HTMLTextFormControlElement::restoreCachedSelection() | 464 void HTMLTextFormControlElement::restoreCachedSelection() |
| 464 { | 465 { |
| 465 setSelectionRange(m_cachedSelectionStart, m_cachedSelectionEnd, m_cachedSele
ctionDirection); | 466 setSelectionRange(m_cachedSelectionStart, m_cachedSelectionEnd, m_cachedSele
ctionDirection); |
| 466 } | 467 } |
| 467 | 468 |
| 468 void HTMLTextFormControlElement::selectionChanged(bool userTriggered) | 469 void HTMLTextFormControlElement::selectionChanged(bool userTriggered) |
| 469 { | 470 { |
| 470 if (!renderer() || !isTextFormControl()) | 471 if (!renderer() || !isTextFormControl()) |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 bool isAuto; | 639 bool isAuto; |
| 639 TextDirection textDirection = static_cast<const HTMLElement*>(elemen
t)->directionalityIfhasDirAutoAttribute(isAuto); | 640 TextDirection textDirection = static_cast<const HTMLElement*>(elemen
t)->directionalityIfhasDirAutoAttribute(isAuto); |
| 640 return textDirection == RTL ? "rtl" : "ltr"; | 641 return textDirection == RTL ? "rtl" : "ltr"; |
| 641 } | 642 } |
| 642 } | 643 } |
| 643 | 644 |
| 644 return "ltr"; | 645 return "ltr"; |
| 645 } | 646 } |
| 646 | 647 |
| 647 } // namespace Webcore | 648 } // namespace Webcore |
| OLD | NEW |