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

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: Land patch upload resulted in python error 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 | 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 27 matching lines...) Expand all
38 #include "core/css/CSSDefaultStyleSheets.h" 38 #include "core/css/CSSDefaultStyleSheets.h"
39 #include "core/css/CSSFontSelector.h" 39 #include "core/css/CSSFontSelector.h"
40 #include "core/css/CSSKeyframeRule.h" 40 #include "core/css/CSSKeyframeRule.h"
41 #include "core/css/CSSKeyframesRule.h" 41 #include "core/css/CSSKeyframesRule.h"
42 #include "core/css/CSSParser.h" 42 #include "core/css/CSSParser.h"
43 #include "core/css/CSSReflectValue.h" 43 #include "core/css/CSSReflectValue.h"
44 #include "core/css/CSSRuleList.h" 44 #include "core/css/CSSRuleList.h"
45 #include "core/css/CSSSelector.h" 45 #include "core/css/CSSSelector.h"
46 #include "core/css/CSSStyleRule.h" 46 #include "core/css/CSSStyleRule.h"
47 #include "core/css/CSSValueList.h" 47 #include "core/css/CSSValueList.h"
48 #include "core/css/CSSValuePool.h"
48 #include "core/css/CSSVariableValue.h" 49 #include "core/css/CSSVariableValue.h"
49 #include "core/css/ElementRuleCollector.h" 50 #include "core/css/ElementRuleCollector.h"
50 #include "core/css/MediaQueryEvaluator.h" 51 #include "core/css/MediaQueryEvaluator.h"
51 #include "core/css/PageRuleCollector.h" 52 #include "core/css/PageRuleCollector.h"
52 #include "core/css/RuleSet.h" 53 #include "core/css/RuleSet.h"
53 #include "core/css/StylePropertySet.h" 54 #include "core/css/StylePropertySet.h"
54 #include "core/css/StylePropertyShorthand.h" 55 #include "core/css/StylePropertyShorthand.h"
55 #include "core/css/resolver/MatchResult.h" 56 #include "core/css/resolver/MatchResult.h"
56 #include "core/css/resolver/MediaQueryResult.h" 57 #include "core/css/resolver/MediaQueryResult.h"
57 #include "core/css/resolver/SharedStyleFinder.h" 58 #include "core/css/resolver/SharedStyleFinder.h"
58 #include "core/css/resolver/StyleAdjuster.h" 59 #include "core/css/resolver/StyleAdjuster.h"
59 #include "core/css/resolver/StyleBuilder.h" 60 #include "core/css/resolver/StyleBuilder.h"
60 #include "core/css/resolver/ViewportStyleResolver.h" 61 #include "core/css/resolver/ViewportStyleResolver.h"
61 #include "core/dom/DocumentStyleSheetCollection.h" 62 #include "core/dom/DocumentStyleSheetCollection.h"
62 #include "core/dom/NodeRenderStyle.h" 63 #include "core/dom/NodeRenderStyle.h"
63 #include "core/dom/NodeRenderingContext.h" 64 #include "core/dom/NodeRenderingContext.h"
64 #include "core/dom/Text.h" 65 #include "core/dom/Text.h"
65 #include "core/dom/shadow/ShadowRoot.h" 66 #include "core/dom/shadow/ShadowRoot.h"
66 #include "core/html/HTMLIFrameElement.h" 67 #include "core/html/HTMLIFrameElement.h"
67 #include "core/inspector/InspectorInstrumentation.h" 68 #include "core/inspector/InspectorInstrumentation.h"
68 #include "core/page/Frame.h" 69 #include "core/page/Frame.h"
69 #include "core/page/FrameView.h" 70 #include "core/page/FrameView.h"
71 #include "core/page/PageGroup.h"
70 #include "core/rendering/RenderView.h" 72 #include "core/rendering/RenderView.h"
71 #include "core/rendering/style/KeyframeList.h" 73 #include "core/rendering/style/KeyframeList.h"
72 #include "core/rendering/style/StyleCustomFilterProgramCache.h" 74 #include "core/rendering/style/StyleCustomFilterProgramCache.h"
73 #include "core/svg/SVGDocumentExtensions.h" 75 #include "core/svg/SVGDocumentExtensions.h"
74 #include "core/svg/SVGElement.h" 76 #include "core/svg/SVGElement.h"
75 #include "core/svg/SVGFontFaceElement.h" 77 #include "core/svg/SVGFontFaceElement.h"
76 #include "wtf/StdLibExtras.h" 78 #include "wtf/StdLibExtras.h"
77 #include "wtf/Vector.h" 79 #include "wtf/Vector.h"
78 80
79 using namespace std; 81 using namespace std;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 m_medium = adoptPtr(new MediaQueryEvaluator("all")); 127 m_medium = adoptPtr(new MediaQueryEvaluator("all"));
126 128
127 if (root) 129 if (root)
128 m_rootDefaultStyle = styleForElement(root, 0, DisallowStyleSharing, Matc hOnlyUserAgentRules); 130 m_rootDefaultStyle = styleForElement(root, 0, DisallowStyleSharing, Matc hOnlyUserAgentRules);
129 131
130 if (m_rootDefaultStyle && view) 132 if (m_rootDefaultStyle && view)
131 m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType(), view->fra me(), m_rootDefaultStyle.get())); 133 m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType(), view->fra me(), m_rootDefaultStyle.get()));
132 134
133 m_styleTree.clear(); 135 m_styleTree.clear();
134 136
137 if (document->isXHTMLMobileProfile()) {
138 Vector<String> whitelist;
139 whitelist.append(document->url());
140 static const char* sheet = "@viewport{-internal-priority:1;width:auto;he ight:auto;zoom:1;}";
141 document->page()->group().addUserStyleSheet(sheet, KURL(), whitelist, Ve ctor<String>(), InjectInAllFrames, UserStyleAuthorLevel, InjectInExistingDocumen ts);
142 }
143
135 DocumentStyleSheetCollection* styleSheetCollection = document->styleSheetCol lection(); 144 DocumentStyleSheetCollection* styleSheetCollection = document->styleSheetCol lection();
136 m_ruleSets.initUserStyle(styleSheetCollection, *m_medium, *this); 145 m_ruleSets.initUserStyle(styleSheetCollection, *m_medium, *this);
137 146
138 #if ENABLE(SVG_FONTS) 147 #if ENABLE(SVG_FONTS)
139 if (document->svgExtensions()) { 148 if (document->svgExtensions()) {
140 const HashSet<SVGFontFaceElement*>& svgFontFaceElements = document->svgE xtensions()->svgFontFaceElements(); 149 const HashSet<SVGFontFaceElement*>& svgFontFaceElements = document->svgE xtensions()->svgFontFaceElements();
141 HashSet<SVGFontFaceElement*>::const_iterator end = svgFontFaceElements.e nd(); 150 HashSet<SVGFontFaceElement*>::const_iterator end = svgFontFaceElements.e nd();
142 for (HashSet<SVGFontFaceElement*>::const_iterator it = svgFontFaceElemen ts.begin(); it != end; ++it) 151 for (HashSet<SVGFontFaceElement*>::const_iterator it = svgFontFaceElemen ts.begin(); it != end; ++it)
143 fontSelector()->addFontFaceRule((*it)->fontFaceRule()); 152 fontSelector()->addFontFaceRule((*it)->fontFaceRule());
144 } 153 }
145 #endif 154 #endif
146 155
147 // FIXME: Stylesheet candidate nodes are sorted in document order, but scopi ng nodes are not sorted. 156 // FIXME: Stylesheet candidate nodes are sorted in document order, but scopi ng nodes are not sorted.
148 appendAuthorStyleSheets(0, styleSheetCollection->activeAuthorStyleSheets()); 157 appendAuthorStyleSheets(0, styleSheetCollection->activeAuthorStyleSheets());
149 } 158 }
150 159
151 void StyleResolver::appendAuthorStyleSheets(unsigned firstNew, const Vector<RefP tr<CSSStyleSheet> >& styleSheets) 160 void StyleResolver::appendAuthorStyleSheets(unsigned firstNew, const Vector<RefP tr<CSSStyleSheet> >& styleSheets)
152 { 161 {
153 // This handles sheets added to the end of the stylesheet list only. In othe r cases the style resolver 162 // This handles sheets added to the end of the stylesheet list only. In othe r cases the style resolver
154 // needs to be reconstructed. To handle insertions too the rule order number s would need to be updated. 163 // needs to be reconstructed. To handle insertions too the rule order number s would need to be updated.
155 unsigned size = styleSheets.size(); 164 unsigned size = styleSheets.size();
156 for (unsigned i = firstNew; i < size; ++i) { 165 for (unsigned i = firstNew; i < size; ++i) {
157 CSSStyleSheet* cssSheet = styleSheets[i].get(); 166 CSSStyleSheet* cssSheet = styleSheets[i].get();
167
158 ASSERT(!cssSheet->disabled()); 168 ASSERT(!cssSheet->disabled());
159 if (cssSheet->mediaQueries() && !m_medium->eval(cssSheet->mediaQueries() , this)) 169 if (cssSheet->mediaQueries() && !m_medium->eval(cssSheet->mediaQueries() , this))
160 continue; 170 continue;
161 171
162 StyleSheetContents* sheet = cssSheet->contents(); 172 StyleSheetContents* sheet = cssSheet->contents();
163 ScopedStyleResolver* resolver = ensureScopedStyleResolver(ScopedStyleRes olver::scopingNodeFor(cssSheet)); 173 ScopedStyleResolver* resolver = ensureScopedStyleResolver(ScopedStyleRes olver::scopingNodeFor(cssSheet));
164 ASSERT(resolver); 174 ASSERT(resolver);
165 resolver->addRulesFromSheet(sheet, *m_medium, this); 175 resolver->addRulesFromSheet(sheet, *m_medium, this);
166 m_inspectorCSSOMWrappers.collectFromStyleSheetIfNeeded(cssSheet); 176 m_inspectorCSSOMWrappers.collectFromStyleSheetIfNeeded(cssSheet);
167 } 177 }
168 178
169 collectFeatures(); 179 collectFeatures();
170 180
171 if (document()->renderer() && document()->renderer()->style()) 181 if (document()->renderer() && document()->renderer()->style())
172 document()->renderer()->style()->font().update(fontSelector()); 182 document()->renderer()->style()->font().update(fontSelector());
173 183
174 if (RuntimeEnabledFeatures::cssViewportEnabled()) 184 collectViewportRules();
175 collectViewportRules();
176 } 185 }
177 186
178 void StyleResolver::resetAuthorStyle() 187 void StyleResolver::resetAuthorStyle()
179 { 188 {
180 m_styleTree.clear(); 189 m_styleTree.clear();
181 } 190 }
182 191
183 void StyleResolver::resetAuthorStyle(const ContainerNode* scopingNode) 192 void StyleResolver::resetAuthorStyle(const ContainerNode* scopingNode)
184 { 193 {
185 m_styleTree.clear(); 194 m_styleTree.clear();
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources()); 871 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources());
863 872
864 document()->didAccessStyleResolver(); 873 document()->didAccessStyleResolver();
865 874
866 // Now return the style. 875 // Now return the style.
867 return state.takeStyle(); 876 return state.takeStyle();
868 } 877 }
869 878
870 void StyleResolver::collectViewportRules() 879 void StyleResolver::collectViewportRules()
871 { 880 {
872 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled());
873
874 collectViewportRules(CSSDefaultStyleSheets::defaultStyle); 881 collectViewportRules(CSSDefaultStyleSheets::defaultStyle);
875 if (m_ruleSets.userStyle()) 882 if (m_ruleSets.userStyle())
876 collectViewportRules(m_ruleSets.userStyle()); 883 collectViewportRules(m_ruleSets.userStyle());
877 884
885 // OK to collect here for viewport meta etc, only the parser doesn't allow a ddition
886 // of @viewport with the runtime check.
878 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor Document()) 887 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor Document())
879 scopedResolver->collectViewportRulesTo(this); 888 scopedResolver->collectViewportRulesTo(this);
880 889
881 viewportStyleResolver()->resolve(); 890 viewportStyleResolver()->resolve();
882 } 891 }
883 892
884 void StyleResolver::collectViewportRules(RuleSet* rules) 893 void StyleResolver::collectViewportRules(RuleSet* rules)
885 { 894 {
886 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled());
887
888 rules->compactRulesIfNeeded(); 895 rules->compactRulesIfNeeded();
889 896
890 const Vector<StyleRuleViewport*>& viewportRules = rules->viewportRules(); 897 const Vector<StyleRuleViewport*>& viewportRules = rules->viewportRules();
891 for (size_t i = 0; i < viewportRules.size(); ++i) 898 for (size_t i = 0; i < viewportRules.size(); ++i)
892 viewportStyleResolver()->addViewportRule(viewportRules[i]); 899 viewportStyleResolver()->addViewportRule(viewportRules[i]);
893 } 900 }
894 901
895 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() 902 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement()
896 { 903 {
897 StyleResolverState state(0, document(), 0); 904 StyleResolverState state(0, document(), 0);
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 m_viewportDependentMediaQueryResults.append(adoptPtr(new MediaQueryResult(*e xpr, result))); 1423 m_viewportDependentMediaQueryResults.append(adoptPtr(new MediaQueryResult(*e xpr, result)));
1417 } 1424 }
1418 1425
1419 bool StyleResolver::affectedByViewportChange() const 1426 bool StyleResolver::affectedByViewportChange() const
1420 { 1427 {
1421 unsigned s = m_viewportDependentMediaQueryResults.size(); 1428 unsigned s = m_viewportDependentMediaQueryResults.size();
1422 for (unsigned i = 0; i < s; i++) { 1429 for (unsigned i = 0; i < s; i++) {
1423 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio n) != m_viewportDependentMediaQueryResults[i]->m_result) 1430 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio n) != m_viewportDependentMediaQueryResults[i]->m_result)
1424 return true; 1431 return true;
1425 } 1432 }
1426 return false; 1433
1434 return m_viewportStyleResolver->affectedByViewportChange();
1427 } 1435 }
1428 1436
1429 } // namespace WebCore 1437 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698