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

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

Issue 1377963004: Use FrameSelection::selectedText where possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comments. Created 5 years, 2 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 setSelectionRange(std::min(end, selectionStart()), end, selectionDirection() ); 182 setSelectionRange(std::min(end, selectionStart()), end, selectionDirection() );
183 } 183 }
184 184
185 void HTMLTextFormControlElement::setSelectionDirection(const String& direction) 185 void HTMLTextFormControlElement::setSelectionDirection(const String& direction)
186 { 186 {
187 setSelectionRange(selectionStart(), selectionEnd(), direction); 187 setSelectionRange(selectionStart(), selectionEnd(), direction);
188 } 188 }
189 189
190 void HTMLTextFormControlElement::select(NeedToDispatchSelectEvent eventBehaviour ) 190 void HTMLTextFormControlElement::select(NeedToDispatchSelectEvent eventBehaviour )
191 { 191 {
192 // We have to update layout here to use isFocusable().
192 document().updateLayoutIgnorePendingStylesheets(); 193 document().updateLayoutIgnorePendingStylesheets();
193 setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirectio n, eventBehaviour, isFocusable() ? ChangeSelectionAndFocus : NotChangeSelection) ; 194 setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirectio n, eventBehaviour, isFocusable() ? ChangeSelectionAndFocus : NotChangeSelection) ;
194 } 195 }
195 196
196 bool HTMLTextFormControlElement::shouldDispatchFormControlChangeEvent(String& ol dValue, String& newValue) 197 bool HTMLTextFormControlElement::shouldDispatchFormControlChangeEvent(String& ol dValue, String& newValue)
197 { 198 {
198 return !equalIgnoringNullity(oldValue, newValue); 199 return !equalIgnoringNullity(oldValue, newValue);
199 } 200 }
200 201
201 void HTMLTextFormControlElement::dispatchFormControlChangeEvent() 202 void HTMLTextFormControlElement::dispatchFormControlChangeEvent()
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 348
348 ASSERT(index >= 0); 349 ASSERT(index >= 0);
349 return index; 350 return index;
350 } 351 }
351 352
352 void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField SelectionDirection direction, NeedToDispatchSelectEvent eventBehaviour, Selectio nOption selectionOption) 353 void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField SelectionDirection direction, NeedToDispatchSelectEvent eventBehaviour, Selectio nOption selectionOption)
353 { 354 {
354 if (openShadowRoot() || !isTextFormControl() || !inDocument()) 355 if (openShadowRoot() || !isTextFormControl() || !inDocument())
355 return; 356 return;
356 357
358 // We need to update layout here so that we have proper types for both dom t ree and composed tree selection.
359 // See https://codereview.chromium.org/1377963004/
360 document().updateLayoutIgnorePendingStylesheets();
361
357 const int editorValueLength = static_cast<int>(innerEditorValue().length()); 362 const int editorValueLength = static_cast<int>(innerEditorValue().length());
358 ASSERT(editorValueLength >= 0); 363 ASSERT(editorValueLength >= 0);
359 end = std::max(std::min(end, editorValueLength), 0); 364 end = std::max(std::min(end, editorValueLength), 0);
360 start = std::min(std::max(start, 0), end); 365 start = std::min(std::max(start, 0), end);
361 cacheSelection(start, end, direction); 366 cacheSelection(start, end, direction);
362 367
363 if (selectionOption == NotChangeSelection || (selectionOption == ChangeSelec tionIfFocused && document().focusedElement() != this)) { 368 if (selectionOption == NotChangeSelection || (selectionOption == ChangeSelec tionIfFocused && document().focusedElement() != this)) {
364 if (eventBehaviour == DispatchSelectEvent) 369 if (eventBehaviour == DispatchSelectEvent)
365 scheduleSelectEvent(); 370 scheduleSelectEvent();
366 return; 371 return;
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 } 1020 }
1016 1021
1017 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele ment& source) 1022 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele ment& source)
1018 { 1023 {
1019 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText FormControlElement&>(source); 1024 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText FormControlElement&>(source);
1020 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; 1025 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit;
1021 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); 1026 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source);
1022 } 1027 }
1023 1028
1024 } // namespace blink 1029 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698