| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #ifndef CHROMEOS_DBUS_IBUS_IBUS_LOOKUP_TABLE_H_ | |
| 6 #define CHROMEOS_DBUS_IBUS_IBUS_LOOKUP_TABLE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "chromeos/chromeos_export.h" | |
| 13 | |
| 14 namespace chromeos { | |
| 15 | |
| 16 // The IBusLookupTable is one of IBusObjects. IBusLookupTable contains IBusTexts | |
| 17 // but all of them are used as plain string. The overview of each data | |
| 18 // structure is as follows: | |
| 19 // | |
| 20 // DATA STRUCTURE OVERVIEW: | |
| 21 // variant struct { | |
| 22 // string "IBusLookupTable" | |
| 23 // array [ | |
| 24 // dict_entry ( | |
| 25 // string "window_show_at_composition" | |
| 26 // variant variant boolean false | |
| 27 // ] | |
| 28 // ) | |
| 29 // ] | |
| 30 // uint32 9 // Page size | |
| 31 // uint32 1 // Cursor position | |
| 32 // boolean true // Cursor visibility. | |
| 33 // boolean true // Round lookup table or not. Not used in Chrome. | |
| 34 // int32 1 // Orientation | |
| 35 // array [ // Array of candidate text. | |
| 36 // variant struct { | |
| 37 // string "IBusText" | |
| 38 // array [] | |
| 39 // string "Candidate Text" | |
| 40 // variant struct { | |
| 41 // string "IBusAttrList" | |
| 42 // array [] | |
| 43 // array [] | |
| 44 // } | |
| 45 // } | |
| 46 // ... more IBusTexts | |
| 47 // ] | |
| 48 // array [ // Array of label text | |
| 49 // variant struct { | |
| 50 // string "IBusText" | |
| 51 // array [] | |
| 52 // string "1" | |
| 53 // variant struct { | |
| 54 // string "IBusAttrList" | |
| 55 // array [] | |
| 56 // array [] | |
| 57 // } | |
| 58 // } | |
| 59 // ... more IBusTexts | |
| 60 // ] | |
| 61 // } | |
| 62 // TODO(nona): Clean up the structure.(crbug.com/129403) | |
| 63 | |
| 64 // An representation of IBusLookupTable object which is used in dbus | |
| 65 // communication with ibus-daemon. | |
| 66 class CHROMEOS_EXPORT IBusLookupTable { | |
| 67 public: | |
| 68 enum Orientation { | |
| 69 HORIZONTAL = 0, | |
| 70 VERTICAL = 1, | |
| 71 }; | |
| 72 | |
| 73 struct CandidateWindowProperty { | |
| 74 CandidateWindowProperty(); | |
| 75 virtual ~CandidateWindowProperty(); | |
| 76 int page_size; | |
| 77 int cursor_position; | |
| 78 bool is_cursor_visible; | |
| 79 bool is_vertical; | |
| 80 bool show_window_at_composition; | |
| 81 }; | |
| 82 | |
| 83 // Represents a candidate entry. In dbus communication, each | |
| 84 // field is represented as IBusText, but attributes are not used in Chrome. | |
| 85 // So just simple string is sufficient in this case. | |
| 86 struct Entry { | |
| 87 Entry(); | |
| 88 virtual ~Entry(); | |
| 89 std::string value; | |
| 90 std::string label; | |
| 91 std::string annotation; | |
| 92 std::string description_title; | |
| 93 std::string description_body; | |
| 94 }; | |
| 95 | |
| 96 IBusLookupTable(); | |
| 97 virtual ~IBusLookupTable(); | |
| 98 | |
| 99 // Returns true if the given |table| is equal to myself. | |
| 100 bool IsEqual(const IBusLookupTable& table) const; | |
| 101 | |
| 102 // Copies |table| to myself. | |
| 103 void CopyFrom(const IBusLookupTable& table); | |
| 104 | |
| 105 const CandidateWindowProperty& GetProperty() const { | |
| 106 return *property_; | |
| 107 } | |
| 108 void SetProperty(const CandidateWindowProperty& property) { | |
| 109 *property_ = property; | |
| 110 } | |
| 111 | |
| 112 // Returns the number of candidates in one page. | |
| 113 uint32 page_size() const { return property_->page_size; } | |
| 114 void set_page_size(uint32 page_size) { property_->page_size = page_size; } | |
| 115 | |
| 116 // Returns the cursor index of the currently selected candidate. | |
| 117 uint32 cursor_position() const { return property_->cursor_position; } | |
| 118 void set_cursor_position(uint32 cursor_position) { | |
| 119 property_->cursor_position = cursor_position; | |
| 120 } | |
| 121 | |
| 122 // Returns true if the cursor is visible. | |
| 123 bool is_cursor_visible() const { return property_->is_cursor_visible; } | |
| 124 void set_is_cursor_visible(bool is_cursor_visible) { | |
| 125 property_->is_cursor_visible = is_cursor_visible; | |
| 126 } | |
| 127 | |
| 128 // Returns the orientation of lookup table. | |
| 129 Orientation orientation() const { | |
| 130 return property_->is_vertical ? VERTICAL : HORIZONTAL; | |
| 131 } | |
| 132 void set_orientation(Orientation orientation) { | |
| 133 property_->is_vertical = (orientation == VERTICAL); | |
| 134 } | |
| 135 | |
| 136 const std::vector<Entry>& candidates() const { return candidates_; } | |
| 137 std::vector<Entry>* mutable_candidates() { return &candidates_; } | |
| 138 | |
| 139 bool show_window_at_composition() const { | |
| 140 return property_->show_window_at_composition; | |
| 141 } | |
| 142 void set_show_window_at_composition(bool show_window_at_composition) { | |
| 143 property_->show_window_at_composition = show_window_at_composition; | |
| 144 } | |
| 145 | |
| 146 private: | |
| 147 scoped_ptr<CandidateWindowProperty> property_; | |
| 148 std::vector<Entry> candidates_; | |
| 149 | |
| 150 DISALLOW_COPY_AND_ASSIGN(IBusLookupTable); | |
| 151 }; | |
| 152 | |
| 153 } // namespace chromeos | |
| 154 | |
| 155 #endif // CHROMEOS_DBUS_IBUS_IBUS_LOOKUP_TABLE_H_ | |
| OLD | NEW |