Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/FrameSelection.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/FrameSelection.cpp b/third_party/WebKit/Source/core/editing/FrameSelection.cpp |
| index f639ca8f81ff559310430e556eec87b95de382ab..544b556c81cdcbd551b75c7346d14b0969e70e49 100644 |
| --- a/third_party/WebKit/Source/core/editing/FrameSelection.cpp |
| +++ b/third_party/WebKit/Source/core/editing/FrameSelection.cpp |
| @@ -250,7 +250,7 @@ void FrameSelection::DidSetSelectionDeprecated(SetSelectionOptions options, |
| } |
| frame_caret_->StopCaretBlinkTimer(); |
| - UpdateAppearance(LayoutSelection::PaintHint::kPaint); |
| + UpdateAppearance(); |
| // Always clear the x position used for vertical arrow navigation. |
| // It will be restored by the vertical arrow navigation code if necessary. |
| @@ -335,26 +335,7 @@ void FrameSelection::DidChangeFocus() { |
| // Hits in |
| // virtual/gpu/compositedscrolling/scrollbars/scrollbar-miss-mousemove-disabled.html |
| DisableCompositingQueryAsserts disabler; |
| - |
| - // No focused element means document root has focus. |
| - const Element* const focus = GetDocument().FocusedElement() |
| - ? GetDocument().FocusedElement() |
| - : GetDocument().documentElement(); |
| - |
| - // Protection against LayoutTests/editing/selection/selection-crash.html |
| - if (!focus) { |
| - frame_caret_->ScheduleVisualUpdateForPaintInvalidationIfNeeded(); |
| - text_control_focused_ = false; |
| - return; |
| - } |
| - |
| - // Hide the selection when focus goes away from a text-field and into |
| - // something that is not a text-field. When focus enters another text-field we |
| - // do not need to update appearance; the appearance is updated when the new |
| - // selection is set. |
| - if (text_control_focused_ && !focus->IsTextControl()) |
| - UpdateAppearance(LayoutSelection::PaintHint::kHide); |
| - text_control_focused_ = focus->IsTextControl(); |
| + UpdateAppearance(); |
| } |
| static DispatchEventResult DispatchSelectStart( |
| @@ -444,6 +425,48 @@ void FrameSelection::Clear() { |
| SetSelection(SelectionInDOMTree()); |
| } |
| +bool FrameSelection::IsHidden() { |
|
yosin_UTC9
2017/04/28 07:57:09
I would like to call this function as |HasFocus()|
|
| + // No focused element means document root has focus. |
| + const Element* const focus_element = GetDocument().FocusedElement() |
| + ? GetDocument().FocusedElement() |
| + : GetDocument().documentElement(); |
| + if (!focus_element) |
| + return true; |
| + |
| + const Node* start = ComputeVisibleSelectionInDOMTreeDeprecated() |
| + .Start() |
| + .ComputeContainerNode(); |
| + if (!start) |
| + return true; |
| + |
| + if (focus_element->IsTextControl()) |
| + return !focus_element->ContainsIncludingHostElements(*start); |
| + |
| + bool has_editable_style = HasEditableStyle(*start); |
| + const Node* current = start; |
| + do { |
| + if (current == focus_element) |
| + return false; |
| + if (has_editable_style && !HasEditableStyle(*current)) { |
| + // We exited an editable subtree without finding focus. |
| + TextControlElement* in_text_control = |
| + EnclosingTextControl(GetSelectionInDOMTree().Base()); |
| + if (in_text_control || !GetSelectionInDOMTree().IsRange()) { |
| + // Example to trigger this: |
| + // <div style="background: orange; padding: 20%; |
| + // user-select: none" tabindex="-1"> |
| + // <input value="click orange" autofocus></div> |
| + // When clicking (focusing) the orange <div>, <input>'s selection |
| + // looses focus (it should not receive input). |
| + return true; |
| + } |
| + } |
| + current = current->ParentOrShadowHostNode(); |
| + } while (current); |
| + |
| + return false; |
|
yosin_UTC9
2017/04/28 01:14:33
We also need to handle Range selection case.
We sh
hugoh_UTC2
2017/04/28 06:55:12
The test I made for that case, see TEST_F(FrameSel
yosin_UTC9
2017/04/28 07:57:09
Yes, it is what I expected.
|
| +} |
| + |
| void FrameSelection::DocumentAttached(Document* document) { |
| DCHECK(document); |
| use_secure_keyboard_entry_when_active_ = false; |
| @@ -792,15 +815,13 @@ void FrameSelection::CommitAppearanceIfNeeded() { |
| } |
| void FrameSelection::DidLayout() { |
| - // Upon relayout, a hidden selection must be kept hidden and a visible |
| - // selection must be kept visible. |
| - UpdateAppearance(LayoutSelection::PaintHint::kKeep); |
| + UpdateAppearance(); |
| } |
| -void FrameSelection::UpdateAppearance(LayoutSelection::PaintHint hint) { |
| +void FrameSelection::UpdateAppearance() { |
| DCHECK(!frame_->ContentLayoutItem().IsNull()); |
| frame_caret_->ScheduleVisualUpdateForPaintInvalidationIfNeeded(); |
| - layout_selection_->SetHasPendingSelection(hint); |
| + layout_selection_->SetHasPendingSelection(); |
| } |
| void FrameSelection::NotifyLayoutObjectOfSelectionChange( |
| @@ -989,7 +1010,7 @@ void FrameSelection::RevealSelection(const ScrollAlignment& alignment, |
| document_loader->GetInitialScrollState().was_scrolled_by_user = true; |
| if (start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( |
| rect, alignment, alignment)) |
| - UpdateAppearance(LayoutSelection::PaintHint::kPaint); |
| + UpdateAppearance(); |
| } |
| } |