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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "wtf/text/StringBuilder.h" | 46 #include "wtf/text/StringBuilder.h" |
47 | 47 |
48 namespace WebCore { | 48 namespace WebCore { |
49 | 49 |
50 using namespace HTMLNames; | 50 using namespace HTMLNames; |
51 using namespace std; | 51 using namespace std; |
52 | 52 |
53 HTMLTextFormControlElement::HTMLTextFormControlElement(const QualifiedName& tagN
ame, Document& doc, HTMLFormElement* form) | 53 HTMLTextFormControlElement::HTMLTextFormControlElement(const QualifiedName& tagN
ame, Document& doc, HTMLFormElement* form) |
54 : HTMLFormControlElementWithState(tagName, doc, form) | 54 : HTMLFormControlElementWithState(tagName, doc, form) |
55 , m_lastChangeWasUserEdit(false) | 55 , m_lastChangeWasUserEdit(false) |
56 , m_cachedSelectionStart(-1) | 56 , m_cachedSelectionStart(0) |
57 , m_cachedSelectionEnd(-1) | 57 , m_cachedSelectionEnd(0) |
58 , m_cachedSelectionDirection(SelectionHasNoDirection) | 58 , m_cachedSelectionDirection(SelectionHasNoDirection) |
59 { | 59 { |
60 } | 60 } |
61 | 61 |
62 HTMLTextFormControlElement::~HTMLTextFormControlElement() | 62 HTMLTextFormControlElement::~HTMLTextFormControlElement() |
63 { | 63 { |
64 } | 64 } |
65 | 65 |
66 Node::InsertionNotificationRequest HTMLTextFormControlElement::insertedInto(Cont
ainerNode* insertionPoint) | 66 Node::InsertionNotificationRequest HTMLTextFormControlElement::insertedInto(Cont
ainerNode* insertionPoint) |
67 { | 67 { |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 RefPtrWillBeRawPtr<Range> range = Range::create(*indexPosition.document()); | 328 RefPtrWillBeRawPtr<Range> range = Range::create(*indexPosition.document()); |
329 range->setStart(innerTextElement(), 0, ASSERT_NO_EXCEPTION); | 329 range->setStart(innerTextElement(), 0, ASSERT_NO_EXCEPTION); |
330 range->setEnd(indexPosition.containerNode(), indexPosition.offsetInContainer
Node(), ASSERT_NO_EXCEPTION); | 330 range->setEnd(indexPosition.containerNode(), indexPosition.offsetInContainer
Node(), ASSERT_NO_EXCEPTION); |
331 return TextIterator::rangeLength(range.get()); | 331 return TextIterator::rangeLength(range.get()); |
332 } | 332 } |
333 | 333 |
334 int HTMLTextFormControlElement::selectionStart() const | 334 int HTMLTextFormControlElement::selectionStart() const |
335 { | 335 { |
336 if (!isTextFormControl()) | 336 if (!isTextFormControl()) |
337 return 0; | 337 return 0; |
338 if (document().focusedElement() != this && hasCachedSelection()) | 338 if (document().focusedElement() != this) |
339 return m_cachedSelectionStart; | 339 return m_cachedSelectionStart; |
340 | 340 |
341 return computeSelectionStart(); | 341 return computeSelectionStart(); |
342 } | 342 } |
343 | 343 |
344 int HTMLTextFormControlElement::computeSelectionStart() const | 344 int HTMLTextFormControlElement::computeSelectionStart() const |
345 { | 345 { |
346 ASSERT(isTextFormControl()); | 346 ASSERT(isTextFormControl()); |
347 LocalFrame* frame = document().frame(); | 347 LocalFrame* frame = document().frame(); |
348 if (!frame) | 348 if (!frame) |
349 return 0; | 349 return 0; |
350 | 350 |
351 return indexForVisiblePosition(VisiblePosition(frame->selection().start())); | 351 return indexForVisiblePosition(VisiblePosition(frame->selection().start())); |
352 } | 352 } |
353 | 353 |
354 int HTMLTextFormControlElement::selectionEnd() const | 354 int HTMLTextFormControlElement::selectionEnd() const |
355 { | 355 { |
356 if (!isTextFormControl()) | 356 if (!isTextFormControl()) |
357 return 0; | 357 return 0; |
358 if (document().focusedElement() != this && hasCachedSelection()) | 358 if (document().focusedElement() != this) |
359 return m_cachedSelectionEnd; | 359 return m_cachedSelectionEnd; |
360 return computeSelectionEnd(); | 360 return computeSelectionEnd(); |
361 } | 361 } |
362 | 362 |
363 int HTMLTextFormControlElement::computeSelectionEnd() const | 363 int HTMLTextFormControlElement::computeSelectionEnd() const |
364 { | 364 { |
365 ASSERT(isTextFormControl()); | 365 ASSERT(isTextFormControl()); |
366 LocalFrame* frame = document().frame(); | 366 LocalFrame* frame = document().frame(); |
367 if (!frame) | 367 if (!frame) |
368 return 0; | 368 return 0; |
(...skipping 17 matching lines...) Expand all Loading... |
386 } | 386 } |
387 | 387 |
388 ASSERT_NOT_REACHED(); | 388 ASSERT_NOT_REACHED(); |
389 return none; | 389 return none; |
390 } | 390 } |
391 | 391 |
392 const AtomicString& HTMLTextFormControlElement::selectionDirection() const | 392 const AtomicString& HTMLTextFormControlElement::selectionDirection() const |
393 { | 393 { |
394 if (!isTextFormControl()) | 394 if (!isTextFormControl()) |
395 return directionString(SelectionHasNoDirection); | 395 return directionString(SelectionHasNoDirection); |
396 if (document().focusedElement() != this && hasCachedSelection()) | 396 if (document().focusedElement() != this) |
397 return directionString(m_cachedSelectionDirection); | 397 return directionString(m_cachedSelectionDirection); |
398 | 398 |
399 return directionString(computeSelectionDirection()); | 399 return directionString(computeSelectionDirection()); |
400 } | 400 } |
401 | 401 |
402 TextFieldSelectionDirection HTMLTextFormControlElement::computeSelectionDirectio
n() const | 402 TextFieldSelectionDirection HTMLTextFormControlElement::computeSelectionDirectio
n() const |
403 { | 403 { |
404 ASSERT(isTextFormControl()); | 404 ASSERT(isTextFormControl()); |
405 LocalFrame* frame = document().frame(); | 405 LocalFrame* frame = document().frame(); |
406 if (!frame) | 406 if (!frame) |
407 return SelectionHasNoDirection; | 407 return SelectionHasNoDirection; |
408 | 408 |
409 const VisibleSelection& selection = frame->selection().selection(); | 409 const VisibleSelection& selection = frame->selection().selection(); |
410 return selection.isDirectional() ? (selection.isBaseFirst() ? SelectionHasFo
rwardDirection : SelectionHasBackwardDirection) : SelectionHasNoDirection; | 410 return selection.isDirectional() ? (selection.isBaseFirst() ? SelectionHasFo
rwardDirection : SelectionHasBackwardDirection) : SelectionHasNoDirection; |
411 } | 411 } |
412 | 412 |
413 static inline void setContainerAndOffsetForRange(Node* node, int offset, Node*&
containerNode, int& offsetInContainer) | 413 static inline void setContainerAndOffsetForRange(Node* node, int offset, Node*&
containerNode, int& offsetInContainer) |
414 { | 414 { |
415 if (node->isTextNode()) { | 415 if (node->isTextNode()) { |
416 containerNode = node; | 416 containerNode = node; |
417 offsetInContainer = offset; | 417 offsetInContainer = offset; |
418 } else { | 418 } else { |
419 containerNode = node->parentNode(); | 419 containerNode = node->parentNode(); |
420 offsetInContainer = node->nodeIndex() + offset; | 420 offsetInContainer = node->nodeIndex() + offset; |
421 } | 421 } |
422 } | 422 } |
423 | 423 |
424 PassRefPtrWillBeRawPtr<Range> HTMLTextFormControlElement::selection() const | 424 PassRefPtrWillBeRawPtr<Range> HTMLTextFormControlElement::selection() const |
425 { | 425 { |
426 if (!renderer() || !isTextFormControl() || !hasCachedSelection()) | 426 if (!renderer() || !isTextFormControl()) |
427 return nullptr; | 427 return nullptr; |
428 | 428 |
429 int start = m_cachedSelectionStart; | 429 int start = m_cachedSelectionStart; |
430 int end = m_cachedSelectionEnd; | 430 int end = m_cachedSelectionEnd; |
431 | 431 |
432 ASSERT(start <= end); | 432 ASSERT(start <= end); |
433 HTMLElement* innerText = innerTextElement(); | 433 HTMLElement* innerText = innerTextElement(); |
434 if (!innerText) | 434 if (!innerText) |
435 return nullptr; | 435 return nullptr; |
436 | 436 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 | 645 |
646 return "ltr"; | 646 return "ltr"; |
647 } | 647 } |
648 | 648 |
649 HTMLElement* HTMLTextFormControlElement::innerTextElement() const | 649 HTMLElement* HTMLTextFormControlElement::innerTextElement() const |
650 { | 650 { |
651 return toHTMLElement(userAgentShadowRoot()->getElementById(ShadowElementName
s::innerEditor())); | 651 return toHTMLElement(userAgentShadowRoot()->getElementById(ShadowElementName
s::innerEditor())); |
652 } | 652 } |
653 | 653 |
654 } // namespace Webcore | 654 } // namespace Webcore |
OLD | NEW |