예제 #1
0
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(&DOMNode::info))
            {
                return Undefined();
            }

            DOM::NodeImpl *node = static_cast< DOM::NodeImpl * >(static_cast< KJS::DOMNode * >(args[0].toObject(exec).imp())->toNode().handle());

            if(!node)
            {
                return Undefined();
            }

            QString body;

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

            return getString(body);
        }
    }

    return Undefined();
}
void KHTMLImage::updateWindowCaption()
{
    if ( !m_khtml )
        return;

    DOM::HTMLDocumentImpl *impl = dynamic_cast<DOM::HTMLDocumentImpl *>( m_khtml->document().handle() );
    if ( !impl )
        return;

    DOM::HTMLElementImpl *body = impl->body();
    if ( !body )
        return;

    DOM::NodeImpl *image = body->firstChild();
    if ( !image )
        return;

    khtml::RenderImage *renderImage = dynamic_cast<khtml::RenderImage *>( image->renderer() );
    if ( !renderImage )
        return;

    QPixmap pix = renderImage->pixmap();

    QString caption;

    KMimeType::Ptr mimeType;
    if ( !m_mimeType.isEmpty() )
        mimeType = KMimeType::mimeType( m_mimeType );

    if ( mimeType )
        caption = i18n( "%1 - %2x%3 Pixels" ).arg( mimeType->comment() )
                  .arg( pix.width() ).arg( pix.height() );
    else
        caption = i18n( "Image - %2x%3 Pixels" ).arg( pix.width() ).arg( pix.height() );

    emit setWindowCaption( caption );
    emit completed();
    emit setStatusBarText(i18n("Done."));
}
예제 #3
0
JSValue *XMLSerializerProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
{
  KJS_CHECK_THIS( XMLSerializer, thisObj );

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

      if (!args[0]->toObject(exec)->inherits(&DOMNode::info)) {
	return jsUndefined();
      }

      DOM::NodeImpl* node = static_cast<KJS::DOMNode *>(args[0]->toObject(exec))->impl();

      if (!node) {
	return jsUndefined();
      }

      DOMString body;

      try {
	  body = node->toString();
      } catch(DOM::DOMException&) {
	  JSObject *err = Error::create(exec, GeneralError, "Exception serializing document");
	  exec->setException(err);
	  return err;
      }

      return ::getStringOrNull(body);
    }
  }

  return jsUndefined();
}
예제 #4
0
파일: editor.cpp 프로젝트: KDE/khtml
bool Editor::handleKeyEvent(QKeyEvent *_ke)
{
    bool handled = false;

    bool ctrl  = _ke->modifiers() & Qt::ControlModifier;
    bool alt   = _ke->modifiers() & Qt::AltModifier;
    //bool shift = _ke->modifiers() & Qt::ShiftModifier;
    bool meta  = _ke->modifiers() & Qt::MetaModifier;

    if (ctrl || alt || meta) {
        return false;
    }

    switch (_ke->key()) {

    case Qt::Key_Delete: {
        Selection selectionToDelete = m_part->caret();
#ifdef DEBUG_COMMANDS
        // qDebug() << "========== KEY_DELETE ==========" << endl;
#endif
        if (selectionToDelete.state() == Selection::CARET) {
            Position pos(selectionToDelete.start());
#ifdef DEBUG_COMMANDS
            // qDebug() << "pos.inLastEditableInRootEditableElement " << pos.inLastEditableInRootEditableElement() << " pos.offset " << pos.offset() << " pos.max " << pos.node()->caretMaxRenderedOffset() << endl;
#endif
            if (pos.nextCharacterPosition() == pos) {
                // we're at the end of a root editable block...do nothing
#ifdef DEBUG_COMMANDS
                // qDebug() << "no delete!!!!!!!!!!" << endl;
#endif
                break;
            }
            m_part->d->editor_context.m_selection
                = Selection(pos, pos.nextCharacterPosition());
        }
        // fall through
    }
    case Qt::Key_Backspace:
        TypingCommandImpl::deleteKeyPressed0(m_part->xmlDocImpl());
        handled = true;
        break;

    case Qt::Key_Return:
    case Qt::Key_Enter:
//       if (shift)
        TypingCommandImpl::insertNewline0(m_part->xmlDocImpl());
//       else
//         TypingCommand::insertParagraph(m_part->xmlDocImpl());
        handled = true;
        break;

    case Qt::Key_Escape:
    case Qt::Key_Insert:
        // FIXME implement me
        handled = true;
        break;

    default:
// handle_input:
        if (m_part->caret().state() != Selection::CARET) {
            // We didn't get a chance to grab the caret, likely because
            // a script messed with contentEditable in the middle of events
            // acquire it now if there isn't a selection
            // qDebug() << "Editable node w/o caret!";
            DOM::NodeImpl *focus = m_part->xmlDocImpl()->focusNode();
            if (m_part->caret().state() == Selection::NONE) {
                if (focus) {
                    m_part->setCaret(Position(focus, focus->caretMinOffset()));
                } else {
                    break;
                }
            }
        }

        if (!_ke->text().isEmpty()) {
            TypingCommandImpl::insertText0(m_part->xmlDocImpl(), _ke->text());
            handled = true;
        }

    }

    //if (handled) {
    // ### check when to emit it
//     m_part->emitSelectionChanged();
    //}

    return handled;

}
bool RenderWidget::eventFilter(QObject* /*o*/, QEvent* e)
{
    if ( !element() ) return true;

    RenderArena *arena = ref();
    DOM::NodeImpl *elem = element();
    elem->ref();

    bool filtered = false;

    //kdDebug() << "RenderWidget::eventFilter type=" << e->type() << endl;
    switch(e->type()) {
    case QEvent::FocusOut:
       //static const char* const r[] = {"Mouse", "Tab", "Backtab", "ActiveWindow", "Popup", "Shortcut", "Other" };
        //kdDebug() << "RenderFormElement::eventFilter FocusOut widget=" << m_widget << " reason:" << r[QFocusEvent::reason()] << endl;
        // Don't count popup as a valid reason for losing the focus
        // (example: opening the options of a select combobox shouldn't emit onblur)
        if ( QFocusEvent::reason() != QFocusEvent::Popup )
       {
           //kdDebug(6000) << "RenderWidget::eventFilter captures FocusOut" << endl;
            if (elem->getDocument()->focusNode() == elem)
                elem->getDocument()->setFocusNode(0);
//             if (  elem->isEditable() ) {
//                 KHTMLPartBrowserExtension *ext = static_cast<KHTMLPartBrowserExtension *>( elem->view->part()->browserExtension() );
//                 if ( ext )  ext->editableWidgetBlurred( m_widget );
//             }
	    handleFocusOut();
        }
        break;
    case QEvent::FocusIn:
        //kdDebug(6000) << "RenderWidget::eventFilter captures FocusIn" << endl;
        elem->getDocument()->setFocusNode(elem);
//         if ( isEditable() ) {
//             KHTMLPartBrowserExtension *ext = static_cast<KHTMLPartBrowserExtension *>( elem->view->part()->browserExtension() );
//             if ( ext )  ext->editableWidgetFocused( m_widget );
//         }
        break;
    case QEvent::MouseButtonPress:
//       handleMousePressed(static_cast<QMouseEvent*>(e));
        break;
    case QEvent::MouseButtonRelease:
//    {
//         int absX, absY;
//         absolutePosition(absX,absY);
//         QMouseEvent* _e = static_cast<QMouseEvent*>(e);
//         m_button = _e->button();
//         m_state  = _e->state();
//         QMouseEvent e2(e->type(),QPoint(absX,absY)+_e->pos(),_e->button(),_e->state());

//         elem->dispatchMouseEvent(&e2,EventImpl::MOUSEUP_EVENT,m_clickCount);

//         if((m_mousePos - e2.pos()).manhattanLength() <= QApplication::startDragDistance()) {
//             // DOM2 Events section 1.6.2 says that a click is if the mouse was pressed
//             // and released in the "same screen location"
//             // As people usually can't click on the same pixel, we're a bit tolerant here
//             elem->dispatchMouseEvent(&e2,EventImpl::CLICK_EVENT,m_clickCount);
//         }

//         if(!isRenderButton()) {
//             // ### DOMActivate is also dispatched for thigs like selects & textareas -
//             // not sure if this is correct
//             elem->dispatchUIEvent(EventImpl::DOMACTIVATE_EVENT,m_isDoubleClick ? 2 : 1);
//             elem->dispatchMouseEvent(&e2, m_isDoubleClick ? EventImpl::KHTML_DBLCLICK_EVENT : EventImpl::KHTML_CLICK_EVENT, m_clickCount);
//             m_isDoubleClick = false;
//         }
//         else
//             // save position for slotClicked - see below -
//             m_mousePos = e2.pos();
//     }
    break;
    case QEvent::MouseButtonDblClick:
//     {
//         m_isDoubleClick = true;
//         handleMousePressed(static_cast<QMouseEvent*>(e));
//     }
    break;
    case QEvent::MouseMove:
//     {
//         int absX, absY;
//         absolutePosition(absX,absY);
//         QMouseEvent* _e = static_cast<QMouseEvent*>(e);
//         QMouseEvent e2(e->type(),QPoint(absX,absY)+_e->pos(),_e->button(),_e->state());
//         elem->dispatchMouseEvent(&e2);
//         // ### change cursor like in KHTMLView?
//     }
    break;
    case QEvent::KeyPress:
    case QEvent::KeyRelease:
    {
        if (!elem->dispatchKeyEvent(static_cast<QKeyEvent*>(e)))
            filtered = true;
        break;
    }
    default: break;
    };

    elem->deref();

    // stop processing if the widget gets deleted, but continue in all other cases
    if (hasOneRef())
        filtered = true;
    deref(arena);

    return filtered;
}