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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 { | 170 { |
171 m_lastChangeWasUserEdit = lastChangeWasUserEdit; | 171 m_lastChangeWasUserEdit = lastChangeWasUserEdit; |
172 document()->setIgnoreAutofocus(lastChangeWasUserEdit); | 172 document()->setIgnoreAutofocus(lastChangeWasUserEdit); |
173 } | 173 } |
174 | 174 |
175 int RenderTextControl::selectionStart() const | 175 int RenderTextControl::selectionStart() const |
176 { | 176 { |
177 Frame* frame = this->frame(); | 177 Frame* frame = this->frame(); |
178 if (!frame) | 178 if (!frame) |
179 return 0; | 179 return 0; |
180 return indexForVisiblePosition(frame->selection()->start()); | 180 |
| 181 HTMLElement* innerText = innerTextElement(); |
| 182 // Do not call innerTextElement() in the function arguments as creating a Vi
siblePosition |
| 183 // from frame->selection->start() can blow us from underneath. Also, functio
n ordering is |
| 184 // usually dependent on the compiler. |
| 185 return RenderTextControl::indexForVisiblePosition(innerText, frame->selectio
n()->start()); |
181 } | 186 } |
182 | 187 |
183 int RenderTextControl::selectionEnd() const | 188 int RenderTextControl::selectionEnd() const |
184 { | 189 { |
185 Frame* frame = this->frame(); | 190 Frame* frame = this->frame(); |
186 if (!frame) | 191 if (!frame) |
187 return 0; | 192 return 0; |
188 return indexForVisiblePosition(frame->selection()->end()); | 193 |
| 194 HTMLElement* innerText = innerTextElement(); |
| 195 // Do not call innerTextElement() in the function arguments as creating a Vi
siblePosition |
| 196 // from frame->selection->end() can blow us from underneath. Also, function
ordering is |
| 197 // usually dependent on the compiler. |
| 198 return RenderTextControl::indexForVisiblePosition(innerText, frame->selectio
n()->end()); |
189 } | 199 } |
190 | 200 |
191 bool RenderTextControl::hasVisibleTextArea() const | 201 bool RenderTextControl::hasVisibleTextArea() const |
192 { | 202 { |
193 HTMLElement* innerText = innerTextElement(); | 203 HTMLElement* innerText = innerTextElement(); |
194 return style()->visibility() == HIDDEN || !innerText || !innerText->renderer
() || !innerText->renderBox()->height(); | 204 return style()->visibility() == HIDDEN || !innerText || !innerText->renderer
() || !innerText->renderBox()->height(); |
195 } | 205 } |
196 | 206 |
197 void setSelectionRange(Node* node, int start, int end) | 207 void setSelectionRange(Node* node, int start, int end) |
198 { | 208 { |
(...skipping 23 matching lines...) Expand all Loading... |
222 // "-webkit-user-select: none" style attribute is specified. | 232 // "-webkit-user-select: none" style attribute is specified. |
223 if (startPosition.isNotNull() && endPosition.isNotNull()) { | 233 if (startPosition.isNotNull() && endPosition.isNotNull()) { |
224 ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowAncestorNo
de() == node && endPosition.deepEquivalent().deprecatedNode()->shadowAncestorNod
e() == node); | 234 ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowAncestorNo
de() == node && endPosition.deepEquivalent().deprecatedNode()->shadowAncestorNod
e() == node); |
225 } | 235 } |
226 VisibleSelection newSelection = VisibleSelection(startPosition, endPosition)
; | 236 VisibleSelection newSelection = VisibleSelection(startPosition, endPosition)
; |
227 | 237 |
228 if (Frame* frame = node->document()->frame()) | 238 if (Frame* frame = node->document()->frame()) |
229 frame->selection()->setSelection(newSelection); | 239 frame->selection()->setSelection(newSelection); |
230 } | 240 } |
231 | 241 |
232 bool RenderTextControl::isSelectableElement(Node* node) const | 242 bool RenderTextControl::isSelectableElement(HTMLElement* innerText, Node* node) |
233 { | 243 { |
234 if (!node) | 244 if (!node || !innerText) |
235 return false; | 245 return false; |
236 | 246 |
237 HTMLElement* innerText = innerTextElement(); | |
238 if (!innerText) | |
239 return false; | |
240 | |
241 if (node->rootEditableElement() == innerText) | 247 if (node->rootEditableElement() == innerText) |
242 return true; | 248 return true; |
243 | 249 |
244 if (!innerText->contains(node)) | 250 if (!innerText->contains(node)) |
245 return false; | 251 return false; |
246 | 252 |
247 Node* shadowAncestor = node->shadowAncestorNode(); | 253 Node* shadowAncestor = node->shadowAncestorNode(); |
248 return shadowAncestor && (shadowAncestor->hasTagName(textareaTag) | 254 return shadowAncestor && (shadowAncestor->hasTagName(textareaTag) |
249 || (shadowAncestor->hasTagName(inputTag) && static_cast<HTMLInputElement
*>(shadowAncestor)->isTextField())); | 255 || (shadowAncestor->hasTagName(inputTag) && static_cast<HTMLInputElement
*>(shadowAncestor)->isTextField())); |
250 } | 256 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 ASSERT(!ec); | 311 ASSERT(!ec); |
306 CharacterIterator it(range.get()); | 312 CharacterIterator it(range.get()); |
307 it.advance(index - 1); | 313 it.advance(index - 1); |
308 Node* endContainer = it.range()->endContainer(ec); | 314 Node* endContainer = it.range()->endContainer(ec); |
309 ASSERT(!ec); | 315 ASSERT(!ec); |
310 int endOffset = it.range()->endOffset(ec); | 316 int endOffset = it.range()->endOffset(ec); |
311 ASSERT(!ec); | 317 ASSERT(!ec); |
312 return VisiblePosition(Position(endContainer, endOffset, Position::PositionI
sOffsetInAnchor), UPSTREAM); | 318 return VisiblePosition(Position(endContainer, endOffset, Position::PositionI
sOffsetInAnchor), UPSTREAM); |
313 } | 319 } |
314 | 320 |
315 int RenderTextControl::indexForVisiblePosition(const VisiblePosition& pos) const | 321 int RenderTextControl::indexForVisiblePosition(HTMLElement* innerTextElement, co
nst VisiblePosition& pos) |
316 { | 322 { |
317 Position indexPosition = pos.deepEquivalent(); | 323 Position indexPosition = pos.deepEquivalent(); |
318 if (!isSelectableElement(indexPosition.deprecatedNode())) | 324 if (!RenderTextControl::isSelectableElement(innerTextElement, indexPosition.
deprecatedNode())) |
319 return 0; | 325 return 0; |
320 ExceptionCode ec = 0; | 326 ExceptionCode ec = 0; |
321 RefPtr<Range> range = Range::create(document()); | 327 RefPtr<Range> range = Range::create(indexPosition.document()); |
322 range->setStart(innerTextElement(), 0, ec); | 328 range->setStart(innerTextElement, 0, ec); |
323 ASSERT(!ec); | 329 ASSERT(!ec); |
324 range->setEnd(indexPosition.deprecatedNode(), indexPosition.deprecatedEditin
gOffset(), ec); | 330 range->setEnd(indexPosition.deprecatedNode(), indexPosition.deprecatedEditin
gOffset(), ec); |
325 ASSERT(!ec); | 331 ASSERT(!ec); |
326 return TextIterator::rangeLength(range.get()); | 332 return TextIterator::rangeLength(range.get()); |
327 } | 333 } |
328 | 334 |
329 void RenderTextControl::subtreeHasChanged() | 335 void RenderTextControl::subtreeHasChanged() |
330 { | 336 { |
331 m_lastChangeWasUserEdit = true; | 337 m_lastChangeWasUserEdit = true; |
332 } | 338 } |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 | 642 |
637 void RenderTextControl::paintObject(PaintInfo& paintInfo, int tx, int ty) | 643 void RenderTextControl::paintObject(PaintInfo& paintInfo, int tx, int ty) |
638 { | 644 { |
639 if (m_placeholderVisible && paintInfo.phase == PaintPhaseForeground) | 645 if (m_placeholderVisible && paintInfo.phase == PaintPhaseForeground) |
640 paintPlaceholder(paintInfo, tx, ty); | 646 paintPlaceholder(paintInfo, tx, ty); |
641 | 647 |
642 RenderBlock::paintObject(paintInfo, tx, ty); | 648 RenderBlock::paintObject(paintInfo, tx, ty); |
643 } | 649 } |
644 | 650 |
645 } // namespace WebCore | 651 } // namespace WebCore |
OLD | NEW |