// FIXME: Figure out the right thing for OOPI here.
if (Frame* frame = root->document().frame())
return frame->deprecatedLocalOwner();
- return 0;
+ return nullptr;
}
-FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node* node)
+FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node& node)
{
- ASSERT(node);
- Node* root = node;
- for (Node* n = node; n; n = n->parentNode())
+ Node* root = &node;
+ for (Node* n = &node; n; n = n->parentNode())
root = n;
// The result is not always a ShadowRoot nor a DocumentNode since
// a starting node is in an orphaned tree in composed shadow tree.
return FocusNavigationScope(&root->treeScope());
}
-FocusNavigationScope FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(Node* node)
+FocusNavigationScope FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(Node& node)
{
- ASSERT(node);
if (isShadowHost(node))
return FocusNavigationScope::ownedByShadowHost(node);
- ASSERT(isShadowInsertionPointFocusScopeOwner(*node));
+ ASSERT(isShadowInsertionPointFocusScopeOwner(node));
return FocusNavigationScope::ownedByShadowInsertionPoint(toHTMLShadowElement(node));
}
-FocusNavigationScope FocusNavigationScope::ownedByShadowHost(Node* node)
+FocusNavigationScope FocusNavigationScope::ownedByShadowHost(Node& node)
{
ASSERT(isShadowHost(node));
- return FocusNavigationScope(toElement(node)->shadow()->youngestShadowRoot());
+ return FocusNavigationScope(toElement(node).shadow()->youngestShadowRoot());
}
-FocusNavigationScope FocusNavigationScope::ownedByIFrame(HTMLFrameOwnerElement* frame)
+FocusNavigationScope FocusNavigationScope::ownedByIFrame(HTMLFrameOwnerElement& frame)
{
- ASSERT(frame && frame->contentFrame() && frame->contentFrame()->isLocalFrame());
- return FocusNavigationScope(toLocalFrame(frame->contentFrame())->document());
+ ASSERT(frame.contentFrame());
+ ASSERT(frame.contentFrame()->isLocalFrame());
+ return FocusNavigationScope(toLocalFrame(frame.contentFrame())->document());
}
-FocusNavigationScope FocusNavigationScope::ownedByShadowInsertionPoint(HTMLShadowElement* shadowInsertionPoint)
+FocusNavigationScope FocusNavigationScope::ownedByShadowInsertionPoint(HTMLShadowElement& shadowInsertionPoint)
{
- ASSERT(isShadowInsertionPointFocusScopeOwner(*shadowInsertionPoint));
- return FocusNavigationScope(shadowInsertionPoint->olderShadowRoot());
+ ASSERT(isShadowInsertionPointFocusScopeOwner(shadowInsertionPoint));
+ return FocusNavigationScope(shadowInsertionPoint.olderShadowRoot());
}
static inline void dispatchEventsOnWindowAndFocusedNode(Document* document, bool focused)
if (!focused && document->focusedElement()) {
RefPtrWillBeRawPtr<Element> focusedElement(document->focusedElement());
focusedElement->setFocus(false);
- focusedElement->dispatchBlurEvent(0);
+ focusedElement->dispatchBlurEvent(nullptr);
if (focusedElement == document->focusedElement()) {
- focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, 0);
+ focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, nullptr);
if (focusedElement == document->focusedElement())
- focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFocusOut, 0);
+ focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFocusOut, nullptr);
}
}
focusedElement->setFocus(true);
focusedElement->dispatchFocusEvent(0, FocusTypePage);
if (focusedElement == document->focusedElement()) {
- document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, 0, FocusTypePage);
+ document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, nullptr, FocusTypePage);
if (focusedElement == document->focusedElement())
- document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, 0, FocusTypePage);
+ document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, nullptr, FocusTypePage);
}
}
}
-static inline bool hasCustomFocusLogic(Element* element)
+static inline bool hasCustomFocusLogic(const Element& element)
{
- return element->isHTMLElement() && toHTMLElement(element)->hasCustomFocusLogic();
+ return element.isHTMLElement() && toHTMLElement(element).hasCustomFocusLogic();
}
#if ENABLE(ASSERT)
-static inline bool isNonFocusableShadowHost(Node* node)
+static inline bool isNonFocusableShadowHost(const Node& node)
{
- ASSERT(node);
- if (!node->isElementNode())
+ if (!node.isElementNode())
return false;
- Element* element = toElement(node);
- return !element->isFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
+ const Element& element = toElement(node);
+ return !element.isFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
}
#endif
-static inline bool isNonKeyboardFocusableShadowHost(Node* node)
+static inline bool isNonKeyboardFocusableShadowHost(const Node& node)
{
- ASSERT(node);
- if (!node->isElementNode())
+ if (!node.isElementNode())
return false;
- Element* element = toElement(node);
- return !element->isKeyboardFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
+ const Element& element = toElement(node);
+ return !element.isKeyboardFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
}
-static inline bool isKeyboardFocusableShadowHost(Node* node)
+static inline bool isKeyboardFocusableShadowHost(const Node& node)
{
- ASSERT(node);
- if (!node->isElementNode())
+ if (!node.isElementNode())
return false;
- Element* element = toElement(node);
- return element->isKeyboardFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
+ const Element& element = toElement(node);
+ return element.isKeyboardFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
}
-static inline bool isNonFocusableFocusScopeOwner(Node* node)
+static inline bool isNonFocusableFocusScopeOwner(Node& node)
{
- ASSERT(node);
- return isNonKeyboardFocusableShadowHost(node) || isShadowInsertionPointFocusScopeOwner(*node);
+ return isNonKeyboardFocusableShadowHost(node) || isShadowInsertionPointFocusScopeOwner(node);
}
-static inline int adjustedTabIndex(Node* node)
+static inline int adjustedTabIndex(Node& node)
{
- ASSERT(node);
- return isNonFocusableFocusScopeOwner(node) ? 0 : node->tabIndex();
+ return isNonFocusableFocusScopeOwner(node) ? 0 : node.tabIndex();
}
-static inline bool shouldVisit(Node* node)
+static inline bool shouldVisit(Node& node)
{
- ASSERT(node);
- return (node->isElementNode() && toElement(node)->isKeyboardFocusable()) || isNonFocusableFocusScopeOwner(node);
+ return (node.isElementNode() && toElement(node).isKeyboardFocusable()) || isNonFocusableFocusScopeOwner(node);
}
FocusController::FocusController(Page* page)
m_isChangingFocusedFrame = true;
- RefPtrWillBeRawPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : 0;
+ RefPtrWillBeRawPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : nullptr;
- RefPtrWillBeRawPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : 0;
+ RefPtrWillBeRawPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : nullptr;
m_focusedFrame = frame.get();
if (m_focusedFrame == frame)
return;
- RefPtrWillBeRawPtr<LocalFrame> focusedFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : 0;
+ RefPtrWillBeRawPtr<LocalFrame> focusedFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : nullptr;
if (focusedFrame && focusedFrame->view()) {
RefPtrWillBeRawPtr<Document> document = focusedFrame->document();
- Element* focusedElement = document ? document->focusedElement() : 0;
+ Element* focusedElement = document ? document->focusedElement() : nullptr;
if (focusedElement) {
- focusedElement->dispatchBlurEvent(0);
+ focusedElement->dispatchBlurEvent(nullptr);
if (focusedElement == document->focusedElement()) {
- focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, 0);
+ focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, nullptr);
if (focusedElement == document->focusedElement())
- focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFocusOut, 0);
+ focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFocusOut, nullptr);
}
}
}
- RefPtrWillBeRawPtr<LocalFrame> newFocusedFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : 0;
+ RefPtrWillBeRawPtr<LocalFrame> newFocusedFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : nullptr;
if (newFocusedFrame && newFocusedFrame->view()) {
RefPtrWillBeRawPtr<Document> document = newFocusedFrame->document();
- Element* focusedElement = document ? document->focusedElement() : 0;
+ Element* focusedElement = document ? document->focusedElement() : nullptr;
if (focusedElement) {
focusedElement->dispatchFocusEvent(0, FocusTypePage);
if (focusedElement == document->focusedElement()) {
- document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, 0, FocusTypePage);
+ document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, nullptr, FocusTypePage);
if (focusedElement == document->focusedElement())
- document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, 0, FocusTypePage);
+ document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, nullptr, FocusTypePage);
}
}
}
// 1) a focusable node, or
// 2) the deepest-nested HTMLFrameOwnerElement.
while (node && node->isFrameOwnerElement()) {
- HTMLFrameOwnerElement* owner = toHTMLFrameOwnerElement(node);
- if (!owner->contentFrame() || !owner->contentFrame()->isLocalFrame())
+ HTMLFrameOwnerElement& owner = toHTMLFrameOwnerElement(*node);
+ if (!owner.contentFrame() || !owner.contentFrame()->isLocalFrame())
break;
- Node* foundNode = findFocusableNode(type, FocusNavigationScope::ownedByIFrame(owner), 0);
+ Node* foundNode = findFocusableNode(type, FocusNavigationScope::ownedByIFrame(owner), nullptr);
if (!foundNode)
break;
ASSERT(node != foundNode);
if (focusedOrMainFrame()->isLocalFrame()) {
Document* document = toLocalFrame(focusedOrMainFrame())->document();
if (AXObjectCache* cache = document->existingAXObjectCache())
- cache->postNotification(document, AXObjectCache::AXFocusedUIElementChanged, true);
+ cache->handleInitialFocus();
}
return didAdvanceFocus;
document->updateLayoutIgnorePendingStylesheets();
- RefPtrWillBeRawPtr<Node> node = findFocusableNodeAcrossFocusScope(type, FocusNavigationScope::focusNavigationScopeOf(currentNode ? currentNode : document), currentNode);
+ RefPtrWillBeRawPtr<Node> node = findFocusableNodeAcrossFocusScope(type, FocusNavigationScope::focusNavigationScopeOf(currentNode ? *currentNode : *document), currentNode);
if (!node) {
// We didn't find a node to focus, so we should try to pass focus to Chrome.
// Chrome doesn't want focus, so we should wrap focus.
if (!m_page->mainFrame()->isLocalFrame())
return false;
- node = findFocusableNodeRecursively(type, FocusNavigationScope::focusNavigationScopeOf(m_page->deprecatedLocalMainFrame()->document()), 0);
+ node = findFocusableNodeRecursively(type, FocusNavigationScope::focusNavigationScopeOf(*m_page->deprecatedLocalMainFrame()->document()), nullptr);
node = findFocusableNodeDecendingDownIntoFrameDocument(type, node.get());
if (!node)
Node* FocusController::findFocusableNodeAcrossFocusScope(FocusType type, FocusNavigationScope scope, Node* currentNode)
{
- ASSERT(!currentNode || !isNonFocusableShadowHost(currentNode));
+ ASSERT(!currentNode || !isNonFocusableShadowHost(*currentNode));
Node* found;
- if (currentNode && type == FocusTypeForward && isKeyboardFocusableShadowHost(currentNode)) {
- Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByShadowHost(currentNode), 0);
+ if (currentNode && type == FocusTypeForward && isKeyboardFocusableShadowHost(*currentNode)) {
+ Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByShadowHost(*currentNode), nullptr);
found = foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableNodeRecursively(type, scope, currentNode);
} else {
found = findFocusableNodeRecursively(type, scope, currentNode);
Node* owner = scope.owner();
if (!owner)
break;
- scope = FocusNavigationScope::focusNavigationScopeOf(owner);
- if (type == FocusTypeBackward && isKeyboardFocusableShadowHost(owner)) {
+ scope = FocusNavigationScope::focusNavigationScopeOf(*owner);
+ if (type == FocusTypeBackward && isKeyboardFocusableShadowHost(*owner)) {
found = owner;
break;
}
Node* FocusController::findFocusableNodeRecursively(FocusType type, FocusNavigationScope scope, Node* start)
{
// Starting node is exclusive.
- Node* found = findFocusableNode(type, scope, start);
- if (!found)
- return 0;
+ Node* foundOrNull = findFocusableNode(type, scope, start);
+ if (!foundOrNull)
+ return nullptr;
+ Node& found = *foundOrNull;
if (type == FocusTypeForward) {
if (!isNonFocusableFocusScopeOwner(found))
- return found;
- Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(found), 0);
- return foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableNodeRecursively(type, scope, found);
+ return &found;
+ Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(found), nullptr);
+ return foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableNodeRecursively(type, scope, &found);
}
ASSERT(type == FocusTypeBackward);
if (isKeyboardFocusableShadowHost(found)) {
- Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByShadowHost(found), 0);
- return foundInInnerFocusScope ? foundInInnerFocusScope : found;
+ Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByShadowHost(found), nullptr);
+ return foundInInnerFocusScope ? foundInInnerFocusScope : &found;
}
if (isNonFocusableFocusScopeOwner(found)) {
- Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(found), 0);
- return foundInInnerFocusScope ? foundInInnerFocusScope :findFocusableNodeRecursively(type, scope, found);
+ Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(found), nullptr);
+ return foundInInnerFocusScope ? foundInInnerFocusScope :findFocusableNodeRecursively(type, scope, &found);
}
- return found;
+ return &found;
}
Node* FocusController::findFocusableNode(FocusType type, FocusNavigationScope scope, Node* node)
{
// Search is inclusive of start
for (Node* node = start; node; node = type == FocusTypeForward ? NodeTraversal::next(*node) : NodeTraversal::previous(*node)) {
- if (shouldVisit(node) && adjustedTabIndex(node) == tabIndex)
+ if (shouldVisit(*node) && adjustedTabIndex(*node) == tabIndex)
return node;
}
- return 0;
+ return nullptr;
}
static Node* nextNodeWithGreaterTabIndex(Node* start, int tabIndex)
{
// Search is inclusive of start
int winningTabIndex = std::numeric_limits<short>::max() + 1;
- Node* winner = 0;
- for (Node* node = start; node; node = NodeTraversal::next(*node)) {
+ Node* winner = nullptr;
+ for (Node& node : NodeTraversal::startsAt(start)) {
int currentTabIndex = adjustedTabIndex(node);
if (shouldVisit(node) && currentTabIndex > tabIndex && currentTabIndex < winningTabIndex) {
- winner = node;
+ winner = &node;
winningTabIndex = currentTabIndex;
}
}
{
// Search is inclusive of start
int winningTabIndex = 0;
- Node* winner = 0;
+ Node* winner = nullptr;
for (Node* node = start; node; node = NodeTraversal::previous(*node)) {
- int currentTabIndex = adjustedTabIndex(node);
- if ((shouldVisit(node) || isNonKeyboardFocusableShadowHost(node)) && currentTabIndex < tabIndex && currentTabIndex > winningTabIndex) {
+ int currentTabIndex = adjustedTabIndex(*node);
+ if (shouldVisit(*node) && currentTabIndex < tabIndex && currentTabIndex > winningTabIndex) {
winner = node;
winningTabIndex = currentTabIndex;
}
Node* FocusController::nextFocusableNode(FocusNavigationScope scope, Node* start)
{
if (start) {
- int tabIndex = adjustedTabIndex(start);
+ int tabIndex = adjustedTabIndex(*start);
// If a node is excluded from the normal tabbing cycle, the next focusable node is determined by tree order
if (tabIndex < 0) {
- for (Node* node = NodeTraversal::next(*start); node; node = NodeTraversal::next(*node)) {
+ for (Node& node : NodeTraversal::startsAfter(*start)) {
if (shouldVisit(node) && adjustedTabIndex(node) >= 0)
- return node;
+ return &node;
}
} else {
// First try to find a node with the same tabindex as start that comes after start in the scope.
if (Node* winner = findNodeWithExactTabIndex(NodeTraversal::next(*start), tabIndex, FocusTypeForward))
return winner;
}
- if (!tabIndex)
+ if (!tabIndex) {
// We've reached the last node in the document with a tabindex of 0. This is the end of the tabbing order.
- return 0;
+ return nullptr;
+ }
}
// Look for the first node in the scope that:
// 1) has the lowest tabindex that is higher than start's tabindex (or 0, if start is null), and
// 2) comes first in the scope, if there's a tie.
- if (Node* winner = nextNodeWithGreaterTabIndex(scope.rootNode(), start ? adjustedTabIndex(start) : 0))
+ if (Node* winner = nextNodeWithGreaterTabIndex(scope.rootNode(), start ? adjustedTabIndex(*start) : 0))
return winner;
// There are no nodes with a tabindex greater than start's tabindex,
Node* FocusController::previousFocusableNode(FocusNavigationScope scope, Node* start)
{
- Node* last = 0;
+ Node* last = nullptr;
for (Node* node = scope.rootNode(); node; node = node->lastChild())
last = node;
ASSERT(last);
int startingTabIndex;
if (start) {
startingNode = NodeTraversal::previous(*start);
- startingTabIndex = adjustedTabIndex(start);
+ startingTabIndex = adjustedTabIndex(*start);
} else {
startingNode = last;
startingTabIndex = 0;
// However, if a node is excluded from the normal tabbing cycle, the previous focusable node is determined by tree order
if (startingTabIndex < 0) {
for (Node* node = startingNode; node; node = NodeTraversal::previous(*node)) {
- if (shouldVisit(node) && adjustedTabIndex(node) >= 0)
+ if (shouldVisit(*node) && adjustedTabIndex(*node) >= 0)
return node;
}
} else {
return previousNodeWithLowerTabIndex(last, startingTabIndex);
}
-static bool relinquishesEditingFocus(Node *node)
+static bool relinquishesEditingFocus(const Element& element)
{
- ASSERT(node);
- ASSERT(node->hasEditableStyle());
- return node->document().frame() && node->rootEditableElement();
+ ASSERT(element.hasEditableStyle());
+ return element.document().frame() && element.rootEditableElement();
}
static void clearSelectionIfNeeded(LocalFrame* oldFocusedFrame, LocalFrame* newFocusedFrame, Node* newFocusedNode)
bool FocusController::setFocusedElement(Element* element, PassRefPtrWillBeRawPtr<Frame> newFocusedFrame, FocusType type)
{
RefPtrWillBeRawPtr<LocalFrame> oldFocusedFrame = toLocalFrame(focusedFrame());
- RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : 0;
+ RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : nullptr;
- Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : 0;
+ Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : nullptr;
if (element && oldFocusedElement == element)
return true;
// FIXME: Might want to disable this check for caretBrowsing
- if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !relinquishesEditingFocus(oldFocusedElement))
+ if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !relinquishesEditingFocus(*oldFocusedElement))
return false;
m_page->chrome().client().willSetInputMethodState();
setFocusedFrame(newFocusedFrame);
// Setting the focused node can result in losing our last reft to node when JS event handlers fire.
- RefPtrWillBeRawPtr<Element> protect ALLOW_UNUSED = element;
+ RefPtrWillBeRawPtr<Element> protect = element;
+ ALLOW_UNUSED_LOCAL(protect);
if (newDocument) {
bool successfullyFocused = newDocument->setFocusedElement(element, type);
if (!successfullyFocused)
void FocusController::findFocusCandidateInContainer(Node& container, const LayoutRect& startingRect, FocusType type, FocusCandidate& closest)
{
- Element* focusedElement = (focusedFrame() && toLocalFrame(focusedFrame())->document()) ? toLocalFrame(focusedFrame())->document()->focusedElement() : 0;
+ Element* focusedElement = (focusedFrame() && toLocalFrame(focusedFrame())->document()) ? toLocalFrame(focusedFrame())->document()->focusedElement() : nullptr;
Element* element = ElementTraversal::firstWithin(container);
FocusCandidate current;