Commit 5dfcd854 authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

Adds an extension API of the event on changing volume.

- experimental.accessibility.onVolumeChange

I run chrome/common/extensions/docs/build/build.py, but no documents about a11y was changed. So this CL doesn't include any changes of documents.

BUG=chromium-os:16592
TEST=call the APIs manually on chromium-os

Review URL: http://codereview.chromium.org/7708025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98948 0039d316-1c4b-4281-b951-d872f2087c98
parent 9a67e2bb
...@@ -8,25 +8,34 @@ ...@@ -8,25 +8,34 @@
#include "chrome/browser/extensions/extension_accessibility_api_constants.h" #include "chrome/browser/extensions/extension_accessibility_api_constants.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/common/content_notification_types.h" #include "content/common/content_notification_types.h"
#include "content/common/notification_service.h" #include "content/common/notification_service.h"
namespace keys = extension_accessibility_api_constants; namespace keys = extension_accessibility_api_constants;
void SendAccessibilityNotification( void SendAccessibilityNotification(
int type, AccessibilityControlInfo* info) { int type, AccessibilityEventInfo* info) {
Profile *profile = info->profile(); Profile *profile = info->profile();
if (profile->ShouldSendAccessibilityEvents()) { if (profile->ShouldSendAccessibilityEvents()) {
NotificationService::current()->Notify( NotificationService::current()->Notify(
type, type,
Source<Profile>(profile), Source<Profile>(profile),
Details<AccessibilityControlInfo>(info)); Details<AccessibilityEventInfo>(info));
} }
} }
void SendAccessibilityVolumeNotification(double volume, bool is_muted) {
Profile* profile = ProfileManager::GetDefaultProfile();
AccessibilityVolumeInfo info(profile, volume, is_muted);
SendAccessibilityNotification(
chrome::NOTIFICATION_ACCESSIBILITY_VOLUME_CHANGED, &info);
}
AccessibilityControlInfo::AccessibilityControlInfo( AccessibilityControlInfo::AccessibilityControlInfo(
Profile* profile, const std::string& control_name) Profile* profile, const std::string& control_name)
: profile_(profile), name_(control_name) { : AccessibilityEventInfo(profile), name_(control_name) {
} }
AccessibilityControlInfo::~AccessibilityControlInfo() { AccessibilityControlInfo::~AccessibilityControlInfo() {
...@@ -188,6 +197,22 @@ void AccessibilityListBoxInfo::SerializeToDict(DictionaryValue *dict) const { ...@@ -188,6 +197,22 @@ void AccessibilityListBoxInfo::SerializeToDict(DictionaryValue *dict) const {
dict->SetInteger(keys::kItemCountKey, item_count_); dict->SetInteger(keys::kItemCountKey, item_count_);
} }
AccessibilityVolumeInfo::AccessibilityVolumeInfo(Profile* profile,
double volume,
bool is_muted)
: AccessibilityEventInfo(profile),
volume_(volume),
is_muted_(is_muted) {
DCHECK(profile);
DCHECK_GE(volume, 0.0);
DCHECK_LE(volume, 100.0);
}
void AccessibilityVolumeInfo::SerializeToDict(DictionaryValue *dict) const {
dict->SetDouble(keys::kVolumeKey, volume_);
dict->SetBoolean(keys::kIsVolumeMutedKey, is_muted_);
}
AccessibilityMenuInfo::AccessibilityMenuInfo(Profile* profile, AccessibilityMenuInfo::AccessibilityMenuInfo(Profile* profile,
const std::string& menu_name) const std::string& menu_name)
: AccessibilityControlInfo(profile, menu_name) { : AccessibilityControlInfo(profile, menu_name) {
......
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
#pragma once #pragma once
#include <string> #include <string>
#include "base/compiler_specific.h"
class AccessibilityControlInfo; class AccessibilityEventInfo;
class Profile; class Profile;
namespace base { namespace base {
...@@ -16,36 +17,51 @@ class DictionaryValue; ...@@ -16,36 +17,51 @@ class DictionaryValue;
} }
// Use the NotificationService to post the given accessibility // Use the NotificationService to post the given accessibility
// notification type with AccessibilityControlInfo details to any // notification type with AccessibilityEventInfo details to any
// listeners. Will not send if the profile's pause level is nonzero // listeners. Will not send if the profile's pause level is nonzero
// (using profile->PauseAccessibilityEvents). // (using profile->PauseAccessibilityEvents).
void SendAccessibilityNotification( void SendAccessibilityNotification(
int type, AccessibilityControlInfo* info); int type, AccessibilityEventInfo* info);
void SendAccessibilityVolumeNotification(double volume, bool is_muted);
// Abstract parent class for accessibility event information passed to event
// listeners.
class AccessibilityEventInfo {
public:
virtual ~AccessibilityEventInfo() {}
// Serialize this class as a DictionaryValue that can be converted to
// a JavaScript object.
virtual void SerializeToDict(base::DictionaryValue* dict) const = 0;
Profile* profile() const { return profile_; }
protected:
explicit AccessibilityEventInfo(Profile* profile) : profile_(profile) {}
// The profile this control belongs to.
Profile* profile_;
};
// Abstract parent class for accessibility information about a control // Abstract parent class for accessibility information about a control
// passed to event listeners. // passed to event listeners.
class AccessibilityControlInfo { class AccessibilityControlInfo : public AccessibilityEventInfo {
public: public:
virtual ~AccessibilityControlInfo(); virtual ~AccessibilityControlInfo();
// Serialize this class as a DictionaryValue that can be converted to // Serialize this class as a DictionaryValue that can be converted to
// a JavaScript object. // a JavaScript object.
virtual void SerializeToDict(base::DictionaryValue* dict) const; virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE;
// Return the specific type of this control, which will be one of the // Return the specific type of this control, which will be one of the
// string constants defined in extension_accessibility_api_constants.h. // string constants defined in extension_accessibility_api_constants.h.
virtual const char* type() const = 0; virtual const char* type() const = 0;
Profile* profile() const { return profile_; }
const std::string& name() const { return name_; } const std::string& name() const { return name_; }
protected: protected:
AccessibilityControlInfo(Profile* profile, const std::string& control_name); AccessibilityControlInfo(Profile* profile, const std::string& control_name);
// The profile this control belongs to.
Profile* profile_;
// The name of the control, like "OK" or "Password". // The name of the control, like "OK" or "Password".
std::string name_; std::string name_;
}; };
...@@ -255,6 +271,20 @@ class AccessibilityMenuInfo : public AccessibilityControlInfo { ...@@ -255,6 +271,20 @@ class AccessibilityMenuInfo : public AccessibilityControlInfo {
virtual const char* type() const; virtual const char* type() const;
}; };
// Accessibility information about a volume; this class is used by
// onVolumeUp, onVolumeDown, and onVolumeMute event listeners.
class AccessibilityVolumeInfo : public AccessibilityEventInfo {
public:
// |volume| must range between 0 to 100.
AccessibilityVolumeInfo(Profile* profile, double volume, bool is_muted);
virtual void SerializeToDict(base::DictionaryValue* dict) const;
private:
double volume_;
bool is_muted_;
};
// Accessibility information about a menu item; this class is used by // Accessibility information about a menu item; this class is used by
// onControlFocused event listeners. // onControlFocused event listeners.
class AccessibilityMenuItemInfo : public AccessibilityControlInfo { class AccessibilityMenuItemInfo : public AccessibilityControlInfo {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <X11/XF86keysym.h> #include <X11/XF86keysym.h>
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#include "chrome/browser/accessibility_events.h"
#include "chrome/browser/chromeos/audio_handler.h" #include "chrome/browser/chromeos/audio_handler.h"
#include "chrome/browser/chromeos/brightness_bubble.h" #include "chrome/browser/chromeos/brightness_bubble.h"
#include "chrome/browser/chromeos/input_method/xkeyboard.h" #include "chrome/browser/chromeos/input_method/xkeyboard.h"
...@@ -174,6 +175,11 @@ void SystemKeyEventListener::OnVolumeMute() { ...@@ -174,6 +175,11 @@ void SystemKeyEventListener::OnVolumeMute() {
// Always muting (and not toggling) as per final decision on // Always muting (and not toggling) as per final decision on
// http://crosbug.com/3751 // http://crosbug.com/3751
audio_handler_->SetMuted(true); audio_handler_->SetMuted(true);
SendAccessibilityVolumeNotification(
audio_handler_->GetVolumePercent(),
audio_handler_->IsMuted());
ShowVolumeBubble(); ShowVolumeBubble();
} }
...@@ -185,6 +191,11 @@ void SystemKeyEventListener::OnVolumeDown() { ...@@ -185,6 +191,11 @@ void SystemKeyEventListener::OnVolumeDown() {
audio_handler_->SetVolumePercent(0.0); audio_handler_->SetVolumePercent(0.0);
else else
audio_handler_->AdjustVolumeByPercent(-kStepPercentage); audio_handler_->AdjustVolumeByPercent(-kStepPercentage);
SendAccessibilityVolumeNotification(
audio_handler_->GetVolumePercent(),
audio_handler_->IsMuted());
ShowVolumeBubble(); ShowVolumeBubble();
} }
...@@ -199,6 +210,11 @@ void SystemKeyEventListener::OnVolumeUp() { ...@@ -199,6 +210,11 @@ void SystemKeyEventListener::OnVolumeUp() {
} else { } else {
audio_handler_->AdjustVolumeByPercent(kStepPercentage); audio_handler_->AdjustVolumeByPercent(kStepPercentage);
} }
SendAccessibilityVolumeNotification(
audio_handler_->GetVolumePercent(),
audio_handler_->IsMuted());
ShowVolumeBubble(); ShowVolumeBubble();
} }
......
...@@ -25,7 +25,7 @@ namespace keys = extension_accessibility_api_constants; ...@@ -25,7 +25,7 @@ namespace keys = extension_accessibility_api_constants;
// Returns the AccessibilityControlInfo serialized into a JSON string, // Returns the AccessibilityControlInfo serialized into a JSON string,
// consisting of an array of a single object of type AccessibilityObject, // consisting of an array of a single object of type AccessibilityObject,
// as defined in the accessibility extension api's json schema. // as defined in the accessibility extension api's json schema.
std::string ControlInfoToJsonString(const AccessibilityControlInfo* info) { std::string ControlInfoToJsonString(const AccessibilityEventInfo* info) {
ListValue args; ListValue args;
DictionaryValue* dict = new DictionaryValue(); DictionaryValue* dict = new DictionaryValue();
info->SerializeToDict(dict); info->SerializeToDict(dict);
...@@ -73,6 +73,9 @@ void ExtensionAccessibilityEventRouter::ObserveProfile(Profile* profile) { ...@@ -73,6 +73,9 @@ void ExtensionAccessibilityEventRouter::ObserveProfile(Profile* profile) {
registrar_.Add(this, registrar_.Add(this,
chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED, chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED,
NotificationService::AllSources()); NotificationService::AllSources());
registrar_.Add(this,
chrome::NOTIFICATION_ACCESSIBILITY_VOLUME_CHANGED,
NotificationService::AllSources());
} }
} }
...@@ -102,6 +105,9 @@ void ExtensionAccessibilityEventRouter::Observe( ...@@ -102,6 +105,9 @@ void ExtensionAccessibilityEventRouter::Observe(
case chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED: case chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED:
OnMenuClosed(Details<const AccessibilityMenuInfo>(details).ptr()); OnMenuClosed(Details<const AccessibilityMenuInfo>(details).ptr());
break; break;
case chrome::NOTIFICATION_ACCESSIBILITY_VOLUME_CHANGED:
OnVolumeChanged(Details<const AccessibilityVolumeInfo>(details).ptr());
break;
default: default:
NOTREACHED(); NOTREACHED();
} }
...@@ -180,6 +186,12 @@ void ExtensionAccessibilityEventRouter::OnMenuClosed( ...@@ -180,6 +186,12 @@ void ExtensionAccessibilityEventRouter::OnMenuClosed(
DispatchEvent(info->profile(), keys::kOnMenuClosed, json_args); DispatchEvent(info->profile(), keys::kOnMenuClosed, json_args);
} }
void ExtensionAccessibilityEventRouter::OnVolumeChanged(
const AccessibilityVolumeInfo* info) {
std::string json_args = ControlInfoToJsonString(info);
DispatchEvent(info->profile(), keys::kOnVolumeChanged, json_args);
}
void ExtensionAccessibilityEventRouter::DispatchEvent( void ExtensionAccessibilityEventRouter::DispatchEvent(
Profile* profile, Profile* profile,
const char* event_name, const char* event_name,
......
...@@ -62,6 +62,7 @@ class ExtensionAccessibilityEventRouter : public NotificationObserver { ...@@ -62,6 +62,7 @@ class ExtensionAccessibilityEventRouter : public NotificationObserver {
void OnTextChanged(const AccessibilityControlInfo* details); void OnTextChanged(const AccessibilityControlInfo* details);
void OnMenuOpened(const AccessibilityMenuInfo* details); void OnMenuOpened(const AccessibilityMenuInfo* details);
void OnMenuClosed(const AccessibilityMenuInfo* details); void OnMenuClosed(const AccessibilityMenuInfo* details);
void OnVolumeChanged(const AccessibilityVolumeInfo* details);
void DispatchEvent(Profile* profile, void DispatchEvent(Profile* profile,
const char* event_name, const char* event_name,
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -18,6 +18,8 @@ const char kSelectionStartKey[] = "details.selectionStart"; ...@@ -18,6 +18,8 @@ const char kSelectionStartKey[] = "details.selectionStart";
const char kSelectionEndKey[] = "details.selectionEnd"; const char kSelectionEndKey[] = "details.selectionEnd";
const char kCheckedKey[] = "details.isChecked"; const char kCheckedKey[] = "details.isChecked";
const char kHasSubmenuKey[] = "details.hasSubmenu"; const char kHasSubmenuKey[] = "details.hasSubmenu";
const char kVolumeKey[] = "volume";
const char kIsVolumeMutedKey[] = "isVolumeMuted";
// Events. // Events.
const char kOnWindowOpened[] = "experimental.accessibility.onWindowOpened"; const char kOnWindowOpened[] = "experimental.accessibility.onWindowOpened";
...@@ -27,6 +29,7 @@ const char kOnControlAction[] = "experimental.accessibility.onControlAction"; ...@@ -27,6 +29,7 @@ const char kOnControlAction[] = "experimental.accessibility.onControlAction";
const char kOnTextChanged[] = "experimental.accessibility.onTextChanged"; const char kOnTextChanged[] = "experimental.accessibility.onTextChanged";
const char kOnMenuOpened[] = "experimental.accessibility.onMenuOpened"; const char kOnMenuOpened[] = "experimental.accessibility.onMenuOpened";
const char kOnMenuClosed[] = "experimental.accessibility.onMenuClosed"; const char kOnMenuClosed[] = "experimental.accessibility.onMenuClosed";
const char kOnVolumeChanged[] = "experimental.accessibility.onVolumeChanged";
// Types of controls that can receive accessibility events. // Types of controls that can receive accessibility events.
const char kTypeButton[] = "button"; const char kTypeButton[] = "button";
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -22,6 +22,8 @@ extern const char kSelectionStartKey[]; ...@@ -22,6 +22,8 @@ extern const char kSelectionStartKey[];
extern const char kSelectionEndKey[]; extern const char kSelectionEndKey[];
extern const char kCheckedKey[]; extern const char kCheckedKey[];
extern const char kHasSubmenuKey[]; extern const char kHasSubmenuKey[];
extern const char kVolumeKey[];
extern const char kIsVolumeMutedKey[];
// Events. // Events.
extern const char kOnWindowOpened[]; extern const char kOnWindowOpened[];
...@@ -31,6 +33,7 @@ extern const char kOnControlAction[]; ...@@ -31,6 +33,7 @@ extern const char kOnControlAction[];
extern const char kOnTextChanged[]; extern const char kOnTextChanged[];
extern const char kOnMenuOpened[]; extern const char kOnMenuOpened[];
extern const char kOnMenuClosed[]; extern const char kOnMenuClosed[];
extern const char kOnVolumeChanged[];
// Types of controls that can receive accessibility events // Types of controls that can receive accessibility events
extern const char kTypeButton[]; extern const char kTypeButton[];
...@@ -43,6 +46,7 @@ extern const char kTypeMenuItem[]; ...@@ -43,6 +46,7 @@ extern const char kTypeMenuItem[];
extern const char kTypeRadioButton[]; extern const char kTypeRadioButton[];
extern const char kTypeTab[]; extern const char kTypeTab[];
extern const char kTypeTextBox[]; extern const char kTypeTextBox[];
extern const char kTypeVolume[];
extern const char kTypeWindow[]; extern const char kTypeWindow[];
}; // namespace extension_accessibility_api_constants }; // namespace extension_accessibility_api_constants
......
...@@ -626,6 +626,11 @@ enum { ...@@ -626,6 +626,11 @@ enum {
// Details will be an AccessibilityMenuInfo. // Details will be an AccessibilityMenuInfo.
NOTIFICATION_ACCESSIBILITY_MENU_CLOSED, NOTIFICATION_ACCESSIBILITY_MENU_CLOSED,
// Notification that the volume was changed, for propagating
// to an accessibility extension.
// Details will be an AccessibilityVolumeInfo.
NOTIFICATION_ACCESSIBILITY_VOLUME_CHANGED,
// Content Settings -------------------------------------------------------- // Content Settings --------------------------------------------------------
// Sent when content settings change. The source is a HostContentSettings // Sent when content settings change. The source is a HostContentSettings
......
...@@ -382,6 +382,15 @@ ...@@ -382,6 +382,15 @@
"selectionStart": {"type": "integer", "description": "The index of the character where the selection starts, if this control contains editable text."}, "selectionStart": {"type": "integer", "description": "The index of the character where the selection starts, if this control contains editable text."},
"selectionEnd": {"type": "integer", "description": "The index of the character where the selection ends, if this control contains editable text."} "selectionEnd": {"type": "integer", "description": "The index of the character where the selection ends, if this control contains editable text."}
} }
},
{
"id": "AccessibilityVolumeInfo",
"type": "object",
"description": "Information about the volume.",
"properties": {
"volume": {"type": "double", "description": "The value of the volume percent. This must be between 0.0 and 100.0."},
"isVolumeMuted": {"type": "boolean", "description": "True if the volume is muted."}
}
} }
], ],
"functions": [ "functions": [
...@@ -503,6 +512,18 @@ ...@@ -503,6 +512,18 @@
"description": "Information about the menu that was closed." "description": "Information about the menu that was closed."
} }
] ]
},
{
"name": "onVolumeChanged",
"type": "function",
"description": "Fired when the volume is changed.",
"parameters": [
{
"$ref": "AccessibilityVolumeInfo",
"name": "volume",
"description": "Information about the current state of the system volume control, including whether it is muted."
}
]
} }
] ]
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment