| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/aura/monitor_manager.h" | 5 #include "ui/aura/monitor_manager.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/aura/display_observer.h" |
| 10 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
| 11 #include "ui/aura/monitor_observer.h" | |
| 12 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
| 13 #include "ui/aura/root_window_host.h" | 13 #include "ui/aura/root_window_host.h" |
| 14 #include "ui/gfx/monitor.h" | 14 #include "ui/gfx/display.h" |
| 15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 16 | 16 |
| 17 namespace aura { | 17 namespace aura { |
| 18 namespace { | 18 namespace { |
| 19 // Default bounds for a monitor. | 19 // Default bounds for a monitor. |
| 20 static const int kDefaultHostWindowX = 200; | 20 const int kDefaultHostWindowX = 200; |
| 21 static const int kDefaultHostWindowY = 200; | 21 const int kDefaultHostWindowY = 200; |
| 22 static const int kDefaultHostWindowWidth = 1280; | 22 const int kDefaultHostWindowWidth = 1280; |
| 23 static const int kDefaultHostWindowHeight = 1024; | 23 const int kDefaultHostWindowHeight = 1024; |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 // static | 26 // static |
| 27 bool MonitorManager::use_fullscreen_host_window_ = false; | 27 bool MonitorManager::use_fullscreen_host_window_ = false; |
| 28 | 28 |
| 29 // static | 29 // static |
| 30 gfx::Monitor MonitorManager::CreateMonitorFromSpec(const std::string& spec) { | 30 gfx::Display MonitorManager::CreateMonitorFromSpec(const std::string& spec) { |
| 31 static int synthesized_monitor_id = 1000; | 31 static int synthesized_monitor_id = 1000; |
| 32 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, | 32 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, |
| 33 kDefaultHostWindowWidth, kDefaultHostWindowHeight); | 33 kDefaultHostWindowWidth, kDefaultHostWindowHeight); |
| 34 int x = 0, y = 0, width, height; | 34 int x = 0, y = 0, width, height; |
| 35 float scale = gfx::Monitor::GetDefaultDeviceScaleFactor(); | 35 float scale = gfx::Display::GetDefaultDeviceScaleFactor(); |
| 36 if (sscanf(spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2) { | 36 if (sscanf(spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2) { |
| 37 bounds.set_size(gfx::Size(width, height)); | 37 bounds.set_size(gfx::Size(width, height)); |
| 38 } else if (sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height, | 38 } else if (sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height, |
| 39 &scale) >= 4 ) { | 39 &scale) >= 4 ) { |
| 40 bounds = gfx::Rect(x, y, width, height); | 40 bounds = gfx::Rect(x, y, width, height); |
| 41 } else if (use_fullscreen_host_window_) { | 41 } else if (use_fullscreen_host_window_) { |
| 42 bounds = gfx::Rect(aura::RootWindowHost::GetNativeScreenSize()); | 42 bounds = gfx::Rect(aura::RootWindowHost::GetNativeScreenSize()); |
| 43 } | 43 } |
| 44 gfx::Monitor monitor(synthesized_monitor_id++); | 44 gfx::Display display(synthesized_monitor_id++); |
| 45 monitor.SetScaleAndBounds(scale, bounds); | 45 display.SetScaleAndBounds(scale, bounds); |
| 46 DVLOG(1) << "Monitor bounds=" << bounds.ToString() << ", scale=" << scale; | 46 DVLOG(1) << "Display bounds=" << bounds.ToString() << ", scale=" << scale; |
| 47 return monitor; | 47 return display; |
| 48 } | 48 } |
| 49 | 49 |
| 50 // static | 50 // static |
| 51 RootWindow* MonitorManager::CreateRootWindowForPrimaryMonitor() { | 51 RootWindow* MonitorManager::CreateRootWindowForPrimaryMonitor() { |
| 52 MonitorManager* manager = aura::Env::GetInstance()->monitor_manager(); | 52 MonitorManager* manager = aura::Env::GetInstance()->monitor_manager(); |
| 53 RootWindow* root = | 53 RootWindow* root = |
| 54 manager->CreateRootWindowForMonitor(manager->GetMonitorAt(0)); | 54 manager->CreateRootWindowForMonitor(manager->GetMonitorAt(0)); |
| 55 if (use_fullscreen_host_window_) | 55 if (use_fullscreen_host_window_) |
| 56 root->ConfineCursorToWindow(); | 56 root->ConfineCursorToWindow(); |
| 57 return root; | 57 return root; |
| 58 } | 58 } |
| 59 | 59 |
| 60 MonitorManager::MonitorManager() { | 60 MonitorManager::MonitorManager() { |
| 61 } | 61 } |
| 62 | 62 |
| 63 MonitorManager::~MonitorManager() { | 63 MonitorManager::~MonitorManager() { |
| 64 } | 64 } |
| 65 | 65 |
| 66 void MonitorManager::AddObserver(MonitorObserver* observer) { | 66 void MonitorManager::AddObserver(DisplayObserver* observer) { |
| 67 observers_.AddObserver(observer); | 67 observers_.AddObserver(observer); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void MonitorManager::RemoveObserver(MonitorObserver* observer) { | 70 void MonitorManager::RemoveObserver(DisplayObserver* observer) { |
| 71 observers_.RemoveObserver(observer); | 71 observers_.RemoveObserver(observer); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void MonitorManager::NotifyBoundsChanged(const gfx::Monitor& monitor) { | 74 void MonitorManager::NotifyBoundsChanged(const gfx::Display& display) { |
| 75 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 75 FOR_EACH_OBSERVER(DisplayObserver, observers_, |
| 76 OnMonitorBoundsChanged(monitor)); | 76 OnDisplayBoundsChanged(display)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void MonitorManager::NotifyMonitorAdded(const gfx::Monitor& monitor) { | 79 void MonitorManager::NotifyDisplayAdded(const gfx::Display& display) { |
| 80 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 80 FOR_EACH_OBSERVER(DisplayObserver, observers_, OnDisplayAdded(display)); |
| 81 OnMonitorAdded(monitor)); | |
| 82 } | 81 } |
| 83 | 82 |
| 84 void MonitorManager::NotifyMonitorRemoved(const gfx::Monitor& monitor) { | 83 void MonitorManager::NotifyDisplayRemoved(const gfx::Display& display) { |
| 85 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 84 FOR_EACH_OBSERVER(DisplayObserver, observers_, OnDisplayRemoved(display)); |
| 86 OnMonitorRemoved(monitor)); | |
| 87 } | 85 } |
| 88 | 86 |
| 89 } // namespace aura | 87 } // namespace aura |
| OLD | NEW |