~oxide-developers/oxide/1.2

« back to all changes in this revision

Viewing changes to oxide-qt/core/browser/oxide_qt_web_view_host_qquick.cc

  • Committer: Chris Coulson
  • Date: 2013-07-23 11:40:24 UTC
  • Revision ID: chris.coulson@canonical.com-20130723114024-p7z00cs9p0s5te6e
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim:expandtab:shiftwidth=2:tabstop=2:
 
2
// Copyright (C) 2013 Canonical Ltd.
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
 
 
18
#include "oxide_qt_web_view_host_qquick.h"
 
19
 
 
20
#include <QPointF>
 
21
#include <QQuickItem>
 
22
#include <QQuickWindow>
 
23
#include <QSize>
 
24
#include <QSizeF>
 
25
 
 
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"
 
30
 
 
31
#include "oxide/browser/oxide_web_contents_view.h"
 
32
 
 
33
#include "oxide_qt_render_widget_host_view_qquick.h"
 
34
#include "oxide_qt_web_view_host_delegate.h"
 
35
 
 
36
QT_USE_NAMESPACE
 
37
 
 
38
namespace oxide {
 
39
namespace qt {
 
40
 
 
41
WebViewHostQQuick::WebViewHostQQuick(QQuickItem* container,
 
42
                                     WebViewHostDelegate* delegate) :
 
43
    container_(container),
 
44
    delegate_(delegate) {}
 
45
 
 
46
void WebViewHostQQuick::OnURLChanged() {
 
47
  delegate_->OnURLChanged();
 
48
}
 
49
 
 
50
void WebViewHostQQuick::OnTitleChanged() {
 
51
  delegate_->OnTitleChanged();
 
52
}
 
53
 
 
54
void WebViewHostQQuick::OnLoadingChanged() {
 
55
  delegate_->OnLoadingChanged();
 
56
}
 
57
 
 
58
void WebViewHostQQuick::OnCommandsUpdated() {
 
59
  delegate_->OnCommandsUpdated();
 
60
}
 
61
 
 
62
WebViewHostQQuick::~WebViewHostQQuick() {}
 
63
 
 
64
WebViewHostQQuick* WebViewHostQQuick::Create(QQuickItem* container,
 
65
                                             WebViewHostDelegate* delegate,
 
66
                                             bool incognito,
 
67
                                             const QSizeF& initial_size,
 
68
                                             bool visible) {
 
69
  CHECK(container && delegate) <<
 
70
      "Invalid parameters to WebViewHostQQuick::Create";
 
71
 
 
72
  WebViewHostQQuick* wvh = new WebViewHostQQuick(container, delegate);
 
73
  if (!wvh->Init(incognito,
 
74
                 gfx::Size(initial_size.toSize().width(),
 
75
                           initial_size.toSize().height()))) {
 
76
    delete wvh;
 
77
    return NULL;
 
78
  }
 
79
 
 
80
  static_cast<oxide::WebContentsView *>(
 
81
      wvh->web_contents()->GetView())->SetDelegate(wvh);
 
82
 
 
83
  visible ? wvh->WasShown() : wvh->WasHidden();
 
84
 
 
85
  return wvh;
 
86
}
 
87
 
 
88
void WebViewHostQQuick::UpdateSize(const QSizeF& size) {
 
89
  oxide::WebViewHost::UpdateSize(gfx::Size(size.toSize().width(),
 
90
                                           size.toSize().height()));
 
91
}
 
92
 
 
93
content::RenderWidgetHostView* WebViewHostQQuick::CreateViewForWidget(
 
94
    content::RenderWidgetHost* render_widget_host) {
 
95
  return new RenderWidgetHostViewQQuick(render_widget_host, container_);
 
96
}
 
97
 
 
98
gfx::Rect WebViewHostQQuick::GetContainerBounds() {
 
99
  QPointF pos(container_->mapToScene(QPointF(0,0)));
 
100
  pos += QPointF(container_->window()->x(), container_->window()->y());
 
101
 
 
102
  return gfx::Rect(qRound(pos.x()),
 
103
                   qRound(pos.y()),
 
104
                   qRound(container_->width()),
 
105
                   qRound(container_->height()));
 
106
}
 
107
 
 
108
} // namespace qt
 
109
} // namespace oxide