Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // |MotermModel| is a class providing a model for terminal emulation. The basic | 5 // |MotermModel| is a class providing a model for terminal emulation. The basic |
| 6 // operations are providing "input" bytes (this is input from the point of view | 6 // operations are providing "input" bytes (this is input from the point of view |
| 7 // of the terminal; from the point of view of applications, it's output) and | 7 // of the terminal; from the point of view of applications, it's output) and |
| 8 // determining what character to display at any given position (with what | 8 // determining what character to display at any given position (with what |
| 9 // attributes). | 9 // attributes). |
| 10 // | 10 // |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 bool IsDirty() const { | 96 bool IsDirty() const { |
| 97 return cursor_moved || bell_count > 0 || !dirty_rect.IsEmpty(); | 97 return cursor_moved || bell_count > 0 || !dirty_rect.IsEmpty(); |
| 98 } | 98 } |
| 99 void Reset() { *this = StateChanges(); } | 99 void Reset() { *this = StateChanges(); } |
| 100 | 100 |
| 101 bool cursor_moved; | 101 bool cursor_moved; |
| 102 unsigned bell_count; | 102 unsigned bell_count; |
| 103 Rectangle dirty_rect; | 103 Rectangle dirty_rect; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 class Delegate { | |
| 107 public: | |
| 108 // Called when a response is received (i.e., the terminal wants to put data | |
| 109 // into the input stream). | |
| 110 virtual void OnResponse(const void* buf, size_t size) = 0; | |
| 111 | |
| 112 protected: | |
| 113 Delegate() {} | |
| 114 ~Delegate() {} | |
|
jamesr
2015/09/09 16:49:45
virtual (since you have a vtable already)
| |
| 115 | |
| 116 private: | |
| 117 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
| 118 }; | |
| 119 | |
| 106 // Maximum number of rows/columns. | 120 // Maximum number of rows/columns. |
| 107 static const unsigned kMaxRows = 500; // TODO(vtl): Made up number. | 121 static const unsigned kMaxRows = 500; // TODO(vtl): Made up number. |
| 108 static const unsigned kMaxColumns = T_NUMCOL; | 122 static const unsigned kMaxColumns = T_NUMCOL; |
| 109 | 123 |
| 110 MotermModel(const Size& max_size, const Size& size); | 124 // If non-null, |delegate| must outlive this object. |
| 125 MotermModel(const Size& max_size, const Size& size, Delegate* delegate); | |
| 111 ~MotermModel(); | 126 ~MotermModel(); |
| 112 | 127 |
| 113 // Process the given input bytes, reporting (additional) state changes to | 128 // Process the given input bytes, reporting (additional) state changes to |
| 114 // |*state_changes| (note: this does not "reset" |*state_changes|, so that | 129 // |*state_changes| (note: this does not "reset" |*state_changes|, so that |
| 115 // state changes can be accumulated across multiple calls). | 130 // state changes can be accumulated across multiple calls). |
| 116 void ProcessInput(const void* input_bytes, | 131 void ProcessInput(const void* input_bytes, |
| 117 size_t num_input_bytes, | 132 size_t num_input_bytes, |
| 118 StateChanges* state_changes); | 133 StateChanges* state_changes); |
| 119 | 134 |
| 120 Size GetSize() const; | 135 Size GetSize() const; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 const teken_rect_t* rect, | 170 const teken_rect_t* rect, |
| 156 teken_char_t ch, | 171 teken_char_t ch, |
| 157 const teken_attr_t* attr); | 172 const teken_attr_t* attr); |
| 158 static void OnCopyThunk(void* ctx, | 173 static void OnCopyThunk(void* ctx, |
| 159 const teken_rect_t* rect, | 174 const teken_rect_t* rect, |
| 160 const teken_pos_t* pos); | 175 const teken_pos_t* pos); |
| 161 static void OnParamThunk(void* ctx, int cmd, unsigned val); | 176 static void OnParamThunk(void* ctx, int cmd, unsigned val); |
| 162 static void OnRespondThunk(void* ctx, const void* buf, size_t size); | 177 static void OnRespondThunk(void* ctx, const void* buf, size_t size); |
| 163 | 178 |
| 164 const Size max_size_; | 179 const Size max_size_; |
| 180 Delegate* const delegate_; | |
| 165 | 181 |
| 166 scoped_ptr<teken_char_t[]> characters_; | 182 scoped_ptr<teken_char_t[]> characters_; |
| 167 scoped_ptr<teken_attr_t[]> attributes_; | 183 scoped_ptr<teken_attr_t[]> attributes_; |
| 168 | 184 |
| 169 teken_t terminal_; | 185 teken_t terminal_; |
| 170 | 186 |
| 171 // Used by the callbacks. ("Usually" null, but must be non-null whenever a | 187 // Used by the callbacks. ("Usually" null, but must be non-null whenever a |
| 172 // callback may be called -- it'll point to a stack variable.) | 188 // callback may be called -- it'll point to a stack variable.) |
| 173 StateChanges* current_state_changes_; | 189 StateChanges* current_state_changes_; |
| 174 | 190 |
| 175 DISALLOW_COPY_AND_ASSIGN(MotermModel); | 191 DISALLOW_COPY_AND_ASSIGN(MotermModel); |
| 176 }; | 192 }; |
| 177 | 193 |
| 178 #endif // APPS_MOTERM_MOTERM_MODEL_H_ | 194 #endif // APPS_MOTERM_MOTERM_MODEL_H_ |
| OLD | NEW |