| Index: Source/core/css/resolver/ViewportStyleResolver.cpp
|
| diff --git a/Source/core/css/resolver/ViewportStyleResolver.cpp b/Source/core/css/resolver/ViewportStyleResolver.cpp
|
| index 539cb0e4ab7199d2cbd6381f475980c8cf988c9e..341a4157212e7088d728e363e8748d159854e67d 100644
|
| --- a/Source/core/css/resolver/ViewportStyleResolver.cpp
|
| +++ b/Source/core/css/resolver/ViewportStyleResolver.cpp
|
| @@ -1,5 +1,5 @@
|
| /*
|
| - * Copyright (C) 2012 Intel Corporation. All rights reserved.
|
| + * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
|
| *
|
| * Redistribution and use in source and binary forms, with or without
|
| * modification, are permitted provided that the following conditions
|
| @@ -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
|
| +{
|
| + if (!m_propertySet)
|
| + return false;
|
| +
|
| + RefPtr<CSSValue> value;
|
| +
|
| + // Check is zoomable.
|
| + if (!getViewportArgumentValue(CSSPropertyUserZoom))
|
| + return true;
|
| +
|
| + float minZoom = getViewportArgumentValue(CSSPropertyMinZoom);
|
| + float maxZoom = getViewportArgumentValue(CSSPropertyMaxZoom);
|
| + if (minZoom == maxZoom && minZoom == ViewportArguments::ValueAuto)
|
| + 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());
|
| + // 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,30 @@ void ViewportStyleResolver::resolve()
|
| arguments.maxHeight = getViewportArgumentValue(CSSPropertyMaxHeight);
|
| arguments.orientation = getViewportArgumentValue(CSSPropertyOrientation);
|
|
|
| + // Deprecated values:
|
| + arguments.deprecatedTargetDensityDPI = getViewportArgumentValue(CSSPropertyInternalTargetDensity);
|
| +
|
| m_document->setViewportArguments(arguments);
|
| m_document->updateViewportArguments();
|
| +}
|
| +
|
| +bool ViewportStyleResolver::affectedByViewportChange() const
|
| +{
|
| + if (!m_propertySet)
|
| + return false;
|
| +
|
| + CSSPropertyID ids[] = { CSSPropertyMaxHeight, CSSPropertyMinHeight, CSSPropertyMaxWidth, CSSPropertyMinWidth };
|
| +
|
| + for (size_t i = 0; i < ARRAY_SIZE(ids); ++i) {
|
| + RefPtr<CSSValue> value = m_propertySet->getPropertyCSSValue(ids[i]);
|
| + if (!value || !value->isPrimitiveValue())
|
| + continue;
|
| + CSSPrimitiveValue* primValue = toCSSPrimitiveValue(value.get());
|
| + if (primValue->isPercentage())
|
| + return true;
|
| + }
|
|
|
| - m_propertySet = 0;
|
| + return false;
|
| }
|
|
|
| float ViewportStyleResolver::getViewportArgumentValue(CSSPropertyID id) const
|
| @@ -146,6 +210,16 @@ float ViewportStyleResolver::getViewportArgumentValue(CSSPropertyID id) const
|
| return ViewportArguments::ValuePortrait;
|
| case CSSValueZoom:
|
| return defaultValue;
|
| + case CSSValueExtendToZoom:
|
| + 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:
|
|
|