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, ChangeFocus); |
| 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 { |
| 286 LocalFrame* frame = document().frame(); | |
| 287 | |
| 288 if (!frame) | |
| 289 return; | |
|
tkent
2014/07/16 23:35:19
Is this compatible with other browsers? Shouldn't
yoichio
2014/07/17 07:16:01
I'm not sure and this change is not related to thi
| |
| 290 | |
| 282 document().updateLayoutIgnorePendingStylesheets(); | 291 document().updateLayoutIgnorePendingStylesheets(); |
| 283 | 292 |
| 284 if (!renderer() || !renderer()->isTextControl()) | 293 if (!renderer() || !renderer()->isTextControl()) |
| 285 return; | 294 return; |
| 286 | 295 |
| 287 int textLength = innerEditorValue().length(); | 296 int textLength = innerEditorValue().length(); |
| 288 end = std::max(std::min(end, textLength), 0); | 297 end = std::max(std::min(end, textLength), 0); |
| 289 start = std::max(std::min(start, end), 0); | 298 start = std::max(std::min(start, end), 0); |
| 290 cacheSelection(start, end, direction); | 299 cacheSelection(start, end, direction); |
| 291 bool isCaretSelection = start == end; | |
| 292 bool shouldSetSelection = document().focusedElement() == this || (!isCaretSe lection && start < textLength); | |
| 293 | 300 |
| 294 if (!hasVisibleTextArea(renderer(), innerEditorElement())) | 301 if (!hasVisibleTextArea(renderer(), innerEditorElement())) |
| 295 return; | 302 return; |
| 296 | 303 |
| 297 LocalFrame* frame = document().frame(); | 304 if (focusOption == NotChangeFocus && document().focusedElement() != this) |
| 298 | |
| 299 if (!frame || !shouldSetSelection) | |
| 300 return; | 305 return; |
| 301 | 306 |
| 302 VisiblePosition startPosition = visiblePositionForIndex(start); | 307 VisiblePosition startPosition = visiblePositionForIndex(start); |
| 303 VisiblePosition endPosition; | 308 VisiblePosition endPosition; |
| 304 if (start == end) | 309 if (start == end) |
| 305 endPosition = startPosition; | 310 endPosition = startPosition; |
| 306 else | 311 else |
| 307 endPosition = visiblePositionForIndex(end); | 312 endPosition = visiblePositionForIndex(end); |
| 308 | 313 |
| 309 // startPosition and endPosition can be null position for example when | 314 // startPosition and endPosition can be null position for example when |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 Text* textNode = toText(node); | 906 Text* textNode = toText(node); |
| 902 size_t firstLineBreak = textNode->data().find('\n', isPivotNode ? pi votPosition.offsetInContainerNode() : 0); | 907 size_t firstLineBreak = textNode->data().find('\n', isPivotNode ? pi votPosition.offsetInContainerNode() : 0); |
| 903 if (firstLineBreak != kNotFound) | 908 if (firstLineBreak != kNotFound) |
| 904 return Position(textNode, firstLineBreak + 1); | 909 return Position(textNode, firstLineBreak + 1); |
| 905 } | 910 } |
| 906 } | 911 } |
| 907 return endOfInnerText(textFormControl); | 912 return endOfInnerText(textFormControl); |
| 908 } | 913 } |
| 909 | 914 |
| 910 } // namespace Webcore | 915 } // namespace Webcore |
| OLD | NEW |