| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 "ui/aura/single_display_manager.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #include "ui/aura/aura_switches.h" | |
| 11 #include "ui/aura/root_window.h" | |
| 12 #include "ui/aura/root_window_host.h" | |
| 13 #include "ui/gfx/display.h" | |
| 14 #include "ui/gfx/rect.h" | |
| 15 | |
| 16 namespace aura { | |
| 17 | |
| 18 using std::string; | |
| 19 | |
| 20 namespace { | |
| 21 // Default bounds for the primary display. | |
| 22 const int kDefaultHostWindowX = 200; | |
| 23 const int kDefaultHostWindowY = 200; | |
| 24 const int kDefaultHostWindowWidth = 1280; | |
| 25 const int kDefaultHostWindowHeight = 1024; | |
| 26 } // namespace | |
| 27 | |
| 28 SingleDisplayManager::SingleDisplayManager() | |
| 29 : root_window_(NULL) { | |
| 30 Init(); | |
| 31 } | |
| 32 | |
| 33 SingleDisplayManager::~SingleDisplayManager() { | |
| 34 // All displays must have been deleted when display manager is deleted. | |
| 35 CHECK(!root_window_); | |
| 36 } | |
| 37 | |
| 38 void SingleDisplayManager::OnNativeDisplaysChanged( | |
| 39 const std::vector<gfx::Display>& displays) { | |
| 40 DCHECK(displays.size() > 0); | |
| 41 if (use_fullscreen_host_window()) { | |
| 42 display_.SetSize(displays[0].bounds().size()); | |
| 43 NotifyBoundsChanged(display_); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 RootWindow* SingleDisplayManager::CreateRootWindowForDisplay( | |
| 48 const gfx::Display& display) { | |
| 49 DCHECK(!root_window_); | |
| 50 DCHECK_EQ(display_.id(), display.id()); | |
| 51 root_window_ = new RootWindow(RootWindow::CreateParams(display.bounds())); | |
| 52 root_window_->AddObserver(this); | |
| 53 root_window_->Init(); | |
| 54 return root_window_; | |
| 55 } | |
| 56 | |
| 57 gfx::Display* SingleDisplayManager::GetDisplayAt(size_t index) { | |
| 58 return &display_; | |
| 59 } | |
| 60 | |
| 61 size_t SingleDisplayManager::GetNumDisplays() const { | |
| 62 return 1; | |
| 63 } | |
| 64 | |
| 65 const gfx::Display& SingleDisplayManager::GetDisplayNearestWindow( | |
| 66 const Window* window) const { | |
| 67 return display_; | |
| 68 } | |
| 69 | |
| 70 const gfx::Display& SingleDisplayManager::GetDisplayNearestPoint( | |
| 71 const gfx::Point& point) const { | |
| 72 return display_; | |
| 73 } | |
| 74 | |
| 75 const gfx::Display& SingleDisplayManager::GetDisplayMatching( | |
| 76 const gfx::Rect& match_rect) const { | |
| 77 return display_; | |
| 78 } | |
| 79 | |
| 80 std::string SingleDisplayManager::GetDisplayNameFor( | |
| 81 const gfx::Display& display) { | |
| 82 return "Display"; | |
| 83 } | |
| 84 | |
| 85 void SingleDisplayManager::OnWindowBoundsChanged( | |
| 86 Window* window, const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) { | |
| 87 if (!use_fullscreen_host_window()) { | |
| 88 Update(new_bounds.size()); | |
| 89 NotifyBoundsChanged(display_); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 void SingleDisplayManager::OnWindowDestroying(Window* window) { | |
| 94 if (root_window_ == window) | |
| 95 root_window_ = NULL; | |
| 96 } | |
| 97 | |
| 98 void SingleDisplayManager::Init() { | |
| 99 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 100 switches::kAuraHostWindowSize); | |
| 101 display_ = CreateDisplayFromSpec(size_str); | |
| 102 } | |
| 103 | |
| 104 void SingleDisplayManager::Update(const gfx::Size size) { | |
| 105 display_.SetSize(size); | |
| 106 } | |
| 107 | |
| 108 } // namespace aura | |
| OLD | NEW |