overlay_event_filter.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2012 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. #include "ash/wm/overlay_event_filter.h"
  5. #include "ui/aura/window.h"
  6. #include "ui/aura/window_delegate.h"
  7. #include "ui/events/event.h"
  8. #include "ui/views/widget/widget.h"
  9. namespace ash {
  10. OverlayEventFilter::OverlayEventFilter() : scoped_session_observer_(this) {}
  11. OverlayEventFilter::~OverlayEventFilter() {
  12. delegate_ = nullptr;
  13. }
  14. void OverlayEventFilter::OnKeyEvent(ui::KeyEvent* event) {
  15. if (!delegate_)
  16. return;
  17. if (delegate_ && delegate_->IsCancelingKeyEvent(event))
  18. Cancel();
  19. // Pass key events only when they are sent to a child of the delegate's
  20. // window.
  21. aura::Window* target = static_cast<aura::Window*>(event->target());
  22. if (!delegate_ || !delegate_->GetWindow() ||
  23. !delegate_->GetWindow()->Contains(target))
  24. event->StopPropagation();
  25. }
  26. void OverlayEventFilter::OnLoginStatusChanged(LoginStatus status) {
  27. Cancel();
  28. }
  29. void OverlayEventFilter::OnChromeTerminating() {
  30. Cancel();
  31. }
  32. void OverlayEventFilter::OnLockStateChanged(bool locked) {
  33. Cancel();
  34. }
  35. void OverlayEventFilter::Activate(Delegate* delegate) {
  36. if (delegate_)
  37. delegate_->Cancel();
  38. delegate_ = delegate;
  39. }
  40. void OverlayEventFilter::Deactivate(Delegate* delegate) {
  41. if (delegate_ == delegate)
  42. delegate_ = nullptr;
  43. }
  44. void OverlayEventFilter::Cancel() {
  45. if (delegate_) {
  46. delegate_->Cancel();
  47. delegate_ = nullptr;
  48. }
  49. }
  50. bool OverlayEventFilter::IsActive() {
  51. return delegate_ != nullptr;
  52. }
  53. } // namespace ash