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

📄 kwqkhtmlpart.cpp

📁 手机浏览器源码程序,功能强大
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        DocumentImpl *doc = xmlDocImpl();
        if (!doc)
            return;
        doc->dispatchHTMLEvent(EventImpl::SCROLL_EVENT, true, false);
    }
}

void KWQKHTMLPart::runJavaScriptAlert(const QString &message)
{
    QString text = message;
    text.replace(QChar('\\'), backslashAsCurrencySymbol());

    _bridge->Client().RunJavaScriptAlertPanelWithMessage(text.Des());
}

bool KWQKHTMLPart::runJavaScriptConfirm(const QString &message, const QString &yes, const QString &no)
{
    QString text = message;
    text.replace(QChar('\\'), backslashAsCurrencySymbol());

    return _bridge->Client().RunJavaScriptConfirmPanelWithMessage(text.Des(), yes.Des(), no.Des());
}



bool KWQKHTMLPart::runJavaScriptPrompt(const QString &prompt, const QString &defaultValue, QString &result)
{
    QString promptText = prompt;
    promptText.replace(QChar('\\'), backslashAsCurrencySymbol());
    QString defaultValueText = defaultValue;
    defaultValueText.replace(QChar('\\'), backslashAsCurrencySymbol());

    HBufC *returnedText = 0;

    bool ok = _bridge->Client().RunJavaScriptTextInputPanelWithPrompt(prompt.Des(),
	       defaultValue.Des(), &returnedText);

    if (ok ) {
        result = QString::FromDes(*returnedText);
        result.replace(backslashAsCurrencySymbol(), QChar('\\'));

        delete returnedText;
    }

    return ok;
}

bool KWQKHTMLPart::locationbarVisible()
{
    //return [_bridge areToolbarsVisible];
    return false;
}

bool KWQKHTMLPart::menubarVisible()
{
    return false;
}

bool KWQKHTMLPart::personalbarVisible()
{
    //return [_bridge areToolbarsVisible];
    return false;
}

bool KWQKHTMLPart::scrollbarsVisible()
{
    if (!view())
        return false;

    if (view()->hScrollBarMode() == QScrollView::AlwaysOff || view()->vScrollBarMode() == QScrollView::AlwaysOff)
        return false;

    return true;
}

bool KWQKHTMLPart::statusbarVisible()
{
    //return [_bridge isStatusBarVisible];
    return false;
}

bool KWQKHTMLPart::toolbarVisible()
{
    //return [_bridge areToolbarsVisible];
    return false;
}

void KWQKHTMLPart::addMessageToConsole(const QString &message, unsigned lineNumber, const QString &sourceURL)
{
// ### NOT IMPLEMENTED javascript console
/*
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
        message.getNSString(), @"message",
        [NSNumber numberWithInt: lineNumber], @"lineNumber",
        sourceURL.getNSString(), @"sourceURL",
        NULL];
    [_bridge addMessageToConsole:dictionary];
*/
}

void KWQKHTMLPart::createEmptyDocument()
{
// could not figure out the need for this function
#if 0
    // Although it's not completely clear from the name of this function,
    // it does nothing if we already have a document, and just creates an
    // empty one if we have no document at all.
    if (!d->m_doc) {
	    _bridge->Client().LoadEmptyDocumentSynchronously();

	if (parentPart() && (parentPart()->childFrame(this)->m_type == ChildFrame::IFrame ||
			     parentPart()->childFrame(this)->m_type == ChildFrame::Object)) {
	    d->m_doc->setBaseURL(parentPart()->d->m_doc->baseURL());
	}
    }
#endif
}

void KWQKHTMLPart::addMetaData(const QString &key, const QString &value)
{
    d->m_job->addMetaData(key, value);
}

static bool IsSpecialKey( TUint aKeyCode )
{
    bool status = false;

    if ( aKeyCode >= ENonCharacterKeyBase && aKeyCode <= EKeyApplication1F ) {
          status = true;
    }
    return status;
}

bool KWQKHTMLPart::KeyEvent(const TKeyEvent& event, bool keyup)
{
    // Check for cases where we are too early for events -- possible unmatched key up
    // from pressing return in the location bar.
    DocumentImpl *doc = xmlDocImpl();
    if (!doc) {
        return false;
    }
    NodeImpl *node = doc->focusNode();
    if (!node) {
        node = doc->body();
        if (!node)
            return false;
    }

    //NSEvent *oldCurrentEvent = _currentEvent;
    //_currentEvent = KWQRetain(event);
	bool result;

    QEvent::Type evtype = keyup?QEvent::KeyRelease:QEvent::KeyPress;

    QKeyEvent qEvent(evtype, event);

    result = !node->dispatchKeyEvent(&qEvent);

    // We want to send both a down and a press for the initial key event.
    // To get KHTML to do this, we send a second KeyPress QKeyEvent with "is repeat" set to true,
    // which causes it to send a press to the DOM.
    // That's not a great hack; it would be good to do this in a better way.
    if (!keyup && !event.iRepeats && !IsSpecialKey( event.iCode )) {
        QKeyEvent repeatEvent(QEvent::KeyPress, event, true);
        if (!node->dispatchKeyEvent(&repeatEvent)) {
            result = true;
	    }
    }

    //ASSERT(_currentEvent == event);
    //KWQRelease(event);
    //_currentEvent = oldCurrentEvent;

    return result;
}

bool KWQKHTMLPart::activateEvent()
{
    // from pressing return in the location bar.
    DocumentImpl *doc = xmlDocImpl();
    if (!doc) {
        return false;
    }
    NodeImpl *focusNode = doc->focusNode();
    if (!focusNode) {
        focusNode = doc->body();
        if (!focusNode)
            return false;
    }

    focusNode->ref();

    // TODO for select element - EElementSelectBox
    // should be element node
    if (focusNode->isElementNode()) {

        NodeImpl::Id id  = idFromNode(focusNode);
        if(id  ==  ID_TEXTAREA) {
            if(!static_cast<RenderWidget*>(focusNode->renderer())->widget()->isActive()) {
                static_cast<RenderWidget*>(focusNode->renderer())->widget()->activate();
            }
        }
        else if (id  ==  ID_INPUT)  {
            HTMLInputElementImpl* inputElement = static_cast<HTMLInputElementImpl *>(focusNode);
            if(inputElement->inputType() == HTMLInputElementImpl::TEXT ||
                inputElement->inputType() == HTMLInputElementImpl::PASSWORD ||
                inputElement->inputType() == HTMLInputElementImpl::RADIO ||
                inputElement->inputType() == HTMLInputElementImpl::CHECKBOX ||
                inputElement->inputType() == HTMLInputElementImpl::FILE){
                if(!static_cast<RenderWidget*>(focusNode->renderer())->widget()->isActive()) {
                    static_cast<RenderWidget*>(focusNode->renderer())->widget()->activate();
                }
            }
        }
        else if (id  ==  ID_SELECT)  {
            if(!static_cast<RenderWidget*>(focusNode->renderer())->widget()->isActive()) {
                static_cast<RenderWidget*>(focusNode->renderer())->widget()->activate();
            }

        }
        else if ((id  ==  ID_OBJECT) || (id  ==  ID_EMBED)) {
            if(focusNode->renderer()->isWidget()) {
               if(!static_cast<RenderWidget*>(focusNode->renderer())->widget()->isActive()) {
               static_cast<RenderWidget*>(focusNode->renderer())->widget()->activate();
               }
            }
        }
    }


    if(focusNode->renderer() && focusNode->renderer()->isWidget()) {
      static_cast<RenderWidget*>(focusNode->renderer())->widget()->clicked();
    } else if (focusNode->isHTMLElement() )  {
      static_cast<HTMLElementImpl*>(focusNode)->click(false);
    }

    focusNode->deref();

    return true;

}


void KWQKHTMLPart::activateNodeAtPoint(const QPoint &point)
{
    RenderObject::NodeInfo renderInfo(true, false);
    renderer()->layer()->hitTest(renderInfo, point.x(), point.y());

    NodeImpl *navNode = renderInfo.innerNode();
    bool activate  = false;

    for (; navNode; navNode = navNode->parentNode()) {
        if (navNode->isElementNode() && navNode->isFocusable()) {
            bool canBeFocused = true;
            switch (navNode->id()) {
                case ID_INPUT:
                     {
                     HTMLInputElementImpl* inputElement = static_cast<HTMLInputElementImpl *>(navNode);
                     activate = inputElement &&
                               (inputElement->inputType() == HTMLInputElementImpl::TEXT ||
                                inputElement->inputType() == HTMLInputElementImpl::PASSWORD ||
                                inputElement->inputType() == HTMLInputElementImpl::RADIO ||
                                inputElement->inputType() == HTMLInputElementImpl::CHECKBOX ||
                                inputElement->inputType() == HTMLInputElementImpl::FILE);
                     break;
                     }
                case ID_SELECT:
                case ID_TEXTAREA:
                     activate = true;
                     break;
                case ID_OBJECT:
                case ID_EMBED:
                     activate = navNode->renderer()->isWidget();
                     break;
                default:
                     canBeFocused = false;
                     break;
            }//End switch statement

            if(canBeFocused) {
               break;
            }
        }
        if (navNode->isElementNode() && navNode->renderer() &&
            navNode->renderer()->layer()) {
            QScrollBar* hbar = navNode->renderer()->layer()->horizontalScrollbar();
            QScrollBar* vbar = navNode->renderer()->layer()->verticalScrollbar();
            if (hbar)
                hbar->clickAtPoint(point);
            if (vbar)
                vbar->clickAtPoint(point);
        }
    }

    if(navNode) {
       navNode->ref();
       if(navNode->renderer() && navNode->renderer()->isWidget()) {
            QWidget* w = static_cast<RenderWidget*>(navNode->renderer())->widget();
            if (w) {
                w->clicked();
				xmlDocImpl()->setFocusNode( navNode );
                //Get the focus node again as it may have to set to NULL because of onfocus="blur()"
	            NodeImpl* focusNode = xmlDocImpl()->focusNode();
	            if(focusNode && activate && !w->isActive())
                    w->activate();
            }
       }
       else if(navNode->isHTMLElement())  {
          static_cast<HTMLElementImpl*>(navNode)->click(false);
		  xmlDocImpl()->setFocusNode( navNode );
       }
       navNode->deref();
    }
}

void KWQKHTMLPart::deActivateEvent(bool acceptChanges)
{
  DocumentImpl* docImpl = view()->part()->xmlDocImpl();
  if(docImpl){
      NodeImpl* focusNode = docImpl->focusNode();

      // TODO for select element - EElementSelectBox
      // should be element node
      if(focusNode && focusNode->isElementNode()) {

          NodeImpl::Id id  = idFromNode(focusNode);
          if(id  ==  ID_TEXTAREA) {
              if(static_cast<RenderWidget*>(focusNode->renderer())->widget()->isActive()) {
                  static_cast<RenderWidget*>(focusNode->renderer())->widget()->deActivate(acceptChanges);
                  focusNode->dispatchHTMLEvent(DOM::EventImpl::BLUR_EVENT, false, false);
                  focusNode->dispatchUIEvent(DOM::EventImpl::DOMFOCUSOUT_EVENT);
              }
          }
          else if (id  ==  ID_INPUT)  {
              HTMLInputElementImpl* inputElement = static_cast<HTMLInputElementImpl *>(focusNode);
              if(inputElement->inputType() == HTMLInputElementImpl::TEXT ||
                inputElement->inputType() == HTMLInputElementImpl::PASSWORD){
                  if(static_cast<RenderWidget*>(focusNode->renderer())->widget()->isActive()) {
                      static_cast<RenderWidget*>(focusNode->renderer())->widget()->deActivate(acceptChanges);
                      focusNode->dispatchHTMLEvent(DOM::EventImpl::BLUR_EVENT, false, false);
                      focusNode->dispatchUIEvent(DOM::EventImpl::DOMFOCUSOUT_EVENT);
                  }
              }
          }
          else if ((id  ==  ID_OBJECT) || (id  ==  ID_EMBED)) {
              if(static_cast<RenderWidget*>(focusNode->renderer())->widget()->isActive()) {
                  static_cast<RenderWidget*>(focusNode->renderer())->widget()->deActivate(acceptChanges);
              }
          }
      }
   }
}



// This does the same kind of work that KHTMLPart::openURL does, except it relies on the fact
// that a higher level already checked that the URLs match and the scrolling is the right thing to do.
void KWQKHTMLPart::scrollToAnchor(const KURL &URL)
{
    m_url = URL;
    started(0);

    gotoAnchor();

    // It's important to model this as a load that starts and immediately finishes.
    // Otherwise, the parent frame may think we never finished loading.
    d->m_bComplete = false;
    checkCompleted();
}

bool KWQKHTMLPart::closeURL()
{
    saveDocumentState();
    return KHTMLPart::closeURL();
}



void KWQKHTMLPart::khtmlMousePressEvent(MousePressEvent *event)
{
// ### NOT IMPLEMENTED events
/*
    bool singleClick = [_currentEvent clickCount] <= 1;

    // If we got the event back, that must mean it wasn't prevented,
    // so it's allowed to start a drag or selection.
    _mouseDownMayStartSelect = true;
    _mouseDownMayStartDrag = singleClick;

    if (!passWidgetMouseDownEventToWidget(event)) {
        // We don't do this at the start of mouse down handling (before calling into WebCore),
        // because we don't want to do it until we know we didn't hit a widget.
        NSView *view = d->m_view->getDocumentVie

⌨️ 快捷键说明

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