Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / wm / core / default_activation_client.h
blob894bccff18f3d3c6170f68ad593e0bc0afaa3310
1 // Copyright 2013 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.
5 #ifndef UI_WM_CORE_DEFAULT_ACTIVATION_CLIENT_H_
6 #define UI_WM_CORE_DEFAULT_ACTIVATION_CLIENT_H_
8 #include <vector>
10 #include "base/compiler_specific.h"
11 #include "base/logging.h"
12 #include "base/observer_list.h"
13 #include "ui/aura/window_observer.h"
14 #include "ui/wm/public/activation_change_observer.h"
15 #include "ui/wm/public/activation_client.h"
16 #include "ui/wm/wm_export.h"
18 namespace aura {
19 namespace client {
20 class ActivationChangeObserver;
24 namespace wm {
26 // Simple ActivationClient implementation for use by tests and other targets
27 // that just need basic behavior (e.g. activate windows whenever requested,
28 // restack windows at the top when they're activated, etc.). This object deletes
29 // itself when the root window it is associated with is destroyed.
30 class WM_EXPORT DefaultActivationClient : public aura::client::ActivationClient,
31 public aura::WindowObserver {
32 public:
33 explicit DefaultActivationClient(aura::Window* root_window);
35 // Overridden from aura::client::ActivationClient:
36 void AddObserver(aura::client::ActivationChangeObserver* observer) override;
37 void RemoveObserver(
38 aura::client::ActivationChangeObserver* observer) override;
39 void ActivateWindow(aura::Window* window) override;
40 void DeactivateWindow(aura::Window* window) override;
41 aura::Window* GetActiveWindow() override;
42 aura::Window* GetActivatableWindow(aura::Window* window) override;
43 aura::Window* GetToplevelWindow(aura::Window* window) override;
44 bool CanActivateWindow(aura::Window* window) const override;
46 // Overridden from WindowObserver:
47 void OnWindowDestroyed(aura::Window* window) override;
49 private:
50 class Deleter;
52 ~DefaultActivationClient() override;
53 void RemoveActiveWindow(aura::Window* window);
55 void ActivateWindowImpl(
56 aura::client::ActivationChangeObserver::ActivationReason reason,
57 aura::Window* window);
59 // This class explicitly does NOT store the active window in a window property
60 // to make sure that ActivationChangeObserver is not treated as part of the
61 // aura API. Assumptions to that end will cause tests that use this client to
62 // fail.
63 std::vector<aura::Window*> active_windows_;
65 // The window which was active before the currently active one.
66 aura::Window* last_active_;
68 base::ObserverList<aura::client::ActivationChangeObserver> observers_;
70 DISALLOW_COPY_AND_ASSIGN(DefaultActivationClient);
73 } // namespace wm
75 #endif // UI_WM_CORE_DEFAULT_ACTIVATION_CLIENT_H_