1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
// Copyright (C) 2013 Canonical Ltd.
4
// This library is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU Lesser General Public
6
// License as published by the Free Software Foundation; either
7
// version 2.1 of the License, or (at your option) any later version.
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// Lesser General Public License for more details.
14
// You should have received a copy of the GNU Lesser General Public
15
// License along with this library; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
#include "oxide_qt_web_view_host_qquick.h"
22
#include <QQuickWindow>
26
#include "base/logging.h"
27
#include "content/public/browser/web_contents.h"
28
#include "ui/gfx/rect.h"
29
#include "ui/gfx/size.h"
31
#include "oxide/browser/oxide_web_contents_view.h"
33
#include "oxide_qt_render_widget_host_view_qquick.h"
34
#include "oxide_qt_web_view_host_delegate.h"
41
WebViewHostQQuick::WebViewHostQQuick(QQuickItem* container,
42
WebViewHostDelegate* delegate) :
43
container_(container),
44
delegate_(delegate) {}
46
void WebViewHostQQuick::OnURLChanged() {
47
delegate_->OnURLChanged();
50
void WebViewHostQQuick::OnTitleChanged() {
51
delegate_->OnTitleChanged();
54
void WebViewHostQQuick::OnLoadingChanged() {
55
delegate_->OnLoadingChanged();
58
void WebViewHostQQuick::OnCommandsUpdated() {
59
delegate_->OnCommandsUpdated();
62
WebViewHostQQuick::~WebViewHostQQuick() {}
64
WebViewHostQQuick* WebViewHostQQuick::Create(QQuickItem* container,
65
WebViewHostDelegate* delegate,
67
const QSizeF& initial_size,
69
CHECK(container && delegate) <<
70
"Invalid parameters to WebViewHostQQuick::Create";
72
WebViewHostQQuick* wvh = new WebViewHostQQuick(container, delegate);
73
if (!wvh->Init(incognito,
74
gfx::Size(initial_size.toSize().width(),
75
initial_size.toSize().height()))) {
80
static_cast<oxide::WebContentsView *>(
81
wvh->web_contents()->GetView())->SetDelegate(wvh);
83
visible ? wvh->WasShown() : wvh->WasHidden();
88
void WebViewHostQQuick::UpdateSize(const QSizeF& size) {
89
oxide::WebViewHost::UpdateSize(gfx::Size(size.toSize().width(),
90
size.toSize().height()));
93
content::RenderWidgetHostView* WebViewHostQQuick::CreateViewForWidget(
94
content::RenderWidgetHost* render_widget_host) {
95
return new RenderWidgetHostViewQQuick(render_widget_host, container_);
98
gfx::Rect WebViewHostQQuick::GetContainerBounds() {
99
QPointF pos(container_->mapToScene(QPointF(0,0)));
100
pos += QPointF(container_->window()->x(), container_->window()->y());
102
return gfx::Rect(qRound(pos.x()),
104
qRound(container_->width()),
105
qRound(container_->height()));