| OLD | NEW |
| (Empty) | |
| 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/wm/window_manager_extension.h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ui/aura/client/activation_client.h" |
| 9 #include "ui/aura/env.h" |
| 10 #include "ui/aura/window.h" |
| 11 |
| 12 namespace ash { |
| 13 namespace internal { |
| 14 |
| 15 //////////////////////////////////////////////////////////////////////////////// |
| 16 // WindowManagerExtension, public: |
| 17 |
| 18 WindowManagerExtension::WindowManagerExtension() |
| 19 : delegate_(NULL) { |
| 20 aura::Env::GetInstance()->AddObserver(this); |
| 21 aura::client::GetActivationClient( |
| 22 Shell::GetPrimaryRootWindow())->AddObserver(this); |
| 23 } |
| 24 |
| 25 WindowManagerExtension::~WindowManagerExtension() { |
| 26 aura::client::GetActivationClient( |
| 27 Shell::GetPrimaryRootWindow())->RemoveObserver(this); |
| 28 aura::Env::GetInstance()->RemoveObserver(this); |
| 29 for (size_t i = 0; i < windows_.size(); ++i) |
| 30 windows_[i]->RemoveObserver(this); |
| 31 } |
| 32 |
| 33 //////////////////////////////////////////////////////////////////////////////// |
| 34 // WindowManagerExtension, aura::EnvObserver implementation: |
| 35 |
| 36 void WindowManagerExtension::OnWindowInitialized(aura::Window* window) { |
| 37 windows_.push_back(window); |
| 38 window->AddObserver(this); |
| 39 |
| 40 if (delegate_) |
| 41 delegate_->OnWindowCreated(window); |
| 42 } |
| 43 |
| 44 //////////////////////////////////////////////////////////////////////////////// |
| 45 // WindowManagerExtension, aura::WindowObserver implementation: |
| 46 |
| 47 void WindowManagerExtension::OnWindowVisibilityChanged( |
| 48 aura::Window* window, |
| 49 bool visible) { |
| 50 if (delegate_) { |
| 51 if (visible) |
| 52 delegate_->OnWindowShown(window); |
| 53 else |
| 54 delegate_->OnWindowHidden(window); |
| 55 } |
| 56 } |
| 57 |
| 58 void WindowManagerExtension::OnWindowDestroyed(aura::Window* window) { |
| 59 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); |
| 60 window->RemoveObserver(this); |
| 61 |
| 62 if (delegate_) |
| 63 delegate_->OnWindowClosed(window); |
| 64 } |
| 65 |
| 66 //////////////////////////////////////////////////////////////////////////////// |
| 67 // WindowManagerExtension, aura::WindowObserver implementation: |
| 68 |
| 69 void WindowManagerExtension::OnWindowActivated(aura::Window* active, |
| 70 aura::Window* old_active) { |
| 71 if (delegate_) |
| 72 delegate_->OnActiveWindowChanged(active); |
| 73 } |
| 74 |
| 75 } // namespace internal |
| 76 } // namespace ash |
| OLD | NEW |