Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1233)

Unified Diff: chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc

Issue 2401393003: Add multiline braille support. (Closed)
Patch Set: Addressed review comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc
diff --git a/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc b/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc
index 78e84507d677a81fe3bf0b41b9dcd1ae20590738..a51c76f2c247c9c1dadd56f1ea2f69fff8aee9f3 100644
--- a/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc
+++ b/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc
@@ -87,29 +87,40 @@ std::unique_ptr<DisplayState> BrailleControllerImpl::GetDisplayState() {
StartConnecting();
std::unique_ptr<DisplayState> display_state(new DisplayState);
if (connection_.get() && connection_->Connected()) {
- size_t size;
- if (!connection_->GetDisplaySize(&size)) {
+ unsigned int columns, rows;
+ if (!connection_->GetDisplaySize(&columns, &rows)) {
Disconnect();
- } else if (size > 0) { // size == 0 means no display present.
+ } else if (rows * columns > 0) {
+ // rows * columns == 0 means no display present.
display_state->available = true;
- display_state->text_cell_count.reset(new int(size));
+ display_state->text_column_count.reset(new int(columns));
+ display_state->text_row_count.reset(new int(rows));
}
}
return display_state;
}
-void BrailleControllerImpl::WriteDots(const std::vector<char>& cells) {
+void BrailleControllerImpl::WriteDots(const std::vector<char>& cells,
+ unsigned int cells_cols,
+ unsigned int cells_rows) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (connection_ && connection_->Connected()) {
- size_t size;
- if (!connection_->GetDisplaySize(&size)) {
+ // Row count and column count of current display.
+ unsigned int rows, columns;
+ if (!connection_->GetDisplaySize(&columns, &rows)) {
Disconnect();
}
- std::vector<unsigned char> sizedCells(size);
- std::memcpy(&sizedCells[0], cells.data(), std::min(cells.size(), size));
- if (size > cells.size())
- std::fill(sizedCells.begin() + cells.size(), sizedCells.end(), 0);
- if (!connection_->WriteDots(&sizedCells[0]))
+ std::vector<unsigned char> sized_cells(rows * columns);
+ for (unsigned int i = 0; i < rows; i++) {
+ for (unsigned int j = 0; j < columns; j++) {
+ // If we go out of the bounds of cell's size, pad with 0.
+ sized_cells[i * columns + j] = (i >= cells_rows || j >= cells_cols)
+ ? 0
+ : cells[i * cells_cols + j];
Devlin 2016/10/18 23:01:28 nit: why not init the vector to all zeros (std::ve
ultimatedbz 2016/10/20 18:27:45 That's a great suggestion! As I was thinking about
Devlin 2016/10/21 15:41:39 Ah, didn't realize that cells_rows could be bigger
ultimatedbz 2016/10/25 19:24:41 Looks good. Thanks!
+ }
+ }
+
+ if (!connection_->WriteDots(sized_cells))
Disconnect();
}
}

Powered by Google App Engine
This is Rietveld 408576698