Home | History | Annotate | Download | only in test
      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 
      5 #include "ash/test/test_activation_delegate.h"
      6 
      7 #include "ash/wm/window_util.h"
      8 #include "ui/aura/client/aura_constants.h"
      9 #include "ui/aura/window.h"
     10 #include "ui/base/events/event.h"
     11 
     12 namespace ash {
     13 namespace test {
     14 
     15 ////////////////////////////////////////////////////////////////////////////////
     16 // TestActivationDelegate
     17 
     18 TestActivationDelegate::TestActivationDelegate()
     19     : window_(NULL),
     20       window_was_active_(false),
     21       activate_(true),
     22       activated_count_(0),
     23       lost_active_count_(0),
     24       should_activate_count_(0) {
     25 }
     26 
     27 TestActivationDelegate::TestActivationDelegate(bool activate)
     28     : window_(NULL),
     29       window_was_active_(false),
     30       activate_(activate),
     31       activated_count_(0),
     32       lost_active_count_(0),
     33       should_activate_count_(0) {
     34 }
     35 
     36 void TestActivationDelegate::SetWindow(aura::Window* window) {
     37   window_ = window;
     38   aura::client::SetActivationDelegate(window, this);
     39   aura::client::SetActivationChangeObserver(window, this);
     40 }
     41 
     42 bool TestActivationDelegate::ShouldActivate() const {
     43   should_activate_count_++;
     44   return activate_;
     45 }
     46 
     47 void TestActivationDelegate::OnWindowActivated(aura::Window* gained_active,
     48                                                aura::Window* lost_active) {
     49   DCHECK(window_ == gained_active || window_ == lost_active);
     50   if (window_ == gained_active) {
     51     activated_count_++;
     52   } else if (window_ == lost_active) {
     53     if (lost_active_count_++ == 0)
     54       window_was_active_ = wm::IsActiveWindow(window_);
     55   }
     56 }
     57 
     58 }  // namespace test
     59 }  // namespace ash
     60