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

Side by Side Diff: chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc

Issue 2401393003: Add multiline braille support. (Closed)
Patch Set: Fixed tests and addressed comments Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome/browser/extensions/api/braille_display_private/braille_controll er_brlapi.h" 5 #include "chrome/browser/extensions/api/braille_display_private/braille_controll er_brlapi.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <cerrno> 10 #include <cerrno>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return; 80 return;
81 } 81 }
82 LOG(WARNING) << "Couldn't load libbrlapi: " << strerror(errno); 82 LOG(WARNING) << "Couldn't load libbrlapi: " << strerror(errno);
83 } 83 }
84 84
85 std::unique_ptr<DisplayState> BrailleControllerImpl::GetDisplayState() { 85 std::unique_ptr<DisplayState> BrailleControllerImpl::GetDisplayState() {
86 DCHECK_CURRENTLY_ON(BrowserThread::IO); 86 DCHECK_CURRENTLY_ON(BrowserThread::IO);
87 StartConnecting(); 87 StartConnecting();
88 std::unique_ptr<DisplayState> display_state(new DisplayState); 88 std::unique_ptr<DisplayState> display_state(new DisplayState);
89 if (connection_.get() && connection_->Connected()) { 89 if (connection_.get() && connection_->Connected()) {
90 size_t size; 90 unsigned int columns, rows;
Devlin 2016/10/25 22:36:53 nit: chromium style says one variable per line, in
ultimatedbz 2016/10/27 03:16:58 Done.
91 if (!connection_->GetDisplaySize(&size)) { 91 if (!connection_->GetDisplaySize(&columns, &rows)) {
92 Disconnect(); 92 Disconnect();
93 } else if (size > 0) { // size == 0 means no display present. 93 } else if (rows * columns > 0) {
94 // rows * columns == 0 means no display present.
94 display_state->available = true; 95 display_state->available = true;
95 display_state->text_cell_count.reset(new int(size)); 96 display_state->text_column_count.reset(new int(columns));
97 display_state->text_row_count.reset(new int(rows));
96 } 98 }
97 } 99 }
98 return display_state; 100 return display_state;
99 } 101 }
100 102
101 void BrailleControllerImpl::WriteDots(const std::vector<char>& cells) { 103 void BrailleControllerImpl::WriteDots(const std::vector<char>& cells,
104 unsigned int cells_cols,
105 unsigned int cells_rows) {
102 DCHECK_CURRENTLY_ON(BrowserThread::IO); 106 DCHECK_CURRENTLY_ON(BrowserThread::IO);
103 if (connection_ && connection_->Connected()) { 107 if (connection_ && connection_->Connected()) {
104 size_t size; 108 // Row count and column count of current display.
105 if (!connection_->GetDisplaySize(&size)) { 109 unsigned int rows, columns;
Devlin 2016/10/25 22:36:53 ditto
ultimatedbz 2016/10/27 03:16:58 Done.
110 if (!connection_->GetDisplaySize(&columns, &rows)) {
106 Disconnect(); 111 Disconnect();
107 } 112 }
108 std::vector<unsigned char> sizedCells(size); 113 std::vector<unsigned char> sized_cells(rows * columns, 0);
109 std::memcpy(&sizedCells[0], cells.data(), std::min(cells.size(), size)); 114 unsigned int row_limit = std::min(rows, cells_rows);
110 if (size > cells.size()) 115 unsigned int col_limit = std::min(columns, cells_cols);
111 std::fill(sizedCells.begin() + cells.size(), sizedCells.end(), 0); 116 for (unsigned int row = 0; row < row_limit; row++) {
112 if (!connection_->WriteDots(&sizedCells[0])) 117 for (unsigned int col = 0; col < col_limit; col++) {
118 sized_cells[row * columns + col] = cells[row * cells_cols + col];
119 }
120 }
121
122 if (!connection_->WriteDots(sized_cells))
113 Disconnect(); 123 Disconnect();
114 } 124 }
115 } 125 }
116 126
117 void BrailleControllerImpl::AddObserver(BrailleObserver* observer) { 127 void BrailleControllerImpl::AddObserver(BrailleObserver* observer) {
118 DCHECK_CURRENTLY_ON(BrowserThread::UI); 128 DCHECK_CURRENTLY_ON(BrowserThread::UI);
119 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 129 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
120 base::Bind( 130 base::Bind(
121 &BrailleControllerImpl::StartConnecting, 131 &BrailleControllerImpl::StartConnecting,
122 base::Unretained(this)))) { 132 base::Unretained(this)))) {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 329 }
320 return; 330 return;
321 } 331 }
322 for (auto& observer : observers_) 332 for (auto& observer : observers_)
323 observer.OnBrailleDisplayStateChanged(*new_state); 333 observer.OnBrailleDisplayStateChanged(*new_state);
324 } 334 }
325 335
326 } // namespace braille_display_private 336 } // namespace braille_display_private
327 } // namespace api 337 } // namespace api
328 } // namespace extensions 338 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698