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

/*
 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

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

#include <stdio.h>

#include <optional>

#include "base/auto_reset.h"
#include "third_party/blink/public/mojom/scroll/scroll_into_view_params.mojom-blink.h"
#include "third_party/blink/renderer/core/accessibility/ax_object_cache.h"
#include "third_party/blink/renderer/core/accessibility/blink_ax_event_intent.h"
#include "third_party/blink/renderer/core/accessibility/scoped_blink_ax_event_intent.h"
#include "third_party/blink/renderer/core/css/css_property_value_set.h"
#include "third_party/blink/renderer/core/display_lock/display_lock_utilities.h"
#include "third_party/blink/renderer/core/dom/character_data.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/dom/node_traversal.h"
#include "third_party/blink/renderer/core/dom/node_with_index.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/editing/caret_display_item_client.h"
#include "third_party/blink/renderer/core/editing/commands/typing_command.h"
#include "third_party/blink/renderer/core/editing/editing_behavior.h"
#include "third_party/blink/renderer/core/editing/editing_utilities.h"
#include "third_party/blink/renderer/core/editing/editor.h"
#include "third_party/blink/renderer/core/editing/ephemeral_range.h"
#include "third_party/blink/renderer/core/editing/frame_caret.h"
#include "third_party/blink/renderer/core/editing/granularity_strategy.h"
#include "third_party/blink/renderer/core/editing/ime/input_method_controller.h"
#include "third_party/blink/renderer/core/editing/iterators/text_iterator.h"
#include "third_party/blink/renderer/core/editing/layout_selection.h"
#include "third_party/blink/renderer/core/editing/local_caret_rect.h"
#include "third_party/blink/renderer/core/editing/position.h"
#include "third_party/blink/renderer/core/editing/selection_controller.h"
#include "third_party/blink/renderer/core/editing/selection_editor.h"
#include "third_party/blink/renderer/core/editing/selection_modifier.h"
#include "third_party/blink/renderer/core/editing/selection_template.h"
#include "third_party/blink/renderer/core/editing/serializers/serialization.h"
#include "third_party/blink/renderer/core/editing/text_affinity.h"
#include "third_party/blink/renderer/core/editing/visible_position.h"
#include "third_party/blink/renderer/core/editing/visible_selection.h"
#include "third_party/blink/renderer/core/editing/visible_units.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/forms/html_select_element.h"
#include "third_party/blink/renderer/core/html/html_body_element.h"
#include "third_party/blink/renderer/core/html/html_frame_element_base.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/input/context_menu_allowed_scope.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/layout/geometry/box_strut.h"
#include "third_party/blink/renderer/core/layout/hit_test_request.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_embedded_content.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/page/focus_controller.h"
#include "third_party/blink/renderer/core/page/frame_tree.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/page/page_animator.h"
#include "third_party/blink/renderer/core/page/spatial_navigation.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/scroll/scroll_into_view_util.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/graphics/graphics_context.h"
#include "third_party/blink/renderer/platform/text/text_direction.h"
#include "third_party/blink/renderer/platform/text/unicode_utilities.h"
#include "ui/gfx/geometry/quad_f.h"

#define EDIT_DEBUG

namespace blink {

static inline bool ShouldAlwaysUseDirectionalSelection(LocalFrame* frame) {}

FrameSelection::FrameSelection(LocalFrame& frame)
    :{}

FrameSelection::~FrameSelection() = default;

const EffectPaintPropertyNode& FrameSelection::CaretEffectNode() const {}

bool FrameSelection::IsAvailable() const {}

Document& FrameSelection::GetDocument() const {}

VisibleSelection FrameSelection::ComputeVisibleSelectionInDOMTree() const {}

VisibleSelectionInFlatTree FrameSelection::ComputeVisibleSelectionInFlatTree()
    const {}

const SelectionInDOMTree& FrameSelection::GetSelectionInDOMTree() const {}

Element* FrameSelection::RootEditableElementOrDocumentElement() const {}

wtf_size_t FrameSelection::CharacterIndexForPoint(
    const gfx::Point& point) const {}

VisibleSelection FrameSelection::ComputeVisibleSelectionInDOMTreeDeprecated()
    const {}

void FrameSelection::MoveCaretSelection(const gfx::Point& point) {}

void FrameSelection::SetSelection(const SelectionInDOMTree& selection,
                                  const SetSelectionOptions& data) {}

void FrameSelection::SetSelectionAndEndTyping(
    const SelectionInDOMTree& selection) {}

static void AssertUserSelection(const SelectionInDOMTree& selection,
                                const SetSelectionOptions& options) {}

bool FrameSelection::SetSelectionDeprecated(
    const SelectionInDOMTree& new_selection,
    const SetSelectionOptions& passed_options) {}

void FrameSelection::DidSetSelectionDeprecated(
    const SelectionInDOMTree& new_selection,
    const SetSelectionOptions& options) {}

void FrameSelection::SetSelectionForAccessibility(
    const SelectionInDOMTree& selection,
    const SetSelectionOptions& options) {}

void FrameSelection::NodeChildrenWillBeRemoved(ContainerNode& container) {}

void FrameSelection::NodeWillBeRemoved(Node& node) {}

void FrameSelection::DidChangeFocus() {}

static DispatchEventResult DispatchSelectStart(
    const VisibleSelection& selection) {}

// The return value of |FrameSelection::modify()| is different based on
// value of |userTriggered| parameter.
// When |userTriggered| is |userTriggered|, |modify()| returns false if
// "selectstart" event is dispatched and canceled, otherwise returns true.
// When |userTriggered| is |NotUserTrigged|, return value specifies whether
// selection is modified or not.
bool FrameSelection::Modify(SelectionModifyAlteration alter,
                            SelectionModifyDirection direction,
                            TextGranularity granularity,
                            SetSelectionBy set_selection_by) {}

void FrameSelection::Clear() {}

bool FrameSelection::SelectionHasFocus() const {}

bool FrameSelection::IsHidden() const {}

void FrameSelection::DidAttachDocument(Document* document) {}

void FrameSelection::ContextDestroyed() {}

void FrameSelection::LayoutBlockWillBeDestroyed(const LayoutBlock& block) {}

void FrameSelection::UpdateStyleAndLayoutIfNeeded() {}

void FrameSelection::InvalidatePaint(const LayoutBlock& block,
                                     const PaintInvalidatorContext& context) {}

void FrameSelection::EnsureInvalidationOfPreviousLayoutBlock() {}

bool FrameSelection::ShouldPaintCaret(const LayoutBlock& block) const {}

bool FrameSelection::ShouldPaintCaret(
    const PhysicalBoxFragment& box_fragment) const {}

gfx::Rect FrameSelection::AbsoluteCaretBounds() const {}

bool FrameSelection::ComputeAbsoluteBounds(gfx::Rect& anchor,
                                           gfx::Rect& focus) const {}

void FrameSelection::PaintCaret(GraphicsContext& context,
                                const PhysicalOffset& paint_offset) {}

bool FrameSelection::Contains(const PhysicalOffset& point) {}

// 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
// setSelection call because in some contexts it might not be good for the focus
// to move to another frame. So instead we call it from places where we are
// selecting with the mouse or the keyboard after setting the selection.
void FrameSelection::SelectFrameElementInParentIfFullySelected() {}

// Returns a shadow tree node for legacy shadow trees, a child of the
// ShadowRoot node for new shadow trees, or 0 for non-shadow trees.
static Node* NonBoundaryShadowTreeRootNode(const Position& position) {}

void FrameSelection::SelectAll(SetSelectionBy set_selection_by,
                               bool canonicalize_selection) {}

void FrameSelection::SelectAll() {}

// Implementation of |SVGTextControlElement::selectSubString()|
void FrameSelection::SelectSubString(const Element& element,
                                     int offset,
                                     int length) {}

void FrameSelection::NotifyAccessibilityForSelectionChange() {}

void FrameSelection::NotifyCompositorForSelectionChange() {}

void FrameSelection::NotifyEventHandlerForSelectionChange() {}

void FrameSelection::NotifyDisplayLockForSelectionChange(
    Document& document,
    const SelectionInDOMTree& old_selection,
    const SelectionInDOMTree& new_selection) {}

void FrameSelection::FocusedOrActiveStateChanged() {}

void FrameSelection::PageActivationChanged() {}

void FrameSelection::SetFrameIsFocused(bool flag) {}

bool FrameSelection::FrameIsFocusedAndActive() const {}

void FrameSelection::CommitAppearanceIfNeeded() {}

void FrameSelection::DidLayout() {}

void FrameSelection::UpdateAppearance() {}

void FrameSelection::NotifyTextControlOfSelectionChange(
    SetSelectionBy set_selection_by) {}

// Helper function that tells whether a particular node is an element that has
// an entire LocalFrame and LocalFrameView, a <frame>, <iframe>, or <object>.
static bool IsFrameElement(const Node* n) {}

void FrameSelection::SetFocusedNodeIfNeeded() {}

static EphemeralRangeInFlatTree ComputeRangeForSerialization(
    const SelectionInDOMTree& selection_in_dom_tree) {}

static String ExtractSelectedText(const FrameSelection& selection,
                                  TextIteratorBehavior behavior) {}

String FrameSelection::SelectedHTMLForClipboard() const {}

String FrameSelection::SelectedText(
    const TextIteratorBehavior& behavior) const {}

String FrameSelection::SelectedText() const {}

String FrameSelection::SelectedTextForClipboard() const {}

PhysicalRect FrameSelection::AbsoluteUnclippedBounds() const {}

gfx::Rect FrameSelection::ComputeRectToScroll(
    RevealExtentOption reveal_extent_option) {}

// TODO(editing-dev): This should be done in FlatTree world.
void FrameSelection::RevealSelection(
    const mojom::blink::ScrollAlignment& alignment,
    RevealExtentOption reveal_extent_option) {}

void FrameSelection::SetSelectionFromNone() {}

#if DCHECK_IS_ON()

void FrameSelection::ShowTreeForThis() const {}

#endif

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

void FrameSelection::ScheduleVisualUpdate() const {}

void FrameSelection::ScheduleVisualUpdateForVisualOverflowIfNeeded() const {}

bool FrameSelection::SelectWordAroundCaret() {}

bool FrameSelection::SelectAroundCaret(
    TextGranularity text_granularity,
    HandleVisibility handle_visibility,
    ContextMenuVisibility context_menu_visibility) {}

EphemeralRange FrameSelection::GetWordSelectionRangeAroundCaret() const {}

EphemeralRange FrameSelection::GetSelectionRangeAroundCaretForTesting(
    TextGranularity text_granularity) const {}

GranularityStrategy* FrameSelection::GetGranularityStrategy() {}

void FrameSelection::MoveRangeSelectionExtent(
    const gfx::Point& contents_point) {}

void FrameSelection::MoveRangeSelection(const gfx::Point& base_point,
                                        const gfx::Point& extent_point,
                                        TextGranularity granularity) {}

void FrameSelection::MoveRangeSelectionInternal(
    const SelectionInDOMTree& new_selection,
    TextGranularity granularity) {}

void FrameSelection::SetCaretEnabled(bool enabled) {}

void FrameSelection::SetCaretBlinkingSuspended(bool suspended) {}

bool FrameSelection::IsCaretBlinkingSuspended() const {}

void FrameSelection::CacheRangeOfDocument(Range* range) {}

Range* FrameSelection::DocumentCachedRange() const {}

void FrameSelection::ClearDocumentCachedRange() {}

LayoutSelectionStatus FrameSelection::ComputeLayoutSelectionStatus(
    const InlineCursor& cursor) const {}

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

bool FrameSelection::IsDirectional() const {}

void FrameSelection::MarkCacheDirty() {}

EphemeralRange FrameSelection::GetSelectionRangeAroundCaret(
    TextGranularity text_granularity) const {}

EphemeralRange FrameSelection::GetSelectionRangeAroundPosition(
    TextGranularity text_granularity,
    Position position,
    WordSide word_side) const {}

}  // namespace blink

#if DCHECK_IS_ON()

void ShowTree(const blink::FrameSelection& sel) {}

void ShowTree(const blink::FrameSelection* sel) {}

#endif