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

Side by Side 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: Initial 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 unified diff | Download patch
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/features.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 22 matching lines...) Expand all
33 #include "RuntimeEnabledFeatures.h" 33 #include "RuntimeEnabledFeatures.h"
34 #include "SVGElementFactory.h" 34 #include "SVGElementFactory.h"
35 #include "SVGNames.h" 35 #include "SVGNames.h"
36 #include "XMLNSNames.h" 36 #include "XMLNSNames.h"
37 #include "XMLNames.h" 37 #include "XMLNames.h"
38 #include "bindings/v8/CustomElementConstructorBuilder.h" 38 #include "bindings/v8/CustomElementConstructorBuilder.h"
39 #include "bindings/v8/Dictionary.h" 39 #include "bindings/v8/Dictionary.h"
40 #include "bindings/v8/ScriptController.h" 40 #include "bindings/v8/ScriptController.h"
41 #include "core/accessibility/AXObjectCache.h" 41 #include "core/accessibility/AXObjectCache.h"
42 #include "core/animation/DocumentTimeline.h" 42 #include "core/animation/DocumentTimeline.h"
43 #include "core/css/CSSParser.h"
43 #include "core/css/CSSStyleDeclaration.h" 44 #include "core/css/CSSStyleDeclaration.h"
44 #include "core/css/CSSStyleSheet.h" 45 #include "core/css/CSSStyleSheet.h"
45 #include "core/css/FontLoader.h" 46 #include "core/css/FontLoader.h"
46 #include "core/css/MediaQueryMatcher.h" 47 #include "core/css/MediaQueryMatcher.h"
47 #include "core/css/StylePropertySet.h" 48 #include "core/css/StylePropertySet.h"
48 #include "core/css/StyleSheetContents.h" 49 #include "core/css/StyleSheetContents.h"
49 #include "core/css/StyleSheetList.h" 50 #include "core/css/StyleSheetList.h"
50 #include "core/css/resolver/StyleResolver.h" 51 #include "core/css/resolver/StyleResolver.h"
51 #include "core/dom/Attr.h" 52 #include "core/dom/Attr.h"
52 #include "core/dom/CDATASection.h" 53 #include "core/dom/CDATASection.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 #include "core/html/PluginDocument.h" 115 #include "core/html/PluginDocument.h"
115 #include "core/html/parser/HTMLDocumentParser.h" 116 #include "core/html/parser/HTMLDocumentParser.h"
116 #include "core/html/parser/HTMLParserIdioms.h" 117 #include "core/html/parser/HTMLParserIdioms.h"
117 #include "core/html/parser/NestingLevelIncrementer.h" 118 #include "core/html/parser/NestingLevelIncrementer.h"
118 #include "core/inspector/InspectorCounters.h" 119 #include "core/inspector/InspectorCounters.h"
119 #include "core/inspector/InspectorInstrumentation.h" 120 #include "core/inspector/InspectorInstrumentation.h"
120 #include "core/inspector/ScriptCallStack.h" 121 #include "core/inspector/ScriptCallStack.h"
121 #include "core/loader/CookieJar.h" 122 #include "core/loader/CookieJar.h"
122 #include "core/loader/DocumentLoader.h" 123 #include "core/loader/DocumentLoader.h"
123 #include "core/loader/FrameLoader.h" 124 #include "core/loader/FrameLoader.h"
125 #include "core/loader/FrameLoaderClient.h"
124 #include "core/loader/ImageLoader.h" 126 #include "core/loader/ImageLoader.h"
125 #include "core/loader/Prerenderer.h" 127 #include "core/loader/Prerenderer.h"
126 #include "core/loader/TextResourceDecoder.h" 128 #include "core/loader/TextResourceDecoder.h"
127 #include "core/loader/cache/CachedResourceLoader.h" 129 #include "core/loader/cache/CachedResourceLoader.h"
128 #include "core/page/Chrome.h" 130 #include "core/page/Chrome.h"
129 #include "core/page/ChromeClient.h" 131 #include "core/page/ChromeClient.h"
130 #include "core/page/ContentSecurityPolicy.h" 132 #include "core/page/ContentSecurityPolicy.h"
131 #include "core/page/DOMSecurityPolicy.h" 133 #include "core/page/DOMSecurityPolicy.h"
132 #include "core/page/DOMWindow.h" 134 #include "core/page/DOMWindow.h"
133 #include "core/page/EventHandler.h" 135 #include "core/page/EventHandler.h"
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 , m_directionSetOnDocumentElement(false) 441 , m_directionSetOnDocumentElement(false)
440 , m_writingModeSetOnDocumentElement(false) 442 , m_writingModeSetOnDocumentElement(false)
441 , m_writeRecursionIsTooDeep(false) 443 , m_writeRecursionIsTooDeep(false)
442 , m_writeRecursionDepth(0) 444 , m_writeRecursionDepth(0)
443 , m_wheelEventHandlerCount(0) 445 , m_wheelEventHandlerCount(0)
444 , m_lastHandledUserGestureTimestamp(0) 446 , m_lastHandledUserGestureTimestamp(0)
445 , m_prerenderer(Prerenderer::create(this)) 447 , m_prerenderer(Prerenderer::create(this))
446 , m_textAutosizer(TextAutosizer::create(this)) 448 , m_textAutosizer(TextAutosizer::create(this))
447 , m_pendingTasksTimer(this, &Document::pendingTasksTimerFired) 449 , m_pendingTasksTimer(this, &Document::pendingTasksTimerFired)
448 , m_scheduledTasksAreSuspended(false) 450 , m_scheduledTasksAreSuspended(false)
451 , m_callbackSelectorChangeTimer(this, &Document::callbackSelectorChangeTimer Fired)
449 , m_sharedObjectPoolClearTimer(this, &Document::sharedObjectPoolClearTimerFi red) 452 , m_sharedObjectPoolClearTimer(this, &Document::sharedObjectPoolClearTimerFi red)
450 #ifndef NDEBUG 453 #ifndef NDEBUG
451 , m_didDispatchViewportPropertiesChanged(false) 454 , m_didDispatchViewportPropertiesChanged(false)
452 #endif 455 #endif
453 , m_timeline(DocumentTimeline::create(this)) 456 , m_timeline(DocumentTimeline::create(this))
454 , m_templateDocumentHost(0) 457 , m_templateDocumentHost(0)
455 , m_fontloader(0) 458 , m_fontloader(0)
456 , m_didAssociateFormControlsTimer(this, &Document::didAssociateFormControlsT imerFired) 459 , m_didAssociateFormControlsTimer(this, &Document::didAssociateFormControlsT imerFired)
457 { 460 {
458 ScriptWrappable::init(this); 461 ScriptWrappable::init(this);
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 matchAuthorAndUserStyles = docSettings->authorAndUserStylesEnabled(); 1846 matchAuthorAndUserStyles = docSettings->authorAndUserStylesEnabled();
1844 m_styleResolver = adoptPtr(new StyleResolver(this, matchAuthorAndUserStyles) ); 1847 m_styleResolver = adoptPtr(new StyleResolver(this, matchAuthorAndUserStyles) );
1845 m_styleSheetCollection->combineCSSFeatureFlags(); 1848 m_styleSheetCollection->combineCSSFeatureFlags();
1846 } 1849 }
1847 1850
1848 void Document::clearStyleResolver() 1851 void Document::clearStyleResolver()
1849 { 1852 {
1850 m_styleResolver.clear(); 1853 m_styleResolver.clear();
1851 } 1854 }
1852 1855
1856 #if ENABLE(CSS_CALLBACKS)
1857 void Document::callbackSelectorChangeTimerFired(Timer<Document>*)
1858 {
1859 if (m_addedSelectors.isEmpty() && m_removedSelectors.isEmpty())
1860 return;
1861 if (frame()) {
1862 Vector<String> addedSelectors, removedSelectors;
1863 copyToVector(m_addedSelectors, addedSelectors);
1864 copyToVector(m_removedSelectors, removedSelectors);
1865 frame()->loader()->client()->selectorMatchChanged(addedSelectors, remove dSelectors);
1866 }
1867 m_addedSelectors.clear();
1868 m_removedSelectors.clear();
1869 }
1870
1871 void Document::addSelectorMatch(const String& selector, StyleRareNonInheritedDat a* data)
1872 {
1873 // Set m_document here to avoid exposing the weakFactory outside of Document .
1874 data->m_document = m_weakFactory.createWeakPtr();
1875
1876 HashMap<String, int>::iterator count = m_matchingCallbackSelectors.find(sele ctor);
1877 if (count != m_matchingCallbackSelectors.end()) {
1878 ++count->value;
1879 return;
1880 }
1881 if (!m_callbackSelectorChangeTimer.isActive())
1882 m_callbackSelectorChangeTimer.startOneShot(0);
1883
1884 m_matchingCallbackSelectors.set(selector, 1);
1885 if (m_removedSelectors.contains(selector))
1886 m_removedSelectors.remove(selector);
1887 else
1888 m_addedSelectors.add(selector);
1889 }
1890
1891 void Document::removeSelectorMatch(const String& selector)
1892 {
1893 HashMap<String, int>::iterator count = m_matchingCallbackSelectors.find(sele ctor);
1894 if (count == m_matchingCallbackSelectors.end())
1895 return;
1896 --count->value;
1897 if (!count->value) {
1898 if (!m_callbackSelectorChangeTimer.isActive())
1899 m_callbackSelectorChangeTimer.startOneShot(0);
1900
1901 m_matchingCallbackSelectors.remove(count);
1902 if (m_addedSelectors.contains(selector))
1903 m_addedSelectors.remove(selector);
1904 else
1905 m_removedSelectors.add(selector);
1906 }
1907 }
1908 #endif // ENABLE(CSS_CALLBACKS)
1909
1853 void Document::attach(const AttachContext& context) 1910 void Document::attach(const AttachContext& context)
1854 { 1911 {
1855 ASSERT(!attached()); 1912 ASSERT(!attached());
1856 ASSERT(!m_axObjectCache || this != topDocument()); 1913 ASSERT(!m_axObjectCache || this != topDocument());
1857 1914
1858 if (!m_renderArena) 1915 if (!m_renderArena)
1859 m_renderArena = RenderArena::create(); 1916 m_renderArena = RenderArena::create();
1860 1917
1861 // Create the rendering tree 1918 // Create the rendering tree
1862 setRenderer(new (m_renderArena.get()) RenderView(this)); 1919 setRenderer(new (m_renderArena.get()) RenderView(this));
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2997 // Seamless child frames are expected to notify their seamless children recu rsively, so we only do direct children. 3054 // Seamless child frames are expected to notify their seamless children recu rsively, so we only do direct children.
2998 for (Frame* child = frame()->tree()->firstChild(); child; child = child->tre e()->nextSibling()) { 3055 for (Frame* child = frame()->tree()->firstChild(); child; child = child->tre e()->nextSibling()) {
2999 Document* childDocument = child->document(); 3056 Document* childDocument = child->document();
3000 if (childDocument->shouldDisplaySeamlesslyWithParent()) { 3057 if (childDocument->shouldDisplaySeamlesslyWithParent()) {
3001 ASSERT(childDocument->seamlessParentIFrame()->document() == this); 3058 ASSERT(childDocument->seamlessParentIFrame()->document() == this);
3002 childDocument->seamlessParentUpdatedStylesheets(); 3059 childDocument->seamlessParentUpdatedStylesheets();
3003 } 3060 }
3004 } 3061 }
3005 } 3062 }
3006 3063
3064 void Document::watchCssSelectors(const Vector<String>& selectors)
3065 {
3066 m_watchedCallbackSelectors.clear();
3067 CSSParserContext context(UASheetMode);
3068 CSSParser parser(context);
3069
3070 const CSSProperty callbackProperty(CSSPropertyInternalCallback, CSSPrimitive Value::createIdentifier(CSSValueInternalPresence));
3071 const RefPtr<StylePropertySet> callbackPropertySet = ImmutableStylePropertyS et::create(&callbackProperty, 1, UASheetMode);
3072
3073 CSSSelectorList selectorList;
3074 for (unsigned i = 0; i < selectors.size(); ++i) {
3075 RefPtr<StyleRule> rule = StyleRule::create(i);
3076
3077 parser.parseSelector(selectors[i], selectorList);
3078 rule->wrapperAdoptSelectorList(selectorList);
3079
3080 rule->setProperties(callbackPropertySet);
3081
3082 m_watchedCallbackSelectors.append(rule.release());
3083 }
3084 styleResolverChanged(RecalcStyleImmediately, FullStyleUpdate);
3085 }
3086
3007 void Document::setHoverNode(PassRefPtr<Node> newHoverNode) 3087 void Document::setHoverNode(PassRefPtr<Node> newHoverNode)
3008 { 3088 {
3009 m_hoverNode = newHoverNode; 3089 m_hoverNode = newHoverNode;
3010 } 3090 }
3011 3091
3012 void Document::setActiveElement(PassRefPtr<Element> newActiveElement) 3092 void Document::setActiveElement(PassRefPtr<Element> newActiveElement)
3013 { 3093 {
3014 if (!newActiveElement) { 3094 if (!newActiveElement) {
3015 m_activeElement.clear(); 3095 m_activeElement.clear();
3016 return; 3096 return;
(...skipping 2120 matching lines...) Expand 10 before | Expand all | Expand 10 after
5137 { 5217 {
5138 return DocumentLifecycleNotifier::create(this); 5218 return DocumentLifecycleNotifier::create(this);
5139 } 5219 }
5140 5220
5141 DocumentLifecycleNotifier* Document::lifecycleNotifier() 5221 DocumentLifecycleNotifier* Document::lifecycleNotifier()
5142 { 5222 {
5143 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier()); 5223 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier());
5144 } 5224 }
5145 5225
5146 } // namespace WebCore 5226 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/features.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698