Commit 2f2a33d5 authored by Anatoliy Potapchuk's avatar Anatoliy Potapchuk Committed by Commit Bot

[Ash] Simplify AccessibilityControllerImpl to remove duplications

AccessibilityControllerImpl had a lot of duplications. Let's fix that.
Also, now it controls fullscreen and docked magnifiers. Before that,
we have to go AccessibilityDelegate and MagnificationManager to do
this.

Change-Id: I6a5d827ded2a88a56eb173fed67e010aa002070d
Bug: 1051892
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2050688Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Anatoliy Potapchuk <apotapchuk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751086}
parent 7c97ef8b
......@@ -13,6 +13,7 @@
#include "ash/public/cpp/tablet_mode_observer.h"
#include "ash/session/session_observer.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/time/time.h"
......@@ -28,6 +29,7 @@ enum class Gesture;
namespace gfx {
class Point;
struct VectorIcon;
} // namespace gfx
namespace ash {
......@@ -50,6 +52,101 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController,
public SessionObserver,
public TabletModeObserver {
public:
enum FeatureType {
kAutoclick = 0,
kCaretHighlight,
KCursorHighlight,
kDictation,
kFocusHighlight,
kFullscreenMagnifier,
kDockedMagnifier,
kHighContrast,
kLargeCursor,
kMonoAudio,
kSpokenFeedback,
kSelectToSpeak,
kStickyKeys,
kSwitchAccess,
kVirtualKeyboard,
kFeatureCount,
kNoConflictingFeature
};
// Common interface for all features.
class Feature {
public:
Feature(FeatureType type,
const std::string& pref_name,
const gfx::VectorIcon* icon,
AccessibilityControllerImpl* controller);
Feature(const Feature&) = delete;
Feature& operator=(Feature const&) = delete;
virtual ~Feature();
FeatureType type() const { return type_; }
// Tries to set the feature to |enabled| by setting the user pref.
// Setting feature to be enabled can fail in following conditions:
// - there is a higher priority pref(managed), which overrides this value.
// - there is an other feature, which conflicts with the current one.
virtual void SetEnabled(bool enabled);
bool enabled() const { return enabled_; }
bool IsVisibleInTray() const;
bool IsEnterpriseIconVisible() const;
const std::string& pref_name() const { return pref_name_; }
const gfx::VectorIcon& icon() const;
void UpdateFromPref();
void SetConflictingFeature(FeatureType feature);
protected:
FeatureType type_;
// Some features cannot be enabled while others are on. When a conflicting
// feature is enabled, we cannot enable current feature.
FeatureType conflicting_feature_ = FeatureType::kNoConflictingFeature;
bool enabled_;
const std::string pref_name_;
const gfx::VectorIcon* icon_;
AccessibilityControllerImpl* owner_;
};
// Helper struct to store information about a11y dialog -- pref name, resource
// ids for title and body. Also stores the information whether this dialog is
// mandatory for every SetEnabled call.
struct Dialog {
std::string pref_name;
int title_resource_id;
int body_resource_id;
// Whether this dialog should be shown on every SetEnabled action.
bool mandatory;
};
// Some features have confirmation dialog associated with them.
// Dialog can be applied for all SetEnabled() actions, or only to ones
// associated with accelerators.
class FeatureWithDialog : public Feature {
public:
FeatureWithDialog(FeatureType type,
const std::string& pref_name,
const gfx::VectorIcon* icon,
const Dialog& dialog,
AccessibilityControllerImpl* controller);
~FeatureWithDialog() override;
// Tries to set the feature enabled, if its dialog is mandatory, shows the
// dailog for the first time feature is enabled.
void SetEnabled(bool enabled) override;
// If the dialog have not been accepted, we show it. When it is accepted, we
// call SetEnabled() and invoke |completion_callback|.
void SetEnabledWithDialog(bool enabled,
base::OnceClosure completion_callback);
void SetDialogAccepted();
bool WasDialogAccepted() const;
private:
Dialog dialog_;
};
AccessibilityControllerImpl();
~AccessibilityControllerImpl() override;
......@@ -61,6 +158,13 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController,
void AddObserver(AccessibilityObserver* observer);
void RemoveObserver(AccessibilityObserver* observer);
Feature& GetFeature(FeatureType feature) const;
// Getters for the corresponding features.
Feature& autoclick() const;
Feature& caret_highlight() const;
Feature& cursor_highlight() const;
// The following functions read and write to their associated preference.
// These values are then used to determine whether the accelerator
// confirmation dialog for the respective preference has been accepted before.
......@@ -76,7 +180,7 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController,
bool HasDisplayRotationAcceleratorDialogBeenAccepted() const;
void SetAutoclickEnabled(bool enabled);
bool autoclick_enabled() const { return autoclick_enabled_; }
bool autoclick_enabled() const { return autoclick().enabled(); }
bool IsAutoclickSettingVisibleInTray();
bool IsEnterpriseIconVisibleForAutoclick();
......@@ -92,12 +196,12 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController,
void UpdateAutoclickMenuBoundsIfNeeded();
void SetCaretHighlightEnabled(bool enabled);
bool caret_highlight_enabled() const { return caret_highlight_enabled_; }
bool caret_highlight_enabled() const { return caret_highlight().enabled(); }
bool IsCaretHighlightSettingVisibleInTray();
bool IsEnterpriseIconVisibleForCaretHighlight();
void SetCursorHighlightEnabled(bool enabled);
bool cursor_highlight_enabled() const { return cursor_highlight_enabled_; }
bool cursor_highlight_enabled() const { return cursor_highlight().enabled(); }
bool IsCursorHighlightSettingVisibleInTray();
bool IsEnterpriseIconVisibleForCursorHighlight();
......@@ -268,6 +372,12 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController,
SwitchAccessEventHandler* GetSwitchAccessEventHandlerForTest();
private:
// Populate |features_| with the feature of the correct type.
void CreateAccessibilityFeatures();
// Propagates the state of |feature| according to |feature->enabled()|.
void OnFeatureChanged(FeatureType feature);
// TabletModeObserver:
void OnTabletModeStarted() override;
void OnTabletModeEnded() override;
......@@ -276,15 +386,15 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController,
// initial settings.
void ObservePrefs(PrefService* prefs);
void UpdateAutoclickFromPref();
// Updates the actual feature status based on the prefs value.
void UpdateFeatureFromPref(FeatureType feature);
void UpdateAutoclickDelayFromPref();
void UpdateAutoclickEventTypeFromPref();
void UpdateAutoclickRevertToLeftClickFromPref();
void UpdateAutoclickStabilizePositionFromPref();
void UpdateAutoclickMovementThresholdFromPref();
void UpdateAutoclickMenuPositionFromPref();
void UpdateCaretHighlightFromPref();
void UpdateCursorHighlightFromPref();
void UpdateDictationFromPref();
void UpdateFocusHighlightFromPref();
void UpdateHighContrastFromPref();
......@@ -306,19 +416,12 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController,
void MaybeCreateSelectToSpeakEventHandler();
void MaybeCreateSwitchAccessEventHandler();
// The pref service of the currently active user or the signin profile before
// user logs in. Can be null in ash_unittests.
PrefService* active_user_prefs_ = nullptr;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
// Client interface in chrome browser.
AccessibilityControllerClient* client_ = nullptr;
bool autoclick_enabled_ = false;
std::unique_ptr<Feature> features_[kFeatureCount];
base::TimeDelta autoclick_delay_;
bool caret_highlight_enabled_ = false;
bool cursor_highlight_enabled_ = false;
bool dictation_enabled_ = false;
bool focus_highlight_enabled_ = false;
bool high_contrast_enabled_ = false;
......@@ -355,6 +458,15 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController,
base::ObserverList<AccessibilityObserver> observers_;
// The pref service of the currently active user or the signin profile before
// user logs in. Can be null in ash_unittests.
PrefService* active_user_prefs_ = nullptr;
// This has to be the first one to be destroyed so we don't get updates about
// any prefs during destruction.
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
base::WeakPtrFactory<AccessibilityControllerImpl> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(AccessibilityControllerImpl);
};
......
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