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

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

Issue 2401393003: Add multiline braille support. (Closed)
Patch Set: more tests 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 = 0;
91 if (!connection_->GetDisplaySize(&size)) { 91 unsigned int rows = 0;
92 if (!connection_->GetDisplaySize(&columns, &rows)) {
92 Disconnect(); 93 Disconnect();
93 } else if (size > 0) { // size == 0 means no display present. 94 } else if (rows * columns > 0) {
95 // rows * columns == 0 means no display present.
94 display_state->available = true; 96 display_state->available = true;
95 display_state->text_cell_count.reset(new int(size)); 97 display_state->text_column_count.reset(new int(columns));
98 display_state->text_row_count.reset(new int(rows));
96 } 99 }
97 } 100 }
98 return display_state; 101 return display_state;
99 } 102 }
100 103
101 void BrailleControllerImpl::WriteDots(const std::vector<char>& cells) { 104 void BrailleControllerImpl::WriteDots(const std::vector<char>& cells,
105 unsigned int cells_cols,
106 unsigned int cells_rows) {
102 DCHECK_CURRENTLY_ON(BrowserThread::IO); 107 DCHECK_CURRENTLY_ON(BrowserThread::IO);
103 if (connection_ && connection_->Connected()) { 108 if (connection_ && connection_->Connected()) {
104 size_t size; 109 // Row count and column count of current display.
105 if (!connection_->GetDisplaySize(&size)) { 110 unsigned int columns = 0;
111 unsigned int rows = 0;
112 if (!connection_->GetDisplaySize(&columns, &rows)) {
106 Disconnect(); 113 Disconnect();
107 } 114 }
108 std::vector<unsigned char> sizedCells(size); 115 std::vector<unsigned char> sized_cells(rows * columns, 0);
109 std::memcpy(&sizedCells[0], cells.data(), std::min(cells.size(), size)); 116 unsigned int row_limit = std::min(rows, cells_rows);
110 if (size > cells.size()) 117 unsigned int col_limit = std::min(columns, cells_cols);
111 std::fill(sizedCells.begin() + cells.size(), sizedCells.end(), 0); 118 for (unsigned int row = 0; row < row_limit; row++) {
112 if (!connection_->WriteDots(&sizedCells[0])) 119 for (unsigned int col = 0; col < col_limit; col++) {
120 sized_cells[row * columns + col] = cells[row * cells_cols + col];
121 }
122 }
123
124 if (!connection_->WriteDots(sized_cells))
113 Disconnect(); 125 Disconnect();
114 } 126 }
115 } 127 }
116 128
117 void BrailleControllerImpl::AddObserver(BrailleObserver* observer) { 129 void BrailleControllerImpl::AddObserver(BrailleObserver* observer) {
118 DCHECK_CURRENTLY_ON(BrowserThread::UI); 130 DCHECK_CURRENTLY_ON(BrowserThread::UI);
119 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 131 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
120 base::Bind( 132 base::Bind(
121 &BrailleControllerImpl::StartConnecting, 133 &BrailleControllerImpl::StartConnecting,
122 base::Unretained(this)))) { 134 base::Unretained(this)))) {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 331 }
320 return; 332 return;
321 } 333 }
322 for (auto& observer : observers_) 334 for (auto& observer : observers_)
323 observer.OnBrailleDisplayStateChanged(*new_state); 335 observer.OnBrailleDisplayStateChanged(*new_state);
324 } 336 }
325 337
326 } // namespace braille_display_private 338 } // namespace braille_display_private
327 } // namespace api 339 } // namespace api
328 } // namespace extensions 340 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698