blob: b59c3169f4c6533daceaa2297a4adb6d7a6e93dd [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2016 The Chromium Authors
Daniel Libbyadeca892020-06-05 20:03:402// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/browser/renderer_host/display_feature.h"
6
7namespace content {
8
Alexis Menardfb62ecc2024-02-26 21:25:199std::vector<gfx::Rect> DisplayFeature::ComputeViewportSegments(
Menard, Alexis91b2a322024-02-23 21:41:1110 const gfx::Size& visible_viewport_size,
11 int root_view_offset_from_origin) const {
Alexis Menardfb62ecc2024-02-26 21:25:1912 std::vector<gfx::Rect> viewport_segments;
Songtao Xia27891f212020-07-09 21:39:1713
14 int display_feature_end = offset + mask_length;
15 if (orientation == DisplayFeature::Orientation::kVertical) {
16 // If the display feature is vertically oriented, it splits or masks
17 // the widget into two side-by-side segments. Note that in the masking
18 // scenario, there is an area of the widget that are not covered by the
Alexis Menardfb62ecc2024-02-26 21:25:1919 // union of the viewport segments - this area's pixels will not be visible
Songtao Xia27891f212020-07-09 21:39:1720 // to the user.
Alexis Menardfb62ecc2024-02-26 21:25:1921 viewport_segments.emplace_back(0, 0, offset,
22 visible_viewport_size.height());
23 viewport_segments.emplace_back(
Songtao Xia27891f212020-07-09 21:39:1724 display_feature_end, 0,
25 visible_viewport_size.width() - display_feature_end,
26 visible_viewport_size.height());
27 } else {
28 // If the display feature is offset in the y direction, it splits or masks
29 // the widget into two stacked segments.
Menard, Alexis91b2a322024-02-23 21:41:1130 // We need to offset the display feature by the browser controls top height.
31 display_feature_end = display_feature_end - root_view_offset_from_origin;
32 int final_offset = offset - root_view_offset_from_origin;
33 if (final_offset < 0 || display_feature_end < 0) {
Alexis Menardfb62ecc2024-02-26 21:25:1934 return viewport_segments;
Menard, Alexis91b2a322024-02-23 21:41:1135 }
Alexis Menardfb62ecc2024-02-26 21:25:1936 viewport_segments.emplace_back(0, 0, visible_viewport_size.width(),
37 final_offset);
38 viewport_segments.emplace_back(
Songtao Xia27891f212020-07-09 21:39:1739 0, display_feature_end, visible_viewport_size.width(),
40 visible_viewport_size.height() - display_feature_end);
41 }
42
Alexis Menardfb62ecc2024-02-26 21:25:1943 return viewport_segments;
Songtao Xia27891f212020-07-09 21:39:1744}
45
46// static
Arthur Sonzognic686e8f2024-01-11 08:36:3747std::optional<DisplayFeature> DisplayFeature::Create(Orientation orientation,
48 int offset,
49 int mask_length,
50 int width,
51 int height,
52 ParamErrorEnum* error) {
Songtao Xia27891f212020-07-09 21:39:1753 if (!width && !height) {
54 *error = ParamErrorEnum::kDisplayFeatureWithZeroScreenSize;
Arthur Sonzognic686e8f2024-01-11 08:36:3755 return std::nullopt;
Songtao Xia27891f212020-07-09 21:39:1756 }
57
58 if (offset < 0 || mask_length < 0) {
59 *error = ParamErrorEnum::kNegativeDisplayFeatureParams;
Arthur Sonzognic686e8f2024-01-11 08:36:3760 return std::nullopt;
Songtao Xia27891f212020-07-09 21:39:1761 }
62
63 if (orientation == Orientation::kVertical && offset + mask_length > width) {
64 *error = ParamErrorEnum::kOutsideScreenWidth;
Arthur Sonzognic686e8f2024-01-11 08:36:3765 return std::nullopt;
Songtao Xia27891f212020-07-09 21:39:1766 }
67
68 if (orientation == Orientation::kHorizontal &&
69 offset + mask_length > height) {
70 *error = ParamErrorEnum::kOutsideScreenHeight;
Arthur Sonzognic686e8f2024-01-11 08:36:3771 return std::nullopt;
Songtao Xia27891f212020-07-09 21:39:1772 }
73
74 return DisplayFeature{orientation, offset, mask_length};
75}
76
Daniel Libbyadeca892020-06-05 20:03:4077} // namespace content