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

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

Issue 14248006: A focused element should lose focus when it becomes unfocusable. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 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') | no next file » | 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 e3ff783900ca656fd499106a88c7daf2f48be5c4..1eeb7cb2c6fb94b4aee23bdb56b4cb09066f8f89 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -384,6 +384,27 @@ static void printNavigationErrorMessage(Frame* frame, const KURL& activeURL, con
uint64_t Document::s_globalTreeVersion = 0;
+// This class should be passed only to Document::postTask.
+class FocusedNodeChecker: public ScriptExecutionContext::Task {
esprehn 2013/05/20 22:03:44 Missing a space before : and this should be FINAL
tkent 2013/05/20 22:29:45 Done.
+public:
+ static PassOwnPtr<FocusedNodeChecker> create()
+ {
+ return adoptPtr(new FocusedNodeChecker());
+ }
+ virtual ~FocusedNodeChecker() { }
+
+private:
+ FocusedNodeChecker() { }
esprehn 2013/05/20 22:03:44 It be nicer if this was called CheckFocusedNodeTas
tkent 2013/05/20 22:29:45 Done.
+ virtual void performTask(ScriptExecutionContext* context) OVERRIDE
+ {
+ ASSERT(context->isDocument());
+ Document* document = toDocument(context);
+ document->didRunFocusedNodeCheker();
+ if (document->focusedNode() && !document->focusedNode()->isFocusable())
+ document->setFocusedNode(0);
+ }
+};
+
Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
: ContainerNode(0, CreateDocument)
, TreeScope(this)
@@ -393,6 +414,7 @@ Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
, m_contextFeatures(ContextFeatures::defaultSwitch())
, m_compatibilityMode(NoQuirksMode)
, m_compatibilityModeLocked(false)
+ , m_didPostFocusedNodeChecker(false)
, m_domTreeVersion(++s_globalTreeVersion)
, m_mutationObserverTypes(0)
, m_styleSheetCollection(DocumentStyleSheetCollection::create(this))
@@ -1808,6 +1830,11 @@ void Document::updateLayout()
// Only do a layout if changes have occurred that make it necessary.
if (frameView && renderer() && (frameView->layoutPending() || renderer()->needsLayout()))
frameView->layout();
+
+ if (m_focusedNode && !m_didPostFocusedNodeChecker) {
+ postTask(FocusedNodeChecker::create());
+ m_didPostFocusedNodeChecker = true;
+ }
}
// FIXME: This is a bad idea and needs to be removed eventually.
« no previous file with comments | « Source/core/dom/Document.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698