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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 setSelectionRange(newSelectionStart, newSelectionEnd, SelectionHasNoDirectio
n); | 263 setSelectionRange(newSelectionStart, newSelectionEnd, SelectionHasNoDirectio
n); |
264 } | 264 } |
265 | 265 |
266 void HTMLTextFormControlElement::setSelectionRangeForBinding(int start, int end,
const String& directionString) | 266 void HTMLTextFormControlElement::setSelectionRangeForBinding(int start, int end,
const String& directionString) |
267 { | 267 { |
268 TextFieldSelectionDirection direction = SelectionHasNoDirection; | 268 TextFieldSelectionDirection direction = SelectionHasNoDirection; |
269 if (directionString == "forward") | 269 if (directionString == "forward") |
270 direction = SelectionHasForwardDirection; | 270 direction = SelectionHasForwardDirection; |
271 else if (directionString == "backward") | 271 else if (directionString == "backward") |
272 direction = SelectionHasBackwardDirection; | 272 direction = SelectionHasBackwardDirection; |
273 | 273 setSelectionRange(start, end, direction); |
274 if (direction == SelectionHasNoDirection && document().frame() && document()
.frame()->editor().behavior().shouldConsiderSelectionAsDirectional()) | |
275 direction = SelectionHasForwardDirection; | |
276 | |
277 return setSelectionRange(start, end, direction); | |
278 } | 274 } |
279 | 275 |
280 static Position positionForIndex(HTMLElement* innerEditor, int index) | 276 static Position positionForIndex(HTMLElement* innerEditor, int index) |
281 { | 277 { |
282 DCHECK_GE(index, 0); | 278 DCHECK_GE(index, 0); |
283 if (index == 0) { | 279 if (index == 0) { |
284 Node* node = NodeTraversal::next(*innerEditor, innerEditor); | 280 Node* node = NodeTraversal::next(*innerEditor, innerEditor); |
285 if (node && node->isTextNode()) | 281 if (node && node->isTextNode()) |
286 return Position(node, 0); | 282 return Position(node, 0); |
287 return Position(innerEditor, 0); | 283 return Position(innerEditor, 0); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 } | 340 } |
345 | 341 |
346 void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField
SelectionDirection direction, NeedToDispatchSelectEvent eventBehaviour) | 342 void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField
SelectionDirection direction, NeedToDispatchSelectEvent eventBehaviour) |
347 { | 343 { |
348 if (openShadowRoot() || !isTextFormControl()) | 344 if (openShadowRoot() || !isTextFormControl()) |
349 return; | 345 return; |
350 const int editorValueLength = static_cast<int>(innerEditorValue().length()); | 346 const int editorValueLength = static_cast<int>(innerEditorValue().length()); |
351 DCHECK_GE(editorValueLength, 0); | 347 DCHECK_GE(editorValueLength, 0); |
352 end = std::max(std::min(end, editorValueLength), 0); | 348 end = std::max(std::min(end, editorValueLength), 0); |
353 start = std::min(std::max(start, 0), end); | 349 start = std::min(std::max(start, 0), end); |
| 350 LocalFrame* frame = document().frame(); |
| 351 if (direction == SelectionHasNoDirection && frame && frame->editor().behavio
r().shouldConsiderSelectionAsDirectional()) |
| 352 direction = SelectionHasForwardDirection; |
354 cacheSelection(start, end, direction); | 353 cacheSelection(start, end, direction); |
355 | 354 |
356 if (document().focusedElement() != this) { | 355 if (document().focusedElement() != this) { |
357 if (eventBehaviour == DispatchSelectEvent) | 356 if (eventBehaviour == DispatchSelectEvent) |
358 scheduleSelectEvent(); | 357 scheduleSelectEvent(); |
359 return; | 358 return; |
360 } | 359 } |
361 | 360 |
362 LocalFrame* frame = document().frame(); | |
363 HTMLElement* innerEditor = innerEditorElement(); | 361 HTMLElement* innerEditor = innerEditorElement(); |
364 if (!frame || !innerEditor) | 362 if (!frame || !innerEditor) |
365 return; | 363 return; |
366 | 364 |
367 Position startPosition = positionForIndex(innerEditor, start); | 365 Position startPosition = positionForIndex(innerEditor, start); |
368 Position endPosition = start == end ? startPosition : positionForIndex(inner
Editor, end); | 366 Position endPosition = start == end ? startPosition : positionForIndex(inner
Editor, end); |
369 | 367 |
370 DCHECK_EQ(start, indexForPosition(innerEditor, startPosition)); | 368 DCHECK_EQ(start, indexForPosition(innerEditor, startPosition)); |
371 DCHECK_EQ(end, indexForPosition(innerEditor, endPosition)); | 369 DCHECK_EQ(end, indexForPosition(innerEditor, endPosition)); |
372 | 370 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 case SelectionHasBackwardDirection: | 462 case SelectionHasBackwardDirection: |
465 return backward; | 463 return backward; |
466 } | 464 } |
467 | 465 |
468 NOTREACHED(); | 466 NOTREACHED(); |
469 return none; | 467 return none; |
470 } | 468 } |
471 | 469 |
472 const AtomicString& HTMLTextFormControlElement::selectionDirection() const | 470 const AtomicString& HTMLTextFormControlElement::selectionDirection() const |
473 { | 471 { |
474 if (!isTextFormControl()) | 472 // Ensured by HTMLInputElement::selectionDirectionForBinding(). |
475 return directionString(SelectionHasNoDirection); | 473 DCHECK(isTextFormControl()); |
476 if (document().focusedElement() != this) | 474 if (document().focusedElement() != this) |
477 return directionString(m_cachedSelectionDirection); | 475 return directionString(m_cachedSelectionDirection); |
478 | |
479 return directionString(computeSelectionDirection()); | 476 return directionString(computeSelectionDirection()); |
480 } | 477 } |
481 | 478 |
482 TextFieldSelectionDirection HTMLTextFormControlElement::computeSelectionDirectio
n() const | 479 TextFieldSelectionDirection HTMLTextFormControlElement::computeSelectionDirectio
n() const |
483 { | 480 { |
484 DCHECK(isTextFormControl()); | 481 DCHECK(isTextFormControl()); |
485 LocalFrame* frame = document().frame(); | 482 LocalFrame* frame = document().frame(); |
486 if (!frame) | 483 if (!frame) |
487 return SelectionHasNoDirection; | 484 return SelectionHasNoDirection; |
488 | 485 |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 } | 1021 } |
1025 | 1022 |
1026 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele
ment& source) | 1023 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele
ment& source) |
1027 { | 1024 { |
1028 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText
FormControlElement&>(source); | 1025 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText
FormControlElement&>(source); |
1029 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; | 1026 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; |
1030 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); | 1027 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); |
1031 } | 1028 } |
1032 | 1029 |
1033 } // namespace blink | 1030 } // namespace blink |
OLD | NEW |