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

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: 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_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 =
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;
115 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue());
116 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue());
113 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { 117 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
114 const gfx::Display* display = display_manager->GetDisplayAt(i); 118 const gfx::Display* display = display_manager->GetDisplayAt(i);
115 const gfx::Rect& bounds = display->bounds(); 119 const gfx::Rect& bounds = display->bounds();
120 const std::string& display_name = display_manager->GetDisplayNameAt(i);
116 base::DictionaryValue* js_display = new base::DictionaryValue(); 121 base::DictionaryValue* js_display = new base::DictionaryValue();
117 js_display->SetDouble("id", display->id()); 122 js_display->SetDouble("id", display->id());
118 js_display->SetDouble("x", bounds.x()); 123 js_display->SetDouble("x", bounds.x());
119 js_display->SetDouble("y", bounds.y()); 124 js_display->SetDouble("y", bounds.y());
120 js_display->SetDouble("width", bounds.width()); 125 js_display->SetDouble("width", bounds.width());
121 js_display->SetDouble("height", bounds.height()); 126 js_display->SetDouble("height", bounds.height());
122 js_display->SetString("name", display_manager->GetDisplayNameAt(i)); 127 js_display->SetString("name", display_name);
123 displays.Set(i, js_display); 128 displays.Set(i, js_display);
129 if (i > 0) {
oshima 2012/08/29 00:10:44 I assume we're dropping 0 because 0 is primary and
Jun Mukai 2012/08/29 02:15:03 Hmm, I'm afraid no. the layout and offset are spe
130 const DisplayLayout& layout =
131 display_controller->GetLayoutForDisplayName(display_name);
132 layout_value.reset(new base::FundamentalValue(layout.position));
133 offset_value.reset(new base::FundamentalValue(layout.offset));
134 }
124 } 135 }
125 136
126 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
127 base::FundamentalValue layout(
128 pref_service->GetInteger(prefs::kSecondaryDisplayLayout));
129 base::FundamentalValue offset(
130 pref_service->GetInteger(prefs::kSecondaryDisplayOffset));
131
132 web_ui()->CallJavascriptFunction( 137 web_ui()->CallJavascriptFunction(
133 "options.DisplayOptions.setDisplayInfo", 138 "options.DisplayOptions.setDisplayInfo",
134 mirroring, displays, layout, offset); 139 mirroring, displays, *layout_value, *offset_value);
135 } 140 }
136 141
137 void DisplayOptionsHandler::FadeOutForMirroringFinished(bool is_mirroring) { 142 void DisplayOptionsHandler::FadeOutForMirroringFinished(bool is_mirroring) {
138 // We use 'PRIMARY_ONLY' for non-mirroring state for now. 143 // We use 'PRIMARY_ONLY' for non-mirroring state for now.
139 // TODO(mukai): fix this and support multiple display modes. 144 // TODO(mukai): fix this and support multiple display modes.
140 chromeos::OutputState new_state = 145 chromeos::OutputState new_state =
141 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_PRIMARY_ONLY; 146 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_PRIMARY_ONLY;
142 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state); 147 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state);
143 SendDisplayInfo(); 148 SendDisplayInfo();
144 // Not necessary to start fade-in animation. OutputConfigurator will do that. 149 // Not necessary to start fade-in animation. OutputConfigurator will do that.
145 } 150 }
146 151
147 void DisplayOptionsHandler::FadeOutForDisplayLayoutFinished( 152 void DisplayOptionsHandler::FadeOutForDisplayLayoutFinished(
148 int layout, int offset) { 153 int layout, int offset) {
149 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 154 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
150 pref_service->SetInteger(prefs::kSecondaryDisplayLayout, layout); 155 aura::DisplayManager* display_manager =
151 pref_service->SetInteger(prefs::kSecondaryDisplayOffset, offset); 156 aura::Env::GetInstance()->display_manager();
157 // Assumes that there are two displays at most and the second item is the
158 // secondary display.
159 if (display_manager->GetNumDisplays() > 1) {
160 gfx::Display* display = display_manager->GetDisplayAt(1);
161 SetDisplayLayoutPref(pref_service, *display, layout, offset);
162 }
163
152 SendDisplayInfo(); 164 SendDisplayInfo();
153 ash::Shell::GetInstance()->output_configurator_animation()-> 165 ash::Shell::GetInstance()->output_configurator_animation()->
154 StartFadeInAnimation(); 166 StartFadeInAnimation();
155 } 167 }
156 168
157 void DisplayOptionsHandler::HandleDisplayInfo( 169 void DisplayOptionsHandler::HandleDisplayInfo(
158 const base::ListValue* unused_args) { 170 const base::ListValue* unused_args) {
159 SendDisplayInfo(); 171 SendDisplayInfo();
160 } 172 }
161 173
162 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) { 174 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) {
163 DCHECK(!args->empty()); 175 DCHECK(!args->empty());
164 bool is_mirroring = false; 176 bool is_mirroring = false;
165 args->GetBoolean(0, &is_mirroring); 177 args->GetBoolean(0, &is_mirroring);
166 ash::Shell::GetInstance()->output_configurator_animation()-> 178 ash::Shell::GetInstance()->output_configurator_animation()->
167 StartFadeOutAnimation(base::Bind( 179 StartFadeOutAnimation(base::Bind(
168 &DisplayOptionsHandler::FadeOutForMirroringFinished, 180 &DisplayOptionsHandler::FadeOutForMirroringFinished,
169 base::Unretained(this), 181 base::Unretained(this),
170 is_mirroring)); 182 is_mirroring));
171 } 183 }
172 184
173 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) { 185 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) {
174 double layout = -1; 186 double layout = -1;
175 double offset = -1; 187 double offset = -1;
176 if (!args->GetDouble(0, &layout) || !args->GetDouble(1, &offset)) { 188 if (!args->GetDouble(0, &layout) || !args->GetDouble(1, &offset)) {
177 LOG(ERROR) << "Invalid parameter"; 189 LOG(ERROR) << "Invalid parameter";
178 SendDisplayInfo(); 190 SendDisplayInfo();
179 return; 191 return;
180 } 192 }
181 DCHECK_LE(DisplayController::TOP, layout); 193 DCHECK_LE(DisplayLayout::TOP, layout);
182 DCHECK_GE(DisplayController::LEFT, layout); 194 DCHECK_GE(DisplayLayout::LEFT, layout);
183 ash::Shell::GetInstance()->output_configurator_animation()-> 195 ash::Shell::GetInstance()->output_configurator_animation()->
184 StartFadeOutAnimation(base::Bind( 196 StartFadeOutAnimation(base::Bind(
185 &DisplayOptionsHandler::FadeOutForDisplayLayoutFinished, 197 &DisplayOptionsHandler::FadeOutForDisplayLayoutFinished,
186 base::Unretained(this), 198 base::Unretained(this),
187 static_cast<int>(layout), 199 static_cast<int>(layout),
188 static_cast<int>(offset))); 200 static_cast<int>(offset)));
189 } 201 }
190 202
191 } // namespace options 203 } // namespace options
192 } // namespace chromeos 204 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698