Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / content / test / web_layer_tree_view_impl_for_testing.cc
blobae83d342bf1e42c84fa8c3a08300abe5d0c7d47f
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/test/web_layer_tree_view_impl_for_testing.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/synchronization/lock.h"
10 #include "cc/base/switches.h"
11 #include "cc/blink/web_layer_impl.h"
12 #include "cc/input/input_handler.h"
13 #include "cc/layers/layer.h"
14 #include "cc/scheduler/begin_frame_source.h"
15 #include "cc/test/pixel_test_output_surface.h"
16 #include "cc/test/test_context_provider.h"
17 #include "cc/trees/layer_tree_host.h"
18 #include "content/test/test_blink_web_unit_test_support.h"
19 #include "third_party/WebKit/public/platform/Platform.h"
20 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
21 #include "third_party/WebKit/public/platform/WebLayer.h"
22 #include "third_party/WebKit/public/platform/WebLayerTreeView.h"
23 #include "third_party/WebKit/public/platform/WebSize.h"
24 #include "ui/gfx/frame_time.h"
26 using blink::WebColor;
27 using blink::WebGraphicsContext3D;
28 using blink::WebRect;
29 using blink::WebSize;
31 namespace content {
33 WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting() {}
35 WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() {}
37 void WebLayerTreeViewImplForTesting::Initialize() {
38 cc::LayerTreeSettings settings;
40 // For web contents, layer transforms should scale up the contents of layers
41 // to keep content always crisp when possible.
42 settings.layer_transforms_should_scale_layer_contents = true;
44 // Accelerated animations are enabled for unit tests.
45 settings.accelerated_animation_enabled = true;
46 layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(
47 this,
48 this,
49 nullptr,
50 nullptr,
51 settings,
52 base::MessageLoopProxy::current(),
53 nullptr);
54 DCHECK(layer_tree_host_);
57 void WebLayerTreeViewImplForTesting::setRootLayer(
58 const blink::WebLayer& root) {
59 layer_tree_host_->SetRootLayer(
60 static_cast<const cc_blink::WebLayerImpl*>(&root)->layer());
63 void WebLayerTreeViewImplForTesting::clearRootLayer() {
64 layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>());
67 void WebLayerTreeViewImplForTesting::setViewportSize(
68 const WebSize& unused_deprecated,
69 const WebSize& device_viewport_size) {
70 layer_tree_host_->SetViewportSize(device_viewport_size);
73 void WebLayerTreeViewImplForTesting::setViewportSize(
74 const WebSize& device_viewport_size) {
75 layer_tree_host_->SetViewportSize(device_viewport_size);
78 WebSize WebLayerTreeViewImplForTesting::layoutViewportSize() const {
79 return layer_tree_host_->device_viewport_size();
82 WebSize WebLayerTreeViewImplForTesting::deviceViewportSize() const {
83 return layer_tree_host_->device_viewport_size();
86 void WebLayerTreeViewImplForTesting::setDeviceScaleFactor(
87 float device_scale_factor) {
88 layer_tree_host_->SetDeviceScaleFactor(device_scale_factor);
91 float WebLayerTreeViewImplForTesting::deviceScaleFactor() const {
92 return layer_tree_host_->device_scale_factor();
95 void WebLayerTreeViewImplForTesting::setBackgroundColor(WebColor color) {
96 layer_tree_host_->set_background_color(color);
99 void WebLayerTreeViewImplForTesting::setHasTransparentBackground(
100 bool transparent) {
101 layer_tree_host_->set_has_transparent_background(transparent);
104 void WebLayerTreeViewImplForTesting::setVisible(bool visible) {
105 layer_tree_host_->SetVisible(visible);
108 void WebLayerTreeViewImplForTesting::setPageScaleFactorAndLimits(
109 float page_scale_factor,
110 float minimum,
111 float maximum) {
112 layer_tree_host_->SetPageScaleFactorAndLimits(
113 page_scale_factor, minimum, maximum);
116 void WebLayerTreeViewImplForTesting::startPageScaleAnimation(
117 const blink::WebPoint& scroll,
118 bool use_anchor,
119 float new_page_scale,
120 double duration_sec) {}
122 void WebLayerTreeViewImplForTesting::setNeedsAnimate() {
123 layer_tree_host_->SetNeedsAnimate();
126 bool WebLayerTreeViewImplForTesting::commitRequested() const {
127 return layer_tree_host_->CommitRequested();
130 void WebLayerTreeViewImplForTesting::didStopFlinging() {}
132 void WebLayerTreeViewImplForTesting::finishAllRendering() {
133 layer_tree_host_->FinishAllRendering();
136 void WebLayerTreeViewImplForTesting::setDeferCommits(bool defer_commits) {
137 layer_tree_host_->SetDeferCommits(defer_commits);
140 void WebLayerTreeViewImplForTesting::Layout() {
143 void WebLayerTreeViewImplForTesting::ApplyViewportDeltas(
144 const gfx::Vector2d& inner_delta,
145 const gfx::Vector2d& outer_delta,
146 const gfx::Vector2dF& elastic_overscroll_delta,
147 float page_scale,
148 float top_controls_delta) {
151 void WebLayerTreeViewImplForTesting::ApplyViewportDeltas(
152 const gfx::Vector2d& scroll_delta,
153 float page_scale,
154 float top_controls_delta) {}
156 void WebLayerTreeViewImplForTesting::RequestNewOutputSurface() {
157 bool flipped_output_surface = false;
158 layer_tree_host_->SetOutputSurface(
159 make_scoped_ptr(new cc::PixelTestOutputSurface(
160 cc::TestContextProvider::Create(), flipped_output_surface)));
163 void WebLayerTreeViewImplForTesting::DidFailToInitializeOutputSurface() {
164 RequestNewOutputSurface();
167 void WebLayerTreeViewImplForTesting::registerViewportLayers(
168 const blink::WebLayer* overscrollElasticityLayer,
169 const blink::WebLayer* pageScaleLayer,
170 const blink::WebLayer* innerViewportScrollLayer,
171 const blink::WebLayer* outerViewportScrollLayer) {
172 layer_tree_host_->RegisterViewportLayers(
173 // The scroll elasticity layer will only exist when using pinch virtual
174 // viewports.
175 overscrollElasticityLayer
176 ? static_cast<const cc_blink::WebLayerImpl*>(
177 overscrollElasticityLayer)->layer()
178 : NULL,
179 static_cast<const cc_blink::WebLayerImpl*>(pageScaleLayer)->layer(),
180 static_cast<const cc_blink::WebLayerImpl*>(innerViewportScrollLayer)
181 ->layer(),
182 // The outer viewport layer will only exist when using pinch virtual
183 // viewports.
184 outerViewportScrollLayer
185 ? static_cast<const cc_blink::WebLayerImpl*>(outerViewportScrollLayer)
186 ->layer()
187 : NULL);
190 void WebLayerTreeViewImplForTesting::clearViewportLayers() {
191 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(),
192 scoped_refptr<cc::Layer>(),
193 scoped_refptr<cc::Layer>(),
194 scoped_refptr<cc::Layer>());
197 void WebLayerTreeViewImplForTesting::registerSelection(
198 const blink::WebSelectionBound& start,
199 const blink::WebSelectionBound& end) {
202 void WebLayerTreeViewImplForTesting::clearSelection() {
205 } // namespace content