sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 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 | |||||
Scott Violet | 4c79b0d | 2017-11-17 21:47:13 | [diff] [blame] | 5 | #include "ash/keyboard/keyboard_ui_mash.h" |
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 6 | |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 7 | #include <memory> |
8 | |||||
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 9 | #include "ash/keyboard/keyboard_ui_observer.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 10 | #include "services/service_manager/public/cpp/connector.h" |
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 11 | |
12 | namespace ash { | ||||
13 | |||||
Scott Violet | f5de121f | 2017-11-16 00:43:10 | [diff] [blame] | 14 | KeyboardUIMash::KeyboardUIMash(service_manager::Connector* connector) |
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 15 | : is_enabled_(false), observer_binding_(this) { |
sky | 1340ff2 | 2017-01-20 21:30:53 | [diff] [blame] | 16 | // TODO: chrome should register the keyboard interface with ash. |
17 | // http://crbug.com/683289. | ||||
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 18 | } |
19 | |||||
Chris Watkins | c24daf6 | 2017-11-28 03:43:09 | [diff] [blame^] | 20 | KeyboardUIMash::~KeyboardUIMash() = default; |
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 21 | |
22 | // static | ||||
Scott Violet | f5de121f | 2017-11-16 00:43:10 | [diff] [blame] | 23 | std::unique_ptr<KeyboardUI> KeyboardUIMash::Create( |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 24 | service_manager::Connector* connector) { |
Scott Violet | f5de121f | 2017-11-16 00:43:10 | [diff] [blame] | 25 | return std::make_unique<KeyboardUIMash>(connector); |
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 26 | } |
27 | |||||
Scott Violet | f5de121f | 2017-11-16 00:43:10 | [diff] [blame] | 28 | void KeyboardUIMash::Hide() { |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 29 | if (keyboard_) |
30 | keyboard_->Hide(); | ||||
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 31 | } |
32 | |||||
Scott Violet | f5de121f | 2017-11-16 00:43:10 | [diff] [blame] | 33 | void KeyboardUIMash::ShowInDisplay(const int64_t display_id) { |
yhanada | 7e20c9b | 2016-11-25 00:03:19 | [diff] [blame] | 34 | // TODO(yhanada): Send display id after adding a display_id argument to |
35 | // |Keyboard::Show()| in keyboard.mojom. See crbug.com/585253. | ||||
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 36 | if (keyboard_) |
37 | keyboard_->Show(); | ||||
yhanada | 7e20c9b | 2016-11-25 00:03:19 | [diff] [blame] | 38 | } |
39 | |||||
Scott Violet | f5de121f | 2017-11-16 00:43:10 | [diff] [blame] | 40 | bool KeyboardUIMash::IsEnabled() { |
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 41 | return is_enabled_; |
42 | } | ||||
43 | |||||
Scott Violet | f5de121f | 2017-11-16 00:43:10 | [diff] [blame] | 44 | void KeyboardUIMash::OnKeyboardStateChanged(bool is_enabled, |
45 | bool is_visible, | ||||
46 | uint64_t display_id, | ||||
47 | const gfx::Rect& bounds) { | ||||
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 48 | if (is_enabled_ == is_enabled) |
49 | return; | ||||
50 | |||||
51 | is_enabled_ = is_enabled; | ||||
ericwilligers | 5eff47d | 2016-10-17 19:19:18 | [diff] [blame] | 52 | for (auto& observer : *observers()) |
53 | observer.OnKeyboardEnabledStateChanged(is_enabled); | ||||
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 54 | } |
55 | |||||
56 | } // namespace ash |