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

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

Issue 10544171: Add OptionsUI and its handler for multiple displays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 8 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/options2/chromeos/display_options_handler.h"
6
7 #include <string>
8
9 #include "ash/monitor/monitor_controller.h"
10 #include "ash/shell.h"
11 #include "base/logging.h"
12 #include "base/json/json_value_converter.h"
13 #include "base/values.h"
14 #include "chromeos/monitor/output_configurator.h"
15 #include "content/public/browser/web_ui.h"
16 #include "grit/generated_resources.h"
17 #include "ui/aura/env.h"
18 #include "ui/aura/monitor_manager.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/gfx/display.h"
21 #include "ui/gfx/rect.h"
22
23 namespace chromeos {
24 namespace options2 {
25
26 using ash::internal::MonitorController;
27
28 DisplayOptionsHandler::DisplayOptionsHandler() {
29 aura::Env::GetInstance()->monitor_manager()->AddObserver(this);
30 }
31
32 DisplayOptionsHandler::~DisplayOptionsHandler() {
33 aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this);
34 }
35
36 void DisplayOptionsHandler::GetLocalizedValues(
37 DictionaryValue* localized_strings) {
38 DCHECK(localized_strings);
39 RegisterTitle(localized_strings, "displayOptionsPage",
40 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_TAB_TITLE);
41 localized_strings->SetString("startMirroring", l10n_util::GetStringUTF16(
42 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_START_MIRRORING));
43 localized_strings->SetString("stopMirroring", l10n_util::GetStringUTF16(
44 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_STOP_MIRRORING));
45 }
46
47 void DisplayOptionsHandler::InitializeHandler() {
48 DCHECK(web_ui());
49 UpdateDisplaySectionVisibility();
50 }
51
52 void DisplayOptionsHandler::RegisterMessages() {
53 web_ui()->RegisterMessageCallback(
54 "getDisplayInfo",
55 base::Bind(&DisplayOptionsHandler::HandleDisplayInfo,
56 base::Unretained(this)));
57 web_ui()->RegisterMessageCallback(
58 "setMirroring",
59 base::Bind(&DisplayOptionsHandler::HandleMirroring,
60 base::Unretained(this)));
61 web_ui()->RegisterMessageCallback(
62 "setDisplayLayout",
63 base::Bind(&DisplayOptionsHandler::HandleDisplayLayout,
64 base::Unretained(this)));
65 }
66
67 void DisplayOptionsHandler::OnDisplayBoundsChanged(
68 const gfx::Display& display) {
69 SendDisplayInfo();
70 }
71
72 void DisplayOptionsHandler::OnDisplayAdded(const gfx::Display& new_display) {
73 UpdateDisplaySectionVisibility();
74 SendDisplayInfo();
75 }
76
77 void DisplayOptionsHandler::OnDisplayRemoved(const gfx::Display& old_display) {
78 UpdateDisplaySectionVisibility();
79 SendDisplayInfo();
80 }
81
82 void DisplayOptionsHandler::UpdateDisplaySectionVisibility() {
83 aura::MonitorManager* monitor_manager =
84 aura::Env::GetInstance()->monitor_manager();
85 chromeos::State output_state =
86 ash::Shell::GetInstance()->output_configurator()->output_state();
87 base::FundamentalValue show_options(
88 MonitorController::IsExtendedDesktopEnabled() &&
89 monitor_manager->GetNumDisplays() > 1 &&
90 output_state != chromeos::STATE_INVALID &&
91 output_state != chromeos::STATE_HEADLESS &&
92 output_state != chromeos::STATE_SINGLE);
93 web_ui()->CallJavascriptFunction(
94 "options.BrowserOptions.showDisplayOptions", show_options);
95 }
96
97 void DisplayOptionsHandler::SendDisplayInfo() {
98 aura::MonitorManager* monitor_manager =
99 aura::Env::GetInstance()->monitor_manager();
100 chromeos::OutputConfigurator* output_configurator =
101 ash::Shell::GetInstance()->output_configurator();
102 base::FundamentalValue mirroring(
103 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR);
104
105 base::ListValue displays;
106 for (size_t i = 0; i < monitor_manager->GetNumDisplays(); ++i) {
107 const gfx::Display& display = monitor_manager->GetDisplayAt(i);
108 const gfx::Rect& bounds = display.bounds();
109 base::DictionaryValue* js_display = new base::DictionaryValue();
110 js_display->SetDouble("id", display.id());
111 js_display->SetDouble("x", bounds.x());
112 js_display->SetDouble("y", bounds.y());
113 js_display->SetDouble("width", bounds.width());
114 js_display->SetDouble("height", bounds.height());
115 displays.Set(i, js_display);
116 }
117
118 MonitorController* monitor_controller =
119 ash::Shell::GetInstance()->monitor_controller();
120 base::FundamentalValue layout(static_cast<int>(
121 monitor_controller->secondary_display_layout()));
122
123 web_ui()->CallJavascriptFunction(
124 "options.DisplayOptions.setDisplayInfo",
125 mirroring, displays, layout);
126 }
127
128 void DisplayOptionsHandler::HandleDisplayInfo(
129 const base::ListValue* unused_args) {
130 SendDisplayInfo();
131 }
132
133 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) {
134 DCHECK(!args->empty());
135 bool is_mirroring = false;
136 args->GetBoolean(0, &is_mirroring);
137 // We use 'PRIMARY_ONLY' for non-mirroring state for now.
138 // TODO(mukai): fix this and support multiple display modes.
139 chromeos::State new_state =
140 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_PRIMARY_ONLY;
141 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state);
142 SendDisplayInfo();
143 }
144
145 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) {
146 double layout = -1;
147 if (!args->GetDouble(0, &layout)) {
148 LOG(ERROR) << "Invalid parameter";
149 return;
150 }
151 DCHECK_LE(MonitorController::TOP, layout);
152 DCHECK_GE(MonitorController::LEFT, layout);
153
154 ash::Shell::GetInstance()->monitor_controller()->SetSecondaryDisplayLayout(
155 static_cast<MonitorController::SecondaryDisplayLayout>(layout));
156 SendDisplayInfo();
157 }
158
159 } // namespace options2
160 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options2/chromeos/display_options_handler.h ('k') | chrome/browser/ui/webui/options2/options_ui2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698