Esempio n. 1
0
static bool aspect_ratioMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part,  MediaFeaturePrefix op)
{
    if (value) {
        KHTMLPart *rootPart = part;
        while (rootPart->parentPart()) {
            rootPart = rootPart->parentPart();
        }
        DOM::DocumentImpl *doc =  static_cast<DOM::DocumentImpl *>(rootPart->document().handle());
        QPaintDevice *pd = doc->paintDevice();
        bool printing = pd ? (pd->devType() == QInternal::Printer) : false;
        QSize vs;
        int h = 0, v = 0;
        if (printing) {
            vs = QSize(pd->width(), pd->height());
        } else {
            vs = QSize(part->view()->visibleWidth(), part->view()->visibleHeight());
        }
        if (parseAspectRatio(value, h, v)) {
            return v != 0  && compareValue(vs.width() * v, vs.height() * h, op);
        }
        return false;
    }
    // ({,min-,max-}aspect-ratio)
    // assume if we have a viewport, its aspect ratio is non-zero
    return true;
}
Esempio n. 2
0
static bool orientationMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part,  MediaFeaturePrefix /*op*/)
{
    if (value) {
        CSSPrimitiveValueImpl *pv = static_cast<CSSPrimitiveValueImpl *>(value);
        if (!value->isPrimitiveValue() || pv->primitiveType() != CSSPrimitiveValue::CSS_IDENT ||
                (pv->getIdent() != CSS_VAL_PORTRAIT && pv->getIdent() != CSS_VAL_LANDSCAPE)) {
            return false;
        }

        KHTMLPart *rootPart = part;
        while (rootPart->parentPart()) {
            rootPart = rootPart->parentPart();
        }
        DOM::DocumentImpl *doc =  static_cast<DOM::DocumentImpl *>(rootPart->document().handle());
        QPaintDevice *pd = doc->paintDevice();
        bool printing = pd ? (pd->devType() == QInternal::Printer) : false;
        if (printing) {
            if (pd->width() > pd->height()) {
                return (pv->getIdent() == CSS_VAL_LANDSCAPE);
            }
        } else {
            if (part->view()->visibleWidth() > part->view()->visibleHeight()) {
                return (pv->getIdent() == CSS_VAL_LANDSCAPE);
            }
        }
        return (pv->getIdent() == CSS_VAL_PORTRAIT);
    }
    return false;
}
Esempio n. 3
0
static bool device_aspect_ratioMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part,  MediaFeaturePrefix op)
{
    if (value) {
        KHTMLPart *rootPart = part;
        while (rootPart->parentPart()) {
            rootPart = rootPart->parentPart();
        }
        DOM::DocumentImpl *doc =  static_cast<DOM::DocumentImpl *>(rootPart->document().handle());
        QPaintDevice *pd = doc->paintDevice();
        bool printing = pd ? (pd->devType() == QInternal::Printer) : false;
        QRect sg;
        int h = 0, v = 0;
        if (printing) {
            sg = QRect(0, 0, pd->width(), pd->height());
        } else {
            sg = QApplication::desktop()->screen(QApplication::desktop()->screenNumber(rootPart->view()))->rect();
        }
        if (parseAspectRatio(value, h, v)) {
            return v != 0  && compareValue(sg.width() * v, sg.height() * h, op);
        }
        return false;
    }

    // ({,min-,max-}device-aspect-ratio)
    // assume if we have a device, its aspect ratio is non-zero
    return true;
}
Esempio n. 4
0
static bool colorMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part,  MediaFeaturePrefix op)
{
    KHTMLPart *rootPart = part;
    while (rootPart->parentPart()) {
        rootPart = rootPart->parentPart();
    }
    DOM::DocumentImpl *doc =  static_cast<DOM::DocumentImpl *>(rootPart->document().handle());
    QPaintDevice *pd = doc->paintDevice();
    bool printing = pd ? (pd->devType() == QInternal::Printer) : false;
    int bitsPerComponent = 0;
    if (printing) {
        if (pd->colorCount() > 2) {
            bitsPerComponent = pd->depth() / 3;
        }
        // assume printer is either b&w or color.
    } else {
        int sn = QApplication::desktop()->screenNumber(rootPart->view());
        if (QColormap::instance(sn).mode() != QColormap::Gray) {
            bitsPerComponent = QApplication::desktop()->screen(sn)->depth() / 3;
        }
    }
    if (value && bitsPerComponent) {
        float number = 0;
        return numberValue(value, number) && compareValue(bitsPerComponent, static_cast<int>(number), op);
    }
    return bitsPerComponent;
}
Esempio n. 5
0
static bool color_indexMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part,  MediaFeaturePrefix op)
{
    KHTMLPart *rootPart = part;
    while (rootPart->parentPart()) {
        rootPart = rootPart->parentPart();
    }
    DOM::DocumentImpl *doc =  static_cast<DOM::DocumentImpl *>(rootPart->document().handle());
    QPaintDevice *pd = doc->paintDevice();
    bool printing = pd ? (pd->devType() == QInternal::Printer) : false;
    unsigned int numColors = 0;
    if (printing) {
        numColors = pd->colorCount();
    } else {
        int sn = QApplication::desktop()->screenNumber(rootPart->view());
        numColors = QApplication::desktop()->screen(sn)->colorCount();
    }
    if (numColors == INT_MAX) {
        numColors = UINT_MAX;
    }
    if (value) {
        float number = 0;
        return numberValue(value, number) && compareValue(numColors, static_cast<unsigned int>(number), op);
    }

    return numColors;
}
Esempio n. 6
0
void HTMLFrameElementImpl::setLocation(const DOMString &str)
{

    url = str;

    if(!attached())
        return;

    if(!m_render)
    {
        detach();
        attach();
        return;
    }

    if(!getDocument()->isURLAllowed(url.string()))
        return;

    // load the frame contents
    KHTMLView *w = getDocument()->view();
    if(w)
    {
        KHTMLPart *part = w->part()->findFrame(name.string());
        if(part)
        {
            part->openURL(KURL(getDocument()->completeURL(url.string())));
        }
        else
        {
            w->part()->requestFrame(static_cast< RenderFrame * >(m_render), url.string(), name.string());
        }
    }
}
bool HTMLElementImpl::isURLAllowed(const QString& url) const
{
    KHTMLView *w = getDocument()->view();

    KURL newURL(getDocument()->completeURL(url));
    newURL.setRef(QString::null);

    // Prohibit non-file URLs if we are asked to.
    if (!w || w->part()->onlyLocalReferences() && newURL.protocol() != "file")
        return false;

    // do we allow this suburl ?
    if ( !kapp || !kapp->kapp->authorizeURLAction("redirect", w->part()->url(), newURL) )
        return false;

    // We allow one level of self-reference because some sites depend on that.
    // But we don't allow more than one.
    bool foundSelfReference = false;
    for (KHTMLPart *part = w->part(); part; part = part->parentPart()) {
        KURL partURL = part->url();
        partURL.setRef(QString::null);
        if (partURL == newURL) {
            if (foundSelfReference)
                return false;
            foundSelfReference = true;
        }
    }

    return true;
}
Esempio n. 8
0
void JSEventListener::handleEvent(DOM::Event &evt)
{
  KHTMLPart *part = qobject_cast<KHTMLPart*>(static_cast<Window*>(win.get())->part());
  KJSProxy *proxy = 0L;
  if (part)
    proxy = part->jScript();

  if (proxy && listener && listener->implementsCall()) {
#ifdef KJS_DEBUGGER
  //### This is the wrong place to do this --- we need 
  // a more global/general stategy to prevent unwanted event loop recursion issues.
    if (proxy->debugEnabled() && DebugWindow::window()->inSession())
      return;
#endif
    ref();

    KJS::ScriptInterpreter *interpreter = static_cast<KJS::ScriptInterpreter *>(proxy->interpreter());
    ExecState *exec = interpreter->globalExec();

    List args;
    args.append(getDOMEvent(exec,evt.handle()));

    JSObject *thisObj = 0;
    // Check whether handler is a function or an object with handleEvent method
    if (listener == compareListenerImp) {
      // Set "this" to the event's current target
      thisObj = getEventTarget(exec,evt.handle()->currentTarget())->getObject();
    } else {
      thisObj = compareListenerImp;
    }

    if ( !thisObj ) {
      // ### can this still happen? eventTarget should be window on Window events now.
      thisObj = win;
    }

    Window *window = static_cast<Window*>(win.get());
    // Set the event we're handling in the Window object
    window->setCurrentEvent( evt.handle() );
    // ... and in the interpreter
    interpreter->setCurrentEvent( &evt );

    interpreter->startCPUGuard();
    JSValue *retval = listener->call(exec, thisObj, args);
    interpreter->stopCPUGuard();

    window->setCurrentEvent( 0 );
    interpreter->setCurrentEvent( 0 );
    if ( exec->hadException() )
      exec->clearException();
    else if (html)
    {
      QVariant ret = ValueToVariant(exec, retval);
      if (ret.type() == QVariant::Bool && ret.toBool() == false)
        evt.preventDefault();
    }
    window->afterScriptExecution();
    deref();
  }
}
Esempio n. 9
0
Value MozillaSidebarExtensionFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
{
    KJS_CHECK_THIS(KJS::MozillaSidebarExtension, thisObj);
    MozillaSidebarExtension *mse = static_cast< MozillaSidebarExtension * >(thisObj.imp());

    KHTMLPart *part = mse->part();
    if(!part)
        return Undefined();

    // addPanel()  id == 0
    KParts::BrowserExtension *ext = part->browserExtension();
    if(ext)
    {
        QString url, name;
        if(args.size() == 1)
        {   // I've seen this, don't know if it's legal.
            name = QString::null;
            url = args[0].toString(exec).qstring();
        }
        else if(args.size() == 2 || args.size() == 3)
        {
            name = args[0].toString(exec).qstring();
            url = args[1].toString(exec).qstring();
            // 2 is the "CURL" which I don't understand and don't think we need.
        }
        else
        {
            return Boolean(false);
        }
        emit ext->addWebSideBar(KURL(url), name);
        return Boolean(true);
    }

    return Undefined();
}
Esempio n. 10
0
void RootView::AttachedToWindow()
{
	SetViewColor( 216,216,216 );
	mURLView->SetDivider( 40 );
	mTopView->show();
	
	AddChild( mURLView );
	AddChild( mTopView );
	AddChild( mStatusBar );

	KHTMLPart *htmlPart = new KHTMLPart( mTopView, "khtmlpart" );

	KHTMLView* pcView = htmlPart->view();
	
	BRect rect = mTopView->Bounds();
	pcView->SetResizingMode( B_FOLLOW_ALL );
	pcView->MoveTo( rect.LeftTop() );
	pcView->ResizeTo( rect.Width(), rect.Height() );
//	pcView->MakeFocus( true );
	pcView->SetTarget( BMessenger( Window() ) );
	pcView->show();
	
	BrowserWindow *bw = (BrowserWindow *)Window();
	bw->SetPart( htmlPart );
	bw->SetStatusBar( mStatusBar );
	bw->SetURLView( mURLView );
	
}
Esempio n. 11
0
static bool monochromeMediaFeatureEval(CSSValueImpl* value, RenderStyle*, KHTMLPart* part,  MediaFeaturePrefix op)
{
    KHTMLPart* rootPart = part;
    while (rootPart->parentPart()) rootPart = rootPart->parentPart();
    DOM::DocumentImpl *doc =  static_cast<DOM::DocumentImpl*>(rootPart->document().handle());
    QPaintDevice *pd = doc->paintDevice(); 
    bool printing = pd ? (pd->devType() == QInternal::Printer) : false;
    int depth = 0;
    if (printing) {
        if (pd->numColors() < 2)
            depth = 1;
        // assume printer is either b&w or color.
    } else {
        int sn = QApplication::desktop()->screenNumber( rootPart->view() );
        if (QApplication::desktop()->screen(sn)->depth() == 1)
            depth = 1;
        else if (QColormap::instance(sn).mode() == QColormap::Gray)
            depth = QApplication::desktop()->screen(sn)->depth();
    }
    if (value)
    {
        float number = 0;
        return numberValue(value, number) && compareValue(depth, static_cast<int>(number), op);
    }
    return depth;
}
bool HTMLEmbedElementImpl::rendererIsNeeded(RenderStyle *style)
{
    KHTMLPart *part = getDocument()->part();
    if (!part)
	return false;
    return part->pluginsEnabled() && parentNode()->id() != ID_OBJECT;
}
Esempio n. 13
0
KHTMLImage::KHTMLImage(QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, KHTMLPart::GUIProfile prof)
    : KParts::ReadOnlyPart(parent, name), m_image(0)
{
    KHTMLPart *parentPart = ::qt_cast< KHTMLPart * >(parent);
    setInstance(KHTMLImageFactory::instance(), prof == KHTMLPart::BrowserViewGUI && !parentPart);

    QVBox *box = new QVBox(parentWidget, widgetName);

    m_khtml = new KHTMLPart(box, widgetName, this, "htmlimagepart", prof);
    m_khtml->setAutoloadImages(true);
    m_khtml->widget()->installEventFilter(this);
    connect(m_khtml->view(), SIGNAL(finishedLayout()), this, SLOT(restoreScrollPosition()));

    setWidget(box);

    // VBox can't take focus, so pass it on to sub-widget
    box->setFocusProxy(m_khtml->widget());

    m_ext = new KHTMLImageBrowserExtension(this, "be");

    // Remove unnecessary actions.
    KAction *encodingAction = actionCollection()->action("setEncoding");
    if(encodingAction)
    {
        encodingAction->unplugAll();
        delete encodingAction;
    }
    KAction *viewSourceAction = actionCollection()->action("viewDocumentSource");
    if(viewSourceAction)
    {
        viewSourceAction->unplugAll();
        delete viewSourceAction;
    }

    KAction *selectAllAction = actionCollection()->action("selectAll");
    if(selectAllAction)
    {
        selectAllAction->unplugAll();
        delete selectAllAction;
    }

    // forward important signals from the khtml part

    // forward opening requests to parent frame (if existing)
    KHTMLPart *p = ::qt_cast< KHTMLPart * >(parent);
    KParts::BrowserExtension *be = p ? p->browserExtension() : m_ext;
    connect(m_khtml->browserExtension(), SIGNAL(openURLRequestDelayed(const KURL &, const KParts::URLArgs &)), be,
            SIGNAL(openURLRequestDelayed(const KURL &, const KParts::URLArgs &)));

    connect(m_khtml->browserExtension(),
            SIGNAL(popupMenu(KXMLGUIClient *, const QPoint &, const KURL &, const KParts::URLArgs &, KParts::BrowserExtension::PopupFlags, mode_t)),
            m_ext,
            SIGNAL(popupMenu(KXMLGUIClient *, const QPoint &, const KURL &, const KParts::URLArgs &, KParts::BrowserExtension::PopupFlags, mode_t)));

    connect(m_khtml->browserExtension(), SIGNAL(enableAction(const char *, bool)), m_ext, SIGNAL(enableAction(const char *, bool)));

    m_ext->setURLDropHandlingEnabled(true);
}
Esempio n. 14
0
void HTMLLinkElementImpl::process()
{
    if(!inDocument())
        return;

    QString type = getAttribute(ATTR_TYPE).string().lower();
    QString rel = getAttribute(ATTR_REL).string().lower();

    KHTMLPart *part = getDocument()->view() ? getDocument()->view()->part() : 0;

    // IE extension: location of small icon for locationbar / bookmarks
    // Uses both "shortcut icon" and "icon"
    if(part && rel.contains("icon") && !m_url.isEmpty() && !part->parentPart())
        part->browserExtension()->setIconURL(KURL(m_url.string()));

    // Stylesheet
    else if(!m_isDisabled && (type.contains("text/css") || rel.contains("stylesheet")))
    {
        // no need to load style sheets which aren't for the screen output
        // ### there may be in some situations e.g. for an editor or script to manipulate
        if(m_media.isNull() || m_media.contains("screen") || m_media.contains("all") || m_media.contains("print"))
        {
            m_loading = true;
            // Add ourselves as a pending sheet, but only if we aren't an alternate
            // stylesheet.  Alternate stylesheets don't hold up render tree construction.
            m_alternate = rel.contains("alternate");
            if(!isAlternate())
                getDocument()->addPendingSheet();

            QString chset = getAttribute(ATTR_CHARSET).string();
            // set chset to charset of referring document when attribute CHARSET is absent.
            // http://www.w3.org/TR/CSS21/syndata.html(4.4)
            if(chset.isEmpty() && part)
                chset = part->encoding();
            if(m_cachedSheet)
                m_cachedSheet->deref(this);
            m_cachedSheet = getDocument()->docLoader()->requestStyleSheet(m_url, chset);
            if(m_cachedSheet)
            {
                m_isCSSSheet = true;
                m_cachedSheet->ref(this);
            }
            else if(!isAlternate())
            {
                // Error requesting sheet; decrement pending sheet count
                getDocument()->styleSheetLoaded();
            }
        }
    }
    else if(m_sheet)
    {
        // we no longer contain a stylesheet, e.g. perhaps rel or type was changed
        m_sheet->deref();
        m_sheet = 0;
        m_isCSSSheet = false;
        getDocument()->updateStyleSelector();
    }
}
Esempio n. 15
0
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();
}
Esempio n. 16
0
void BrowserWindow::OpenURL( const std::string& cURL, const KParts::URLArgs& cArgs )
{
//	GlobalMutex::Lock();
	
//	m_pcURLView->Set( cURL.c_str(), false );
	m_pcURLView->SetText( cURL.c_str() );
	m_pcHTMLPart->browserExtension()->setURLArgs( cArgs );

	m_pcHTMLPart->openURL( cURL.c_str() );
//	GlobalMutex::Unlock();
	
}
Esempio n. 17
0
KHTMLImage::KHTMLImage( QWidget *parentWidget,
                        QObject *parent, KHTMLPart::GUIProfile prof )
    : KParts::ReadOnlyPart( parent ), m_image( 0 )
{
    KHTMLPart* parentPart = qobject_cast<KHTMLPart*>( parent );
    setComponentData( KHTMLImageFactory::componentData(), prof == KHTMLPart::BrowserViewGUI && !parentPart );

    KVBox *box = new KVBox( parentWidget );
    box->setAcceptDrops( true );

    m_khtml = new KHTMLPart( box, this, prof );
    m_khtml->setAutoloadImages( true );

    // We do not want our subpart to be destroyed when its widget is,
    // since that may cause all KHTMLParts to die when we're dealing
    // with
    m_khtml->setAutoDeletePart( false );

    connect( m_khtml->view(), SIGNAL(finishedLayout()), this, SLOT(restoreScrollPosition()) );

    setWidget( box );

    // VBox can't take focus, so pass it on to sub-widget
    box->setFocusProxy( m_khtml->widget() );

    m_ext = new KHTMLImageBrowserExtension( this );
    m_ext->setObjectName( "be" );

    m_sbExt = new KParts::StatusBarExtension( this );
    m_sbExt->setObjectName( "sbe" );

    // Remove unnecessary actions.
    delete actionCollection()->action( "setEncoding" );
    delete actionCollection()->action( "viewDocumentSource" );
    delete actionCollection()->action( "selectAll" );

    // forward important signals from the khtml part

    // forward opening requests to parent frame (if existing)
    KHTMLPart *p = qobject_cast<KHTMLPart*>(parent);
    KParts::BrowserExtension *be = p ? p->browserExtension() : m_ext;
    connect(m_khtml->browserExtension(), SIGNAL(openUrlRequestDelayed(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)),
               be, SIGNAL(openUrlRequestDelayed(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)));

    connect(m_khtml->browserExtension(), SIGNAL(popupMenu(QPoint,KUrl,mode_t,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)),
            this, SLOT(slotPopupMenu(QPoint,KUrl,mode_t,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)));

    connect( m_khtml->browserExtension(), SIGNAL(enableAction(const char*,bool)),
             m_ext, SIGNAL(enableAction(const char*,bool)) );

    m_ext->setURLDropHandlingEnabled( true );
}
Esempio n. 18
0
Audio::Audio(ExecState *exec, DOM::DocumentImpl* d, const QString& url)
 :  m_doc(d), 
    m_cs(0),
    m_qObj(new AudioQObject(this)),
    m_onLoadListener(0), 
    m_onErrorListener(0)
{
    setPrototype(AudioProto::self(exec));
    KHTMLPart *part = qobject_cast<KHTMLPart*>(Window::retrieveActive(exec)->part());
    if (part)
        m_url = part->htmlDocument().completeURL(url).string();
    m_cs = m_doc->docLoader()->requestSound( DOM::DOMString(m_url) );
}
Esempio n. 19
0
void Plugin$ {APP_NAME}::slotAction()
{
    // This plugin assumes KHTMLPart.  If your plugin can handle more
    // than this or a different Part than this, simply delete or
    // change the following block.
    if ( !parent()->inherits("KHTMLPart") )
    {
        QString title( i18n( "Cannot Translate Source" ) );
        QString text( i18n( "You cannot translate anything except web pages "
                            "with this plugin." ) );

        KMessageBox::sorry( 0, text, title );
        return;
    }

    // Get a handle on our parent so we may get the necessary data for
    // processing
    KHTMLPart *part = dynamic_cast<KHTMLPart *>(parent());

    // This plugin only uses the URL.  You may use whatever data you
    // need.
    KURL url( part->url() );

    // This is a standard check to make sure we are dealing with a
    // valid URL
    if ( !url.isValid() )
    {
        QString title( i18n( "Malformed URL" ) );
        QString text( i18n( "The URL you entered is not valid, please "
                            "correct it and try again." ) );

        KMessageBox::sorry( 0, text, title );
        return;
    }

// The following block is very plugin specific.  In this example, we
// translate the current page with AltaVista's BabelFish.  You will
// definitely want to change this.
// BEGIN
    KURL work( "http://babel.altavista.com/translate.dyn" );

    QString query( "urltext=" );
    query += KURL::encode_string( url.url() );
    work.setQuery( query );
// END

    // Finally, execute the request
    part->openURL( work );
}
void RenderPartObject::slotPartLoadingErrorNotify()
{
#if APPLE_CHANGES
    // FIXME: What are we going to do for this case?
#else
    // First we need to find out the servicetype - again - this code is too duplicated !
    HTMLEmbedElementImpl *embed = 0;
    QString serviceType;
    if( element()->id()==ID_OBJECT ) {

        // check for embed child object
        HTMLObjectElementImpl *o = static_cast<HTMLObjectElementImpl *>(element());
        serviceType = o->serviceType;
        NodeImpl *child = o->firstChild();
        while ( child ) {
            if ( child->id() == ID_EMBED )
                embed = static_cast<HTMLEmbedElementImpl *>( child );

            child = child->nextSibling();
        }

    } else if( element()->id()==ID_EMBED ) {
        embed = static_cast<HTMLEmbedElementImpl *>(element());
    }
    if ( embed )
	serviceType = embed->serviceType;

    KHTMLPart *part = static_cast<KHTMLView *>(m_view)->part();
    KParts::BrowserExtension *ext = part->browserExtension();
    if( embed && !embed->pluginPage.isEmpty() && ext ) {
        // Prepare the mimetype to show in the question (comment if available, name as fallback)
        QString mimeName = serviceType;
        KMimeType::Ptr mime = KMimeType::mimeType(serviceType);
        if ( mime->name() != KMimeType::defaultMimeType() )
            mimeName = mime->comment();
        // Prepare the URL to show in the question (host only if http, to make it short)
        KURL pluginPageURL( embed->pluginPage );
        QString shortURL = pluginPageURL.protocol() == "http" ? pluginPageURL.host() : pluginPageURL.prettyURL();
        int res = KMessageBox::questionYesNo( m_view,
            i18n("No plugin found for '%1'.\nDo you want to download one from %2?").arg(mimeName).arg(shortURL),
	    i18n("Missing plugin"), QString::null, QString::null, QString("plugin-")+serviceType);
	if ( res == KMessageBox::Yes )
	{
          // Display vendor download page
          ext->createNewWindow( pluginPageURL );
	}
    }
#endif // APPLE_CHANGES
}
Esempio n. 21
0
void BrowserWindow::UpdateHistory()
{	
	HistoryEntry* pcCurrent = HistoryCurrent();
	if ( pcCurrent == NULL ) {
		pcCurrent = new HistoryEntry;
		m_nCurHistoryPos = m_cHistory.size();
		m_cHistory.push_back( pcCurrent );
	} else {
		pcCurrent->m_cState.MakeEmpty();
	}
	GlobalMutex::PushLooper( this );
	m_pcHTMLPart->browserExtension()->saveState( &pcCurrent->m_cState );
	pcCurrent->m_cURL = m_pcHTMLPart->url().prettyURL().utf8().data(); // m_pcURLView->GetBuffer()[0];
	GlobalMutex::PopLooper();
}
Esempio n. 22
0
void BrowserWindow::GoHistory( int nStep )
{

//	if ( nStep != 0 ) {
//	UpdateHistory();
//	}
	m_nCurHistoryPos += nStep;
	HistoryEntry* pcCurrent = HistoryCurrent();
	if ( pcCurrent != NULL ) {
		GlobalMutex::PushLooper( this );
		m_pcHTMLPart->browserExtension()->restoreState( pcCurrent->m_cState );
		m_pcURLView->Set( pcCurrent->m_cURL.c_str(), false );
		GlobalMutex::PopLooper();
	}
	if ( m_nCurHistoryPos == 0 ) {
	m_pcToolBar->EnableButton( BI_BACK, false );
	} else {
	m_pcToolBar->EnableButton( BI_BACK, true );
	}
	if ( m_nCurHistoryPos >= int(m_cHistory.size()) - 1 ) {
	m_pcToolBar->EnableButton( BI_FORWARD, false );
	} else {
	m_pcToolBar->EnableButton( BI_FORWARD, true );
	}
}
Esempio n. 23
0
void BrowserWindow::SetLocationBarURL( const std::string &/*cURL*/ )
{
//	m_pcURLView->Set( m_pcHTMLPart->url().prettyURL().utf8().data(), false );
	m_pcURLView->SetText( m_pcHTMLPart->url().prettyURL().utf8().data() );
//??	m_pcURLView->SetText( cURL.c_str() );
//	m_pcURLView->Set( cURL.c_str(), false );
}
Esempio n. 24
0
RenderApplet::RenderApplet(HTMLElementImpl *applet, const QMap<QString, QString> &args )
    : RenderWidget(applet)
{
    // init RenderObject attributes
    setInline(true);

    KJavaAppletContext *context = 0;
    KHTMLView *_view = applet->getDocument()->view();
    if ( _view ) {
        KHTMLPart *part = _view->part();
        context = part->createJavaContext();
    }

    if ( context ) {
        //kdDebug(6100) << "RenderApplet::RenderApplet, setting QWidget" << endl;
        setQWidget( new KJavaAppletWidget(context, _view->viewport()) );
        processArguments(args);
    }
}
Esempio n. 25
0
static bool heightMediaFeatureEval(CSSValueImpl* value, RenderStyle* style, KHTMLPart* part,  MediaFeaturePrefix op)
{
    KHTMLPart* rootPart = part;
    while (rootPart->parentPart()) rootPart = rootPart->parentPart();
    DOM::DocumentImpl *doc =  static_cast<DOM::DocumentImpl*>(rootPart->document().handle());
    QPaintDevice *pd = doc->paintDevice(); 
    bool printing = pd ? (pd->devType() == QInternal::Printer) : false;
    int height;
    if (printing)
        height = pd->height();
    else {
        height = part->view()->visibleHeight();
        doc = static_cast<DOM::DocumentImpl*>(part->document().handle());
    }
    int logicalDpiY = doc->logicalDpiY();
    if (value)
        return value->isPrimitiveValue() && compareValue(height, static_cast<CSSPrimitiveValueImpl*>(value)->computeLength(style, logicalDpiY), op);

    return height > 0;
}
KJS::Bindings::Instance *HTMLAppletElementImpl::getAppletInstance() const
{
    KHTMLPart* part = getDocument()->part();
    if (!part || !part->javaEnabled())
        return 0;

    if (appletInstance)
        return appletInstance;
    
    RenderApplet *r = static_cast<RenderApplet*>(m_render);
    if (r) {
        r->createWidgetIfNecessary();
        if (r->widget()){
            // Call into the part (and over the bridge) to pull the Bindings::Instance
            // from the guts of the plugin.
            void *_view = r->widget()->getView();
            appletInstance = KWQ(part)->getAppletInstanceForView((NSView *)_view);
        }
    }
    return appletInstance;
}
void HTMLLinkElementImpl::process()
{
    if (!inDocument())
        return;

    QString type = m_type.string().lower();
    QString rel = m_rel.string().lower();

    KHTMLPart* part = getDocument()->part();

    // IE extension: location of small icon for locationbar / bookmarks
#if APPLE_CHANGES
    if ( part && rel == "shortcut icon" && !m_url.isEmpty() && !part->parentPart())
    	part->browserExtension()->setIconURL( KURL(m_url.string()) );

    // Mozilla extension to IE extension: icon specified with type
    if ( part && rel == "icon" && !m_url.isEmpty() && !part->parentPart())
    	part->browserExtension()->setTypedIconURL( KURL(m_url.string()), type );
#else
    // Uses both "shortcut icon" and "icon"
   
    if ( part && rel.contains("icon") && !m_url.isEmpty() && !part->parentPart())
        part->browserExtension()->setIconURL( KURL(m_url.string()) );
#endif

    // Stylesheet
    // This was buggy and would incorrectly match <link rel="alternate">, which has a different specified meaning. -dwh
    if(m_disabledState != 2 && (type.contains("text/css") || rel == "stylesheet" || (rel.contains("alternate") && rel.contains("stylesheet"))) && getDocument()->part()) {
        // no need to load style sheets which aren't for the screen output
        // ### there may be in some situations e.g. for an editor or script to manipulate
	// also, don't load style sheets for standalone documents
        if( m_media.isNull() || m_media.contains("screen") || m_media.contains("all") || m_media.contains("print") ) {
            m_loading = true;

            // Add ourselves as a pending sheet, but only if we aren't an alternate 
            // stylesheet.  Alternate stylesheets don't hold up render tree construction.
            m_alternate = rel.contains("alternate");
            if (!isAlternate())
                getDocument()->addPendingSheet();
            
            QString chset = getAttribute( ATTR_CHARSET ).string();
            if (m_cachedSheet)
                m_cachedSheet->deref(this);
            m_cachedSheet = getDocument()->docLoader()->requestStyleSheet(m_url, chset);
            if (m_cachedSheet)
                m_cachedSheet->ref(this);
        }
    }
    else if (m_sheet) {
        // we no longer contain a stylesheet, e.g. perhaps rel or type was changed
        m_sheet->deref();
        m_sheet = 0;
        getDocument()->updateStyleSelector();
    }
}
Esempio n. 28
0
bool KHTMLImage::eventFilter(QObject *, QEvent *e)
{
    switch(e->type())
    {
        case QEvent::DragEnter:
        case QEvent::DragMove:
        case QEvent::DragLeave:
        case QEvent::Drop:
        {
            // find out if this part is embedded in a frame, and send the
            // event to its outside widget
            KHTMLPart *p = ::qt_cast< KHTMLPart * >(parent());
            if(p)
                return QApplication::sendEvent(p->widget(), e);
            // otherwise simply forward all dnd events to the part widget,
            // konqueror will handle them properly there
            return QApplication::sendEvent(widget(), e);
        }
        default:;
    }
    return false;
}
Esempio n. 29
0
static bool device_widthMediaFeatureEval(CSSValueImpl* value, RenderStyle* style, KHTMLPart* part,  MediaFeaturePrefix op)
{
    if (value) {
        KHTMLPart* rootPart = part;
        while (rootPart->parentPart()) rootPart = rootPart->parentPart();
        DOM::DocumentImpl *doc =  static_cast<DOM::DocumentImpl*>(rootPart->document().handle());
        QPaintDevice *pd = doc->paintDevice(); 
        bool printing = pd ? (pd->devType() == QInternal::Printer) : false;
        int width;
        if (printing)
            width = pd->width();
        else {
            width = QApplication::desktop()->screen(QApplication::desktop()->screenNumber( rootPart->view() ))->rect().width();
            doc = static_cast<DOM::DocumentImpl*>(part->document().handle());
        }
        int logicalDpiY = doc->logicalDpiY();
        return value->isPrimitiveValue() && compareValue(width, static_cast<CSSPrimitiveValueImpl*>(value)->computeLength(style,logicalDpiY), op);
    }
    // ({,min-,max-}device-width)
    // assume if we have a device, assume non-zero
    return true;
}
RenderObject *HTMLAppletElementImpl::createRenderer(RenderArena *arena, RenderStyle *style)
{
#ifndef Q_WS_QWS // FIXME(E)? I don't think this is possible with Qt Embedded...
    KHTMLPart *part = getDocument()->part();

    if( part && part->javaEnabled() )
    {
	QMap<QString, QString> args;

	args.insert( "code", getAttribute(ATTR_CODE).string());
	DOMString codeBase = getAttribute(ATTR_CODEBASE);
	if(!codeBase.isNull())
	    args.insert( "codeBase", codeBase.string() );
	DOMString name = getDocument()->htmlMode() != DocumentImpl::XHtml ?
			 getAttribute(ATTR_NAME) : getAttribute(ATTR_ID);
	if(!name.isNull())
	    args.insert( "name", name.string() );
	DOMString archive = getAttribute(ATTR_ARCHIVE);
	if(!archive.isNull())
	    args.insert( "archive", archive.string() );

	args.insert( "baseURL", getDocument()->baseURL() );

        DOMString mayScript = getAttribute(ATTR_MAYSCRIPT);
        if (!mayScript.isNull())
            args.insert("mayScript", mayScript.string());

        // Other arguments (from <PARAM> tags) are added later.
        
        return new (getDocument()->renderArena()) RenderApplet(this, args);
    }

    // ### remove me. we should never show an empty applet, instead
    // render the alternative content given by the webpage
    return new (getDocument()->renderArena()) RenderEmptyApplet(this);
#else
    return 0;
#endif
}