Commit 70d04c31 authored by sky@chromium.org's avatar sky@chromium.org

Moves transient window observer methods out of WindowObserver

As transient logic has been moved outside of aura it doesn't make
sense for these methods to be in WindowObserver anymore. Instead they
have been added to TransientWindowManager.

BUG=none
TEST=none
R=ben@chromium.org

Review URL: https://codereview.chromium.org/132013004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244176 0039d316-1c4b-4281-b951-d872f2087c98
parent b2e92599
......@@ -23,6 +23,7 @@
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/corewm/transient_window_manager.h"
#include "ui/views/corewm/window_util.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
......@@ -473,7 +474,7 @@ void ImmersiveFullscreenController::AnimationProgressed(
////////////////////////////////////////////////////////////////////////////////
// aura::WindowObserver overrides:
void ImmersiveFullscreenController::OnAddTransientChild(
void ImmersiveFullscreenController::OnTransientChildAdded(
aura::Window* window,
aura::Window* transient) {
views::BubbleDelegateView* bubble_delegate = AsBubbleDelegate(transient);
......@@ -487,7 +488,7 @@ void ImmersiveFullscreenController::OnAddTransientChild(
}
}
void ImmersiveFullscreenController::OnRemoveTransientChild(
void ImmersiveFullscreenController::OnTransientChildRemoved(
aura::Window* window,
aura::Window* transient) {
bubble_manager_->StopObserving(transient);
......@@ -527,14 +528,16 @@ void ImmersiveFullscreenController::EnableWindowObservers(bool enable) {
widget_->AddObserver(this);
focus_manager->AddFocusChangeListener(this);
Shell::GetInstance()->AddPreTargetHandler(this);
native_window_->AddObserver(this);
views::corewm::TransientWindowManager::Get(native_window_)->
AddObserver(this);
RecreateBubbleManager();
} else {
widget_->RemoveObserver(this);
focus_manager->RemoveFocusChangeListener(this);
Shell::GetInstance()->RemovePreTargetHandler(this);
native_window_->RemoveObserver(this);
views::corewm::TransientWindowManager::Get(native_window_)->
RemoveObserver(this);
// We have stopped observing whether transient children are added or removed
// to |native_window_|. The set of bubbles that BubbleManager is observing
......
......@@ -13,6 +13,7 @@
#include "ui/aura/window_observer.h"
#include "ui/events/event_handler.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/views/corewm/transient_window_observer.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/widget/widget_observer.h"
......@@ -40,9 +41,9 @@ namespace ash {
class ASH_EXPORT ImmersiveFullscreenController
: public gfx::AnimationDelegate,
public ui::EventHandler,
public views::corewm::TransientWindowObserver,
public views::FocusChangeListener,
public views::WidgetObserver,
public aura::WindowObserver,
public ImmersiveRevealedLock::Delegate {
public:
// The enum is used for an enumerated histogram. New items should be only
......@@ -142,11 +143,11 @@ class ASH_EXPORT ImmersiveFullscreenController
virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
// aura::WindowObserver overrides:
virtual void OnAddTransientChild(aura::Window* window,
aura::Window* transient) OVERRIDE;
virtual void OnRemoveTransientChild(aura::Window* window,
aura::Window* transient) OVERRIDE;
// views::corewm::TransientWindowObserver overrides:
virtual void OnTransientChildAdded(aura::Window* window,
aura::Window* transient) OVERRIDE;
virtual void OnTransientChildRemoved(aura::Window* window,
aura::Window* transient) OVERRIDE;
// ash::ImmersiveRevealedLock::Delegate overrides:
virtual void LockRevealedState(AnimateReveal animate_reveal) OVERRIDE;
......
......@@ -38,6 +38,7 @@
#include "ui/base/ui_base_types.h"
#include "ui/events/event.h"
#include "ui/message_center/message_center.h"
#include "ui/views/corewm/transient_window_manager.h"
#include "ui/views/corewm/window_util.h"
namespace {
......@@ -239,9 +240,10 @@ void MultiUserWindowManagerChromeOS::SetWindowOwner(
// Remember the initial visibility of the window.
window_to_entry_[window]->set_show(window->IsVisible());
// Set the window and the state observer.
// Add observers to track state changes.
window->AddObserver(this);
ash::wm::GetWindowState(window)->AddObserver(this);
views::corewm::TransientWindowManager::Get(window)->AddObserver(this);
// Check if this window was created due to a user interaction. If it was,
// transfer it to the current user.
......@@ -440,8 +442,8 @@ void MultiUserWindowManagerChromeOS::OnWindowDestroyed(aura::Window* window) {
RemoveTransientOwnerRecursive(window);
return;
}
// Remove the state and the window observer.
ash::wm::GetWindowState(window)->RemoveObserver(this);
views::corewm::TransientWindowManager::Get(window)->RemoveObserver(this);
// Remove the window from the owners list.
delete window_to_entry_[window];
window_to_entry_.erase(window);
......@@ -489,7 +491,7 @@ void MultiUserWindowManagerChromeOS::OnWindowVisibilityChanged(
SetWindowVisibility(window, false);
}
void MultiUserWindowManagerChromeOS::OnAddTransientChild(
void MultiUserWindowManagerChromeOS::OnTransientChildAdded(
aura::Window* window,
aura::Window* transient_window) {
if (!GetWindowOwner(window).empty()) {
......@@ -504,7 +506,7 @@ void MultiUserWindowManagerChromeOS::OnAddTransientChild(
AddTransientOwnerRecursive(transient_window, owned_parent);
}
void MultiUserWindowManagerChromeOS::OnRemoveTransientChild(
void MultiUserWindowManagerChromeOS::OnTransientChildRemoved(
aura::Window* window,
aura::Window* transient_window) {
// Remove the transient child if the window itself is owned, or one of the
......@@ -632,8 +634,9 @@ void MultiUserWindowManagerChromeOS::AddTransientOwnerRecursive(
transient_window_to_visibility_.end());
transient_window_to_visibility_[window] = window->IsVisible();
// Add a window observer to make sure that we catch status changes.
// Add observers to track state changes.
window->AddObserver(this);
views::corewm::TransientWindowManager::Get(window)->AddObserver(this);
// Hide the window if it should not be shown. Note that this hide operation
// will hide recursively this and all children - but we have already collected
......@@ -656,8 +659,8 @@ void MultiUserWindowManagerChromeOS::RemoveTransientOwnerRecursive(
transient_window_to_visibility_.find(window);
DCHECK(visibility_item != transient_window_to_visibility_.end());
// Remove the window observer.
window->RemoveObserver(this);
views::corewm::TransientWindowManager::Get(window)->RemoveObserver(this);
bool unowned_view_state = visibility_item->second;
transient_window_to_visibility_.erase(visibility_item);
......
......@@ -16,6 +16,7 @@
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/aura/window_observer.h"
#include "ui/views/corewm/transient_window_observer.h"
class Browser;
class MultiUserNotificationBlockerChromeOS;
......@@ -44,11 +45,13 @@ class AppObserver;
// visibility changes from the owning user. This way the visibility can be
// changed back to its requested state upon showing by us - or when the window
// gets detached from its current owning parent.
class MultiUserWindowManagerChromeOS : public MultiUserWindowManager,
public ash::SessionStateObserver,
public aura::WindowObserver,
public content::NotificationObserver,
public ash::wm::WindowStateObserver {
class MultiUserWindowManagerChromeOS
: public MultiUserWindowManager,
public ash::SessionStateObserver,
public ash::wm::WindowStateObserver,
public aura::WindowObserver,
public content::NotificationObserver,
public views::corewm::TransientWindowObserver {
public:
// Create the manager and use |active_user_id| as the active user.
explicit MultiUserWindowManagerChromeOS(const std::string& active_user_id);
......@@ -78,10 +81,12 @@ class MultiUserWindowManagerChromeOS : public MultiUserWindowManager,
bool visible) OVERRIDE;
virtual void OnWindowVisibilityChanged(aura::Window* window,
bool visible) OVERRIDE;
virtual void OnAddTransientChild(aura::Window* window,
aura::Window* transient) OVERRIDE;
virtual void OnRemoveTransientChild(aura::Window* window,
aura::Window* transient) OVERRIDE;
// TransientWindowObserver overrides:
virtual void OnTransientChildAdded(aura::Window* window,
aura::Window* transient) OVERRIDE;
virtual void OnTransientChildRemoved(aura::Window* window,
aura::Window* transient) OVERRIDE;
// Window .. overrides:
virtual void OnWindowShowTypeChanged(
......
......@@ -41,12 +41,6 @@ class Layer;
class Texture;
}
// TODO(sky): nuke. Temporary while moving transients out of Window.
namespace views {
namespace corewm {
class TransientWindowManager;
}
}
namespace aura {
class LayoutManager;
......@@ -369,8 +363,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
private:
friend class test::WindowTestApi;
// TODO(sky): temporary until TransientWindowManager gets its own observer.
friend class views::corewm::TransientWindowManager;
friend class LayoutManager;
friend class RootWindow;
friend class WindowTargeter;
......
......@@ -103,12 +103,6 @@ class AURA_EXPORT WindowObserver {
// Called when a Window is about to be removed from a RootWindow.
virtual void OnWindowRemovingFromRootWindow(Window* window) {}
// Called when a transient child is added to |window|.
virtual void OnAddTransientChild(Window* window, Window* transient) {}
// Called when a transient child is removed from |window|.
virtual void OnRemoveTransientChild(Window* window, Window* transient) {}
protected:
virtual ~WindowObserver() {}
};
......
......@@ -11,6 +11,7 @@
#include "base/stl_util.h"
#include "ui/aura/window.h"
#include "ui/aura/window_property.h"
#include "ui/views/corewm/transient_window_observer.h"
#include "ui/views/corewm/transient_window_stacking_client.h"
#include "ui/views/corewm/window_util.h"
......@@ -40,6 +41,14 @@ const TransientWindowManager* TransientWindowManager::Get(
return window->GetProperty(kPropertyKey);
}
void TransientWindowManager::AddObserver(TransientWindowObserver* observer) {
observers_.AddObserver(observer);
}
void TransientWindowManager::RemoveObserver(TransientWindowObserver* observer) {
observers_.RemoveObserver(observer);
}
void TransientWindowManager::AddTransientChild(Window* child) {
// TransientWindowStackingClient does the stacking of transient windows. If it
// isn't installed stacking is going to be wrong.
......@@ -52,8 +61,8 @@ void TransientWindowManager::AddTransientChild(Window* child) {
child) == transient_children_.end());
transient_children_.push_back(child);
child_manager->transient_parent_ = window_;
FOR_EACH_OBSERVER(WindowObserver, window_->observers_,
OnAddTransientChild(window_, child));
FOR_EACH_OBSERVER(TransientWindowObserver, observers_,
OnTransientChildAdded(window_, child));
}
void TransientWindowManager::RemoveTransientChild(Window* child) {
......@@ -64,8 +73,8 @@ void TransientWindowManager::RemoveTransientChild(Window* child) {
TransientWindowManager* child_manager = Get(child);
DCHECK_EQ(window_, child_manager->transient_parent_);
child_manager->transient_parent_ = NULL;
FOR_EACH_OBSERVER(WindowObserver, window_->observers_,
OnRemoveTransientChild(window_, child));
FOR_EACH_OBSERVER(TransientWindowObserver, observers_,
OnTransientChildRemoved(window_, child));
}
bool TransientWindowManager::IsStackingTransient(
......
......@@ -7,12 +7,15 @@
#include <vector>
#include "base/observer_list.h"
#include "ui/aura/window_observer.h"
#include "ui/views/views_export.h"
namespace views {
namespace corewm {
class TransientWindowObserver;
// TransientWindowManager manages the set of transient children for a window
// along with the transient parent. Transient children get the following
// behavior:
......@@ -37,6 +40,9 @@ class VIEWS_EXPORT TransientWindowManager : public aura::WindowObserver {
// WARNING: this may return NULL.
static const TransientWindowManager* Get(const aura::Window* window);
void AddObserver(TransientWindowObserver* observer);
void RemoveObserver(TransientWindowObserver* observer);
// Adds or removes a transient child.
void AddTransientChild(aura::Window* child);
void RemoveTransientChild(aura::Window* child);
......@@ -87,6 +93,8 @@ class VIEWS_EXPORT TransientWindowManager : public aura::WindowObserver {
// transient ancestor changing. This is a pointer to a value on the stack.
StackingPair* stacking_pair_;
ObserverList<TransientWindowObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(TransientWindowManager);
};
......
......@@ -9,6 +9,7 @@
#include "ui/aura/layout_manager.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/views/corewm/transient_window_observer.h"
#include "ui/views/corewm/window_util.h"
#include "ui/views/test/views_test_base.h"
......@@ -20,6 +21,34 @@ using aura::test::CreateTestWindowWithId;
namespace views {
namespace corewm {
class TestTransientWindowObserver : public TransientWindowObserver {
public:
TestTransientWindowObserver() : add_count_(0), remove_count_(0) {
}
virtual ~TestTransientWindowObserver() {
}
int add_count() const { return add_count_; }
int remove_count() const { return remove_count_; }
// TransientWindowObserver overrides:
virtual void OnTransientChildAdded(Window* window,
Window* transient) OVERRIDE {
add_count_++;
}
virtual void OnTransientChildRemoved(Window* window,
Window* transient) OVERRIDE {
remove_count_++;
}
private:
int add_count_;
int remove_count_;
DISALLOW_COPY_AND_ASSIGN(TestTransientWindowObserver);
};
class TransientWindowManagerTest : public views::ViewsTestBase {
public:
TransientWindowManagerTest() {}
......@@ -573,5 +602,24 @@ TEST_F(TransientWindowManagerTest, StackOverClosingTransient) {
EXPECT_EQ(root->layer()->children()[3], window3->layer());
}
// Verifies TransientWindowObserver is notified appropriately.
TEST_F(TransientWindowManagerTest, TransientWindowObserverNotified) {
scoped_ptr<Window> parent(CreateTestWindowWithId(0, GetContext()));
scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
TestTransientWindowObserver test_observer;
TransientWindowManager::Get(parent.get())->AddObserver(&test_observer);
AddTransientChild(parent.get(), w1.get());
EXPECT_EQ(1, test_observer.add_count());
EXPECT_EQ(0, test_observer.remove_count());
RemoveTransientChild(parent.get(), w1.get());
EXPECT_EQ(1, test_observer.add_count());
EXPECT_EQ(1, test_observer.remove_count());
TransientWindowManager::Get(parent.get())->RemoveObserver(&test_observer);
}
} // namespace corewm
} // namespace views
// Copyright 2014 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.
#ifndef UI_VIEWS_COREWM_TRANSIENT_WINDOW_OBSERVER_H_
#define UI_VIEWS_COREWM_TRANSIENT_WINDOW_OBSERVER_H_
#include "ui/views/views_export.h"
namespace aura {
class Window;
}
namespace views {
namespace corewm {
class VIEWS_EXPORT TransientWindowObserver {
public:
// Called when a transient child is added to |window|.
virtual void OnTransientChildAdded(aura::Window* window,
aura::Window* transient) = 0;
// Called when a transient child is removed from |window|.
virtual void OnTransientChildRemoved(aura::Window* window,
aura::Window* transient) = 0;
protected:
virtual ~TransientWindowObserver() {}
};
} // namespace corewm
} // namespace views
#endif // UI_VIEWS_COREWM_TRANSIENT_WINDOW_OBSERVER_H_
......@@ -267,6 +267,7 @@
'corewm/transient_window_controller.h',
'corewm/transient_window_manager.cc',
'corewm/transient_window_manager.h',
'corewm/transient_window_observer.h',
'corewm/transient_window_stacking_client.cc',
'corewm/transient_window_stacking_client.h',
'corewm/visibility_controller.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment