--- a/src/hbcore/cssparser/hbcssparser_p.cpp Thu Sep 02 20:44:51 2010 +0300
+++ b/src/hbcore/cssparser/hbcssparser_p.cpp Fri Sep 17 08:32:10 2010 +0300
@@ -44,6 +44,7 @@
#include "hblayeredstyleloader_p.h"
#include "hbthemeindex_p.h"
#include "hblayoutparameters_p.h"
+#include "hbhash_p.h"
using namespace HbCss;
@@ -181,38 +182,16 @@
#ifndef HB_BIN_CSS
///////////////////////////////////////////////////////////////////////////////
// Value Extractor
-ValueExtractor::ValueExtractor(const HbVector<Declaration> &decls, const HbDeviceProfile &profile)
-: declarations(decls), layoutParameters(0), currentProfile(profile)
-{
-}
ValueExtractor::ValueExtractor(
- const HbVector<Declaration> &decls,
- const HbLayoutParameters &layoutParameters,
+ const HbVector<Declaration> &decls,
const HbDeviceProfile &profile)
-: declarations(decls), layoutParameters(&layoutParameters), currentProfile(profile)
+: declarations(decls), layoutParameters(0), variables(0), currentProfile(profile)
{
}
-ValueExtractor::ValueExtractor(
- const HbVector<Declaration> &varDecls,
- bool isVariable,
- const HbDeviceProfile &profile)
-: variableDeclarations(varDecls), layoutParameters(0), currentProfile(profile)
+ValueExtractor::ValueExtractor( const HbDeviceProfile &profile)
+: layoutParameters(0), variables(0), currentProfile(profile)
{
- Q_UNUSED(isVariable)
- // Initialize to some profile.
- if ( currentProfile.isNull() ) {
- currentProfile = HbDeviceProfile::current();
- }
-}
-
-ValueExtractor::ValueExtractor(
- const HbLayoutParameters &layoutParameters,
- bool isVariable,
- const HbDeviceProfile &profile)
-: layoutParameters(&layoutParameters), currentProfile(profile)
-{
- Q_UNUSED(isVariable)
// Initialize to some profile.
if ( currentProfile.isNull() ) {
currentProfile = HbDeviceProfile::current();
@@ -235,6 +214,14 @@
return v.variant.toDouble() / 100.0;
} else if (v.type == Value::Number) {
return v.variant.toDouble();
+ } else if (v.type == Value::Variable || v.type == Value::VariableNegative) {
+ qreal factor = (v.type == Value::Variable) ? 1.0 : -1.0;
+ qreal variableValue(0.0);
+ bool tempOk = extractVariableValue((quint32)v.variant.toInt(), variableValue);
+ if (ok) {
+ *ok = tempOk;
+ }
+ return factor * variableValue;
}
QString s = v.variant.toString();
@@ -797,50 +784,45 @@
: QColor::fromHsv(v1, v2, v3, alpha);
}
-bool ValueExtractor::extractVariableValue(const QString& variableName, qreal& realValue)
+bool ValueExtractor::extractVariableValue(quint32 hashValue, HbCss::Value &value) const
{
bool variableFound = false;
- HbCss::Value value;
- if (extractVariableValue(variableName, value)) {
- realValue = asReal(value);
+ if (layoutParameters && !layoutParameters->isEmpty()) {
+ HbLayoutParameters::const_iterator i = layoutParameters->find(hashValue);
+ if (i != layoutParameters->end()) {
+ value = layoutParameters->value(i);
+ variableFound = true;
+ }
+ } else if (variables && !variables->isEmpty()) {
+ QHash<quint32, HbCss::Declaration>::const_iterator f = variables->find(hashValue);
+ if (f != variables->end() && !f.value().values.isEmpty()) {
+ value = f.value().values.first();
+ variableFound = true;
+ }
+ }
+ return variableFound;
+}
+
+
+bool ValueExtractor::extractVariableValue(quint32 hashValue, qreal& value)
+{
+ bool variableFound = false;
+ HbCss::Value v;
+ if (extractVariableValue(hashValue, v)) {
+ value = asReal(v);
variableFound = true;
}
return variableFound;
}
-bool ValueExtractor::extractVariableValue( const QString& variableName, HbCss::Value &val ) const
+bool ValueExtractor::extractVariableValue(const QString& variableName, HbCss::Value &value) const
{
- bool variableFound = false;
- if (layoutParameters && !layoutParameters->isEmpty()) {
- HbLayoutParameters::const_iterator i = layoutParameters->find(variableName);
- if (i != layoutParameters->end()) {
- val = layoutParameters->value(i);
- variableFound = true;
- }
- } else if (!variableDeclarationsHash.isEmpty()) {
- QHash<QString, HbCss::Declaration>::const_iterator f = variableDeclarationsHash.find(variableName);
- if (f != variableDeclarationsHash.end() && !f.value().values.isEmpty()) {
- val = f.value().values.first();
- variableFound = true;
- }
- } else {
- const int variableCount = variableDeclarations.count();
- for (int i=variableCount-1; i>=0; i--) {
- if (variableDeclarations.at(i).property == variableName ) {
- val = variableDeclarations.at(i).values.first();
- variableFound = true;
- break;
- }
- }
- }
+ return extractVariableValue(hbHash(variableName), value);
+}
- //for variable cascading support
- if ( variableFound ) {
- if ( val.type == Value::Variable ){
- variableFound = extractVariableValue(val.variant.toString(), val);
- }
- }
- return variableFound;
+bool ValueExtractor::extractVariableValue(const QString& variableName, qreal& value)
+{
+ return extractVariableValue(hbHash(variableName), value);
}
bool ValueExtractor::extractExpressionValue(QString &expression, qreal &value)
@@ -1136,14 +1118,14 @@
{
HbCss::Value value;
if ( decl.values.at(0).type == Value::Variable ) {
- const QString variableName = decl.values.at(0).variant.toString();
- HbThemeIndexResource resource(variableName);
+ quint32 hashValue = (quint32)decl.values.at(0).variant.toInt();
+ HbThemeIndexResource resource(hashValue);
if (resource.isValid()) {
// Color value coming from index
color = resource.colorValue();
} else {
// Color value coming from custom css
- extractVariableValue( variableName, value );
+ extractVariableValue( hashValue, value );
color = parseColorValue(value);
}
} else {
@@ -1561,7 +1543,7 @@
return decls;
}
-void StyleSelector::variableRuleSets(QHash<QString, HbCss::Declaration> *variables) const
+void StyleSelector::variableRuleSets(QHash<quint32, HbCss::Declaration> *variables) const
{
HbVector<Declaration> decls;
const int styleSheetsCount = styleSheets.count();
@@ -1572,7 +1554,7 @@
decls = styleSheet->variableRules.at(j).declarations;
const int declsCount = decls.count();
for (int k=0; k<declsCount; k++) {
- variables->insert(decls.at(k).property, decls.at(k));
+ variables->insert(hbHash(decls.at(k).property), decls.at(k));
}
}
}
@@ -2404,10 +2386,10 @@
//changes for variable support
else if (name == QLatin1String("var")) {
value->type = Value::Variable;
- value->variant = args;
+ value->variant = (int)hbHash( args );
} else if (name == QLatin1String("-var")) {
value->type = Value::VariableNegative;
- value->variant = args;
+ value->variant = (int)hbHash( args );
} //change end
//changes for expression support
else if (name == QLatin1String("expr")) {