Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / views / apps / desktop_keyboard_capture.cc
blob578b1daf25c197fec719ff782ffbe1d45eca0731
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() {
17 if (is_registered_)
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,
34 bool active) {
35 if (active) {
36 RegisterKeyboardHooks();
37 } else {
38 DeregisterKeyboardHooks();