Chromium Code Reviews| 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 | 272 |
| 273 void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField SelectionDirection direction) | 273 void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField SelectionDirection direction) |
| 274 { | 274 { |
| 275 document().updateLayoutIgnorePendingStylesheets(); | 275 document().updateLayoutIgnorePendingStylesheets(); |
| 276 | 276 |
| 277 if (!renderer() || !renderer()->isTextControl()) | 277 if (!renderer() || !renderer()->isTextControl()) |
| 278 return; | 278 return; |
| 279 | 279 |
| 280 end = max(end, 0); | 280 end = max(end, 0); |
| 281 start = min(max(start, 0), end); | 281 start = min(max(start, 0), end); |
| 282 cacheSelection(start, end, direction); | |
|
tkent
2014/04/29 23:55:44
What happens if |start| or |end| is larger than va
harpreet.sk
2014/04/30 14:36:27
The browser will displays the caret at end of the
| |
| 282 | 283 |
| 283 if (!hasVisibleTextArea(renderer(), innerTextElement())) { | 284 if (!hasVisibleTextArea(renderer(), innerTextElement())) |
| 284 cacheSelection(start, end, direction); | |
| 285 return; | 285 return; |
| 286 } | |
| 287 VisiblePosition startPosition = visiblePositionForIndex(start); | 286 VisiblePosition startPosition = visiblePositionForIndex(start); |
| 288 VisiblePosition endPosition; | 287 VisiblePosition endPosition; |
| 289 if (start == end) | 288 if (start == end) |
| 290 endPosition = startPosition; | 289 endPosition = startPosition; |
| 291 else | 290 else |
| 292 endPosition = visiblePositionForIndex(end); | 291 endPosition = visiblePositionForIndex(end); |
| 293 | 292 |
| 294 // startPosition and endPosition can be null position for example when | 293 // startPosition and endPosition can be null position for example when |
| 295 // "-webkit-user-select: none" style attribute is specified. | 294 // "-webkit-user-select: none" style attribute is specified. |
| 296 if (startPosition.isNotNull() && endPosition.isNotNull()) { | 295 if (startPosition.isNotNull() && endPosition.isNotNull()) { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 void HTMLTextFormControlElement::restoreCachedSelection() | 464 void HTMLTextFormControlElement::restoreCachedSelection() |
| 466 { | 465 { |
| 467 setSelectionRange(m_cachedSelectionStart, m_cachedSelectionEnd, m_cachedSele ctionDirection); | 466 setSelectionRange(m_cachedSelectionStart, m_cachedSelectionEnd, m_cachedSele ctionDirection); |
| 468 } | 467 } |
| 469 | 468 |
| 470 void HTMLTextFormControlElement::selectionChanged(bool userTriggered) | 469 void HTMLTextFormControlElement::selectionChanged(bool userTriggered) |
| 471 { | 470 { |
| 472 if (!renderer() || !isTextFormControl()) | 471 if (!renderer() || !isTextFormControl()) |
| 473 return; | 472 return; |
| 474 | 473 |
| 475 // selectionStart() or selectionEnd() will return cached selection when this node doesn't have focus | |
| 476 cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelect ionDirection()); | |
| 477 | |
| 478 if (LocalFrame* frame = document().frame()) { | 474 if (LocalFrame* frame = document().frame()) { |
| 479 if (frame->selection().isRange() && userTriggered) | 475 if (frame->selection().isRange() && userTriggered) |
| 480 dispatchEvent(Event::createBubble(EventTypeNames::select)); | 476 dispatchEvent(Event::createBubble(EventTypeNames::select)); |
| 481 } | 477 } |
| 482 } | 478 } |
| 483 | 479 |
| 484 void HTMLTextFormControlElement::parseAttribute(const QualifiedName& name, const AtomicString& value) | 480 void HTMLTextFormControlElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 485 { | 481 { |
| 486 if (name == placeholderAttr) { | 482 if (name == placeholderAttr) { |
| 487 updatePlaceholderVisibility(true); | 483 updatePlaceholderVisibility(true); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 645 | 641 |
| 646 return "ltr"; | 642 return "ltr"; |
| 647 } | 643 } |
| 648 | 644 |
| 649 HTMLElement* HTMLTextFormControlElement::innerTextElement() const | 645 HTMLElement* HTMLTextFormControlElement::innerTextElement() const |
| 650 { | 646 { |
| 651 return toHTMLElement(userAgentShadowRoot()->getElementById(ShadowElementName s::innerEditor())); | 647 return toHTMLElement(userAgentShadowRoot()->getElementById(ShadowElementName s::innerEditor())); |
| 652 } | 648 } |
| 653 | 649 |
| 654 } // namespace Webcore | 650 } // namespace Webcore |
| OLD | NEW |