chromium/third_party/blink/renderer/core/page/focus_controller.cc

/*
 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
 * Copyright (C) 2008 Nuanti Ltd.
 *
 * 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/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"  // For firstPositionInOrBeforeNode
#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) {}

// https://open-ui.org/components/focusgroup.explainer/#last-focused-memory
Element* MaybeRestoreFocusedElementForFocusGroup(Element* element) {}

bool IsOpenPopoverWithInvoker(const Node* node) {}

const Element* InclusiveAncestorOpenPopoverWithInvoker(const Element* element) {}

bool IsOpenPopoverInvoker(const Node* node) {}

// If node is a reading-flow container or a display: contents element whose
// layout parent is a reading-flow container, return that container.
// This is a helper for SetReadingFlowInfo.
const ContainerNode* ReadingFlowContainerOrDisplayContents(
    const ContainerNode* node) {}

bool IsReadingFlowScopeOwner(const ContainerNode* node) {}

// This class defines the navigation order.
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) {}

// Checks whether |element| is an <iframe> and seems like a captcha based on
// heuristics. The heuristics cannot be perfect and therefore is a subject to
// change, e.g. adding a list of domains of captcha providers to be compared
// with 'src' attribute.
bool IsLikelyCaptchaIframe(const Element& element) {}

// Checks whether |element| is a captcha <iframe> or enclosed with such an
// <iframe>.
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) {}

}  // anonymous namespace

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) {}

// This is an implementation of step 2 of the "shadow host" branch of
// https://html.spec.whatwg.org/C/#get-the-focusable-area
Element* FocusController::FindFocusableElementInShadowHost(
    const Element& shadow_host) {}

// static
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 {}

// static
int FocusController::AdjustedTabIndex(const Element& element) {}

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

}  // namespace blink