#include "ash/keyboard/ui/keyboard_layout_manager.h"
#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "base/trace_event/trace_event.h"
#include "ui/compositor/layer_animator.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
namespace keyboard {
KeyboardLayoutManager::KeyboardLayoutManager(KeyboardUIController* controller)
: controller_(controller) {}
KeyboardLayoutManager::~KeyboardLayoutManager() = default;
void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
SetChildBounds(child, child->GetBoundsInRootWindow());
}
void KeyboardLayoutManager::SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) {
aura::Window* contents_window = controller_->GetKeyboardWindow();
if (contents_window != child) {
if (child->bounds() != requested_bounds)
SetChildBoundsDirect(child, requested_bounds);
return;
}
TRACE_EVENT0("vk", "KeyboardLayoutSetChildBounds");
aura::Window* root_window = controller_->GetRootWindow();
if (!root_window)
return;
DisplayUtil display_util;
const display::Display& display =
display_util.GetNearestDisplayToWindow(root_window);
const gfx::Vector2d display_offset =
display.bounds().origin().OffsetFromOrigin();
const gfx::Rect new_bounds =
controller_->AdjustSetBoundsRequest(display.bounds(),
requested_bounds + display_offset) -
display_offset;
gfx::Rect old_bounds = contents_window->GetTargetBounds();
if (new_bounds == old_bounds)
return;
SetChildBoundsDirect(contents_window, new_bounds);
}
}