summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/ibus/ibus_lookup_table.h
blob: d87bf55a3f438639e28df61bbd4253fc70d24118 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// 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 CHROMEOS_DBUS_IBUS_IBUS_LOOKUP_TABLE_H_
#define CHROMEOS_DBUS_IBUS_IBUS_LOOKUP_TABLE_H_

#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "chromeos/chromeos_export.h"

namespace dbus {
class MessageWriter;
class MessageReader;
}  // namespace dbus

namespace chromeos {
// TODO(nona): Remove ibus namespace after complete libibus removal.
namespace ibus {

// The IBusLookupTable is one of IBusObjects. IBusLookupTable contains IBusTexts
// but all of them are used as plain string. The overview of each data
// strucutres is as follows:
//
// DATA STRUCTURE OVERVIEW:
//  variant  struct {
//   string "IBusLookupTable"
//   array [
//     dict_entry (
//       string "window_show_at_composition"
//       variant  variant  boolean false
//       ]
//     )
//   ]
//   uint32 9  // Page size
//   uint32 1  // Cursor position
//   boolean true  // Cursor visibility.
//   boolean true  // Round lookup table or not. Not used in Chrome.
//   int32 1  // Orientation
//   array [  // Array of candidate text.
//    variant struct {
//      string "IBusText"
//      array []
//      string "Candidate Text"
//      variant struct {
//       string "IBusAttrList"
//       array []
//       array []
//       }
//     }
//     ... more IBusTexts
//   ]
//   array [  // Array of label text
//    variant struct {
//      string "IBusText"
//      array []
//      string "1"
//      variant struct {
//       string "IBusAttrList"
//       array []
//       array []
//       }
//     }
//     ... more IBusTexts
//   ]
//  }
//  TODO(nona): Clean up the structure.(crbug.com/129403)
class IBusLookupTable;

// Pops a IBusLookupTable from |reader|.
// Returns false if an error occures.
bool CHROMEOS_EXPORT PopIBusLookupTable(dbus::MessageReader* reader,
                                        IBusLookupTable* table);
// Appends a IBusLookupTable to |writer| except mozc_candidates_ in |table|.
void CHROMEOS_EXPORT AppendIBusLookupTable(const IBusLookupTable& table,
                                           dbus::MessageWriter* writer);

// An representation of IBusLookupTable object which is used in dbus
// communication with ibus-daemon.
class CHROMEOS_EXPORT IBusLookupTable {
 public:
  enum Orientation {
    IBUS_LOOKUP_TABLE_ORIENTATION_HORIZONTAL = 0,
    IBUS_LOOKUP_TABLE_ORIENTATION_VERTICAL = 1,
  };

  // Represents a candidate entry. In dbus communication, each
  // field is represented as IBusText, but attributes are not used in Chrome.
  // So just simple string is sufficient in this case.
  struct Entry {
    Entry();
    virtual ~Entry();
    std::string value;
    std::string label;
    std::string annotation;
    std::string description_title;
    std::string description_body;
  };

  IBusLookupTable();
  virtual ~IBusLookupTable();

  // Returns the number of candidates in one page.
  uint32 page_size() const { return page_size_; }
  void set_page_size(uint32 page_size) { page_size_ = page_size; }

  // Returns the cursor index of the currently selected candidate.
  uint32 cursor_position() const { return cursor_position_; }
  void set_cursor_position(uint32 cursor_position) {
    cursor_position_ = cursor_position;
  }

  // Returns true if the cusros is visible.
  bool is_cursor_visible() const { return is_cursor_visible_; }
  void set_is_cursor_visible(bool is_cursor_visible) {
    is_cursor_visible_ = is_cursor_visible;
  }

  // Returns the orientation of lookup table.
  Orientation orientation() const { return orientation_; }
  void set_orientation(Orientation orientation) {
    orientation_ = orientation;
  }

  const std::vector<Entry>& candidates() const { return candidates_; }
  std::vector<Entry>* mutable_candidates() { return &candidates_; }

  bool show_window_at_composition() const {
    return show_window_at_composition_;
  }
  void set_show_window_at_composition(bool show_window_at_composition) {
    show_window_at_composition_ = show_window_at_composition;
  }

 private:
  uint32 page_size_;
  uint32 cursor_position_;
  bool is_cursor_visible_;
  Orientation orientation_;
  std::vector<Entry> candidates_;
  bool show_window_at_composition_;

  DISALLOW_COPY_AND_ASSIGN(IBusLookupTable);
};

}  // namespace ibus
}  // namespace chromeos

#endif  // CHROMEOS_DBUS_IBUS_IBUS_LOOKUP_TABLE_H_