test_activation_delegate.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/test_activation_delegate.h"
  5. #include "ash/wm/window_util.h"
  6. #include "ui/aura/client/aura_constants.h"
  7. #include "ui/aura/window.h"
  8. #include "ui/events/event.h"
  9. namespace ash {
  10. TestActivationDelegate::TestActivationDelegate()
  11. : window_(NULL),
  12. window_was_active_(false),
  13. activate_(true),
  14. activated_count_(0),
  15. lost_active_count_(0),
  16. should_activate_count_(0) {}
  17. TestActivationDelegate::TestActivationDelegate(bool activate)
  18. : window_(NULL),
  19. window_was_active_(false),
  20. activate_(activate),
  21. activated_count_(0),
  22. lost_active_count_(0),
  23. should_activate_count_(0) {}
  24. void TestActivationDelegate::SetWindow(aura::Window* window) {
  25. window_ = window;
  26. ::wm::SetActivationDelegate(window, this);
  27. ::wm::SetActivationChangeObserver(window, this);
  28. }
  29. bool TestActivationDelegate::ShouldActivate() const {
  30. should_activate_count_++;
  31. return activate_;
  32. }
  33. void TestActivationDelegate::OnWindowActivated(
  34. ::wm::ActivationChangeObserver::ActivationReason reason,
  35. aura::Window* gained_active,
  36. aura::Window* lost_active) {
  37. DCHECK(window_ == gained_active || window_ == lost_active);
  38. if (window_ == gained_active) {
  39. activated_count_++;
  40. } else if (window_ == lost_active) {
  41. if (lost_active_count_++ == 0)
  42. window_was_active_ = wm::IsActiveWindow(window_);
  43. }
  44. }
  45. } // namespace ash