Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Unified Diff: Source/core/dom/Document.cpp

Issue 141733006: Move focus management API from HTMLDocument to Document (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add extra prototype check Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/Document.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Document.cpp
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index 73f20e044eff49f9a207fc7fc9b2a43e45470128..85193f46c6ddcd6d109459fa9f4f120fd9ab06e2 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -580,7 +580,7 @@ void Document::dispose()
m_docType = 0;
m_focusedElement = 0;
m_hoverNode = 0;
- m_activeElement = 0;
+ m_activeHoverElement = 0;
m_titleElement = 0;
m_documentElement = 0;
m_contextFeatures = ContextFeatures::defaultSwitch();
@@ -2051,7 +2051,7 @@ void Document::detach(const AttachContext& context)
m_hoverNode = 0;
m_focusedElement = 0;
- m_activeElement = 0;
+ m_activeHoverElement = 0;
m_autofocusElement = 0;
ContainerNode::detach(context);
@@ -3270,14 +3270,14 @@ void Document::setHoverNode(PassRefPtr<Node> newHoverNode)
m_hoverNode = newHoverNode;
}
-void Document::setActiveElement(PassRefPtr<Element> newActiveElement)
+void Document::setActiveHoverElement(PassRefPtr<Element> newActiveElement)
{
if (!newActiveElement) {
- m_activeElement.clear();
+ m_activeHoverElement.clear();
return;
}
- m_activeElement = newActiveElement;
+ m_activeHoverElement = newActiveElement;
}
void Document::removeFocusedElementOfSubtree(Node* node, bool amongChildrenOnly)
@@ -3317,17 +3317,17 @@ void Document::hoveredNodeDetached(Node* node)
void Document::activeChainNodeDetached(Node* node)
{
- if (!m_activeElement)
+ if (!m_activeHoverElement)
return;
- if (node != m_activeElement && (!m_activeElement->isTextNode() || node != NodeRenderingTraversal::parent(m_activeElement.get())))
+ if (node != m_activeHoverElement && (!m_activeHoverElement->isTextNode() || node != NodeRenderingTraversal::parent(m_activeHoverElement.get())))
return;
Node* activeNode = NodeRenderingTraversal::parent(node);
while (activeNode && activeNode->isElementNode() && !activeNode->renderer())
activeNode = NodeRenderingTraversal::parent(activeNode);
- m_activeElement = activeNode && activeNode->isElementNode() ? toElement(activeNode) : 0;
+ m_activeHoverElement = activeNode && activeNode->isElementNode() ? toElement(activeNode) : 0;
}
const Vector<AnnotatedRegionValue>& Document::annotatedRegions() const
@@ -5073,7 +5073,7 @@ void Document::updateHoverActiveState(const HitTestRequest& request, Element* in
innerElementInDocument = innerElementInDocument->document().ownerElement();
}
- Element* oldActiveElement = activeElement();
+ Element* oldActiveElement = activeHoverElement();
if (oldActiveElement && !request.active()) {
// We are clearing the :active chain because the mouse has been released.
for (RenderObject* curr = oldActiveElement->renderer(); curr; curr = curr->parent()) {
@@ -5083,7 +5083,7 @@ void Document::updateHoverActiveState(const HitTestRequest& request, Element* in
m_userActionElements.setInActiveChain(curr->node(), false);
}
}
- setActiveElement(0);
+ setActiveHoverElement(0);
} else {
Element* newActiveElement = innerElementInDocument;
if (!oldActiveElement && newActiveElement && request.active() && !request.touchMove()) {
@@ -5094,12 +5094,12 @@ void Document::updateHoverActiveState(const HitTestRequest& request, Element* in
m_userActionElements.setInActiveChain(curr->node(), true);
}
- setActiveElement(newActiveElement);
+ setActiveHoverElement(newActiveElement);
}
}
// If the mouse has just been pressed, set :active on the chain. Those (and only those)
// nodes should remain :active until the mouse is released.
- bool allowActiveChanges = !oldActiveElement && activeElement();
+ bool allowActiveChanges = !oldActiveElement && activeHoverElement();
// If the mouse is down and if this is a mouse move event, we want to restrict changes in
// :hover/:active to only apply to elements that are in the :active chain that we froze
@@ -5322,4 +5322,25 @@ void Document::setAutofocusElement(Element* element)
m_taskRunner->postTask(AutofocusTask::create());
}
+Element* Document::activeElement() const
+{
+ if (Element* element = treeScope().adjustedFocusedElement())
+ return element;
+ return body();
+}
+
+bool Document::hasFocus() const
+{
+ Page* page = this->page();
+ if (!page)
+ return false;
+ if (!page->focusController().isActive() || !page->focusController().isFocused())
+ return false;
+ if (Frame* focusedFrame = page->focusController().focusedFrame()) {
+ if (focusedFrame->tree().isDescendantOf(frame()))
+ return true;
+ }
+ return false;
+}
+
} // namespace WebCore
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/Document.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698