Commit 62b0c8d1 authored by Daniel Nicoara's avatar Daniel Nicoara Committed by Chromium LUCI CQ

webview: client: Add support for SetInsets command

Bug: None
Test: Compiled & ran wayland_webview_client
Change-Id: I928ec220a0406dcb13466c00a4c8072d9f7ee326
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2616832Reviewed-by: default avatarShawn Gallea <sagallea@google.com>
Reviewed-by: default avatarRyan Daum <rdaum@chromium.org>
Commit-Queue: Daniel Nicoara <dnicoara@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842176}
parent fafb9536
......@@ -39,6 +39,7 @@ constexpr char kResizeCommand[] = "resize";
constexpr char kPositionCommand[] = "position";
constexpr char kKeyCommand[] = "key";
constexpr char kFillCommand[] = "fill";
constexpr char kSetInsetsCommand[] = "set_insets";
void FrameCallback(void* data, wl_callback* callback, uint32_t time) {
WebviewClient* webview_client = static_cast<WebviewClient*>(data);
......@@ -356,6 +357,8 @@ void WebviewClient::InputCallback() {
SendKeyRequest(tokens);
else if (tokens[1] == kFillCommand)
HandleFillSurfaceColor(tokens);
else if (tokens[1] == kSetInsetsCommand)
HandleSetInsets(tokens);
std::cout << "Enter command: ";
std::cout.flush();
......@@ -499,6 +502,40 @@ void WebviewClient::HandleFillSurfaceColor(
surfaces_[id]->buffer->sk_surface->getCanvas()->clear(color);
}
void WebviewClient::HandleSetInsets(const std::vector<std::string>& tokens) {
int id, top, left, bottom, right;
if (tokens.size() != 6 || !base::StringToInt(tokens[0], &id) ||
!base::StringToInt(tokens[2], &top) ||
!base::StringToInt(tokens[3], &left) ||
!base::StringToInt(tokens[4], &bottom) ||
!base::StringToInt(tokens[5], &right)) {
LOG(ERROR) << "Usage: [ID] " << kSetInsetsCommand
<< " [top] [left] [bottom] [right]";
return;
}
if (surfaces_.find(id) == surfaces_.end()) {
LOG(ERROR) << "Failed to find surface " << id;
return;
}
Webview* webview = Webview::FromSurface(surfaces_[id].get());
if (!webview) {
LOG(ERROR) << "Failed to find webview " << id;
return;
}
WebviewRequest request;
request.mutable_set_insets()->set_top(top);
request.mutable_set_insets()->set_left(left);
request.mutable_set_insets()->set_bottom(bottom);
request.mutable_set_insets()->set_right(right);
if (!webview->client->Write(request)) {
LOG(ERROR) << "SetInsets failed";
return;
}
}
void WebviewClient::SendResizeRequest(Webview* webview, int width, int height) {
WebviewRequest resize_request;
resize_request.mutable_resize()->set_width(width);
......
......@@ -99,6 +99,7 @@ class WebviewClient : public exo::wayland::clients::ClientBase {
void HandleResizeRequest(const std::vector<std::string>& tokens);
void HandleFillSurfaceColor(const std::vector<std::string>& tokens);
void SendKeyRequest(const std::vector<std::string>& tokens);
void HandleSetInsets(const std::vector<std::string>& tokens);
void SendTouchInput(const Webview* webview,
int x,
......
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