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