File: container_floating_behavior.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (117 lines) | stat: -rw-r--r-- 5,000 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_KEYBOARD_UI_CONTAINER_FLOATING_BEHAVIOR_H_
#define ASH_KEYBOARD_UI_CONTAINER_FLOATING_BEHAVIOR_H_

#include <memory>
#include <optional>

#include "ash/keyboard/ui/container_behavior.h"
#include "ash/keyboard/ui/drag_descriptor.h"
#include "ash/keyboard/ui/keyboard_export.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.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 {
 public:
  explicit ContainerFloatingBehavior(Delegate* delegate);
  ~ContainerFloatingBehavior() override;

  // ContainerBehavior overrides
  void DoHidingAnimation(
      aura::Window* container,
      ::wm::ScopedHidingAnimationSettings* animation_settings) override;
  void DoShowingAnimation(
      aura::Window* container,
      ui::ScopedLayerAnimationSettings* animation_settings) override;
  void InitializeShowAnimationStartingState(aura::Window* container) override;
  gfx::Rect AdjustSetBoundsRequest(
      const gfx::Rect& display_bounds,
      const gfx::Rect& requested_bounds_in_screen_coords) override;
  bool IsOverscrollAllowed() const override;
  void SavePosition(const gfx::Rect& keyboard_bounds_in_screen,
                    const gfx::Size& screen_size) override;
  bool HandlePointerEvent(const ui::LocatedEvent& event,
                          const display::Display& current_display) override;
  bool HandleGestureEvent(const ui::GestureEvent& event,
                          const gfx::Rect& bounds_in_screen) override;

  void SetCanonicalBounds(aura::Window* container,
                          const gfx::Rect& display_bounds) override;
  ContainerType GetType() const override;
  bool TextBlurHidesKeyboard() const override;
  gfx::Rect GetOccludedBounds(
      const gfx::Rect& visual_bounds_in_screen) const override;
  bool OccludedBoundsAffectWorkspaceLayout() const override;
  void SetDraggableArea(const gfx::Rect& rect) override;
  void SetAreaToRemainOnScreen(const gfx::Rect& bounds) override;

  // 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;

 private:
  struct KeyboardPosition {
    double left_padding_allotment_ratio;
    double top_padding_allotment_ratio;
  };

  // This returns a new bounds that is guaranteed to be contained within the
  // bounds of the user's display. If the given bounds is contained within
  // the display's bounds then they remain unchanged. If the given bounds are
  // overlapping an edge of the display, or are completely off the display,
  // then the closest valid bounds within the display will be returned.
  gfx::Rect GetBoundsWithinDisplay(const gfx::Rect& bounds,
                                   const gfx::Rect& display_bounds) const;

  // Convert bounds that are relative to the origin of the keyboard window, to
  // bounds that are relative to the origin of the display.
  gfx::Rect ConvertAreaInKeyboardToScreenBounds(
      const gfx::Rect& area_in_keyboard_window,
      const gfx::Rect& keyboard_window_bounds_in_display) const;

  // This returns a new bounds for the keyboard window that is guaranteed to
  // keep the keyboard window on the display. The area of the keyboard window
  // that is guaranteed to remain on the display is either;
  //
  //  1) the area defined by area_in_window_to_remain_on_screen_, or
  //  2) the entire keyboard window bounds.
  //
  // If area_in_window_to_remain_on_screen_ is not defined, then the entire
  // keyboard window bounds are kept on the display. Otherwise the area
  // defined by area_in_window_to_remain_on_screen_ is kept on the display.
  gfx::Rect ContainKeyboardToDisplayBounds(
      const gfx::Rect& keyboard_window_bounds_in_screen,
      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);

  // TODO(blakeo): cache the default_position_ on a per-display basis.
  std::unique_ptr<KeyboardPosition> default_position_in_screen_;

  // Current state of a cursor drag to move the keyboard, if one exists.
  // Otherwise nullptr.
  std::unique_ptr<const DragDescriptor> drag_descriptor_;

  gfx::Rect draggable_area_ = gfx::Rect();

  // The area within the keyboard window that must remain on screen during a
  // drag operation. Note that this is relative to the current keyboard window
  // not the screen.
  std::optional<gfx::Rect> area_in_window_to_remain_on_screen_;
};

}  // namespace keyboard

#endif  // ASH_KEYBOARD_UI_CONTAINER_FLOATING_BEHAVIOR_H_