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/options/chromeos/pointer_handler.h" 6 7#include "base/basictypes.h" 8#include "base/strings/utf_string_conversions.h" 9#include "base/values.h" 10#include "chrome/common/url_constants.h" 11#include "content/public/browser/web_ui.h" 12#include "grit/generated_resources.h" 13#include "ui/base/l10n/l10n_util.h" 14 15namespace chromeos { 16namespace options { 17 18PointerHandler::PointerHandler() 19 : has_touchpad_(false), 20 has_mouse_(false) { 21} 22 23PointerHandler::~PointerHandler() { 24} 25 26void PointerHandler::GetLocalizedValues(DictionaryValue* localized_strings) { 27 DCHECK(localized_strings); 28 29 static OptionsStringResource resources[] = { 30 { "pointerOverlayTitleTouchpadOnly", 31 IDS_OPTIONS_POINTER_TOUCHPAD_OVERLAY_TITLE }, 32 { "pointerOverlayTitleMouseOnly", 33 IDS_OPTIONS_POINTER_MOUSE_OVERLAY_TITLE }, 34 { "pointerOverlayTitleTouchpadMouse", 35 IDS_OPTIONS_POINTER_TOUCHPAD_MOUSE_OVERLAY_TITLE }, 36 { "pointerOverlaySectionTitleTouchpad", 37 IDS_OPTIONS_POINTER_OVERLAY_SECTION_TITLE_TOUCHPAD }, 38 { "pointerOverlaySectionTitleMouse", 39 IDS_OPTIONS_POINTER_OVERLAY_SECTION_TITLE_MOUSE }, 40 { "enableTapToClick", 41 IDS_OPTIONS_SETTINGS_TAP_TO_CLICK_ENABLED_DESCRIPTION }, 42 { "primaryMouseRight", 43 IDS_OPTIONS_SETTINGS_PRIMARY_MOUSE_RIGHT_DESCRIPTION }, 44 { "traditionalScroll", 45 IDS_OPTIONS_SETTINGS_TRADITIONAL_SCROLL_DESCRIPTION }, 46 }; 47 48 localized_strings->SetString("naturalScroll", 49 l10n_util::GetStringFUTF16( 50 IDS_OPTIONS_SETTINGS_NATURAL_SCROLL_DESCRIPTION, 51 ASCIIToUTF16(chrome::kNaturalScrollHelpURL))); 52 53 RegisterStrings(localized_strings, resources, arraysize(resources)); 54} 55 56 57void PointerHandler::TouchpadExists(bool exists) { 58 has_touchpad_ = exists; 59 base::FundamentalValue val(exists); 60 web_ui()->CallJavascriptFunction("PointerOverlay.showTouchpadControls", val); 61 UpdateTitle(); 62} 63 64void PointerHandler::MouseExists(bool exists) { 65 has_mouse_ = exists; 66 base::FundamentalValue val(exists); 67 web_ui()->CallJavascriptFunction("PointerOverlay.showMouseControls", val); 68 UpdateTitle(); 69} 70 71void PointerHandler::UpdateTitle() { 72 std::string label; 73 if (has_touchpad_) { 74 label = has_mouse_ ? "pointerOverlayTitleTouchpadMouse" : 75 "pointerOverlayTitleTouchpadOnly"; 76 } else { 77 label = has_mouse_ ? "pointerOverlayTitleMouseOnly" : ""; 78 } 79 base::StringValue val(label); 80 web_ui()->CallJavascriptFunction("PointerOverlay.setTitle", val); 81} 82 83} // namespace options 84} // namespace chromeos 85