Commit 72eb1cf6 authored by ben@chromium.org's avatar ben@chromium.org

Revert 119976 - Adds two new observer methods to allow code to be notified...

Revert 119976 - Adds two new observer methods to allow code to be notified when a Window is added/removed from a RootWindow. This allows hierarchy-specific cleanup code to execute when a Window is removed rather than when it is destroyed, necessary for multiple root windows.

http://crbug.com/112131
TEST=see unittests
Review URL: https://chromiumcodereview.appspot.com/9315015

TBR=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9315017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119986 0039d316-1c4b-4281-b951-d872f2087c98
parent a7b35ed1
......@@ -413,9 +413,6 @@ void RootWindow::ToggleFullScreen() {
}
#endif
////////////////////////////////////////////////////////////////////////////////
// RootWindow, Window overrides:
RootWindow* RootWindow::GetRootWindow() {
return this;
}
......@@ -429,17 +426,6 @@ void RootWindow::SetTransform(const ui::Transform& transform) {
OnHostResized(host_->GetSize());
}
////////////////////////////////////////////////////////////////////////////////
// RootWindow, ui::CompositorDelegate implementation:
void RootWindow::ScheduleDraw() {
if (!schedule_paint_factory_.HasWeakPtrs()) {
MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&RootWindow::Draw, schedule_paint_factory_.GetWeakPtr()));
}
}
////////////////////////////////////////////////////////////////////////////////
// RootWindow, private:
......@@ -629,7 +615,27 @@ bool RootWindow::ProcessGestures(GestureRecognizer::Gestures* gestures) {
return handled;
}
void RootWindow::OnWindowRemovedFromRootWindow(Window* detached) {
void RootWindow::ScheduleDraw() {
if (!schedule_paint_factory_.HasWeakPtrs()) {
MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&RootWindow::Draw, schedule_paint_factory_.GetWeakPtr()));
}
}
bool RootWindow::CanFocus() const {
return IsVisible();
}
bool RootWindow::CanReceiveEvents() const {
return IsVisible();
}
internal::FocusManager* RootWindow::GetFocusManager() {
return this;
}
void RootWindow::OnWindowDetachingFromRootWindow(Window* detached) {
DCHECK(capture_window_ != this);
// If the ancestor of the capture window is detached,
......@@ -657,24 +663,12 @@ void RootWindow::OnWindowRemovedFromRootWindow(Window* detached) {
}
}
void RootWindow::OnWindowAddedToRootWindow(Window* attached) {
void RootWindow::OnWindowAttachedToRootWindow(Window* attached) {
if (attached->IsVisible() &&
attached->ContainsPointInRoot(last_mouse_location_))
PostMouseMoveEventAfterWindowChange();
}
bool RootWindow::CanFocus() const {
return IsVisible();
}
bool RootWindow::CanReceiveEvents() const {
return IsVisible();
}
internal::FocusManager* RootWindow::GetFocusManager() {
return this;
}
void RootWindow::OnLayerAnimationEnded(
const ui::LayerAnimationSequence* animation) {
OnHostResized(host_->GetSize());
......
......@@ -192,9 +192,13 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// Overridden from ui::CompositorDelegate:
virtual void ScheduleDraw() OVERRIDE;
private:
friend class Window;
// Overridden from Window:
virtual void OnWindowAttachedToRootWindow(
Window* window) OVERRIDE;
virtual void OnWindowDetachingFromRootWindow(
Window* window) OVERRIDE;
private:
RootWindow();
virtual ~RootWindow();
......@@ -208,10 +212,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
ui::GestureStatus ProcessGestureEvent(Window* target, GestureEvent* event);
bool ProcessGestures(GestureRecognizer::Gestures* gestures);
// Called when a Window is attached or detached from the RootWindow.
void OnWindowAddedToRootWindow(Window* window);
void OnWindowRemovedFromRootWindow(Window* window);
// Overridden from Window:
virtual bool CanFocus() const OVERRIDE;
virtual bool CanReceiveEvents() const OVERRIDE;
......
......@@ -294,10 +294,8 @@ void Window::AddChild(Window* child) {
child->OnParentChanged();
RootWindow* root_window = child->GetRootWindow();
if (root_window) {
root_window->OnWindowAddedToRootWindow(child);
NotifyAddedToRootWindow();
}
if (root_window)
root_window->OnWindowAttachedToRootWindow(child);
}
void Window::AddTransientChild(Window* child) {
......@@ -325,10 +323,8 @@ void Window::RemoveChild(Window* child) {
layout_manager_->OnWillRemoveWindowFromLayout(child);
FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child));
RootWindow* root_window = child->GetRootWindow();
if (root_window) {
root_window->OnWindowRemovedFromRootWindow(child);
child->NotifyRemovingFromRootWindow();
}
if (root_window)
root_window->OnWindowDetachingFromRootWindow(child);
child->parent_ = NULL;
// We should only remove the child's layer if the child still owns that layer.
// Someone else may have acquired ownership of it via AcquireLayer() and may
......@@ -523,6 +519,12 @@ bool Window::StopsEventPropagation() const {
return it != children_.end();
}
void Window::OnWindowDetachingFromRootWindow(aura::Window* window) {
}
void Window::OnWindowAttachedToRootWindow(aura::Window* window) {
}
void Window::SetBoundsInternal(const gfx::Rect& new_bounds) {
gfx::Rect actual_new_bounds(new_bounds);
......@@ -641,24 +643,6 @@ void Window::OnStackingChanged() {
FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowStackingChanged(this));
}
void Window::NotifyRemovingFromRootWindow() {
FOR_EACH_OBSERVER(WindowObserver, observers_,
OnWindowRemovingFromRootWindow(this));
for (Window::Windows::const_iterator it = children_.begin();
it != children_.end(); ++it) {
(*it)->NotifyRemovingFromRootWindow();
}
}
void Window::NotifyAddedToRootWindow() {
FOR_EACH_OBSERVER(WindowObserver, observers_,
OnWindowAddedToRootWindow(this));
for (Window::Windows::const_iterator it = children_.begin();
it != children_.end(); ++it) {
(*it)->NotifyAddedToRootWindow();
}
}
void Window::OnPaintLayer(gfx::Canvas* canvas) {
if (delegate_)
delegate_->OnPaint(canvas);
......
......@@ -293,6 +293,16 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// propagation for any windows behind it in the z-order.
bool StopsEventPropagation() const;
protected:
// Called when the |window| is being detached from the root window
// by being removed from its parent. It is called before |parent_| is
// set to NULL.
virtual void OnWindowDetachingFromRootWindow(aura::Window* window);
// Called when the |window| is attached to the root window by being added
// to its parent.
virtual void OnWindowAttachedToRootWindow(aura::Window* window);
private:
friend class LayoutManager;
......@@ -322,11 +332,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// Called when this window's stacking order among its siblings is changed.
void OnStackingChanged();
// Notifies observers registered with this Window (and its subtree) when the
// Window has been added or is about to be removed from a RootWindow.
void NotifyAddedToRootWindow();
void NotifyRemovingFromRootWindow();
// Overridden from ui::LayerDelegate:
virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
......
......@@ -58,12 +58,6 @@ class AURA_EXPORT WindowObserver {
// destructor). This is called after the window is removed from its parent.
virtual void OnWindowDestroyed(Window* window) {}
// Called when a Window has been added to a RootWindow.
virtual void OnWindowAddedToRootWindow(Window* window) {}
// Called when a Window is about to be removed from a RootWindow.
virtual void OnWindowRemovingFromRootWindow(Window* window) {}
protected:
virtual ~WindowObserver() {}
};
......
......@@ -1462,98 +1462,5 @@ TEST_F(WindowTest, StackingMadrigal) {
EXPECT_TRUE(LayerIsAbove(window12.get(), window1.get()));
}
class RootWindowAttachmentObserver : public WindowObserver {
public:
RootWindowAttachmentObserver() : added_count_(0), removed_count_(0) {}
virtual ~RootWindowAttachmentObserver() {}
int added_count() const { return added_count_; }
int removed_count() const { return removed_count_; }
void Clear() {
added_count_ = 0;
removed_count_ = 0;
}
// Overridden from WindowObserver:
virtual void OnWindowAddedToRootWindow(Window* window) OVERRIDE {
++added_count_;
}
virtual void OnWindowRemovingFromRootWindow(Window* window) OVERRIDE {
++removed_count_;
}
private:
int added_count_;
int removed_count_;
DISALLOW_COPY_AND_ASSIGN(RootWindowAttachmentObserver);
};
TEST_F(WindowTest, RootWindowAttachment) {
RootWindowAttachmentObserver observer;
// Test a direct add/remove from the RootWindow.
scoped_ptr<Window> w1(new Window(NULL));
w1->Init(ui::Layer::LAYER_NOT_DRAWN);
w1->AddObserver(&observer);
w1->SetParent(NULL);
EXPECT_EQ(1, observer.added_count());
EXPECT_EQ(0, observer.removed_count());
w1.reset();
EXPECT_EQ(1, observer.added_count());
EXPECT_EQ(1, observer.removed_count());
observer.Clear();
// Test an indirect add/remove from the RootWindow.
w1.reset(new Window(NULL));
w1->Init(ui::Layer::LAYER_NOT_DRAWN);
Window* w11 = new Window(NULL);
w11->Init(ui::Layer::LAYER_NOT_DRAWN);
w11->AddObserver(&observer);
w11->SetParent(w1.get());
EXPECT_EQ(0, observer.added_count());
EXPECT_EQ(0, observer.removed_count());
w1->SetParent(NULL);
EXPECT_EQ(1, observer.added_count());
EXPECT_EQ(0, observer.removed_count());
w1.reset(); // Deletes w11.
w11 = NULL;
EXPECT_EQ(1, observer.added_count());
EXPECT_EQ(1, observer.removed_count());
observer.Clear();
// Test an indirect add/remove with nested observers.
w1.reset(new Window(NULL));
w1->Init(ui::Layer::LAYER_NOT_DRAWN);
w11 = new Window(NULL);
w11->Init(ui::Layer::LAYER_NOT_DRAWN);
w11->AddObserver(&observer);
w11->SetParent(w1.get());
Window* w111 = new Window(NULL);
w111->Init(ui::Layer::LAYER_NOT_DRAWN);
w111->AddObserver(&observer);
w111->SetParent(w11);
EXPECT_EQ(0, observer.added_count());
EXPECT_EQ(0, observer.removed_count());
w1->SetParent(NULL);
EXPECT_EQ(2, observer.added_count());
EXPECT_EQ(0, observer.removed_count());
w1.reset(); // Deletes w11 and w111.
w11 = NULL;
w111 = NULL;
EXPECT_EQ(2, observer.added_count());
EXPECT_EQ(2, observer.removed_count());
}
} // namespace test
} // namespace aura
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