Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: ash/monitor/monitor_controller.cc

Issue 9960042: Refactor screen/monitor so that gfx::Screen returns monitor object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/monitor/monitor_controller.h ('k') | ash/monitor/multi_monitor_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/monitor/monitor_controller.h" 5 #include "ash/monitor/monitor_controller.h"
6 6
7 #include "ash/monitor/multi_monitor_manager.h" 7 #include "ash/monitor/multi_monitor_manager.h"
8 #include "ash/monitor/secondary_monitor_view.h" 8 #include "ash/monitor/secondary_monitor_view.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/base_layout_manager.h" 10 #include "ash/wm/base_layout_manager.h"
11 #include "ash/wm/root_window_layout_manager.h" 11 #include "ash/wm/root_window_layout_manager.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "ui/aura/env.h" 15 #include "ui/aura/env.h"
16 #include "ui/aura/monitor.h"
17 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
18 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/gfx/monitor.h"
19 19
20 namespace ash { 20 namespace ash {
21 namespace internal { 21 namespace internal {
22 22
23 namespace { 23 namespace {
24 24
25 void SetupAsSecondaryMonitor(aura::RootWindow* root) { 25 void SetupAsSecondaryMonitor(aura::RootWindow* root) {
26 root->SetFocusWhenShown(false); 26 root->SetFocusWhenShown(false);
27 root->SetLayoutManager(new internal::RootWindowLayoutManager(root)); 27 root->SetLayoutManager(new internal::RootWindowLayoutManager(root));
28 aura::Window* container = new aura::Window(NULL); 28 aura::Window* container = new aura::Window(NULL);
(...skipping 10 matching lines...) Expand all
39 } // namespace 39 } // namespace
40 40
41 MonitorController::MonitorController() { 41 MonitorController::MonitorController() {
42 aura::Env::GetInstance()->monitor_manager()->AddObserver(this); 42 aura::Env::GetInstance()->monitor_manager()->AddObserver(this);
43 Init(); 43 Init();
44 } 44 }
45 45
46 MonitorController::~MonitorController() { 46 MonitorController::~MonitorController() {
47 aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this); 47 aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this);
48 // Remove the root first. 48 // Remove the root first.
49 aura::Monitor* monitor = Shell::GetRootWindow()->GetProperty(kMonitorKey); 49 int monitor_id = Shell::GetRootWindow()->GetProperty(kMonitorIdKey);
50 DCHECK(monitor); 50 DCHECK(monitor_id >= 0);
51 root_windows_.erase(monitor); 51 root_windows_.erase(monitor_id);
52 STLDeleteContainerPairSecondPointers( 52 STLDeleteContainerPairSecondPointers(
53 root_windows_.begin(), root_windows_.end()); 53 root_windows_.begin(), root_windows_.end());
54 } 54 }
55 55
56 void MonitorController::OnMonitorBoundsChanged(const aura::Monitor* monitor) { 56 void MonitorController::OnMonitorBoundsChanged(const gfx::Monitor& monitor) {
57 root_windows_[monitor]->SetHostBounds(monitor->bounds()); 57 root_windows_[monitor.id()]->SetHostBounds(monitor.bounds());
58 } 58 }
59 59
60 void MonitorController::OnMonitorAdded(aura::Monitor* monitor) { 60 void MonitorController::OnMonitorAdded(const gfx::Monitor& monitor) {
61 if (root_windows_.empty()) { 61 if (root_windows_.empty()) {
62 root_windows_[monitor] = Shell::GetRootWindow(); 62 root_windows_[monitor.id()] = Shell::GetRootWindow();
63 Shell::GetRootWindow()->SetHostBounds(monitor->bounds()); 63 Shell::GetRootWindow()->SetHostBounds(monitor.bounds());
64 return; 64 return;
65 } 65 }
66 aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> 66 aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()->
67 CreateRootWindowForMonitor(monitor); 67 CreateRootWindowForMonitor(monitor);
68 root_windows_[monitor] = root; 68 root_windows_[monitor.id()] = root;
69 SetupAsSecondaryMonitor(root); 69 SetupAsSecondaryMonitor(root);
70 } 70 }
71 71
72 void MonitorController::OnMonitorRemoved(const aura::Monitor* monitor) { 72 void MonitorController::OnMonitorRemoved(const gfx::Monitor& monitor) {
73 aura::RootWindow* root = root_windows_[monitor]; 73 aura::RootWindow* root = root_windows_[monitor.id()];
74 DCHECK(root); 74 DCHECK(root);
75 // Primary monitor should never be removed by MonitorManager. 75 // Primary monitor should never be removed by MonitorManager.
76 DCHECK(root != Shell::GetRootWindow()); 76 DCHECK(root != Shell::GetRootWindow());
77 // Monitor for root window will be deleted when the Primary RootWindow 77 // Monitor for root window will be deleted when the Primary RootWindow
78 // is deleted by the Shell. 78 // is deleted by the Shell.
79 if (root != Shell::GetRootWindow()) { 79 if (root != Shell::GetRootWindow()) {
80 root_windows_.erase(monitor); 80 root_windows_.erase(monitor.id());
81 delete root; 81 delete root;
82 } 82 }
83 } 83 }
84 84
85 void MonitorController::Init() { 85 void MonitorController::Init() {
86 aura::MonitorManager* monitor_manager = 86 aura::MonitorManager* monitor_manager =
87 aura::Env::GetInstance()->monitor_manager(); 87 aura::Env::GetInstance()->monitor_manager();
88 for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) { 88 for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) {
89 aura::Monitor* monitor = monitor_manager->GetMonitorAt(i); 89 const gfx::Monitor& monitor = monitor_manager->GetMonitorAt(i);
90 const aura::Monitor* key = monitor;
91 if (i == 0) { 90 if (i == 0) {
92 // Primary monitor 91 // Primary monitor
93 root_windows_[key] = Shell::GetRootWindow(); 92 root_windows_[monitor.id()] = Shell::GetRootWindow();
94 Shell::GetRootWindow()->SetHostBounds(monitor->bounds()); 93 Shell::GetRootWindow()->SetHostBounds(monitor.bounds());
95 } else { 94 } else {
96 aura::RootWindow* root = 95 aura::RootWindow* root =
97 monitor_manager->CreateRootWindowForMonitor(monitor); 96 monitor_manager->CreateRootWindowForMonitor(monitor);
98 root_windows_[key] = root; 97 root_windows_[monitor.id()] = root;
99 SetupAsSecondaryMonitor(root); 98 SetupAsSecondaryMonitor(root);
100 } 99 }
101 } 100 }
102 } 101 }
103 102
104 } // namespace internal 103 } // namespace internal
105 } // namespace ash 104 } // namespace ash
OLDNEW
« no previous file with comments | « ash/monitor/monitor_controller.h ('k') | ash/monitor/multi_monitor_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698