summaryrefslogtreecommitdiffstats
path: root/ui/aura/scoped_window_targeter.cc
blob: d71e9193df9bf39f8cb6f08ad1b26e5ba3ca9eb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/aura/scoped_window_targeter.h"

#include "ui/aura/window.h"

namespace aura {

ScopedWindowTargeter::ScopedWindowTargeter(
    Window* window,
    scoped_ptr<ui::EventTargeter> new_targeter)
    : window_(window),
      old_targeter_(window->SetEventTargeter(new_targeter.Pass())) {
  window_->AddObserver(this);
}

ScopedWindowTargeter::~ScopedWindowTargeter() {
  if (window_) {
    window_->RemoveObserver(this);
    window_->SetEventTargeter(old_targeter_.Pass());
  }
}

void ScopedWindowTargeter::OnWindowDestroyed(Window* window) {
  CHECK_EQ(window_, window);
  window_ = NULL;
  old_targeter_.reset();
}

}  // namespace aura