summaryrefslogtreecommitdiffstats
path: root/components/html_viewer/web_layer_impl.cc
blob: e4a2cacbcf284d2a97096152a830b2f77020de8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/html_viewer/web_layer_impl.h"

#include "cc/layers/layer.h"
#include "components/view_manager/public/cpp/view.h"
#include "ui/gfx/geometry/dip_util.h"
#include "ui/mojo/geometry/geometry.mojom.h"

using blink::WebFloatPoint;
using blink::WebSize;

namespace html_viewer {

WebLayerImpl::WebLayerImpl(mojo::View* view, float device_pixel_ratio)
    : view_(view), device_pixel_ratio_(device_pixel_ratio) {}

WebLayerImpl::~WebLayerImpl() {
}

void WebLayerImpl::setBounds(const WebSize& size) {
  mojo::Rect rect = view_->bounds();
  const gfx::Size size_in_pixels(ConvertSizeToPixel(
      device_pixel_ratio_, gfx::Size(size.width, size.height)));
  rect.width = size_in_pixels.width();
  rect.height = size_in_pixels.height();
  view_->SetBounds(rect);
  cc_blink::WebLayerImpl::setBounds(size);
}

void WebLayerImpl::setPosition(const WebFloatPoint& position) {
  int x = 0, y = 0;
  // TODO(fsamuel): This is a temporary hack until we have a UI process in
  // Mandoline. The View will always lag behind the cc::Layer.
  cc::Layer* current_layer = layer();
  while (current_layer) {
    x += current_layer->position().x();
    x -= current_layer->scroll_offset().x();
    y += current_layer->position().y();
    y -= current_layer->scroll_offset().y();
    current_layer = current_layer->parent();
  }
  const gfx::Point point_in_pixels(
      ConvertPointToPixel(device_pixel_ratio_, gfx::Point(x, y)));
  mojo::Rect rect = view_->bounds();
  rect.x = point_in_pixels.x();
  rect.y = point_in_pixels.y();
  view_->SetBounds(rect);
  cc_blink::WebLayerImpl::setPosition(position);
}

}  // namespace html_viewer