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.
4 
5 #include "extensions/shell/browser/shell_screen.h"
6 
7 #include <stdint.h>
8 #include <vector>
9 
10 #include "base/check.h"
11 #include "extensions/shell/browser/root_window_controller.h"
12 #include "extensions/shell/browser/shell_desktop_controller_aura.h"
13 #include "ui/aura/env.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_tree_host.h"
16 #include "ui/display/display.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/size.h"
19 #include "ui/gfx/native_widget_types.h"
20 
21 namespace extensions {
22 namespace {
23 
24 const int64_t kDisplayId = 0;
25 
26 }  // namespace
27 
ShellScreen(ShellDesktopControllerAura * desktop_controller,const gfx::Size & size)28 ShellScreen::ShellScreen(ShellDesktopControllerAura* desktop_controller,
29                          const gfx::Size& size)
30     : desktop_controller_(desktop_controller) {
31   DCHECK(!size.IsEmpty());
32 
33   // Screen is positioned at (0,0).
34   display::Display display(kDisplayId);
35   gfx::Rect bounds(size);
36   display.SetScaleAndBounds(1.0f, bounds);
37   ProcessDisplayChanged(display, true /* is_primary */);
38 }
39 
~ShellScreen()40 ShellScreen::~ShellScreen() {
41   DCHECK(!desktop_controller_ || !desktop_controller_->GetPrimaryHost())
42       << "WindowTreeHost not closed before destroying ShellScreen";
43 }
44 
OnHostResized(aura::WindowTreeHost * host)45 void ShellScreen::OnHostResized(aura::WindowTreeHost* host) {
46   // Based on ash::WindowTreeHostManager.
47   display::Display display = GetDisplayNearestWindow(host->window());
48   display.SetSize(host->GetBoundsInPixels().size());
49   display_list().UpdateDisplay(display);
50 }
51 
GetCursorScreenPoint()52 gfx::Point ShellScreen::GetCursorScreenPoint() {
53   return aura::Env::GetInstance()->last_mouse_location();
54 }
55 
IsWindowUnderCursor(gfx::NativeWindow window)56 bool ShellScreen::IsWindowUnderCursor(gfx::NativeWindow window) {
57   return GetWindowAtScreenPoint(GetCursorScreenPoint()) == window;
58 }
59 
GetWindowAtScreenPoint(const gfx::Point & point)60 gfx::NativeWindow ShellScreen::GetWindowAtScreenPoint(const gfx::Point& point) {
61   return desktop_controller_->GetPrimaryHost()
62       ->window()
63       ->GetEventHandlerForPoint(point);
64 }
65 
GetDisplayNearestWindow(gfx::NativeWindow window) const66 display::Display ShellScreen::GetDisplayNearestWindow(
67     gfx::NativeWindow window) const {
68   return GetPrimaryDisplay();
69 }
70 
71 }  // namespace extensions
72