| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/apps/desktop_keyboard_capture.h" | |
| 6 #include "chrome/browser/ui/views/apps/keyboard_hook_handler.h" | |
| 7 | |
| 8 DesktopKeyboardCapture::DesktopKeyboardCapture(views::Widget* widget) | |
| 9 : widget_(widget), is_registered_(false) { | |
| 10 widget_->AddObserver(this); | |
| 11 | |
| 12 if (widget_->IsActive()) | |
| 13 RegisterKeyboardHooks(); | |
| 14 } | |
| 15 | |
| 16 DesktopKeyboardCapture::~DesktopKeyboardCapture() { | |
| 17 if (is_registered_) | |
| 18 DeregisterKeyboardHooks(); | |
| 19 | |
| 20 widget_->RemoveObserver(this); | |
| 21 } | |
| 22 | |
| 23 void DesktopKeyboardCapture::RegisterKeyboardHooks() { | |
| 24 KeyboardHookHandler::GetInstance()->Register(widget_); | |
| 25 is_registered_ = true; | |
| 26 } | |
| 27 | |
| 28 void DesktopKeyboardCapture::DeregisterKeyboardHooks() { | |
| 29 KeyboardHookHandler::GetInstance()->Deregister(widget_); | |
| 30 is_registered_ = false; | |
| 31 } | |
| 32 | |
| 33 void DesktopKeyboardCapture::OnWidgetActivationChanged(views::Widget* widget, | |
| 34 bool active) { | |
| 35 if (active) { | |
| 36 RegisterKeyboardHooks(); | |
| 37 } else { | |
| 38 DeregisterKeyboardHooks(); | |
| 39 } | |
| 40 } | |
| OLD | NEW |