Commit df7b4f83 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Plumb through an api to get display cell size from brltty

R=dmazzoni@chromium.org

Test: manual; verify a cell size of 8 on a display, when call chrome.brailleDisplayPrivate.getDisplayState, on a 8-dot celled braille display.
Change-Id: I25a2517e2a6ff29b38746a7ddfb8294669476d9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2194339
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#769511}
parent 9c09335c
...@@ -74,23 +74,17 @@ BrailleControllerImpl::~BrailleControllerImpl() { ...@@ -74,23 +74,17 @@ BrailleControllerImpl::~BrailleControllerImpl() {
void BrailleControllerImpl::TryLoadLibBrlApi() { void BrailleControllerImpl::TryLoadLibBrlApi() {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (libbrlapi_loader_.loaded()) if (skip_libbrlapi_so_load_ || libbrlapi_loader_.loaded())
return; return;
// This list of api versions needs to contain the one used by the // This api version needs to match the one contained in
// corresponding brltty used by Chrome OS for this version of Chrome. For // third_party/libbrlapi/brlapi.h.
// example, in Chrome OS 84, we use brltty 6.1, which is using brlapi 0.8. static const char* const kSupportedVersion = "libbrlapi.so.0.8";
// The relevant header is checked into //third_party/libbrlapi/. Ensure to
// keep this list in descendning order. Note that we keep older versions so if (!libbrlapi_loader_.Load(kSupportedVersion)) {
// that tests will continue to work. LOG(WARNING) << "Couldn't load libbrlapi(" << kSupportedVersion << ": "
static const char* const kSupportedVersions[] = { << strerror(errno);
"libbrlapi.so.0.8", "libbrlapi.so.0.7", "libbrlapi.so.0.6",
"libbrlapi.so.0.5"};
for (size_t i = 0; i < base::size(kSupportedVersions); ++i) {
if (libbrlapi_loader_.Load(kSupportedVersions[i]))
return;
} }
LOG(WARNING) << "Couldn't load libbrlapi: " << strerror(errno);
} }
std::unique_ptr<DisplayState> BrailleControllerImpl::GetDisplayState() { std::unique_ptr<DisplayState> BrailleControllerImpl::GetDisplayState() {
...@@ -107,6 +101,10 @@ std::unique_ptr<DisplayState> BrailleControllerImpl::GetDisplayState() { ...@@ -107,6 +101,10 @@ std::unique_ptr<DisplayState> BrailleControllerImpl::GetDisplayState() {
display_state->available = true; display_state->available = true;
display_state->text_column_count.reset(new int(columns)); display_state->text_column_count.reset(new int(columns));
display_state->text_row_count.reset(new int(rows)); display_state->text_row_count.reset(new int(rows));
unsigned int cell_size = 0;
if (connection_->GetCellSize(&cell_size))
display_state->cell_size.reset(new int(cell_size));
} }
} }
return display_state; return display_state;
...@@ -173,7 +171,7 @@ void BrailleControllerImpl::StartConnecting() { ...@@ -173,7 +171,7 @@ void BrailleControllerImpl::StartConnecting() {
return; return;
started_connecting_ = true; started_connecting_ = true;
TryLoadLibBrlApi(); TryLoadLibBrlApi();
if (!libbrlapi_loader_.loaded()) { if (!libbrlapi_loader_.loaded() && !skip_libbrlapi_so_load_) {
return; return;
} }
...@@ -235,7 +233,7 @@ void BrailleControllerImpl::OnSocketDirChangedOnIOThread() { ...@@ -235,7 +233,7 @@ void BrailleControllerImpl::OnSocketDirChangedOnIOThread() {
void BrailleControllerImpl::TryToConnect() { void BrailleControllerImpl::TryToConnect() {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(libbrlapi_loader_.loaded()); DCHECK(skip_libbrlapi_so_load_ || libbrlapi_loader_.loaded());
connect_scheduled_ = false; connect_scheduled_ = false;
if (!connection_.get()) if (!connection_.get())
connection_ = create_brlapi_connection_function_.Run(); connection_ = create_brlapi_connection_function_.Run();
...@@ -293,7 +291,7 @@ void BrailleControllerImpl::Disconnect() { ...@@ -293,7 +291,7 @@ void BrailleControllerImpl::Disconnect() {
std::unique_ptr<BrlapiConnection> std::unique_ptr<BrlapiConnection>
BrailleControllerImpl::CreateBrlapiConnection() { BrailleControllerImpl::CreateBrlapiConnection() {
DCHECK(libbrlapi_loader_.loaded()); DCHECK(skip_libbrlapi_so_load_ || libbrlapi_loader_.loaded());
return BrlapiConnection::Create(&libbrlapi_loader_); return BrlapiConnection::Create(&libbrlapi_loader_);
} }
......
...@@ -83,6 +83,9 @@ class BrailleControllerImpl : public BrailleController { ...@@ -83,6 +83,9 @@ class BrailleControllerImpl : public BrailleController {
// Manipulated by the SequencedTaskRunner. // Manipulated by the SequencedTaskRunner.
base::FilePathWatcher file_path_watcher_; base::FilePathWatcher file_path_watcher_;
// Set by tests to skip libbrlapi.so loading.
bool skip_libbrlapi_so_load_ = false;
friend struct base::DefaultSingletonTraits<BrailleControllerImpl>; friend struct base::DefaultSingletonTraits<BrailleControllerImpl>;
DISALLOW_COPY_AND_ASSIGN(BrailleControllerImpl); DISALLOW_COPY_AND_ASSIGN(BrailleControllerImpl);
......
...@@ -50,6 +50,7 @@ struct MockBrlapiConnectionData { ...@@ -50,6 +50,7 @@ struct MockBrlapiConnectionData {
bool connected; bool connected;
size_t display_columns; size_t display_columns;
size_t display_rows; size_t display_rows;
size_t cell_size;
brlapi_error_t error; brlapi_error_t error;
std::vector<std::string> written_content; std::vector<std::string> written_content;
// List of brlapi key codes. A negative number makes the connection mock // List of brlapi key codes. A negative number makes the connection mock
...@@ -125,6 +126,11 @@ class MockBrlapiConnection : public BrlapiConnection { ...@@ -125,6 +126,11 @@ class MockBrlapiConnection : public BrlapiConnection {
} }
} }
bool GetCellSize(unsigned int* cell_size) override {
*cell_size = data_->cell_size;
return true;
}
private: private:
void NotifyDataReady() { void NotifyDataReady() {
on_data_ready_.Run(); on_data_ready_.Run();
...@@ -152,6 +158,7 @@ class BrailleDisplayPrivateApiTest : public ExtensionApiTest { ...@@ -152,6 +158,7 @@ class BrailleDisplayPrivateApiTest : public ExtensionApiTest {
base::Bind( base::Bind(
&BrailleDisplayPrivateApiTest::CreateBrlapiConnection, &BrailleDisplayPrivateApiTest::CreateBrlapiConnection,
base::Unretained(this))); base::Unretained(this)));
BrailleControllerImpl::GetInstance()->skip_libbrlapi_so_load_ = true;
DisableAccessibilityManagerBraille(); DisableAccessibilityManagerBraille();
} }
...@@ -259,6 +266,7 @@ IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, KeyEvents) { ...@@ -259,6 +266,7 @@ IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, KeyEvents) {
IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, DisplayStateChanges) { IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, DisplayStateChanges) {
connection_data_.display_columns = 11; connection_data_.display_columns = 11;
connection_data_.display_rows = 1; connection_data_.display_rows = 1;
connection_data_.cell_size = 6;
connection_data_.pending_keys.push_back(kErrorKeyCode); connection_data_.pending_keys.push_back(kErrorKeyCode);
connection_data_.reappear_on_disconnect = true; connection_data_.reappear_on_disconnect = true;
ASSERT_TRUE(RunComponentExtensionTest( ASSERT_TRUE(RunComponentExtensionTest(
......
...@@ -44,6 +44,7 @@ class BrlapiConnectionImpl : public BrlapiConnection { ...@@ -44,6 +44,7 @@ class BrlapiConnectionImpl : public BrlapiConnection {
bool GetDisplaySize(unsigned int* rows, unsigned int* columns) override; bool GetDisplaySize(unsigned int* rows, unsigned int* columns) override;
bool WriteDots(const std::vector<unsigned char>& cells) override; bool WriteDots(const std::vector<unsigned char>& cells) override;
int ReadKey(brlapi_keyCode_t* keyCode) override; int ReadKey(brlapi_keyCode_t* keyCode) override;
bool GetCellSize(unsigned int* cell_size) override;
private: private:
bool CheckConnected(); bool CheckConnected();
...@@ -180,6 +181,23 @@ int BrlapiConnectionImpl::ReadKey(brlapi_keyCode_t* key_code) { ...@@ -180,6 +181,23 @@ int BrlapiConnectionImpl::ReadKey(brlapi_keyCode_t* key_code) {
handle_.get(), 0 /*wait*/, key_code); handle_.get(), 0 /*wait*/, key_code);
} }
bool BrlapiConnectionImpl::GetCellSize(unsigned int* cell_size) {
if (!CheckConnected()) {
return false;
}
brlapi_param_deviceCellSize_t device_cell_size;
ssize_t result = libbrlapi_loader_->brlapi__getParameter(
handle_.get(), BRLAPI_PARAM_DEVICE_CELL_SIZE, 0, BRLAPI_PARAMF_GLOBAL,
&device_cell_size, sizeof(device_cell_size));
if (result == -1 || result != sizeof(device_cell_size))
return false;
*cell_size = device_cell_size;
return true;
}
bool BrlapiConnectionImpl::CheckConnected() { bool BrlapiConnectionImpl::CheckConnected() {
if (!handle_) { if (!handle_) {
BrlapiError()->brlerrno = BRLAPI_ERROR_ILLEGAL_INSTRUCTION; BrlapiError()->brlerrno = BRLAPI_ERROR_ILLEGAL_INSTRUCTION;
......
...@@ -67,6 +67,9 @@ class BrlapiConnection { ...@@ -67,6 +67,9 @@ class BrlapiConnection {
// value. // value.
virtual int ReadKey(brlapi_keyCode_t* keyCode) = 0; virtual int ReadKey(brlapi_keyCode_t* keyCode) = 0;
// Gets the number of dots in a braille cell.
virtual bool GetCellSize(unsigned int* cell_size) = 0;
protected: protected:
BrlapiConnection(); BrlapiConnection();
DISALLOW_COPY_AND_ASSIGN(BrlapiConnection); DISALLOW_COPY_AND_ASSIGN(BrlapiConnection);
......
...@@ -56,6 +56,8 @@ namespace brailleDisplayPrivate { ...@@ -56,6 +56,8 @@ namespace brailleDisplayPrivate {
long? textRowCount; long? textRowCount;
// Number of columns of braille cells on the currently connected display. // Number of columns of braille cells on the currently connected display.
long? textColumnCount; long? textColumnCount;
// The number of dots in a braille cell on the currently connected display.
long? cellSize;
}; };
callback DisplayStateCallback = void(DisplayState result); callback DisplayStateCallback = void(DisplayState result);
......
...@@ -9,9 +9,9 @@ var pass = chrome.test.callbackPass; ...@@ -9,9 +9,9 @@ var pass = chrome.test.callbackPass;
var callbackCompleted; var callbackCompleted;
var EXPECTED_EVENTS = [ var EXPECTED_EVENTS = [
{ "available": true, "textColumnCount": 11, "textRowCount": 1 }, {'available': true, 'textColumnCount': 11, 'textRowCount': 1, cellSize: 6},
{ "available": false }, {'available': false},
{ "available": true, "textColumnCount": 22, "textRowCount": 1 }, {'available': true, 'textColumnCount': 22, 'textRowCount': 1, cellSize: 6},
]; ];
var eventNumber = 0; var eventNumber = 0;
......
...@@ -23,5 +23,6 @@ generate_library_loader("libbrlapi") { ...@@ -23,5 +23,6 @@ generate_library_loader("libbrlapi") {
"brlapi__leaveTtyMode", "brlapi__leaveTtyMode",
"brlapi__writeDots", "brlapi__writeDots",
"brlapi__readKey", "brlapi__readKey",
"brlapi__getParameter",
] ]
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment