⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html_inlineimpl.cpp

📁 最新Nokia手机浏览器全套源代码完美版。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/**
 * This file is part of the DOM implementation for KDE.
 *
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
 *           (C) 2000 Simon Hausmann <hausmann@kde.org>
 * Copyright (C) 2003 Apple Computer, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
// -------------------------------------------------------------------------

#include "html/html_inlineimpl.h"
#include "html/html_imageimpl.h"
#include "html/html_documentimpl.h"

#include "misc/htmlhashes.h"
#include "khtmlview.h"
#include "khtml_part.h"
#include "css/csshelper.h"
#include "css/cssproperties.h"
#include "css/cssvalues.h"
#include "css/cssstyleselector.h"
#include "xml/dom2_eventsimpl.h"
#include "rendering/render_br.h"
#include "rendering/render_image.h"
#include "KWQPhoneNumberParser.h"

#include <kdebug.h>

using namespace khtml;
using namespace DOM;

HTMLAnchorElementImpl::HTMLAnchorElementImpl(DocumentPtr *doc)
    : HTMLElementImpl(doc)
{
    m_hasTarget = false;
    m_soundstart = 0;
}

HTMLAnchorElementImpl::~HTMLAnchorElementImpl()
{
#if NOKIA_CHANGES
    if (m_soundstart) {
        delete m_soundstart;
    }
#endif
}

bool HTMLAnchorElementImpl::isFocusable() const
{
    if (isContentEditable())
        return HTMLElementImpl::isFocusable();

    // FIXME: Even if we are not visible, we might have a child that is visible.
    // Dave wants to fix that some day with a "has visible content" flag or the like.
    if (!(m_hasAnchor && m_render && m_render->style()->visibility() == VISIBLE))
        return false;

    // Before calling absoluteRects, check for the common case where the renderer
    // or one of the continuations is non-empty, since this is a faster check and
    // almost always returns true.
    for (RenderObject *r = m_render; r; r = r->continuation()) {
        if (r->width() > 0 && r->height() > 0)
            return true;
    }

    QValueList<QRect> rects;
    int x = 0, y = 0;
    m_render->absolutePosition(x, y);
    m_render->absoluteRects(rects, x, y);
    for (QValueList<QRect>::ConstIterator it = rects.begin(); it != rects.end(); ++it) {
        if ((*it).isValid())
            return true;
    }
    
    return false;
}

bool HTMLAnchorElementImpl::isMouseFocusable() const
{
#if APPLE_CHANGES
    return false;
#else
    return isFocusable();
#endif
}

bool HTMLAnchorElementImpl::isKeyboardFocusable() const
{
    if (!isFocusable())
        return false;
    
    if (!getDocument()->part())
  return false;

    return getDocument()->part()->tabsToLinks();
}

NodeImpl::Id HTMLAnchorElementImpl::id() const
{
    return ID_A;
}

void HTMLAnchorElementImpl::defaultEventHandler(EventImpl *evt)
{
#if NOKIA_CHANGES
    if (m_focused || evt->id() == EventImpl::MOUSEOVER_EVENT) {
        // Handle soundstart on focus
        if (m_soundstart && m_soundstart->onFocus && m_soundstart->qWidget) {
            
            KURL completedUrl;
            if (!m_soundstart->srcUrl.isEmpty()) {
                completedUrl = getDocument()->part()->completeURL(m_soundstart->srcUrl);
                if (!completedUrl.isEmpty()) {
                    m_soundstart->qWidget->playContent(completedUrl.url());
                }
            }
        }
    }
#endif
    // React on clicks and on keypresses.
    // Don't make this KEYUP_EVENT again, it makes khtml follow links it shouldn't,
    // when pressing Enter in the combo.
    if ( ( evt->id() == EventImpl::KHTML_CLICK_EVENT ||
         ( evt->id() == EventImpl::KEYDOWN_EVENT && m_focused)) && m_hasAnchor) {
#if NOKIA_CHANGES
        // Handle soundstart on select
        if (m_soundstart && m_soundstart->onSelect && m_soundstart->qWidget) {
            
            KURL completedUrl;
            if (!m_soundstart->srcUrl.isEmpty()) {
                completedUrl = getDocument()->part()->completeURL(m_soundstart->srcUrl);
                if (!completedUrl.isEmpty()) {
                    m_soundstart->qWidget->playContent(completedUrl.url());
                }
            }
        }
#endif
        MouseEventImpl *e = 0;
        if ( evt->id() == EventImpl::KHTML_CLICK_EVENT )
            e = static_cast<MouseEventImpl*>( evt );

        KeyboardEventImpl *k = 0;
        if (evt->id() == EventImpl::KEYDOWN_EVENT)
            k = static_cast<KeyboardEventImpl *>( evt );

        QString utarget;
        QString url;

        if ( e && e->button() == 2 ) {
      HTMLElementImpl::defaultEventHandler(evt);
      return;
        }

        if ( k ) {
            if (k->keyIdentifier() != "Enter") {
                HTMLElementImpl::defaultEventHandler(evt);
                return;
            }
            if (k->qKeyEvent()) {
                k->qKeyEvent()->accept();
                evt->setDefaultHandled();
                click(false);
                return;
            }
        }
        url = khtml::parseURL(getAttribute(ATTR_HREF)).string();
        
#if NOKIA_CHANGES
      // Check if there is a cti attribute. If yes, construct the wtai url
        if (!getAttribute(ATTR_CTI).string().isNull()) {
          QString number = getAttribute(ATTR_CTI).string();
          number = number.stripWhiteSpace();
          
        QString makeCallUrlPrefix("wtai://wp/mc;");
        
        QString ctiUrl;
        ctiUrl.reserve( makeCallUrlPrefix.length() + number.length());
          ctiUrl.append(makeCallUrlPrefix);
        ctiUrl.append(number);
        url = ctiUrl;
        }
#endif        
        utarget = getAttribute(ATTR_TARGET).string();

        if ( e && e->button() == 1 )
            utarget = "_blank";

        if ( evt->target()->id() == ID_IMG ) {
            HTMLImageElementImpl* img = static_cast<HTMLImageElementImpl*>( evt->target() );
            if ( img && img->isServerMap() )
            {
                khtml::RenderImage *r = static_cast<khtml::RenderImage *>(img->renderer());
                if(r && e)
                {
                    int absx, absy;
                    r->absolutePosition(absx, absy);
                    int x(e->clientX() - absx), y(e->clientY() - absy);
                    url += QString("?%1,%2").arg( x ).arg( y );
                }
                else {
                    evt->setDefaultHandled();
        HTMLElementImpl::defaultEventHandler(evt);
        return;
                }
            }
        }
        if ( !evt->defaultPrevented() ) {
            int state = 0;
            int button = 0;

            if ( e ) {
                if ( e->ctrlKey() )
                    state |= Qt::ControlButton;
                if ( e->shiftKey() )
                    state |= Qt::ShiftButton;
                if ( e->altKey() )
                    state |= Qt::AltButton;
                if ( e->metaKey() )
                    state |= Qt::MetaButton;

                if ( e->button() == 0 )
                    button = Qt::LeftButton;
                else if ( e->button() == 1 )
                    button = Qt::MidButton;
                else if ( e->button() == 2 )
                    button = Qt::RightButton;
            }
      else if ( k )
      {
        if ( k->shiftKey() )
                state |= Qt::ShiftButton;
        if ( k->altKey() )
                state |= Qt::AltButton;
        if ( k->ctrlKey() )
                state |= Qt::ControlButton;
      }
      
            if (getDocument() && getDocument()->view() && getDocument()->part()) {
                getDocument()->view()->resetCursor();
                getDocument()->part()->
                    urlSelected( url, button, state, utarget );
            }
        }
        evt->setDefaultHandled();
    }
    HTMLElementImpl::defaultEventHandler(evt);
}


void HTMLAnchorElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr)
{
  DOMString attrValue = attr->value();
  switch(attr->id())
    {
    case ATTR_HREF:
        m_hasAnchor = !attr->isNull();
#if NOKIA_CHANGES
    {
        const char* telString = "tel:";
          // Check if tel number is valid. If not, the anchor is not focussable
            if ( !attrValue.isNull() && 
              attrValue.string().startsWith(telString)) {
              if ( !parseNumber(attrValue.string().mid(4), false)) {
              m_hasAnchor = false;   
              }
            }
    }
#endif        
        break;
    case ATTR_TARGET:
        m_hasTarget = !attr->isNull();
        break;
#if NOKIA_CHANGES
    case ATTR_CTI:
        {
      // Check if cti number is valid. If not, the anchor is not focussable
      if (!attrValue.isNull()) {
          if ( parseNumber(attrValue.string(), true) ) {
            m_hasAnchor = true;   
          }
      }
      break;
        }
    case ATTR_SOUNDSTART:
        {
        if (!m_soundstart) {
            // Create a Soundstart data structure, if not break
            m_soundstart = new SoundstartData;
            if (!m_soundstart) break;
        }
        QString soundstartName(getAttrName(ATTR_SOUNDSTART).string().lower());
        // Default soundstart value is select
        QString soundstartValue("select");
        m_soundstart->onSelect = true;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -