~oxide-developers/oxide/14.04

« back to all changes in this revision

Viewing changes to qt/lib/browser/oxide_qquick_web_view.cc

  • Committer: Chris Coulson
  • Date: 2013-07-26 22:30:14 UTC
  • Revision ID: chris.coulson@canonical.com-20130726223014-22diaj17fd9luojc
Get rid of liboxideprivate.so. It doesn't really make any sense to split functionality between 2 libraries and then have to expose private implementation details across API boundaries. Now we have a single public library exposing the QtQuick API, and a tiny Qml plugin to register the types

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include "oxide_qquick_web_view.h"
19
19
 
 
20
#include <QPointF>
 
21
#include <QQuickWindow>
20
22
#include <QRectF>
21
 
 
22
 
#include "oxide-qt/core/browser/oxide_qt_web_view_host_qquick.h"
23
 
#include "oxide-qt/core/browser/oxide_qt_web_view_host_delegate.h"
 
23
#include <QSize>
 
24
 
 
25
#include "content/public/browser/web_contents.h"
 
26
#include "ui/gfx/size.h"
 
27
 
 
28
#include "shared/browser/oxide_web_contents_view.h"
 
29
#include "shared/browser/oxide_web_contents_view_delegate.h"
 
30
#include "shared/browser/oxide_web_view_host.h"
 
31
 
 
32
#include "oxide_qt_render_widget_host_view_qquick.h"
24
33
 
25
34
QT_USE_NAMESPACE
26
35
 
31
40
  QUrl url;
32
41
};
33
42
 
34
 
class OxideQQuickWebViewPrivate : public oxide::qt::WebViewHostDelegate {
 
43
class OxideQQuickWebViewPrivate FINAL :
 
44
    public oxide::WebViewHost,
 
45
    public oxide::WebContentsViewDelegate {
35
46
  Q_DECLARE_PUBLIC(OxideQQuickWebView)
36
47
 
37
48
 public:
38
49
  OxideQQuickWebViewPrivate(OxideQQuickWebView* view) :
39
 
      oxide::qt::WebViewHostDelegate(),
 
50
      oxide::WebViewHost(),
 
51
      oxide::WebContentsViewDelegate(),
40
52
      q_ptr(view) {}
41
53
 
42
 
  void OnURLChanged();
43
 
  void OnTitleChanged();
44
 
  void OnLoadingChanged();
45
 
  void OnCommandsUpdated();
 
54
  void UpdateVisibility();
 
55
 
 
56
  content::RenderWidgetHostView* CreateViewForWidget(
 
57
      content::RenderWidgetHost* render_widget_host) FINAL;
 
58
 
 
59
  gfx::Rect GetContainerBounds() FINAL;
 
60
 
 
61
  QScopedPointer<InitData> init_props_;
 
62
 
 
63
 private:
 
64
  void OnURLChanged() FINAL;
 
65
  void OnTitleChanged() FINAL;
 
66
  void OnLoadingChanged() FINAL;
 
67
  void OnCommandsUpdated() FINAL;
46
68
 
47
69
  OxideQQuickWebView* q_ptr;
48
 
  QScopedPointer<oxide::qt::WebViewHostQQuick> web_view_host_;
49
 
  QScopedPointer<InitData> init_props_;
50
70
};
51
71
 
52
72
void OxideQQuickWebViewPrivate::OnURLChanged() {
73
93
  emit q->commandsUpdated();
74
94
}
75
95
 
 
96
void OxideQQuickWebViewPrivate::UpdateVisibility() {
 
97
  Q_Q(OxideQQuickWebView);
 
98
 
 
99
  if (q->isVisible()) {
 
100
    Shown();
 
101
  } else {
 
102
    Hidden();
 
103
  }  
 
104
}
 
105
 
 
106
content::RenderWidgetHostView* OxideQQuickWebViewPrivate::CreateViewForWidget(
 
107
    content::RenderWidgetHost* render_widget_host) {
 
108
  Q_Q(OxideQQuickWebView);
 
109
 
 
110
  return new oxide::qt::RenderWidgetHostViewQQuick(render_widget_host, q);
 
111
}
 
112
 
 
113
gfx::Rect OxideQQuickWebViewPrivate::GetContainerBounds() {
 
114
  Q_Q(OxideQQuickWebView);
 
115
 
 
116
  QPointF pos(q->mapToScene(QPointF(0,0)));
 
117
  if (q->window()) {
 
118
    // We could be called before being added to a scene
 
119
    pos += q->window()->position();
 
120
  }
 
121
 
 
122
  return gfx::Rect(qRound(pos.x()),
 
123
                   qRound(pos.y()),
 
124
                   qRound(q->width()),
 
125
                   qRound(q->height()));
 
126
}
 
127
 
76
128
void OxideQQuickWebView::visibilityChangedListener() {
77
129
  Q_D(OxideQQuickWebView);
78
130
 
79
 
  if (d->web_view_host_) {
80
 
    d->web_view_host_->UpdateVisibility();
81
 
  }
 
131
  d->UpdateVisibility();
82
132
}
83
133
 
84
134
void OxideQQuickWebView::geometryChanged(const QRectF& newGeometry,
92
142
    item->setSize(newGeometry.size());
93
143
  }
94
144
 
95
 
  if (d->web_view_host_) {
96
 
    d->web_view_host_->UpdateSize();
97
 
  }
 
145
  d->UpdateSize(gfx::Size(qRound(width()), qRound(height())));
98
146
}
99
147
 
100
148
OxideQQuickWebView::OxideQQuickWebView(QQuickItem* parent) :
112
160
void OxideQQuickWebView::classBegin() {
113
161
  Q_D(OxideQQuickWebView);
114
162
 
115
 
  Q_ASSERT(!d->web_view_host_);
116
163
  Q_ASSERT(!d->init_props_);
117
164
 
118
165
  d->init_props_.reset(new InitData());
121
168
void OxideQQuickWebView::componentComplete() {
122
169
  Q_D(OxideQQuickWebView);
123
170
 
124
 
  Q_ASSERT(!d->web_view_host_);
125
171
  Q_ASSERT(d->init_props_);
126
172
 
127
 
  d->web_view_host_.reset(
128
 
      oxide::qt::WebViewHostQQuick::Create(
129
 
        this, d, d->init_props_->incognito));
 
173
  d->Init(d->init_props_->incognito,
 
174
          gfx::Size(qRound(width()), qRound(height())));
 
175
 
 
176
  static_cast<oxide::WebContentsView *>(
 
177
      d->web_contents()->GetView())->SetDelegate(d);
130
178
 
131
179
  if (!d->init_props_->url.isEmpty()) {
132
 
    d->web_view_host_->SetURL(d->init_props_->url);
 
180
    d->SetURL(GURL(d->init_props_->url.toString().toStdString()));
133
181
  }
134
182
 
 
183
  d->UpdateVisibility();
 
184
 
135
185
  d->init_props_.reset();
136
186
}
137
187
 
138
188
QUrl OxideQQuickWebView::url() const {
139
189
  Q_D(const OxideQQuickWebView);
140
190
 
141
 
  if (d->init_props_) {
142
 
    return d->init_props_->url;
143
 
  }
144
 
 
145
 
  if (d->web_view_host_) {
146
 
    return d->web_view_host_->GetURL();
147
 
  }
148
 
 
149
 
  return QUrl();
 
191
  return QUrl(QString::fromStdString(d->GetURL().spec()));
150
192
}
151
193
 
152
194
void OxideQQuickWebView::setUrl(const QUrl& url) {
154
196
 
155
197
  if (d->init_props_) {
156
198
    d->init_props_->url = url;
157
 
  } else if (d->web_view_host_) {
158
 
    d->web_view_host_->SetURL(url);
 
199
  } else {
 
200
    d->SetURL(GURL(url.toString().toStdString()));
159
201
  }
160
202
}
161
203
 
162
204
QString OxideQQuickWebView::title() const {
163
205
  Q_D(const OxideQQuickWebView);
164
206
 
165
 
  if (d->web_view_host_) {
166
 
    return QString::fromStdString(d->web_view_host_->GetTitle());
167
 
  }
168
 
 
169
 
  return QString();
 
207
  return QString::fromStdString(d->GetTitle());
170
208
}
171
209
 
172
210
bool OxideQQuickWebView::canGoBack() const {
173
211
  Q_D(const OxideQQuickWebView);
174
212
 
175
 
  if (!d->web_view_host_) {
176
 
    return false;
177
 
  }
178
 
 
179
 
  return d->web_view_host_->CanGoBack();
 
213
  return d->CanGoBack();
180
214
}
181
215
 
182
216
bool OxideQQuickWebView::canGoForward() const {
183
217
  Q_D(const OxideQQuickWebView);
184
218
 
185
 
  if (!d->web_view_host_) {
186
 
    return false;
187
 
  }
188
 
 
189
 
  return d->web_view_host_->CanGoForward();
 
219
  return d->CanGoForward();
190
220
}
191
221
 
192
222
bool OxideQQuickWebView::incognito() const {
193
223
  Q_D(const OxideQQuickWebView);
194
224
 
195
 
  if (d->init_props_) {
196
 
    return d->init_props_->incognito;
197
 
  }
198
 
 
199
 
  if (d->web_view_host_) {
200
 
    return d->web_view_host_->IsIncognito();
201
 
  }
202
 
 
203
 
  return false;
 
225
  return d->IsIncognito();
204
226
}
205
227
 
206
228
void OxideQQuickWebView::setIncognito(bool incognito) {
214
236
bool OxideQQuickWebView::loading() const {
215
237
  Q_D(const OxideQQuickWebView);
216
238
 
217
 
  if (d->web_view_host_) {
218
 
    return d->web_view_host_->IsLoading();
219
 
  }
220
 
 
221
 
  return false;
 
239
  return d->IsLoading();
222
240
}
223
241
 
224
242
void OxideQQuickWebView::goBack() {
225
243
  Q_D(OxideQQuickWebView);
226
244
 
227
 
  if (d->web_view_host_) {
228
 
    d->web_view_host_->GoBack();
229
 
  }
 
245
  d->GoBack();
230
246
}
231
247
 
232
248
void OxideQQuickWebView::goForward() {
233
249
  Q_D(OxideQQuickWebView);
234
250
 
235
 
  if (d->web_view_host_) {
236
 
    d->web_view_host_->GoForward();
237
 
  }
 
251
  d->GoForward();
238
252
}
239
253
 
240
254
void OxideQQuickWebView::stop() {
241
255
  Q_D(OxideQQuickWebView);
242
256
 
243
 
  if (d->web_view_host_) {
244
 
    d->web_view_host_->Stop();
245
 
  }
 
257
  d->Stop();
246
258
}
247
259
 
248
260
void OxideQQuickWebView::reload() {
249
261
  Q_D(OxideQQuickWebView);
250
262
 
251
 
  if (d->web_view_host_) {
252
 
    d->web_view_host_->Reload();
253
 
  }
 
263
  d->Reload();
254
264
}