Пример #1
0
void DOMTreeView::recursive(const DOM::Node &pNode, const DOM::Node &node)
{
    QListViewItem *cur_item;
    if(pNode.ownerDocument() != document)
    {
	QString val = node.nodeValue().string();
	if ( val.length() > 20 )
	    val.truncate( 20 );
	cur_item = new QListViewItem(static_cast<QListView *>(this), node.nodeName().string(), val );
	document = pNode.ownerDocument();
    }
    else {
	QString val = node.nodeValue().string();
	if ( val.length() > 20 )
	    val.truncate( 20 );
	cur_item = new QListViewItem(m_itemdict[pNode.handle()], node.nodeName().string(), val);
    }

    if(node.handle())
    {
	m_itemdict.insert(node.handle(), cur_item);
	m_nodedict.insert(cur_item, new DOM::Node(node));
    }

    DOM::Node cur_child = node.lastChild();
    while(!cur_child.isNull())
    {
	recursive(node, cur_child);
	cur_child = cur_child.previousSibling();
    }
}
Пример #2
0
void DOMTreeView::showRecursive(const DOM::Node &pNode, const DOM::Node &node, uint depth)
{
  DOMListViewItem *cur_item;
  DOMListViewItem *parent_item = m_itemdict.value(pNode.handle(), 0);

  if (depth > m_maxDepth) {
    m_maxDepth = depth;
  }

  if (depth == 0) {
    cur_item = new DOMListViewItem(node, m_listView);
    m_document = pNode.ownerDocument();
  } else {
    cur_item = new DOMListViewItem(node, parent_item);
  }

  //kDebug(90180) << node.nodeName().string() << " [" << depth << "]";
  cur_item = addElement (node, cur_item, false);
  m_listView->setItemExpanded(cur_item, depth < m_expansionDepth);

  if(node.handle()) {
    m_itemdict.insert(node.handle(), cur_item);
  }

  DOM::Node child = node.firstChild();
  if (child.isNull()) {
    DOM::HTMLFrameElement frame = node;
    if (!frame.isNull()) {
      child = frame.contentDocument().documentElement();
    } else {
      DOM::HTMLIFrameElement iframe = node;
      if (!iframe.isNull())
        child = iframe.contentDocument().documentElement();
    }
  }
  while(!child.isNull()) {
    showRecursive(node, child, depth + 1);
    child = child.nextSibling();
  }

  const DOM::Element element = node;
  if (!m_bPure) {
    if (!element.isNull() && !element.firstChild().isNull()) {
      if(depth == 0) {
	cur_item = new DOMListViewItem(node, m_listView, cur_item);
	m_document = pNode.ownerDocument();
      } else {
	cur_item = new DOMListViewItem(node, parent_item, cur_item);
      }
      //kDebug(90180) << "</" << node.nodeName().string() << ">";
      cur_item = addElement(element, cur_item, true);
//       m_listView->setItemExpanded(cur_item, depth < m_expansionDepth);
    }
  }
}
Пример #3
0
khtml::MouseEvent::MouseEvent(const char *name, QMouseEvent *qmouseEvent, int x, int y,
                              const DOM::DOMString &url, const DOM::DOMString &target,
                              const DOM::Node &innerNode)
    : KParts::Event(name), m_qmouseEvent(qmouseEvent), m_x(x), m_y(y),
      m_url(url), m_target(target), m_innerNode(innerNode)
{
    d = 0;
    if (innerNode.handle() && innerNode.handle()->renderer()) {
        innerNode.handle()->renderer()->absolutePosition(m_nodeAbsX, m_nodeAbsY);
    }
}
Пример #4
0
void DOMTreeView::slotRefreshNode(const DOM::Node &pNode)
{
  DOMListViewItem *cur = static_cast<DOMListViewItem *>(m_itemdict[pNode.handle()]);
  if (!cur) return;

  addElement(pNode, cur, false);
}
Пример #5
0
void DOMTreeView::showTree(const DOM::Node &pNode)
{
    if(pNode.isNull() || document != pNode.ownerDocument())
    {
	clear();
	m_itemdict.clear();
	m_nodedict.clear();
	if(pNode.isNull())
	    return;
	else if(pNode.ownerDocument().isNull())
	    recursive(0, pNode);
	else
	    recursive(0, pNode.ownerDocument());
    }
    setCurrentItem(m_itemdict[pNode.handle()]);
    ensureItemVisible(m_itemdict[pNode.handle()]);
}
Пример #6
0
void DOMTreeView::slotShowNode(const DOM::Node &pNode)
{

  if (QListViewItem *item = m_itemdict[pNode.handle()]) {
    m_listView->setCurrentItem(item);
    m_listView->ensureItemVisible(item);
  }
}
Пример #7
0
void DOMTreeView::slotShowNode(const DOM::Node &pNode)
{

  if (QTreeWidgetItem *item = m_itemdict.value(pNode.handle(), 0)) {
    m_listView->setCurrentItem(item);
    m_listView->scrollToItem(item);
  }
}
Пример #8
0
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();
}
Value XMLSerializerProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
{
  if (!thisObj.inherits(&XMLSerializer::info)) {
    Object err = Error::create(exec,TypeError);
    exec->setException(err);
    return err;
  }

  switch (id) {
  case XMLSerializer::SerializeToString:
    {
      if (args.size() != 1) {
	return Undefined();
      }

      if (!args[0].toObject(exec).inherits(&DOMDocument::info)) {
	return Undefined();
      }

      DOM::Node docNode = static_cast<KJS::DOMDocument *>(args[0].toObject(exec).imp())->toNode();
      DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(docNode.handle());

      if (!doc) {
	return Undefined();
      }
	  
      QString body;

      try {
	  body = doc->toString().string();
      } catch(DOM::DOMException& e) {
	  Object err = Error::create(exec, GeneralError, "Exception serializing document");
	  exec->setException(err);
	  return err;
      }
    
      return getStringOrNull(body);
    }
  }

  return Undefined();
}
Пример #10
0
JSValue *DOMMutationEvent::getValueProperty(ExecState *exec, int token) const
{
  DOM::MutationEventImpl& event = *impl();
  switch (token) {
  case RelatedNode: {
    DOM::Node relatedNode = event.relatedNode();
    return getDOMNode(exec,relatedNode.handle());
  }
  case PrevValue:
    return jsString(event.prevValue());
  case NewValue:
    return jsString(event.newValue());
  case AttrName:
    return jsString(event.attrName());
  case AttrChange:
    return jsNumber((unsigned int)event.attrChange());
  default:
    kDebug(6070) << "WARNING: Unhandled token in DOMMutationEvent::getValueProperty : " << token;
    return 0;
  }
}
Пример #11
0
void DOMTreeView::addElement ( const DOM::Node &node,  DOMListViewItem *cur_item, bool isLast)
{
  cur_item->setClosing(isLast);

  const QString nodeName(node.nodeName().string());
  QString text;
  const DOM::Element element = node;
  if (!element.isNull()) {
    if (!m_bPure) {
      if (isLast) {
	text ="</";
      } else {
	text = "<";
      }
      text += nodeName;
    } else {
      text = nodeName;
    }

    if (m_bShowAttributes && !isLast) {
      QString attributes;
      DOM::Attr attr;
      DOM::NamedNodeMap attrs = element.attributes();
      unsigned long lmap = attrs.length();
      for( unsigned int j=0; j<lmap; j++ ) {
	attr = static_cast<DOM::Attr>(attrs.item(j));
	attributes += " " + attr.name().string() + "=\"" + attr.value().string() + "\"";
      }
      if (!(attributes.isEmpty())) {
	text += " ";
      }
      text += attributes.simplifyWhiteSpace();
    }

    if (!m_bPure) {
      if(element.firstChild().isNull()) {
	text += "/>";
      } else {
	text += ">";
      }
    }
    cur_item->setText(0, text);
  } else {
    text = "`" + node.nodeValue().string() + "'";

    // Hacks to deal with PRE
    QTextStream ts( text, IO_ReadOnly );
    while (!ts.eof()) {
      const QString txt(ts.readLine());
      const QFont font(KGlobalSettings::fixedFont());
      cur_item->setFont( font );
      cur_item->setText(0, txt);

      if(node.handle()) {
	m_itemdict.insert(node.handle(), cur_item);
      }

      DOMListViewItem *parent;
      if (cur_item->parent()) {
	parent = static_cast<DOMListViewItem *>(cur_item->parent());
      } else {
	parent = cur_item;
      }
      cur_item = new DOMListViewItem(node, parent, cur_item);
    }
    // This is one is too much
    DOMListViewItem *notLastItem = static_cast<DOMListViewItem *>(cur_item->itemAbove());
    delete cur_item;
    cur_item = notLastItem;
  }

  if (m_bHighlightHTML && node.ownerDocument().isHTMLDocument()) {
    highlightHTML(cur_item, nodeName);
  }
}
Пример #12
0
ArtSVP *LibartCanvas::clipSingleSVP(ArtSVP *svp, SVGShapeImpl *shape)
{
	ArtSVP *clippedSvp = copy_svp(svp);
	SVGStylableImpl *style = dynamic_cast<SVGStylableImpl *>(shape);

	if(style)
	{
		QString clipPathRef = style->getClipPath();

		if(!clipPathRef.isEmpty())
		{
			CanvasClipPath *clipPath = m_clipPaths[clipPathRef];

			if(clipPath)
			{
				LibartClipPath *lclip = dynamic_cast<LibartClipPath *>(clipPath);
				reinterpret_cast<SVGClipPathElementImpl *>(clipPath->element())->setBBoxTarget(shape);

				lclip->init();

				if(lclip->clipSVP())
				{
					ArtSVP *s = art_svp_intersect(lclip->clipSVP(), clippedSvp);
					art_svp_free(clippedSvp);
					clippedSvp = s;
				}
			}
		}
	}

	SVGSVGElementImpl *svg = dynamic_cast<SVGSVGElementImpl *>(shape);

	// Clip outer svg, unless width and height not set
	if(svg && (!svg->isRootElement() || !svg->getAttribute("width").isEmpty() || !svg->getAttribute("height").isEmpty()) && !svg->getOverflow())
	{
		ArtSVP *svgClip = clippingRect(svg->clip(), svg->screenCTM());
		ArtSVP *s = art_svp_intersect(svgClip, clippedSvp);
		art_svp_free(clippedSvp);
		art_svp_free(svgClip);
		clippedSvp = s;
	}

	if(dynamic_cast<SVGPatternElementImpl *>(shape) != 0)
	{
		// TODO: inherit clipping paths into tile space
	}
	else if(dynamic_cast<SVGMarkerElementImpl *>(shape) != 0)
	{
		SVGMarkerElementImpl *marker = static_cast<SVGMarkerElementImpl *>(shape);

		if(!marker->clipShape().isEmpty())
		{
			ArtSVP *clipShape = svpFromPolygon(marker->clipShape());
			ArtSVP *s = art_svp_intersect(clipShape, clippedSvp);
			art_svp_free(clipShape);
			art_svp_free(clippedSvp);
			clippedSvp = s;
		}

		// TODO: inherit clipping paths into marker space
	}
	else
	{
		SVGElementImpl *element = dynamic_cast<SVGElementImpl *>(shape);
		DOM::Node parentNode = element->parentNode();

		if(!parentNode.isNull())
		{
			SVGElementImpl *parent = element->ownerDoc()->getElementFromHandle(parentNode.handle());

			if(parent)
			{
				SVGShapeImpl *parentShape = dynamic_cast<SVGShapeImpl *>(parent);

				if(parentShape)
				{
					// Clip against ancestor clipping paths
					ArtSVP *parentClippedSvp = clipSingleSVP(clippedSvp, parentShape);
					art_svp_free(clippedSvp);
					clippedSvp = parentClippedSvp;
				}
			}
		}
	}

	return clippedSvp;
}
Пример #13
0
// collection of nodes for which to emit the nodeChanged signal
inline static bool operator <(const DOM::Node &n1, const DOM::Node &n2)
{
  return (qptrdiff)n1.handle() - (qptrdiff)n2.handle() < 0;
}
Пример #14
0
JSValue *DOMMouseEvent::getValueProperty(ExecState *exec, int token) const
{
  DOM::MouseEventImpl& event = *impl();
  switch (token) {
  case ScreenX:
    return jsNumber(event.screenX());
  case ScreenY:
    return jsNumber(event.screenY());
  case ClientX:
  case X:
    return jsNumber(event.clientX());
  case ClientY:
  case Y:
    return jsNumber(event.clientY());
  case OffsetX:
  case OffsetY: // MSIE extension
  {
    if (event.target()->eventTargetType() != EventTargetImpl::DOM_NODE)
        return jsUndefined();
    
    DOM::Node node = static_cast<NodeImpl*>(event.target());
    khtml::RenderObject *rend = 0;
    if (node.handle()) {
        node.handle()->document()->updateRendering();
        rend = node.handle()->renderer();
    }
    int x = event.clientX();
    int y = event.clientY();
    if ( rend ) {
      int xPos, yPos;
      if ( rend->absolutePosition( xPos, yPos ) ) {
        //kDebug() << "DOMMouseEvent::getValueProperty rend=" << rend << "  xPos=" << xPos << "  yPos=" << yPos;
        x -= xPos;
        y -= yPos;
      }
      if ( rend->canvas() ) {
        int cYPos, cXPos;
        rend->canvas()->absolutePosition( cXPos,  cYPos,  true );
        x += cXPos;
        y += cYPos;
      }
    }
    return jsNumber( token == OffsetX ? x : y );
  }
  case CtrlKey:
    return jsBoolean(event.ctrlKey());
  case ShiftKey:
    return jsBoolean(event.shiftKey());
  case AltKey:
    return jsBoolean(event.altKey());
  case MetaKey:
    return jsBoolean(event.metaKey());
  case Button:
  {
    if ( exec->dynamicInterpreter()->compatMode() == Interpreter::IECompat ) {
      // Tricky. The DOM (and khtml) use 0 for LMB, 1 for MMB and 2 for RMB
      // but MSIE uses 1=LMB, 2=RMB, 4=MMB, as a bitfield
      int domButton = event.button();
      int button = domButton==0 ? 1 : domButton==1 ? 4 : domButton==2 ? 2 : 0;
      return jsNumber( (unsigned int)button );
    }
    return jsNumber(event.button());
  }
  case ToElement:
    // MSIE extension - "the object toward which the user is moving the mouse pointer"
    if (event.id() == DOM::EventImpl::MOUSEOUT_EVENT)
      return getEventTarget(exec,event.relatedTarget());
    return getEventTarget(exec,event.target());
  case FromElement:
    // MSIE extension - "object from which activation
    // or the mouse pointer is exiting during the event" (huh?)
    if (event.id() == DOM::EventImpl::MOUSEOUT_EVENT)
      return getEventTarget(exec,event.target());
    /* fall through */
  case RelatedTarget:
    return getEventTarget(exec,event.relatedTarget());
  default:
    kDebug(6070) << "WARNING: Unhandled token in DOMMouseEvent::getValueProperty : " << token;
    return 0;
  }
}