Index: Source/core/css/resolver/ViewportStyleResolver.cpp |
diff --git a/Source/core/css/resolver/ViewportStyleResolver.cpp b/Source/core/css/resolver/ViewportStyleResolver.cpp |
index 4480d7f47ed72473c1df70a02e517c538613d8a5..63775d31b5ef5df0c0232d6be7d0c000fb697006 100644 |
--- a/Source/core/css/resolver/ViewportStyleResolver.cpp |
+++ b/Source/core/css/resolver/ViewportStyleResolver.cpp |
@@ -36,11 +36,13 @@ |
#include "core/dom/Document.h" |
#include "core/dom/NodeRenderStyle.h" |
#include "core/dom/ViewportArguments.h" |
+#include "wtf/dtoa/utils.h" |
namespace WebCore { |
ViewportStyleResolver::ViewportStyleResolver(Document* document) |
: m_document(document) |
+ , m_maxPriority(0) |
{ |
ASSERT(m_document); |
} |
@@ -57,15 +59,57 @@ void ViewportStyleResolver::addViewportRule(StyleRuleViewport* viewportRule) |
if (!propertyCount) |
return; |
- if (!m_propertySet) { |
- m_propertySet = propertySet->mutableCopy(); |
+ // Rules derived from legacy meta tags are only applied if no author @viewport rule |
+ // precedes it, with the exception of viewport meta which is considered an actual |
+ // @viewport rule according to the spec. They also have individual priority as defined |
+ // below. |
+ // |
+ // 1) UA stylesheet is always applied first (min priority) |
+ // 2) XHTML Mobile Profile (priority 1) |
+ // 3) handheldfriendly meta tag (priority 2) |
+ // 4) mobileoptimized meta tag (priority 3) |
+ // 5) viewport meta tag and any author style sheet (max priority). |
+ |
+ RefPtr<CSSValue> value = propertySet->getPropertyCSSValue(CSSPropertyInternalPriority); |
+ float priority = (value && value->isPrimitiveValue()) ? toCSSPrimitiveValue(value.get())->getFloatValue() : std::numeric_limits<float>::max(); |
+ |
+ if (priority < m_maxPriority) |
return; |
+ m_maxPriority = priority; |
+ |
+ if (m_propertySet) { |
+ // We cannot use mergeAndOverrideOnConflict() here because it doesn't |
+ // respect the !important declaration (but addParsedProperty() does). |
+ for (unsigned i = 0; i < propertyCount; ++i) |
+ m_propertySet->addParsedProperty(propertySet->propertyAt(i).toCSSProperty()); |
+ } else { |
+ m_propertySet = propertySet->mutableCopy(); |
} |
+} |
+ |
+bool ViewportStyleResolver::shouldDisableDesktopWorkarounds() const |
rune
2013/08/28 23:30:14
I have tried to split this out as a separate chang
|
+{ |
+ if (!m_propertySet) |
+ return false; |
+ |
+ RefPtr<CSSValue> value; |
+ |
+ // Check is zoomable. |
+ if (!getViewportArgumentValue(CSSPropertyUserZoom)) |
+ return true; |
- // We cannot use mergeAndOverrideOnConflict() here because it doesn't |
- // respect the !important declaration (but addParsedProperty() does). |
- for (unsigned i = 0; i < propertyCount; ++i) |
- m_propertySet->addParsedProperty(propertySet->propertyAt(i).toCSSProperty()); |
+ float minZoom = getViewportArgumentValue(CSSPropertyMinZoom); |
+ float maxZoom = getViewportArgumentValue(CSSPropertyMaxZoom); |
+ if (minZoom == maxZoom && minZoom == ViewportArguments::ValueAuto) |
rune
2013/08/28 23:30:14
Should have been "minZoom != ViewportArguments::Va
|
+ return true; |
+ |
+ // Check whether 100% of viewport (device-width etc.) |
+ value = m_propertySet->getPropertyCSSValue(CSSPropertyMaxWidth); |
+ if (!value || !value->isPrimitiveValue()) |
+ return false; |
+ |
+ CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get()); |
+ return primitiveValue->isPercentage() && primitiveValue->getFloatValue() == 100.0f; |
} |
void ViewportStyleResolver::clearDocument() |
@@ -78,7 +122,7 @@ void ViewportStyleResolver::resolve() |
if (!m_document || !m_propertySet) |
return; |
- ViewportArguments arguments(ViewportArguments::CSSDeviceAdaptation); |
+ ViewportArguments arguments; |
arguments.userZoom = getViewportArgumentValue(CSSPropertyUserZoom); |
arguments.zoom = getViewportArgumentValue(CSSPropertyZoom); |
@@ -90,10 +134,11 @@ void ViewportStyleResolver::resolve() |
arguments.maxHeight = getViewportArgumentValue(CSSPropertyMaxHeight); |
arguments.orientation = getViewportArgumentValue(CSSPropertyOrientation); |
+ // Deprecated values: |
+ arguments.deprecatedTargetDensityDPI = getViewportArgumentValue(CSSPropertyInternalTargetDensity); |
+ |
m_document->setViewportArguments(arguments); |
m_document->updateViewportArguments(); |
- |
- m_propertySet = 0; |
rune
2013/08/21 09:18:22
I can't see where the property set is reset betwee
|
} |
float ViewportStyleResolver::getViewportArgumentValue(CSSPropertyID id) const |
@@ -148,6 +193,14 @@ float ViewportStyleResolver::getViewportArgumentValue(CSSPropertyID id) const |
return defaultValue; |
case CSSValueInternalExtendToZoom: |
return ViewportArguments::ValueExtendToZoom; |
+ case CSSValueDevice: |
+ return ViewportArguments::ValueDeviceDPI; |
+ case CSSValueSmall: |
+ return ViewportArguments::ValueLowDPI; |
+ case CSSValueMedium: |
+ return ViewportArguments::ValueMediumDPI; |
+ case CSSValueLarge: |
+ return ViewportArguments::ValueHighDPI; |
case CSSValueFixed: |
return 0; |
default: |