chromium/third_party/blink/renderer/core/editing/layout_selection.cc

/*
 * Copyright (C) 1999 Lars Knoll ([email protected])
 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
 * reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "third_party/blink/renderer/core/editing/layout_selection.h"

#include "third_party/blink/renderer/core/css/style_change_reason.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/editing/editing_utilities.h"
#include "third_party/blink/renderer/core/editing/ephemeral_range.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/selection_template.h"
#include "third_party/blink/renderer/core/editing/visible_position.h"
#include "third_party/blink/renderer/core/editing/visible_units.h"
#include "third_party/blink/renderer/core/html/forms/text_control_element.h"
#include "third_party/blink/renderer/core/html/html_wbr_element.h"
#include "third_party/blink/renderer/core/layout/block_node.h"
#include "third_party/blink/renderer/core/layout/inline/fragment_item.h"
#include "third_party/blink/renderer/core/layout/inline/inline_cursor.h"
#include "third_party/blink/renderer/core/layout/inline/offset_mapping.h"
#include "third_party/blink/renderer/core/layout/inline/physical_line_box_fragment.h"
#include "third_party/blink/renderer/core/layout/layout_text.h"
#include "third_party/blink/renderer/core/layout/layout_text_fragment.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/platform/fonts/shaping/shape_result_view.h"

namespace blink {

namespace {

// TODO(yoichio): Share condition between OffsetMapping::AcceptsPosition.
// TODO(1229581): Do we need this function anymore?
bool ShouldUseLayoutNGTextContent(const Node& node) {}

}  // namespace

// The current selection to be painted is represented as 2 pairs of
// (Node, offset).
// Each offset represents text offsets on selection edge if it is text.
// For example, suppose we select "f^oo<br><img>|",
// |start_offset_| is 1 and |end_offset_| is nullopt.
// If on NG, offset is on text content offset rather than each text node.
class SelectionPaintRange : public GarbageCollected<SelectionPaintRange> {};

LayoutSelection::LayoutSelection(FrameSelection& frame_selection)
    :{}

enum class SelectionMode {};

void LayoutSelection::AssertIsValid() const {}

static SelectionMode ComputeSelectionMode(
    const FrameSelection& frame_selection) {}

static EphemeralRangeInFlatTree CalcSelectionInFlatTree(
    const FrameSelection& frame_selection) {}

// OldSelectedNodes is current selected Nodes with
// current SelectionState which is kStart, kEnd, kStartAndEnd or kInside.
struct OldSelectedNodes {};

std::ostream& operator<<(std::ostream&, const OldSelectedNodes&);

// This struct represents a selection range in layout tree and each
// Node is SelectionState-marked.
struct NewPaintRangeAndSelectedNodes {};

std::ostream& operator<<(std::ostream&, const NewPaintRangeAndSelectedNodes&);

static void SetShouldInvalidateIfNeeded(LayoutObject* layout_object) {}

static LayoutTextFragment* FirstLetterPartFor(
    const LayoutObject* layout_object) {}

static void SetShouldInvalidateIfNeeded(const Node& node) {}

static void SetSelectionStateIfNeeded(const Node& node, SelectionState state) {}

// Set ShouldInvalidateSelection flag of LayoutObjects
// comparing them in |new_range| and |old_range|.
static void SetShouldInvalidateSelection(
    const NewPaintRangeAndSelectedNodes& new_range,
    const OldSelectedNodes& old_selected_objects) {}

static bool IsDisplayContentElement(const Node& node) {}

template <typename Visitor>
static void VisitSelectedInclusiveDescendantsOfInternal(Node& node,
                                                        Visitor* visitor) {}

static inline bool IsFlatTreeClean(const Node& node) {}

template <typename Visitor>
static void VisitSelectedInclusiveDescendantsOf(Node& node, Visitor* visitor) {}

static OldSelectedNodes ResetOldSelectedNodes(
    Node& root,
    std::optional<unsigned> old_start_offset,
    std::optional<unsigned> old_end_offset) {}

static std::optional<unsigned> ComputeStartOffset(
    const Node& node,
    const PositionInFlatTree& selection_start) {}

static std::optional<unsigned> ComputeEndOffset(
    const Node& node,
    const PositionInFlatTree& selection_end) {}

#if DCHECK_IS_ON()
// Position should be offset on text or before/after a break element.
static bool IsPositionValidText(const Position& position) {}
#endif

static std::optional<unsigned> GetTextContentOffset(const Position& position) {}

// Computes text content offset of selection start if |layout_object| is
// LayoutText.
static std::optional<unsigned> GetTextContentOffsetStart(
    const Node& node,
    std::optional<unsigned> node_offset) {}

// Computes text content offset of selection end if |layout_object| is
// LayoutText.
static std::optional<unsigned> GetTextContentOffsetEnd(
    const Node& node,
    std::optional<unsigned> node_offset) {}

static SelectionPaintRange* ComputeNewPaintRange(
    const SelectionPaintRange& paint_range) {}

static unsigned ClampOffset(unsigned offset,
                            unsigned start_offset,
                            unsigned end_offset) {}

static Text* AssociatedTextNode(const LayoutText& text) {}

static SelectionState GetSelectionStateFor(const LayoutText& layout_text) {}

static SelectionState GetSelectionStateFor(
    const InlineCursorPosition& position) {}

static SelectionState GetPaintingSelectionStateFor(
    const LayoutText& layout_text) {}

bool LayoutSelection::IsSelected(const LayoutObject& layout_object) {}

static inline unsigned ClampOffset(unsigned node_offset,
                                   const LayoutTextFragment& fragment) {}

static LayoutTextSelectionStatus ComputeSelectionStatusForNode(
    const Text& text,
    SelectionState selection_state,
    std::optional<unsigned> start_offset,
    std::optional<unsigned> end_offset) {}

LayoutTextSelectionStatus LayoutSelection::ComputeSelectionStatus(
    const LayoutText& layout_text) const {}

LayoutTextSelectionStatus FrameSelection::ComputeLayoutSelectionStatus(
    const LayoutText& text) const {}

// FrameSelection holds selection offsets in layout block flow at
// LayoutSelection::Commit() if selection starts/ends within Text that
// each LayoutObject::SelectionState indicates.
// These offset can be out of fragment because SelectionState is of each
// LayoutText and not of each fragment for it.
LayoutSelectionStatus LayoutSelection::ComputeSelectionStatus(
    const InlineCursor& cursor) const {}

LayoutSelectionStatus LayoutSelection::ComputeSelectionStatus(
    const InlineCursor& cursor,
    const TextOffsetRange& offset) const {}

// Given |state| that describes the provided offsets relationship to the
// |paint_range_| (and thus which comparisons are valid), returns a
// SelectionState that reflects where the endpoints of the selection fall,
// relative to the range expressed by the offsets.
SelectionState LayoutSelection::ComputeSelectionStateFromOffsets(
    SelectionState state,
    unsigned start_offset,
    unsigned end_offset) const {}

SelectionState LayoutSelection::ComputePaintingSelectionStateForCursor(
    const InlineCursorPosition& position) const {}

static void SetSelectionStateForPaint(
    const EphemeralRangeInFlatTree& selection) {}

static NewPaintRangeAndSelectedNodes CalcSelectionRangeAndSetSelectionState(
    const FrameSelection& frame_selection) {}

void LayoutSelection::SetHasPendingSelection() {}

void LayoutSelection::Commit() {}

void LayoutSelection::ContextDestroyed() {}

static PhysicalRect SelectionRectForLayoutObject(const LayoutObject* object) {}

template <typename Visitor>
static void VisitLayoutObjectsOf(const Node& node, Visitor* visitor) {}

gfx::Rect LayoutSelection::AbsoluteSelectionBounds() {}

void LayoutSelection::InvalidateStyleAndPaintForSelection() {}

void LayoutSelection::Trace(Visitor* visitor) const {}

void PrintSelectionStatus(std::ostream& ostream, const Node& node) {}

#if DCHECK_IS_ON()
std::ostream& operator<<(std::ostream& ostream,
                         const std::optional<unsigned>& offset) {}

std::ostream& operator<<(std::ostream& ostream,
                         const SelectionPaintRange& range) {}

std::ostream& operator<<(
    std::ostream& ostream,
    const HeapHashMap<Member<const Node>, SelectionState>& map) {}

std::ostream& operator<<(std::ostream& ostream,
                         const OldSelectedNodes& old_node) {}

void PrintOldSelectedNodes(const OldSelectedNodes& old_node) {}

std::ostream& operator<<(
    std::ostream& ostream,
    const HeapHashSet<Member<const Node>>& selected_objects) {}

std::ostream& operator<<(std::ostream& ostream,
                         const NewPaintRangeAndSelectedNodes& new_range) {}

void PrintSelectedNodes(const NewPaintRangeAndSelectedNodes& new_range) {}

void PrintSelectionStateInDocument(const FrameSelection& selection) {}
#endif

}  // namespace blink