1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ui/events/test/keyboard_layout.h" 6 7 #include "base/check_op.h" 8 #include "base/notreached.h" 9 10 #if defined(USE_OZONE) 11 #include "ui/base/ui_base_features.h" // nogncheck 12 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" // nogncheck 13 #endif 14 15 namespace ui { 16 ScopedKeyboardLayout(KeyboardLayout layout)17ScopedKeyboardLayout::ScopedKeyboardLayout(KeyboardLayout layout) { 18 #if defined(USE_OZONE) 19 if (features::IsUsingOzonePlatform()) { 20 CHECK_EQ(layout, KEYBOARD_LAYOUT_ENGLISH_US); 21 auto keyboard_layout_engine = std::make_unique<StubKeyboardLayoutEngine>(); 22 scoped_keyboard_layout_engine_ = 23 std::make_unique<ScopedKeyboardLayoutEngine>( 24 std::move(keyboard_layout_engine)); 25 } 26 #elif defined(OS_WIN) || defined(OS_MAC) 27 original_layout_ = GetActiveLayout(); 28 ActivateLayout(GetPlatformKeyboardLayout(layout)); 29 #else 30 NOTIMPLEMENTED(); 31 #endif 32 } 33 ~ScopedKeyboardLayout()34ScopedKeyboardLayout::~ScopedKeyboardLayout() { 35 #if defined(OS_WIN) || defined(OS_MAC) 36 ActivateLayout(original_layout_); 37 #endif 38 } 39 40 } // namespace ui 41