Skip to content

Commit

Permalink
Added side slide gestures to touch exploration controller.
Browse files Browse the repository at this point in the history
The user can control settings that might be normally changed using sliders by sliding along the edge of the screen when ChromeVox is on. For example, the user can slide along the right edge of the screen and adjust the volume.

If the user enters this mode and leaves the boundaries without releasing their touch, they will stop adjusting the setting, however, they will not enter touch exploration. If they return to the given boundaries, they will be able to modify the setting again. If the user does not touch a "hot edge" of the screen, they will not enter this state if they move to the an of the screen. 

BUG=393326

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=284819

Review URL: https://codereview.chromium.org/385073009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285149 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
lisayin@chromium.org committed Jul 24, 2014
1 parent 518c63a commit 7d48759
Show file tree
Hide file tree
Showing 12 changed files with 703 additions and 75 deletions.
3 changes: 3 additions & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
'ash_constants.h',
'ash_switches.cc',
'ash_switches.h',
'ash_touch_exploration_manager_chromeos.cc',
'ash_touch_exploration_manager_chromeos.h',
'cancel_mode.cc',
'cancel_mode.h',
'debug.cc',
Expand Down Expand Up @@ -753,6 +755,7 @@
'accelerators/accelerator_table_unittest.cc',
'accelerators/magnifier_key_scroller_unittest.cc',
'accelerators/spoken_feedback_toggler_unittest.cc',
'ash_touch_exploration_manager_chromeos_unittest.cc',
'autoclick/autoclick_unittest.cc',
'desktop_background/desktop_background_controller_unittest.cc',
'desktop_background/wallpaper_resizer_unittest.cc',
Expand Down
78 changes: 78 additions & 0 deletions ash/ash_touch_exploration_manager_chromeos.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/ash_touch_exploration_manager_chromeos.h"

#include "ash/accessibility_delegate.h"
#include "ash/audio/sounds.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "base/command_line.h"
#include "chromeos/audio/chromeos_sounds.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/chromeos_switches.h"
#include "ui/chromeos/touch_exploration_controller.h"

namespace ash {

AshTouchExplorationManager::AshTouchExplorationManager(
RootWindowController* root_window_controller)
: root_window_controller_(root_window_controller),
audio_handler_(chromeos::CrasAudioHandler::Get()) {
Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this);
UpdateTouchExplorationState();
}

AshTouchExplorationManager::~AshTouchExplorationManager() {
SystemTrayNotifier* system_tray_notifier =
Shell::GetInstance()->system_tray_notifier();
if (system_tray_notifier)
system_tray_notifier->RemoveAccessibilityObserver(this);
}

void AshTouchExplorationManager::OnAccessibilityModeChanged(
AccessibilityNotificationVisibility notify) {
UpdateTouchExplorationState();
}

void AshTouchExplorationManager::PlayVolumeAdjustSound() {
if (!VolumeAdjustSoundEnabled())
return;
if ((!audio_handler_->IsOutputMuted()) ||
!(audio_handler_->GetOutputVolumePercent() == 100))
PlaySystemSoundIfSpokenFeedback(chromeos::SOUND_VOLUME_ADJUST);
}

void AshTouchExplorationManager::SetOutputLevel(int volume) {
if (volume > 0) {
if (audio_handler_->IsOutputMuted()) {
audio_handler_->SetOutputMute(false);
}
}
audio_handler_->SetOutputVolumePercent(volume);
// Avoid negative volume.
if (audio_handler_->IsOutputVolumeBelowDefaultMuteLevel())
audio_handler_->SetOutputMute(true);
}

void AshTouchExplorationManager::UpdateTouchExplorationState() {
AccessibilityDelegate* delegate =
Shell::GetInstance()->accessibility_delegate();
bool enabled = delegate->IsSpokenFeedbackEnabled();

if (enabled && !touch_exploration_controller_.get()) {
touch_exploration_controller_.reset(new ui::TouchExplorationController(
root_window_controller_->GetRootWindow(), this));
} else if (!enabled) {
touch_exploration_controller_.reset();
}
}

bool AshTouchExplorationManager::VolumeAdjustSoundEnabled() {
return !CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kDisableVolumeAdjustSound);
}

} // namespace ash
52 changes: 52 additions & 0 deletions ash/ash_touch_exploration_manager_chromeos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_TOUCH_EXPLORATION_MANAGER_CHROMEOS_H_
#define ASH_TOUCH_EXPLORATION_MANAGER_CHROMEOS_H_

#include "ash/ash_export.h"
#include "ash/system/tray_accessibility.h"
#include "ui/chromeos/touch_exploration_controller.h"

namespace chromeos {
class CrasAudioHandler;
}

namespace ash {
class RootWindowController;

// Responsible for initializing TouchExplorationController when spoken
// feedback is on for ChromeOS only. This class implements
// TouchExplorationControllerDelegate which allows touch gestures to manipulate
// the system.
class ASH_EXPORT AshTouchExplorationManager
: public ash::AccessibilityObserver,
public ui::TouchExplorationControllerDelegate {
public:
explicit AshTouchExplorationManager(
RootWindowController* root_window_controller);
virtual ~AshTouchExplorationManager();

// AccessibilityObserver overrides:
virtual void OnAccessibilityModeChanged(
AccessibilityNotificationVisibility notify) OVERRIDE;

// TouchExplorationControllerDelegate overrides:
virtual void PlayVolumeAdjustSound() OVERRIDE;
virtual void SetOutputLevel(int volume) OVERRIDE;

private:
void UpdateTouchExplorationState();
bool VolumeAdjustSoundEnabled();

scoped_ptr<ui::TouchExplorationController> touch_exploration_controller_;
RootWindowController* root_window_controller_;
chromeos::CrasAudioHandler* audio_handler_;

DISALLOW_COPY_AND_ASSIGN(AshTouchExplorationManager);
};

} // namespace ash

#endif // ASH_TOUCH_EXPLORATION_MANAGER_CHROMEOS_H_
39 changes: 39 additions & 0 deletions ash/ash_touch_exploration_manager_chromeos_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/ash_touch_exploration_manager_chromeos.h"

#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "chromeos/audio/cras_audio_handler.h"

namespace ash {

typedef test::AshTestBase AshTouchExplorationManagerTest;

TEST_F(AshTouchExplorationManagerTest, AdjustSound) {
RootWindowController* controller = Shell::GetPrimaryRootWindowController();
AshTouchExplorationManager touch_exploration_manager(controller);
chromeos::CrasAudioHandler* audio_handler =
chromeos::CrasAudioHandler::Get();

touch_exploration_manager.SetOutputLevel(10);
EXPECT_EQ(audio_handler->GetOutputVolumePercent(), 10);
EXPECT_FALSE(audio_handler->IsOutputMuted());

touch_exploration_manager.SetOutputLevel(100);
EXPECT_EQ(audio_handler->GetOutputVolumePercent(), 100);
EXPECT_FALSE(audio_handler->IsOutputMuted());

touch_exploration_manager.SetOutputLevel(0);
EXPECT_EQ(audio_handler->GetOutputVolumePercent(), 0);
EXPECT_TRUE(audio_handler->IsOutputMuted());

touch_exploration_manager.SetOutputLevel(-10);
EXPECT_EQ(audio_handler->GetOutputVolumePercent(), 0);
EXPECT_TRUE(audio_handler->IsOutputMuted());
}

} // namespace ash
56 changes: 4 additions & 52 deletions ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#include "ui/wm/public/window_types.h"

#if defined(OS_CHROMEOS)
#include "ash/system/tray_accessibility.h"
#include "ash/ash_touch_exploration_manager_chromeos.h"
#include "ash/wm/boot_splash_screen_chromeos.h"
#include "ui/chromeos/touch_exploration_controller.h"
#endif
Expand Down Expand Up @@ -261,54 +261,6 @@ class EmptyWindowDelegate : public aura::WindowDelegate {
DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate);
};

#if defined(OS_CHROMEOS)
// Responsible for initializing TouchExplorationController when spoken
// feedback is on.
class CrosAccessibilityObserver : public AccessibilityObserver {
public:
explicit CrosAccessibilityObserver(
RootWindowController* root_window_controller)
: root_window_controller_(root_window_controller) {
Shell::GetInstance()->system_tray_notifier()->
AddAccessibilityObserver(this);
UpdateTouchExplorationState();
}

virtual ~CrosAccessibilityObserver() {
SystemTrayNotifier* system_tray_notifier =
Shell::GetInstance()->system_tray_notifier();
if (system_tray_notifier)
system_tray_notifier->RemoveAccessibilityObserver(this);
}

private:
void UpdateTouchExplorationState() {
AccessibilityDelegate* delegate =
Shell::GetInstance()->accessibility_delegate();
bool enabled = delegate->IsSpokenFeedbackEnabled();

if (enabled && !touch_exploration_controller_.get()) {
touch_exploration_controller_.reset(
new ui::TouchExplorationController(
root_window_controller_->GetRootWindow()));
} else if (!enabled) {
touch_exploration_controller_.reset();
}
}

// Overridden from AccessibilityObserver.
virtual void OnAccessibilityModeChanged(
AccessibilityNotificationVisibility notify) OVERRIDE {
UpdateTouchExplorationState();
}

scoped_ptr<ui::TouchExplorationController> touch_exploration_controller_;
RootWindowController* root_window_controller_;

DISALLOW_COPY_AND_ASSIGN(CrosAccessibilityObserver);
};
#endif // OS_CHROMEOS

} // namespace

void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) {
Expand Down Expand Up @@ -396,8 +348,8 @@ void RootWindowController::Shutdown() {
shell->RemoveShellObserver(this);

#if defined(OS_CHROMEOS)
if (cros_accessibility_observer_) {
cros_accessibility_observer_.reset();
if (touch_exploration_manager_) {
touch_exploration_manager_.reset();
}
#endif

Expand Down Expand Up @@ -807,7 +759,7 @@ void RootWindowController::Init(RootWindowType root_window_type,
#if defined(OS_CHROMEOS)
if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshDisableTouchExplorationMode)) {
cros_accessibility_observer_.reset(new CrosAccessibilityObserver(this));
touch_exploration_manager_.reset(new AshTouchExplorationManager(this));
}
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions ash/root_window_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class WorkspaceController;

#if defined(OS_CHROMEOS)
class BootSplashScreen;
class AccessibilityObserver;
class AshTouchExplorationManager;
#endif

// This class maintains the per root window state for ash. This class
Expand Down Expand Up @@ -298,7 +298,7 @@ class ASH_EXPORT RootWindowController : public ShellObserver {
scoped_ptr<BootSplashScreen> boot_splash_screen_;
// Responsible for initializing TouchExplorationController when spoken
// feedback is on.
scoped_ptr<AccessibilityObserver> cros_accessibility_observer_;
scoped_ptr<AshTouchExplorationManager> touch_exploration_manager_;
#endif

scoped_ptr<ScreenDimmer> screen_dimmer_;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/ash/volume_controller_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool VolumeController::HandleVolumeDown(const ui::Accelerator& accelerator) {
audio_handler->SetOutputVolumePercent(0);
} else {
audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage);
if (audio_handler->IsOutputVolumeBelowDefaultMuteLvel())
if (audio_handler->IsOutputVolumeBelowDefaultMuteLevel())
audio_handler->SetOutputMute(true);
else
PlayVolumeAdjustSound();
Expand Down
2 changes: 1 addition & 1 deletion chromeos/audio/cras_audio_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool CrasAudioHandler::IsOutputMutedForDevice(uint64 device_id) {
return audio_pref_handler_->GetMuteValue(*device);
}

bool CrasAudioHandler::IsOutputVolumeBelowDefaultMuteLvel() {
bool CrasAudioHandler::IsOutputVolumeBelowDefaultMuteLevel() {
return output_volume_ <= kMuteThresholdPercent;
}

Expand Down
2 changes: 1 addition & 1 deletion chromeos/audio/cras_audio_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
virtual bool IsInputMutedForDevice(uint64 device_id);

// Returns true if the output volume is below the default mute volume level.
virtual bool IsOutputVolumeBelowDefaultMuteLvel();
virtual bool IsOutputVolumeBelowDefaultMuteLevel();

// Returns volume level in 0-100% range at which the volume should be muted.
virtual int GetOutputDefaultVolumeMuteThreshold();
Expand Down
Loading

0 comments on commit 7d48759

Please sign in to comment.