#include "third_party/blink/renderer/core/page/focus_controller.h"
#include <limits>
#include "third_party/blink/public/mojom/input/focus_type.mojom-blink.h"
#include "third_party/blink/renderer/core/accessibility/ax_object_cache.h"
#include "third_party/blink/renderer/core/dom/container_node.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/flat_tree_traversal.h"
#include "third_party/blink/renderer/core/dom/focus_params.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/popover_data.h"
#include "third_party/blink/renderer/core/dom/range.h"
#include "third_party/blink/renderer/core/dom/scroll_marker_group_pseudo_element.h"
#include "third_party/blink/renderer/core/dom/scroll_marker_pseudo_element.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/editing/editing_utilities.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/ime/input_method_controller.h"
#include "third_party/blink/renderer/core/frame/frame_client.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/remote_frame.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/fenced_frame/html_fenced_frame_element.h"
#include "third_party/blink/renderer/core/html/forms/html_form_control_element.h"
#include "third_party/blink/renderer/core/html/forms/html_form_element.h"
#include "third_party/blink/renderer/core/html/forms/html_select_element.h"
#include "third_party/blink/renderer/core/html/forms/listed_element.h"
#include "third_party/blink/renderer/core/html/forms/text_control_element.h"
#include "third_party/blink/renderer/core/html/html_iframe_element.h"
#include "third_party/blink/renderer/core/html/html_plugin_element.h"
#include "third_party/blink/renderer/core/html/html_slot_element.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/physical_box_fragment.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/focus_changed_observer.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/spatial_navigation.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink {
namespace {
const Element* MaybeAdjustSearchElementForFocusGroup(const Element& element,
bool get_last) { … }
Element* MaybeRestoreFocusedElementForFocusGroup(Element* element) { … }
bool IsOpenPopoverWithInvoker(const Node* node) { … }
const Element* InclusiveAncestorOpenPopoverWithInvoker(const Element* element) { … }
bool IsOpenPopoverInvoker(const Node* node) { … }
const ContainerNode* ReadingFlowContainerOrDisplayContents(
const ContainerNode* node) { … }
bool IsReadingFlowScopeOwner(const ContainerNode* node) { … }
class FocusNavigation : public GarbageCollected<FocusNavigation> { … };
class ScopedFocusNavigation { … };
ScopedFocusNavigation::ScopedFocusNavigation(
ContainerNode& scoping_root_node,
const Element* current,
FocusController::OwnerMap& owner_map)
: … { … }
void ScopedFocusNavigation::MoveToNext() { … }
void ScopedFocusNavigation::MoveToPrevious() { … }
void ScopedFocusNavigation::MoveToFirst() { … }
void ScopedFocusNavigation::MoveToLast() { … }
Element* ScopedFocusNavigation::Owner() const { … }
ScopedFocusNavigation ScopedFocusNavigation::CreateFor(
const Element& current,
FocusController::OwnerMap& owner_map) { … }
ScopedFocusNavigation ScopedFocusNavigation::CreateForDocument(
Document& document,
FocusController::OwnerMap& owner_map) { … }
ScopedFocusNavigation ScopedFocusNavigation::OwnedByNonFocusableFocusScopeOwner(
Element& element,
FocusController::OwnerMap& owner_map) { … }
ScopedFocusNavigation ScopedFocusNavigation::OwnedByShadowHost(
const Element& element,
FocusController::OwnerMap& owner_map) { … }
ScopedFocusNavigation ScopedFocusNavigation::OwnedByIFrame(
const HTMLFrameOwnerElement& frame,
FocusController::OwnerMap& owner_map) { … }
ScopedFocusNavigation ScopedFocusNavigation::OwnedByPopoverInvoker(
const Element& invoker,
FocusController::OwnerMap& owner_map) { … }
ScopedFocusNavigation ScopedFocusNavigation::OwnedByReadingFlow(
const Element& owner,
FocusController::OwnerMap& owner_map) { … }
ScopedFocusNavigation ScopedFocusNavigation::OwnedByHTMLSlotElement(
const HTMLSlotElement& element,
FocusController::OwnerMap& owner_map) { … }
HTMLSlotElement* ScopedFocusNavigation::FindFallbackScopeOwnerSlot(
const Element& element) { … }
bool IsLikelyCaptchaIframe(const Element& element) { … }
bool IsLikelyWithinCaptchaIframe(const Element& element,
FocusController::OwnerMap& owner_map) { … }
inline void DispatchBlurEvent(const Document& document,
Element& focused_element) { … }
inline void DispatchFocusEvent(const Document& document,
Element& focused_element) { … }
inline void DispatchEventsOnWindowAndFocusedElement(Document* document,
bool focused) { … }
inline bool HasCustomFocusLogic(const Element& element) { … }
inline bool IsShadowHostWithoutCustomFocusLogic(const Element& element) { … }
inline bool IsNonKeyboardFocusableShadowHost(const Element& element) { … }
inline bool IsNonKeyboardFocusableReadingFlowOwner(const Element& element) { … }
inline bool IsKeyboardFocusableReadingFlowOwner(const Element& element) { … }
inline bool IsKeyboardFocusableShadowHost(const Element& element) { … }
inline bool IsNonFocusableFocusScopeOwner(Element& element) { … }
inline bool ShouldVisit(Element& element) { … }
Element* ScopedFocusNavigation::FindElementWithExactTabIndex(
int tab_index,
mojom::blink::FocusType type) { … }
Element* ScopedFocusNavigation::NextElementWithGreaterTabIndex(int tab_index) { … }
Element* ScopedFocusNavigation::PreviousElementWithLowerTabIndex(
int tab_index) { … }
Element* ScopedFocusNavigation::NextFocusableElement() { … }
Element* ScopedFocusNavigation::PreviousFocusableElement() { … }
Element* FindFocusableElementRecursivelyForward(
ScopedFocusNavigation& scope,
FocusController::OwnerMap& owner_map) { … }
Element* FindFocusableElementRecursivelyBackward(
ScopedFocusNavigation& scope,
FocusController::OwnerMap& owner_map) { … }
Element* FindFocusableElementRecursively(mojom::blink::FocusType type,
ScopedFocusNavigation& scope,
FocusController::OwnerMap& owner_map) { … }
Element* FindFocusableElementDescendingDownIntoFrameDocument(
mojom::blink::FocusType type,
Element* element,
FocusController::OwnerMap& owner_map) { … }
Element* FindFocusableElementAcrossFocusScopesForward(
ScopedFocusNavigation& scope,
FocusController::OwnerMap& owner_map) { … }
Element* FindFocusableElementAcrossFocusScopesBackward(
ScopedFocusNavigation& scope,
FocusController::OwnerMap& owner_map) { … }
Element* FindFocusableElementAcrossFocusScopes(
mojom::blink::FocusType type,
ScopedFocusNavigation& scope,
FocusController::OwnerMap& owner_map) { … }
}
FocusController::FocusController(Page* page)
: … { … }
void FocusController::SetFocusedFrame(Frame* frame, bool notify_embedder) { … }
void FocusController::FocusDocumentView(Frame* frame, bool notify_embedder) { … }
LocalFrame* FocusController::FocusedFrame() const { … }
Frame* FocusController::FocusedOrMainFrame() const { … }
void FocusController::FrameDetached(Frame* detached_frame) { … }
HTMLFrameOwnerElement* FocusController::FocusedFrameOwnerElement(
LocalFrame& current_frame) const { … }
bool FocusController::IsDocumentFocused(const Document& document) const { … }
void FocusController::FocusHasChanged() { … }
void FocusController::SetFocused(bool focused) { … }
void FocusController::SetFocusEmulationEnabled(bool emulate_focus) { … }
bool FocusController::SetInitialFocus(mojom::blink::FocusType type) { … }
bool FocusController::AdvanceFocus(
mojom::blink::FocusType type,
bool initial_focus,
InputDeviceCapabilities* source_capabilities) { … }
bool FocusController::AdvanceFocusAcrossFrames(
mojom::blink::FocusType type,
RemoteFrame* from,
LocalFrame* to,
InputDeviceCapabilities* source_capabilities) { … }
#if DCHECK_IS_ON()
inline bool IsNonFocusableShadowHost(const Element& element) { … }
#endif
bool FocusController::AdvanceFocusInDocumentOrder(
LocalFrame* frame,
Element* start,
mojom::blink::FocusType type,
bool initial_focus,
InputDeviceCapabilities* source_capabilities) { … }
Element* FocusController::FindFocusableElement(mojom::blink::FocusType type,
Element& element,
OwnerMap& owner_map) { … }
Element* FocusController::NextFocusableElementForImeAndAutofill(
Element* element,
mojom::blink::FocusType focus_type) { … }
Element* FocusController::FindFocusableElementInShadowHost(
const Element& shadow_host) { … }
HTMLElement* FocusController::FindScopeOwnerSlotOrReadingFlowContainer(
const Element& current) { … }
Element* FocusController::FindFocusableElementAfter(
Element& element,
mojom::blink::FocusType type) { … }
static bool RelinquishesEditingFocus(const Element& element) { … }
bool FocusController::SetFocusedElement(Element* element,
Frame* new_focused_frame) { … }
bool FocusController::SetFocusedElement(Element* element,
Frame* new_focused_frame,
const FocusParams& params) { … }
void FocusController::ActiveHasChanged() { … }
void FocusController::SetActive(bool active) { … }
void FocusController::RegisterFocusChangedObserver(
FocusChangedObserver* observer) { … }
void FocusController::NotifyFocusChangedObservers() const { … }
int FocusController::AdjustedTabIndex(const Element& element) { … }
void FocusController::Trace(Visitor* visitor) const { … }
}