blob: a5b95a1401457d183a005c87796a175842481f2a (
plain)
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
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright 2016 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 COMPONENTS_ARC_IME_ARC_IME_SERVICE_H_
#define COMPONENTS_ARC_IME_ARC_IME_SERVICE_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "components/arc/arc_service.h"
#include "components/arc/ime/arc_ime_bridge.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/aura/env_observer.h"
#include "ui/aura/window_observer.h"
#include "ui/aura/window_tracker.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/ime/text_input_flags.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/gfx/geometry/rect.h"
namespace aura {
class Window;
}
namespace ui {
class InputMethod;
}
namespace arc {
class ArcBridgeService;
// This class implements ui::TextInputClient and makes ARC windows behave
// as a text input target in Chrome OS environment.
class ArcImeService : public ArcService,
public ArcImeBridge::Delegate,
public aura::EnvObserver,
public aura::WindowObserver,
public aura::client::FocusChangeObserver,
public ui::TextInputClient {
public:
explicit ArcImeService(ArcBridgeService* bridge_service);
~ArcImeService() override;
// Injects the custom IPC bridge object for testing purpose only.
void SetImeBridgeForTesting(scoped_ptr<ArcImeBridge> test_ime_bridge);
// Injects the custom IME for testing purpose only.
void SetInputMethodForTesting(ui::InputMethod* test_input_method);
// Overridden from aura::EnvObserver:
void OnWindowInitialized(aura::Window* new_window) override;
// Overridden from aura::WindowObserver:
void OnWindowAddedToRootWindow(aura::Window* window) override;
// Overridden from aura::client::FocusChangeObserver:
void OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) override;
// Overridden from ArcImeBridge::Delegate:
void OnTextInputTypeChanged(ui::TextInputType type) override;
void OnCursorRectChanged(const gfx::Rect& rect) override;
void OnCancelComposition() override;
// Overridden from ui::TextInputClient:
void SetCompositionText(const ui::CompositionText& composition) override;
void ConfirmCompositionText() override;
void ClearCompositionText() override;
void InsertText(const base::string16& text) override;
void InsertChar(const ui::KeyEvent& event) override;
ui::TextInputType GetTextInputType() const override;
gfx::Rect GetCaretBounds() const override;
// Overridden from ui::TextInputClient (with default implementation):
// TODO(kinaba): Support each of these methods to the extent possible in
// Android input method API.
ui::TextInputMode GetTextInputMode() const override;
int GetTextInputFlags() const override;
bool CanComposeInline() const override;
bool GetCompositionCharacterBounds(uint32_t index,
gfx::Rect* rect) const override;
bool HasCompositionText() const override;
bool GetTextRange(gfx::Range* range) const override;
bool GetCompositionTextRange(gfx::Range* range) const override;
bool GetSelectionRange(gfx::Range* range) const override;
bool SetSelectionRange(const gfx::Range& range) override;
bool DeleteRange(const gfx::Range& range) override;
bool GetTextFromRange(const gfx::Range& range,
base::string16* text) const override;
void OnInputMethodChanged() override {}
bool ChangeTextDirectionAndLayoutAlignment(
base::i18n::TextDirection direction) override;
void ExtendSelectionAndDelete(size_t before, size_t after) override {}
void EnsureCaretInRect(const gfx::Rect& rect) override {}
bool IsEditCommandEnabled(int command_id) override;
void SetEditCommandForNextKeyEvent(int command_id) override {}
private:
ui::InputMethod* GetInputMethod();
scoped_ptr<ArcImeBridge> ime_bridge_;
ui::TextInputType ime_type_;
gfx::Rect cursor_rect_;
bool has_composition_text_;
aura::WindowTracker observing_root_windows_;
aura::WindowTracker arc_windows_;
aura::WindowTracker focused_arc_window_;
ui::InputMethod* test_input_method_;
DISALLOW_COPY_AND_ASSIGN(ArcImeService);
};
} // namespace arc
#endif // COMPONENTS_ARC_IME_ARC_IME_SERVICE_H_
|