Commit c972bfd1 authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Commit Bot

Add new method, virtualKeyboardPrivate.setContainerBehavior().

virtualKeyboardPrivate.setMode() lacks 'bounds' parameter to set the
virtual keyboard bounds after changing mode.
The new method will replace setMode() with an ability to set bounds of
the virtual keyboard container after changing mode.
It's needed to prevent flashing when changing virtual keyboard
mode. We want to change the window bounds before starting showing
animation.

Bug: 776260, 802991
Test: Manual.
Change-Id: Iacf9977d06e05ac4dd3c66175cae7ba87d5fa0c6
Reviewed-on: https://chromium-review.googlesource.com/942281Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Reviewed-by: default avatarToni Barzic <tbarzic@chromium.org>
Reviewed-by: default avatarBlake O'Hare <blakeo@chromium.org>
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543878}
parent 04717d77
......@@ -279,6 +279,7 @@ TEST_F(LockLayoutManagerTest, KeyboardBounds) {
keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE);
keyboard->SetContainerType(keyboard::ContainerType::FLOATING,
base::nullopt /* target_bounds */,
base::BindOnce([](bool success) {}));
ShowKeyboard(true);
primary_display = display::Screen::GetScreen()->GetPrimaryDisplay();
......
......@@ -161,6 +161,7 @@ bool ChromeVirtualKeyboardDelegate::ShowLanguageSettings() {
bool ChromeVirtualKeyboardDelegate::SetVirtualKeyboardMode(
int mode_enum,
base::Optional<gfx::Rect> target_bounds,
OnSetModeCallback on_set_mode_callback) {
keyboard::KeyboardController* controller =
keyboard::KeyboardController::GetInstance();
......@@ -168,6 +169,7 @@ bool ChromeVirtualKeyboardDelegate::SetVirtualKeyboardMode(
return false;
controller->SetContainerType(ConvertKeyboardModeToContainerType(mode_enum),
std::move(target_bounds),
std::move(on_set_mode_callback));
return true;
}
......
......@@ -46,6 +46,7 @@ class ChromeVirtualKeyboardDelegate : public VirtualKeyboardDelegate {
bool ShowLanguageSettings() override;
bool IsLanguageSettingsEnabled() override;
bool SetVirtualKeyboardMode(int mode_enum,
base::Optional<gfx::Rect> target_bounds,
OnSetModeCallback on_set_mode_callback) override;
bool SetDraggableArea(
const api::virtual_keyboard_private::Bounds& rect) override;
......
......@@ -10,11 +10,13 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "base/values.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/common/api/virtual_keyboard.h"
#include "extensions/common/api/virtual_keyboard_private.h"
#include "ui/gfx/geometry/rect.h"
namespace extensions {
......@@ -78,6 +80,7 @@ class VirtualKeyboardDelegate {
// Sets virtual keyboard window mode.
virtual bool SetVirtualKeyboardMode(
int mode_enum,
base::Optional<gfx::Rect> target_bounds,
OnSetModeCallback on_set_mode_callback) = 0;
// Sets virtual keyboard draggable area bounds.
......
......@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/api/virtual_keyboard_private/virtual_keyboard_delegate.h"
......@@ -131,7 +132,7 @@ ExtensionFunction::ResponseAction VirtualKeyboardPrivateSetModeFunction::Run() {
keyboard::SetMode::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
if (!delegate()->SetVirtualKeyboardMode(
params->mode,
params->mode, base::nullopt,
base::BindOnce(&VirtualKeyboardPrivateSetModeFunction::OnSetMode,
this)))
return RespondNow(Error(kVirtualKeyboardNotEnabled));
......@@ -142,6 +143,31 @@ void VirtualKeyboardPrivateSetModeFunction::OnSetMode(bool success) {
Respond(OneArgument(std::make_unique<base::Value>(success)));
}
ExtensionFunction::ResponseAction
VirtualKeyboardPrivateSetContainerBehaviorFunction::Run() {
std::unique_ptr<keyboard::SetContainerBehavior::Params> params =
keyboard::SetContainerBehavior::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
base::Optional<gfx::Rect> target_bounds(base::nullopt);
if (params->options.bounds) {
target_bounds = gfx::Rect(
params->options.bounds->top, params->options.bounds->left,
params->options.bounds->width, params->options.bounds->height);
}
if (!delegate()->SetVirtualKeyboardMode(
params->options.mode, std::move(target_bounds),
base::BindOnce(&VirtualKeyboardPrivateSetContainerBehaviorFunction::
OnSetContainerBehavior,
this)))
return RespondNow(Error(kVirtualKeyboardNotEnabled));
return RespondLater();
}
void VirtualKeyboardPrivateSetContainerBehaviorFunction::OnSetContainerBehavior(
bool success) {
Respond(OneArgument(std::make_unique<base::Value>(success)));
}
ExtensionFunction::ResponseAction
VirtualKeyboardPrivateSetDraggableAreaFunction::Run() {
std::unique_ptr<keyboard::SetDraggableArea::Params> params =
......
......@@ -156,6 +156,22 @@ class VirtualKeyboardPrivateSetModeFunction
void OnSetMode(bool success);
};
class VirtualKeyboardPrivateSetContainerBehaviorFunction
: public VirtualKeyboardPrivateFunction {
public:
DECLARE_EXTENSION_FUNCTION("virtualKeyboardPrivate.setContainerBehavior",
VIRTUALKEYBOARDPRIVATE_SETCONTAINERBEHAVIOR);
protected:
~VirtualKeyboardPrivateSetContainerBehaviorFunction() override = default;
// ExtensionFunction:
ResponseAction Run() override;
private:
void OnSetContainerBehavior(bool success);
};
class VirtualKeyboardPrivateSetDraggableAreaFunction
: public VirtualKeyboardPrivateFunction {
public:
......
......@@ -1287,6 +1287,7 @@ enum HistogramValue {
WALLPAPERPRIVATE_CONFIRMPREVIEWWALLPAPER,
WALLPAPERPRIVATE_CANCELPREVIEWWALLPAPER,
WEBRTCLOGGINGPRIVATE_STARTEVENTLOGGING,
VIRTUALKEYBOARDPRIVATE_SETCONTAINERBEHAVIOR,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
......
......@@ -73,6 +73,22 @@
"description": "List of experimental feature flags."
}
}
},
{
"id": "ContainerBehaviorOptions",
"type": "object",
"properties": {
"mode": {
"$ref": "KeyboardMode",
"name": "mode",
"description": "The value of the virtual keyboard mode to set to."
},
"bounds": {
"$ref": "Bounds",
"description": "The bounds of the virtual keyboard after changing mode",
"optional": true
}
}
}
],
"functions": [
......@@ -200,6 +216,26 @@
"description": "Called when container mode is ready to change.",
"parameters": []
}
],
"deprecated": "Please use $(ref:setContainerBehavior)"
},
{
"name": "setContainerBehavior",
"type": "function",
"description": "Sets the virtual keyboard container behavior",
"parameters": [
{
"$ref": "ContainerBehaviorOptions",
"name": "options",
"description": "Optional parameters for new container behavior."
},
{
"type": "function",
"name": "callback",
"optional": true,
"description": "Called when container mode is ready to chagne.",
"parameters": []
}
]
},
{
......
......@@ -63,6 +63,7 @@ bool ShellVirtualKeyboardDelegate::IsLanguageSettingsEnabled() {
bool ShellVirtualKeyboardDelegate::SetVirtualKeyboardMode(
int mode_enum,
base::Optional<gfx::Rect> target_bounds,
OnSetModeCallback on_set_mode_callback) {
return false;
}
......
......@@ -36,6 +36,7 @@ class ShellVirtualKeyboardDelegate : public VirtualKeyboardDelegate {
bool ShowLanguageSettings() override;
bool IsLanguageSettingsEnabled() override;
bool SetVirtualKeyboardMode(int mode_enum,
base::Optional<gfx::Rect> target_bounds,
OnSetModeCallback on_set_mode_callback) override;
bool SetDraggableArea(
const api::virtual_keyboard_private::Bounds& rect) override;
......
......@@ -14810,6 +14810,7 @@ Called by update_net_error_codes.py.-->
<int value="1224" label="WALLPAPERPRIVATE_CONFIRMPREVIEWWALLPAPER"/>
<int value="1225" label="WALLPAPERPRIVATE_CANCELPREVIEWWALLPAPER"/>
<int value="1226" label="WEBRTCLOGGINGPRIVATE_STARTEVENTLOGGING"/>
<int value="1227" label="VIRTUALKEYBOARDPRIVATE_SETCONTAINERBEHAVIOR"/>
</enum>
<enum name="ExtensionIconState">
......@@ -777,10 +777,12 @@ void KeyboardController::HandlePointerEvent(const ui::LocatedEvent& event) {
event, container_->GetRootWindow()->bounds());
}
void KeyboardController::SetContainerType(
const ContainerType type,
base::Optional<gfx::Rect> target_bounds,
base::OnceCallback<void(bool)> callback) {
// TODO(yhanada): Use target_bounds parameter to change the size of the
// container window.
if (container_behavior_->GetType() == type) {
std::move(callback).Run(false);
return;
......
......@@ -177,6 +177,7 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
// will trigger a hide animation and a subsequent show animation. Otherwise
// the ContainerBehavior change is synchronous.
void SetContainerType(const ContainerType type,
base::Optional<gfx::Rect> target_bounds,
base::OnceCallback<void(bool)> callback);
// Sets floating keyboard drggable rect.
......
......@@ -751,7 +751,7 @@ TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) {
EXPECT_FALSE(notified_is_available());
SetModeCallbackInvocationCounter invocation_counter;
controller()->SetContainerType(ContainerType::FLOATING,
controller()->SetContainerType(ContainerType::FLOATING, base::nullopt,
invocation_counter.GetInvocationCallback());
EXPECT_EQ(1, invocation_counter.invocation_count_for_status(true));
EXPECT_EQ(0, invocation_counter.invocation_count_for_status(false));
......@@ -767,7 +767,7 @@ TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) {
// callback should do nothing when container mode is set to the current active
// container type. An unnecessary call gets registered synchronously as a
// failure status to the callback.
controller()->SetContainerType(ContainerType::FLOATING,
controller()->SetContainerType(ContainerType::FLOATING, base::nullopt,
invocation_counter.GetInvocationCallback());
EXPECT_EQ(1, invocation_counter.invocation_count_for_status(true));
EXPECT_EQ(1, invocation_counter.invocation_count_for_status(false));
......
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