| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef ASH_COMMON_SHELF_SHELF_WINDOW_WATCHER_H_ | |
| 6 #define ASH_COMMON_SHELF_SHELF_WINDOW_WATCHER_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/scoped_observer.h" | |
| 12 #include "ui/aura/window_observer.h" | |
| 13 #include "ui/display/display_observer.h" | |
| 14 #include "ui/wm/public/activation_change_observer.h" | |
| 15 | |
| 16 namespace ash { | |
| 17 | |
| 18 class ShelfModel; | |
| 19 | |
| 20 // ShelfWindowWatcher creates and handles a ShelfItem for windows in the default | |
| 21 // container and panels in the panel container that have a valid ShelfItemType | |
| 22 // property (e.g. the task manager dialog or the OS settings window). It adds | |
| 23 // the ShelfItem when the window is added to the default container and maintains | |
| 24 // it until the window is closed, even if the window is transiently reparented | |
| 25 // (e.g. during a drag). | |
| 26 class ShelfWindowWatcher : public aura::client::ActivationChangeObserver, | |
| 27 public display::DisplayObserver { | |
| 28 public: | |
| 29 explicit ShelfWindowWatcher(ShelfModel* model); | |
| 30 ~ShelfWindowWatcher() override; | |
| 31 | |
| 32 private: | |
| 33 // Observes for windows being added to a root window's default container. | |
| 34 class ContainerWindowObserver : public aura::WindowObserver { | |
| 35 public: | |
| 36 explicit ContainerWindowObserver(ShelfWindowWatcher* window_watcher); | |
| 37 ~ContainerWindowObserver() override; | |
| 38 | |
| 39 private: | |
| 40 // aura::WindowObserver: | |
| 41 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override; | |
| 42 void OnWindowDestroying(aura::Window* window) override; | |
| 43 | |
| 44 ShelfWindowWatcher* window_watcher_; | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(ContainerWindowObserver); | |
| 47 }; | |
| 48 | |
| 49 // Observes individual user windows to detect when they are closed or when | |
| 50 // their shelf item properties have changed. | |
| 51 class UserWindowObserver : public aura::WindowObserver { | |
| 52 public: | |
| 53 explicit UserWindowObserver(ShelfWindowWatcher* window_watcher); | |
| 54 ~UserWindowObserver() override; | |
| 55 | |
| 56 private: | |
| 57 // aura::WindowObserver: | |
| 58 void OnWindowPropertyChanged(aura::Window* window, | |
| 59 const void* key, | |
| 60 intptr_t old) override; | |
| 61 void OnWindowDestroying(aura::Window* window) override; | |
| 62 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override; | |
| 63 void OnWindowTitleChanged(aura::Window* window) override; | |
| 64 | |
| 65 ShelfWindowWatcher* window_watcher_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(UserWindowObserver); | |
| 68 }; | |
| 69 | |
| 70 // Creates a ShelfItem for |window|. | |
| 71 void AddShelfItem(aura::Window* window); | |
| 72 | |
| 73 // Removes a ShelfItem for |window|. | |
| 74 void RemoveShelfItem(aura::Window* window); | |
| 75 | |
| 76 // Returns the index of ShelfItem associated with |window|, or -1 if none. | |
| 77 int GetShelfItemIndexForWindow(aura::Window* window) const; | |
| 78 | |
| 79 // Cleans up observers on |container|. | |
| 80 void OnContainerWindowDestroying(aura::Window* container); | |
| 81 | |
| 82 // Adds a shelf item for new windows added to the default container that have | |
| 83 // a valid ShelfItemType property value. | |
| 84 void OnUserWindowAdded(aura::Window* window); | |
| 85 | |
| 86 // Adds, updates or removes the shelf item based on a property change. | |
| 87 void OnUserWindowPropertyChanged(aura::Window* window); | |
| 88 | |
| 89 // Removes the shelf item when a window closes. | |
| 90 void OnUserWindowDestroying(aura::Window* window); | |
| 91 | |
| 92 // aura::client::ActivationChangeObserver: | |
| 93 void OnWindowActivated(ActivationReason reason, | |
| 94 aura::Window* gained_active, | |
| 95 aura::Window* lost_active) override; | |
| 96 | |
| 97 // display::DisplayObserver overrides: | |
| 98 void OnDisplayAdded(const display::Display& display) override; | |
| 99 void OnDisplayRemoved(const display::Display& old_display) override; | |
| 100 void OnDisplayMetricsChanged(const display::Display& display, | |
| 101 uint32_t metrics) override; | |
| 102 | |
| 103 ShelfModel* model_; | |
| 104 | |
| 105 ContainerWindowObserver container_window_observer_; | |
| 106 UserWindowObserver user_window_observer_; | |
| 107 | |
| 108 ScopedObserver<aura::Window, ContainerWindowObserver> | |
| 109 observed_container_windows_; | |
| 110 ScopedObserver<aura::Window, UserWindowObserver> observed_user_windows_; | |
| 111 | |
| 112 // The set of windows with shelf items managed by this ShelfWindowWatcher. | |
| 113 std::set<aura::Window*> user_windows_with_items_; | |
| 114 | |
| 115 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcher); | |
| 116 }; | |
| 117 | |
| 118 } // namespace ash | |
| 119 | |
| 120 #endif // ASH_COMMON_SHELF_SHELF_WINDOW_WATCHER_H_ | |
| OLD | NEW |