blob: 58bcb0b0a17e038a02d36436a7a31f2ca473f2ee [file] [log] [blame]
// Copyright 2017 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 "ui/aura/window.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/geometry/point.h"
#include "ui/keyboard/container_behavior.h"
#include "ui/keyboard/container_type.h"
#include "ui/keyboard/drag_descriptor.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_export.h"
#include "ui/wm/core/window_animations.h"
namespace keyboard {
// Margins from the bottom right corner of the screen for the default location
// of the keyboard.
constexpr int kDefaultDistanceFromScreenBottom = 20;
constexpr int kDefaultDistanceFromScreenRight = 20;
class KEYBOARD_EXPORT ContainerFloatingBehavior : public ContainerBehavior {
ContainerFloatingBehavior(KeyboardController* controller);
~ContainerFloatingBehavior() override;
// ContainerBehavior overrides
void DoHidingAnimation(
aura::Window* window,
::wm::ScopedHidingAnimationSettings* animation_settings) override;
void DoShowingAnimation(
aura::Window* window,
ui::ScopedLayerAnimationSettings* animation_settings) override;
void InitializeShowAnimationStartingState(aura::Window* container) override;
const gfx::Rect AdjustSetBoundsRequest(
const gfx::Rect& display_bounds,
const gfx::Rect& requested_bounds) override;
bool IsOverscrollAllowed() const override;
bool IsDragHandle(const gfx::Vector2d& offset,
const gfx::Size& keyboard_size) const override;
void SavePosition(const gfx::Point& position) override;
void HandlePointerEvent(bool isMouseButtonPressed,
const gfx::Vector2d& kb_offset) override;
void SetCanonicalBounds(aura::Window* container,
const gfx::Rect& display_bounds) override;
ContainerType GetType() const override;
bool TextBlurHidesKeyboard() const override;
bool BoundsObscureUsableRegion() const override;
bool BoundsAffectWorkspaceLayout() const override;
// Ensures that the keyboard is neither off the screen nor overlapping an
// edge.
gfx::Rect ContainKeyboardToScreenBounds(
const gfx::Rect& keyboard_bounds,
const gfx::Rect& display_bounds) const;
// Saves the current keyboard location for use the next time it is displayed.
void UpdateLastPoint(const gfx::Point& position);
// Returns true if the keyboard has not been display/moved yet and the default
// position should be used.
bool UseDefaultPosition() const;
// Calculate the position of the keyboard for when it is being shown.
gfx::Point GetPositionForShowingKeyboard(
const gfx::Size& keyboard_size,
const gfx::Rect& display_bounds) const;
KeyboardController* controller_;
// TODO(blakeo): cache the default_position_ on a per-display basis.
gfx::Point default_position_ = gfx::Point(-1, -1);
// Current state of a cursor drag to move the keyboard, if one exists.
// Otherwise nullptr.
std::unique_ptr<DragDescriptor> drag_descriptor_ = nullptr;
} // namespace keyboard