1 // Copyright 2014 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.
5 #include "chrome/browser/ui/views/apps/desktop_keyboard_capture.h"
6 #include "chrome/browser/ui/views/apps/keyboard_hook_handler.h"
8 DesktopKeyboardCapture::DesktopKeyboardCapture(views::Widget
* widget
)
9 : widget_(widget
), is_registered_(false) {
10 widget_
->AddObserver(this);
12 if (widget_
->IsActive())
13 RegisterKeyboardHooks();
16 DesktopKeyboardCapture::~DesktopKeyboardCapture() {
18 DeregisterKeyboardHooks();
20 widget_
->RemoveObserver(this);
23 void DesktopKeyboardCapture::RegisterKeyboardHooks() {
24 KeyboardHookHandler::GetInstance()->Register(widget_
);
25 is_registered_
= true;
28 void DesktopKeyboardCapture::DeregisterKeyboardHooks() {
29 KeyboardHookHandler::GetInstance()->Deregister(widget_
);
30 is_registered_
= false;
33 void DesktopKeyboardCapture::OnWidgetActivationChanged(views::Widget
* widget
,
36 RegisterKeyboardHooks();
38 DeregisterKeyboardHooks();