| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2012 Intel Corporation. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above | |
| 9 * copyright notice, this list of conditions and the following | |
| 10 * disclaimer. | |
| 11 * 2. Redistributions in binary form must reproduce the above | |
| 12 * copyright notice, this list of conditions and the following | |
| 13 * disclaimer in the documentation and/or other materials | |
| 14 * provided with the distribution. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY | |
| 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE | |
| 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | |
| 21 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
| 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | |
| 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 27 * SUCH DAMAGE. | |
| 28 */ | |
| 29 | |
| 30 #include "config.h" | |
| 31 #include "core/css/ViewportStyleResolver.h" | |
| 32 | |
| 33 #if ENABLE(CSS_DEVICE_ADAPTATION) | |
| 34 | |
| 35 #include "CSSValueKeywords.h" | |
| 36 #include "core/css/StylePropertySet.h" | |
| 37 #include "core/css/StyleRule.h" | |
| 38 #include "core/dom/Document.h" | |
| 39 #include "core/dom/ViewportArguments.h" | |
| 40 #include "core/page/Page.h" | |
| 41 #include "core/rendering/RenderView.h" | |
| 42 | |
| 43 namespace WebCore { | |
| 44 | |
| 45 ViewportStyleResolver::ViewportStyleResolver(Document* document) | |
| 46 : m_document(document) | |
| 47 { | |
| 48 ASSERT(m_document); | |
| 49 } | |
| 50 | |
| 51 ViewportStyleResolver::~ViewportStyleResolver() | |
| 52 { | |
| 53 } | |
| 54 | |
| 55 void ViewportStyleResolver::addViewportRule(StyleRuleViewport* viewportRule) | |
| 56 { | |
| 57 StylePropertySet* propertySet = viewportRule->mutableProperties(); | |
| 58 | |
| 59 unsigned propertyCount = propertySet->propertyCount(); | |
| 60 if (!propertyCount) | |
| 61 return; | |
| 62 | |
| 63 if (!m_propertySet) { | |
| 64 m_propertySet = propertySet->copy(); | |
| 65 return; | |
| 66 } | |
| 67 | |
| 68 // We cannot use mergeAndOverrideOnConflict() here because it doesn't | |
| 69 // respect the !important declaration (but addParsedProperty() does). | |
| 70 for (unsigned i = 0; i < propertyCount; ++i) | |
| 71 m_propertySet->addParsedProperty(propertySet->propertyAt(i).toCSSPropert
y()); | |
| 72 } | |
| 73 | |
| 74 void ViewportStyleResolver::clearDocument() | |
| 75 { | |
| 76 m_document = 0; | |
| 77 } | |
| 78 | |
| 79 void ViewportStyleResolver::resolve() | |
| 80 { | |
| 81 if (!m_document || !m_propertySet) | |
| 82 return; | |
| 83 | |
| 84 ViewportArguments arguments(ViewportArguments::CSSDeviceAdaptation); | |
| 85 | |
| 86 arguments.userZoom = getViewportArgumentValue(CSSPropertyUserZoom); | |
| 87 arguments.zoom = getViewportArgumentValue(CSSPropertyZoom); | |
| 88 arguments.minZoom = getViewportArgumentValue(CSSPropertyMinZoom); | |
| 89 arguments.maxZoom = getViewportArgumentValue(CSSPropertyMaxZoom); | |
| 90 arguments.minWidth = getViewportArgumentValue(CSSPropertyMinWidth); | |
| 91 arguments.maxWidth = getViewportArgumentValue(CSSPropertyMaxWidth); | |
| 92 arguments.minHeight = getViewportArgumentValue(CSSPropertyMinHeight); | |
| 93 arguments.maxHeight = getViewportArgumentValue(CSSPropertyMaxHeight); | |
| 94 arguments.orientation = getViewportArgumentValue(CSSPropertyOrientation); | |
| 95 | |
| 96 m_document->setViewportArguments(arguments); | |
| 97 m_document->updateViewportArguments(); | |
| 98 | |
| 99 m_propertySet = 0; | |
| 100 } | |
| 101 | |
| 102 float ViewportStyleResolver::getViewportArgumentValue(CSSPropertyID id) const | |
| 103 { | |
| 104 float defaultValue = ViewportArguments::ValueAuto; | |
| 105 | |
| 106 // UserZoom default value is CSSValueZoom, which maps to true, meaning that | |
| 107 // yes, it is user scalable. When the value is set to CSSValueFixed, we | |
| 108 // return false. | |
| 109 if (id == CSSPropertyUserZoom) | |
| 110 defaultValue = 1; | |
| 111 | |
| 112 RefPtr<CSSValue> value = m_propertySet->getPropertyCSSValue(id); | |
| 113 if (!value || !value->isPrimitiveValue()) | |
| 114 return defaultValue; | |
| 115 | |
| 116 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value.ge
t()); | |
| 117 | |
| 118 if (primitiveValue->isNumber() || primitiveValue->isPx()) | |
| 119 return primitiveValue->getFloatValue(); | |
| 120 | |
| 121 if (primitiveValue->isFontRelativeLength()) | |
| 122 return primitiveValue->getFloatValue() * m_document->documentElement()->
renderStyle()->fontDescription().computedSize(); | |
| 123 | |
| 124 if (primitiveValue->isPercentage()) { | |
| 125 float percentValue = primitiveValue->getFloatValue() / 100.0f; | |
| 126 switch (id) { | |
| 127 case CSSPropertyMaxHeight: | |
| 128 case CSSPropertyMinHeight: | |
| 129 ASSERT(m_document->initialViewportSize().height() > 0); | |
| 130 return percentValue * m_document->initialViewportSize().height(); | |
| 131 case CSSPropertyMaxWidth: | |
| 132 case CSSPropertyMinWidth: | |
| 133 ASSERT(m_document->initialViewportSize().width() > 0); | |
| 134 return percentValue * m_document->initialViewportSize().width(); | |
| 135 case CSSPropertyMaxZoom: | |
| 136 case CSSPropertyMinZoom: | |
| 137 case CSSPropertyZoom: | |
| 138 return percentValue; | |
| 139 default: | |
| 140 ASSERT_NOT_REACHED(); | |
| 141 break; | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 switch (primitiveValue->getIdent()) { | |
| 146 case CSSValueAuto: | |
| 147 return defaultValue; | |
| 148 case CSSValueDeviceHeight: | |
| 149 return ViewportArguments::ValueDeviceHeight; | |
| 150 case CSSValueDeviceWidth: | |
| 151 return ViewportArguments::ValueDeviceWidth; | |
| 152 case CSSValueLandscape: | |
| 153 return ViewportArguments::ValueLandscape; | |
| 154 case CSSValuePortrait: | |
| 155 return ViewportArguments::ValuePortrait; | |
| 156 case CSSValueZoom: | |
| 157 return defaultValue; | |
| 158 case CSSValueFixed: | |
| 159 return 0; | |
| 160 default: | |
| 161 return defaultValue; | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 } // namespace WebCore | |
| 166 | |
| 167 #endif // ENABLE(CSS_DEVICE_ADAPTATION) | |
| OLD | NEW |