示例#1
0
void HSSRequest::setDTarget(HSSParserNode::p value)
{
    switch (value->getType())
    {
    case HSSParserNodeTypeKeywordConstant:
    case HSSParserNodeTypeFunctionCall:
    {
        this->dTarget = value;
        if (this->observedTarget)
        {
            this->observedTarget->removeObserver(this->observedTargetProperty, HSSObservablePropertyTarget, this);
        }

        switch (value->getType())
        {
        case HSSParserNodeTypeKeywordConstant:
            /**
             *  @todo what here?
             */
            break;

        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p fnct = qSharedPointerCast<HSSFunction > (value)->clone();
            if (fnct)
            {
                fnct->setScope(this->scope);
                fnct->setThisObj(this->getThisObj());
                QVariant remoteValue = fnct->evaluate();
                if (remoteValue.canConvert< HSSSelection::p >())
                {
                    HSSSimpleSelection::p selection = remoteValue.value< HSSSelection::p >()->joinAll();
                    this->target->clear();
                    this->target->insert(this->target->end(), selection->begin(), selection->end());
                }

                /**
                 *  @todo potentially leaking
                 */
                fnct->observe(HSSObservablePropertyValue, HSSObservablePropertyTarget, this, new HSSValueChangedCallback<HSSRequest > (this, &HSSRequest::targetChanged));
                this->observedTarget = fnct.data();
                this->observedTargetProperty = HSSObservablePropertyValue;
            }

            break;
        }

        default:
            break;
        }

        this->notifyObservers(HSSObservablePropertySrc, &this->src);

        break;
    }

    default:
        throw AXRWarning("HSSRequest", "Invalid value for src of " + this->name);
    }
}
示例#2
0
void HSSSelectorChain::add(HSSParserNode::p newNode)
{
    if (newNode)
    {
        std_log3("HSSSelectorChain: Added node of type " + newNode->toString());
        newNode->setParentNode(this->shared_from_this());
        this->nodeList.push_back(newNode);
    }
}
示例#3
0
void HSSSelectorChain::prepend(HSSParserNode::p newNode)
{
    if (newNode)
    {
        std_log3("HSSSelectorChain: Added node of type " + newNode->toString() + " to the front of the selector");
        newNode->setParentNode(this->shared_from_this());
        this->nodeList.push_front(newNode);
    }
}
示例#4
0
void HSSRequest::setDSrc(HSSParserNode::p value)
{
    switch (value->getType())
    {
    case HSSParserNodeTypeKeywordConstant:
    case HSSParserNodeTypeFunctionCall:
    case HSSParserNodeTypeStringConstant:
    {
        this->dSrc = value;
        if (this->observedSrc)
        {
            this->observedSrc->removeObserver(this->observedSrcProperty, HSSObservablePropertySrc, this);
        }

        switch (value->getType())
        {
        case HSSParserNodeTypeKeywordConstant:
            /**
             *  @todo what here?
             */
            break;

        case HSSParserNodeTypeStringConstant:
        {
            HSSStringConstant::p theString = qSharedPointerCast<HSSStringConstant > (value);
            this->src = QUrl(theString->getValue());
            break;
        }

        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p fnct = qSharedPointerCast<HSSFunction > (value)->clone();
            fnct->setScope(this->scope);
            fnct->setThisObj(this->getThisObj());
            QVariant remoteValue = fnct->evaluate();
            if (remoteValue.canConvert<AXRString>())
            {
                this->src = QUrl(remoteValue.value<AXRString>());
            }

            break;
        }

        default:
            break;
        }

        this->notifyObservers(HSSObservablePropertySrc, &this->src);

        break;
    }

    default:
        throw AXRWarning("HSSRequest", "Invalid value for src of " + this->name);
    }
}
AXRString HSSMultipleValueDefinition::toString()
{
    AXRString tempstr = AXRString("HSSMultipleValueDefinition with the following values:\n");

    for (std::vector<HSSParserNode::p>::iterator it = this->values.begin(); it != this->values.end(); ++it)
    {
        HSSParserNode::p value = *it;
        tempstr.append(value->toString().append("\n"));
    }

    return tempstr;
}
示例#6
0
void HSSMultipleValue::add(HSSParserNode::p newValue)
{
    if (newValue)
    {
        std_log3("Added value to HSSMultipleValue: " + newValue->toString());
        this->valueList.push_back(newValue);
    }
}
void HSSPropertyDefinition::addValue(HSSParserNode::p value)
{
    if (this->value){
        if(this->value->isA(HSSParserNodeTypeMultipleValueDefinition)) {
            HSSMultipleValueDefinition::p mvDef = boost::static_pointer_cast<HSSMultipleValueDefinition>(this->value);
            value->setParentNode(this->shared_from_this());
            mvDef->add(value);
        } else {
            HSSMultipleValueDefinition::p mvDef = HSSMultipleValueDefinition::p(new HSSMultipleValueDefinition());
            mvDef->setParentNode(this->shared_from_this());
            mvDef->add(this->value);
            value->setParentNode(this->shared_from_this());
            mvDef->add(value);
            this->value = mvDef;
        }
    } else {
        this->value = value;
    }
}
示例#8
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;
}
示例#9
0
void HSSFunction::setScope(HSSSimpleSelection::p newScope)
{
    this->scope = newScope;
    std::deque<HSSParserNode::p>::const_iterator it;
    for (it = this->_arguments.begin(); it != this->_arguments.end(); ++it)
    {
        const HSSParserNode::p node = (*it);
        switch (node->getType())
        {
        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p func = qSharedPointerCast<HSSFunction > (node);
            func->setScope(newScope);
            break;
        }

        case HSSParserNodeTypeExpression:
        {
            HSSExpression::p exp = qSharedPointerCast<HSSExpression > (node);
            exp->setScope(newScope);
            break;
        }

        default:
            break;
        }

        switch (node->getStatementType())
        {
        case HSSStatementTypeObjectDefinition:
        {
            HSSObjectDefinition::p objdef = qSharedPointerCast<HSSObjectDefinition > (node);
            objdef->setScope(newScope);
            break;
        }

        default:
            break;
        }
    }
}
示例#10
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;
}
示例#11
0
void HSSColorStop::setDBalance(HSSParserNode::p value)
{
    switch (value->getType())
    {
    case HSSParserNodeTypeNumberConstant:
    case HSSParserNodeTypePercentageConstant:
    case HSSParserNodeTypeExpression:
        this->dBalance = value;
        this->balance = this->_evaluatePropertyValue(
                                             &HSSColorStop::balanceChanged,
                                             value,
                                             1.,
                                             HSSObservablePropertyBalance,
                                             this->observedBalance,
                                             this->observedBalanceProperty
                                             );

        break;

    case HSSParserNodeTypeFunctionCall:
    {
        this->dBalance = value;
        HSSFunction::p fnct = qSharedPointerCast<HSSFunction > (value)->clone();
        if (fnct && fnct->isA(HSSFunctionTypeRef))
        {
            fnct->setScope(this->scope);
            fnct->setThisObj(this->getThisObj());
            QVariant remoteValue = fnct->evaluate();
            if (remoteValue.canConvert<HSSUnit>())
            {
                this->balance = remoteValue.value<HSSUnit>();
            }

            fnct->observe(HSSObservablePropertyValue, HSSObservablePropertyBalance, this, new HSSValueChangedCallback<HSSColorStop > (this, &HSSColorStop::balanceChanged));

        }
        else
        {
            throw AXRWarning("HSSDGradient", "Invalid function type for balance of " + this->name);
        }

        break;
    }

    default:
        throw AXRWarning("HSSColorStop", "Invalid value for balance of " + this->name);
    }
    this->notifyObservers(HSSObservablePropertyBalance, &this->balance);
    this->notifyObservers(HSSObservablePropertyValue, NULL);
}
示例#12
0
void HSSParserNode::removeFromParentNode()
{
    HSSParserNode::p parentNode = this->getParentNode();
    if(parentNode) parentNode->removeNode(this->shared_from_this());
}
void HSSDisplayObject::setDHeight(HSSParserNode::p value)
{
    if(value->isA(HSSParserNodeTypeKeywordConstant)){
        
    } else {
        this->dHeight = value;
        HSSObservableProperty observedProperty = HSSObservablePropertyHeight;
        if(this->observedHeight != NULL)
        {
            this->observedHeight->removeObserver(this->observedHeightProperty, this);
            //we're cheating a bit here (maybe FIXME?)
        }
        HSSContainer::p parentContainer = this->getParent();
        if(parentContainer){
            this->height = this->_setLDProperty(
                                                &HSSDisplayObject::heightChanged,
                                                value,
                                                parentContainer->height,
                                                observedProperty,
                                                parentContainer.get(),
                                                this->observedHeight,
                                                this->observedHeightProperty,
                                                &(parentContainer->getChildren())
                                                );
        } else {
            this->height = this->_setLDProperty(
                                                NULL,
                                                value,
                                                150,
                                                observedProperty,
                                                this,
                                                this->observedHeight,
                                                this->observedHeightProperty,
                                                NULL
                                                );
        }
        
        this->notifyObservers(HSSObservablePropertyHeight, &this->height);
        this->setNeedsSurface(true);
        this->setDirty(true);
    }
    
    
    
//    //std_log1("setting height of "+this->name+":");
//    this->dHeight = value;
//    HSSParserNodeType nodeType = value->getType();
//    
//    if(observedHeight != NULL)
//    {
//        observedHeight->removeObserver(HSSObservablePropertyHeight, this);
//    }
//    
//    switch (nodeType) {
//        case HSSParserNodeTypeNumberConstant:
//        {
//            HSSNumberConstant::p heightValue = boost::static_pointer_cast<HSSNumberConstant>(value);
//            this->height = heightValue->getValue();
//            break;
//        }
//            
//        case HSSParserNodeTypePercentageConstant:
//        {
//            HSSPercentageConstant::p heightValue = boost::static_pointer_cast<HSSPercentageConstant>(value);
//            HSSContainer::p parentContainer = this->getParent();
//            if(parentContainer){
//                this->height = heightValue->getValue(parentContainer->height);
//                parentContainer->observe(HSSObservablePropertyHeight, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::heightChanged));
//                this->observedHeight = parentContainer.get();
//            }
//            break;
//        }
//        
//        case HSSParserNodeTypeExpression:
//        {
//            HSSExpression::p heightExpression = boost::static_pointer_cast<HSSExpression>(value);
//            HSSContainer::p parentContainer = this->getParent();
//            if(parentContainer){
//                heightExpression->setPercentageBase(parentContainer->height);
//                heightExpression->setPercentageObserved(HSSObservablePropertyHeight, parentContainer.get());
//                heightExpression->setScope(&(parentContainer->getChildren()));
//                this->height = heightExpression->evaluate();
//                heightExpression->observe(HSSObservablePropertyHeight, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::heightChanged));
//            } else {
//                heightExpression->setPercentageBase(this->height);
//                heightExpression->setPercentageObserved(HSSObservablePropertyHeight, this);
//                if(this->isA(HSSObjectTypeContainer)){
//                    HSSContainer * thisContainer = static_cast<HSSContainer *>(this);
//                    heightExpression->setScope(&(thisContainer->getChildren()));
//                }
//                this->height = heightExpression->evaluate();
//                heightExpression->observe(HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::heightChanged));
//            }
//            break; 
//        }
//            
//        case HSSParserNodeTypeKeywordConstant:
//            
//            break;
//            
//        default:
//            throw "unknown parser node type while setting dHeight";
//            break;
//    }
//    
//    //fprintf(stderr, "%f\n", this->height);
//    this->notifyObservers(HSSObservablePropertyHeight, &this->height);
//    this->setNeedsSurface(true);
//    this->setDirty(true);
}
void HSSDisplayObject::setDWidth(HSSParserNode::p value)
{
    
    if(value->isA(HSSParserNodeTypeKeywordConstant)){
        
    } else {
        this->dWidth = value;
        HSSObservableProperty observedProperty = HSSObservablePropertyWidth;
        if(this->observedWidth != NULL)
        {
            this->observedWidth->removeObserver(this->observedWidthProperty, this);
        }
        HSSContainer::p parentContainer = this->getParent();
        if(parentContainer){
            this->width = this->_setLDProperty(
                                               &HSSDisplayObject::widthChanged,
                                               value,
                                               parentContainer->width,
                                               observedProperty,
                                               parentContainer.get(),
                                               this->observedWidth,
                                               this->observedWidthProperty,
                                               &(parentContainer->getChildren())
                                               );
        } else {
            this->width = this->_setLDProperty(
                                               NULL,
                                               value,
                                               150,
                                               observedProperty,
                                               this,
                                               this->observedWidth,
                                               this->observedWidthProperty,
                                               NULL
                                               );
        }
        
        
        this->notifyObservers(HSSObservablePropertyWidth, &this->width);
        this->setNeedsSurface(true);
        this->setDirty(true);
    }

    
//    //std_log1("setting width of "+this->name+":");
//    this->dWidth = value;
//    HSSParserNodeType nodeType = value->getType();
//    
//    if(observedWidth != NULL)
//    {
//        //std_log1("#################should unsubscribe observer here#########################");
//        observedWidth->removeObserver(HSSObservablePropertyWidth, this);
//    }
//    
//    switch (nodeType) {
//        case HSSParserNodeTypeNumberConstant:
//        {
//            HSSNumberConstant::p widthValue = boost::static_pointer_cast<HSSNumberConstant>(value);
//            this->width = widthValue->getValue();
//            break;
//        }
//            
//        case HSSParserNodeTypePercentageConstant:
//        {
//            HSSPercentageConstant::p widthValue = boost::static_pointer_cast<HSSPercentageConstant>(value);
//            HSSContainer::p parentContainer = this->getParent();
//            if(parentContainer){
//                this->width = widthValue->getValue(parentContainer->width);
//                parentContainer->observe(HSSObservablePropertyWidth, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::widthChanged));
//                this->observedWidth = parentContainer.get();
//                
//            } else {
//                this->width = widthValue->getValue(this->width);
//            }
//            break;
//        }
//            
//        case HSSParserNodeTypeExpression:
//        {
//            HSSExpression::p widthExpression = boost::static_pointer_cast<HSSExpression>(value);
//            HSSContainer::p parentContainer = this->getParent();
//            if(parentContainer){
//                widthExpression->setPercentageBase(parentContainer->width);
//                widthExpression->setPercentageObserved(HSSObservablePropertyWidth, parentContainer.get());
//                widthExpression->setScope(&(parentContainer->getChildren()));
//                this->width = widthExpression->evaluate();
//                widthExpression->observe(HSSObservablePropertyWidth, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::widthChanged));
//            } else {
//                widthExpression->setPercentageBase(this->width);
//                widthExpression->setPercentageObserved(HSSObservablePropertyWidth, this);
//                if(this->isA(HSSObjectTypeContainer)){
//                    HSSContainer * thisContainer = static_cast<HSSContainer *>(this);
//                    widthExpression->setScope(&(thisContainer->getChildren()));
//                }
//                this->width = widthExpression->evaluate();
//                widthExpression->observe(HSSObservablePropertyWidth, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::widthChanged));
//            }
//            break; 
//        }
//            
//        case HSSParserNodeTypeKeywordConstant:
//            
//            break;
//            
//        default:
//            throw "unknown parser node type while setting dWidth";
//            break;
//    }
//    
//    //fprintf(stderr, "%f\n", this->width);
//    this->notifyObservers(HSSObservablePropertyWidth, &this->width);
//    this->setNeedsSurface(true);
//    this->setDirty(true);
}
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;
}
示例#16
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);
                }
            }
        }
    }
}
示例#17
0
void HSSColorStop::setDColor(HSSParserNode::p value)
{
    bool valid = false;

    switch (value->getType())
    {
    case HSSParserNodeTypeObjectNameConstant:
    {
        this->dColor = value;
        try
        {
            HSSObjectNameConstant::p objname = qSharedPointerCast<HSSObjectNameConstant > (value);
            HSSObjectDefinition::p objdef = this->getController()->objectTreeGet(objname->getValue());
            this->setDColor(objdef);
            valid = true;

        }
        catch (const AXRError &e)
        {
            e.raise();
        }

        break;
    }


    case HSSParserNodeTypeFunctionCall:
    {
        this->dColor = value;
        HSSFunction::p fnct = qSharedPointerCast<HSSFunction > (value)->clone();
        if (fnct && fnct->isA(HSSFunctionTypeRef))
        {
            fnct->setScope(this->scope);
            fnct->setThisObj(this->getThisObj());
            QVariant remoteValue = fnct->evaluate();
            if (remoteValue.canConvert<HSSRgb::p>())
            {
                this->color = remoteValue.value<HSSRgb::p>();
                valid = true;
            }

            fnct->observe(HSSObservablePropertyValue, HSSObservablePropertyColor, this, new HSSValueChangedCallback<HSSColorStop > (this, &HSSColorStop::colorChanged));
        }
        break;
    }

    case HSSParserNodeTypeKeywordConstant:
    {
        HSSKeywordConstant::p theKW = qSharedPointerCast<HSSKeywordConstant>(value);
        AXRString kwValue = theKW->getValue();

        if (kwValue == "black")
        {
            this->color = HSSRgb::blackColor(this->getController());
            valid = true;
        }
        else if (kwValue == "white")
        {
            this->color = HSSRgb::whiteColor(this->getController());
            valid = true;
        }
        else if (kwValue == "transparent")
        {
            //the color will remain empty for transparent
            this->color.clear();
            valid = true;
        }

        break;
    }

    default:
        break;
    }

    switch (value->getStatementType())
    {
    case HSSStatementTypeObjectDefinition:
    {
        this->dColor = value;
        HSSObjectDefinition::p objdef = qSharedPointerCast<HSSObjectDefinition > (value);
        objdef->setScope(this->scope);
        objdef->setThisObj(this->getThisObj());
        objdef->apply();
        HSSObject::p theobj = objdef->getObject();
        if (theobj && theobj->isA(HSSObjectTypeRgb))
        {
            this->color = qSharedPointerCast<HSSRgb > (theobj);
            valid = true;
        }

        break;
    }

    default:
        break;
    }

    if (!valid)
        throw AXRWarning("HSSColorStop", "Invalid value for color of " + this->name);

    this->notifyObservers(HSSObservablePropertyColor, &this->color);
    this->notifyObservers(HSSObservablePropertyValue, NULL);
}