void HSSDisplayObject::setDAnchorY(HSSParserNode::p value) { this->dAnchorY = value; HSSObservableProperty observedProperty = HSSObservablePropertyHeight; if(this->observedAnchorY != NULL) { this->observedAnchorY->removeObserver(this->observedAnchorYProperty, this); } HSSContainer::p parentContainer = this->getParent(); const std::vector<HSSDisplayObject::p> * scope; if(parentContainer){ scope = &(parentContainer->getChildren()); } else { scope = NULL; } this->anchorY = this->_setLDProperty( &HSSDisplayObject::anchorYChanged, value, this->height, observedProperty, this, this->observedAnchorY, this->observedAnchorYProperty, scope ); this->notifyObservers(HSSObservablePropertyAnchorY, &this->anchorY); #if AXR_DEBUG_LEVEL > 0 this->setDirty(true); #endif }
std::vector< std::vector<HSSDisplayObject::p> > AXRController::selectAllHierarchical(const std::vector<HSSDisplayObject::p> & scope, HSSDisplayObject::p thisObj, bool negating, bool processing) { std::vector< std::vector<HSSDisplayObject::p> > selections = this->selectOnLevel(scope, thisObj, negating, processing); unsigned i, j, k, size, size2, size3; for (i=0, size=selections.size(); i<size; i++) { std::vector<HSSDisplayObject::p> newSearch; for(j=0, size2=scope.size(); j<size2; j++){ if(scope[j]->isA(HSSObjectTypeContainer)){ HSSContainer::p theContainer = boost::static_pointer_cast<HSSContainer>(scope[j]); const std::vector<HSSDisplayObject::p> children = theContainer->getChildren(); for(k=0, size3 = children.size(); k<size3; k++){ newSearch.push_back(children[k]); } } } std::vector< std::vector<HSSDisplayObject::p> > childSelection; if(newSearch.size() > 0){ this->currentChainCount -= 1; this->readNextSelectorNode(); childSelection = this->selectAllHierarchical(newSearch, thisObj, false, processing); for (j=0, size2=selections.size(); j<size2; j++) { //std::vector<HSSDisplayObject::p> & selection = selections[j]; for (k=0, size3=childSelection.size(); k<size3; k++) { selections[j].insert(selections[j].end(), childSelection[k].begin(), childSelection[k].end()); } } } } return selections; }
const std::vector<HSSDisplayObject::p> HSSParentFilter::apply(const std::vector<HSSDisplayObject::p> &scope, bool negating) { if(scope.size() > 0){ std::vector<HSSDisplayObject::p> ret; int size=scope.size(); HSSContainer::p container; if (!negating) for (int i=0; i<size; i++){ container = HSSContainer::asContainer(scope[i]); if (container && container->getChildren(false).size()>0) ret.push_back(scope[i]); } else for (int i=0; i<size; i++){ container = HSSContainer::asContainer(scope[i]); if (container && container->getChildren(false).size()==0) ret.push_back(scope[i]); } return ret; } else { return scope; } }
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); }
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); } } } } }
std::vector< std::vector<HSSDisplayObject::p> > AXRController::selectHierarchical(const std::vector<HSSDisplayObject::p> & scope, HSSDisplayObject::p thisObj, bool negating, bool processing) { std::vector< std::vector<HSSDisplayObject::p> > selections = this->selectOnLevel(scope, thisObj, negating, processing); unsigned i, size; for (i=0, size=selections.size(); i<size; i++) { std::vector<HSSDisplayObject::p> selection = selections[i]; if(selection.size() > 0){ if(!this->isAtEndOfSelector()){ if(this->currentSelectorNode->isA(HSSParserNodeTypeCombinator)){ HSSCombinator::p combinator = boost::static_pointer_cast<HSSCombinator>(this->currentSelectorNode); HSSCombinatorType combinatorType = combinator->getCombinatorType(); switch (combinatorType) { case HSSCombinatorTypeChildren: { std::vector<HSSDisplayObject::p> newScope; unsigned j, size2, k, size3; for(j=0, size2 = selection.size(); j<size2; j++){ if(selection[j]->isA(HSSObjectTypeContainer)){ HSSContainer::p theContainer = boost::static_pointer_cast<HSSContainer>(selection[j]); const std::vector<HSSDisplayObject::p> children = theContainer->getChildren(); for(k=0, size3 = children.size(); k<size3; k++){ newScope.push_back(children[k]); } } } this->readNextSelectorNode(); return this->selectHierarchical(newScope, thisObj, false, processing); break; } case HSSCombinatorTypeDescendants: { std::vector<HSSDisplayObject::p> newScope; unsigned j, size2, k, size3; for(j=0, size2 = selection.size(); j<size2; j++){ if(selection[j]->isA(HSSObjectTypeContainer)){ HSSContainer::p theContainer = boost::static_pointer_cast<HSSContainer>(selection[j]); const std::vector<HSSDisplayObject::p> children = theContainer->getChildren(); for(k=0, size3 = children.size(); k<size3; k++){ newScope.push_back(children[k]); } } } this->readNextSelectorNode(); return this->selectAllHierarchical(newScope, thisObj, false, processing); break; } default: break; } } } } } return selections; }
void HSSRequest::fire() { AXRDocument* document = this->getController()->document(); //if there is no target if (this->target->empty()) { document->loadXMLFile(this->src); } else { switch (this->mode) { default: { AXRController::p controller = AXRController::p(new AXRController(document)); XMLParser::p xmlParser(new XMLParser(controller.data())); HSSParser::p hssParser(new HSSParser(controller.data())); AXRBuffer::p baseFile = document->getFile(); AXRBuffer::p newFile; try { newFile = document->getFile(this->src); } catch (const AXRError &e) { e.raise(); } if (newFile) { bool loadingSuccess = xmlParser->loadFile(newFile); if (!loadingSuccess) { AXRError("AXRDocument", "Could not load the XML file").raise(); } else { HSSContainer::p root = qSharedPointerCast<HSSContainer > (controller->getRoot()); if (root) { std::vector<QUrl> loadSheets = controller->loadSheetsGet(); for (std::vector<QUrl>::iterator sheetsIt = loadSheets.begin(); sheetsIt != loadSheets.end(); ++sheetsIt) { AXRBuffer::p hssfile; try { hssfile = document->getFile(*sheetsIt); } catch (const AXRError &e) { e.raise(); continue; } if (!hssParser->loadFile(hssfile)) { AXRError("AXRDocument", "Could not load the HSS file").raise(); } } controller->matchRulesToContentTree(); HSSSimpleSelection::const_iterator targetIt, childIt; for (targetIt = this->target->begin(); targetIt != this->target->end(); ++targetIt) { const HSSDisplayObject::p & theDO = *targetIt; HSSContainer::p theContainer = HSSContainer::asContainer(theDO); if (theContainer) { theContainer->clear(); for (childIt = root->getChildren()->begin(); childIt != root->getChildren()->end(); ++childIt) { const HSSDisplayObject::p & theChild = *childIt; theContainer->add(theChild); } } } root->setNeedsRereadRules(true); root->recursiveReadDefinitionObjects(); root->handleEvent(HSSEventTypeLoad, NULL); document->setNeedsDisplay(true); } } } // AXRDocument::tp document = AXRDocument::getInstance(); // AXRWrapper * document = document->getWrapper(); // AXRBuffer::p baseFile = document->getFile(); // // bool loadingSuccess = document->loadFile(baseFile->basePath+this->src, this->src); // if(loadingSuccess){ // unsigned i, size; // for (i=0, size=this->target.size(); i<size; ++i) { // std_log1("Adding loaded file to target"); // // if(this->target[i]->isA(HSSObjectTypeContainer)){ // const HSSContainer::p & theCont = qSharedPointerCast<HSSContainer>(this->target[i]); // const HSSContainer::p & loadedRoot = fileController.getRoot(); // theCont->add(loadedRoot); // // unsigned j, k, size2, size3; // HSSSimpleSelection::p scope = theCont->getChildren(); // for (j=0, size2=fileController.rulesSize(); j<size2; ++j) { // HSSRule::p & theRule = fileController.rulesGet(j); // theRule->childrenAdd(theRule); // } // for (j=0, size2=theCont->rulesSize(); j<size2; ++j) { // HSSRule::p theRule = theCont->rulesGet(j); // for (k=0, size3=theRule->childrenSize(); k<size3; ++k) { // HSSRule::p childRule = theRule->childrenGet(k); // this->getController()->recursiveMatchRulesToDisplayObjects(childRule, scope, theCont); // } // } // // theCont->recursiveReadDefinitionObjects(); // theCont->setNeedsLayout(true); // } // } // } break; } } } }