| 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/env.h" | 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/monitor.h" | 11 #include "ui/aura/monitor_aura.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/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 #include "ui/gfx/monitor_observer.h" |
| 15 | 16 |
| 16 namespace aura { | 17 namespace aura { |
| 17 namespace { | 18 namespace { |
| 18 // Default bounds for a monitor. | 19 // Default bounds for a monitor. |
| 19 static const int kDefaultHostWindowX = 200; | 20 static const int kDefaultHostWindowX = 200; |
| 20 static const int kDefaultHostWindowY = 200; | 21 static const int kDefaultHostWindowY = 200; |
| 21 static const int kDefaultHostWindowWidth = 1280; | 22 static const int kDefaultHostWindowWidth = 1280; |
| 22 static const int kDefaultHostWindowHeight = 1024; | 23 static const int kDefaultHostWindowHeight = 1024; |
| 23 } // namespace | 24 } // namespace |
| 24 | 25 |
| 25 // static | 26 // static |
| 26 bool MonitorManager::use_fullscreen_host_window_ = false; | 27 bool MonitorManager::use_fullscreen_host_window_ = false; |
| 27 | 28 |
| 28 // static | 29 // static |
| 29 Monitor* MonitorManager::CreateMonitorFromSpec(const std::string& spec) { | 30 MonitorAura* MonitorManager::CreateMonitorFromSpec(const std::string& spec) { |
| 30 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, | 31 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, |
| 31 kDefaultHostWindowWidth, kDefaultHostWindowHeight); | 32 kDefaultHostWindowWidth, kDefaultHostWindowHeight); |
| 32 int x = 0, y = 0, width, height; | 33 int x = 0, y = 0, width, height; |
| 33 float scale = 1.0f; | 34 float scale = 1.0f; |
| 34 if (sscanf(spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2) { | 35 if (sscanf(spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2) { |
| 35 bounds.set_size(gfx::Size(width, height)); | 36 bounds.set_size(gfx::Size(width, height)); |
| 36 } else if (sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height, | 37 } else if (sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height, |
| 37 &scale) >= 4 ) { | 38 &scale) >= 4 ) { |
| 38 bounds = gfx::Rect(x, y, width, height); | 39 bounds = gfx::Rect(x, y, width, height); |
| 39 } else if (use_fullscreen_host_window_) { | 40 } else if (use_fullscreen_host_window_) { |
| 40 bounds = gfx::Rect(aura::RootWindowHost::GetNativeScreenSize()); | 41 bounds = gfx::Rect(aura::RootWindowHost::GetNativeScreenSize()); |
| 41 } | 42 } |
| 42 Monitor* monitor = new Monitor(); | 43 MonitorAura* monitor = new MonitorAura(); |
| 43 monitor->set_bounds(bounds); | 44 monitor->set_bounds(bounds); |
| 45 monitor->set_device_scale_factor(scale); |
| 44 VLOG(1) << "Monitor bounds=" << bounds.ToString() << ", scale=" << scale; | 46 VLOG(1) << "Monitor bounds=" << bounds.ToString() << ", scale=" << scale; |
| 45 return monitor; | 47 return monitor; |
| 46 } | 48 } |
| 47 | 49 |
| 48 // static | 50 // static |
| 49 RootWindow* MonitorManager::CreateRootWindowForPrimaryMonitor() { | 51 RootWindow* MonitorManager::CreateRootWindowForPrimaryMonitor() { |
| 50 MonitorManager* manager = aura::Env::GetInstance()->monitor_manager(); | 52 MonitorManager* manager = aura::Env::GetInstance()->monitor_manager(); |
| 51 RootWindow* root = | 53 RootWindow* root = |
| 52 manager->CreateRootWindowForMonitor(manager->GetMonitorAt(0)); | 54 manager->CreateRootWindowForMonitor(manager->GetMonitorAt(0)); |
| 53 if (use_fullscreen_host_window_) | 55 if (use_fullscreen_host_window_) |
| 54 root->ConfineCursorToWindow(); | 56 root->ConfineCursorToWindow(); |
| 55 return root; | 57 return root; |
| 56 } | 58 } |
| 57 | 59 |
| 58 MonitorManager::MonitorManager() { | 60 MonitorManager::MonitorManager() { |
| 59 } | 61 } |
| 60 | 62 |
| 61 MonitorManager::~MonitorManager() { | 63 MonitorManager::~MonitorManager() { |
| 62 } | 64 } |
| 63 | 65 |
| 64 void MonitorManager::AddObserver(MonitorObserver* observer) { | 66 void MonitorManager::AddObserver(gfx::MonitorObserver* observer) { |
| 65 observers_.AddObserver(observer); | 67 observers_.AddObserver(observer); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void MonitorManager::RemoveObserver(MonitorObserver* observer) { | 70 void MonitorManager::RemoveObserver(gfx::MonitorObserver* observer) { |
| 69 observers_.RemoveObserver(observer); | 71 observers_.RemoveObserver(observer); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void MonitorManager::NotifyBoundsChanged(const Monitor* monitor) { | 74 void MonitorManager::NotifyBoundsChanged(const gfx::Monitor* monitor) { |
| 73 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 75 FOR_EACH_OBSERVER(gfx::MonitorObserver, observers_, |
| 74 OnMonitorBoundsChanged(monitor)); | 76 OnMonitorBoundsChanged(monitor)); |
| 75 } | 77 } |
| 76 | 78 |
| 77 void MonitorManager::NotifyMonitorAdded(Monitor* monitor) { | 79 void MonitorManager::NotifyMonitorAdded(gfx::Monitor* monitor) { |
| 78 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 80 FOR_EACH_OBSERVER(gfx::MonitorObserver, observers_, |
| 79 OnMonitorAdded(monitor)); | 81 OnMonitorAdded(monitor)); |
| 80 } | 82 } |
| 81 | 83 |
| 82 void MonitorManager::NotifyMonitorRemoved(const Monitor* monitor) { | 84 void MonitorManager::NotifyMonitorRemoved(const gfx::Monitor* monitor) { |
| 83 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 85 FOR_EACH_OBSERVER(gfx::MonitorObserver, observers_, |
| 84 OnMonitorRemoved(monitor)); | 86 OnMonitorRemoved(monitor)); |
| 85 } | 87 } |
| 86 | 88 |
| 87 } // namespace aura | 89 } // namespace aura |
| OLD | NEW |