summaryrefslogtreecommitdiffstats
path: root/chromium/ui/keyboard/keyboard_ui.cc
blob: 31708469ae32dd6f67c377defc64573e887c2654 (plain)
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
// Copyright 2015 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/keyboard/keyboard_ui.h"

#include "base/command_line.h"
#include "ui/aura/window.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/ui_base_switches.h"
#include "ui/keyboard/keyboard_controller.h"

namespace keyboard {

KeyboardUI::KeyboardUI() : keyboard_controller_(nullptr) {}
KeyboardUI::~KeyboardUI() {}

void KeyboardUI::ShowKeyboardContainer(aura::Window* container) {
  if (HasContentsWindow()) {
    {
      TRACE_EVENT0("vk", "ShowKeyboardContainerWindow");
      GetContentsWindow()->Show();
    }
    {
      TRACE_EVENT0("vk", "ShowKeyboardContainer");
      container->Show();
    }
  }
}

void KeyboardUI::HideKeyboardContainer(aura::Window* container) {
  if (HasContentsWindow()) {
    container->Hide();
    GetContentsWindow()->Hide();
  }
}

void KeyboardUI::EnsureCaretInWorkArea() {
  if (!GetInputMethod())
    return;

  TRACE_EVENT0("vk", "EnsureCaretInWorkArea");

  const aura::Window* contents_window = GetContentsWindow();
  const gfx::Rect keyboard_bounds_in_screen =
      contents_window->IsVisible() ? contents_window->GetBoundsInScreen()
                                   : gfx::Rect();

  // Use new virtual keyboard behavior only if in non-sticky mode.
  const bool new_vk_behavior = !keyboard_controller_->keyboard_locked();

  if (new_vk_behavior) {
    GetInputMethod()->SetOnScreenKeyboardBounds(keyboard_bounds_in_screen);
  } else if (GetInputMethod()->GetTextInputClient()) {
    GetInputMethod()->GetTextInputClient()->EnsureCaretNotInRect(
        keyboard_bounds_in_screen);
  }
}

void KeyboardUI::SetController(KeyboardController* controller) {
  keyboard_controller_ = controller;
}

}  // namespace keyboard