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

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

Issue 18371008: Add a WebDocument::watchCssSelectors(selectors) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@pinned
Patch Set: Omit split CLs Created 7 years, 5 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
Index: Source/core/dom/Document.cpp
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index 95f472d66f5410d5b3092bf470ae642040180b90..72266456254f94d98ad58fde293f47ff1cfa3ba2 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -40,6 +40,7 @@
#include "bindings/v8/ScriptController.h"
#include "core/accessibility/AXObjectCache.h"
#include "core/animation/DocumentTimeline.h"
+#include "core/css/CSSParser.h"
#include "core/css/CSSStyleDeclaration.h"
#include "core/css/CSSStyleSheet.h"
#include "core/css/FontLoader.h"
@@ -122,6 +123,7 @@
#include "core/loader/CookieJar.h"
#include "core/loader/DocumentLoader.h"
#include "core/loader/FrameLoader.h"
+#include "core/loader/FrameLoaderClient.h"
#include "core/loader/ImageLoader.h"
#include "core/loader/Prerenderer.h"
#include "core/loader/TextResourceDecoder.h"
@@ -444,6 +446,7 @@ Document::Document(Frame* frame, const KURL& url, DocumentClassFlags documentCla
, m_pendingTasksTimer(this, &Document::pendingTasksTimerFired)
, m_import(0)
, m_scheduledTasksAreSuspended(false)
+ , m_callbackSelectorChangeTimer(this, &Document::callbackSelectorChangeTimerFired)
, m_sharedObjectPoolClearTimer(this, &Document::sharedObjectPoolClearTimerFired)
#ifndef NDEBUG
, m_didDispatchViewportPropertiesChanged(false)
@@ -1847,6 +1850,60 @@ void Document::clearStyleResolver()
m_styleResolver.clear();
}
+#if ENABLE(CSS_CALLBACKS)
+void Document::callbackSelectorChangeTimerFired(Timer<Document>*)
+{
+ if (m_addedSelectors.isEmpty() && m_removedSelectors.isEmpty())
+ return;
+ if (frame()) {
+ Vector<String> addedSelectors, removedSelectors;
+ copyToVector(m_addedSelectors, addedSelectors);
+ copyToVector(m_removedSelectors, removedSelectors);
+ frame()->loader()->client()->selectorMatchChanged(addedSelectors, removedSelectors);
+ }
+ m_addedSelectors.clear();
+ m_removedSelectors.clear();
+}
+
+void Document::addSelectorMatch(const String& selector, StyleRareNonInheritedData* data)
+{
+ // Set m_document here to avoid exposing the weakFactory outside of Document.
+ data->m_document = m_weakFactory.createWeakPtr();
+
+ HashMap<String, int>::iterator count = m_matchingCallbackSelectors.find(selector);
+ if (count != m_matchingCallbackSelectors.end()) {
+ ++count->value;
+ return;
+ }
+ if (!m_callbackSelectorChangeTimer.isActive())
+ m_callbackSelectorChangeTimer.startOneShot(0);
+
+ m_matchingCallbackSelectors.set(selector, 1);
+ if (m_removedSelectors.contains(selector))
+ m_removedSelectors.remove(selector);
+ else
+ m_addedSelectors.add(selector);
+}
+
+void Document::removeSelectorMatch(const String& selector)
+{
+ HashMap<String, int>::iterator count = m_matchingCallbackSelectors.find(selector);
+ if (count == m_matchingCallbackSelectors.end())
+ return;
+ --count->value;
+ if (!count->value) {
+ if (!m_callbackSelectorChangeTimer.isActive())
+ m_callbackSelectorChangeTimer.startOneShot(0);
+
+ m_matchingCallbackSelectors.remove(count);
+ if (m_addedSelectors.contains(selector))
+ m_addedSelectors.remove(selector);
+ else
+ m_removedSelectors.add(selector);
+ }
+}
+#endif // ENABLE(CSS_CALLBACKS)
abarth-chromium 2013/07/12 23:44:11 This code should move into a supplement too. It's
Jeffrey Yasskin 2013/07/16 00:38:51 Done.
+
void Document::attach(const AttachContext& context)
{
ASSERT(!attached());
@@ -3025,6 +3082,29 @@ void Document::notifySeamlessChildDocumentsOfStylesheetUpdate() const
}
}
+void Document::watchCssSelectors(const Vector<String>& selectors)
+{
+ m_watchedCallbackSelectors.clear();
+ CSSParserContext context(UASheetMode);
+ CSSParser parser(context);
+
+ const CSSProperty callbackProperty(CSSPropertyInternalCallback, CSSPrimitiveValue::createIdentifier(CSSValueInternalPresence));
+ const RefPtr<StylePropertySet> callbackPropertySet = ImmutableStylePropertySet::create(&callbackProperty, 1, UASheetMode);
+
+ CSSSelectorList selectorList;
+ for (unsigned i = 0; i < selectors.size(); ++i) {
+ RefPtr<StyleRule> rule = StyleRule::create(i);
+
+ parser.parseSelector(selectors[i], selectorList);
+ rule->wrapperAdoptSelectorList(selectorList);
+
+ rule->setProperties(callbackPropertySet);
+
+ m_watchedCallbackSelectors.append(rule.release());
+ }
+ styleResolverChanged(RecalcStyleImmediately, FullStyleUpdate);
esprehn 2013/07/13 01:43:01 DeferRecalcStyle, this definitely doesn't need a s
Jeffrey Yasskin 2013/07/16 00:38:51 Done.
+}
+
void Document::setHoverNode(PassRefPtr<Node> newHoverNode)
{
m_hoverNode = newHoverNode;

Powered by Google App Engine
This is Rietveld 408576698