Changeset 269587 in webkit
- Timestamp:
- Nov 9, 2020 11:08:31 AM (21 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 21 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/forms/input-first-letter-edit-expected.html (modified) (1 diff)
-
LayoutTests/fast/forms/input-first-letter-edit.html (modified) (1 diff)
-
LayoutTests/fast/forms/input-text-autofocus-expected.txt (added)
-
LayoutTests/fast/forms/input-text-autofocus.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/dom/Document.h (modified) (1 diff)
-
Source/WebCore/dom/Element.cpp (modified) (2 diffs)
-
Source/WebCore/dom/Element.h (modified) (1 diff)
-
Source/WebCore/history/CachedPage.cpp (modified) (1 diff)
-
Source/WebCore/html/HTMLFormControlElement.cpp (modified) (1 diff)
-
Source/WebCore/html/HTMLInputElement.cpp (modified) (4 diffs)
-
Source/WebCore/html/HTMLInputElement.h (modified) (1 diff)
-
Source/WebCore/html/HTMLLabelElement.cpp (modified) (3 diffs)
-
Source/WebCore/html/HTMLLabelElement.h (modified) (1 diff)
-
Source/WebCore/html/HTMLLegendElement.cpp (modified) (2 diffs)
-
Source/WebCore/html/HTMLLegendElement.h (modified) (1 diff)
-
Source/WebCore/html/HTMLTextAreaElement.cpp (modified) (1 diff)
-
Source/WebCore/html/InputType.cpp (modified) (1 diff)
-
Source/WebCore/page/EventHandler.cpp (modified) (1 diff)
-
Source/WebCore/page/FocusController.cpp (modified) (2 diffs)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/WebProcess/WebPage/WebPage.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r269584 r269587 1 2020-11-09 Devin Rousso <drousso@apple.com> 2 3 autofocus of text input should not select text 4 https://bugs.webkit.org/show_bug.cgi?id=218585 5 <rdar://problem/60130704> 6 7 Reviewed by Wenson Hsieh. 8 9 * fast/forms/input-text-autofocus.html: Added. 10 * fast/forms/input-text-autofocus-expected.txt: Added. 11 12 * fast/forms/input-first-letter-edit.html: 13 * fast/forms/input-first-letter-edit-expected.html: 14 1 15 2020-11-09 Per Arne Vollan <pvollan@apple.com> 2 16 -
trunk/LayoutTests/fast/forms/input-first-letter-edit-expected.html
r118711 r269587 4 4 </head> 5 5 <body> 6 <input type="text" id="target" value="Hello" autofocus="autofocus"/>6 <input type="text" id="target" value="Hello" /> 7 7 </body> 8 8 </html> -
trunk/LayoutTests/fast/forms/input-first-letter-edit.html
r121008 r269587 20 20 eventSender.keyDown("l"); 21 21 eventSender.keyDown("o"); 22 document.execCommand("selectAll"); // Does selectAll for aligning the @autofocus attribute on the expectation.22 target.blur(); 23 23 testRunner.notifyDone(); 24 24 } -
trunk/Source/WebCore/ChangeLog
r269585 r269587 1 2020-11-09 Devin Rousso <drousso@apple.com> 2 3 autofocus of text input should not select text 4 https://bugs.webkit.org/show_bug.cgi?id=218585 5 <rdar://problem/60130704> 6 7 Reviewed by Wenson Hsieh. 8 9 Test: fast/forms/input-text-autofocus.html 10 11 * dom/Document.h: 12 * history/CachedPage.cpp: 13 (WebCore::CachedPage::restore): 14 * html/HTMLInputElement.h: 15 * html/HTMLInputElement.cpp: 16 (WebCore::HTMLInputElement::updateFocusAppearance): 17 (WebCore::HTMLInputElement::setDefaultSelectionAfterFocus): 18 (WebCore::HTMLInputElement::runPostTypeUpdateTasks): 19 (WebCore::HTMLInputElement::didAttachRenderers): 20 * html/HTMLTextAreaElement.cpp: 21 (WebCore::HTMLTextAreaElement::updateFocusAppearance): 22 * html/InputType.cpp: 23 (WebCore::InputType::accessKeyAction): 24 * page/EventHandler.cpp: 25 (WebCore::EventHandler::dispatchMouseEvent): 26 * page/FocusController.cpp: 27 (WebCore::FocusController::advanceFocusInDocumentOrder): 28 (WebCore::FocusController::advanceFocusDirectionallyInContainer): 29 Slightly rework `SelectionRestorationMode` to replace `SetDefault` with two new values: 30 - `PlaceCaretAtStart` puts the caret at the start, regardless of any cached selection 31 - `SelectAll` selects all text, regardless of any cached selection (existing behavior) 32 In order to preserve existing behavior, the default `Restore` will have the same effect as 33 `SelectAll` if there is no cached selection (and is renamed to `RestoreOrSelectAll` as such). 34 35 * dom/Element.h: 36 * dom/Element.cpp: 37 (WebCore::Element::focus): 38 * html/HTMLLabelElement.h: 39 * html/HTMLLabelElement.cpp: 40 (WebCore::HTMLLabelElement::focus): 41 * html/HTMLLegendElement.h: 42 * html/HTMLLegendElement.cpp: 43 (WebCore::HTMLLegendElement::focus): 44 Replace the `bool restorePreviousSelection` with `SelectionRestorationMode` since that's 45 what it's eventually used for anyways. This also allows for more flexibility in behavior, 46 such as callers using the new `SelectionRestorationMode` values. 47 48 * html/HTMLFormControlElement.cpp: 49 (WebCore::HTMLFormControlElement::didAttachRenderers): 50 Change to `PlaceCaretAtStart` to match other browsers. 51 1 52 2020-11-09 Antti Koivisto <antti@apple.com> 2 53 -
trunk/Source/WebCore/dom/Document.h
r269437 r269587 289 289 enum DimensionsCheck { WidthDimensionsCheck = 1 << 0, HeightDimensionsCheck = 1 << 1, AllDimensionsCheck = 1 << 2 }; 290 290 291 enum class SelectionRestorationMode { Restore, SetDefault }; 291 enum class SelectionRestorationMode : uint8_t { 292 RestoreOrSelectAll, 293 SelectAll, 294 PlaceCaretAtStart, 295 }; 292 296 293 297 enum class HttpEquivPolicy { -
trunk/Source/WebCore/dom/Element.cpp
r269161 r269587 2994 2994 } 2995 2995 2996 void Element::focus( bool restorePreviousSelection, FocusDirection direction)2996 void Element::focus(SelectionRestorationMode restorationMode, FocusDirection direction) 2997 2997 { 2998 2998 if (!isConnected()) … … 3042 3042 } 3043 3043 3044 newTarget->revealFocusedElement(restor ePreviousSelection ? SelectionRestorationMode::Restore : SelectionRestorationMode::SetDefault);3044 newTarget->revealFocusedElement(restorationMode); 3045 3045 } 3046 3046 -
trunk/Source/WebCore/dom/Element.h
r269027 r269587 401 401 402 402 static AXTextStateChangeIntent defaultFocusTextStateChangeIntent() { return AXTextStateChangeIntent(AXTextStateChangeTypeSelectionMove, AXTextSelection { AXTextSelectionDirectionDiscontiguous, AXTextSelectionGranularityUnknown, true }); } 403 virtual void focus( bool restorePreviousSelection = true, FocusDirection = FocusDirection::None);403 virtual void focus(SelectionRestorationMode = SelectionRestorationMode::RestoreOrSelectAll, FocusDirection = FocusDirection::None); 404 404 void revealFocusedElement(SelectionRestorationMode); 405 405 virtual RefPtr<Element> focusAppearanceUpdateTarget(); -
trunk/Source/WebCore/history/CachedPage.cpp
r267614 r269587 146 146 } 147 147 #endif 148 element->updateFocusAppearance(SelectionRestorationMode::Restore );148 element->updateFocusAppearance(SelectionRestorationMode::RestoreOrSelectAll); 149 149 #if PLATFORM(IOS_FAMILY) 150 150 if (frameView) -
trunk/Source/WebCore/html/HTMLFormControlElement.cpp
r268866 r269587 255 255 if (frameView && frameView->layoutContext().isInLayout()) { 256 256 frameView->queuePostLayoutCallback([element] { 257 element->focus( );257 element->focus(SelectionRestorationMode::PlaceCaretAtStart); 258 258 }); 259 259 } else { 260 260 Style::queuePostResolutionCallback([element] { 261 element->focus( );261 element->focus(SelectionRestorationMode::PlaceCaretAtStart); 262 262 }); 263 263 } -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r269528 r269587 477 477 { 478 478 if (isTextField()) { 479 if (restorationMode == SelectionRestorationMode:: SetDefault || !hasCachedSelection())480 setDefaultSelectionAfterFocus(revealMode);479 if (restorationMode == SelectionRestorationMode::RestoreOrSelectAll && hasCachedSelection()) 480 restoreCachedSelection(revealMode); 481 481 else 482 restoreCachedSelection(revealMode);482 setDefaultSelectionAfterFocus(restorationMode, revealMode); 483 483 } else 484 484 HTMLTextFormControlElement::updateFocusAppearance(restorationMode, revealMode); 485 485 } 486 486 487 void HTMLInputElement::setDefaultSelectionAfterFocus(SelectionRe vealMode revealMode)487 void HTMLInputElement::setDefaultSelectionAfterFocus(SelectionRestorationMode restorationMode, SelectionRevealMode revealMode) 488 488 { 489 489 ASSERT(isTextField()); … … 495 495 direction = SelectionHasForwardDirection; 496 496 } 497 setSelectionRange(start, std::numeric_limits<int>::max(), direction, revealMode, Element::defaultFocusTextStateChangeIntent()); 497 int end = restorationMode == SelectionRestorationMode::PlaceCaretAtStart ? start : std::numeric_limits<int>::max(); 498 setSelectionRange(start, end, direction, revealMode, Element::defaultFocusTextStateChangeIntent()); 498 499 } 499 500 … … 619 620 620 621 if (document().focusedElement() == this) 621 updateFocusAppearance(SelectionRestorationMode::Restore , SelectionRevealMode::Reveal);622 updateFocusAppearance(SelectionRestorationMode::RestoreOrSelectAll, SelectionRevealMode::Reveal); 622 623 623 624 setChangedSinceLastFormControlChangeEvent(false); … … 867 868 if (document().focusedElement() == this) { 868 869 document().view()->queuePostLayoutCallback([protectedThis = makeRef(*this)] { 869 protectedThis->updateFocusAppearance(SelectionRestorationMode::Restore , SelectionRevealMode::Reveal);870 protectedThis->updateFocusAppearance(SelectionRestorationMode::RestoreOrSelectAll, SelectionRevealMode::Reveal); 870 871 }); 871 872 } -
trunk/Source/WebCore/html/HTMLInputElement.h
r266114 r269587 456 456 void removeFromRadioButtonGroup(); 457 457 458 void setDefaultSelectionAfterFocus(SelectionRe vealMode);458 void setDefaultSelectionAfterFocus(SelectionRestorationMode, SelectionRevealMode); 459 459 460 460 AtomString m_name; -
trunk/Source/WebCore/html/HTMLLabelElement.cpp
r259687 r269587 173 173 } 174 174 175 void HTMLLabelElement::focus( bool restorePreviousSelection, FocusDirection direction)175 void HTMLLabelElement::focus(SelectionRestorationMode restorationMode, FocusDirection direction) 176 176 { 177 177 Ref<HTMLLabelElement> protectedThis(*this); … … 179 179 document().updateLayout(); 180 180 if (isFocusable()) { 181 // The value of restor ePreviousSelectionis not used for label elements as it doesn't override updateFocusAppearance.182 Element::focus(restor ePreviousSelection, direction);181 // The value of restorationMode is not used for label elements as it doesn't override updateFocusAppearance. 182 Element::focus(restorationMode, direction); 183 183 return; 184 184 } … … 187 187 // To match other browsers, always restore previous selection. 188 188 if (auto element = control()) 189 element->focus( true, direction);189 element->focus(SelectionRestorationMode::RestoreOrSelectAll, direction); 190 190 } 191 191 -
trunk/Source/WebCore/html/HTMLLabelElement.h
r259687 r269587 52 52 void defaultEventHandler(Event&) final; 53 53 54 void focus( bool restorePreviousSelection, FocusDirection) final;54 void focus(SelectionRestorationMode, FocusDirection) final; 55 55 56 56 bool isInteractiveContent() const final { return true; } -
trunk/Source/WebCore/html/HTMLLegendElement.cpp
r259687 r269587 58 58 } 59 59 60 void HTMLLegendElement::focus( bool restorePreviousSelection, FocusDirection direction)60 void HTMLLegendElement::focus(SelectionRestorationMode restorationMode, FocusDirection direction) 61 61 { 62 62 if (document().haveStylesheetsLoaded()) { 63 63 document().updateLayoutIgnorePendingStylesheets(); 64 64 if (isFocusable()) { 65 Element::focus(restor ePreviousSelection, direction);65 Element::focus(restorationMode, direction); 66 66 return; 67 67 } … … 70 70 // To match other browsers' behavior, never restore previous selection. 71 71 if (auto control = associatedControl()) 72 control->focus( false, direction);72 control->focus(SelectionRestorationMode::SelectAll, direction); 73 73 } 74 74 -
trunk/Source/WebCore/html/HTMLLegendElement.h
r259687 r269587 44 44 45 45 bool accessKeyAction(bool sendMouseEvents) final; 46 void focus( bool restorePreviousSelection, FocusDirection) final;46 void focus(SelectionRestorationMode, FocusDirection) final; 47 47 }; 48 48 -
trunk/Source/WebCore/html/HTMLTextAreaElement.cpp
r266026 r269587 269 269 void HTMLTextAreaElement::updateFocusAppearance(SelectionRestorationMode restorationMode, SelectionRevealMode revealMode) 270 270 { 271 if (restorationMode == SelectionRestorationMode::SetDefault || !hasCachedSelection()) { 271 if (restorationMode == SelectionRestorationMode::RestoreOrSelectAll && hasCachedSelection()) 272 restoreCachedSelection(revealMode, Element::defaultFocusTextStateChangeIntent()); 273 else { 272 274 // If this is the first focus, set a caret at the beginning of the text. 273 275 // This matches some browsers' behavior; see bug 11746 Comment #15. 274 276 // http://bugs.webkit.org/show_bug.cgi?id=11746#c15 275 277 setSelectionRange(0, 0, SelectionHasNoDirection, revealMode, Element::defaultFocusTextStateChangeIntent()); 276 } else 277 restoreCachedSelection(revealMode, Element::defaultFocusTextStateChangeIntent()); 278 } 278 279 } 279 280 -
trunk/Source/WebCore/html/InputType.cpp
r266114 r269587 583 583 { 584 584 ASSERT(element()); 585 element()->focus( false);585 element()->focus(SelectionRestorationMode::SelectAll); 586 586 return false; 587 587 } -
trunk/Source/WebCore/page/EventHandler.cpp
r269442 r269587 2754 2754 2755 2755 if (element && m_mouseDownDelegatedFocus) 2756 element->revealFocusedElement(SelectionRestorationMode::Se tDefault);2756 element->revealFocusedElement(SelectionRestorationMode::SelectAll); 2757 2757 2758 2758 return true; -
trunk/Source/WebCore/page/FocusController.cpp
r269059 r269587 534 534 } 535 535 536 element->focus( false, direction);536 element->focus(SelectionRestorationMode::SelectAll, direction); 537 537 return true; 538 538 } … … 1108 1108 ASSERT(element); 1109 1109 1110 element->focus( false, direction);1110 element->focus(SelectionRestorationMode::SelectAll, direction); 1111 1111 return true; 1112 1112 } -
trunk/Source/WebKit/ChangeLog
r269584 r269587 1 2020-11-09 Devin Rousso <drousso@apple.com> 2 3 autofocus of text input should not select text 4 https://bugs.webkit.org/show_bug.cgi?id=218585 5 <rdar://problem/60130704> 6 7 Reviewed by Wenson Hsieh. 8 9 * WebProcess/WebPage/WebPage.cpp: 10 (WebKit::WebPage::restoreSelectionInFocusedEditableElement): 11 Slightly rework `SelectionRestorationMode` to replace `SetDefault` with two new values: 12 - `PlaceCaretAtStart` puts the caret at the start, regardless of any cached selection 13 - `SelectAll` selects all text, regardless of any cached selection (existing behavior) 14 In order to preserve existing behavior, the default `Restore` will have the same effect as 15 `SelectAll` if there is no cached selection (and is renamed to `RestoreOrSelectAll` as such). 16 1 17 2020-11-09 Per Arne Vollan <pvollan@apple.com> 2 18 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r269498 r269587 4571 4571 if (auto document = frame.document()) { 4572 4572 if (auto element = document->focusedElement()) 4573 element->updateFocusAppearance(SelectionRestorationMode::Restore , SelectionRevealMode::DoNotReveal);4573 element->updateFocusAppearance(SelectionRestorationMode::RestoreOrSelectAll, SelectionRevealMode::DoNotReveal); 4574 4574 } 4575 4575 }
Note: See TracChangeset
for help on using the changeset viewer.