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

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: fix 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
« no previous file with comments | « chrome/browser/chromeos/preferences.cc ('k') | chrome/chrome_browser_chromeos.gypi » ('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 "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;
33
34 DisplayOptionsHandler::DisplayOptionsHandler() { 32 DisplayOptionsHandler::DisplayOptionsHandler() {
35 aura::Env::GetInstance()->display_manager()->AddObserver(this); 33 aura::Env::GetInstance()->display_manager()->AddObserver(this);
36 } 34 }
37 35
38 DisplayOptionsHandler::~DisplayOptionsHandler() { 36 DisplayOptionsHandler::~DisplayOptionsHandler() {
39 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); 37 aura::Env::GetInstance()->display_manager()->RemoveObserver(this);
40 } 38 }
41 39
42 void DisplayOptionsHandler::GetLocalizedValues( 40 void DisplayOptionsHandler::GetLocalizedValues(
43 DictionaryValue* localized_strings) { 41 DictionaryValue* localized_strings) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 84
87 void DisplayOptionsHandler::OnDisplayRemoved(const gfx::Display& old_display) { 85 void DisplayOptionsHandler::OnDisplayRemoved(const gfx::Display& old_display) {
88 UpdateDisplaySectionVisibility(); 86 UpdateDisplaySectionVisibility();
89 SendDisplayInfo(); 87 SendDisplayInfo();
90 } 88 }
91 89
92 void DisplayOptionsHandler::UpdateDisplaySectionVisibility() { 90 void DisplayOptionsHandler::UpdateDisplaySectionVisibility() {
93 chromeos::OutputState output_state = 91 chromeos::OutputState output_state =
94 ash::Shell::GetInstance()->output_configurator()->output_state(); 92 ash::Shell::GetInstance()->output_configurator()->output_state();
95 base::FundamentalValue show_options( 93 base::FundamentalValue show_options(
96 DisplayController::IsExtendedDesktopEnabled() && 94 ash::DisplayController::IsExtendedDesktopEnabled() &&
97 output_state != chromeos::STATE_INVALID && 95 output_state != chromeos::STATE_INVALID &&
98 output_state != chromeos::STATE_HEADLESS && 96 output_state != chromeos::STATE_HEADLESS &&
99 output_state != chromeos::STATE_SINGLE); 97 output_state != chromeos::STATE_SINGLE);
100 web_ui()->CallJavascriptFunction( 98 web_ui()->CallJavascriptFunction(
101 "options.BrowserOptions.showDisplayOptions", show_options); 99 "options.BrowserOptions.showDisplayOptions", show_options);
102 } 100 }
103 101
104 void DisplayOptionsHandler::SendDisplayInfo() { 102 void DisplayOptionsHandler::SendDisplayInfo() {
105 aura::DisplayManager* display_manager = 103 aura::DisplayManager* display_manager =
106 aura::Env::GetInstance()->display_manager(); 104 aura::Env::GetInstance()->display_manager();
105 ash::DisplayController* display_controller =
106 ash::Shell::GetInstance()->display_controller();
107 chromeos::OutputConfigurator* output_configurator = 107 chromeos::OutputConfigurator* output_configurator =
108 ash::Shell::GetInstance()->output_configurator(); 108 ash::Shell::GetInstance()->output_configurator();
109 base::FundamentalValue mirroring( 109 base::FundamentalValue mirroring(
110 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR); 110 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR);
111 111
112 base::ListValue displays; 112 base::ListValue displays;
113 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { 113 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
114 const gfx::Display* display = display_manager->GetDisplayAt(i); 114 const gfx::Display* display = display_manager->GetDisplayAt(i);
115 const gfx::Rect& bounds = display->bounds(); 115 const gfx::Rect& bounds = display->bounds();
116 base::DictionaryValue* js_display = new base::DictionaryValue(); 116 base::DictionaryValue* js_display = new base::DictionaryValue();
117 js_display->SetDouble("id", display->id()); 117 js_display->SetDouble("id", display->id());
118 js_display->SetDouble("x", bounds.x()); 118 js_display->SetDouble("x", bounds.x());
119 js_display->SetDouble("y", bounds.y()); 119 js_display->SetDouble("y", bounds.y());
120 js_display->SetDouble("width", bounds.width()); 120 js_display->SetDouble("width", bounds.width());
121 js_display->SetDouble("height", bounds.height()); 121 js_display->SetDouble("height", bounds.height());
122 js_display->SetString("name", display_manager->GetDisplayNameAt(i)); 122 js_display->SetString("name", display_manager->GetDisplayNameAt(i));
123 displays.Set(i, js_display); 123 displays.Set(i, js_display);
124 } 124 }
125 125
126 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 126 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue());
127 base::FundamentalValue layout( 127 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue());
128 pref_service->GetInteger(prefs::kSecondaryDisplayLayout)); 128 if (display_manager->GetNumDisplays() > 1) {
129 base::FundamentalValue offset( 129 const std::string& secondary_display_name =
130 pref_service->GetInteger(prefs::kSecondaryDisplayOffset)); 130 display_manager->GetDisplayNameAt(1);
131 const ash::DisplayLayout& layout =
132 display_controller->GetLayoutForDisplayName(secondary_display_name);
133 layout_value.reset(new base::FundamentalValue(layout.position));
134 offset_value.reset(new base::FundamentalValue(layout.offset));
135 }
131 136
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);
Nikita (slow) 2012/08/30 14:18:52 layout_value.get() offset_value.get()
Jun Mukai 2012/08/31 09:19:05 Done.
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(ash::DisplayLayout::TOP, layout);
182 DCHECK_GE(DisplayController::LEFT, layout); 194 DCHECK_GE(ash::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
« no previous file with comments | « chrome/browser/chromeos/preferences.cc ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698