[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / content / browser / renderer_host / frame_metadata_util.cc
blob11cf5d2e65e2b5d4de95cc2886549cffb17c3cc3
1 // Copyright (c) 2014 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/browser/renderer_host/frame_metadata_util.h"
7 #include "cc/output/compositor_frame_metadata.h"
9 namespace {
11 // Used to accomodate finite precision when comparing scaled viewport and
12 // content widths. While this value may seem large, width=device-width on an N7
13 // V1 saw errors of ~0.065 between computed window and content widths.
14 const float kMobileViewportWidthEpsilon = 0.15f;
16 bool HasFixedPageScale(const cc::CompositorFrameMetadata& frame_metadata) {
17 return frame_metadata.min_page_scale_factor ==
18 frame_metadata.max_page_scale_factor;
21 bool HasMobileViewport(const cc::CompositorFrameMetadata& frame_metadata) {
22 float window_width_dip =
23 frame_metadata.page_scale_factor *
24 frame_metadata.scrollable_viewport_size.width();
25 float content_width_css = frame_metadata.root_layer_size.width();
26 return content_width_css <= window_width_dip + kMobileViewportWidthEpsilon;
29 } // namespace
31 namespace content {
33 bool IsMobileOptimizedFrame(const cc::CompositorFrameMetadata& frame_metadata) {
34 bool has_mobile_viewport = HasMobileViewport(frame_metadata);
35 bool has_fixed_page_scale = HasFixedPageScale(frame_metadata);
36 return has_fixed_page_scale || has_mobile_viewport;
39 } // namespace content