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 "chrome/browser/ui/webui/options2/chromeos/display_options_handler.h" | 5 #include "chrome/browser/ui/webui/options2/chromeos/display_options_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/monitor/monitor_controller.h" | 9 #include "ash/display/display_controller.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/json/json_value_converter.h" | 12 #include "base/json/json_value_converter.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chromeos/monitor/output_configurator.h" | 14 #include "chromeos/display/output_configurator.h" |
15 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
17 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
18 #include "ui/aura/monitor_manager.h" | 18 #include "ui/aura/display_manager.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
21 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
22 | 22 |
23 namespace chromeos { | 23 namespace chromeos { |
24 namespace options2 { | 24 namespace options2 { |
25 | 25 |
26 using ash::internal::MonitorController; | 26 using ash::internal::DisplayController; |
27 | 27 |
28 DisplayOptionsHandler::DisplayOptionsHandler() { | 28 DisplayOptionsHandler::DisplayOptionsHandler() { |
29 aura::Env::GetInstance()->monitor_manager()->AddObserver(this); | 29 aura::Env::GetInstance()->display_manager()->AddObserver(this); |
30 } | 30 } |
31 | 31 |
32 DisplayOptionsHandler::~DisplayOptionsHandler() { | 32 DisplayOptionsHandler::~DisplayOptionsHandler() { |
33 aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this); | 33 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); |
34 } | 34 } |
35 | 35 |
36 void DisplayOptionsHandler::GetLocalizedValues( | 36 void DisplayOptionsHandler::GetLocalizedValues( |
37 DictionaryValue* localized_strings) { | 37 DictionaryValue* localized_strings) { |
38 DCHECK(localized_strings); | 38 DCHECK(localized_strings); |
39 RegisterTitle(localized_strings, "displayOptionsPage", | 39 RegisterTitle(localized_strings, "displayOptionsPage", |
40 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_TAB_TITLE); | 40 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_TAB_TITLE); |
41 localized_strings->SetString("startMirroring", l10n_util::GetStringUTF16( | 41 localized_strings->SetString("startMirroring", l10n_util::GetStringUTF16( |
42 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_START_MIRRORING)); | 42 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_START_MIRRORING)); |
43 localized_strings->SetString("stopMirroring", l10n_util::GetStringUTF16( | 43 localized_strings->SetString("stopMirroring", l10n_util::GetStringUTF16( |
(...skipping 29 matching lines...) Expand all Loading... |
73 UpdateDisplaySectionVisibility(); | 73 UpdateDisplaySectionVisibility(); |
74 SendDisplayInfo(); | 74 SendDisplayInfo(); |
75 } | 75 } |
76 | 76 |
77 void DisplayOptionsHandler::OnDisplayRemoved(const gfx::Display& old_display) { | 77 void DisplayOptionsHandler::OnDisplayRemoved(const gfx::Display& old_display) { |
78 UpdateDisplaySectionVisibility(); | 78 UpdateDisplaySectionVisibility(); |
79 SendDisplayInfo(); | 79 SendDisplayInfo(); |
80 } | 80 } |
81 | 81 |
82 void DisplayOptionsHandler::UpdateDisplaySectionVisibility() { | 82 void DisplayOptionsHandler::UpdateDisplaySectionVisibility() { |
83 aura::MonitorManager* monitor_manager = | 83 aura::DisplayManager* display_manager = |
84 aura::Env::GetInstance()->monitor_manager(); | 84 aura::Env::GetInstance()->display_manager(); |
85 chromeos::State output_state = | 85 chromeos::State output_state = |
86 ash::Shell::GetInstance()->output_configurator()->output_state(); | 86 ash::Shell::GetInstance()->output_configurator()->output_state(); |
87 base::FundamentalValue show_options( | 87 base::FundamentalValue show_options( |
88 MonitorController::IsExtendedDesktopEnabled() && | 88 DisplayController::IsExtendedDesktopEnabled() && |
89 monitor_manager->GetNumDisplays() > 1 && | 89 display_manager->GetNumDisplays() > 1 && |
90 output_state != chromeos::STATE_INVALID && | 90 output_state != chromeos::STATE_INVALID && |
91 output_state != chromeos::STATE_HEADLESS && | 91 output_state != chromeos::STATE_HEADLESS && |
92 output_state != chromeos::STATE_SINGLE); | 92 output_state != chromeos::STATE_SINGLE); |
93 web_ui()->CallJavascriptFunction( | 93 web_ui()->CallJavascriptFunction( |
94 "options.BrowserOptions.showDisplayOptions", show_options); | 94 "options.BrowserOptions.showDisplayOptions", show_options); |
95 } | 95 } |
96 | 96 |
97 void DisplayOptionsHandler::SendDisplayInfo() { | 97 void DisplayOptionsHandler::SendDisplayInfo() { |
98 aura::MonitorManager* monitor_manager = | 98 aura::DisplayManager* display_manager = |
99 aura::Env::GetInstance()->monitor_manager(); | 99 aura::Env::GetInstance()->display_manager(); |
100 chromeos::OutputConfigurator* output_configurator = | 100 chromeos::OutputConfigurator* output_configurator = |
101 ash::Shell::GetInstance()->output_configurator(); | 101 ash::Shell::GetInstance()->output_configurator(); |
102 base::FundamentalValue mirroring( | 102 base::FundamentalValue mirroring( |
103 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR); | 103 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR); |
104 | 104 |
105 base::ListValue displays; | 105 base::ListValue displays; |
106 for (size_t i = 0; i < monitor_manager->GetNumDisplays(); ++i) { | 106 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
107 const gfx::Display& display = monitor_manager->GetDisplayAt(i); | 107 const gfx::Display& display = display_manager->GetDisplayAt(i); |
108 const gfx::Rect& bounds = display.bounds(); | 108 const gfx::Rect& bounds = display.bounds(); |
109 base::DictionaryValue* js_display = new base::DictionaryValue(); | 109 base::DictionaryValue* js_display = new base::DictionaryValue(); |
110 js_display->SetDouble("id", display.id()); | 110 js_display->SetDouble("id", display.id()); |
111 js_display->SetDouble("x", bounds.x()); | 111 js_display->SetDouble("x", bounds.x()); |
112 js_display->SetDouble("y", bounds.y()); | 112 js_display->SetDouble("y", bounds.y()); |
113 js_display->SetDouble("width", bounds.width()); | 113 js_display->SetDouble("width", bounds.width()); |
114 js_display->SetDouble("height", bounds.height()); | 114 js_display->SetDouble("height", bounds.height()); |
115 displays.Set(i, js_display); | 115 displays.Set(i, js_display); |
116 } | 116 } |
117 | 117 |
118 MonitorController* monitor_controller = | 118 DisplayController* display_controller = |
119 ash::Shell::GetInstance()->monitor_controller(); | 119 ash::Shell::GetInstance()->display_controller(); |
120 base::FundamentalValue layout(static_cast<int>( | 120 base::FundamentalValue layout(static_cast<int>( |
121 monitor_controller->secondary_display_layout())); | 121 display_controller->secondary_display_layout())); |
122 | 122 |
123 web_ui()->CallJavascriptFunction( | 123 web_ui()->CallJavascriptFunction( |
124 "options.DisplayOptions.setDisplayInfo", | 124 "options.DisplayOptions.setDisplayInfo", |
125 mirroring, displays, layout); | 125 mirroring, displays, layout); |
126 } | 126 } |
127 | 127 |
128 void DisplayOptionsHandler::HandleDisplayInfo( | 128 void DisplayOptionsHandler::HandleDisplayInfo( |
129 const base::ListValue* unused_args) { | 129 const base::ListValue* unused_args) { |
130 SendDisplayInfo(); | 130 SendDisplayInfo(); |
131 } | 131 } |
132 | 132 |
133 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) { | 133 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) { |
134 DCHECK(!args->empty()); | 134 DCHECK(!args->empty()); |
135 bool is_mirroring = false; | 135 bool is_mirroring = false; |
136 args->GetBoolean(0, &is_mirroring); | 136 args->GetBoolean(0, &is_mirroring); |
137 // We use 'PRIMARY_ONLY' for non-mirroring state for now. | 137 // We use 'PRIMARY_ONLY' for non-mirroring state for now. |
138 // TODO(mukai): fix this and support multiple display modes. | 138 // TODO(mukai): fix this and support multiple display modes. |
139 chromeos::State new_state = | 139 chromeos::State new_state = |
140 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_PRIMARY_ONLY; | 140 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_PRIMARY_ONLY; |
141 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state); | 141 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state); |
142 SendDisplayInfo(); | 142 SendDisplayInfo(); |
143 } | 143 } |
144 | 144 |
145 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) { | 145 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) { |
146 double layout = -1; | 146 double layout = -1; |
147 if (!args->GetDouble(0, &layout)) { | 147 if (!args->GetDouble(0, &layout)) { |
148 LOG(ERROR) << "Invalid parameter"; | 148 LOG(ERROR) << "Invalid parameter"; |
149 return; | 149 return; |
150 } | 150 } |
151 DCHECK_LE(MonitorController::TOP, layout); | 151 DCHECK_LE(DisplayController::TOP, layout); |
152 DCHECK_GE(MonitorController::LEFT, layout); | 152 DCHECK_GE(DisplayController::LEFT, layout); |
153 | 153 |
154 ash::Shell::GetInstance()->monitor_controller()->SetSecondaryDisplayLayout( | 154 ash::Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout( |
155 static_cast<MonitorController::SecondaryDisplayLayout>(layout)); | 155 static_cast<DisplayController::SecondaryDisplayLayout>(layout)); |
156 SendDisplayInfo(); | 156 SendDisplayInfo(); |
157 } | 157 } |
158 | 158 |
159 } // namespace options2 | 159 } // namespace options2 |
160 } // namespace chromeos | 160 } // namespace chromeos |
OLD | NEW |