void Range::checkNodeBA( DOM::Node n ) const { checkNode( n ); if( n.nodeType() == Node::DOCUMENT_NODE || n.nodeType() == Node::DOCUMENT_FRAGMENT_NODE || n.nodeType() == Node::ATTRIBUTE_NODE || n.nodeType() == Node::ENTITY_NODE || n.nodeType() == Node::NOTATION_NODE ) throw RangeException( RangeException::INVALID_NODE_TYPE_ERR ); }
void DOMTreeView::initializeOptionsFromNode(const DOM::Node &node) { infoNode = node; nodeName->clear(); nodeType->clear(); nodeNamespace->clear(); nodeValue->clear(); if (node.isNull()) { nodeInfoStack->raiseWidget(EmptyPanel); return; } nodeName->setText(node.nodeName().string()); nodeType->setText(QString::number(node.nodeType())); nodeNamespace->setText(node.namespaceURI().string()); // nodeValue->setText(node.value().string()); DOM::Element element = node; if (!element.isNull()) { initializeOptionsFromElement(element); return; } DOM::CharacterData cdata = node; if (!cdata.isNull()) { initializeOptionsFromCData(cdata); return; } // Fallback nodeInfoStack->raiseWidget(EmptyPanel); }
void KGet_plug_in::slotShowLinks() { if ( !parent() || !parent()->inherits( "KHTMLPart" ) ) return; KHTMLPart *htmlPart = static_cast<KHTMLPart*>( parent() ); KParts::Part *activePart = 0L; if ( htmlPart->partManager() ) { activePart = htmlPart->partManager()->activePart(); if ( activePart && activePart->inherits( "KHTMLPart" ) ) htmlPart = static_cast<KHTMLPart*>( activePart ); } DOM::HTMLDocument doc = htmlPart->htmlDocument(); if ( doc.isNull() ) return; DOM::HTMLCollection links = doc.links(); QPtrList<LinkItem> linkList; std::set<QString> dupeCheck; for ( uint i = 0; i < links.length(); i++ ) { DOM::Node link = links.item( i ); if ( link.isNull() || link.nodeType() != DOM::Node::ELEMENT_NODE ) continue; LinkItem *item = new LinkItem( (DOM::Element) link ); if ( item->isValid() && dupeCheck.find( item->url.url() ) == dupeCheck.end() ) { linkList.append( item ); dupeCheck.insert( item->url.url() ); } else delete item; } if ( linkList.isEmpty() ) { KMessageBox::sorry( htmlPart->widget(), i18n("There are no links in the active frame of the current HTML page."), i18n("No Links") ); return; } KGetLinkView *view = new KGetLinkView(); QString url = doc.URL().string(); view->setPageURL( url ); view->setLinks( linkList ); view->show(); }
static QString textForNode(DOM::Node node) { QString rc; DOM::NodeList nl = node.childNodes(); for (unsigned int i = 0; i < nl.length(); ++i) { DOM::Node n = nl.item(i); if (n.nodeType() == DOM::Node::TEXT_NODE) { rc += n.nodeValue().string(); } } // FIXME: entries need to be escaped for vcard/vevent return rc.stripWhiteSpace(); }
long khtml::MouseEvent::offset() const { Position pos; if (innerNode().handle()) { // FIXME: Shouldn't be necessary to skip text nodes. DOM::Node inner = innerNode(); if (inner.nodeType() == Node::TEXT_NODE) { inner = inner.parentNode(); } pos = inner.handle()->positionForCoordinates(m_x, m_y).position(); } return pos.offset(); }
void EnhancedTagAttributeTree::deleteSubTree() { QuantaView *view = ViewManager::ref()->activeView(); if(!curNode || !view->document()) return; Node *oldCurNode; NodeModifsSet *modifs; int curLine, curCol; long offset; DOM::Node domNode; QValueList<int> loc; //Save the cursor position in kafka/quanta if(view->hadLastFocus() == QuantaView::SourceFocus) curNode->tag->beginPos(curLine, curCol); else { KafkaDocument::ref()->getKafkaWidget()->getCurrentNode(domNode, offset); if(!domNode.previousSibling().isNull()) domNode = domNode.previousSibling(); else if(!domNode.parentNode().isNull()) domNode = domNode.parentNode(); else domNode = KafkaDocument::ref()->getKafkaWidget()->document(); if(domNode.nodeType() == DOM::Node::TEXT_NODE) offset = domNode.nodeValue().length(); else offset = 0; loc = kafkaCommon::getLocation(domNode); } //Remove the Nodes oldCurNode = curNode; curNode = 0L; attrTree->setCurrentNode(curNode); modifs = new NodeModifsSet(); kafkaCommon::extractAndDeleteNode(oldCurNode, modifs); view->document()->docUndoRedo->addNewModifsSet(modifs, undoRedo::NodeTreeModif); //set the cursor position in kafka/quanta if(view->hadLastFocus() == QuantaView::SourceFocus) view->document()->viewCursorIf->setCursorPositionReal((uint)curLine, (uint)curCol); else { domNode = kafkaCommon::getNodeFromLocation(loc, KafkaDocument::ref()->getKafkaWidget()->document()); KafkaDocument::ref()->getKafkaWidget()->setCurrentNode(domNode, offset); } }
void Range::checkNodeWOffset( DOM::Node n, int offset) const { checkNode( n ); if( offset < 0 ) throw DOMException( DOMException::INDEX_SIZE_ERR ); if( n.nodeType() != Node::TEXT_NODE ) { if( (unsigned int)offset > n.childNodes().length() ) throw DOMException( DOMException::INDEX_SIZE_ERR ); } else { Text t; t = n; if( t.isNull() || (unsigned)offset > t.length() ) throw DOMException( DOMException::INDEX_SIZE_ERR ); } }
LinkItem::LinkItem( DOM::Element link ) : m_valid( false ) { DOM::NamedNodeMap attrs = link.attributes(); DOM::Node href = attrs.getNamedItem( "href" ); // Load source address of images too DOM::Node src = attrs.getNamedItem( "src" ); if ( href.nodeValue().string().isEmpty() && !src.nodeValue().string().isEmpty() ) href = src; // qDebug("*** href: %s", href.nodeValue().string().latin1() ); QString urlString = link.ownerDocument().completeURL( href.nodeValue() ).string(); if ( urlString.isEmpty() ) return; url = KUrl( urlString ); if ( !KProtocolManager::supportsReading( url ) ) return; // somehow getElementsByTagName("#text") doesn't work :( DOM::NodeList children = link.childNodes(); for ( uint i = 0; i < children.length(); i++ ) { DOM::Node node = children.item( i ); if ( node.nodeType() == DOM::Node::TEXT_NODE ) text.append( node.nodeValue().string() ); } // force "local file" mimetype determination KMimeType::Ptr mt = KMimeType::findByUrl( url, 0, true, true); icon = mt->iconName(); mimeType = mt->comment(); m_valid = true; }
void EnhancedTagAttributeTree::deleteNode() { QuantaView *view = ViewManager::ref()->activeView(); if(!curNode || !view->document()) return; Node *oldCurNode, *oldCurNodeParent, *child; QTag *oldCurNodeParentQTag; int curLine, curCol; long offset; DOM::Node domNode; QValueList<int> loc; NodeModifsSet *modifs; //Save the cursor position in kafka/quanta if(view->hadLastFocus() == QuantaView::SourceFocus) curNode->tag->beginPos(curLine, curCol); else { KafkaDocument::ref()->getKafkaWidget()->getCurrentNode(domNode, offset); if(!domNode.previousSibling().isNull()) domNode = domNode.previousSibling(); else if(!domNode.parentNode().isNull()) domNode = domNode.parentNode(); else domNode = KafkaDocument::ref()->getKafkaWidget()->document(); if(domNode.nodeType() == DOM::Node::TEXT_NODE) offset = domNode.nodeValue().length(); else offset = 0; loc = kafkaCommon::getLocation(domNode); } //remove the Nodes oldCurNode = curNode; oldCurNodeParent = curNode->parent; curNode = 0L; attrTree->setCurrentNode(curNode); modifs = new NodeModifsSet(); kafkaCommon::extractAndDeleteNode(oldCurNode, modifs, false); //Then we see if the new parent - child relationships are valid, and if not, delete the child and restart if(oldCurNodeParent) { oldCurNodeParentQTag = QuantaCommon::tagFromDTD(oldCurNodeParent); if(oldCurNodeParentQTag) { child = oldCurNodeParent->child; while(child) { if(!oldCurNodeParentQTag->isChild(child)) { kafkaCommon::extractAndDeleteNode(child, modifs, false); //too lazy to get the real next node ;-) child = oldCurNodeParent->child; } else child = child->next; } } } view->document()->docUndoRedo->addNewModifsSet(modifs, undoRedo::NodeTreeModif); //set the cursor position in kafka/quanta if(view->hadLastFocus() == QuantaView::SourceFocus) view->document()->viewCursorIf->setCursorPositionReal((uint)curLine, (uint)curCol); else { domNode = kafkaCommon::getNodeFromLocation(loc, KafkaDocument::ref()->getKafkaWidget()->document()); KafkaDocument::ref()->getKafkaWidget()->setCurrentNode(domNode, offset); } }
void HTMLEnhancer::postEnhanceNode(DOM::Node domNode) { DOM::Node textNode; kNodeAttrs *props; QTag *qTag; bool isInline; if(domNode.isNull()) return; //If domNode is a Block and there is no text around, and if domNode's parent can handle //text or a P tag, add an empty text DOM::Node // so that the user can access this area. qTag = QuantaCommon::tagFromDTD(m_wkafkapart->getCurrentDoc()->defaultDTD(), domNode.nodeName().string()); isInline = kafkaCommon::isInline(domNode.nodeName().string()); if(domNode.nodeType() == DOM::Node::ELEMENT_NODE && (!isInline || (isInline && qTag && qTag->isSingle()))) { qTag = QuantaCommon::tagFromDTD(m_wkafkapart->getNode(domNode.parentNode())); if((domNode.nextSibling().isNull() || (!domNode.nextSibling().isNull() && domNode.nextSibling().nodeType() == DOM::Node::ELEMENT_NODE && !kafkaCommon::isInline(domNode.nextSibling().nodeName().string()))) && qTag && (qTag->isChild("#text", false) || qTag->isChild("p", false)) && domNode.nodeName().string().lower() != "p") { textNode = kafkaCommon::createTextDomNode("", m_wkafkapart->getKafkaWidget()->document()); props = m_wkafkapart->connectDomNodeToQuantaNode(textNode, 0L); props->setIsLinkedToNode(false); props->setSpecialBehavior(kNodeAttrs::emptyTextSurroundingBlockElementAtTheRight); kafkaCommon::insertDomNode(textNode, domNode.parentNode(), domNode.nextSibling()); } if((domNode.previousSibling().isNull() || (!domNode.previousSibling().isNull() && domNode.previousSibling().nodeType() == DOM::Node::ELEMENT_NODE && !kafkaCommon::isInline(domNode.previousSibling().nodeName().string()))) && qTag && (qTag->isChild("#text", false) || qTag->isChild("p", false)) && domNode.nodeName().string().lower() != "p") { textNode = kafkaCommon::createTextDomNode("", m_wkafkapart->getKafkaWidget()->document()); props = m_wkafkapart->connectDomNodeToQuantaNode(textNode, 0L); props->setIsLinkedToNode(false); props->setSpecialBehavior(kNodeAttrs::emptyTextSurroundingBlockElementAtTheLeft); kafkaCommon::insertDomNode(textNode, domNode.parentNode(), domNode); } } //If domNode is an childless element, and if it can handle Text or a P tag, //add an empty text DOM::Node so that the //user can access this area. qTag = QuantaCommon::tagFromDTD(m_wkafkapart->getNode(domNode)); if(domNode.nodeType() == DOM::Node::ELEMENT_NODE && !domNode.hasChildNodes() && qTag && (qTag->isChild("#text", false) || qTag->isChild("p", false))) { textNode = kafkaCommon::createTextDomNode("", m_wkafkapart->getKafkaWidget()->document()); props = m_wkafkapart->connectDomNodeToQuantaNode(textNode, 0L); props->setIsLinkedToNode(false); props->setSpecialBehavior(kNodeAttrs::emptyTextAsChildOfAChildlessElement); kafkaCommon::insertDomNode(textNode, domNode); } }