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

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

Issue 2201853002: Blink handle selection handle visibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing clear handles Created 4 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 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 7ad67e21b4bffa488464c508307e4cbcd7b57954..389c25019fea18a48b7cca0dc5471a83f455001f 100644
--- a/third_party/WebKit/Source/core/editing/FrameSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/FrameSelection.cpp
@@ -167,7 +167,8 @@ void FrameSelection::moveCaretSelection(const IntPoint& point) {
builder.setIsDirectional(selection().isDirectional());
if (position.isNotNull())
builder.collapse(position.toPositionWithAffinity());
- setSelection(builder.build(), CloseTyping | ClearTypingStyle | UserTriggered);
+ setSelection(builder.build(),
+ CloseTyping | ClearTypingStyle | UserTriggered | HandleVisible);
}
// TODO(xiaochengh): We should not use reference to return value.
@@ -228,7 +229,8 @@ static void adjustEndpointsAtBidiBoundary(
void SelectionController::setNonDirectionalSelectionIfNeeded(
const VisibleSelectionInFlatTree& passedNewSelection,
TextGranularity granularity,
- EndPointsAdjustmentMode endpointsAdjustmentMode) {
+ EndPointsAdjustmentMode endpointsAdjustmentMode,
+ HandleVisibility handleVisibility) {
VisibleSelectionInFlatTree newSelection = passedNewSelection;
bool isDirectional = shouldAlwaysUseDirectionalSelection(m_frame) ||
newSelection.isDirectional();
@@ -266,11 +268,16 @@ void SelectionController::setNonDirectionalSelectionIfNeeded(
// Adjusting base and extent will make newSelection always directional
newSelection.setIsDirectional(isDirectional);
- if (selection().visibleSelection<EditingInFlatTreeStrategy>() == newSelection)
+ const bool isHandleVisible = handleVisibility == HandleVisibility::Visible;
+ if (selection().visibleSelection<EditingInFlatTreeStrategy>() ==
+ newSelection &&
+ selection().isHandleVisible() == isHandleVisible)
return;
- const FrameSelection::SetSelectionOptions options =
+ FrameSelection::SetSelectionOptions options =
FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle;
+ if (isHandleVisible)
+ options |= FrameSelection::HandleVisible;
selection().setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded,
granularity);
}
@@ -289,6 +296,9 @@ void FrameSelection::setSelectionAlgorithm(
m_granularityStrategy->Clear();
bool closeTyping = options & CloseTyping;
bool shouldClearTypingStyle = options & ClearTypingStyle;
+ const HandleVisibility handleVisibility = options & HandleVisible
+ ? HandleVisibility::Visible
+ : HandleVisibility::NotVisible;
EUserTriggered userTriggered = selectionOptionsToUserTriggered(options);
// TODO(editing-dev): We should rename variable |s| to another name to avoid
@@ -307,7 +317,8 @@ void FrameSelection::setSelectionAlgorithm(
if (shouldClearTypingStyle)
clearTypingStyle();
- if (m_selectionEditor->visibleSelection<Strategy>() == s) {
+ if (m_selectionEditor->visibleSelection<Strategy>() == s &&
+ m_handleVisibility == handleVisibility) {
// Even if selection was not changed, selection offsets may have been
// changed.
m_frame->inputMethodController().cancelCompositionIfSelectionIsInvalid();
@@ -319,6 +330,7 @@ void FrameSelection::setSelectionAlgorithm(
visibleSelection<Strategy>();
const Position& oldSelectionStart = selection().start();
+ m_handleVisibility = handleVisibility;
m_selectionEditor->setVisibleSelection(s, options);
m_frameCaret->setCaretRectNeedsUpdate();
@@ -806,6 +818,11 @@ void FrameSelection::clear() {
setSelection(VisibleSelection());
}
+void FrameSelection::clearHandles() {
+ m_handleVisibility = HandleVisibility::NotVisible;
+ notifyCompositorForSelectionChange();
+}
+
void FrameSelection::documentAttached(Document* document) {
DCHECK(document);
DCHECK(!m_document) << "FrameSelection is already attached to " << m_document;
@@ -853,19 +870,13 @@ void FrameSelection::paintCaret(GraphicsContext& context,
m_frameCaret->paintCaret(context, paintOffset);
}
-bool FrameSelection::contains(const LayoutPoint& point) {
- if (document().layoutViewItem().isNull())
- return false;
-
+bool FrameSelection::contains(const HitTestResult& result) {
// Treat a collapsed selection like no selection.
const VisibleSelectionInFlatTree& visibleSelection =
this->visibleSelection<EditingInFlatTreeStrategy>();
if (!visibleSelection.isRange())
return false;
- HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
- HitTestResult result(request, point);
- document().layoutViewItem().hitTest(result);
Node* innerNode = result.innerNode();
if (!innerNode || !innerNode->layoutObject())
return false;
@@ -888,6 +899,17 @@ bool FrameSelection::contains(const LayoutPoint& point) {
return start.compareTo(pos) <= 0 && pos.compareTo(end) <= 0;
}
+bool FrameSelection::contains(const LayoutPoint& point) {
bokan 2016/10/26 16:17:23 Please rename point to pointInContent
amaralp 2017/01/13 23:52:51 Done.
+ if (document().layoutViewItem().isNull())
+ return false;
+
+ HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
+ HitTestResult result(request, point);
+ document().layoutViewItem().hitTest(result);
+
+ return contains(result);
+}
+
// Workaround for the fact that it's hard to delete a frame.
// Call this after doing user-triggered selections to make it easy to delete the
// frame you entirely selected. Can't do this implicitly as part of every
@@ -1436,7 +1458,8 @@ void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) {
granularityStrategy()->updateExtent(contentsPoint, m_frame);
setSelection(newSelection,
FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle |
- FrameSelection::DoNotClearStrategy | UserTriggered,
+ FrameSelection::DoNotClearStrategy | UserTriggered |
+ FrameSelection::HandleVisible,
CursorAlignOnScroll::IfNeeded, CharacterGranularity);
}
@@ -1457,8 +1480,11 @@ void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition,
if (newSelection.isNone())
return;
- setSelection(newSelection, CloseTyping | ClearTypingStyle,
- CursorAlignOnScroll::IfNeeded, granularity);
+ SetSelectionOptions options = CloseTyping | ClearTypingStyle;
+ if (isHandleVisible())
+ options |= HandleVisible;
+ setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded,
+ granularity);
}
void FrameSelection::updateIfNeeded() {
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.h ('k') | third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698