~abreu-alexandre/oxide/remove-chromedriver-build

1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
// Copyright (C) 2016 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_contents_view.h"
19
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
20
#include <QCursor>
1334.1.8 by Chris Coulson
Route input events through ContentsView
21
#include <QEvent>
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
22
#include <QImage>
1334.1.8 by Chris Coulson
Route input events through ContentsView
23
#include <QKeyEvent>
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
24
#include <QGuiApplication>
1334.1.8 by Chris Coulson
Route input events through ContentsView
25
#include <QMouseEvent>
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
26
#include <QPixmap>
27
#include <QRect>
1334.1.8 by Chris Coulson
Route input events through ContentsView
28
#include <QTouchEvent>
29
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
30
#include "base/logging.h"
31
#include "base/memory/ref_counted.h"
1361 by Chris Coulson
Switch to a single-threaded webview compositor
32
#include "base/memory/ref_counted_memory.h"
1334.1.8 by Chris Coulson
Route input events through ContentsView
33
#include "base/memory/scoped_vector.h"
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
34
#include "content/common/cursors/webcursor.h"
1334.1.8 by Chris Coulson
Route input events through ContentsView
35
#include "content/public/browser/native_web_keyboard_event.h"
36
#include "content/public/common/drop_data.h"
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
37
#include "third_party/WebKit/public/platform/WebCursorInfo.h"
1334.1.8 by Chris Coulson
Route input events through ContentsView
38
#include "ui/events/event.h"
39
#include "ui/gfx/geometry/point.h"
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
40
1334.1.11 by Chris Coulson
Move InputMethodContext bits and remaining view notifications out of WebView
41
#include "qt/core/browser/input/oxide_qt_input_method_context.h"
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
42
#include "qt/core/glue/oxide_qt_contents_view_proxy_client.h"
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
43
#include "shared/browser/compositor/oxide_compositor_frame_data.h"
44
#include "shared/browser/compositor/oxide_compositor_frame_handle.h"
1334.1.5 by Chris Coulson
Use the public facing QObjects as handles to proxy objects
45
#include "shared/browser/oxide_web_contents_view.h"
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
46
#include "shared/browser/oxide_web_view.h"
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
47
1334.1.8 by Chris Coulson
Route input events through ContentsView
48
#include "oxide_qt_drag_utils.h"
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
49
#include "oxide_qt_screen_utils.h"
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
50
#include "oxide_qt_skutils.h"
51
#include "oxide_qt_touch_handle_drawable.h"
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
52
#include "oxide_qt_web_context_menu.h"
53
#include "oxide_qt_web_popup_menu.h"
54
55
namespace oxide {
56
namespace qt {
57
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
58
namespace {
59
60
inline QCursor QCursorFromWebCursor(blink::WebCursorInfo::Type type) {
61
  Qt::CursorShape cs = Qt::ArrowCursor;
62
  switch (type) {
63
  case blink::WebCursorInfo::TypeCross:
64
    cs = Qt::CrossCursor;
65
    break;
66
67
  case blink::WebCursorInfo::TypeHand:
68
    cs = Qt::PointingHandCursor;
69
    break;
70
71
  case blink::WebCursorInfo::TypeCell:
72
  case blink::WebCursorInfo::TypeIBeam:
73
    cs = Qt::IBeamCursor;
74
    break;
75
76
  case blink::WebCursorInfo::TypeWait:
77
    cs = Qt::WaitCursor;
78
    break;
79
80
  case blink::WebCursorInfo::TypeHelp:
81
    cs = Qt::WhatsThisCursor;
82
    break;
83
84
  case blink::WebCursorInfo::TypeEastResize:
85
  case blink::WebCursorInfo::TypeWestResize:
86
  case blink::WebCursorInfo::TypeEastWestResize:
87
    cs = Qt::SizeHorCursor;
88
    break;
89
90
  case blink::WebCursorInfo::TypeNorthResize:
91
  case blink::WebCursorInfo::TypeSouthResize:
92
  case blink::WebCursorInfo::TypeNorthSouthResize:
93
    cs = Qt::SizeVerCursor;
94
    break;
95
96
  case blink::WebCursorInfo::TypeNorthEastResize:
97
  case blink::WebCursorInfo::TypeSouthWestResize:
98
    cs = Qt::SizeBDiagCursor;
99
    break;
100
101
  case blink::WebCursorInfo::TypeNorthWestResize:
102
  case blink::WebCursorInfo::TypeSouthEastResize:
103
    cs = Qt::SizeFDiagCursor;
104
    break;
105
106
  case blink::WebCursorInfo::TypeNorthEastSouthWestResize:
107
  case blink::WebCursorInfo::TypeNorthWestSouthEastResize:
108
  case blink::WebCursorInfo::TypeMove:
109
    cs = Qt::SizeAllCursor;
110
    break;
111
112
  case blink::WebCursorInfo::TypeColumnResize:
113
    cs = Qt::SplitHCursor;
114
    break;
115
116
  case blink::WebCursorInfo::TypeRowResize:
117
    cs = Qt::SplitVCursor;
118
    break;
119
120
  case blink::WebCursorInfo::TypeMiddlePanning:
121
  case blink::WebCursorInfo::TypeEastPanning:
122
  case blink::WebCursorInfo::TypeNorthPanning:
123
  case blink::WebCursorInfo::TypeNorthEastPanning:
124
  case blink::WebCursorInfo::TypeNorthWestPanning:
125
  case blink::WebCursorInfo::TypeSouthPanning:
126
  case blink::WebCursorInfo::TypeSouthEastPanning:
127
  case blink::WebCursorInfo::TypeSouthWestPanning:
128
  case blink::WebCursorInfo::TypeWestPanning:
129
  case blink::WebCursorInfo::TypeGrab:
130
  case blink::WebCursorInfo::TypeGrabbing:
131
    cs = Qt::ClosedHandCursor;
132
    break;
133
134
  case blink::WebCursorInfo::TypeProgress:
135
    cs = Qt::BusyCursor;
136
    break;
137
138
  case blink::WebCursorInfo::TypeNoDrop:
139
  case blink::WebCursorInfo::TypeNotAllowed:
140
    cs = Qt::ForbiddenCursor;
141
    break;
142
143
  case blink::WebCursorInfo::TypeCopy:
144
  case blink::WebCursorInfo::TypeContextMenu:
145
  case blink::WebCursorInfo::TypeVerticalText:
146
  case blink::WebCursorInfo::TypeAlias:
147
  case blink::WebCursorInfo::TypeZoomIn:
148
  case blink::WebCursorInfo::TypeZoomOut:
149
  case blink::WebCursorInfo::TypeCustom:
150
  case blink::WebCursorInfo::TypePointer:
151
  case blink::WebCursorInfo::TypeNone:
152
  default:
153
    break;
154
  }
155
156
  return QCursor(cs);
157
}
158
159
}
160
161
class CompositorFrameHandleImpl : public CompositorFrameHandle {
162
 public:
163
  CompositorFrameHandleImpl(oxide::CompositorFrameHandle* frame,
164
                            int location_bar_content_offset)
165
      : frame_(frame) {
166
    if (frame_.get()) {
167
      rect_ = QRect(0, location_bar_content_offset,
168
                    frame_->data()->size_in_pixels.width(),
169
                    frame_->data()->size_in_pixels.height());
170
    }
171
  }
172
173
  virtual ~CompositorFrameHandleImpl() {}
174
175
  CompositorFrameHandle::Type GetType() final {
176
    if (!frame_.get()) {
177
      return CompositorFrameHandle::TYPE_INVALID;
178
    }
179
    if (frame_->data()->gl_frame_data) {
180
      DCHECK_NE(frame_->data()->gl_frame_data->type,
181
                oxide::GLFrameData::Type::INVALID);
182
      if (frame_->data()->gl_frame_data->type ==
183
          oxide::GLFrameData::Type::TEXTURE) {
184
        return CompositorFrameHandle::TYPE_ACCELERATED;
185
      }
186
      return CompositorFrameHandle::TYPE_IMAGE;
187
    }
188
    if (frame_->data()->software_frame_data) {
189
      return CompositorFrameHandle::TYPE_SOFTWARE;
190
    }
191
192
    NOTREACHED();
193
    return CompositorFrameHandle::TYPE_INVALID;
194
  }
195
196
  const QRect& GetRect() const final {
197
    return rect_;
198
  }
199
200
  QImage GetSoftwareFrame() final {
201
    DCHECK_EQ(GetType(), CompositorFrameHandle::TYPE_SOFTWARE);
202
    return QImage(
1361 by Chris Coulson
Switch to a single-threaded webview compositor
203
        frame_->data()->software_frame_data->pixels->front(),
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
204
        frame_->data()->size_in_pixels.width(),
205
        frame_->data()->size_in_pixels.height(),
206
        QImage::Format_ARGB32);
207
  }
208
209
  unsigned int GetAcceleratedFrameTexture() final {
210
    DCHECK_EQ(GetType(), CompositorFrameHandle::TYPE_ACCELERATED);
211
    return frame_->data()->gl_frame_data->resource.texture;
212
  }
213
214
  EGLImageKHR GetImageFrame() final {
215
    return frame_->data()->gl_frame_data->resource.egl_image;
216
  }
217
218
 private:
219
  scoped_refptr<oxide::CompositorFrameHandle> frame_;
220
  QRect rect_;
221
};
1334.1.8 by Chris Coulson
Route input events through ContentsView
222
223
float ContentsView::GetLocationBarContentOffsetDip() {
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
224
  // XXX: Stop using WebView here
225
  oxide::WebView* web_view =
226
      oxide::WebView::FromWebContents(view()->GetWebContents());
227
  if (!web_view) {
1334.1.8 by Chris Coulson
Route input events through ContentsView
228
    return 0.f;
229
  }
230
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
231
  return web_view->GetLocationBarContentOffsetDip();
232
}
233
234
QSharedPointer<CompositorFrameHandle> ContentsView::compositorFrameHandle() {
235
  if (!compositor_frame_) {
236
    compositor_frame_ =
237
        QSharedPointer<CompositorFrameHandle>(new CompositorFrameHandleImpl(
238
          view()->GetCompositorFrameHandle(),
239
          view()->committed_frame_metadata().device_scale_factor *
240
            view()->committed_frame_metadata().location_bar_content_translation.y()));
241
  }
242
243
  return compositor_frame_;
244
}
245
246
void ContentsView::didCommitCompositorFrame() {
247
  view()->DidCommitCompositorFrame();
1334.1.8 by Chris Coulson
Route input events through ContentsView
248
}
249
1334.1.11 by Chris Coulson
Move InputMethodContext bits and remaining view notifications out of WebView
250
void ContentsView::wasResized() {
251
  view()->WasResized();
252
}
253
254
void ContentsView::visibilityChanged() {
255
  view()->VisibilityChanged();
256
}
257
258
void ContentsView::screenUpdated() {
259
  view()->ScreenUpdated();
260
}
261
262
QVariant ContentsView::inputMethodQuery(Qt::InputMethodQuery query) const {
263
  return input_method_context_->Query(query);
264
}
265
1334.1.8 by Chris Coulson
Route input events through ContentsView
266
void ContentsView::handleKeyEvent(QKeyEvent* event) {
267
  content::NativeWebKeyboardEvent e(MakeNativeWebKeyboardEvent(event, false));
268
  view()->HandleKeyEvent(e);
269
270
  // If the event is a printable character, send a corresponding Char event
271
  if (event->type() == QEvent::KeyPress && e.text[0] != 0) {
272
    view()->HandleKeyEvent(MakeNativeWebKeyboardEvent(event, true));
273
  }
274
275
  event->accept();
276
}
277
1334.1.11 by Chris Coulson
Move InputMethodContext bits and remaining view notifications out of WebView
278
void ContentsView::handleInputMethodEvent(QInputMethodEvent* event) {
279
  input_method_context_->HandleEvent(event);
280
  event->accept();
281
}
282
283
void ContentsView::handleFocusEvent(QFocusEvent* event) {
284
  input_method_context_->FocusChanged(event);
285
  view()->FocusChanged();
286
287
  event->accept();
288
}
289
1334.1.8 by Chris Coulson
Route input events through ContentsView
290
void ContentsView::handleMouseEvent(QMouseEvent* event) {
291
  if (!(event->button() == Qt::LeftButton ||
292
        event->button() == Qt::MidButton ||
293
        event->button() == Qt::RightButton ||
294
        event->button() == Qt::NoButton)) {
295
    event->ignore();
296
    return;
297
  }
298
299
  view()->HandleMouseEvent(
300
      MakeWebMouseEvent(event,
301
                        GetDeviceScaleFactor(),
302
                        GetLocationBarContentOffsetDip()));
303
  event->accept();
304
}
305
1334.1.12 by Chris Coulson
Merge from trunk
306
void ContentsView::handleTouchUngrabEvent() {
307
  scoped_ptr<ui::TouchEvent> cancel_event(touch_event_factory_.Cancel());
308
  view()->HandleTouchEvent(*cancel_event.get());
309
}
310
1334.1.11 by Chris Coulson
Move InputMethodContext bits and remaining view notifications out of WebView
311
void ContentsView::handleWheelEvent(QWheelEvent* event,
312
                                    const QPoint& window_pos) {
313
  view()->HandleWheelEvent(
314
      MakeWebMouseWheelEvent(event,
315
                             window_pos,
316
                             GetDeviceScaleFactor(),
317
                             GetLocationBarContentOffsetDip()));
1334.1.8 by Chris Coulson
Route input events through ContentsView
318
  event->accept();
319
}
320
321
void ContentsView::handleTouchEvent(QTouchEvent* event) {
322
  ScopedVector<ui::TouchEvent> events;
323
  touch_event_factory_.MakeEvents(event,
324
                                  GetDeviceScaleFactor(),
325
                                  GetLocationBarContentOffsetDip(),
326
                                  &events);
327
328
  for (size_t i = 0; i < events.size(); ++i) {
329
    view()->HandleTouchEvent(*events[i]);
330
  }
331
332
  event->accept();
333
}
334
1334.1.11 by Chris Coulson
Move InputMethodContext bits and remaining view notifications out of WebView
335
void ContentsView::handleHoverEvent(QHoverEvent* event,
336
                                    const QPoint& window_pos,
337
                                    const QPoint& global_pos) {
338
  view()->HandleMouseEvent(
339
      MakeWebMouseEvent(event,
340
                        window_pos,
341
                        global_pos,
342
                        GetDeviceScaleFactor(),
343
                        GetLocationBarContentOffsetDip()));
1334.1.8 by Chris Coulson
Route input events through ContentsView
344
  event->accept();
345
}
346
347
void ContentsView::handleDragEnterEvent(QDragEnterEvent* event) {
348
  content::DropData drop_data;
349
  gfx::Point location;
350
  blink::WebDragOperationsMask allowed_ops = blink::WebDragOperationNone;
351
  int key_modifiers = 0;
352
353
  GetDragEnterEventParams(event,
354
                          GetDeviceScaleFactor(),
355
                          &drop_data,
356
                          &location,
357
                          &allowed_ops,
358
                          &key_modifiers);
359
360
  view()->HandleDragEnter(drop_data, location, allowed_ops, key_modifiers);
361
362
  event->accept();
363
}
364
365
void ContentsView::handleDragMoveEvent(QDragMoveEvent* event) {
366
  gfx::Point location;
367
  int key_modifiers = 0;
368
369
  GetDropEventParams(event, GetDeviceScaleFactor(), &location, &key_modifiers);
370
371
  blink::WebDragOperation op = view()->HandleDragMove(location, key_modifiers);
372
373
  Qt::DropAction action;
374
  if ((action = ToQtDropAction(op)) != Qt::IgnoreAction) {
375
    event->setDropAction(action);
376
    event->accept();
377
  } else {
378
    event->ignore();
379
  }
380
}
381
382
void ContentsView::handleDragLeaveEvent(QDragLeaveEvent* event) {
383
  view()->HandleDragLeave();
384
}
385
386
void ContentsView::handleDropEvent(QDropEvent* event) {
387
  gfx::Point location;
388
  int key_modifiers = 0;
389
390
  GetDropEventParams(event, GetDeviceScaleFactor(), &location, &key_modifiers);
391
392
  blink::WebDragOperation op = view()->HandleDrop(location, key_modifiers);
393
394
  Qt::DropAction action;
395
  if ((action = ToQtDropAction(op)) != Qt::IgnoreAction) {
396
    event->setDropAction(action);
397
    event->accept();
398
  } else {
399
    event->ignore();
400
  }
401
}
402
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
403
blink::WebScreenInfo ContentsView::GetScreenInfo() const {
404
  QScreen* screen = client_->GetScreen();
405
  if (!screen) {
406
    screen = QGuiApplication::primaryScreen();
407
  }
408
409
  return GetWebScreenInfoFromQScreen(screen);
410
}
411
1334.1.11 by Chris Coulson
Move InputMethodContext bits and remaining view notifications out of WebView
412
void ContentsView::SetInputMethodEnabled(bool enabled) {
413
  client_->SetInputMethodEnabled(enabled);
414
}
415
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
416
bool ContentsView::IsVisible() const {
417
  return client_->IsVisible();
418
}
419
420
bool ContentsView::HasFocus() const {
421
  return client_->HasFocus();
422
}
423
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
424
gfx::Rect ContentsView::GetBoundsPix() const {
425
  QRect bounds = client_->GetBoundsPix();
426
  return gfx::Rect(bounds.x(),
427
                   bounds.y(),
428
                   bounds.width(),
429
                   bounds.height());
430
}
431
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
432
void ContentsView::SwapCompositorFrame() {
433
  compositor_frame_.reset();
434
  client_->ScheduleUpdate();
435
}
436
437
void ContentsView::EvictCurrentFrame() {
438
  compositor_frame_.reset();
439
  client_->EvictCurrentFrame();
440
}
441
442
void ContentsView::UpdateCursor(const content::WebCursor& cursor) {
443
  content::WebCursor::CursorInfo cursor_info;
444
445
  cursor.GetCursorInfo(&cursor_info);
446
  if (cursor.IsCustom()) {
447
    QImage cursor_image = QImageFromSkBitmap(cursor_info.custom_image);
448
    if (cursor_image.isNull()) {
449
      return;
450
    }
451
452
    QPixmap cursor_pixmap = QPixmap::fromImage(cursor_image);
453
    client_->UpdateCursor(QCursor(cursor_pixmap));
454
  } else {
455
    client_->UpdateCursor(QCursorFromWebCursor(cursor_info.type));
456
  }
457
}
458
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
459
oxide::WebContextMenu* ContentsView::CreateContextMenu(
460
    content::RenderFrameHost* rfh,
461
    const content::ContextMenuParams& params) {
462
  WebContextMenu* menu = new WebContextMenu(rfh, params);
463
  menu->SetProxy(client_->CreateWebContextMenu(menu));
464
  return menu;
465
}
466
467
oxide::WebPopupMenu* ContentsView::CreatePopupMenu(
468
    content::RenderFrameHost* rfh) {
469
  WebPopupMenu* menu = new WebPopupMenu(rfh);
470
  menu->SetProxy(client_->CreateWebPopupMenu(menu));
471
  return menu;
472
}
473
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
474
ui::TouchHandleDrawable* ContentsView::CreateTouchHandleDrawable() const {
475
  TouchHandleDrawable* drawable = new TouchHandleDrawable(this);
476
  drawable->SetProxy(client_->CreateTouchHandleDrawable());
477
  return drawable;
478
}
479
480
void ContentsView::TouchSelectionChanged(bool active,
481
                                         const gfx::RectF& bounds) const {
482
  const float dpr = GetDeviceScaleFactor();
483
  QRectF rect(bounds.x() * dpr, bounds.y() * dpr,
484
              bounds.width() * dpr, bounds.height() * dpr);
485
  client_->TouchSelectionChanged(active, rect);
486
}
487
1334.1.11 by Chris Coulson
Move InputMethodContext bits and remaining view notifications out of WebView
488
oxide::InputMethodContext* ContentsView::GetInputMethodContext() const {
489
  return input_method_context_.get();
490
}
491
1334.1.13 by Chris Coulson
Move unhandled key event handling to ContentsView
492
void ContentsView::UnhandledKeyboardEvent(
493
    const content::NativeWebKeyboardEvent& event) {
494
  if (event.skip_in_browser) {
495
    return;
496
  }
497
498
  if (event.type != blink::WebInputEvent::RawKeyDown &&
499
      event.type != blink::WebInputEvent::KeyUp) {
500
    return;
501
  }
502
503
  if (!event.os_event) {
504
    return;
505
  }
506
  
507
  DCHECK(!event.os_event->isAccepted());
508
509
  client_->HandleUnhandledKeyboardEvent(event.os_event);
510
}
511
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
512
ContentsView::ContentsView(ContentsViewProxyClient* client,
513
                           QObject* native_view)
1334.1.5 by Chris Coulson
Use the public facing QObjects as handles to proxy objects
514
    : client_(client),
1334.1.11 by Chris Coulson
Move InputMethodContext bits and remaining view notifications out of WebView
515
      native_view_(native_view),
516
      input_method_context_(new InputMethodContext(this)) {
1334.1.8 by Chris Coulson
Route input events through ContentsView
517
  DCHECK(!client_->proxy_);
518
  client_->proxy_ = this;
1334.1.6 by Chris Coulson
Add oxide::qquick::ContentsView
519
}
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
520
1334.1.6 by Chris Coulson
Add oxide::qquick::ContentsView
521
ContentsView::~ContentsView() {
1334.1.8 by Chris Coulson
Route input events through ContentsView
522
  DCHECK_EQ(client_->proxy_, this);
523
  client_->proxy_ = nullptr;
1334.1.11 by Chris Coulson
Move InputMethodContext bits and remaining view notifications out of WebView
524
  input_method_context_->DetachClient();
1334.1.6 by Chris Coulson
Add oxide::qquick::ContentsView
525
}
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
526
1334.1.5 by Chris Coulson
Use the public facing QObjects as handles to proxy objects
527
// static
528
ContentsView* ContentsView::FromWebContents(content::WebContents* contents) {
529
  oxide::WebContentsView* view =
530
      oxide::WebContentsView::FromWebContents(contents);
531
  if (!view) {
532
    return nullptr;
533
  }
534
535
  return static_cast<ContentsView*>(view->client());
536
}
537
1334.1.9 by Chris Coulson
Hoist compositing out of WebView
538
float ContentsView::GetDeviceScaleFactor() const {
539
  QScreen* screen = client_->GetScreen();
540
  if (!screen) {
541
    screen = QGuiApplication::primaryScreen();
542
  }
543
544
  return GetDeviceScaleFactorFromQScreen(screen);
545
}
546
547
int ContentsView::GetLocationBarContentOffsetPix() const {
548
  // XXX: Stop using WebView here
549
  oxide::WebView* web_view =
550
      oxide::WebView::FromWebContents(view()->GetWebContents());
551
  if (!web_view) {
552
    return 0;
553
  }
554
555
  return web_view->GetLocationBarContentOffsetPix();
556
}
557
1334.1.4 by Chris Coulson
Add WebContentsViewClient implementation in qt/
558
} // namespace qt
559
} // namespace oxide