#ifndef FocusController_h
#define FocusController_h
#include "core/page/FocusType.h"
#include "platform/geometry/LayoutRect.h"
#include "wtf/Forward.h"
#include "wtf/Noncopyable.h"
#include "wtf/RefPtr.h"
namespace WebCore {
struct FocusCandidate;
class Document;
class Element;
class Frame;
class HTMLFrameOwnerElement;
class HTMLShadowElement;
class IntRect;
class KeyboardEvent;
class Node;
class Page;
class TreeScope;
class FocusNavigationScope {
public:
Node* rootNode() const;
Element* owner() const;
static FocusNavigationScope focusNavigationScopeOf(Node*);
static FocusNavigationScope ownedByNonFocusableFocusScopeOwner(Node*);
static FocusNavigationScope ownedByShadowHost(Node*);
static FocusNavigationScope ownedByShadowInsertionPoint(HTMLShadowElement*);
static FocusNavigationScope ownedByIFrame(HTMLFrameOwnerElement*);
private:
explicit FocusNavigationScope(TreeScope*);
TreeScope* m_rootTreeScope;
};
class FocusController {
WTF_MAKE_NONCOPYABLE(FocusController); WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<FocusController> create(Page*);
void setFocusedFrame(PassRefPtr<Frame>);
Frame* focusedFrame() const { return m_focusedFrame.get(); }
Frame* focusedOrMainFrame() const;
bool setInitialFocus(FocusType);
bool advanceFocus(FocusType type) { return advanceFocus(type, false); }
bool setFocusedElement(Element*, PassRefPtr<Frame>, FocusType = FocusTypeNone);
void setActive(bool);
bool isActive() const { return m_isActive; }
void setFocused(bool);
bool isFocused() const { return m_isFocused; }
void setContainingWindowIsVisible(bool);
bool containingWindowIsVisible() const { return m_containingWindowIsVisible; }
private:
explicit FocusController(Page*);
bool advanceFocus(FocusType, bool initialFocus);
bool advanceFocusDirectionally(FocusType);
bool advanceFocusInDocumentOrder(FocusType, bool initialFocus);
Node* findFocusableNodeAcrossFocusScope(FocusType, FocusNavigationScope startScope, Node* start);
Node* findFocusableNodeRecursively(FocusType, FocusNavigationScope, Node* start);
Node* findFocusableNodeDecendingDownIntoFrameDocument(FocusType, Node*);
inline Node* findFocusableNode(FocusType, FocusNavigationScope, Node* start);
Node* nextFocusableNode(FocusNavigationScope, Node* start);
Node* previousFocusableNode(FocusNavigationScope, Node* start);
Node* findNodeWithExactTabIndex(Node* start, int tabIndex, FocusType);
bool advanceFocusDirectionallyInContainer(Node* container, const LayoutRect& startingRect, FocusType);
void findFocusCandidateInContainer(Node& container, const LayoutRect& startingRect, FocusType, FocusCandidate& closest);
Page* m_page;
RefPtr<Frame> m_focusedFrame;
bool m_isActive;
bool m_isFocused;
bool m_isChangingFocusedFrame;
bool m_containingWindowIsVisible;
};
}
#endif