1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_BASE_IME_ASH_IME_KEYBOARD_H_
#define UI_BASE_IME_ASH_IME_KEYBOARD_H_
#include <string>
#include <vector>
#include "base/component_export.h"
#include "base/functional/callback_forward.h"
#include "base/observer_list.h"
#include "base/time/time.h"
namespace ash {
namespace input_method {
struct AutoRepeatRate {
base::TimeDelta initial_delay;
base::TimeDelta repeat_interval;
};
class COMPONENT_EXPORT(UI_BASE_IME_ASH) ImeKeyboard {
public:
class Observer : public base::CheckedObserver {
public:
// Called when the caps lock state has changed.
virtual void OnCapsLockChanged(bool enabled) = 0;
// Called when the layout state is changing.
virtual void OnLayoutChanging(const std::string& layout_name) = 0;
protected:
~Observer() override = default;
};
ImeKeyboard();
virtual ~ImeKeyboard();
// Adds/removes observer.
virtual void AddObserver(Observer* observer);
virtual void RemoveObserver(Observer* observer);
// Sets the current keyboard layout to |layout_name|. This function does not
// change the current mapping of the modifier keys. Callback is supplied
// boolean with true on success and false on failure. Callback can potentially
// be ran immediately with no delay.
virtual void SetCurrentKeyboardLayoutByName(
const std::string& layout_name,
base::OnceCallback<void(bool)> callback);
// Gets the current keyboard layout name.
const std::string& GetCurrentKeyboardLayoutName() const {
return last_layout_;
}
// Sets the caps lock status to |enable_caps_lock|. Do not call the function
// from non-UI threads.
virtual void SetCapsLockEnabled(bool enable_caps_lock);
// Returns true if caps lock is enabled. Do not call the function from non-UI
// threads.
virtual bool IsCapsLockEnabled();
// Returns true if the current layout supports ISO Level 5 shift.
virtual bool IsISOLevel5ShiftAvailable() const;
// Returns true if the current layout supports alt gr.
virtual bool IsAltGrAvailable() const;
// Turns on and off the auto-repeat of the keyboard.
// Do not call the function from non-UI threads.
virtual void SetAutoRepeatEnabled(bool enabled) = 0;
// Returns true if auto-repeat is enabled.
virtual bool GetAutoRepeatEnabled() = 0;
// Sets the auto-repeat rate of the keyboard, initial delay in ms, and repeat
// interval in ms. Returns true on success. Do not call the function from
// non-UI threads.
virtual bool SetAutoRepeatRate(const AutoRepeatRate& rate) = 0;
// Enables or disables the Slow Keys a11y functionality on the keyboard.
// Do not call the function from non-UI threads.
virtual void SetSlowKeysEnabled(bool enabled) = 0;
// Returns whether Slow Keys is enabled.
virtual bool IsSlowKeysEnabled() const = 0;
// Sets the amount of delay for Slow Keys.
// Do not call the function from non-UI threads.
virtual void SetSlowKeysDelay(base::TimeDelta delay) = 0;
protected:
bool SetCurrentKeyboardLayoutByNameImpl(const std::string& layout_name);
private:
bool caps_lock_is_enabled_ = false;
std::string last_layout_;
base::ObserverList<Observer> observers_;
};
} // namespace input_method
} // namespace ash
#endif // UI_BASE_IME_ASH_IME_KEYBOARD_H_
|