Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / shell / browser / shell_screen.cc
blob14c54015b14a15e70b2591990eded19f034e98ef
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"
7 #include <stdint.h>
8 #include <vector>
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 {
19 namespace {
21 const int64_t kDisplayId = 0;
23 } // namespace
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() {
38 DCHECK(!host_);
39 host_ = aura::WindowTreeHost::Create(gfx::Rect(display_.GetSizeInPixel()));
40 host_->window()->AddObserver(this);
41 host_->InitHost();
42 return host_;
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);
57 host_ = nullptr;
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 {
75 return 1;
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 {
84 return display_;
87 gfx::Display ShellScreen::GetDisplayNearestPoint(
88 const gfx::Point& point) const {
89 return display_;
92 gfx::Display ShellScreen::GetDisplayMatching(
93 const gfx::Rect& match_rect) const {
94 return display_;
97 gfx::Display ShellScreen::GetPrimaryDisplay() const {
98 return display_;
101 void ShellScreen::AddObserver(gfx::DisplayObserver* observer) {
104 void ShellScreen::RemoveObserver(gfx::DisplayObserver* observer) {
107 } // namespace extensions