static Position innerNodePosition(const Position& innerPosition) { ASSERT(!innerPosition.isBeforeAnchor()); ASSERT(!innerPosition.isAfterAnchor()); HTMLElement* element = toHTMLElement(innerPosition.anchorNode()); ASSERT(element); NodeList* childNodes = element->childNodes(); if (!childNodes->length()) return Position(element, 0); unsigned offset = 0; if (innerPosition.isOffsetInAnchor()) offset = std::max(0, std::min(innerPosition.offsetInContainerNode(), static_cast<int>(childNodes->length()))); else if (innerPosition.isAfterChildren()) offset = childNodes->length(); if (offset == childNodes->length()) return Position(element->lastChild(), PositionAnchorType::AfterAnchor); Node* node = childNodes->item(offset); if (node->isTextNode()) return Position(toText(node), 0); return Position(node, PositionAnchorType::BeforeAnchor); }
NodeList Element::getElementsByTagName (const DOMString& name) { NodeList elements; for (size_t i = 0; i < _children.length(); i++) { Node* node = _children.item(i); if (node->nodeType() == Node::ELEMENT_NODE) { if (((Element*)node)->tagName() == Utils::toUpper(name)) { elements.insert(node); } } } for (size_t i = 0; i < _children.length(); i++) { Node* node = _children.item(i); if (node->nodeType() == Node::ELEMENT_NODE) { NodeList subElements = ((Element*)node)->getElementsByTagName(name); for (size_t h = 0; h < subElements.length(); h++) { elements.insert(subElements.item(h)); } } } return elements; }
// Compiles a list of zoomable subtargets. void compileZoomableSubtargets(const NodeList& intersectedNodes, SubtargetGeometryList& subtargets) { unsigned length = intersectedNodes.length(); for (unsigned i = 0; i < length; ++i) { Node* const candidate = intersectedNodes.item(i); if (nodeIsZoomTarget(candidate)) appendZoomableSubtargets(candidate, subtargets); } }
// Compiles a list of subtargets of all the relevant target nodes. void compileSubtargetList(const NodeList& intersectedNodes, SubtargetGeometryList& subtargets, NodeFilter nodeFilter) { // Find candidates responding to tap gesture events in O(n) time. HashMap<Node*, Node*> responderMap; HashSet<Node*> ancestorsToRespondersSet; Vector<Node*> candidates; // A node matching the NodeFilter is called a responder. Candidate nodes must either be a // responder or have an ancestor that is a responder. // This iteration tests all ancestors at most once by caching earlier results. unsigned length = intersectedNodes.length(); for (unsigned i = 0; i < length; ++i) { Node* const node = intersectedNodes.item(i); Vector<Node*> visitedNodes; Node* respondingNode = 0; for (Node* visitedNode = node; visitedNode; visitedNode = visitedNode->parentOrHostNode()) { // Check if we already have a result for a common ancestor from another candidate. respondingNode = responderMap.get(visitedNode); if (respondingNode) break; visitedNodes.append(visitedNode); // Check if the node filter applies, which would mean we have found a responding node. if (nodeFilter(visitedNode)) { respondingNode = visitedNode; // Continue the iteration to collect the ancestors of the responder, which we will need later. for (visitedNode = visitedNode->parentOrHostNode(); visitedNode; visitedNode = visitedNode->parentOrHostNode()) { pair<HashSet<Node*>::iterator, bool> addResult = ancestorsToRespondersSet.add(visitedNode); if (!addResult.second) break; } break; } } // Insert the detected responder for all the visited nodes. for (unsigned j = 0; j < visitedNodes.size(); j++) responderMap.add(visitedNodes[j], respondingNode); if (respondingNode) candidates.append(node); } // We compile the list of component absolute quads instead of using the bounding rect // to be able to perform better hit-testing on inline links on line-breaks. length = candidates.size(); for (unsigned i = 0; i < length; i++) { Node* candidate = candidates[i]; // Skip nodes who's responders are ancestors of other responders. This gives preference to // the inner-most event-handlers. So that a link is always preferred even when contained // in an element that monitors all click-events. Node* respondingNode = responderMap.get(candidate); ASSERT(respondingNode); if (ancestorsToRespondersSet.contains(respondingNode)) continue; appendSubtargetsForNodeToList(candidate, subtargets); } }
JSValue* JSNodeList::getValueProperty(ExecState* exec, int token) const { switch (token) { case LengthAttrNum: { NodeList* imp = static_cast<NodeList*>(impl()); return jsNumber(exec, imp->length()); } case ConstructorAttrNum: return getConstructor(exec); } return 0; }
void post(NIFFile *nif) { Node::post(nif); children.post(nif); effects.post(nif); for(size_t i = 0;i < children.length();i++) { // Why would a unique list of children contain empty refs? if(!children[i].empty()) children[i]->parent = this; } }
PlaneFunctionBuilder * PlaneImplicitFunctionParser::parsePlaneFunction(Poco::XML::Element* functionElement) { using namespace Poco::XML; boost::interprocess::unique_ptr<PlaneFunctionBuilder, Mantid::API::DeleterPolicy<PlaneFunctionBuilder> > functionBuilder(new PlaneFunctionBuilder); NodeList* parameterList = functionElement->getChildElement("ParameterList")->childNodes(); //Loop through all parameters and attempt to identify those that are known to belong to this implicit function type. for(unsigned int i = 0; i < parameterList->length(); i++) { Element* parameterElement = dynamic_cast<Element*>(parameterList->item(i)); boost::scoped_ptr<API::ImplicitFunctionParameter> parameter(this->parseParameter(parameterElement)); if(NormalParameter::parameterName() == parameter->getName()) { NormalParameter* pCurr = dynamic_cast<NormalParameter*>(parameter.get()); NormalParameter normal(pCurr->getX(), pCurr->getY(), pCurr->getZ()); functionBuilder->addNormalParameter(normal); } else if(OriginParameter::parameterName() == parameter->getName()) { OriginParameter* pCurr = dynamic_cast<OriginParameter*>(parameter.get()); OriginParameter origin(pCurr->getX(), pCurr->getY(), pCurr->getZ()); functionBuilder->addOriginParameter(origin); } else if(WidthParameter::parameterName() == parameter->getName()) { WidthParameter* pCurr = dynamic_cast<WidthParameter*>(parameter.get()); WidthParameter width(pCurr->getValue()); functionBuilder->addWidthParameter(width); } else { std::string message = "The parameter cannot be processed or is unrecognised: " + parameter->getName(); message += ". The parameter cannot be processed or is unrecognised: " + (dynamic_cast<InvalidParameter*>(parameter.get()))->getValue(); throw std::invalid_argument(message); } } return functionBuilder.release(); //convert to raw pointer and cancel smart management. }
int no_of_destinations() const { return _destinations.length(); }