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

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

Issue 2616623002: Do not send redundant selectionchange-events (decouple focus) (Closed)
Patch Set: Rebase 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 02bbb33ccdf67e5049609a9090e042a4e3c899f3..dd7d834fcf7426b5692f10380ed474cf5f33c836 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,26 @@ void FrameSelection::DidChangeFocus() {
// Hits in
// virtual/gpu/compositedscrolling/scrollbars/scrollbar-miss-mousemove-disabled.html
DisableCompositingQueryAsserts disabler;
- UpdateAppearance();
+
+ // 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();
}
static DispatchEventResult DispatchSelectStart(
@@ -773,13 +792,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(
@@ -968,7 +989,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);
}
}
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.h ('k') | third_party/WebKit/Source/core/editing/LayoutSelection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698