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

Unified Diff: third_party/WebKit/Source/core/editing/FrameSelection.cpp

Issue 2616623002: Do not send redundant selectionchange-events (decouple focus) (Closed)
Patch Set: Add comment Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
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 6467d40158b462f9ef3272f1b678b2bd85edc4b7..d85af769ad84b284ac3e0f051cb583d43a133543 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();
+ UpdateAppearance(LayoutSelection::PaintHint::kPaint);
// Always clear the x position used for vertical arrow navigation.
// It will be restored by the vertical arrow navigation code if necessary.
@@ -335,7 +335,21 @@ void FrameSelection::DidChangeFocus() {
// Hits in
// virtual/gpu/compositedscrolling/scrollbars/scrollbar-miss-mousemove-disabled.html
DisableCompositingQueryAsserts disabler;
- UpdateAppearance();
+
+ const Element* focus = GetDocument().FocusedElement();
yosin_UTC9 2017/04/13 09:31:50 Since Document::FocusedElement() is simple getter.
hugoh_UTC2 2017/04/14 01:34:47 Done. (But the comment must go above the ternary o
+ if (!focus) {
+ // No focused element means document root has focus.
+ focus = GetDocument().documentElement();
+ if (!focus)
+ return;
yosin_UTC9 2017/04/13 09:31:50 We still need to call frame_caret_->ScheduleVisual
hugoh_UTC2 2017/04/14 01:34:47 Done.
+ }
+ // 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_focus_ && !focus->IsTextControl())
+ UpdateAppearance(LayoutSelection::PaintHint::kHide);
+ text_control_focus_ = focus->IsTextControl();
}
static DispatchEventResult DispatchSelectStart(
@@ -773,13 +787,15 @@ void FrameSelection::CommitAppearanceIfNeeded(LayoutView& layout_view) {
}
void FrameSelection::DidLayout() {
- UpdateAppearance();
+ // Upon relayout, a hidden selection must be kept hidden and a visible
+ // selection must be kept visible.
+ UpdateAppearance(LayoutSelection::PaintHint::kKeep);
}
-void FrameSelection::UpdateAppearance() {
+void FrameSelection::UpdateAppearance(LayoutSelection::PaintHint hint) {
DCHECK(!frame_->ContentLayoutItem().IsNull());
frame_caret_->ScheduleVisualUpdateForPaintInvalidationIfNeeded();
- layout_selection_->SetHasPendingSelection();
+ layout_selection_->SetHasPendingSelection(hint);
}
void FrameSelection::NotifyLayoutObjectOfSelectionChange(
@@ -970,7 +986,7 @@ void FrameSelection::RevealSelection(const ScrollAlignment& alignment,
document_loader->GetInitialScrollState().was_scrolled_by_user = true;
if (start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible(
rect, alignment, alignment))
- UpdateAppearance();
+ UpdateAppearance(LayoutSelection::PaintHint::kPaint);
}
}

Powered by Google App Engine
This is Rietveld 408576698