Commit 4f8542d8 authored by Blake O'Hare's avatar Blake O'Hare Committed by Commit Bot

Add another KeyboardControllerObserver method that aggregates state

This observer method is redundant with the other methods. However it
seems that some of the implementations are querying multiple aspects of
the keyboard and performing an action based on that. For example, the
Arc IME needs to know both changes in availability and the occluded
bounds at the same time. Using the methods currently provided is
unviable because it would require tracking state between the two calls
and then invoking the system call to ARC++ once both calls have
completed. This is cumbersome.

In addition to this, I'd also like to eliminate direct calls to
KeyboardController::GetInstance()->keyboard_locked() and so I am
putting this property into the struct of this notification as well.

There are only a couple of usages where this pattern is necessary and
so most consumers should simply use the more specific existing methods.

Bug: 786290
Change-Id: I3e2db92273f0a144c87caef29b860cb6b7f83995
Reviewed-on: https://chromium-review.googlesource.com/813147Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Commit-Queue: Blake O'Hare <blakeo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522375}
parent f4b4cee4
......@@ -262,8 +262,8 @@ void KeyboardController::NotifyContentsBoundsChanging(
if (ui_->HasContentsWindow() && ui_->GetContentsWindow()->IsVisible()) {
notification_manager_.SendNotifications(
container_behavior_->BoundsObscureUsableRegion(),
container_behavior_->BoundsAffectWorkspaceLayout(), new_bounds,
observer_list_);
container_behavior_->BoundsAffectWorkspaceLayout(), keyboard_locked(),
new_bounds, observer_list_);
if (keyboard::IsKeyboardOverscrollEnabled())
ui_->InitInsets(new_bounds);
......
......@@ -14,6 +14,15 @@ class Rect;
namespace keyboard {
// Describes the various attributes of the keyboard's appearance and usability.
struct KeyboardStateDescriptor {
bool is_available;
bool is_locked;
gfx::Rect visual_bounds;
gfx::Rect occluded_bounds;
gfx::Rect displaced_bounds;
};
// Observers to the KeyboardController are notified of significant events that
// occur with the keyboard, such as the bounds or visiility changing.
class KEYBOARD_EXPORT KeyboardControllerObserver {
......@@ -42,6 +51,12 @@ class KEYBOARD_EXPORT KeyboardControllerObserver {
virtual void OnKeyboardWorkspaceDisplacingBoundsChanging(
const gfx::Rect& new_bounds){};
// Redundant with other various notification methods. Use this if the state of
// multiple properties need to be conveyed simultaneously to observer
// implementations without the need to track multiple stateful properties.
virtual void OnKeyboardAppearanceChanging(
const KeyboardStateDescriptor& state){};
// Called when the keyboard was closed.
virtual void OnKeyboardClosed(){};
......
......@@ -29,6 +29,7 @@ NotificationManager::NotificationManager() {}
void NotificationManager::SendNotifications(
bool bounds_obscure_usable_region,
bool bounds_affect_layout,
bool is_locked,
const gfx::Rect& bounds,
const base::ObserverList<KeyboardControllerObserver>& observers) {
bool is_available = !bounds.IsEmpty();
......@@ -49,6 +50,13 @@ void NotificationManager::SendNotifications(
ShouldSendWorkspaceDisplacementBoundsNotification(
workspace_layout_offset_region);
KeyboardStateDescriptor state;
state.is_available = is_available;
state.is_locked = is_locked;
state.visual_bounds = bounds;
state.occluded_bounds = occluded_region;
state.displaced_bounds = workspace_layout_offset_region;
for (KeyboardControllerObserver& observer : observers) {
if (send_availability_notification)
observer.OnKeyboardAvailabilityChanging(is_available);
......@@ -64,6 +72,8 @@ void NotificationManager::SendNotifications(
workspace_layout_offset_region);
}
observer.OnKeyboardAppearanceChanging(state);
// TODO(blakeo): remove this when all consumers have migrated to one of
// the notifications above.
observer.OnKeyboardBoundsChanging(bounds);
......
......@@ -40,6 +40,7 @@ class KEYBOARD_EXPORT NotificationManager {
void SendNotifications(
bool bounds_obscure_usable_region,
bool bounds_affect_layout,
bool is_locked,
const gfx::Rect& bounds,
const base::ObserverList<KeyboardControllerObserver>& observers);
......
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