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 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 #include "bindings/core/v8/ExceptionState.h" | 28 #include "bindings/core/v8/ExceptionState.h" |
| 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 30 #include "core/HTMLNames.h" | 30 #include "core/HTMLNames.h" |
| 31 #include "core/accessibility/AXObjectCache.h" | 31 #include "core/accessibility/AXObjectCache.h" |
| 32 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
| 33 #include "core/dom/NodeList.h" | 33 #include "core/dom/NodeList.h" |
| 34 #include "core/dom/NodeTraversal.h" | 34 #include "core/dom/NodeTraversal.h" |
| 35 #include "core/dom/Text.h" | 35 #include "core/dom/Text.h" |
| 36 #include "core/dom/shadow/ShadowRoot.h" | 36 #include "core/dom/shadow/ShadowRoot.h" |
| 37 #include "core/editing/Editor.h" | |
| 37 #include "core/editing/FrameSelection.h" | 38 #include "core/editing/FrameSelection.h" |
| 38 #include "core/editing/TextIterator.h" | 39 #include "core/editing/TextIterator.h" |
| 39 #include "core/events/Event.h" | 40 #include "core/events/Event.h" |
| 40 #include "core/frame/LocalFrame.h" | 41 #include "core/frame/LocalFrame.h" |
| 41 #include "core/frame/UseCounter.h" | 42 #include "core/frame/UseCounter.h" |
| 42 #include "core/html/HTMLBRElement.h" | 43 #include "core/html/HTMLBRElement.h" |
| 43 #include "core/html/shadow/ShadowElementNames.h" | 44 #include "core/html/shadow/ShadowElementNames.h" |
| 44 #include "core/rendering/RenderBlock.h" | 45 #include "core/rendering/RenderBlock.h" |
| 45 #include "core/rendering/RenderTheme.h" | 46 #include "core/rendering/RenderTheme.h" |
| 46 #include "platform/heap/Handle.h" | 47 #include "platform/heap/Handle.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 setSelectionRange(std::min(end, selectionStart()), end, selectionDirection() ); | 174 setSelectionRange(std::min(end, selectionStart()), end, selectionDirection() ); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void HTMLTextFormControlElement::setSelectionDirection(const String& direction) | 177 void HTMLTextFormControlElement::setSelectionDirection(const String& direction) |
| 177 { | 178 { |
| 178 setSelectionRange(selectionStart(), selectionEnd(), direction); | 179 setSelectionRange(selectionStart(), selectionEnd(), direction); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void HTMLTextFormControlElement::select() | 182 void HTMLTextFormControlElement::select() |
| 182 { | 183 { |
| 183 setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirectio n); | 184 setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirectio n, MustFocus); |
|
tkent
2014/07/16 07:11:34
Is this compatible with other browsers?
Can we add
yoichio
2014/07/16 08:07:12
Both FF and IE do.
tkent
2014/07/16 23:34:16
Please have an investigation.
Adding no flag is si
| |
| 184 } | 185 } |
| 185 | 186 |
| 186 bool HTMLTextFormControlElement::shouldDispatchFormControlChangeEvent(String& ol dValue, String& newValue) | 187 bool HTMLTextFormControlElement::shouldDispatchFormControlChangeEvent(String& ol dValue, String& newValue) |
| 187 { | 188 { |
| 188 return !equalIgnoringNullity(oldValue, newValue); | 189 return !equalIgnoringNullity(oldValue, newValue); |
| 189 } | 190 } |
| 190 | 191 |
| 191 void HTMLTextFormControlElement::dispatchFormControlChangeEvent() | 192 void HTMLTextFormControlElement::dispatchFormControlChangeEvent() |
| 192 { | 193 { |
| 193 String newValue = value(); | 194 String newValue = value(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 } | 268 } |
| 268 | 269 |
| 269 void HTMLTextFormControlElement::setSelectionRange(int start, int end, const Str ing& directionString) | 270 void HTMLTextFormControlElement::setSelectionRange(int start, int end, const Str ing& directionString) |
| 270 { | 271 { |
| 271 TextFieldSelectionDirection direction = SelectionHasNoDirection; | 272 TextFieldSelectionDirection direction = SelectionHasNoDirection; |
| 272 if (directionString == "forward") | 273 if (directionString == "forward") |
| 273 direction = SelectionHasForwardDirection; | 274 direction = SelectionHasForwardDirection; |
| 274 else if (directionString == "backward") | 275 else if (directionString == "backward") |
| 275 direction = SelectionHasBackwardDirection; | 276 direction = SelectionHasBackwardDirection; |
| 276 | 277 |
| 278 if (direction == SelectionHasNoDirection && document().frame() && document() .frame()->editor().behavior().shouldConsiderSelectionAsDirectional()) | |
| 279 direction = SelectionHasForwardDirection; | |
| 280 | |
| 277 return setSelectionRange(start, end, direction); | 281 return setSelectionRange(start, end, direction); |
| 278 } | 282 } |
| 279 | 283 |
| 280 void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField SelectionDirection direction) | 284 void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField SelectionDirection direction, FocusOption focusOption) |
| 281 { | 285 { |
| 282 document().updateLayoutIgnorePendingStylesheets(); | 286 document().updateLayoutIgnorePendingStylesheets(); |
| 283 | 287 |
| 284 if (!renderer() || !renderer()->isTextControl()) | 288 if (!renderer() || !renderer()->isTextControl()) |
| 285 return; | 289 return; |
| 286 | 290 |
| 287 int textLength = innerEditorValue().length(); | 291 int textLength = innerEditorValue().length(); |
| 288 end = std::max(std::min(end, textLength), 0); | 292 end = std::max(std::min(end, textLength), 0); |
| 289 start = std::max(std::min(start, end), 0); | 293 start = std::max(std::min(start, end), 0); |
| 290 cacheSelection(start, end, direction); | 294 cacheSelection(start, end, direction); |
| 291 bool isCaretSelection = start == end; | 295 if (focusOption != MustFocus && (document().focusedElement() != this || !has VisibleTextArea(renderer(), innerEditorElement()))) |
| 292 bool shouldSetSelection = document().focusedElement() == this || (!isCaretSe lection && start < textLength); | |
| 293 | |
| 294 if (!hasVisibleTextArea(renderer(), innerEditorElement())) | |
| 295 return; | 296 return; |
| 296 | 297 |
| 297 LocalFrame* frame = document().frame(); | 298 LocalFrame* frame = document().frame(); |
|
yosin_UTC9
2014/07/16 07:09:14
nit: You can move |!frame| before L286.
yoichio
2014/07/16 08:07:12
Done.
| |
| 298 | 299 |
| 299 if (!frame || !shouldSetSelection) | 300 if (!frame) |
| 300 return; | 301 return; |
| 301 | 302 |
| 302 VisiblePosition startPosition = visiblePositionForIndex(start); | 303 VisiblePosition startPosition = visiblePositionForIndex(start); |
| 303 VisiblePosition endPosition; | 304 VisiblePosition endPosition; |
| 304 if (start == end) | 305 if (start == end) |
| 305 endPosition = startPosition; | 306 endPosition = startPosition; |
| 306 else | 307 else |
| 307 endPosition = visiblePositionForIndex(end); | 308 endPosition = visiblePositionForIndex(end); |
| 308 | 309 |
| 309 // startPosition and endPosition can be null position for example when | 310 // startPosition and endPosition can be null position for example when |
| 310 // "-webkit-user-select: none" style attribute is specified. | 311 // "-webkit-user-select: none" style attribute is specified. |
| 311 if (startPosition.isNotNull() && endPosition.isNotNull()) { | 312 if (startPosition.isNotNull() && endPosition.isNotNull()) { |
| 312 ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowHost() == this | 313 ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowHost() == this |
| 313 && endPosition.deepEquivalent().deprecatedNode()->shadowHost() == th is); | 314 && endPosition.deepEquivalent().deprecatedNode()->shadowHost() == th is); |
| 314 } | 315 } |
| 315 VisibleSelection newSelection; | 316 VisibleSelection newSelection; |
| 316 if (direction == SelectionHasBackwardDirection) | 317 if (direction == SelectionHasBackwardDirection) |
| 317 newSelection = VisibleSelection(endPosition, startPosition); | 318 newSelection = VisibleSelection(endPosition, startPosition); |
| 318 else | 319 else |
| 319 newSelection = VisibleSelection(startPosition, endPosition); | 320 newSelection = VisibleSelection(startPosition, endPosition); |
| 320 newSelection.setIsDirectional(direction != SelectionHasNoDirection); | 321 newSelection.setIsDirectional(direction != SelectionHasNoDirection); |
| 321 | 322 |
| 322 frame->selection().setSelection(newSelection); | 323 frame->selection().setSelection(newSelection); |
|
tkent
2014/07/16 07:11:34
We should pass DoNotSetFocus option, IMO.
yoichio
2014/07/16 08:07:12
Acknowledged.
| |
| 323 } | 324 } |
| 324 | 325 |
| 325 VisiblePosition HTMLTextFormControlElement::visiblePositionForIndex(int index) c onst | 326 VisiblePosition HTMLTextFormControlElement::visiblePositionForIndex(int index) c onst |
| 326 { | 327 { |
| 327 if (index <= 0) | 328 if (index <= 0) |
| 328 return VisiblePosition(firstPositionInNode(innerEditorElement()), DOWNST REAM); | 329 return VisiblePosition(firstPositionInNode(innerEditorElement()), DOWNST REAM); |
| 329 RefPtrWillBeRawPtr<Range> range = Range::create(document()); | 330 RefPtrWillBeRawPtr<Range> range = Range::create(document()); |
| 330 range->selectNodeContents(innerEditorElement(), ASSERT_NO_EXCEPTION); | 331 range->selectNodeContents(innerEditorElement(), ASSERT_NO_EXCEPTION); |
| 331 CharacterIterator it(range.get()); | 332 CharacterIterator it(range.get()); |
| 332 it.advance(index - 1); | 333 it.advance(index - 1); |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 Text* textNode = toText(node); | 902 Text* textNode = toText(node); |
| 902 size_t firstLineBreak = textNode->data().find('\n', isPivotNode ? pi votPosition.offsetInContainerNode() : 0); | 903 size_t firstLineBreak = textNode->data().find('\n', isPivotNode ? pi votPosition.offsetInContainerNode() : 0); |
| 903 if (firstLineBreak != kNotFound) | 904 if (firstLineBreak != kNotFound) |
| 904 return Position(textNode, firstLineBreak + 1); | 905 return Position(textNode, firstLineBreak + 1); |
| 905 } | 906 } |
| 906 } | 907 } |
| 907 return endOfInnerText(textFormControl); | 908 return endOfInnerText(textFormControl); |
| 908 } | 909 } |
| 909 | 910 |
| 910 } // namespace Webcore | 911 } // namespace Webcore |
| OLD | NEW |