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) == 2) { |
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); |
| 52 LOG(ERROR) << "monitor:" << bounds.ToString() << ", scale=" << scale; |
42 return monitor; | 53 return monitor; |
43 } | 54 } |
44 | 55 |
45 // static | 56 // static |
46 RootWindow* MonitorManager::CreateRootWindowForPrimaryMonitor() { | 57 RootWindow* MonitorManager::CreateRootWindowForPrimaryMonitor() { |
47 MonitorManager* manager = aura::Env::GetInstance()->monitor_manager(); | 58 MonitorManager* manager = aura::Env::GetInstance()->monitor_manager(); |
48 RootWindow* root = | 59 RootWindow* root = |
49 manager->CreateRootWindowForMonitor(manager->GetMonitorAt(0)); | 60 manager->CreateRootWindowForMonitor(manager->GetMonitorAt(0)); |
50 if (use_fullscreen_host_window_) | 61 if (use_fullscreen_host_window_) |
51 root->ConfineCursorToWindow(); | 62 root->ConfineCursorToWindow(); |
52 return root; | 63 return root; |
53 } | 64 } |
54 | 65 |
55 MonitorManager::MonitorManager() { | 66 MonitorManager::MonitorManager() { |
56 } | 67 } |
57 | 68 |
58 MonitorManager::~MonitorManager() { | 69 MonitorManager::~MonitorManager() { |
59 } | 70 } |
60 | 71 |
61 void MonitorManager::AddObserver(MonitorObserver* observer) { | 72 void MonitorManager::AddObserver(gfx::MonitorObserver* observer) { |
62 observers_.AddObserver(observer); | 73 observers_.AddObserver(observer); |
63 } | 74 } |
64 | 75 |
65 void MonitorManager::RemoveObserver(MonitorObserver* observer) { | 76 void MonitorManager::RemoveObserver(gfx::MonitorObserver* observer) { |
66 observers_.RemoveObserver(observer); | 77 observers_.RemoveObserver(observer); |
67 } | 78 } |
68 | 79 |
69 void MonitorManager::NotifyBoundsChanged(const Monitor* monitor) { | 80 void MonitorManager::NotifyBoundsChanged(const gfx::Monitor* monitor) { |
70 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 81 FOR_EACH_OBSERVER(gfx::MonitorObserver, observers_, |
71 OnMonitorBoundsChanged(monitor)); | 82 OnMonitorBoundsChanged(monitor)); |
72 } | 83 } |
73 | 84 |
74 void MonitorManager::NotifyMonitorAdded(Monitor* monitor) { | 85 void MonitorManager::NotifyMonitorAdded(gfx::Monitor* monitor) { |
75 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 86 FOR_EACH_OBSERVER(gfx::MonitorObserver, observers_, |
76 OnMonitorAdded(monitor)); | 87 OnMonitorAdded(monitor)); |
77 } | 88 } |
78 | 89 |
79 void MonitorManager::NotifyMonitorRemoved(const Monitor* monitor) { | 90 void MonitorManager::NotifyMonitorRemoved(const gfx::Monitor* monitor) { |
80 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 91 FOR_EACH_OBSERVER(gfx::MonitorObserver, observers_, |
81 OnMonitorRemoved(monitor)); | 92 OnMonitorRemoved(monitor)); |
82 } | 93 } |
83 | 94 |
84 } // namespace aura | 95 } // namespace aura |
OLD | NEW |