| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
| 3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 { | 198 { |
| 199 m_lastChangeWasUserEdit = lastChangeWasUserEdit; | 199 m_lastChangeWasUserEdit = lastChangeWasUserEdit; |
| 200 document()->setIgnoreAutofocus(lastChangeWasUserEdit); | 200 document()->setIgnoreAutofocus(lastChangeWasUserEdit); |
| 201 } | 201 } |
| 202 | 202 |
| 203 int RenderTextControl::selectionStart() const | 203 int RenderTextControl::selectionStart() const |
| 204 { | 204 { |
| 205 Frame* frame = this->frame(); | 205 Frame* frame = this->frame(); |
| 206 if (!frame) | 206 if (!frame) |
| 207 return 0; | 207 return 0; |
| 208 return indexForVisiblePosition(frame->selection()->start()); | 208 |
| 209 HTMLElement* innerText = innerTextElement(); |
| 210 // Do not call innerTextElement() in the function arguments as creating a Vi
siblePosition |
| 211 // from frame->selection->start() can blow us from underneath. Also, functio
n ordering is |
| 212 // usually dependent on the compiler. |
| 213 return RenderTextControl::indexForVisiblePosition(innerText, frame->selectio
n()->start()); |
| 209 } | 214 } |
| 210 | 215 |
| 211 int RenderTextControl::selectionEnd() const | 216 int RenderTextControl::selectionEnd() const |
| 212 { | 217 { |
| 213 Frame* frame = this->frame(); | 218 Frame* frame = this->frame(); |
| 214 if (!frame) | 219 if (!frame) |
| 215 return 0; | 220 return 0; |
| 216 return indexForVisiblePosition(frame->selection()->end()); | 221 |
| 222 HTMLElement* innerText = innerTextElement(); |
| 223 // Do not call innerTextElement() in the function arguments as creating a Vi
siblePosition |
| 224 // from frame->selection->end() can blow us from underneath. Also, function
ordering is |
| 225 // usually dependent on the compiler. |
| 226 return RenderTextControl::indexForVisiblePosition(innerText, frame->selectio
n()->end()); |
| 217 } | 227 } |
| 218 | 228 |
| 219 bool RenderTextControl::hasVisibleTextArea() const | 229 bool RenderTextControl::hasVisibleTextArea() const |
| 220 { | 230 { |
| 221 return style()->visibility() == HIDDEN || !m_innerText || !m_innerText->rend
erer() || !m_innerText->renderBox()->height(); | 231 return style()->visibility() == HIDDEN || !m_innerText || !m_innerText->rend
erer() || !m_innerText->renderBox()->height(); |
| 222 } | 232 } |
| 223 | 233 |
| 224 void setSelectionRange(Node* node, int start, int end) | 234 void setSelectionRange(Node* node, int start, int end) |
| 225 { | 235 { |
| 226 ASSERT(node); | 236 ASSERT(node); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 249 // "-webkit-user-select: none" style attribute is specified. | 259 // "-webkit-user-select: none" style attribute is specified. |
| 250 if (startPosition.isNotNull() && endPosition.isNotNull()) { | 260 if (startPosition.isNotNull() && endPosition.isNotNull()) { |
| 251 ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowAncestorNo
de() == node && endPosition.deepEquivalent().deprecatedNode()->shadowAncestorNod
e() == node); | 261 ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowAncestorNo
de() == node && endPosition.deepEquivalent().deprecatedNode()->shadowAncestorNod
e() == node); |
| 252 } | 262 } |
| 253 VisibleSelection newSelection = VisibleSelection(startPosition, endPosition)
; | 263 VisibleSelection newSelection = VisibleSelection(startPosition, endPosition)
; |
| 254 | 264 |
| 255 if (Frame* frame = node->document()->frame()) | 265 if (Frame* frame = node->document()->frame()) |
| 256 frame->selection()->setSelection(newSelection); | 266 frame->selection()->setSelection(newSelection); |
| 257 } | 267 } |
| 258 | 268 |
| 259 bool RenderTextControl::isSelectableElement(Node* node) const | 269 bool RenderTextControl::isSelectableElement(HTMLElement* innerText, Node* node) |
| 260 { | 270 { |
| 261 if (!node || !m_innerText) | 271 if (!node || !innerText) |
| 262 return false; | 272 return false; |
| 263 | 273 |
| 264 if (node->rootEditableElement() == m_innerText) | 274 if (node->rootEditableElement() == innerText) |
| 265 return true; | 275 return true; |
| 266 | 276 |
| 267 if (!m_innerText->contains(node)) | 277 if (!innerText->contains(node)) |
| 268 return false; | 278 return false; |
| 269 | 279 |
| 270 Node* shadowAncestor = node->shadowAncestorNode(); | 280 Node* shadowAncestor = node->shadowAncestorNode(); |
| 271 return shadowAncestor && (shadowAncestor->hasTagName(textareaTag) | 281 return shadowAncestor && (shadowAncestor->hasTagName(textareaTag) |
| 272 || (shadowAncestor->hasTagName(inputTag) && static_cast<HTMLInputElement
*>(shadowAncestor)->isTextField())); | 282 || (shadowAncestor->hasTagName(inputTag) && static_cast<HTMLInputElement
*>(shadowAncestor)->isTextField())); |
| 273 } | 283 } |
| 274 | 284 |
| 275 static inline void setContainerAndOffsetForRange(Node* node, int offset, Node*&
containerNode, int& offsetInContainer) | 285 static inline void setContainerAndOffsetForRange(Node* node, int offset, Node*&
containerNode, int& offsetInContainer) |
| 276 { | 286 { |
| 277 if (node->isTextNode()) { | 287 if (node->isTextNode()) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 ASSERT(!ec); | 337 ASSERT(!ec); |
| 328 CharacterIterator it(range.get()); | 338 CharacterIterator it(range.get()); |
| 329 it.advance(index - 1); | 339 it.advance(index - 1); |
| 330 Node* endContainer = it.range()->endContainer(ec); | 340 Node* endContainer = it.range()->endContainer(ec); |
| 331 ASSERT(!ec); | 341 ASSERT(!ec); |
| 332 int endOffset = it.range()->endOffset(ec); | 342 int endOffset = it.range()->endOffset(ec); |
| 333 ASSERT(!ec); | 343 ASSERT(!ec); |
| 334 return VisiblePosition(Position(endContainer, endOffset, Position::PositionI
sOffsetInAnchor), UPSTREAM); | 344 return VisiblePosition(Position(endContainer, endOffset, Position::PositionI
sOffsetInAnchor), UPSTREAM); |
| 335 } | 345 } |
| 336 | 346 |
| 337 int RenderTextControl::indexForVisiblePosition(const VisiblePosition& pos) const | 347 int RenderTextControl::indexForVisiblePosition(HTMLElement* innerTextElement, co
nst VisiblePosition& pos) |
| 338 { | 348 { |
| 339 Position indexPosition = pos.deepEquivalent(); | 349 Position indexPosition = pos.deepEquivalent(); |
| 340 if (!isSelectableElement(indexPosition.deprecatedNode())) | 350 if (!RenderTextControl::isSelectableElement(innerTextElement, indexPosition.
deprecatedNode())) |
| 341 return 0; | 351 return 0; |
| 342 ExceptionCode ec = 0; | 352 ExceptionCode ec = 0; |
| 343 RefPtr<Range> range = Range::create(document()); | 353 RefPtr<Range> range = Range::create(indexPosition.document()); |
| 344 range->setStart(m_innerText.get(), 0, ec); | 354 range->setStart(innerTextElement, 0, ec); |
| 345 ASSERT(!ec); | 355 ASSERT(!ec); |
| 346 range->setEnd(indexPosition.deprecatedNode(), indexPosition.deprecatedEditin
gOffset(), ec); | 356 range->setEnd(indexPosition.deprecatedNode(), indexPosition.deprecatedEditin
gOffset(), ec); |
| 347 ASSERT(!ec); | 357 ASSERT(!ec); |
| 348 return TextIterator::rangeLength(range.get()); | 358 return TextIterator::rangeLength(range.get()); |
| 349 } | 359 } |
| 350 | 360 |
| 351 void RenderTextControl::subtreeHasChanged() | 361 void RenderTextControl::subtreeHasChanged() |
| 352 { | 362 { |
| 353 m_lastChangeWasUserEdit = true; | 363 m_lastChangeWasUserEdit = true; |
| 354 } | 364 } |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 665 |
| 656 void RenderTextControl::paintObject(PaintInfo& paintInfo, int tx, int ty) | 666 void RenderTextControl::paintObject(PaintInfo& paintInfo, int tx, int ty) |
| 657 { | 667 { |
| 658 if (m_placeholderVisible && paintInfo.phase == PaintPhaseForeground) | 668 if (m_placeholderVisible && paintInfo.phase == PaintPhaseForeground) |
| 659 paintPlaceholder(paintInfo, tx, ty); | 669 paintPlaceholder(paintInfo, tx, ty); |
| 660 | 670 |
| 661 RenderBlock::paintObject(paintInfo, tx, ty); | 671 RenderBlock::paintObject(paintInfo, tx, ty); |
| 662 } | 672 } |
| 663 | 673 |
| 664 } // namespace WebCore | 674 } // namespace WebCore |
| OLD | NEW |