Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Side by Side Diff: Source/core/html/HTMLTextFormControlElement.cpp

Issue 392573002: HTMLTextAreaElement.setSelectionRange should not change focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update validity before updatelayout Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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"
45 #include "core/page/FocusController.h"
46 #include "core/page/Page.h"
47 #include "core/rendering/RenderBlock.h"
44 #include "core/rendering/RenderBlockFlow.h" 48 #include "core/rendering/RenderBlockFlow.h"
45 #include "core/rendering/RenderTheme.h" 49 #include "core/rendering/RenderTheme.h"
46 #include "platform/heap/Handle.h" 50 #include "platform/heap/Handle.h"
47 #include "platform/text/TextBoundaries.h" 51 #include "platform/text/TextBoundaries.h"
48 #include "wtf/text/StringBuilder.h" 52 #include "wtf/text/StringBuilder.h"
49 53
50 namespace blink { 54 namespace blink {
51 55
52 using namespace HTMLNames; 56 using namespace HTMLNames;
53 57
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 setSelectionRange(std::min(end, selectionStart()), end, selectionDirection() ); 177 setSelectionRange(std::min(end, selectionStart()), end, selectionDirection() );
174 } 178 }
175 179
176 void HTMLTextFormControlElement::setSelectionDirection(const String& direction) 180 void HTMLTextFormControlElement::setSelectionDirection(const String& direction)
177 { 181 {
178 setSelectionRange(selectionStart(), selectionEnd(), direction); 182 setSelectionRange(selectionStart(), selectionEnd(), direction);
179 } 183 }
180 184
181 void HTMLTextFormControlElement::select() 185 void HTMLTextFormControlElement::select()
182 { 186 {
183 setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirectio n); 187 document().updateLayoutIgnorePendingStylesheets();
188 if (isFocusable()) {
189 RefPtrWillBeRawPtr<HTMLTextFormControlElement> protector(this);
tkent 2014/07/24 01:04:22 This should be moved to the outside of the |if|.
yoichio 2014/07/24 03:06:07 Done.
190 document().page()->focusController().setFocusedElement(this, document(). frame());
191 }
192 setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirectio n, ChangeSelection);
184 } 193 }
185 194
186 bool HTMLTextFormControlElement::shouldDispatchFormControlChangeEvent(String& ol dValue, String& newValue) 195 bool HTMLTextFormControlElement::shouldDispatchFormControlChangeEvent(String& ol dValue, String& newValue)
187 { 196 {
188 return !equalIgnoringNullity(oldValue, newValue); 197 return !equalIgnoringNullity(oldValue, newValue);
189 } 198 }
190 199
191 void HTMLTextFormControlElement::dispatchFormControlChangeEvent() 200 void HTMLTextFormControlElement::dispatchFormControlChangeEvent()
192 { 201 {
193 String newValue = value(); 202 String newValue = value();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 276 }
268 277
269 void HTMLTextFormControlElement::setSelectionRange(int start, int end, const Str ing& directionString) 278 void HTMLTextFormControlElement::setSelectionRange(int start, int end, const Str ing& directionString)
270 { 279 {
271 TextFieldSelectionDirection direction = SelectionHasNoDirection; 280 TextFieldSelectionDirection direction = SelectionHasNoDirection;
272 if (directionString == "forward") 281 if (directionString == "forward")
273 direction = SelectionHasForwardDirection; 282 direction = SelectionHasForwardDirection;
274 else if (directionString == "backward") 283 else if (directionString == "backward")
275 direction = SelectionHasBackwardDirection; 284 direction = SelectionHasBackwardDirection;
276 285
286 if (direction == SelectionHasNoDirection && document().frame() && document() .frame()->editor().behavior().shouldConsiderSelectionAsDirectional())
287 direction = SelectionHasForwardDirection;
288
277 return setSelectionRange(start, end, direction); 289 return setSelectionRange(start, end, direction);
278 } 290 }
279 291
280 void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField SelectionDirection direction) 292 void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField SelectionDirection direction, SelectionOption selectionOption)
281 { 293 {
294 setNeedsValidityCheck();
282 document().updateLayoutIgnorePendingStylesheets(); 295 document().updateLayoutIgnorePendingStylesheets();
283 296
284 if (!renderer() || !renderer()->isTextControl()) 297 if (!renderer() || !renderer()->isTextControl())
285 return; 298 return;
286 299
287 end = std::max(end, 0); 300 end = std::max(end, 0);
288 start = std::min(std::max(start, 0), end); 301 start = std::min(std::max(start, 0), end);
302 cacheSelection(start, end, direction);
303 if (!hasVisibleTextArea(renderer(), innerEditorElement()))
304 return;
289 305
290 if (!hasVisibleTextArea(renderer(), innerEditorElement())) { 306 LocalFrame* frame = document().frame();
291 cacheSelection(start, end, direction); 307
308 if (!frame)
292 return; 309 return;
293 } 310
311 if (selectionOption == NotChangeSelection && document().focusedElement() != this)
312 return;
313
294 VisiblePosition startPosition = visiblePositionForIndex(start); 314 VisiblePosition startPosition = visiblePositionForIndex(start);
295 VisiblePosition endPosition; 315 VisiblePosition endPosition;
296 if (start == end) 316 if (start == end)
297 endPosition = startPosition; 317 endPosition = startPosition;
298 else 318 else
299 endPosition = visiblePositionForIndex(end); 319 endPosition = visiblePositionForIndex(end);
300 320
301 // startPosition and endPosition can be null position for example when 321 // startPosition and endPosition can be null position for example when
302 // "-webkit-user-select: none" style attribute is specified. 322 // "-webkit-user-select: none" style attribute is specified.
303 if (startPosition.isNotNull() && endPosition.isNotNull()) { 323 if (startPosition.isNotNull() && endPosition.isNotNull()) {
304 ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowHost() == this 324 ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowHost() == this
305 && endPosition.deepEquivalent().deprecatedNode()->shadowHost() == th is); 325 && endPosition.deepEquivalent().deprecatedNode()->shadowHost() == th is);
306 } 326 }
307 VisibleSelection newSelection; 327 VisibleSelection newSelection;
308 if (direction == SelectionHasBackwardDirection) 328 if (direction == SelectionHasBackwardDirection)
309 newSelection = VisibleSelection(endPosition, startPosition); 329 newSelection = VisibleSelection(endPosition, startPosition);
310 else 330 else
311 newSelection = VisibleSelection(startPosition, endPosition); 331 newSelection = VisibleSelection(startPosition, endPosition);
312 newSelection.setIsDirectional(direction != SelectionHasNoDirection); 332 newSelection.setIsDirectional(direction != SelectionHasNoDirection);
313 333
314 if (LocalFrame* frame = document().frame()) 334 frame->selection().setSelection(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSelection::DoNotSetFocus);
315 frame->selection().setSelection(newSelection);
316 } 335 }
317 336
318 VisiblePosition HTMLTextFormControlElement::visiblePositionForIndex(int index) c onst 337 VisiblePosition HTMLTextFormControlElement::visiblePositionForIndex(int index) c onst
319 { 338 {
320 if (index <= 0) 339 if (index <= 0)
321 return VisiblePosition(firstPositionInNode(innerEditorElement()), DOWNST REAM); 340 return VisiblePosition(firstPositionInNode(innerEditorElement()), DOWNST REAM);
322 RefPtrWillBeRawPtr<Range> range = Range::create(document()); 341 RefPtrWillBeRawPtr<Range> range = Range::create(document());
323 range->selectNodeContents(innerEditorElement(), ASSERT_NO_EXCEPTION); 342 range->selectNodeContents(innerEditorElement(), ASSERT_NO_EXCEPTION);
324 CharacterIterator it(range.get()); 343 CharacterIterator it(range.get());
325 it.advance(index - 1); 344 it.advance(index - 1);
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 Text* textNode = toText(node); 913 Text* textNode = toText(node);
895 size_t firstLineBreak = textNode->data().find('\n', isPivotNode ? pi votPosition.offsetInContainerNode() : 0); 914 size_t firstLineBreak = textNode->data().find('\n', isPivotNode ? pi votPosition.offsetInContainerNode() : 0);
896 if (firstLineBreak != kNotFound) 915 if (firstLineBreak != kNotFound)
897 return Position(textNode, firstLineBreak + 1); 916 return Position(textNode, firstLineBreak + 1);
898 } 917 }
899 } 918 }
900 return endOfInnerText(textFormControl); 919 return endOfInnerText(textFormControl);
901 } 920 }
902 921
903 } // namespace Webcore 922 } // namespace Webcore
OLDNEW
« Source/core/html/HTMLTextAreaElement.cpp ('K') | « Source/core/html/HTMLTextFormControlElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698