<commit_before>#include "qquickchromiumwebview.h"

QQuickChromiumWebView::QQuickChromiumWebView(QQuickItem *webview): QQuickItem(webview), _cangoback(false), _cangoforward(false), _loading(false), _buffer(NULL), _texture(NULL)
{
    this->setFlag(QQuickItem::ItemHasContents);
    this->setFlag(QQuickItem::ItemIsFocusScope);
    this->setFlag(QQuickItem::ItemAcceptsInputMethod);

    this->setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton);
    this->setAcceptHoverEvents(true);
    this->forceActiveFocus();

    this->_handler = CefRefPtr<ChromiumHandler>(new ChromiumHandler());

    connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(onWindowChanged(QQuickWindow*)));
    connect(this, SIGNAL(widthChanged()), this, SLOT(onResize()));
    connect(this, SIGNAL(heightChanged()), this, SLOT(onResize()));
}

QQuickChromiumWebView::~QQuickChromiumWebView()
{

}

bool QQuickChromiumWebView::loading() const
{
    return this->_loading;
}

bool QQuickChromiumWebView::canGoBack() const
{
    return this->_cangoback;
}

bool QQuickChromiumWebView::canGoForward() const
{
    return this->_cangoforward;
}

QString QQuickChromiumWebView::title() const
{
    return this->_title;
}

QString QQuickChromiumWebView::url() const
{
    CefRefPtr<CefBrowser> browser = this->_handler->GetBrowser();
    return QString::fromStdWString(browser->GetMainFrame()->GetURL().ToWString());
}

void QQuickChromiumWebView::setUrl(const QString &url)
{
    CefRefPtr<CefBrowser> browser = this->_handler->GetBrowser();
    browser->GetMainFrame()->LoadURL(CefString(url.toStdWString()));
}

void QQuickChromiumWebView::createBrowser()
{
    CefWindowInfo windowinfo;
    CefBrowserSettings browsersettings;

    windowinfo.SetAsWindowless(this->window()->winId(), false);
    this->_handler->SetListener(this);
    CefBrowserHost::CreateBrowserSync(windowinfo, this->_handler.get(), "https://www.google.it", browsersettings, NULL);
}

void QQuickChromiumWebView::OnAddressChange(const QString &url)
{
    emit urlChanged();
}

void QQuickChromiumWebView::OnTitleChange(const QString &title)
{
    this->_title = title;

    emit titleChanged();
}

void QQuickChromiumWebView::SetLoading(bool isloading)
{
    if(this->_loading == isloading)
        return;

    this->_loading = isloading;
    emit loadingChanged();
}

void QQuickChromiumWebView::SetNavState(bool cangoback, bool cangoforward)
{
    if(this->_cangoback != cangoback)
    {
        this->_cangoback = cangoback;
        emit canGoBackChanged();
    }

    if(this->_cangoforward != cangoforward)
    {
        this->_cangoforward = cangoforward;
        emit canGoForwardChanged();
    }
}

void QQuickChromiumWebView::OnAfterCreated()
{

}

bool QQuickChromiumWebView::GetViewRect(CefRect &rect)
{
    QQuickWindow* window = this->window();

    rect.Set(window->x(), window->y(), this->width(), this->height());
    return true;
}

void QQuickChromiumWebView::OnPaint(CefRenderHandler::PaintElementType type, const CefRenderHandler::RectList &dirtyrects, const void *buffer, int width, int height)
{
    if(type != PET_VIEW)
        return;

    this->_buffer = buffer;
    this->_texwidth = width;
    this->_texheight = height;
    this->update();
}

void QQuickChromiumWebView::OnMessageEvent(ChromiumMessageEvent *e)
{
    qDebug() << Q_FUNC_INFO << e->name();
}

void QQuickChromiumWebView::focusInEvent(QFocusEvent *focusevent)
{
    CefRefPtr<CefBrowser> browser = this->_handler->GetBrowser();
    browser->GetHost()->SendFocusEvent(true);
}

void QQuickChromiumWebView::focusOutEvent(QFocusEvent *focusevent)
{
    CefRefPtr<CefBrowser> browser = this->_handler->GetBrowser();
    browser->GetHost()->SendFocusEvent(false);
}

void QQuickChromiumWebView::mousePressEvent(QMouseEvent *mouseevent)
{
    CefMouseEvent cefmouseevent;
    cefmouseevent.x = mouseevent->x();<commit_msg>QQuickWebView: Force Active Focus when WebView is clicked<commit_after>#include "qquickchromiumwebview.h"

QQuickChromiumWebView::QQuickChromiumWebView(QQuickItem *webview): QQuickItem(webview), _cangoback(false), _cangoforward(false), _loading(false), _buffer(NULL), _texture(NULL)
{
    this->setFlag(QQuickItem::ItemHasContents);
    this->setFlag(QQuickItem::ItemIsFocusScope);
    this->setFlag(QQuickItem::ItemAcceptsInputMethod);

    this->setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton);
    this->setAcceptHoverEvents(true);
    this->forceActiveFocus();

    this->_handler = CefRefPtr<ChromiumHandler>(new ChromiumHandler());

    connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(onWindowChanged(QQuickWindow*)));
    connect(this, SIGNAL(widthChanged()), this, SLOT(onResize()));
    connect(this, SIGNAL(heightChanged()), this, SLOT(onResize()));
}

QQuickChromiumWebView::~QQuickChromiumWebView()
{

}

bool QQuickChromiumWebView::loading() const
{
    return this->_loading;
}

bool QQuickChromiumWebView::canGoBack() const
{
    return this->_cangoback;
}

bool QQuickChromiumWebView::canGoForward() const
{
    return this->_cangoforward;
}

QString QQuickChromiumWebView::title() const
{
    return this->_title;
}

QString QQuickChromiumWebView::url() const
{
    CefRefPtr<CefBrowser> browser = this->_handler->GetBrowser();
    return QString::fromStdWString(browser->GetMainFrame()->GetURL().ToWString());
}

void QQuickChromiumWebView::setUrl(const QString &url)
{
    CefRefPtr<CefBrowser> browser = this->_handler->GetBrowser();
    browser->GetMainFrame()->LoadURL(CefString(url.toStdWString()));
}

void QQuickChromiumWebView::createBrowser()
{
    CefWindowInfo windowinfo;
    CefBrowserSettings browsersettings;

    windowinfo.SetAsWindowless(this->window()->winId(), false);
    this->_handler->SetListener(this);
    CefBrowserHost::CreateBrowserSync(windowinfo, this->_handler.get(), "https://www.google.it", browsersettings, NULL);
}

void QQuickChromiumWebView::OnAddressChange(const QString &url)
{
    emit urlChanged();
}

void QQuickChromiumWebView::OnTitleChange(const QString &title)
{
    this->_title = title;

    emit titleChanged();
}

void QQuickChromiumWebView::SetLoading(bool isloading)
{
    if(this->_loading == isloading)
        return;

    this->_loading = isloading;
    emit loadingChanged();
}

void QQuickChromiumWebView::SetNavState(bool cangoback, bool cangoforward)
{
    if(this->_cangoback != cangoback)
    {
        this->_cangoback = cangoback;
        emit canGoBackChanged();
    }

    if(this->_cangoforward != cangoforward)
    {
        this->_cangoforward = cangoforward;
        emit canGoForwardChanged();
    }
}

void QQuickChromiumWebView::OnAfterCreated()
{

}

bool QQuickChromiumWebView::GetViewRect(CefRect &rect)
{
    QQuickWindow* window = this->window();

    rect.Set(window->x(), window->y(), this->width(), this->height());
    return true;
}

void QQuickChromiumWebView::OnPaint(CefRenderHandler::PaintElementType type, const CefRenderHandler::RectList &dirtyrects, const void *buffer, int width, int height)
{
    if(type != PET_VIEW)
        return;

    this->_buffer = buffer;
    this->_texwidth = width;
    this->_texheight = height;
    this->update();
}

void QQuickChromiumWebView::OnMessageEvent(ChromiumMessageEvent *e)
{
    qDebug() << Q_FUNC_INFO << e->name();
}

void QQuickChromiumWebView::focusInEvent(QFocusEvent *focusevent)
{
    CefRefPtr<CefBrowser> browser = this->_handler->GetBrowser();
    browser->GetHost()->SendFocusEvent(true);
}

void QQuickChromiumWebView::focusOutEvent(QFocusEvent *focusevent)
{
    CefRefPtr<CefBrowser> browser = this->_handler->GetBrowser();
    browser->GetHost()->SendFocusEvent(false);
}

void QQuickChromiumWebView::mousePressEvent(QMouseEvent *mouseevent)
{
    this->forceActiveFocus();

    CefMouseEvent cefmouseevent;
    cefmouseevent.x = mouseevent->x();
{'fraction_non_alphanumeric': 0.13649700216864397, 'fraction_numerical': 0.0, 'mean_word_length': 5.5278934221482094, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 114, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3858268', 'n_tokens_mistral': 2608, 'n_tokens_neox': 2570, 'n_words': 385}