Skip to content

Commit

Permalink
chromeos: Make ShelfWindowWatcher a ShellObserver vs DisplayObserver.
Browse files Browse the repository at this point in the history
Follows https://chromium-review.googlesource.com/c/570777
Eliminates the need to check for already-observed root windows.

Bug: None
Test: No cros task-manager, settings, or panel shelf item changes.
Change-Id: I8cf9d79efc44b3a223f99162123ccb4e8a027cd9
Reviewed-on: https://chromium-review.googlesource.com/607351
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Michael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#492865}
  • Loading branch information
Michael Wasserman authored and Commit Bot committed Aug 9, 2017
1 parent 5bb9470 commit 4a00c45
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 36 deletions.
40 changes: 11 additions & 29 deletions ash/shelf/shelf_window_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/wm/public/activation_client.h"

Expand Down Expand Up @@ -168,13 +166,13 @@ ShelfWindowWatcher::ShelfWindowWatcher(ShelfModel* model)
observed_container_windows_(&container_window_observer_),
observed_user_windows_(&user_window_observer_) {
Shell::Get()->activation_client()->AddObserver(this);
for (const auto& display : display::Screen::GetScreen()->GetAllDisplays())
OnDisplayAdded(display);
display::Screen::GetScreen()->AddObserver(this);
Shell::Get()->AddShellObserver(this);
for (aura::Window* window : Shell::GetAllRootWindows())
OnRootWindowAdded(window);
}

ShelfWindowWatcher::~ShelfWindowWatcher() {
display::Screen::GetScreen()->RemoveObserver(this);
Shell::Get()->RemoveShellObserver(this);
Shell::Get()->activation_client()->RemoveObserver(this);
}

Expand Down Expand Up @@ -259,31 +257,15 @@ void ShelfWindowWatcher::OnWindowActivated(ActivationReason reason,
OnUserWindowPropertyChanged(lost_active);
}

void ShelfWindowWatcher::OnDisplayAdded(const display::Display& new_display) {
aura::Window* root = Shell::GetRootWindowForDisplayId(new_display.id());

// When the primary root window's display is removed, the existing root window
// is taken over by the new display, and the observer is already set.
aura::Window* default_container =
root->GetChildById(kShellWindowId_DefaultContainer);
if (!observed_container_windows_.IsObserving(default_container)) {
for (aura::Window* window : default_container->children())
OnUserWindowAdded(window);
observed_container_windows_.Add(default_container);
}
aura::Window* panel_container =
root->GetChildById(kShellWindowId_PanelContainer);
if (!observed_container_windows_.IsObserving(panel_container)) {
for (aura::Window* window : panel_container->children())
void ShelfWindowWatcher::OnRootWindowAdded(aura::Window* root_window) {
constexpr int container_ids[] = {kShellWindowId_DefaultContainer,
kShellWindowId_PanelContainer};
for (const int container_id : container_ids) {
aura::Window* container = root_window->GetChildById(container_id);
for (aura::Window* window : container->children())
OnUserWindowAdded(window);
observed_container_windows_.Add(panel_container);
observed_container_windows_.Add(container);
}
}

void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) {
}

void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&,
uint32_t) {}

} // namespace ash
11 changes: 4 additions & 7 deletions ash/shelf/shelf_window_watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#include <set>

#include "ash/shell_observer.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "ui/aura/window_observer.h"
#include "ui/display/display_observer.h"
#include "ui/wm/public/activation_change_observer.h"

namespace ash {
Expand All @@ -24,7 +24,7 @@ class ShelfModel;
// it until the window is closed, even if the window is transiently reparented
// (e.g. during a drag).
class ShelfWindowWatcher : public ::wm::ActivationChangeObserver,
public display::DisplayObserver {
public ShellObserver {
public:
explicit ShelfWindowWatcher(ShelfModel* model);
~ShelfWindowWatcher() override;
Expand Down Expand Up @@ -91,11 +91,8 @@ class ShelfWindowWatcher : public ::wm::ActivationChangeObserver,
aura::Window* gained_active,
aura::Window* lost_active) override;

// display::DisplayObserver overrides:
void OnDisplayAdded(const display::Display& display) override;
void OnDisplayRemoved(const display::Display& old_display) override;
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t metrics) override;
// ShellObserver:
void OnRootWindowAdded(aura::Window* root_window) override;

ShelfModel* model_;

Expand Down

0 comments on commit 4a00c45

Please sign in to comment.