1 // Copyright 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 "extensions/shell/browser/shell_screen.h"
10 #include "base/logging.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_tree_host.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/native_widget_types.h"
18 namespace extensions
{
21 const int64_t kDisplayId
= 0;
25 ShellScreen::ShellScreen(const gfx::Size
& size
)
26 : host_(nullptr), display_(kDisplayId
) {
27 DCHECK(!size
.IsEmpty());
28 // Screen is positioned at (0,0).
29 gfx::Rect
bounds(size
);
30 display_
.SetScaleAndBounds(1.0f
, bounds
);
33 ShellScreen::~ShellScreen() {
34 DCHECK(!host_
) << "Window not closed before destroying ShellScreen";
37 aura::WindowTreeHost
* ShellScreen::CreateHostForPrimaryDisplay() {
39 host_
= aura::WindowTreeHost::Create(gfx::Rect(display_
.GetSizeInPixel()));
40 host_
->window()->AddObserver(this);
45 // aura::WindowObserver overrides:
47 void ShellScreen::OnWindowBoundsChanged(aura::Window
* window
,
48 const gfx::Rect
& old_bounds
,
49 const gfx::Rect
& new_bounds
) {
50 DCHECK_EQ(host_
->window(), window
);
51 display_
.SetSize(new_bounds
.size());
54 void ShellScreen::OnWindowDestroying(aura::Window
* window
) {
55 DCHECK_EQ(host_
->window(), window
);
56 host_
->window()->RemoveObserver(this);
60 // gfx::Screen overrides:
62 gfx::Point
ShellScreen::GetCursorScreenPoint() {
63 return aura::Env::GetInstance()->last_mouse_location();
66 gfx::NativeWindow
ShellScreen::GetWindowUnderCursor() {
67 return GetWindowAtScreenPoint(GetCursorScreenPoint());
70 gfx::NativeWindow
ShellScreen::GetWindowAtScreenPoint(const gfx::Point
& point
) {
71 return host_
->window()->GetTopWindowContainingPoint(point
);
74 int ShellScreen::GetNumDisplays() const {
78 std::vector
<gfx::Display
> ShellScreen::GetAllDisplays() const {
79 return std::vector
<gfx::Display
>(1, display_
);
82 gfx::Display
ShellScreen::GetDisplayNearestWindow(
83 gfx::NativeWindow window
) const {
87 gfx::Display
ShellScreen::GetDisplayNearestPoint(
88 const gfx::Point
& point
) const {
92 gfx::Display
ShellScreen::GetDisplayMatching(
93 const gfx::Rect
& match_rect
) const {
97 gfx::Display
ShellScreen::GetPrimaryDisplay() const {
101 void ShellScreen::AddObserver(gfx::DisplayObserver
* observer
) {
104 void ShellScreen::RemoveObserver(gfx::DisplayObserver
* observer
) {
107 } // namespace extensions