Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / base / ime / chromeos / ime_keyboard_x11.h
blob6b9da522e413b35800a341ec33b2b6b6cfe8815a
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_BASE_IME_CHROMEOS_IME_KEYBOARD_X11_H_
6 #define UI_BASE_IME_CHROMEOS_IME_KEYBOARD_X11_H_
8 #include "ui/base/ime/chromeos/ime_keyboard.h"
10 #include <cstdlib>
11 #include <cstring>
12 #include <queue>
13 #include <set>
14 #include <utility>
16 #include "base/bind.h"
17 #include "base/logging.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/message_loop/message_loop.h"
20 #include "base/process/kill.h"
21 #include "base/process/launch.h"
22 #include "base/process/process_handle.h"
23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h"
25 #include "base/sys_info.h"
26 #include "base/threading/thread_checker.h"
27 #include "ui/base/ime/ui_base_ime_export.h"
29 namespace chromeos {
30 namespace input_method {
32 class UI_BASE_IME_EXPORT ImeKeyboardX11 : public ImeKeyboard {
33 public:
34 ImeKeyboardX11();
35 ~ImeKeyboardX11() override;
37 // ImeKeyboard:
38 bool SetCurrentKeyboardLayoutByName(const std::string& layout_name) override;
39 bool ReapplyCurrentKeyboardLayout() override;
40 void ReapplyCurrentModifierLockStatus() override;
41 void DisableNumLock() override;
42 void SetCapsLockEnabled(bool enable_caps_lock) override;
43 bool CapsLockIsEnabled() override;
44 bool SetAutoRepeatEnabled(bool enabled) override;
45 bool GetAutoRepeatEnabled() override;
46 bool SetAutoRepeatRate(const AutoRepeatRate& rate) override;
48 private:
49 // Returns a mask for Num Lock (e.g. 1U << 4). Returns 0 on error.
50 unsigned int GetNumLockMask();
52 // Sets the caps-lock status. Note that calling this function always disables
53 // the num-lock.
54 void SetLockedModifiers();
56 // This function is used by SetLayout() and RemapModifierKeys(). Calls
57 // setxkbmap command if needed, and updates the last_full_layout_name_ cache.
58 bool SetLayoutInternal(const std::string& layout_name, bool force);
60 // Executes 'setxkbmap -layout ...' command asynchronously using a layout name
61 // in the |execute_queue_|. Do nothing if the queue is empty.
62 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105)
63 void MaybeExecuteSetLayoutCommand();
65 // Polls to see setxkbmap process exits.
66 void PollUntilChildFinish(const base::ProcessHandle handle);
68 // Called when execve'd setxkbmap process exits.
69 void OnSetLayoutFinish();
71 const bool is_running_on_chrome_os_;
72 unsigned int num_lock_mask_;
74 // A queue for executing setxkbmap one by one.
75 std::queue<std::string> execute_queue_;
77 base::ThreadChecker thread_checker_;
79 base::WeakPtrFactory<ImeKeyboardX11> weak_factory_;
81 DISALLOW_COPY_AND_ASSIGN(ImeKeyboardX11);
85 } // namespace input_method
86 } // namespace chromeos
88 #endif // UI_BASE_IME_CHROMEOS_IME_KEYBOARD_X11_H_