Skip to content

Commit

Permalink
Introduce AccessibiltyDelegate
Browse files Browse the repository at this point in the history
I'll incorporate changes in https://codereview.chromium.org/27238008 when it's landed.

BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230619 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
oshima@chromium.org committed Oct 24, 2013
1 parent c6b8bb4 commit f3ab6ef
Show file tree
Hide file tree
Showing 28 changed files with 481 additions and 447 deletions.
16 changes: 10 additions & 6 deletions ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ void HandleCycleLinear(const ui::Accelerator& accelerator) {
}

bool HandleAccessibleFocusCycle(bool reverse) {
if (!Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled())
if (!Shell::GetInstance()->accessibility_delegate()->
IsSpokenFeedbackEnabled()) {
return false;
}
aura::Window* active_window = ash::wm::GetActiveWindow();
if (!active_window)
return false;
Expand All @@ -157,10 +159,11 @@ bool HandleAccessibleFocusCycle(bool reverse) {
}

void HandleSilenceSpokenFeedback() {
if (!Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled())
AccessibilityDelegate* delegate =
Shell::GetInstance()->accessibility_delegate();
if (!delegate->IsSpokenFeedbackEnabled())
return;

Shell::GetInstance()->delegate()->SilenceSpokenFeedback();
delegate->SilenceSpokenFeedback();
}

#if defined(OS_CHROMEOS)
Expand All @@ -180,7 +183,7 @@ bool HandleCrosh() {
}

bool HandleToggleSpokenFeedback() {
Shell::GetInstance()->delegate()->
Shell::GetInstance()->accessibility_delegate()->
ToggleSpokenFeedback(A11Y_NOTIFICATION_SHOW);
return true;
}
Expand Down Expand Up @@ -662,7 +665,8 @@ bool AcceleratorController::PerformAction(int action,
// consume the key since Search+Shift is one of the shortcuts the a11y
// feature uses. crbug.com/132296
DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code());
if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled())
if (Shell::GetInstance()->accessibility_delegate()->
IsSpokenFeedbackEnabled())
return false;
ash::Shell::GetInstance()->ToggleAppList(NULL);
return true;
Expand Down
6 changes: 3 additions & 3 deletions ash/accelerators/accelerator_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "ash/accelerators/accelerator_controller.h"
#include "ash/accelerators/accelerator_table.h"
#include "ash/accessibility_delegate.h"
#include "ash/caps_lock_delegate.h"
#include "ash/display/display_manager.h"
#include "ash/ime_control_delegate.h"
Expand Down Expand Up @@ -957,9 +958,8 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) {
}

TEST_F(AcceleratorControllerTest, GlobalAcceleratorsToggleAppList) {
test::TestShellDelegate* delegate =
reinterpret_cast<test::TestShellDelegate*>(
ash::Shell::GetInstance()->delegate());
AccessibilityDelegate* delegate =
ash::Shell::GetInstance()->accessibility_delegate();
EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility());

// The press event should not open the AppList, the release should instead.
Expand Down
78 changes: 78 additions & 0 deletions ash/accessibility_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2013 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_ACCESSIBILITY_DELEGATE_H_
#define ASH_ACCESSIBILITY_DELEGATE_H_

#include "ash/ash_export.h"
#include "ash/magnifier/magnifier_constants.h"

namespace ash {

enum AccessibilityNotificationVisibility {
A11Y_NOTIFICATION_NONE,
A11Y_NOTIFICATION_SHOW,
};

// A deletate class to control accessibility features.
class ASH_EXPORT AccessibilityDelegate {
public:
AccessibilityDelegate() {}
virtual ~AccessibilityDelegate() {}

// Invoked to toggle spoken feedback for accessibility
virtual void ToggleSpokenFeedback(
AccessibilityNotificationVisibility notify) = 0;

// Returns true if spoken feedback is enabled.
virtual bool IsSpokenFeedbackEnabled() const = 0;

// Invoked to toggle high contrast mode for accessibility.
virtual void ToggleHighContrast() = 0;

// Returns true if high contrast mode is enabled.
virtual bool IsHighContrastEnabled() const = 0;

// Invoked to enable the screen magnifier.
virtual void SetMagnifierEnabled(bool enabled) = 0;

// Invoked to change the type of the screen magnifier.
virtual void SetMagnifierType(MagnifierType type) = 0;

// Returns true if the screen magnifier is enabled or not.
virtual bool IsMagnifierEnabled() const = 0;

// Returns the current screen magnifier mode.
virtual MagnifierType GetMagnifierType() const = 0;

// Invoked to enable Large Cursor.
virtual void SetLargeCursorEnabled(bool enabled) = 0;

// Returns ture if Large Cursor is enabled or not.
virtual bool IsLargeCursorEnabled() const = 0;

// Invoked to enable autoclick.
virtual void SetAutoclickEnabled(bool enabled) = 0;

// Returns if autoclick is enabled or not.
virtual bool IsAutoclickEnabled() const = 0;

// Returns true if the user wants to show accesibility menu even when all the
// accessibility features are disabled.
virtual bool ShouldAlwaysShowAccessibilityMenu() const = 0;

// Cancel all current and queued speech immediately.
virtual void SilenceSpokenFeedback() const = 0;

// Saves the zoom scale of the full screen magnifier.
virtual void SaveScreenMagnifierScale(double scale) = 0;

// Gets a saved value of the zoom scale of full screen magnifier. If a value
// is not saved, return a negative value.
virtual double GetSavedScreenMagnifierScale() = 0;
};

} // namespace ash

#endif // ASH_ACCESSIBILITYDELEGATE_H_
3 changes: 3 additions & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
'accelerators/focus_manager_factory.h',
'accelerators/nested_dispatcher_controller.cc',
'accelerators/nested_dispatcher_controller.h',
'accessibility_delegate.h',
'autoclick/autoclick_controller.cc',
'autoclick/autoclick_controller.h',
'ash_constants.cc',
Expand All @@ -80,6 +81,8 @@
'caps_lock_delegate_stub.h',
'debug.cc',
'debug.h',
'default_accessibility_delegate.cc',
'default_accessibility_delegate.h',
'default_user_wallpaper_delegate.cc',
'default_user_wallpaper_delegate.h',
'desktop_background/desktop_background_controller.cc',
Expand Down
87 changes: 87 additions & 0 deletions ash/default_accessibility_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2013 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/default_accessibility_delegate.h"

#include <limits>

namespace ash {
namespace internal {

DefaultAccessibilityDelegate::DefaultAccessibilityDelegate()
: spoken_feedback_enabled_(false),
high_contrast_enabled_(false),
screen_magnifier_enabled_(false),
screen_magnifier_type_(kDefaultMagnifierType),
large_cursor_enabled_(false),
autoclick_enabled_(false) {
}

DefaultAccessibilityDelegate::~DefaultAccessibilityDelegate() {}

bool DefaultAccessibilityDelegate::IsSpokenFeedbackEnabled() const {
return spoken_feedback_enabled_;
}

void DefaultAccessibilityDelegate::ToggleHighContrast() {
high_contrast_enabled_ = !high_contrast_enabled_;
}

bool DefaultAccessibilityDelegate::IsHighContrastEnabled() const {
return high_contrast_enabled_;
}

void DefaultAccessibilityDelegate::SetMagnifierEnabled(bool enabled) {
screen_magnifier_enabled_ = enabled;
}

void DefaultAccessibilityDelegate::SetMagnifierType(MagnifierType type) {
screen_magnifier_type_ = type;
}

bool DefaultAccessibilityDelegate::IsMagnifierEnabled() const {
return screen_magnifier_enabled_;
}

MagnifierType DefaultAccessibilityDelegate::GetMagnifierType() const {
return screen_magnifier_type_;
}

void DefaultAccessibilityDelegate::SetLargeCursorEnabled(bool enabled) {
large_cursor_enabled_ = enabled;
}

bool DefaultAccessibilityDelegate::IsLargeCursorEnabled() const {
return large_cursor_enabled_;
}

void DefaultAccessibilityDelegate::SetAutoclickEnabled(bool enabled) {
autoclick_enabled_ = enabled;
}

bool DefaultAccessibilityDelegate::IsAutoclickEnabled() const {
return autoclick_enabled_;
}

bool DefaultAccessibilityDelegate::ShouldAlwaysShowAccessibilityMenu() const {
return false;
}

void DefaultAccessibilityDelegate::SilenceSpokenFeedback() const {
}

void DefaultAccessibilityDelegate::ToggleSpokenFeedback(
AccessibilityNotificationVisibility notify) {
spoken_feedback_enabled_ = !spoken_feedback_enabled_;
}

void DefaultAccessibilityDelegate::SaveScreenMagnifierScale(double scale) {
}

double DefaultAccessibilityDelegate::GetSavedScreenMagnifierScale() {
return std::numeric_limits<double>::min();
}

} // namespace internal
} // namespace ash
53 changes: 53 additions & 0 deletions ash/default_accessibility_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2013 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_DEFAULT_ACCESSIBILITY_DELEGATE_H_
#define ASH_DEFAULT_ACCESSIBILITY_DELEGATE_H_

#include "ash/accessibility_delegate.h"
#include "ash/ash_export.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"

namespace ash {
namespace internal {

class ASH_EXPORT DefaultAccessibilityDelegate : public AccessibilityDelegate {
public:
DefaultAccessibilityDelegate();
virtual ~DefaultAccessibilityDelegate();

virtual bool IsSpokenFeedbackEnabled() const OVERRIDE;
virtual void ToggleHighContrast() OVERRIDE;
virtual bool IsHighContrastEnabled() const OVERRIDE;
virtual void SetMagnifierEnabled(bool enabled) OVERRIDE;
virtual void SetMagnifierType(MagnifierType type) OVERRIDE;
virtual bool IsMagnifierEnabled() const OVERRIDE;
virtual MagnifierType GetMagnifierType() const OVERRIDE;
virtual void SetLargeCursorEnabled(bool enabled) OVERRIDE;
virtual bool IsLargeCursorEnabled() const OVERRIDE;
virtual void SetAutoclickEnabled(bool enabled) OVERRIDE;
virtual bool IsAutoclickEnabled() const OVERRIDE;
virtual bool ShouldAlwaysShowAccessibilityMenu() const OVERRIDE;
virtual void SilenceSpokenFeedback() const OVERRIDE;
virtual void ToggleSpokenFeedback(
AccessibilityNotificationVisibility notify) OVERRIDE;
virtual void SaveScreenMagnifierScale(double scale) OVERRIDE;
virtual double GetSavedScreenMagnifierScale() OVERRIDE;

private:
bool spoken_feedback_enabled_;
bool high_contrast_enabled_;
bool screen_magnifier_enabled_;
MagnifierType screen_magnifier_type_;
bool large_cursor_enabled_;
bool autoclick_enabled_;

DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityDelegate);
};

} // namespace internal
} // namespace ash

#endif // DEFAULT_ACCESSIBILITY_DELEGATE_H_
11 changes: 7 additions & 4 deletions ash/magnifier/magnification_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include "ash/magnifier/magnification_controller.h"

#include "ash/accessibility_delegate.h"
#include "ash/display/root_window_transformers.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "base/synchronization/waitable_event.h"
#include "ui/aura/client/cursor_client.h"
Expand Down Expand Up @@ -503,7 +503,8 @@ void MagnificationControllerImpl::SetScale(float scale, bool animate) {
return;

ValidateScale(&scale);
ash::Shell::GetInstance()->delegate()->SaveScreenMagnifierScale(scale);
ash::Shell::GetInstance()->accessibility_delegate()->
SaveScreenMagnifierScale(scale);
RedrawKeepingMousePosition(scale, animate);
}

Expand Down Expand Up @@ -543,7 +544,8 @@ void MagnificationControllerImpl::EnsurePointIsVisible(
void MagnificationControllerImpl::SetEnabled(bool enabled) {
if (enabled) {
float scale =
ash::Shell::GetInstance()->delegate()->GetSavedScreenMagnifierScale();
ash::Shell::GetInstance()->accessibility_delegate()->
GetSavedScreenMagnifierScale();
if (scale <= 0.0f)
scale = kInitialMagnifiedScale;
ValidateScale(&scale);
Expand All @@ -554,7 +556,8 @@ void MagnificationControllerImpl::SetEnabled(bool enabled) {

is_enabled_ = enabled;
RedrawKeepingMousePosition(scale, true);
ash::Shell::GetInstance()->delegate()->SaveScreenMagnifierScale(scale);
ash::Shell::GetInstance()->accessibility_delegate()->
SaveScreenMagnifierScale(scale);
} else {
// Do nothing, if already disabled.
if (!is_enabled_)
Expand Down
2 changes: 2 additions & 0 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ Shell::~Shell() {
screen_position_controller_.reset();

keyboard_controller_.reset();
accessibility_delegate_.reset();

#if defined(OS_CHROMEOS) && defined(USE_X11)
if (display_change_observer_)
Expand Down Expand Up @@ -831,6 +832,7 @@ void Shell::Init() {
caps_lock_delegate_.reset(delegate_->CreateCapsLockDelegate());

session_state_delegate_.reset(delegate_->CreateSessionStateDelegate());
accessibility_delegate_.reset(delegate_->CreateAccessibilityDelegate());

if (!command_line->HasSwitch(views::corewm::switches::kNoDropShadows)) {
resize_shadow_controller_.reset(new internal::ResizeShadowController());
Expand Down
6 changes: 6 additions & 0 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class WindowModalityController;
namespace ash {

class AcceleratorController;
class AccessibilityDelegate;
class AshNativeCursorManager;
class AutoclickController;
class CapsLockDelegate;
Expand Down Expand Up @@ -366,6 +367,10 @@ class ASH_EXPORT Shell
return session_state_delegate_.get();
}

AccessibilityDelegate* accessibility_delegate() {
return accessibility_delegate_.get();
}

HighContrastController* high_contrast_controller() {
return high_contrast_controller_.get();
}
Expand Down Expand Up @@ -573,6 +578,7 @@ class ASH_EXPORT Shell
scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
scoped_ptr<SessionStateDelegate> session_state_delegate_;
scoped_ptr<AccessibilityDelegate> accessibility_delegate_;
scoped_ptr<LauncherDelegate> launcher_delegate_;
scoped_ptr<LauncherItemDelegateManager> launcher_item_delegate_manager_;

Expand Down
Loading

0 comments on commit f3ab6ef

Please sign in to comment.