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

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: add a FIXME comment Created 7 years, 7 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 2fe8f42feedf361a990ffb5bfd1ac881627671fb..cfddc74d2fe18a0e070d10850da96967395d4fc9 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -370,6 +370,31 @@ 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 CheckFocusedNodeTask FINAL : public ScriptExecutionContext::Task {
+public:
+ static PassOwnPtr<CheckFocusedNodeTask> create()
+ {
+ return adoptPtr(new CheckFocusedNodeTask());
+ }
+ virtual ~CheckFocusedNodeTask() { }
+
+private:
+ CheckFocusedNodeTask() { }
+ virtual void performTask(ScriptExecutionContext* context) OVERRIDE
+ {
+ ASSERT(context->isDocument());
+ Document* document = toDocument(context);
+ document->didRunCheckFocusedNodeTask();
+ if (!document->focusedNode())
+ return;
+ if (document->focusedNode()->renderer() && document->focusedNode()->renderer()->needsLayout())
+ return;
+ if (!document->focusedNode()->isFocusable())
+ document->setFocusedNode(0);
+ }
+};
+
Document::Document(Frame* frame, const KURL& url, DocumentClassFlags documentClasses)
: ContainerNode(0, CreateDocument)
, TreeScope(this)
@@ -379,6 +404,7 @@ Document::Document(Frame* frame, const KURL& url, DocumentClassFlags documentCla
, m_contextFeatures(ContextFeatures::defaultSwitch())
, m_compatibilityMode(NoQuirksMode)
, m_compatibilityModeLocked(false)
+ , m_didPostCheckFocusedNodeTask(false)
, m_domTreeVersion(++s_globalTreeVersion)
, m_mutationObserverTypes(0)
, m_styleSheetCollection(DocumentStyleSheetCollection::create(this))
@@ -1707,6 +1733,12 @@ void Document::updateLayout()
// Only do a layout if changes have occurred that make it necessary.
if (frameView && renderer() && (frameView->layoutPending() || renderer()->needsLayout()))
frameView->layout();
+
+ // FIXME: Using a Task doesn't look a good idea.
+ if (m_focusedNode && !m_didPostCheckFocusedNodeTask) {
+ postTask(CheckFocusedNodeTask::create());
+ m_didPostCheckFocusedNodeTask = 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