OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/aura/display_manager.h" | |
6 | |
7 #include <stdio.h> | |
8 | |
9 #include "base/logging.h" | |
10 #include "ui/aura/display_observer.h" | |
11 #include "ui/aura/env.h" | |
12 #include "ui/aura/root_window.h" | |
13 #include "ui/aura/root_window_host.h" | |
14 #include "ui/gfx/display.h" | |
15 #include "ui/gfx/rect.h" | |
16 | |
17 namespace aura { | |
18 namespace { | |
19 // Default bounds for a display. | |
20 const int kDefaultHostWindowX = 200; | |
21 const int kDefaultHostWindowY = 200; | |
22 const int kDefaultHostWindowWidth = 1280; | |
23 const int kDefaultHostWindowHeight = 1024; | |
24 } // namespace | |
25 | |
26 // static | |
27 bool DisplayManager::use_fullscreen_host_window_ = false; | |
28 | |
29 // static | |
30 gfx::Display DisplayManager::CreateDisplayFromSpec(const std::string& spec) { | |
31 static int64 synthesized_display_id = 1000; | |
32 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, | |
33 kDefaultHostWindowWidth, kDefaultHostWindowHeight); | |
34 int x = 0, y = 0, width, height; | |
35 float scale = 1.0f; | |
36 if (sscanf(spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2 || | |
37 sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height, | |
38 &scale) >= 4) { | |
39 bounds.SetRect(x, y, width, height); | |
40 } else if (use_fullscreen_host_window_) { | |
41 bounds = gfx::Rect(aura::RootWindowHost::GetNativeScreenSize()); | |
42 } | |
43 gfx::Display display(synthesized_display_id++); | |
44 display.SetScaleAndBounds(scale, bounds); | |
45 DVLOG(1) << "Display bounds=" << bounds.ToString() << ", scale=" << scale; | |
46 return display; | |
47 } | |
48 | |
49 // static | |
50 RootWindow* DisplayManager::CreateRootWindowForPrimaryDisplay() { | |
51 DisplayManager* manager = aura::Env::GetInstance()->display_manager(); | |
52 RootWindow* root = | |
53 manager->CreateRootWindowForDisplay(*manager->GetDisplayAt(0)); | |
54 if (use_fullscreen_host_window_) | |
55 root->ConfineCursorToWindow(); | |
56 return root; | |
57 } | |
58 | |
59 DisplayManager::DisplayManager() { | |
60 } | |
61 | |
62 DisplayManager::~DisplayManager() { | |
63 } | |
64 | |
65 void DisplayManager::AddObserver(DisplayObserver* observer) { | |
66 observers_.AddObserver(observer); | |
67 } | |
68 | |
69 void DisplayManager::RemoveObserver(DisplayObserver* observer) { | |
70 observers_.RemoveObserver(observer); | |
71 } | |
72 | |
73 void DisplayManager::NotifyBoundsChanged(const gfx::Display& display) { | |
74 FOR_EACH_OBSERVER(DisplayObserver, observers_, | |
75 OnDisplayBoundsChanged(display)); | |
76 } | |
77 | |
78 void DisplayManager::NotifyDisplayAdded(const gfx::Display& display) { | |
79 FOR_EACH_OBSERVER(DisplayObserver, observers_, OnDisplayAdded(display)); | |
80 } | |
81 | |
82 void DisplayManager::NotifyDisplayRemoved(const gfx::Display& display) { | |
83 FOR_EACH_OBSERVER(DisplayObserver, observers_, OnDisplayRemoved(display)); | |
84 } | |
85 | |
86 } // namespace aura | |
OLD | NEW |