Commit f746c767 authored by yosin@chromium.org's avatar yosin@chromium.org

Moves an implementation of LayoutView::commitPendingSelection() to PendingSelection::commit()

This patch moves an implementation of |LayoutView::commitPendingSelection()| to
|PendingSelection::commit()| as a preparation of moving it to "editing/",
for reducing exposing editing functions to layout layer.

Following patch will move |PendingSelection| to "editing/".

This patch is a preparation of making selection to handle granularity for web
component, http://crrev.com/1277863002

BUG=513568
TEST=n/a; no behavior changes

Review URL: https://codereview.chromium.org/1315423006

git-svn-id: svn://svn.chromium.org/blink/trunk@201854 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent acdaaaf1
......@@ -773,61 +773,9 @@ void LayoutView::setSelection(const FrameSelection& selection)
m_pendingSelection->setSelection(selection);
}
template <typename Strategy>
void LayoutView::commitPendingSelectionAlgorithm()
{
using PositionType = typename Strategy::PositionType;
if (!hasPendingSelection())
return;
ASSERT(!needsLayout());
// Skip if pending VisibilePositions became invalid before we reach here.
if (!m_pendingSelection->isInDocument(document())) {
m_pendingSelection->clear();
return;
}
// Construct a new VisibleSolution, since m_selection is not necessarily valid, and the following steps
// assume a valid selection. See <https://bugs.webkit.org/show_bug.cgi?id=69563> and <rdar://problem/10232866>.
VisibleSelection selection = m_pendingSelection->calcVisibleSelection();
m_pendingSelection->clear();
if (!selection.isRange()) {
clearSelection();
return;
}
// Use the rightmost candidate for the start of the selection, and the leftmost candidate for the end of the selection.
// Example: foo <a>bar</a>. Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. If we pass [foo, 3]
// as the start of the selection, the selection painting code will think that content on the line containing 'foo' is selected
// and will fill the gap before 'bar'.
PositionType startPos = Strategy::selectionStart(selection);
PositionType candidate = mostForwardCaretPosition(startPos);
if (isVisuallyEquivalentCandidate(candidate))
startPos = candidate;
PositionType endPos = Strategy::selectionEnd(selection);
candidate = mostBackwardCaretPosition(endPos);
if (isVisuallyEquivalentCandidate(candidate))
endPos = candidate;
// We can get into a state where the selection endpoints map to the same VisiblePosition when a selection is deleted
// because we don't yet notify the FrameSelection of text removal.
if (startPos.isNull() || endPos.isNull() || Strategy::selectionVisibleStart(selection).deepEquivalent() == Strategy::selectionVisibleEnd(selection).deepEquivalent())
return;
LayoutObject* startLayoutObject = startPos.anchorNode()->layoutObject();
LayoutObject* endLayoutObject = endPos.anchorNode()->layoutObject();
if (!startLayoutObject || !endLayoutObject)
return;
ASSERT(startLayoutObject->view() == this && endLayoutObject->view() == this);
setSelection(startLayoutObject, startPos.computeEditingOffset(), endLayoutObject, endPos.computeEditingOffset());
}
void LayoutView::commitPendingSelection()
{
if (RuntimeEnabledFeatures::selectionForComposedTreeEnabled())
return commitPendingSelectionAlgorithm<VisibleSelection::InComposedTree>();
commitPendingSelectionAlgorithm<VisibleSelection::InDOMTree>();
m_pendingSelection->commit(*this);
}
LayoutObject* LayoutView::selectionStart()
......
......@@ -24,7 +24,6 @@
#include "core/CoreExport.h"
#include "core/compositing/DisplayListCompositingBuilder.h"
#include "core/editing/Position.h"
#include "core/frame/FrameView.h"
#include "core/layout/HitTestCache.h"
#include "core/layout/HitTestResult.h"
......@@ -192,9 +191,6 @@ public:
private:
void mapLocalToContainer(const LayoutBoxModelObject* paintInvalidationContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = nullptr, const PaintInvalidationState* = nullptr) const override;
template <typename Strategy>
void commitPendingSelectionAlgorithm();
const LayoutObject* pushMappingToContainer(const LayoutBoxModelObject* ancestorToStopAt, LayoutGeometryMap&) const override;
void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const override;
void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const override;
......
......@@ -27,6 +27,7 @@
#include "core/editing/VisiblePosition.h"
#include "core/editing/VisibleUnits.h"
#include "core/html/HTMLTextFormControlElement.h"
#include "core/layout/LayoutView.h"
namespace blink {
......@@ -105,11 +106,66 @@ VisibleSelection PendingSelection::calcVisibleSelectionAlgorithm() const
return VisibleSelection(visibleStart, visibleEnd);
}
VisibleSelection PendingSelection::calcVisibleSelection() const
template <typename Strategy>
void PendingSelection::commitAlgorithm(LayoutView& layoutView)
{
using PositionType = typename Strategy::PositionType;
if (!hasPendingSelection())
return;
ASSERT(!layoutView.needsLayout());
// Skip if pending VisibilePositions became invalid before we reach here.
if (!isInDocument(layoutView.document())) {
clear();
return;
}
// Construct a new VisibleSolution, since m_selection is not necessarily
// valid, and the following steps assume a valid selection.
// See <https://bugs.webkit.org/show_bug.cgi?id=69563> and
// <rdar://problem/10232866>.
VisibleSelection selection = calcVisibleSelectionAlgorithm<Strategy>();
clear();
if (!selection.isRange()) {
layoutView.clearSelection();
return;
}
// Use the rightmost candidate for the start of the selection, and the
// leftmost candidate for the end of the selection. Example: foo <a>bar</a>.
// Imagine that a line wrap occurs after 'foo', and that 'bar' is selected.
// If we pass [foo, 3] as the start of the selection, the selection painting
// code will think that content on the line containing 'foo' is selected
// and will fill the gap before 'bar'.
PositionType startPos = Strategy::selectionStart(selection);
PositionType candidate = mostForwardCaretPosition(startPos);
if (isVisuallyEquivalentCandidate(candidate))
startPos = candidate;
PositionType endPos = Strategy::selectionEnd(selection);
candidate = mostBackwardCaretPosition(endPos);
if (isVisuallyEquivalentCandidate(candidate))
endPos = candidate;
// We can get into a state where the selection endpoints map to the same
// |VisiblePosition| when a selection is deleted because we don't yet notify
// the |FrameSelection| of text removal.
if (startPos.isNull() || endPos.isNull() || Strategy::selectionVisibleStart(selection).deepEquivalent() == Strategy::selectionVisibleEnd(selection).deepEquivalent())
return;
LayoutObject* startLayoutObject = startPos.anchorNode()->layoutObject();
LayoutObject* endLayoutObject = endPos.anchorNode()->layoutObject();
if (!startLayoutObject || !endLayoutObject)
return;
ASSERT(layoutView == startLayoutObject->view() && layoutView == endLayoutObject->view());
layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(), endLayoutObject, endPos.computeEditingOffset());
}
void PendingSelection::commit(LayoutView& layoutView)
{
if (RuntimeEnabledFeatures::selectionForComposedTreeEnabled())
return calcVisibleSelectionAlgorithm<VisibleSelection::InComposedTree>();
return calcVisibleSelectionAlgorithm<VisibleSelection::InDOMTree>();
return commitAlgorithm<VisibleSelection::InComposedTree>(layoutView);
commitAlgorithm<VisibleSelection::InDOMTree>(layoutView);
}
DEFINE_TRACE(PendingSelection)
......
......@@ -30,6 +30,7 @@ namespace blink {
class Document;
class FrameSelection;
class LayoutView;
class PendingSelection final : public NoBaseWillBeGarbageCollected<PendingSelection> {
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(PendingSelection);
......@@ -41,10 +42,7 @@ public:
bool hasPendingSelection() const { return m_hasPendingSelection; }
void setSelection(const FrameSelection&);
void clear();
bool isInDocument(const Document&) const;
VisibleSelection calcVisibleSelection() const;
void commit(LayoutView&);
DECLARE_TRACE();
......@@ -56,6 +54,10 @@ private:
template <typename Strategy>
VisibleSelection calcVisibleSelectionAlgorithm() const;
void clear();
template <typename Strategy>
void commitAlgorithm(LayoutView&);
bool isInDocument(const Document&) const;
VisibleSelection m_selection;
bool m_hasPendingSelection : 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment