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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
content / browser / renderer_host / screen_state.cc [blame]
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/renderer_host/screen_state.h"
namespace content {
ScreenState::ScreenState() = default;
void ScreenState::CopyDefinedAttributes(const ScreenState& other) {
if (!other.visible_viewport_size.IsEmpty())
visible_viewport_size = other.visible_viewport_size;
if (!other.physical_backing_size.IsEmpty())
physical_backing_size = other.physical_backing_size;
if (!other.screen_info_size.IsEmpty())
screen_info_size = other.screen_info_size;
if (other.orientation_type != display::mojom::ScreenOrientation::kUndefined)
orientation_type = other.orientation_type;
has_unlocked_orientation_lock = other.has_unlocked_orientation_lock;
is_expecting_fullscreen_rotation = other.is_expecting_fullscreen_rotation;
is_fullscreen = other.is_fullscreen;
is_picture_in_picture = other.is_picture_in_picture;
on_physical_backing_changed_received =
other.on_physical_backing_changed_received;
on_sync_display_properties_changed_received =
other.on_sync_display_properties_changed_received;
any_non_rotation_size_changed = other.any_non_rotation_size_changed;
if (other.local_surface_id.is_valid())
local_surface_id = other.local_surface_id;
}
bool ScreenState::EqualOrientations(const ScreenState& other) {
return !IsRotation(visible_viewport_size, other.visible_viewport_size) &&
!IsRotation(physical_backing_size, other.physical_backing_size) &&
!ExpectsResizeForOrientationChange(orientation_type,
other.orientation_type);
}
bool ScreenState::IsRotated(const ScreenState& other) {
return IsRotation(visible_viewport_size, other.visible_viewport_size) &&
IsRotation(physical_backing_size, other.physical_backing_size) &&
ExpectsResizeForOrientationChange(orientation_type,
other.orientation_type);
}
bool ScreenState::IsValid() {
return !visible_viewport_size.IsEmpty() && !physical_backing_size.IsEmpty() &&
!screen_info_size.IsEmpty() &&
orientation_type != display::mojom::ScreenOrientation::kUndefined;
}
bool ScreenState::EqualVisualProperties(const ScreenState& other) const {
return visible_viewport_size == other.visible_viewport_size &&
physical_backing_size == other.physical_backing_size &&
screen_info_size == other.screen_info_size &&
orientation_type == other.orientation_type &&
is_fullscreen == other.is_fullscreen;
}
// static
bool ScreenState::IsRotation(const gfx::Size& old_size,
const gfx::Size& new_size) {
// The size change can sometimes include both the rotation and top-controls
// adjustments at the same time. So we can't rely on it being a direct swap.
if (old_size.width() > old_size.height() &&
new_size.width() < new_size.height()) {
return true;
} else if (old_size.width() < old_size.height() &&
new_size.width() > new_size.height()) {
return true;
}
return false;
}
// static
bool ScreenState::IsSingleAxisResize(const gfx::Size& old_size,
const gfx::Size& new_size) {
if (old_size.width() == new_size.width() &&
old_size.height() != new_size.height()) {
return true;
}
if (old_size.height() == new_size.height() &&
old_size.width() != new_size.width()) {
return true;
}
return false;
}
// static
bool ScreenState::ExpectsResizeForOrientationChange(
display::mojom::ScreenOrientation current,
display::mojom::ScreenOrientation pending) {
switch (current) {
case display::mojom::ScreenOrientation::kUndefined:
return false;
case display::mojom::ScreenOrientation::kPortraitPrimary:
case display::mojom::ScreenOrientation::kPortraitSecondary:
return pending == display::mojom::ScreenOrientation::kLandscapePrimary ||
pending == display::mojom::ScreenOrientation::kLandscapeSecondary;
case display::mojom::ScreenOrientation::kLandscapePrimary:
case display::mojom::ScreenOrientation::kLandscapeSecondary:
return pending == display::mojom::ScreenOrientation::kPortraitPrimary ||
pending == display::mojom::ScreenOrientation::kPortraitSecondary;
}
return false;
}
} // namespace content