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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/display_options_handler.cc

Issue 10870036: Allow storing display preferences per device. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move to chrome/browser/chromeos/display Created 8 years, 3 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
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 "chrome/browser/ui/webui/options/chromeos/display_options_handler.h" 5 #include "chrome/browser/ui/webui/options/chromeos/display_options_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/display/display_controller.h" 9 #include "ash/display/display_controller.h"
10 #include "ash/display/output_configurator_animation.h" 10 #include "ash/display/output_configurator_animation.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/json/json_value_converter.h" 13 #include "base/json/json_value_converter.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/chromeos/display/display_preferences.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chromeos/display/output_configurator.h" 20 #include "chromeos/display/output_configurator.h"
21 #include "content/public/browser/web_ui.h" 21 #include "content/public/browser/web_ui.h"
22 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
23 #include "ui/aura/env.h" 23 #include "ui/aura/env.h"
24 #include "ui/aura/display_manager.h" 24 #include "ui/aura/display_manager.h"
25 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/gfx/display.h" 26 #include "ui/gfx/display.h"
27 #include "ui/gfx/rect.h" 27 #include "ui/gfx/rect.h"
28 28
29 namespace chromeos { 29 namespace chromeos {
30 namespace options { 30 namespace options {
31 31
32 using ash::internal::DisplayController; 32 using ash::internal::DisplayLayout;
33 33
34 DisplayOptionsHandler::DisplayOptionsHandler() { 34 DisplayOptionsHandler::DisplayOptionsHandler() {
35 aura::Env::GetInstance()->display_manager()->AddObserver(this); 35 aura::Env::GetInstance()->display_manager()->AddObserver(this);
36 } 36 }
37 37
38 DisplayOptionsHandler::~DisplayOptionsHandler() { 38 DisplayOptionsHandler::~DisplayOptionsHandler() {
39 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); 39 aura::Env::GetInstance()->display_manager()->RemoveObserver(this);
40 } 40 }
41 41
42 void DisplayOptionsHandler::GetLocalizedValues( 42 void DisplayOptionsHandler::GetLocalizedValues(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 void DisplayOptionsHandler::OnDisplayRemoved(const gfx::Display& old_display) { 87 void DisplayOptionsHandler::OnDisplayRemoved(const gfx::Display& old_display) {
88 UpdateDisplaySectionVisibility(); 88 UpdateDisplaySectionVisibility();
89 SendDisplayInfo(); 89 SendDisplayInfo();
90 } 90 }
91 91
92 void DisplayOptionsHandler::UpdateDisplaySectionVisibility() { 92 void DisplayOptionsHandler::UpdateDisplaySectionVisibility() {
93 chromeos::OutputState output_state = 93 chromeos::OutputState output_state =
94 ash::Shell::GetInstance()->output_configurator()->output_state(); 94 ash::Shell::GetInstance()->output_configurator()->output_state();
95 base::FundamentalValue show_options( 95 base::FundamentalValue show_options(
96 DisplayController::IsExtendedDesktopEnabled() && 96 ash::internal::DisplayController::IsExtendedDesktopEnabled() &&
97 output_state != chromeos::STATE_INVALID && 97 output_state != chromeos::STATE_INVALID &&
98 output_state != chromeos::STATE_HEADLESS && 98 output_state != chromeos::STATE_HEADLESS &&
99 output_state != chromeos::STATE_SINGLE); 99 output_state != chromeos::STATE_SINGLE);
100 web_ui()->CallJavascriptFunction( 100 web_ui()->CallJavascriptFunction(
101 "options.BrowserOptions.showDisplayOptions", show_options); 101 "options.BrowserOptions.showDisplayOptions", show_options);
102 } 102 }
103 103
104 void DisplayOptionsHandler::SendDisplayInfo() { 104 void DisplayOptionsHandler::SendDisplayInfo() {
105 aura::DisplayManager* display_manager = 105 aura::DisplayManager* display_manager =
106 aura::Env::GetInstance()->display_manager(); 106 aura::Env::GetInstance()->display_manager();
107 ash::internal::DisplayController* display_controller =
sky 2012/08/29 15:05:57 Classes that are needed outside of ash shouldn't b
Jun Mukai 2012/08/30 02:08:04 Done.
108 ash::Shell::GetInstance()->display_controller();
107 chromeos::OutputConfigurator* output_configurator = 109 chromeos::OutputConfigurator* output_configurator =
108 ash::Shell::GetInstance()->output_configurator(); 110 ash::Shell::GetInstance()->output_configurator();
109 base::FundamentalValue mirroring( 111 base::FundamentalValue mirroring(
110 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR); 112 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR);
111 113
112 base::ListValue displays; 114 base::ListValue displays;
113 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { 115 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
114 const gfx::Display* display = display_manager->GetDisplayAt(i); 116 const gfx::Display* display = display_manager->GetDisplayAt(i);
115 const gfx::Rect& bounds = display->bounds(); 117 const gfx::Rect& bounds = display->bounds();
116 base::DictionaryValue* js_display = new base::DictionaryValue(); 118 base::DictionaryValue* js_display = new base::DictionaryValue();
117 js_display->SetDouble("id", display->id()); 119 js_display->SetDouble("id", display->id());
118 js_display->SetDouble("x", bounds.x()); 120 js_display->SetDouble("x", bounds.x());
119 js_display->SetDouble("y", bounds.y()); 121 js_display->SetDouble("y", bounds.y());
120 js_display->SetDouble("width", bounds.width()); 122 js_display->SetDouble("width", bounds.width());
121 js_display->SetDouble("height", bounds.height()); 123 js_display->SetDouble("height", bounds.height());
122 js_display->SetString("name", display_manager->GetDisplayNameAt(i)); 124 js_display->SetString("name", display_manager->GetDisplayNameAt(i));
123 displays.Set(i, js_display); 125 displays.Set(i, js_display);
124 } 126 }
125 127
126 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 128 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue());
127 base::FundamentalValue layout( 129 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue());
128 pref_service->GetInteger(prefs::kSecondaryDisplayLayout)); 130 if (display_manager->GetNumDisplays() > 1) {
129 base::FundamentalValue offset( 131 const std::string& secondary_display_name =
130 pref_service->GetInteger(prefs::kSecondaryDisplayOffset)); 132 display_manager->GetDisplayNameAt(1);
133 const DisplayLayout& layout =
134 display_controller->GetLayoutForDisplayName(secondary_display_name);
135 layout_value.reset(new base::FundamentalValue(layout.position));
136 offset_value.reset(new base::FundamentalValue(layout.offset));
137 }
131 138
132 web_ui()->CallJavascriptFunction( 139 web_ui()->CallJavascriptFunction(
133 "options.DisplayOptions.setDisplayInfo", 140 "options.DisplayOptions.setDisplayInfo",
134 mirroring, displays, layout, offset); 141 mirroring, displays, *layout_value, *offset_value);
135 } 142 }
136 143
137 void DisplayOptionsHandler::FadeOutForMirroringFinished(bool is_mirroring) { 144 void DisplayOptionsHandler::FadeOutForMirroringFinished(bool is_mirroring) {
138 // We use 'PRIMARY_ONLY' for non-mirroring state for now. 145 // We use 'PRIMARY_ONLY' for non-mirroring state for now.
139 // TODO(mukai): fix this and support multiple display modes. 146 // TODO(mukai): fix this and support multiple display modes.
140 chromeos::OutputState new_state = 147 chromeos::OutputState new_state =
141 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_PRIMARY_ONLY; 148 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_PRIMARY_ONLY;
142 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state); 149 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state);
143 SendDisplayInfo(); 150 SendDisplayInfo();
144 // Not necessary to start fade-in animation. OutputConfigurator will do that. 151 // Not necessary to start fade-in animation. OutputConfigurator will do that.
145 } 152 }
146 153
147 void DisplayOptionsHandler::FadeOutForDisplayLayoutFinished( 154 void DisplayOptionsHandler::FadeOutForDisplayLayoutFinished(
148 int layout, int offset) { 155 int layout, int offset) {
149 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 156 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
150 pref_service->SetInteger(prefs::kSecondaryDisplayLayout, layout); 157 aura::DisplayManager* display_manager =
151 pref_service->SetInteger(prefs::kSecondaryDisplayOffset, offset); 158 aura::Env::GetInstance()->display_manager();
159 // Assumes that there are two displays at most and the second item is the
160 // secondary display.
161 if (display_manager->GetNumDisplays() > 1) {
162 gfx::Display* display = display_manager->GetDisplayAt(1);
163 SetDisplayLayoutPref(pref_service, *display, layout, offset);
164 }
165
152 SendDisplayInfo(); 166 SendDisplayInfo();
153 ash::Shell::GetInstance()->output_configurator_animation()-> 167 ash::Shell::GetInstance()->output_configurator_animation()->
154 StartFadeInAnimation(); 168 StartFadeInAnimation();
155 } 169 }
156 170
157 void DisplayOptionsHandler::HandleDisplayInfo( 171 void DisplayOptionsHandler::HandleDisplayInfo(
158 const base::ListValue* unused_args) { 172 const base::ListValue* unused_args) {
159 SendDisplayInfo(); 173 SendDisplayInfo();
160 } 174 }
161 175
162 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) { 176 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) {
163 DCHECK(!args->empty()); 177 DCHECK(!args->empty());
164 bool is_mirroring = false; 178 bool is_mirroring = false;
165 args->GetBoolean(0, &is_mirroring); 179 args->GetBoolean(0, &is_mirroring);
166 ash::Shell::GetInstance()->output_configurator_animation()-> 180 ash::Shell::GetInstance()->output_configurator_animation()->
167 StartFadeOutAnimation(base::Bind( 181 StartFadeOutAnimation(base::Bind(
168 &DisplayOptionsHandler::FadeOutForMirroringFinished, 182 &DisplayOptionsHandler::FadeOutForMirroringFinished,
169 base::Unretained(this), 183 base::Unretained(this),
170 is_mirroring)); 184 is_mirroring));
171 } 185 }
172 186
173 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) { 187 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) {
174 double layout = -1; 188 double layout = -1;
175 double offset = -1; 189 double offset = -1;
176 if (!args->GetDouble(0, &layout) || !args->GetDouble(1, &offset)) { 190 if (!args->GetDouble(0, &layout) || !args->GetDouble(1, &offset)) {
177 LOG(ERROR) << "Invalid parameter"; 191 LOG(ERROR) << "Invalid parameter";
178 SendDisplayInfo(); 192 SendDisplayInfo();
179 return; 193 return;
180 } 194 }
181 DCHECK_LE(DisplayController::TOP, layout); 195 DCHECK_LE(DisplayLayout::TOP, layout);
182 DCHECK_GE(DisplayController::LEFT, layout); 196 DCHECK_GE(DisplayLayout::LEFT, layout);
183 ash::Shell::GetInstance()->output_configurator_animation()-> 197 ash::Shell::GetInstance()->output_configurator_animation()->
184 StartFadeOutAnimation(base::Bind( 198 StartFadeOutAnimation(base::Bind(
185 &DisplayOptionsHandler::FadeOutForDisplayLayoutFinished, 199 &DisplayOptionsHandler::FadeOutForDisplayLayoutFinished,
186 base::Unretained(this), 200 base::Unretained(this),
187 static_cast<int>(layout), 201 static_cast<int>(layout),
188 static_cast<int>(offset))); 202 static_cast<int>(offset)));
189 } 203 }
190 204
191 } // namespace options 205 } // namespace options
192 } // namespace chromeos 206 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698