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

Side by Side Diff: Source/core/css/resolver/ViewportStyleResolver.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) 2012-2013 Intel Corporation. All rights reserved. 2 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 18 matching lines...) Expand all
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "core/css/resolver/ViewportStyleResolver.h" 31 #include "core/css/resolver/ViewportStyleResolver.h"
32 32
33 #include "CSSValueKeywords.h" 33 #include "CSSValueKeywords.h"
34 #include "core/css/StylePropertySet.h" 34 #include "core/css/StylePropertySet.h"
35 #include "core/css/StyleRule.h" 35 #include "core/css/StyleRule.h"
36 #include "core/dom/Document.h" 36 #include "core/dom/Document.h"
37 #include "core/dom/NodeRenderStyle.h" 37 #include "core/dom/NodeRenderStyle.h"
38 #include "core/dom/ViewportArguments.h" 38 #include "core/dom/ViewportArguments.h"
39 #include "wtf/dtoa/utils.h"
39 40
40 namespace WebCore { 41 namespace WebCore {
41 42
42 ViewportStyleResolver::ViewportStyleResolver(Document* document) 43 ViewportStyleResolver::ViewportStyleResolver(Document* document)
43 : m_document(document) 44 : m_document(document)
45 , m_maxPriority(0)
44 { 46 {
45 ASSERT(m_document); 47 ASSERT(m_document);
46 } 48 }
47 49
48 ViewportStyleResolver::~ViewportStyleResolver() 50 ViewportStyleResolver::~ViewportStyleResolver()
49 { 51 {
50 } 52 }
51 53
52 void ViewportStyleResolver::addViewportRule(StyleRuleViewport* viewportRule) 54 void ViewportStyleResolver::addViewportRule(StyleRuleViewport* viewportRule)
53 { 55 {
54 StylePropertySet* propertySet = viewportRule->mutableProperties(); 56 StylePropertySet* propertySet = viewportRule->mutableProperties();
55 57
56 unsigned propertyCount = propertySet->propertyCount(); 58 unsigned propertyCount = propertySet->propertyCount();
57 if (!propertyCount) 59 if (!propertyCount)
58 return; 60 return;
59 61
60 if (!m_propertySet) { 62 // Rules derived from legacy meta tags are only applied if no author @viewpo rt rule
63 // precedes it, with the exception of viewport meta which is considered an a ctual
64 // @viewport rule according to the spec. They also have individual priority as defined
65 // below.
66 //
67 // 1) UA stylesheet is always applied first (min priority)
68 // 2) XHTML Mobile Profile (priority 1)
69 // 3) handheldfriendly meta tag (priority 2)
70 // 4) mobileoptimized meta tag (priority 3)
71 // 5) viewport meta tag and any author style sheet (max priority).
72
73 RefPtr<CSSValue> value = propertySet->getPropertyCSSValue(CSSPropertyInterna lPriority);
74 float priority = (value && value->isPrimitiveValue()) ? toCSSPrimitiveValue( value.get())->getFloatValue() : std::numeric_limits<float>::max();
75
76 if (priority < m_maxPriority)
77 return;
78 m_maxPriority = priority;
79
80 if (m_propertySet) {
81 // We cannot use mergeAndOverrideOnConflict() here because it doesn't
82 // respect the !important declaration (but addParsedProperty() does).
83 for (unsigned i = 0; i < propertyCount; ++i)
84 m_propertySet->addParsedProperty(propertySet->propertyAt(i).toCSSPro perty());
85 } else {
61 m_propertySet = propertySet->mutableCopy(); 86 m_propertySet = propertySet->mutableCopy();
62 return;
63 } 87 }
88 }
64 89
65 // We cannot use mergeAndOverrideOnConflict() here because it doesn't 90 bool ViewportStyleResolver::shouldDisableDesktopWorkarounds() const
rune 2013/08/28 23:30:14 I have tried to split this out as a separate chang
66 // respect the !important declaration (but addParsedProperty() does). 91 {
67 for (unsigned i = 0; i < propertyCount; ++i) 92 if (!m_propertySet)
68 m_propertySet->addParsedProperty(propertySet->propertyAt(i).toCSSPropert y()); 93 return false;
94
95 RefPtr<CSSValue> value;
96
97 // Check is zoomable.
98 if (!getViewportArgumentValue(CSSPropertyUserZoom))
99 return true;
100
101 float minZoom = getViewportArgumentValue(CSSPropertyMinZoom);
102 float maxZoom = getViewportArgumentValue(CSSPropertyMaxZoom);
103 if (minZoom == maxZoom && minZoom == ViewportArguments::ValueAuto)
rune 2013/08/28 23:30:14 Should have been "minZoom != ViewportArguments::Va
104 return true;
105
106 // Check whether 100% of viewport (device-width etc.)
107 value = m_propertySet->getPropertyCSSValue(CSSPropertyMaxWidth);
108 if (!value || !value->isPrimitiveValue())
109 return false;
110
111 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get());
112 return primitiveValue->isPercentage() && primitiveValue->getFloatValue() == 100.0f;
69 } 113 }
70 114
71 void ViewportStyleResolver::clearDocument() 115 void ViewportStyleResolver::clearDocument()
72 { 116 {
73 m_document = 0; 117 m_document = 0;
74 } 118 }
75 119
76 void ViewportStyleResolver::resolve() 120 void ViewportStyleResolver::resolve()
77 { 121 {
78 if (!m_document || !m_propertySet) 122 if (!m_document || !m_propertySet)
79 return; 123 return;
80 124
81 ViewportArguments arguments(ViewportArguments::CSSDeviceAdaptation); 125 ViewportArguments arguments;
82 126
83 arguments.userZoom = getViewportArgumentValue(CSSPropertyUserZoom); 127 arguments.userZoom = getViewportArgumentValue(CSSPropertyUserZoom);
84 arguments.zoom = getViewportArgumentValue(CSSPropertyZoom); 128 arguments.zoom = getViewportArgumentValue(CSSPropertyZoom);
85 arguments.minZoom = getViewportArgumentValue(CSSPropertyMinZoom); 129 arguments.minZoom = getViewportArgumentValue(CSSPropertyMinZoom);
86 arguments.maxZoom = getViewportArgumentValue(CSSPropertyMaxZoom); 130 arguments.maxZoom = getViewportArgumentValue(CSSPropertyMaxZoom);
87 arguments.minWidth = getViewportArgumentValue(CSSPropertyMinWidth); 131 arguments.minWidth = getViewportArgumentValue(CSSPropertyMinWidth);
88 arguments.maxWidth = getViewportArgumentValue(CSSPropertyMaxWidth); 132 arguments.maxWidth = getViewportArgumentValue(CSSPropertyMaxWidth);
89 arguments.minHeight = getViewportArgumentValue(CSSPropertyMinHeight); 133 arguments.minHeight = getViewportArgumentValue(CSSPropertyMinHeight);
90 arguments.maxHeight = getViewportArgumentValue(CSSPropertyMaxHeight); 134 arguments.maxHeight = getViewportArgumentValue(CSSPropertyMaxHeight);
91 arguments.orientation = getViewportArgumentValue(CSSPropertyOrientation); 135 arguments.orientation = getViewportArgumentValue(CSSPropertyOrientation);
92 136
137 // Deprecated values:
138 arguments.deprecatedTargetDensityDPI = getViewportArgumentValue(CSSPropertyI nternalTargetDensity);
139
93 m_document->setViewportArguments(arguments); 140 m_document->setViewportArguments(arguments);
94 m_document->updateViewportArguments(); 141 m_document->updateViewportArguments();
95
96 m_propertySet = 0;
rune 2013/08/21 09:18:22 I can't see where the property set is reset betwee
97 } 142 }
98 143
99 float ViewportStyleResolver::getViewportArgumentValue(CSSPropertyID id) const 144 float ViewportStyleResolver::getViewportArgumentValue(CSSPropertyID id) const
100 { 145 {
101 float defaultValue = ViewportArguments::ValueAuto; 146 float defaultValue = ViewportArguments::ValueAuto;
102 147
103 // UserZoom default value is CSSValueZoom, which maps to true, meaning that 148 // UserZoom default value is CSSValueZoom, which maps to true, meaning that
104 // yes, it is user scalable. When the value is set to CSSValueFixed, we 149 // yes, it is user scalable. When the value is set to CSSValueFixed, we
105 // return false. 150 // return false.
106 if (id == CSSPropertyUserZoom) 151 if (id == CSSPropertyUserZoom)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 case CSSValueAuto: 186 case CSSValueAuto:
142 return defaultValue; 187 return defaultValue;
143 case CSSValueLandscape: 188 case CSSValueLandscape:
144 return ViewportArguments::ValueLandscape; 189 return ViewportArguments::ValueLandscape;
145 case CSSValuePortrait: 190 case CSSValuePortrait:
146 return ViewportArguments::ValuePortrait; 191 return ViewportArguments::ValuePortrait;
147 case CSSValueZoom: 192 case CSSValueZoom:
148 return defaultValue; 193 return defaultValue;
149 case CSSValueInternalExtendToZoom: 194 case CSSValueInternalExtendToZoom:
150 return ViewportArguments::ValueExtendToZoom; 195 return ViewportArguments::ValueExtendToZoom;
196 case CSSValueDevice:
197 return ViewportArguments::ValueDeviceDPI;
198 case CSSValueSmall:
199 return ViewportArguments::ValueLowDPI;
200 case CSSValueMedium:
201 return ViewportArguments::ValueMediumDPI;
202 case CSSValueLarge:
203 return ViewportArguments::ValueHighDPI;
151 case CSSValueFixed: 204 case CSSValueFixed:
152 return 0; 205 return 0;
153 default: 206 default:
154 return defaultValue; 207 return defaultValue;
155 } 208 }
156 } 209 }
157 210
158 } // namespace WebCore 211 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698