summaryrefslogtreecommitdiffstats
path: root/ui/base/ime/ibus_client.h
blob: 5b87a3f3896658435357e9ce7ff3ddf6e65b2dbc (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
119
120
121
122
123
124
125
126
// Copyright (c) 2012 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 UI_BASE_IME_IBUS_CLIENT_H_
#define UI_BASE_IME_IBUS_CLIENT_H_
#pragma once

#include <glib/gtypes.h>

#include "base/basictypes.h"
#include "base/event_types.h"
#include "base/string16.h"
#include "ui/base/events.h"
#include "ui/base/ui_export.h"

typedef struct _IBusBus IBusBus;
typedef struct _IBusInputContext IBusInputContext;
typedef struct _IBusText IBusText;

namespace ui {

struct CompositionText;

namespace internal {

// An interface implemented by the object that sends and receives an event to
// and from ibus-daemon.
class UI_EXPORT IBusClient {
 public:
  // A class to hold all data related to a key event being processed by the
  // input method but still has no result back yet.
  class PendingKeyEvent {
   public:
    virtual ~PendingKeyEvent() {}
    // Process this pending key event after we receive its result from the input
    // method. It just call through InputMethodIBus::ProcessKeyEventPostIME().
    virtual void ProcessPostIME(bool handled) = 0;
  };

  // A class to hold information of a pending request for creating an ibus input
  // context.
  class PendingCreateICRequest {
   public:
    virtual ~PendingCreateICRequest() {};
    // Stores the result input context to |input_method_|, or abandon it if
    // |input_method_| is NULL.
    virtual void StoreOrAbandonInputContext(IBusInputContext* ic) = 0;
  };

  enum InlineCompositionCapability {
    OFF_THE_SPOT_COMPOSITION = 0,
    INLINE_COMPOSITION = 1,
  };

  // The type of IME which is currently selected. Implementations should return
  // the former when no IME is selected or the type of the current IME is
  // unknown.
  enum InputMethodType {
    INPUT_METHOD_NORMAL = 0,
    INPUT_METHOD_XKB_LAYOUT,
  };

  virtual ~IBusClient() {}

  // Gets a D-Bus connection to ibus-daemon. An implementation should establish
  // a connection to the daemon when the method is called first. After that, the
  // implementation should return the same object as before.
  virtual IBusBus* GetConnection() = 0;

  // Returns true if |bus| is connected.
  virtual bool IsConnected(IBusBus* bus) = 0;

  // Creates a new input context asynchronously. An implementation has to call
  // PendingCreateICRequest::StoreOrAbandonInputContext() with the newly created
  // context when the asynchronous request succeeds.
  virtual void CreateContext(IBusBus* bus,
                             PendingCreateICRequest* request) = 0;

  // Destroys the proxy object for the |context|. An implementation must send
  // "destroy" signal to the context object.
  virtual void DestroyProxy(IBusInputContext* context) = 0;

  // Updates the set of capabilities of the |context|.
  virtual void SetCapabilities(IBusInputContext* context,
                               InlineCompositionCapability inline_type) = 0;

  // Focuses the |context| asynchronously.
  virtual void FocusIn(IBusInputContext* context) = 0;
  // Blurs the |context| asynchronously.
  virtual void FocusOut(IBusInputContext* context) = 0;
  // Resets the |context| asynchronously.
  virtual void Reset(IBusInputContext* context) = 0;

  // Returns the current input method type.
  virtual InputMethodType GetInputMethodType() = 0;

  // Resets the cursor location asynchronously.
  virtual void SetCursorLocation(IBusInputContext* context,
                                 int32 x,
                                 int32 y,
                                 int32 w,
                                 int32 h) = 0;

  // Sends the key to ibus-daemon asynchronously.
  virtual void SendKeyEvent(IBusInputContext* context,
                            uint32 keyval,
                            uint32 keycode,
                            uint32 state,
                            PendingKeyEvent* pending_key) = 0;

  // Called by InputMethodIBus::OnUpdatePreeditText to convert |text| into a
  // CompositionText.
  virtual void ExtractCompositionText(IBusText* text,
                                      guint cursor_position,
                                      CompositionText* out_composition) = 0;

  // Called by InputMethodIBus::OnCommitText to convert |text| into a Unicode
  // string.
  virtual string16 ExtractCommitText(IBusText* text) = 0;
};

}  // namespace internal
}  // namespace ui

#endif  // UI_BASE_IME_IBUS_CLIENT_H_