#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) { … }
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) { … }
void FrameSelection::SelectFrameElementInParentIfFullySelected() { … }
static Node* NonBoundaryShadowTreeRootNode(const Position& position) { … }
void FrameSelection::SelectAll(SetSelectionBy set_selection_by,
bool canonicalize_selection) { … }
void FrameSelection::SelectAll() { … }
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) { … }
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) { … }
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 { … }
}
#if DCHECK_IS_ON()
void ShowTree(const blink::FrameSelection& sel) { … }
void ShowTree(const blink::FrameSelection* sel) { … }
#endif