Commit 9449db5f authored by Mike Wasserman's avatar Mike Wasserman Committed by Commit Bot

Screen Enumeration: Implement Screen.internal property

Plumb the internal display id to populate the Screen.internal attribute.
Follows the primary display id and Screen.primary attribute pattern.

This requires the ScreenEnumeration experimental flag to be enabled:
  chrome://flags#enable-experimental-web-platform-features OR
  $ chrome --enable-blink-features=ScreenEnumeration

Test with this demo:
  https://github.com/michaelwasserman/window-placement-demo

Bug: 994889
Test: getScreens()[i].internal returns an accurate value.
Change-Id: I71ed5eb8b164eff6f2f5d93a7a400e69df219490
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2015555
Commit-Queue: Michael Wasserman <msw@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734550}
parent f3534cc8
......@@ -25,9 +25,12 @@ ScreenEnumerationImpl::~ScreenEnumerationImpl() = default;
void ScreenEnumerationImpl::GetDisplays(GetDisplaysCallback callback) {
display::Screen* screen = display::Screen::GetScreen();
const std::vector<display::Display> displays = screen->GetAllDisplays();
const int64_t internal_id = display::Display::HasInternalDisplay()
? display::Display::InternalDisplayId()
: display::kInvalidDisplayId;
const int64_t primary_id = screen->GetPrimaryDisplay().id();
// TODO(msw): Return no data and |false| if a permission check fails.
std::move(callback).Run(std::move(displays), primary_id, true);
std::move(callback).Run(std::move(displays), internal_id, primary_id, true);
}
} // namespace content
\ No newline at end of file
......@@ -10,9 +10,10 @@ import "ui/display/mojom/display.mojom";
// window and worker processes.
interface ScreenEnumeration {
// If success is false, other returned values are meaningless. Otherwise,
// |displays| is the list of connected display devices, and |primary_id| is
// the id of the primary display.
// |displays| is the list of connected display devices; |internal_id| and
// |primary_id| are respectively the ids of the internal and primary displays.
GetDisplays() => (array<display.mojom.Display> displays,
int64 internal_id,
int64 primary_id,
bool success);
};
......@@ -171,9 +171,12 @@ void Screen::Trace(blink::Visitor* visitor) {
Supplementable<Screen>::Trace(visitor);
}
Screen::Screen(display::mojom::blink::DisplayPtr display, bool primary)
Screen::Screen(display::mojom::blink::DisplayPtr display,
bool internal,
bool primary)
: DOMWindowClient(static_cast<LocalFrame*>(nullptr)),
display_(std::move(display)),
internal_(internal),
primary_(primary) {}
int Screen::left() const {
......@@ -211,7 +214,11 @@ int Screen::top() const {
}
bool Screen::internal() const {
// TODO(http://crbug.com/994889): Implement this.
if (display_) {
DCHECK(RuntimeEnabledFeatures::ScreenEnumerationEnabled());
return internal_.has_value() && internal_.value();
}
// TODO(http://crbug.com/994889): Implement this for |window.screen|?
NOTIMPLEMENTED_LOG_ONCE();
return false;
}
......
......@@ -65,7 +65,9 @@ class CORE_EXPORT Screen final : public ScriptWrappable,
// Proposed extensions to the Screen interface.
// https://github.com/webscreens/screen-enumeration
// TODO(msw): Resolve different info sources, caching, and lifetimes.
Screen(display::mojom::blink::DisplayPtr display, bool primary);
Screen(display::mojom::blink::DisplayPtr display,
bool internal,
bool primary);
int left() const;
int top() const;
bool internal() const;
......@@ -82,6 +84,10 @@ class CORE_EXPORT Screen final : public ScriptWrappable,
// This member is only valid for Screen objects obtained via the experimental
// Screen Enumeration API.
const display::mojom::blink::DisplayPtr display_;
// True if this is an internal display of the device; it is a static value
// provided upon construction. This member is only valid for Screen objects
// obtained via the experimental Screen Enumeration API.
const base::Optional<bool> internal_;
// True if this is the primary screen of the operating system; it is a static
// value provided upon construction. This member is only valid for Screen
// objects obtained via the experimental Screen Enumeration API.
......
......@@ -26,6 +26,7 @@ void DidGetDisplays(
ScriptPromiseResolver* resolver,
mojo::Remote<mojom::blink::ScreenEnumeration>,
WTF::Vector<display::mojom::blink::DisplayPtr> backend_displays,
int64_t internal_id,
int64_t primary_id,
bool success) {
ScriptState* script_state = resolver->GetScriptState();
......@@ -35,9 +36,10 @@ void DidGetDisplays(
HeapVector<Member<Screen>> screens;
screens.ReserveInitialCapacity(backend_displays.size());
for (display::mojom::blink::DisplayPtr& backend_display : backend_displays) {
const bool internal = backend_display->id == internal_id;
const bool primary = backend_display->id == primary_id;
screens.emplace_back(
MakeGarbageCollected<Screen>(std::move(backend_display), primary));
screens.emplace_back(MakeGarbageCollected<Screen>(
std::move(backend_display), internal, primary));
}
resolver->Resolve(std::move(screens));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment