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