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/command_line.h" | |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/string_number_conversions.h" | |
10 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
13 #include "ui/aura/aura_switches.h" | |
11 #include "ui/aura/monitor_observer.h" | 14 #include "ui/aura/monitor_observer.h" |
12 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
13 #include "ui/aura/root_window_host.h" | 16 #include "ui/aura/root_window_host.h" |
14 #include "ui/gfx/monitor.h" | 17 #include "ui/gfx/monitor.h" |
15 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
16 | 19 |
17 namespace aura { | 20 namespace aura { |
18 namespace { | 21 namespace { |
19 // Default bounds for a monitor. | 22 // Default bounds for a monitor. |
20 static const int kDefaultHostWindowX = 200; | 23 static const int kDefaultHostWindowX = 200; |
21 static const int kDefaultHostWindowY = 200; | 24 static const int kDefaultHostWindowY = 200; |
22 static const int kDefaultHostWindowWidth = 1280; | 25 static const int kDefaultHostWindowWidth = 1280; |
23 static const int kDefaultHostWindowHeight = 1024; | 26 static const int kDefaultHostWindowHeight = 1024; |
24 } // namespace | 27 } // namespace |
25 | 28 |
26 // static | 29 // static |
27 bool MonitorManager::use_fullscreen_host_window_ = false; | 30 bool MonitorManager::use_fullscreen_host_window_ = false; |
28 | 31 |
29 // static | 32 // static |
30 gfx::Monitor MonitorManager::CreateMonitorFromSpec(const std::string& spec) { | 33 gfx::Monitor MonitorManager::CreateMonitorFromSpec( |
34 float device_scale_factor, const std::string& spec) { | |
sadrul
2012/04/30 15:15:49
one param in a line
| |
31 static int synthesized_monitor_id = 1000; | 35 static int synthesized_monitor_id = 1000; |
32 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, | 36 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, |
33 kDefaultHostWindowWidth, kDefaultHostWindowHeight); | 37 kDefaultHostWindowWidth, kDefaultHostWindowHeight); |
34 int x = 0, y = 0, width, height; | 38 int x = 0, y = 0, width, height; |
35 float scale = 1.0f; | 39 float scale = device_scale_factor; |
36 if (sscanf(spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2) { | 40 if (sscanf(spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2) { |
37 bounds.set_size(gfx::Size(width, height)); | 41 bounds.set_size(gfx::Size(width, height)); |
38 } else if (sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height, | 42 } else if (sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height, |
39 &scale) >= 4 ) { | 43 &scale) >= 4 ) { |
40 bounds = gfx::Rect(x, y, width, height); | 44 bounds = gfx::Rect(x, y, width, height); |
41 } else if (use_fullscreen_host_window_) { | 45 } else if (use_fullscreen_host_window_) { |
42 bounds = gfx::Rect(aura::RootWindowHost::GetNativeScreenSize()); | 46 bounds = gfx::Rect(aura::RootWindowHost::GetNativeScreenSize()); |
43 } | 47 } |
44 gfx::Monitor monitor(synthesized_monitor_id++); | 48 gfx::Monitor monitor(synthesized_monitor_id++); |
45 monitor.SetScaleAndBounds(scale, bounds); | 49 monitor.SetScaleAndBounds(scale, bounds); |
46 DVLOG(1) << "Monitor bounds=" << bounds.ToString() << ", scale=" << scale; | 50 DVLOG(1) << "Monitor bounds=" << bounds.ToString() << ", scale=" << scale; |
47 return monitor; | 51 return monitor; |
48 } | 52 } |
49 | 53 |
50 // static | 54 // static |
51 RootWindow* MonitorManager::CreateRootWindowForPrimaryMonitor() { | 55 RootWindow* MonitorManager::CreateRootWindowForPrimaryMonitor() { |
52 MonitorManager* manager = aura::Env::GetInstance()->monitor_manager(); | 56 MonitorManager* manager = aura::Env::GetInstance()->monitor_manager(); |
53 RootWindow* root = | 57 RootWindow* root = |
54 manager->CreateRootWindowForMonitor(manager->GetMonitorAt(0)); | 58 manager->CreateRootWindowForMonitor(manager->GetMonitorAt(0)); |
55 if (use_fullscreen_host_window_) | 59 if (use_fullscreen_host_window_) |
56 root->ConfineCursorToWindow(); | 60 root->ConfineCursorToWindow(); |
57 return root; | 61 return root; |
58 } | 62 } |
59 | 63 |
60 MonitorManager::MonitorManager() { | 64 MonitorManager::MonitorManager() : default_device_scale_factor_(1.0f) { |
65 | |
sadrul
2012/04/30 15:15:49
-newline
| |
66 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
67 if (command_line.HasSwitch(switches::kDefaultDeviceScaleFactor)) { | |
68 double scale_in_double; | |
69 base::StringToDouble( | |
70 command_line.GetSwitchValueASCII(switches::kDefaultDeviceScaleFactor), | |
71 &scale_in_double); | |
72 default_device_scale_factor_ = static_cast<float>(scale_in_double); | |
73 } | |
61 } | 74 } |
62 | 75 |
63 MonitorManager::~MonitorManager() { | 76 MonitorManager::~MonitorManager() { |
64 } | 77 } |
65 | 78 |
66 void MonitorManager::AddObserver(MonitorObserver* observer) { | 79 void MonitorManager::AddObserver(MonitorObserver* observer) { |
67 observers_.AddObserver(observer); | 80 observers_.AddObserver(observer); |
68 } | 81 } |
69 | 82 |
70 void MonitorManager::RemoveObserver(MonitorObserver* observer) { | 83 void MonitorManager::RemoveObserver(MonitorObserver* observer) { |
71 observers_.RemoveObserver(observer); | 84 observers_.RemoveObserver(observer); |
72 } | 85 } |
73 | 86 |
74 void MonitorManager::NotifyBoundsChanged(const gfx::Monitor& monitor) { | 87 void MonitorManager::NotifyBoundsChanged(const gfx::Monitor& monitor) { |
75 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 88 FOR_EACH_OBSERVER(MonitorObserver, observers_, |
76 OnMonitorBoundsChanged(monitor)); | 89 OnMonitorBoundsChanged(monitor)); |
77 } | 90 } |
78 | 91 |
79 void MonitorManager::NotifyMonitorAdded(const gfx::Monitor& monitor) { | 92 void MonitorManager::NotifyMonitorAdded(const gfx::Monitor& monitor) { |
80 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 93 FOR_EACH_OBSERVER(MonitorObserver, observers_, |
81 OnMonitorAdded(monitor)); | 94 OnMonitorAdded(monitor)); |
82 } | 95 } |
83 | 96 |
84 void MonitorManager::NotifyMonitorRemoved(const gfx::Monitor& monitor) { | 97 void MonitorManager::NotifyMonitorRemoved(const gfx::Monitor& monitor) { |
85 FOR_EACH_OBSERVER(MonitorObserver, observers_, | 98 FOR_EACH_OBSERVER(MonitorObserver, observers_, |
86 OnMonitorRemoved(monitor)); | 99 OnMonitorRemoved(monitor)); |
87 } | 100 } |
88 | 101 |
89 } // namespace aura | 102 } // namespace aura |
OLD | NEW |