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 118 119 120 121 122 123 124 125 126 127
|
// Copyright 2014 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 "chrome/browser/extensions/api/virtual_keyboard_private/chrome_virtual_keyboard_delegate.h"
#include "base/command_line.h"
#include "base/metrics/histogram.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/string16.h"
#include "chrome/browser/chromeos/login/lock/screen_locker.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/common/url_constants.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/user_metrics.h"
#include "ui/aura/window_tree_host.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_switches.h"
#include "ui/keyboard/keyboard_util.h"
namespace {
aura::Window* GetKeyboardContainer() {
keyboard::KeyboardController* controller =
keyboard::KeyboardController::GetInstance();
return controller ? controller->GetContainerWindow() : nullptr;
}
} // namespace
namespace extensions {
bool ChromeVirtualKeyboardDelegate::GetKeyboardConfig(
base::DictionaryValue* results) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
results->SetString("layout", keyboard::GetKeyboardLayout());
results->SetBoolean("a11ymode", keyboard::GetAccessibilityKeyboardEnabled());
results->SetBoolean("experimental",
keyboard::IsExperimentalInputViewEnabled());
return true;
}
bool ChromeVirtualKeyboardDelegate::HideKeyboard() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
keyboard::KeyboardController* controller =
keyboard::KeyboardController::GetInstance();
if (!controller)
return false;
UMA_HISTOGRAM_ENUMERATION("VirtualKeyboard.KeyboardControlEvent",
keyboard::KEYBOARD_CONTROL_HIDE_USER,
keyboard::KEYBOARD_CONTROL_MAX);
// Pass HIDE_REASON_MANUAL since calls to HideKeyboard as part of this API
// would be user generated.
controller->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL);
return true;
}
bool ChromeVirtualKeyboardDelegate::InsertText(const base::string16& text) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
return keyboard::InsertText(text);
}
bool ChromeVirtualKeyboardDelegate::OnKeyboardLoaded() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
keyboard::MarkKeyboardLoadFinished();
base::UserMetricsAction("VirtualKeyboardLoaded");
return true;
}
bool ChromeVirtualKeyboardDelegate::LockKeyboard(bool state) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
keyboard::KeyboardController* controller =
keyboard::KeyboardController::GetInstance();
if (!controller)
return false;
keyboard::KeyboardController::GetInstance()->set_lock_keyboard(state);
return true;
}
bool ChromeVirtualKeyboardDelegate::MoveCursor(int swipe_direction,
int modifier_flags) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
keyboard::switches::kEnableSwipeSelection)) {
return false;
}
aura::Window* window = GetKeyboardContainer();
return window && keyboard::MoveCursor(
swipe_direction, modifier_flags, window->GetHost());
}
bool ChromeVirtualKeyboardDelegate::SendKeyEvent(const std::string& type,
int char_value,
int key_code,
const std::string& key_name,
int modifiers) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
aura::Window* window = GetKeyboardContainer();
return window && keyboard::SendKeyEvent(type,
char_value,
key_code,
key_name,
modifiers,
window->GetHost());
}
bool ChromeVirtualKeyboardDelegate::ShowLanguageSettings() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::RecordAction(base::UserMetricsAction("OpenLanguageOptionsDialog"));
chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(),
chrome::kLanguageOptionsSubPage);
return true;
}
bool ChromeVirtualKeyboardDelegate::IsLanguageSettingsEnabled() {
return (user_manager::UserManager::Get()->IsUserLoggedIn() &&
!chromeos::UserAddingScreen::Get()->IsRunning() &&
!(chromeos::ScreenLocker::default_screen_locker() &&
chromeos::ScreenLocker::default_screen_locker()->locked()));
}
} // namespace extensions
|