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

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

Issue 1269263003: The start and end arguments should be unsigned long in setSelectionRange() function Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixing tests Created 5 years, 4 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
« no previous file with comments | « Source/core/html/HTMLTextFormControlElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 259
260 if (newSelectionEnd > end) 260 if (newSelectionEnd > end)
261 newSelectionEnd += delta; 261 newSelectionEnd += delta;
262 else if (newSelectionEnd > start) 262 else if (newSelectionEnd > start)
263 newSelectionEnd = start + replacementLength; 263 newSelectionEnd = start + replacementLength;
264 } 264 }
265 265
266 setSelectionRange(newSelectionStart, newSelectionEnd, SelectionHasNoDirectio n); 266 setSelectionRange(newSelectionStart, newSelectionEnd, SelectionHasNoDirectio n);
267 } 267 }
268 268
269 void HTMLTextFormControlElement::setSelectionRange(int start, int end, const Str ing& directionString) 269 void HTMLTextFormControlElement::setSelectionRange(unsigned start, unsigned end, const String& directionString)
270 { 270 {
271 TextFieldSelectionDirection direction = SelectionHasNoDirection; 271 TextFieldSelectionDirection direction = SelectionHasNoDirection;
272 if (directionString == "forward") 272 if (directionString == "forward")
273 direction = SelectionHasForwardDirection; 273 direction = SelectionHasForwardDirection;
274 else if (directionString == "backward") 274 else if (directionString == "backward")
275 direction = SelectionHasBackwardDirection; 275 direction = SelectionHasBackwardDirection;
276 276
277 if (direction == SelectionHasNoDirection && document().frame() && document() .frame()->editor().behavior().shouldConsiderSelectionAsDirectional()) 277 if (direction == SelectionHasNoDirection && document().frame() && document() .frame()->editor().behavior().shouldConsiderSelectionAsDirectional())
278 direction = SelectionHasForwardDirection; 278 direction = SelectionHasForwardDirection;
279 279
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 index += length; 339 index += length;
340 } else if (node->hasTagName(brTag)) { 340 } else if (node->hasTagName(brTag)) {
341 ++index; 341 ++index;
342 } 342 }
343 } 343 }
344 344
345 ASSERT(index >= 0); 345 ASSERT(index >= 0);
346 return index; 346 return index;
347 } 347 }
348 348
349 void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField SelectionDirection direction, NeedToDispatchSelectEvent eventBehaviour, Selectio nOption selectionOption) 349 void HTMLTextFormControlElement::setSelectionRange(unsigned start, unsigned end, TextFieldSelectionDirection direction, NeedToDispatchSelectEvent eventBehaviour , SelectionOption selectionOption)
350 { 350 {
351 if (openShadowRoot() || !isTextFormControl() || !inDocument()) 351 if (openShadowRoot() || !isTextFormControl() || !inDocument())
352 return; 352 return;
353 353
354 const int editorValueLength = static_cast<int>(innerEditorValue().length()); 354 const int editorValueLength = static_cast<int>(innerEditorValue().length());
philipj_slow 2015/08/12 13:20:03 Making this unsigned now would make more sense.
tanay.c 2015/08/14 05:39:11 Done.
355 ASSERT(editorValueLength >= 0); 355 ASSERT(editorValueLength >= 0);
356 end = std::max(std::min(end, editorValueLength), 0); 356 end = std::min<unsigned>(end, editorValueLength);
357 start = std::min(std::max(start, 0), end); 357 start = std::min<unsigned>(start, end);
358 cacheSelection(start, end, direction); 358 cacheSelection(start, end, direction);
359 359
360 if (selectionOption == NotChangeSelection || (selectionOption == ChangeSelec tionIfFocused && document().focusedElement() != this)) { 360 if (selectionOption == NotChangeSelection || (selectionOption == ChangeSelec tionIfFocused && document().focusedElement() != this)) {
361 if (eventBehaviour == DispatchSelectEvent) 361 if (eventBehaviour == DispatchSelectEvent)
362 scheduleSelectEvent(); 362 scheduleSelectEvent();
363 return; 363 return;
364 } 364 }
365 365
366 LocalFrame* frame = document().frame(); 366 LocalFrame* frame = document().frame();
367 HTMLElement* innerEditor = innerEditorElement(); 367 HTMLElement* innerEditor = innerEditorElement();
368 if (!frame || !innerEditor) 368 if (!frame || !innerEditor)
369 return; 369 return;
370 370
371 Position startPosition = positionForIndex(innerEditor, start); 371 Position startPosition = positionForIndex(innerEditor, start);
372 Position endPosition = start == end ? startPosition : positionForIndex(inner Editor, end); 372 Position endPosition = start == end ? startPosition : positionForIndex(inner Editor, end);
373 373
374 ASSERT(start == indexForPosition(innerEditor, startPosition)); 374 ASSERT(start == (unsigned)indexForPosition(innerEditor, startPosition));
philipj_slow 2015/08/12 13:20:03 So indexForPosition() still returns int. It looks
tanay.c 2015/08/14 05:39:11 It may not be possible to find a clean cut boundar
375 ASSERT(end == indexForPosition(innerEditor, endPosition)); 375 ASSERT(end == (unsigned)indexForPosition(innerEditor, endPosition));
376 376
377 // startPosition and endPosition can be null position for example when 377 // startPosition and endPosition can be null position for example when
378 // "-webkit-user-select: none" style attribute is specified. 378 // "-webkit-user-select: none" style attribute is specified.
379 if (startPosition.isNotNull() && endPosition.isNotNull()) { 379 if (startPosition.isNotNull() && endPosition.isNotNull()) {
380 ASSERT(startPosition.anchorNode()->shadowHost() == this 380 ASSERT(startPosition.anchorNode()->shadowHost() == this
381 && endPosition.anchorNode()->shadowHost() == this); 381 && endPosition.anchorNode()->shadowHost() == this);
382 } 382 }
383 VisibleSelection newSelection; 383 VisibleSelection newSelection;
384 if (direction == SelectionHasBackwardDirection) 384 if (direction == SelectionHasBackwardDirection)
385 newSelection.setWithoutValidation(endPosition, startPosition); 385 newSelection.setWithoutValidation(endPosition, startPosition);
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 } 1003 }
1004 1004
1005 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele ment& source) 1005 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele ment& source)
1006 { 1006 {
1007 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText FormControlElement&>(source); 1007 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText FormControlElement&>(source);
1008 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; 1008 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit;
1009 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); 1009 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source);
1010 } 1010 }
1011 1011
1012 } // namespace blink 1012 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/HTMLTextFormControlElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698