Commit 2e9ed82a authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

Add SetOccludedBounds extension API.

The occluded bounds is stored in the fullscreen container and retreived to
ensure caret in work area. Also updated the places to notify the correct
occluded bounds for the new container mode.

Bug: 826617
Change-Id: Iafe3dcf291975b586dece39ee6e07bb3f7f49dba
Reviewed-on: https://chromium-review.googlesource.com/1036867
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Reviewed-by: default avatarBlake O'Hare <blakeo@chromium.org>
Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567222}
parent 56bc73a9
...@@ -174,6 +174,19 @@ bool ChromeVirtualKeyboardDelegate::SetVirtualKeyboardMode( ...@@ -174,6 +174,19 @@ bool ChromeVirtualKeyboardDelegate::SetVirtualKeyboardMode(
return true; return true;
} }
bool ChromeVirtualKeyboardDelegate::SetOccludedBounds(
const std::vector<gfx::Rect>& bounds) {
keyboard::KeyboardController* controller =
keyboard::KeyboardController::Get();
if (!controller->enabled())
return false;
// TODO(https://crbug.com/826617): Support occluded bounds with multiple
// rectangles.
controller->SetOccludedBounds(bounds.empty() ? gfx::Rect() : bounds[0]);
return true;
}
keyboard::ContainerType keyboard::ContainerType
ChromeVirtualKeyboardDelegate::ConvertKeyboardModeToContainerType( ChromeVirtualKeyboardDelegate::ConvertKeyboardModeToContainerType(
int mode) const { int mode) const {
......
...@@ -51,6 +51,7 @@ class ChromeVirtualKeyboardDelegate : public VirtualKeyboardDelegate { ...@@ -51,6 +51,7 @@ class ChromeVirtualKeyboardDelegate : public VirtualKeyboardDelegate {
bool SetDraggableArea( bool SetDraggableArea(
const api::virtual_keyboard_private::Bounds& rect) override; const api::virtual_keyboard_private::Bounds& rect) override;
bool SetRequestedKeyboardState(int state_enum) override; bool SetRequestedKeyboardState(int state_enum) override;
bool SetOccludedBounds(const std::vector<gfx::Rect>& bounds) override;
api::virtual_keyboard::FeatureRestrictions RestrictFeatures( api::virtual_keyboard::FeatureRestrictions RestrictFeatures(
const api::virtual_keyboard::RestrictFeatures::Params& params) override; const api::virtual_keyboard::RestrictFeatures::Params& params) override;
......
...@@ -384,11 +384,6 @@ void ChromeKeyboardUI::InitInsets(const gfx::Rect& new_bounds) { ...@@ -384,11 +384,6 @@ void ChromeKeyboardUI::InitInsets(const gfx::Rect& new_bounds) {
gfx::Rect window_bounds = window->GetBoundsInScreen(); gfx::Rect window_bounds = window->GetBoundsInScreen();
gfx::Rect intersect = gfx::IntersectRects(window_bounds, new_bounds); gfx::Rect intersect = gfx::IntersectRects(window_bounds, new_bounds);
int overlap = intersect.height(); int overlap = intersect.height();
// TODO(crbug.com/826617): get the actual obscured height from IME side.
if (keyboard::IsFullscreenHandwritingVirtualKeyboardEnabled())
overlap = 0;
if (overlap > 0 && overlap < window_bounds.height()) if (overlap > 0 && overlap < window_bounds.height())
view->SetInsets(gfx::Insets(0, 0, overlap, 0)); view->SetInsets(gfx::Insets(0, 0, overlap, 0));
else else
......
...@@ -71,7 +71,7 @@ function mockExtensionApis(mockController) { ...@@ -71,7 +71,7 @@ function mockExtensionApis(mockController) {
var virtualKeyboardPrivateMethods = [ var virtualKeyboardPrivateMethods = [
'getKeyboardConfig', 'hideKeyboard', 'insertText', 'lockKeyboard', 'getKeyboardConfig', 'hideKeyboard', 'insertText', 'lockKeyboard',
'moveCursor', 'sendKeyEvent', 'setMode', 'setKeyboardState', 'moveCursor', 'sendKeyEvent', 'setMode', 'setKeyboardState',
'setHotrodKeyboard' 'setOccludedBounds', 'setHotrodKeyboard'
]; ];
var inputMethodPrivateMethods = var inputMethodPrivateMethods =
......
...@@ -662,6 +662,7 @@ source_set("unit_tests") { ...@@ -662,6 +662,7 @@ source_set("unit_tests") {
"api/lock_screen_data/lock_screen_value_store_migrator_impl_unittest.cc", "api/lock_screen_data/lock_screen_value_store_migrator_impl_unittest.cc",
"api/media_perception_private/conversion_utils_unittest.cc", "api/media_perception_private/conversion_utils_unittest.cc",
"api/media_perception_private/media_perception_api_manager_unittest.cc", "api/media_perception_private/media_perception_api_manager_unittest.cc",
"api/virtual_keyboard_private/virtual_keyboard_private_api_unittest.cc",
"api/webcam_private/visca_webcam_unittest.cc", "api/webcam_private/visca_webcam_unittest.cc",
] ]
......
...@@ -91,6 +91,9 @@ class VirtualKeyboardDelegate { ...@@ -91,6 +91,9 @@ class VirtualKeyboardDelegate {
// Sets requested virtual keyboard state. // Sets requested virtual keyboard state.
virtual bool SetRequestedKeyboardState(int state_enum) = 0; virtual bool SetRequestedKeyboardState(int state_enum) = 0;
// Sets the area on the screen that is occluded by the keyboard.
virtual bool SetOccludedBounds(const std::vector<gfx::Rect>& bounds) = 0;
// Restricts the virtual keyboard IME features. // Restricts the virtual keyboard IME features.
// Returns the values which were updated. // Returns the values which were updated.
virtual api::virtual_keyboard::FeatureRestrictions RestrictFeatures( virtual api::virtual_keyboard::FeatureRestrictions RestrictFeatures(
......
...@@ -31,6 +31,10 @@ const char kUnknownError[] = "Unknown error."; ...@@ -31,6 +31,10 @@ const char kUnknownError[] = "Unknown error.";
namespace keyboard = api::virtual_keyboard_private; namespace keyboard = api::virtual_keyboard_private;
gfx::Rect KeyboardBoundsToRect(const keyboard::Bounds& bounds) {
return {bounds.left, bounds.top, bounds.width, bounds.height};
}
} // namespace } // namespace
bool VirtualKeyboardPrivateFunction::PreRunValidation(std::string* error) { bool VirtualKeyboardPrivateFunction::PreRunValidation(std::string* error) {
...@@ -133,11 +137,9 @@ VirtualKeyboardPrivateSetContainerBehaviorFunction::Run() { ...@@ -133,11 +137,9 @@ VirtualKeyboardPrivateSetContainerBehaviorFunction::Run() {
keyboard::SetContainerBehavior::Params::Create(*args_); keyboard::SetContainerBehavior::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
base::Optional<gfx::Rect> target_bounds(base::nullopt); base::Optional<gfx::Rect> target_bounds(base::nullopt);
if (params->options.bounds) { if (params->options.bounds)
target_bounds = gfx::Rect( target_bounds = KeyboardBoundsToRect(*params->options.bounds);
params->options.bounds->top, params->options.bounds->left,
params->options.bounds->width, params->options.bounds->height);
}
if (!delegate()->SetVirtualKeyboardMode( if (!delegate()->SetVirtualKeyboardMode(
params->options.mode, std::move(target_bounds), params->options.mode, std::move(target_bounds),
base::BindOnce(&VirtualKeyboardPrivateSetContainerBehaviorFunction:: base::BindOnce(&VirtualKeyboardPrivateSetContainerBehaviorFunction::
...@@ -172,6 +174,22 @@ VirtualKeyboardPrivateSetKeyboardStateFunction::Run() { ...@@ -172,6 +174,22 @@ VirtualKeyboardPrivateSetKeyboardStateFunction::Run() {
return RespondNow(NoArguments()); return RespondNow(NoArguments());
} }
ExtensionFunction::ResponseAction
VirtualKeyboardPrivateSetOccludedBoundsFunction::Run() {
std::unique_ptr<keyboard::SetOccludedBounds::Params> params =
keyboard::SetOccludedBounds::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
std::vector<gfx::Rect> occluded_bounds;
occluded_bounds.reserve(params->bounds_list.size());
for (const auto& bounds : params->bounds_list)
occluded_bounds.push_back(KeyboardBoundsToRect(bounds));
if (!delegate()->SetOccludedBounds(occluded_bounds))
return RespondNow(Error(kVirtualKeyboardNotEnabled));
return RespondNow(NoArguments());
}
VirtualKeyboardAPI::VirtualKeyboardAPI(content::BrowserContext* context) { VirtualKeyboardAPI::VirtualKeyboardAPI(content::BrowserContext* context) {
delegate_ = delegate_ =
ExtensionsAPIClient::Get()->CreateVirtualKeyboardDelegate(context); ExtensionsAPIClient::Get()->CreateVirtualKeyboardDelegate(context);
......
...@@ -182,6 +182,19 @@ class VirtualKeyboardPrivateSetKeyboardStateFunction ...@@ -182,6 +182,19 @@ class VirtualKeyboardPrivateSetKeyboardStateFunction
ResponseAction Run() override; ResponseAction Run() override;
}; };
class VirtualKeyboardPrivateSetOccludedBoundsFunction
: public VirtualKeyboardPrivateFunction {
public:
DECLARE_EXTENSION_FUNCTION("virtualKeyboardPrivate.setOccludedBounds",
VIRTUALKEYBOARDPRIVATE_SETOCCLUDEDBOUNDS);
protected:
~VirtualKeyboardPrivateSetOccludedBoundsFunction() override {}
// ExtensionFunction:
ResponseAction Run() override;
};
class VirtualKeyboardDelegate; class VirtualKeyboardDelegate;
class VirtualKeyboardAPI : public BrowserContextKeyedAPI { class VirtualKeyboardAPI : public BrowserContextKeyedAPI {
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/browser/api/virtual_keyboard_private/virtual_keyboard_private_api.h"
#include <memory>
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/api/virtual_keyboard_private/virtual_keyboard_delegate.h"
#include "extensions/browser/api_unittest.h"
namespace extensions {
namespace {
class MockVirtualKeyboardDelegate : public VirtualKeyboardDelegate {
public:
MockVirtualKeyboardDelegate() {}
~MockVirtualKeyboardDelegate() override = default;
// VirtualKeyboardDelegate impl:
void GetKeyboardConfig(
OnKeyboardSettingsCallback on_settings_callback) override {}
void OnKeyboardConfigChanged() override {}
bool HideKeyboard() override { return false; }
bool InsertText(const base::string16& text) override { return false; }
bool OnKeyboardLoaded() override { return false; }
void SetHotrodKeyboard(bool enable) override {}
bool LockKeyboard(bool state) override { return false; }
bool SendKeyEvent(const std::string& type,
int char_value,
int key_code,
const std::string& key_name,
int modifiers) override {
return false;
}
bool ShowLanguageSettings() override { return false; }
bool IsLanguageSettingsEnabled() override { return false; }
bool SetVirtualKeyboardMode(int mode_enum,
base::Optional<gfx::Rect> target_bounds,
OnSetModeCallback on_set_mode_callback) override {
return false;
}
bool SetDraggableArea(
const api::virtual_keyboard_private::Bounds& rect) override {
return false;
}
bool SetRequestedKeyboardState(int state_enum) override { return false; }
bool SetOccludedBounds(const std::vector<gfx::Rect>& bounds) override {
occluded_bounds_ = bounds;
return true;
}
const std::vector<gfx::Rect>& GetOccludedBounds() { return occluded_bounds_; }
api::virtual_keyboard::FeatureRestrictions RestrictFeatures(
const api::virtual_keyboard::RestrictFeatures::Params& params) override {
return api::virtual_keyboard::FeatureRestrictions();
}
private:
std::vector<gfx::Rect> occluded_bounds_;
DISALLOW_COPY_AND_ASSIGN(MockVirtualKeyboardDelegate);
};
class TestVirtualKeyboardExtensionsAPIClient : public ExtensionsAPIClient {
public:
TestVirtualKeyboardExtensionsAPIClient() {}
~TestVirtualKeyboardExtensionsAPIClient() override {}
// ExtensionsAPIClient implementation.
std::unique_ptr<VirtualKeyboardDelegate> CreateVirtualKeyboardDelegate(
content::BrowserContext* browser_context) const override {
auto delegate = std::make_unique<MockVirtualKeyboardDelegate>();
delegates_[browser_context] = delegate.get();
return std::move(delegate);
}
MockVirtualKeyboardDelegate* GetDelegateForBrowserContext(
content::BrowserContext* browser_context) const {
return delegates_[browser_context];
}
private:
// Points to the last mock delegate created for each browser context. Does not
// own the delegates.
mutable std::map<content::BrowserContext*, MockVirtualKeyboardDelegate*>
delegates_;
DISALLOW_COPY_AND_ASSIGN(TestVirtualKeyboardExtensionsAPIClient);
};
} // namespace
class VirtualKeyboardPrivateApiUnittest : public ApiUnitTest {
public:
VirtualKeyboardPrivateApiUnittest() {}
~VirtualKeyboardPrivateApiUnittest() override {}
const TestVirtualKeyboardExtensionsAPIClient& client() const {
return extensions_api_client_;
}
protected:
TestVirtualKeyboardExtensionsAPIClient extensions_api_client_;
};
TEST_F(VirtualKeyboardPrivateApiUnittest, SetOccludedBoundsWithNoBounds) {
RunFunction(new VirtualKeyboardPrivateSetOccludedBoundsFunction(), "[[]]");
const auto bounds = client()
.GetDelegateForBrowserContext(browser_context())
->GetOccludedBounds();
EXPECT_EQ(0U, bounds.size());
};
TEST_F(VirtualKeyboardPrivateApiUnittest, SetOccludedBoundsWithOneBound) {
RunFunction(
new VirtualKeyboardPrivateSetOccludedBoundsFunction(),
"[[{ \"left\": 0, \"top\": 10, \"width\": 20, \"height\": 30 }]]");
const auto bounds = client()
.GetDelegateForBrowserContext(browser_context())
->GetOccludedBounds();
ASSERT_EQ(1U, bounds.size());
EXPECT_EQ(gfx::Rect(0, 10, 20, 30), bounds[0]);
};
TEST_F(VirtualKeyboardPrivateApiUnittest, SetOccludedBoundsWithTwoBounds) {
RunFunction(
new VirtualKeyboardPrivateSetOccludedBoundsFunction(),
"[[{ \"left\": 0, \"top\": 10, \"width\": 20, \"height\": 30 }, "
" { \"left\": 10, \"top\": 20, \"width\": 30, \"height\": 40 }]]");
const auto bounds = client()
.GetDelegateForBrowserContext(browser_context())
->GetOccludedBounds();
ASSERT_EQ(2U, bounds.size());
EXPECT_EQ(gfx::Rect(0, 10, 20, 30), bounds[0]);
EXPECT_EQ(gfx::Rect(10, 20, 30, 40), bounds[1]);
};
} // namespace extensions
...@@ -1318,6 +1318,7 @@ enum HistogramValue { ...@@ -1318,6 +1318,7 @@ enum HistogramValue {
MEDIAPERCEPTIONPRIVATE_SETCOMPONENTPROCESSSTATE = 1255, MEDIAPERCEPTIONPRIVATE_SETCOMPONENTPROCESSSTATE = 1255,
USERSPRIVATE_GETCURRENTUSER = 1256, USERSPRIVATE_GETCURRENTUSER = 1256,
WALLPAPERPRIVATE_GETSURPRISEMEIMAGE = 1257, WALLPAPERPRIVATE_GETSURPRISEMEIMAGE = 1257,
VIRTUALKEYBOARDPRIVATE_SETOCCLUDEDBOUNDS = 1258,
// Last entry: Add new entries above, then run: // Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py // python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY ENUM_BOUNDARY
......
...@@ -241,8 +241,23 @@ ...@@ -241,8 +241,23 @@
"description": "The value of the virtual keyboard state to change to." "description": "The value of the virtual keyboard state to change to."
} }
] ]
},
{
"name": "setOccludedBounds",
"type": "function",
"description": "Sets the areas on the screen that are blocked by the virtual keyboard.",
"parameters": [
{
"name": "boundsList",
"type": "array",
"description": "List of rectangles representing regions occluded by the keyboard.",
"items": {
"type": "object",
"$ref": "Bounds"
}
}
]
} }
], ],
"events": [ "events": [
{ {
......
...@@ -77,6 +77,11 @@ bool ShellVirtualKeyboardDelegate::SetRequestedKeyboardState(int state_enum) { ...@@ -77,6 +77,11 @@ bool ShellVirtualKeyboardDelegate::SetRequestedKeyboardState(int state_enum) {
return false; return false;
} }
bool ShellVirtualKeyboardDelegate::SetOccludedBounds(
const std::vector<gfx::Rect>& bounds) {
return false;
}
api::virtual_keyboard::FeatureRestrictions api::virtual_keyboard::FeatureRestrictions
ShellVirtualKeyboardDelegate::RestrictFeatures( ShellVirtualKeyboardDelegate::RestrictFeatures(
const api::virtual_keyboard::RestrictFeatures::Params& params) { const api::virtual_keyboard::RestrictFeatures::Params& params) {
......
...@@ -41,6 +41,7 @@ class ShellVirtualKeyboardDelegate : public VirtualKeyboardDelegate { ...@@ -41,6 +41,7 @@ class ShellVirtualKeyboardDelegate : public VirtualKeyboardDelegate {
bool SetDraggableArea( bool SetDraggableArea(
const api::virtual_keyboard_private::Bounds& rect) override; const api::virtual_keyboard_private::Bounds& rect) override;
bool SetRequestedKeyboardState(int state_enum) override; bool SetRequestedKeyboardState(int state_enum) override;
bool SetOccludedBounds(const std::vector<gfx::Rect>& bounds) override;
api::virtual_keyboard::FeatureRestrictions RestrictFeatures( api::virtual_keyboard::FeatureRestrictions RestrictFeatures(
const api::virtual_keyboard::RestrictFeatures::Params& params) override; const api::virtual_keyboard::RestrictFeatures::Params& params) override;
......
...@@ -15713,6 +15713,7 @@ Called by update_net_error_codes.py.--> ...@@ -15713,6 +15713,7 @@ Called by update_net_error_codes.py.-->
<int value="1255" label="MEDIAPERCEPTIONPRIVATE_SETCOMPONENTPROCESSSTATE"/> <int value="1255" label="MEDIAPERCEPTIONPRIVATE_SETCOMPONENTPROCESSSTATE"/>
<int value="1256" label="USERSPRIVATE_GETCURRENTUSER"/> <int value="1256" label="USERSPRIVATE_GETCURRENTUSER"/>
<int value="1257" label="WALLPAPERPRIVATE_GETSURPRISEMEIMAGE"/> <int value="1257" label="WALLPAPERPRIVATE_GETSURPRISEMEIMAGE"/>
<int value="1258" label="VIRTUALKEYBOARDPRIVATE_SETOCCLUDEDBOUNDS"/>
</enum> </enum>
<enum name="ExtensionIconState"> <enum name="ExtensionIconState">
...@@ -26,13 +26,16 @@ void ContainerFullscreenBehavior::SetCanonicalBounds( ...@@ -26,13 +26,16 @@ void ContainerFullscreenBehavior::SetCanonicalBounds(
gfx::Rect ContainerFullscreenBehavior::GetOccludedBounds( gfx::Rect ContainerFullscreenBehavior::GetOccludedBounds(
const gfx::Rect& visual_bounds_in_screen) const { const gfx::Rect& visual_bounds_in_screen) const {
// TODO(https://crbug.com/826617): Get occluded bounds from IME. return occluded_bounds_;
NOTIMPLEMENTED_LOG_ONCE();
return {};
} }
ContainerType ContainerFullscreenBehavior::GetType() const { ContainerType ContainerFullscreenBehavior::GetType() const {
return ContainerType::FULLSCREEN; return ContainerType::FULLSCREEN;
} }
void ContainerFullscreenBehavior::SetOccludedBounds(
const gfx::Rect& occluded_bounds) {
occluded_bounds_ = occluded_bounds;
}
} // namespace keyboard } // namespace keyboard
...@@ -27,6 +27,14 @@ class KEYBOARD_EXPORT ContainerFullscreenBehavior ...@@ -27,6 +27,14 @@ class KEYBOARD_EXPORT ContainerFullscreenBehavior
ContainerType GetType() const override; ContainerType GetType() const override;
gfx::Rect GetOccludedBounds( gfx::Rect GetOccludedBounds(
const gfx::Rect& visual_bounds_in_screen) const override; const gfx::Rect& visual_bounds_in_screen) const override;
// Sets the occluded bounds that is returned by |GetOccludedBounds|.
void SetOccludedBounds(const gfx::Rect& occluded_bounds);
private:
// The occluded bounds for fullscreen behavior is determined on the IME
// extension side, so it has to be passed here via the extension API.
gfx::Rect occluded_bounds_;
}; };
} // namespace keyboard } // namespace keyboard
......
...@@ -296,13 +296,14 @@ void KeyboardController::NotifyContentsBoundsChanging( ...@@ -296,13 +296,14 @@ void KeyboardController::NotifyContentsBoundsChanging(
const gfx::Rect& new_bounds) { const gfx::Rect& new_bounds) {
visual_bounds_in_screen_ = new_bounds; visual_bounds_in_screen_ = new_bounds;
if (ui_->HasContentsWindow() && ui_->GetContentsWindow()->IsVisible()) { if (ui_->HasContentsWindow() && ui_->GetContentsWindow()->IsVisible()) {
const gfx::Rect occluded_bounds =
container_behavior_->GetOccludedBounds(new_bounds);
notification_manager_.SendNotifications( notification_manager_.SendNotifications(
container_behavior_->GetOccludedBounds(new_bounds),
container_behavior_->OccludedBoundsAffectWorkspaceLayout(), container_behavior_->OccludedBoundsAffectWorkspaceLayout(),
keyboard_locked(), new_bounds, observer_list_); keyboard_locked(), new_bounds, occluded_bounds, observer_list_);
if (keyboard::IsKeyboardOverscrollEnabled()) if (keyboard::IsKeyboardOverscrollEnabled())
ui_->InitInsets(new_bounds); ui_->InitInsets(occluded_bounds);
else else
ui_->ResetInsets(); ui_->ResetInsets();
} else { } else {
...@@ -830,6 +831,18 @@ gfx::Rect KeyboardController::GetKeyboardLockScreenOffsetBounds() const { ...@@ -830,6 +831,18 @@ gfx::Rect KeyboardController::GetKeyboardLockScreenOffsetBounds() const {
return gfx::Rect(); return gfx::Rect();
} }
void KeyboardController::SetOccludedBounds(const gfx::Rect& bounds) {
if (container_behavior_->GetType() != ContainerType::FULLSCREEN)
return;
static_cast<ContainerFullscreenBehavior&>(*container_behavior_)
.SetOccludedBounds(bounds);
// Notify that only the occluded bounds have changed.
if (keyboard_visible())
NotifyContentsBoundsChanging(visual_bounds_in_screen_);
}
gfx::Rect KeyboardController::AdjustSetBoundsRequest( gfx::Rect KeyboardController::AdjustSetBoundsRequest(
const gfx::Rect& display_bounds, const gfx::Rect& display_bounds,
const gfx::Rect& requested_bounds) const { const gfx::Rect& requested_bounds) const {
...@@ -888,7 +901,6 @@ bool KeyboardController::DisplayVirtualKeyboard() { ...@@ -888,7 +901,6 @@ bool KeyboardController::DisplayVirtualKeyboard() {
} }
return false; return false;
} }
void KeyboardController::AddObserver( void KeyboardController::AddObserver(
ui::InputMethodKeyboardControllerObserver* observer) { ui::InputMethodKeyboardControllerObserver* observer) {
// TODO: Implement me // TODO: Implement me
......
...@@ -170,6 +170,9 @@ class KEYBOARD_EXPORT KeyboardController ...@@ -170,6 +170,9 @@ class KEYBOARD_EXPORT KeyboardController
// lock screens. // lock screens.
gfx::Rect GetKeyboardLockScreenOffsetBounds() const; gfx::Rect GetKeyboardLockScreenOffsetBounds() const;
// Set the area on the screen that are occluded by the keyboard.
void SetOccludedBounds(const gfx::Rect& bounds);
KeyboardControllerState GetStateForTest() const { return state_; } KeyboardControllerState GetStateForTest() const { return state_; }
ContainerType GetActiveContainerType() const { ContainerType GetActiveContainerType() const {
......
...@@ -604,6 +604,36 @@ TEST_F(KeyboardControllerTest, CloseKeyboard) { ...@@ -604,6 +604,36 @@ TEST_F(KeyboardControllerTest, CloseKeyboard) {
EXPECT_TRUE(IsKeyboardClosed()); EXPECT_TRUE(IsKeyboardClosed());
} }
TEST_F(KeyboardControllerTest, SetOccludedBoundsChangesFullscreenBounds) {
aura::Window* keyboard_container(controller().GetContainerWindow());
root_window()->AddChild(keyboard_container);
controller().LoadKeyboardUiInBackground();
// Keyboard is hidden, so SetContainerType should be synchronous.
controller().SetContainerType(ContainerType::FULLSCREEN, base::nullopt,
base::DoNothing());
// KeyboardController only notifies occluded bound changes when the keyboard
// is visible.
ShowKeyboard();
const gfx::Rect test_occluded_bounds(0, 10, 20, 30);
// Expect that setting the occluded bounds raises
// OnKeyboardWorkspaceOccludedBoundsChanged event.
struct MockObserver : public KeyboardControllerObserver {
MOCK_METHOD1(OnKeyboardWorkspaceOccludedBoundsChanged,
void(const gfx::Rect& new_bounds));
} observer;
EXPECT_CALL(observer,
OnKeyboardWorkspaceOccludedBoundsChanged(test_occluded_bounds));
controller().AddObserver(&observer);
controller().SetOccludedBounds(test_occluded_bounds);
controller().RemoveObserver(&observer);
}
class KeyboardControllerAnimationTest : public KeyboardControllerTest { class KeyboardControllerAnimationTest : public KeyboardControllerTest {
public: public:
KeyboardControllerAnimationTest() {} KeyboardControllerAnimationTest() {}
......
...@@ -27,23 +27,23 @@ bool ValueNotificationConsolidator<T>::ShouldSendNotification( ...@@ -27,23 +27,23 @@ bool ValueNotificationConsolidator<T>::ShouldSendNotification(
NotificationManager::NotificationManager() {} NotificationManager::NotificationManager() {}
void NotificationManager::SendNotifications( void NotificationManager::SendNotifications(
const gfx::Rect& occluded_bounds,
bool bounds_affect_layout, bool bounds_affect_layout,
bool is_locked, bool is_locked,
const gfx::Rect& bounds, const gfx::Rect& visual_bounds,
const gfx::Rect& occluded_bounds,
const base::ObserverList<KeyboardControllerObserver>& observers) { const base::ObserverList<KeyboardControllerObserver>& observers) {
bool is_available = !bounds.IsEmpty(); bool is_available = !visual_bounds.IsEmpty();
bool send_availability_notification = bool send_availability_notification =
ShouldSendAvailabilityNotification(is_available); ShouldSendAvailabilityNotification(is_available);
bool send_visual_bounds_notification = bool send_visual_bounds_notification =
ShouldSendVisualBoundsNotification(bounds); ShouldSendVisualBoundsNotification(visual_bounds);
bool send_occluded_bounds_notification = bool send_occluded_bounds_notification =
ShouldSendOccludedBoundsNotification(occluded_bounds); ShouldSendOccludedBoundsNotification(occluded_bounds);
const gfx::Rect workspace_layout_offset_region = const gfx::Rect workspace_layout_offset_region =
bounds_affect_layout ? bounds : gfx::Rect(); bounds_affect_layout ? visual_bounds : gfx::Rect();
bool send_displaced_bounds_notification = bool send_displaced_bounds_notification =
ShouldSendWorkspaceDisplacementBoundsNotification( ShouldSendWorkspaceDisplacementBoundsNotification(
workspace_layout_offset_region); workspace_layout_offset_region);
...@@ -51,7 +51,7 @@ void NotificationManager::SendNotifications( ...@@ -51,7 +51,7 @@ void NotificationManager::SendNotifications(
KeyboardStateDescriptor state; KeyboardStateDescriptor state;
state.is_available = is_available; state.is_available = is_available;
state.is_locked = is_locked; state.is_locked = is_locked;
state.visual_bounds = bounds; state.visual_bounds = visual_bounds;
state.occluded_bounds = occluded_bounds; state.occluded_bounds = occluded_bounds;
state.displaced_bounds = workspace_layout_offset_region; state.displaced_bounds = workspace_layout_offset_region;
...@@ -60,7 +60,7 @@ void NotificationManager::SendNotifications( ...@@ -60,7 +60,7 @@ void NotificationManager::SendNotifications(
observer.OnKeyboardAvailabilityChanged(is_available); observer.OnKeyboardAvailabilityChanged(is_available);
if (send_visual_bounds_notification) if (send_visual_bounds_notification)
observer.OnKeyboardVisibleBoundsChanged(bounds); observer.OnKeyboardVisibleBoundsChanged(visual_bounds);
if (send_occluded_bounds_notification) if (send_occluded_bounds_notification)
observer.OnKeyboardWorkspaceOccludedBoundsChanged(occluded_bounds); observer.OnKeyboardWorkspaceOccludedBoundsChanged(occluded_bounds);
......
...@@ -38,10 +38,10 @@ class KEYBOARD_EXPORT NotificationManager { ...@@ -38,10 +38,10 @@ class KEYBOARD_EXPORT NotificationManager {
// - layout displacement bounds change // - layout displacement bounds change
// - general availability change // - general availability change
void SendNotifications( void SendNotifications(
const gfx::Rect& occluded_bounds,
bool bounds_affect_layout, bool bounds_affect_layout,
bool is_locked, bool is_locked,
const gfx::Rect& bounds, const gfx::Rect& visual_bounds,
const gfx::Rect& occluded_bounds,
const base::ObserverList<KeyboardControllerObserver>& observers); const base::ObserverList<KeyboardControllerObserver>& observers);
bool ShouldSendAvailabilityNotification(bool current_availability); bool ShouldSendAvailabilityNotification(bool current_availability);
......
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