Skip to content

Commit

Permalink
Floating Keyboard: position heuristic for moving keyboard to new display
Browse files Browse the repository at this point in the history
When dragging the keyboard to a new display, the keyboard should appear
in the part of the display closest to where the keyboard was on the
previous display.

This is implemented by containing the bounds of the keyboard in global
coordinates using the bounds of the new display.

Change-Id: Ie650529fd6bb66da2108b47e8aafab43ddd43856
Reviewed-on: https://chromium-review.googlesource.com/1011484
Commit-Queue: Blake O'Hare <blakeo@chromium.org>
Reviewed-by: Yuichiro Hanada <yhanada@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550933}
  • Loading branch information
Blake O'Hare authored and Commit Bot committed Apr 16, 2018
1 parent 9d31e1c commit 1f02393
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
20 changes: 14 additions & 6 deletions ui/keyboard/container_floating_behavior.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void ContainerFloatingBehavior::HandlePointerEvent(
const gfx::Point new_keyboard_location =
drag_descriptor_->original_keyboard_location() +
cumulative_drag_offset;
gfx::Rect new_bounds =
gfx::Rect new_bounds_in_local =
gfx::Rect(new_keyboard_location, keyboard_bounds.size());

DisplayUtil display_util;
Expand All @@ -254,17 +254,25 @@ void ContainerFloatingBehavior::HandlePointerEvent(
current_display, current_drag_location);

if (current_display.id() == new_display.id()) {
controller_->MoveKeyboard(new_bounds);
controller_->MoveKeyboard(new_bounds_in_local);
} else {
new_bounds =
ContainKeyboardToScreenBounds(new_bounds, new_display.bounds());
// Since the keyboard has jumped across screens, cancel the current
// drag descriptor as though the user has lifted their finger.
drag_descriptor_ = nullptr;

gfx::Rect new_bounds_in_screen =
new_bounds_in_local +
current_display.bounds().origin().OffsetFromOrigin();
gfx::Rect contained_new_bounds_in_screen =
ContainKeyboardToScreenBounds(new_bounds_in_screen,
new_display.bounds());

// Enqueue a transition to the adjacent display.
// TODO(blakeo): pass new_bounds to display transition.
controller_->MoveToDisplayWithTransition(new_display);
new_bounds_in_local =
contained_new_bounds_in_screen -
new_display.bounds().origin().OffsetFromOrigin();
controller_->MoveToDisplayWithTransition(new_display,
new_bounds_in_local);
}
SavePosition(container->bounds(), new_display.size());
}
Expand Down
8 changes: 6 additions & 2 deletions ui/keyboard/keyboard_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,11 @@ void KeyboardController::RemoveObserver(KeyboardControllerObserver* observer) {
observer_list_.RemoveObserver(observer);
}

void KeyboardController::MoveToDisplayWithTransition(display::Display display) {
queued_display_change_ = std::make_unique<QueuedDisplayChange>(display);
void KeyboardController::MoveToDisplayWithTransition(
display::Display display,
gfx::Rect new_bounds_in_local) {
queued_display_change_ =
std::make_unique<QueuedDisplayChange>(display, new_bounds_in_local);
HideKeyboard(HIDE_REASON_AUTOMATIC);
}

Expand Down Expand Up @@ -410,6 +413,7 @@ void KeyboardController::HideAnimationFinished() {

if (queued_display_change_) {
ShowKeyboardInDisplay(queued_display_change_->new_display().id());
container_->SetBounds(queued_display_change_->new_bounds_in_local());
queued_display_change_ = nullptr;
}
}
Expand Down
3 changes: 2 additions & 1 deletion ui/keyboard/keyboard_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
// Sets floating keyboard drggable rect.
bool SetDraggableArea(const gfx::Rect& rect);

void MoveToDisplayWithTransition(display::Display display);
void MoveToDisplayWithTransition(display::Display display,
gfx::Rect new_bounds_in_local);

private:
// For access to Observer methods for simulation.
Expand Down
5 changes: 3 additions & 2 deletions ui/keyboard/queued_display_change.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

namespace keyboard {

QueuedDisplayChange::QueuedDisplayChange(const display::Display& display)
: new_display_(display){};
QueuedDisplayChange::QueuedDisplayChange(const display::Display& display,
const gfx::Rect& new_bounds_in_local)
: new_display_(display), new_bounds_in_local_(new_bounds_in_local){};

QueuedDisplayChange::~QueuedDisplayChange(){};

Expand Down
5 changes: 4 additions & 1 deletion ui/keyboard/queued_display_change.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ namespace keyboard {
// something like QueuedVisualChange or similar.
class QueuedDisplayChange {
public:
QueuedDisplayChange(const display::Display& display_info);
QueuedDisplayChange(const display::Display& display,
const gfx::Rect& new_bounds_in_local);
~QueuedDisplayChange();

display::Display new_display() { return new_display_; }
gfx::Rect new_bounds_in_local() { return new_bounds_in_local_; }

private:
display::Display new_display_;
gfx::Rect new_bounds_in_local_;
};

} // namespace keyboard
Expand Down

0 comments on commit 1f02393

Please sign in to comment.