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