summaryrefslogtreecommitdiff
path: root/chromium/ui/views/view_tracker.cc
blob: 4d2032a8eb146b755d35ade756d76ec2172f6826 (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
33
34
// Copyright 2017 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/views/view_tracker.h"

#include "ui/views/view.h"

namespace views {

ViewTracker::ViewTracker(View* view) : view_(nullptr) {
  SetView(view);
}

ViewTracker::~ViewTracker() {
  SetView(nullptr);
}

void ViewTracker::SetView(View* view) {
  if (view == view_)
    return;

  if (view_)
    view_->RemoveObserver(this);
  view_ = view;
  if (view_)
    view_->AddObserver(this);
}

void ViewTracker::OnViewIsDeleting(View* observed_view) {
  SetView(nullptr);
}

}  // namespace views