Esempio n. 1
0
HSSUnit HSSColorStop::_evaluatePropertyValue(
                                         void(HSSColorStop::*callback)(HSSObservableProperty property, void* data),
                                         HSSParserNode::p value,
                                         HSSUnit percentageBase,
                                         HSSObservableProperty observedSourceProperty,
                                         HSSObservable * &observedStore,
                                         HSSObservableProperty &observedStoreProperty
                                         )
{
    HSSUnit ret;

    HSSParserNodeType nodeType = value->getType();
    switch (nodeType)
    {
    case HSSParserNodeTypeNumberConstant:
    {
        HSSNumberConstant::p numberValue = qSharedPointerCast<HSSNumberConstant > (value);
        ret = numberValue->getValue();
        break;
    }

    case HSSParserNodeTypePercentageConstant:
    {
        HSSPercentageConstant::p percentageValue = qSharedPointerCast<HSSPercentageConstant > (value);
        ret = percentageValue->getValue(percentageBase);
        break;
    }

    case HSSParserNodeTypeExpression:
    {
        HSSExpression::p expressionValue = qSharedPointerCast<HSSExpression > (value);
        expressionValue->setPercentageBase(percentageBase);
        expressionValue->setScope(this->scope);
        expressionValue->setThisObj(this->getThisObj());
        ret = expressionValue->evaluate();
        if (callback)
        {
            expressionValue->observe(HSSObservablePropertyValue, observedSourceProperty, this, new HSSValueChangedCallback<HSSColorStop > (this, callback));
        }

        break;
    }

    case HSSParserNodeTypeKeywordConstant:

        break;

    default:
        AXRWarning("HSSColorStop", "Unknown parser node type while setting value for HSSLineGradient property").raise();
        break;
    }

    return ret;
}
Esempio n. 2
0
long double HSSRgb::_setLDProperty(
                                             void(HSSRgb::*callback)(HSSObservableProperty property, void* data),
                                             HSSParserNode::p         value,
                                             long double              percentageBase,
                                             HSSObservableProperty    observedSourceProperty,
                                             HSSObservable *          &observedStore,
                                             HSSObservableProperty    &observedStoreProperty
                                             )
{
    long double ret;
    
    HSSParserNodeType nodeType = value->getType();
    switch (nodeType) {
        case HSSParserNodeTypeNumberConstant:
        {
            HSSNumberConstant::p numberValue = boost::static_pointer_cast<HSSNumberConstant>(value);
            ret = numberValue->getValue();
            break;
        }
            
        case HSSParserNodeTypePercentageConstant:
        {
            HSSPercentageConstant::p percentageValue = boost::static_pointer_cast<HSSPercentageConstant>(value);
            ret = percentageValue->getValue(percentageBase);
            break;
        }
            
        case HSSParserNodeTypeExpression:
        {
            HSSExpression::p expressionValue = boost::static_pointer_cast<HSSExpression>(value);
            expressionValue->setPercentageBase(percentageBase);
            //expressionValue->setScope(scope);
            ret = expressionValue->evaluate();
            if(callback != NULL){
                expressionValue->observe(HSSObservablePropertyValue, observedSourceProperty, this, new HSSValueChangedCallback<HSSRgb>(this, callback));
                observedStore = expressionValue.get();
                observedStoreProperty = HSSObservablePropertyValue;
            }
            
            break;
        }
            
        case HSSParserNodeTypeKeywordConstant:
            
            break;
            
        default:
            throw AXRError::p(new AXRError("HSSRgb", "Unknown parser node type "+HSSParserNode::parserNodeStringRepresentation(nodeType)+" while setting value for HSSRgb property"));
            break;
    }
    
    return ret;
}
long double HSSDisplayObject::_setLDProperty(
                                             void(HSSDisplayObject::*callback)(HSSObservableProperty property, void* data),
                                             HSSParserNode::p       value,
                                             long double            percentageBase,
                                             HSSObservableProperty  observedProperty,
                                             HSSObservable *        observedObject,
                                             HSSObservable *        &observedStore,
                                             HSSObservableProperty  &observedStoreProperty,
                                             const std::vector<HSSDisplayObject::p> * scope
                                             )
{
    long double ret;
    
    HSSParserNodeType nodeType = value->getType();
    switch (nodeType) {
        case HSSParserNodeTypeNumberConstant:
        {
            HSSNumberConstant::p numberValue = boost::static_pointer_cast<HSSNumberConstant>(value);
            ret = numberValue->getValue();
            break;
        }
            
        case HSSParserNodeTypePercentageConstant:
        {
            HSSPercentageConstant::p percentageValue = boost::static_pointer_cast<HSSPercentageConstant>(value);
            ret = percentageValue->getValue(percentageBase);
            if(callback != NULL)
            {
                observedObject->observe(observedProperty, this, new HSSValueChangedCallback<HSSDisplayObject>(this, callback));
                observedStore = observedObject;
                observedStoreProperty = observedProperty;
            }
            break;
        }
            
        case HSSParserNodeTypeExpression:
        {
            HSSExpression::p expressionValue = boost::static_pointer_cast<HSSExpression>(value);
            expressionValue->setPercentageBase(percentageBase);
            expressionValue->setPercentageObserved(observedProperty, observedObject);
            expressionValue->setScope(scope);
            ret = expressionValue->evaluate();
            if(callback != NULL){
                expressionValue->observe(HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSDisplayObject>(this, callback));
                observedStore = expressionValue.get();
                observedStoreProperty = HSSObservablePropertyValue;
            }
            
            break;
        }
            
        case HSSParserNodeTypeKeywordConstant:
            
            break;
            
        default:
            throw "unknown parser node type while setting dHeight";
            break;
    }
    
    return ret;
}
Esempio n. 4
0
HSSUnit HSSExpression::evaluate()
{
    if (this->isDirty())
    {
        this->setDirty(false);

        //left
        switch (this->getLeft()->getType())
        {
        case HSSParserNodeTypeExpression:
        {
            HSSExpression::p leftExpression = qSharedPointerCast<HSSExpression > (this->getLeft());
            this->leftval = leftExpression->evaluate();
            if (this->leftObserved)
            {
                this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this);
            }
            leftExpression->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged));
            this->leftObserved = leftExpression.data();
            this->leftObservedProperty = HSSObservablePropertyValue;
            break;
        }

        case HSSParserNodeTypeNumberConstant:
        {
            HSSNumberConstant::p leftNumber = qSharedPointerCast<HSSNumberConstant > (this->getLeft());
            this->leftval = leftNumber->getValue();
            break;
        }

        case HSSParserNodeTypePercentageConstant:
        {
            HSSPercentageConstant::p leftPercentage = qSharedPointerCast<HSSPercentageConstant > (this->getLeft());
            this->leftval = leftPercentage->getValue(this->percentageBase);
            if (this->leftObserved)
            {
                this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this);
            }
            this->percentageObserved->observe(this->percentageObservedProperty, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged));
            this->leftObserved = this->percentageObserved;
            this->leftObservedProperty = this->percentageObservedProperty;
            break;
        }

        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p leftFunction = qSharedPointerCast<HSSFunction > (this->getLeft());
            QVariant remoteValue = leftFunction->evaluate();
            if (remoteValue.canConvert<HSSUnit*>())
            {
                this->leftval = *remoteValue.value<HSSUnit*>();
                if (this->leftObserved)
                {
                    this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this);
                }
                leftFunction->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged));
                this->leftObserved = leftFunction.data();
                this->leftObservedProperty = HSSObservablePropertyValue;

            }
            else
            {
                this->rightval = 0.;
            }

            break;
        }

        default:
            std_log1("############ HSSExpression::evaluate() unknwown node type in left member");
            break;
        }


        //right
        switch (this->getRight()->getType())
        {
        case HSSParserNodeTypeExpression:
        {
            HSSExpression::p rightExpression = qSharedPointerCast<HSSExpression > (this->getRight());
            this->rightval = rightExpression->evaluate();
            if (this->rightObserved)
            {
                this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this);
            }
            rightExpression->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged));
            this->rightObserved = rightExpression.data();
            this->rightObservedProperty = HSSObservablePropertyValue;
            break;
        }

        case HSSParserNodeTypeNumberConstant:
        {
            HSSNumberConstant::p rightNumber = qSharedPointerCast<HSSNumberConstant > (this->getRight());
            this->rightval = rightNumber->getValue();
            break;
        }

        case HSSParserNodeTypePercentageConstant:
        {
            HSSPercentageConstant::p rightPercentage = qSharedPointerCast<HSSPercentageConstant > (this->getRight());
            this->rightval = rightPercentage->getValue(this->percentageBase);
            if (this->rightObserved)
            {
                this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this);
            }
            this->percentageObserved->observe(this->percentageObservedProperty, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged));
            this->rightObserved = this->percentageObserved;
            this->rightObservedProperty = this->percentageObservedProperty;
            break;
        }

        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p rightFunction = qSharedPointerCast<HSSFunction > (this->getRight());
            QVariant remoteValue = rightFunction->evaluate();
            if (remoteValue.canConvert<HSSUnit*>())
            {
                this->rightval = *remoteValue.value<HSSUnit*>();
                if (this->rightObserved)
                {
                    this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this);
                }
                rightFunction->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged));
                this->rightObserved = rightFunction.data();
                this->rightObservedProperty = HSSObservablePropertyValue;
            }
            else
            {
                this->rightval = 0.;
            }

            break;
        }

        default:
            std_log1("############ HSSExpression::evaluate() unknwown node type in right member");
            break;
        }

        this->setValue(this->calculate(this->leftval, this->rightval));
    }

    return this->getValue();
}
Esempio n. 5
0
void AXRController::recursiveMatchRulesToDisplayObjects(const HSSRule::p & rule, const std::vector<HSSDisplayObject::p> & scope, HSSContainer::p container, bool applyingInstructions)
{
    HSSInstruction::p instruction = rule->getInstruction();
    if (instruction && applyingInstructions) {
        switch (instruction->getInstructionType()) {
            case HSSNewInstruction:
            {
                std::string elementName = rule->getSelectorChain()->subject()->getElementName();
                unsigned i;
                unsigned argssize = 1;
                HSSParserNode::p argument = instruction->getArgument();
                if(argument){
                    if (argument->isA(HSSParserNodeTypeNumberConstant)) {
                        HSSNumberConstant::p argnum = boost::static_pointer_cast<HSSNumberConstant>(argument);
                        argssize = (int)argnum->getValue();
                    }
                }
                
                for (i=0; i<argssize; i++) {
                    HSSContainer::p newContainer = HSSContainer::p(new HSSContainer());
                    newContainer->setName(elementName);
                    newContainer->setElementName(elementName);;
                    this->add(newContainer);
                    rule->setThisObj(newContainer);
                    newContainer->rulesAdd(rule, (rule->getActiveByDefault() ? HSSRuleStateOn : HSSRuleStateOff ));
                    std_log1("created "+newContainer->getElementName());
                    newContainer->setNeedsRereadRules(true);
                    newContainer->setNeedsSurface(true);
                    newContainer->setDirty(true);
                    unsigned i, size;
                    this->currentContext.push(newContainer);
                    for (i=0, size=rule->childrenSize(); i<size; i++) {
                        const HSSRule::p childRule = rule->childrenGet(i);
                        this->recursiveMatchRulesToDisplayObjects(childRule, newContainer->getChildren(), newContainer, applyingInstructions);
                    }
                    newContainer->setNeedsRereadRules(true);
                    //newContainer->fireEvent(HSSEventTypeLoad);
                    this->currentContext.pop();
                }
                
                break;
            }
                
            case HSSMoveInstruction:
            {
                HSSContainer::p parent = container->getParent();
                if (parent) {
                    std::vector<HSSDisplayObject::p> moveScope = parent->getChildren();
                    this->setSelectorChain(rule->getSelectorChain());
                    std::vector< std::vector<HSSDisplayObject::p> > selection = this->selectHierarchical(moveScope, container);
                    unsigned i, j, k, size, size2, size3;
                    
                    this->currentContext.push(container);
                    //move the children over
                    for (i=0, size=selection.size(); i<size; i++) {
                        std::vector<HSSDisplayObject::p> inner = selection[i];
                        for (j=0, size2=inner.size(); j<size2; j++) {
                            HSSDisplayObject::p theDO = inner[j];
                            if(theDO != container){
                                theDO->removeFromParent();
                                this->add(theDO);
                                rule->setThisObj(theDO);
                                std_log1("moved "+theDO->getElementName());
                                theDO->rulesAdd(rule, (rule->getActiveByDefault() ? HSSRuleStateOn : HSSRuleStateOff ));
                                theDO->setNeedsRereadRules(true);
                                theDO->setNeedsSurface(true);
                                theDO->setDirty(true);
                                
                                if(theDO->isA(HSSObjectTypeContainer)){
                                    HSSContainer::p theContainer = boost::static_pointer_cast<HSSContainer>(theDO);
                                    this->currentContext.push(theContainer);
                                    //assign more rules
                                    for (k=0, size3=rule->childrenSize(); k<size3; k++) {
                                        const HSSRule::p childRule = rule->childrenGet(k);
                                        this->recursiveMatchRulesToDisplayObjects(childRule, theContainer->getChildren(), theContainer, applyingInstructions);
                                    }
                                    this->currentContext.pop();
                                }
                                
                                theDO->setNeedsRereadRules(true);
                                //theDO->fireEvent(HSSEventTypeLoad);
                            }
                            
                        }
                    }
                    this->currentContext.pop();
                }
                
                break;
            }
                
            case HSSDeleteInstruction:
            {
                //select the items to be deleted
                this->setSelectorChain(rule->getSelectorChain());
                std::vector< std::vector<HSSDisplayObject::p> > selection = this->selectHierarchical(scope, container);
                unsigned i, j, size, size2;
                for (i=0, size=selection.size(); i<size; i++) {
                    std::vector<HSSDisplayObject::p> inner = selection[i];
                    for (j=0, size2=inner.size(); j<size2; j++) {
                        inner[j]->removeFromParent();
                    }
                }
                break;
            }
                                
            default:
                break;
        }
        
    } else {
        HSSSelectorChain::p selectorChain = rule->getSelectorChain();
        if(selectorChain){
            this->setSelectorChain(selectorChain);
            
            //if it starts with a combinator, adjust the scope and selector chain
            bool useAdjustedScope = false;
            std::vector<HSSDisplayObject::p> adjustedScope;
            if(this->currentSelectorNode->isA(HSSParserNodeTypeCombinator)){
                useAdjustedScope = true;
                adjustedScope.push_back(container);
                this->currentChain->prepend(HSSSelector::p(new HSSSelector(container->getElementName())));
                this->currentChainSize ++;
                this->currentSelectorNode = this->currentChain->get(0);
            }
            
            //we observe the parent for dom changes
            container->observe(HSSObservablePropertyTreeChange, HSSObservablePropertyValue, rule.get(), new HSSValueChangedCallback<HSSRule>(rule.get(), &HSSRule::treeChanged));
            rule->setObservedTreeChanger(container.get());
            rule->setThisObj(container);
            
            rule->setOriginalScope(scope);
            std::vector< std::vector<HSSDisplayObject::p> > selection = this->selectHierarchical((useAdjustedScope ? adjustedScope : scope), container);
            unsigned i, j, k, size, size2, size3;
            for (i=0, size=selection.size(); i<size; i++) {
                std::vector<HSSDisplayObject::p> inner = selection[i];
                for (j=0, size2=inner.size(); j<size2; j++) {
                    const HSSDisplayObject::p & displayObject = inner[j];
                    std_log1("match "+displayObject->getElementName());
                    displayObject->rulesAdd(rule, (rule->getActiveByDefault() ? HSSRuleStateOn : HSSRuleStateOff ));
                    
                    displayObject->setNeedsRereadRules(true);
                    displayObject->setNeedsSurface(true);
                    displayObject->setDirty(true);
                    
                    //if it is a container it may have children
                    if(displayObject->isA(HSSObjectTypeContainer)){
                        HSSContainer::p selectedContainer = boost::static_pointer_cast<HSSContainer>(displayObject);
                        this->currentContext.push(selectedContainer);
                        for (k=0, size3=rule->childrenSize(); k<size3; k++) {
                            const HSSRule::p childRule = rule->childrenGet(k);
                            this->recursiveMatchRulesToDisplayObjects(childRule, selectedContainer->getChildren(), selectedContainer, applyingInstructions);
                        }
                        this->currentContext.pop();
                    }
                    
                    displayObject->setNeedsRereadRules(true);
                }
            }
        }
    }
}