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

Side by Side Diff: Source/core/css/resolver/StyleResolver.cpp

Issue 19555002: Translate viewport related meta tags into @viewport descriptors as suggested by the CSS Device Adap… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "core/css/CSSDefaultStyleSheets.h" 43 #include "core/css/CSSDefaultStyleSheets.h"
44 #include "core/css/CSSFontSelector.h" 44 #include "core/css/CSSFontSelector.h"
45 #include "core/css/CSSKeyframeRule.h" 45 #include "core/css/CSSKeyframeRule.h"
46 #include "core/css/CSSKeyframesRule.h" 46 #include "core/css/CSSKeyframesRule.h"
47 #include "core/css/CSSParser.h" 47 #include "core/css/CSSParser.h"
48 #include "core/css/CSSReflectValue.h" 48 #include "core/css/CSSReflectValue.h"
49 #include "core/css/CSSRuleList.h" 49 #include "core/css/CSSRuleList.h"
50 #include "core/css/CSSSelector.h" 50 #include "core/css/CSSSelector.h"
51 #include "core/css/CSSStyleRule.h" 51 #include "core/css/CSSStyleRule.h"
52 #include "core/css/CSSValueList.h" 52 #include "core/css/CSSValueList.h"
53 #include "core/css/CSSValuePool.h"
53 #include "core/css/CSSVariableValue.h" 54 #include "core/css/CSSVariableValue.h"
54 #include "core/css/ElementRuleCollector.h" 55 #include "core/css/ElementRuleCollector.h"
55 #include "core/css/MediaQueryEvaluator.h" 56 #include "core/css/MediaQueryEvaluator.h"
56 #include "core/css/PageRuleCollector.h" 57 #include "core/css/PageRuleCollector.h"
57 #include "core/css/RuleSet.h" 58 #include "core/css/RuleSet.h"
58 #include "core/css/StylePropertySet.h" 59 #include "core/css/StylePropertySet.h"
59 #include "core/css/resolver/AnimatedStyleBuilder.h" 60 #include "core/css/resolver/AnimatedStyleBuilder.h"
60 #include "core/css/resolver/MatchResult.h" 61 #include "core/css/resolver/MatchResult.h"
61 #include "core/css/resolver/MediaQueryResult.h" 62 #include "core/css/resolver/MediaQueryResult.h"
62 #include "core/css/resolver/SharedStyleFinder.h" 63 #include "core/css/resolver/SharedStyleFinder.h"
63 #include "core/css/resolver/StyleAdjuster.h" 64 #include "core/css/resolver/StyleAdjuster.h"
64 #include "core/css/resolver/StyleBuilder.h" 65 #include "core/css/resolver/StyleBuilder.h"
65 #include "core/css/resolver/ViewportStyleResolver.h" 66 #include "core/css/resolver/ViewportStyleResolver.h"
66 #include "core/dom/DocumentStyleSheetCollection.h" 67 #include "core/dom/DocumentStyleSheetCollection.h"
67 #include "core/dom/NodeRenderStyle.h" 68 #include "core/dom/NodeRenderStyle.h"
68 #include "core/dom/NodeRenderingContext.h" 69 #include "core/dom/NodeRenderingContext.h"
69 #include "core/dom/Text.h" 70 #include "core/dom/Text.h"
70 #include "core/dom/shadow/ElementShadow.h" 71 #include "core/dom/shadow/ElementShadow.h"
71 #include "core/dom/shadow/ShadowRoot.h" 72 #include "core/dom/shadow/ShadowRoot.h"
72 #include "core/html/HTMLIFrameElement.h" 73 #include "core/html/HTMLIFrameElement.h"
73 #include "core/inspector/InspectorInstrumentation.h" 74 #include "core/inspector/InspectorInstrumentation.h"
74 #include "core/page/Frame.h" 75 #include "core/page/Frame.h"
75 #include "core/page/FrameView.h" 76 #include "core/page/FrameView.h"
77 #include "core/page/PageGroup.h"
76 #include "core/rendering/RenderView.h" 78 #include "core/rendering/RenderView.h"
77 #include "core/rendering/style/KeyframeList.h" 79 #include "core/rendering/style/KeyframeList.h"
78 #include "core/rendering/style/StyleCustomFilterProgramCache.h" 80 #include "core/rendering/style/StyleCustomFilterProgramCache.h"
79 #include "core/svg/SVGDocumentExtensions.h" 81 #include "core/svg/SVGDocumentExtensions.h"
80 #include "core/svg/SVGElement.h" 82 #include "core/svg/SVGElement.h"
81 #include "core/svg/SVGFontFaceElement.h" 83 #include "core/svg/SVGFontFaceElement.h"
82 #include "wtf/StdLibExtras.h" 84 #include "wtf/StdLibExtras.h"
83 #include "wtf/Vector.h" 85 #include "wtf/Vector.h"
84 86
85 using namespace std; 87 using namespace std;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 m_medium = adoptPtr(new MediaQueryEvaluator("all")); 132 m_medium = adoptPtr(new MediaQueryEvaluator("all"));
131 133
132 if (root) 134 if (root)
133 m_rootDefaultStyle = styleForElement(root, 0, DisallowStyleSharing, Matc hOnlyUserAgentRules); 135 m_rootDefaultStyle = styleForElement(root, 0, DisallowStyleSharing, Matc hOnlyUserAgentRules);
134 136
135 if (m_rootDefaultStyle && view) 137 if (m_rootDefaultStyle && view)
136 m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType(), view->fra me(), m_rootDefaultStyle.get())); 138 m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType(), view->fra me(), m_rootDefaultStyle.get()));
137 139
138 m_styleTree.clear(); 140 m_styleTree.clear();
139 141
142 if (document->isXHTMLMobileProfile()) {
143 Vector<String> whitelist;
144 whitelist.append(document->url());
145 static const char* sheet = "@viewport{-internal-priority:1;width:auto;he ight:auto;zoom:1;}";
146 document->page()->group().addUserStyleSheet(sheet, KURL(), whitelist, Ve ctor<String>(), InjectInAllFrames, UserStyleAuthorLevel, InjectInExistingDocumen ts);
147 }
148
140 DocumentStyleSheetCollection* styleSheetCollection = document->styleSheetCol lection(); 149 DocumentStyleSheetCollection* styleSheetCollection = document->styleSheetCol lection();
141 m_ruleSets.initUserStyle(styleSheetCollection, *m_medium, *this); 150 m_ruleSets.initUserStyle(styleSheetCollection, *m_medium, *this);
142 151
143 #if ENABLE(SVG_FONTS) 152 #if ENABLE(SVG_FONTS)
144 if (document->svgExtensions()) { 153 if (document->svgExtensions()) {
145 const HashSet<SVGFontFaceElement*>& svgFontFaceElements = document->svgE xtensions()->svgFontFaceElements(); 154 const HashSet<SVGFontFaceElement*>& svgFontFaceElements = document->svgE xtensions()->svgFontFaceElements();
146 HashSet<SVGFontFaceElement*>::const_iterator end = svgFontFaceElements.e nd(); 155 HashSet<SVGFontFaceElement*>::const_iterator end = svgFontFaceElements.e nd();
147 for (HashSet<SVGFontFaceElement*>::const_iterator it = svgFontFaceElemen ts.begin(); it != end; ++it) 156 for (HashSet<SVGFontFaceElement*>::const_iterator it = svgFontFaceElemen ts.begin(); it != end; ++it)
148 fontSelector()->addFontFaceRule((*it)->fontFaceRule()); 157 fontSelector()->addFontFaceRule((*it)->fontFaceRule());
149 } 158 }
150 #endif 159 #endif
151 160
152 styleSheetCollection->appendActiveAuthorStyleSheets(this); 161 styleSheetCollection->appendActiveAuthorStyleSheets(this);
153 } 162 }
154 163
155 void StyleResolver::appendAuthorStyleSheets(unsigned firstNew, const Vector<RefP tr<CSSStyleSheet> >& styleSheets) 164 void StyleResolver::appendAuthorStyleSheets(unsigned firstNew, const Vector<RefP tr<CSSStyleSheet> >& styleSheets)
156 { 165 {
157 // This handles sheets added to the end of the stylesheet list only. In othe r cases the style resolver 166 // This handles sheets added to the end of the stylesheet list only. In othe r cases the style resolver
158 // needs to be reconstructed. To handle insertions too the rule order number s would need to be updated. 167 // needs to be reconstructed. To handle insertions too the rule order number s would need to be updated.
159 unsigned size = styleSheets.size(); 168 unsigned size = styleSheets.size();
160 for (unsigned i = firstNew; i < size; ++i) { 169 for (unsigned i = firstNew; i < size; ++i) {
161 CSSStyleSheet* cssSheet = styleSheets[i].get(); 170 CSSStyleSheet* cssSheet = styleSheets[i].get();
171
162 ASSERT(!cssSheet->disabled()); 172 ASSERT(!cssSheet->disabled());
163 if (cssSheet->mediaQueries() && !m_medium->eval(cssSheet->mediaQueries() , this)) 173 if (cssSheet->mediaQueries() && !m_medium->eval(cssSheet->mediaQueries() , this))
164 continue; 174 continue;
165 175
166 StyleSheetContents* sheet = cssSheet->contents(); 176 StyleSheetContents* sheet = cssSheet->contents();
167 ScopedStyleResolver* resolver = ensureScopedStyleResolver(ScopedStyleRes olver::scopingNodeFor(cssSheet)); 177 ScopedStyleResolver* resolver = ensureScopedStyleResolver(ScopedStyleRes olver::scopingNodeFor(cssSheet));
168 ASSERT(resolver); 178 ASSERT(resolver);
169 resolver->addRulesFromSheet(sheet, *m_medium, this); 179 resolver->addRulesFromSheet(sheet, *m_medium, this);
170 m_inspectorCSSOMWrappers.collectFromStyleSheetIfNeeded(cssSheet); 180 m_inspectorCSSOMWrappers.collectFromStyleSheetIfNeeded(cssSheet);
171 } 181 }
172 } 182 }
173 183
174 void StyleResolver::finishAppendAuthorStyleSheets() 184 void StyleResolver::finishAppendAuthorStyleSheets()
175 { 185 {
176 collectFeatures(); 186 collectFeatures();
177 187
178 if (document()->renderer() && document()->renderer()->style()) 188 if (document()->renderer() && document()->renderer()->style())
179 document()->renderer()->style()->font().update(fontSelector()); 189 document()->renderer()->style()->font().update(fontSelector());
180 190
181 if (RuntimeEnabledFeatures::cssViewportEnabled()) 191 collectViewportRules();
182 collectViewportRules();
183 } 192 }
184 193
185 void StyleResolver::resetAuthorStyle(const ContainerNode* scopingNode) 194 void StyleResolver::resetAuthorStyle(const ContainerNode* scopingNode)
186 { 195 {
187 ScopedStyleResolver* resolver = scopingNode ? m_styleTree.scopedStyleResolve rFor(scopingNode) : m_styleTree.scopedStyleResolverForDocument(); 196 ScopedStyleResolver* resolver = scopingNode ? m_styleTree.scopedStyleResolve rFor(scopingNode) : m_styleTree.scopedStyleResolverForDocument();
188 if (!resolver) 197 if (!resolver)
189 return; 198 return;
190 199
191 m_ruleSets.shadowDistributedRules().reset(scopingNode); 200 m_ruleSets.shadowDistributedRules().reset(scopingNode);
192 201
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources()); 1032 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources());
1024 1033
1025 document()->didAccessStyleResolver(); 1034 document()->didAccessStyleResolver();
1026 1035
1027 // Now return the style. 1036 // Now return the style.
1028 return state.takeStyle(); 1037 return state.takeStyle();
1029 } 1038 }
1030 1039
1031 void StyleResolver::collectViewportRules() 1040 void StyleResolver::collectViewportRules()
1032 { 1041 {
1033 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled());
1034
1035 collectViewportRules(CSSDefaultStyleSheets::defaultStyle); 1042 collectViewportRules(CSSDefaultStyleSheets::defaultStyle);
1036 if (m_ruleSets.userStyle()) 1043 if (m_ruleSets.userStyle())
1037 collectViewportRules(m_ruleSets.userStyle()); 1044 collectViewportRules(m_ruleSets.userStyle());
1038 1045
1046 // OK to collect here for viewport meta etc, only the parser doesn't allow a ddition
1047 // of @viewport with the runtime check.
1039 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor Document()) 1048 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor Document())
1040 scopedResolver->collectViewportRulesTo(this); 1049 scopedResolver->collectViewportRulesTo(this);
1041 1050
1042 viewportStyleResolver()->resolve(); 1051 viewportStyleResolver()->resolve();
1043 } 1052 }
1044 1053
1045 void StyleResolver::collectViewportRules(RuleSet* rules) 1054 void StyleResolver::collectViewportRules(RuleSet* rules)
1046 { 1055 {
1047 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled());
1048
1049 rules->compactRulesIfNeeded(); 1056 rules->compactRulesIfNeeded();
1050 1057
1051 const Vector<StyleRuleViewport*>& viewportRules = rules->viewportRules(); 1058 const Vector<StyleRuleViewport*>& viewportRules = rules->viewportRules();
1052 for (size_t i = 0; i < viewportRules.size(); ++i) 1059 for (size_t i = 0; i < viewportRules.size(); ++i)
1053 viewportStyleResolver()->addViewportRule(viewportRules[i]); 1060 viewportStyleResolver()->addViewportRule(viewportRules[i]);
1054 } 1061 }
1055 1062
1056 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() 1063 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement()
1057 { 1064 {
1058 StyleResolverState state(document(), 0); 1065 StyleResolverState state(document(), 0);
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 m_viewportDependentMediaQueryResults.append(adoptPtr(new MediaQueryResult(*e xpr, result))); 1503 m_viewportDependentMediaQueryResults.append(adoptPtr(new MediaQueryResult(*e xpr, result)));
1497 } 1504 }
1498 1505
1499 bool StyleResolver::affectedByViewportChange() const 1506 bool StyleResolver::affectedByViewportChange() const
1500 { 1507 {
1501 unsigned s = m_viewportDependentMediaQueryResults.size(); 1508 unsigned s = m_viewportDependentMediaQueryResults.size();
1502 for (unsigned i = 0; i < s; i++) { 1509 for (unsigned i = 0; i < s; i++) {
1503 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio n) != m_viewportDependentMediaQueryResults[i]->m_result) 1510 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio n) != m_viewportDependentMediaQueryResults[i]->m_result)
1504 return true; 1511 return true;
1505 } 1512 }
1513
1506 return false; 1514 return false;
1507 } 1515 }
1508 1516
1509 #ifdef STYLE_STATS 1517 #ifdef STYLE_STATS
1510 StyleSharingStats StyleResolver::m_styleSharingStats; 1518 StyleSharingStats StyleResolver::m_styleSharingStats;
1511 1519
1512 static void printStyleStats(unsigned searches, unsigned elementsEligibleForShari ng, unsigned stylesShared, unsigned searchFoundSiblingForSharing, unsigned searc hesMissedSharing, 1520 static void printStyleStats(unsigned searches, unsigned elementsEligibleForShari ng, unsigned stylesShared, unsigned searchFoundSiblingForSharing, unsigned searc hesMissedSharing,
1513 unsigned matchedPropertiesSearches, unsigned matchedPropertiesHit, unsigned matchedPropertiesSharedInheritedHit, unsigned matchedPropertiesToCache, unsigned matchedPropertiesEnteredIntoCache) 1521 unsigned matchedPropertiesSearches, unsigned matchedPropertiesHit, unsigned matchedPropertiesSharedInheritedHit, unsigned matchedPropertiesToCache, unsigned matchedPropertiesEnteredIntoCache)
1514 { 1522 {
1515 double percentOfElementsSharingStyle = (stylesShared * 100.0) / searches; 1523 double percentOfElementsSharingStyle = (stylesShared * 100.0) / searches;
(...skipping 19 matching lines...) Expand all
1535 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che); 1543 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che);
1536 1544
1537 fprintf(stderr, "Total:\n"); 1545 fprintf(stderr, "Total:\n");
1538 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing, 1546 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing,
1539 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache); 1547 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache);
1540 fprintf(stderr, "----------------------------------------------------------- ---------------------\n"); 1548 fprintf(stderr, "----------------------------------------------------------- ---------------------\n");
1541 } 1549 }
1542 #endif 1550 #endif
1543 1551
1544 } // namespace WebCore 1552 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698