forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_method_surface.cc
104 lines (83 loc) · 3.38 KB
/
input_method_surface.cc
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
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/exo/input_method_surface.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "components/exo/input_method_surface_manager.h"
#include "components/exo/wm_helper.h"
#include "ui/base/class_property.h"
#include "ui/gfx/geometry/dip_util.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/views/accessibility/view_accessibility.h"
DEFINE_UI_CLASS_PROPERTY_KEY(exo::InputMethodSurface*,
kInputMethodSurface,
nullptr)
DEFINE_UI_CLASS_PROPERTY_TYPE(exo::InputMethodSurface*)
namespace exo {
InputMethodSurface::InputMethodSurface(InputMethodSurfaceManager* manager,
Surface* surface,
bool default_scale_cancellation)
: ClientControlledShellSurface(
surface,
true /* can_minimize */,
ash::kShellWindowId_ArcVirtualKeyboardContainer,
default_scale_cancellation),
manager_(manager),
input_method_bounds_() {
host_window()->SetName("ExoInputMethodSurface");
host_window()->SetProperty(kInputMethodSurface, this);
}
InputMethodSurface::~InputMethodSurface() {
if (added_to_manager_)
manager_->RemoveSurface(this);
}
exo::InputMethodSurface* InputMethodSurface::GetInputMethodSurface() {
WMHelper* wm_helper = exo::WMHelper::GetInstance();
if (!wm_helper)
return nullptr;
aura::Window* container = wm_helper->GetPrimaryDisplayContainer(
ash::kShellWindowId_ArcVirtualKeyboardContainer);
if (!container)
return nullptr;
// Host window of InputMethodSurface is grandchild of the container.
if (container->children().empty())
return nullptr;
aura::Window* child = container->children().at(0);
if (child->children().empty())
return nullptr;
aura::Window* host_window = child->children().at(0);
return host_window->GetProperty(kInputMethodSurface);
}
void InputMethodSurface::OnSurfaceCommit() {
ClientControlledShellSurface::OnSurfaceCommit();
if (!added_to_manager_) {
added_to_manager_ = true;
manager_->AddSurface(this);
}
gfx::RectF new_bounds_in_dips = gfx::ConvertRectToDips(
root_surface()->hit_test_region().bounds(), GetScale());
// TODO(crbug.com/1131682): We should avoid dropping precision to integers
// here if we want to know the true rectangle bounds in DIPs. If not, we
// should use ToEnclosingRect() if we want to include DIPs that partly overlap
// the physical pixel bounds, or ToEnclosedRect() if we do not.
gfx::Rect int_bounds_in_dips =
gfx::ToFlooredRectDeprecated(new_bounds_in_dips);
if (input_method_bounds_ != int_bounds_in_dips) {
input_method_bounds_ = int_bounds_in_dips;
manager_->OnTouchableBoundsChanged(this);
GetViewAccessibility().OverrideBounds(gfx::RectF(input_method_bounds_));
}
}
void InputMethodSurface::SetWidgetBounds(const gfx::Rect& bounds,
bool adjusted_by_server) {
if (bounds == widget_->GetWindowBoundsInScreen())
return;
widget_->SetBounds(bounds);
UpdateSurfaceBounds();
// Bounds change requests will be ignored in client side.
}
gfx::Rect InputMethodSurface::GetBounds() const {
return input_method_bounds_;
}
} // namespace exo