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
ash / quick_insert / quick_insert_action_on_next_focus_request.h [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_QUICK_INSERT_QUICK_INSERT_ACTION_ON_NEXT_FOCUS_REQUEST_H_
#define ASH_QUICK_INSERT_QUICK_INSERT_ACTION_ON_NEXT_FOCUS_REQUEST_H_
#include "ash/ash_export.h"
#include "base/functional/callback_forward.h"
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "ui/base/ime/input_method_observer.h"
namespace ui {
class InputMethod;
} // namespace ui
namespace ash {
// A request to perform an action the next time an input field gains focus.
class ASH_EXPORT QuickInsertActionOnNextFocusRequest
: public ui::InputMethodObserver {
public:
// Creates a request to perform `action_callback` the next time an input field
// gains focus. If there's no focus change within `action_timeout`, then
// `timeout_callback` is run instead of `action_callback`. If this request is
// destroyed before the action could happen, then neither `action_callback`
// nor `timeout_callback` are run.
QuickInsertActionOnNextFocusRequest(ui::InputMethod* input_method,
base::TimeDelta action_timeout,
base::OnceClosure action_callback,
base::OnceClosure timeout_callback);
~QuickInsertActionOnNextFocusRequest() override;
// ui::InputMethodObserver:
void OnFocus() override {}
void OnBlur() override {}
void OnCaretBoundsChanged(const ui::TextInputClient* client) override {}
void OnTextInputStateChanged(const ui::TextInputClient* client) override;
void OnInputMethodDestroyed(const ui::InputMethod* input_method) override;
private:
void OnTimeout();
base::ScopedObservation<ui::InputMethod, ui::InputMethodObserver>
observation_{this};
base::OneShotTimer action_timeout_timer_;
base::OnceClosure action_callback_;
base::OnceClosure timeout_callback_;
};
} // namespace ash
#endif // ASH_QUICK_INSERT_QUICK_INSERT_ACTION_ON_NEXT_FOCUS_REQUEST_H_