summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-23 12:02:39 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-23 12:02:39 +0000
commita34edf290367d37ccbfcaf1b21cdbbebb679284a (patch)
tree53dda0db19b4585bafef8139b7814b1110209d87 /ui
parent4958f0d2b68a5881f96d81fc722c915d270305e9 (diff)
downloadchromium_src-a34edf290367d37ccbfcaf1b21cdbbebb679284a.zip
chromium_src-a34edf290367d37ccbfcaf1b21cdbbebb679284a.tar.gz
chromium_src-a34edf290367d37ccbfcaf1b21cdbbebb679284a.tar.bz2
Revert 178251 - Suspected for CrOS ASAN break
> Situation: There are 5 ways of knowing that the window hierarchy changed. > This is ridiculous! > We need to develop one universal standard that covers everyone's use cases. > Yeah! > ... > Situation: There are 6 ways of knowing that the window hierarchy changed. > > (source: http://xkcd.com/927/) > > Creates a single hierarchy change notification capable of expressing everything all our clients currently need and more (needed for FocusController). > This adds the notification and the unit tests, I will work on replacing the existing users in a future CL. > > BUG=none > R=sky@chromium.org > > Review URL: https://chromiumcodereview.appspot.com/12042034 TBR=ben@chromium.org Review URL: https://codereview.chromium.org/12040038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178280 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/test/test_windows.cc3
-rw-r--r--ui/aura/test/test_windows.h3
-rw-r--r--ui/aura/window.cc77
-rw-r--r--ui/aura/window.h15
-rw-r--r--ui/aura/window_observer.h23
-rw-r--r--ui/aura/window_unittest.cc214
6 files changed, 16 insertions, 319 deletions
diff --git a/ui/aura/test/test_windows.cc b/ui/aura/test/test_windows.cc
index 16171f3..f41a034 100644
--- a/ui/aura/test/test_windows.cc
+++ b/ui/aura/test/test_windows.cc
@@ -52,8 +52,7 @@ Window* CreateTestWindowWithDelegateAndType(WindowDelegate* delegate,
window->Init(ui::LAYER_TEXTURED);
window->SetBounds(bounds);
window->Show();
- if (parent)
- parent->AddChild(window);
+ parent->AddChild(window);
window->SetProperty(aura::client::kCanMaximizeKey, true);
return window;
}
diff --git a/ui/aura/test/test_windows.h b/ui/aura/test/test_windows.h
index e99fa62..94f3ac6 100644
--- a/ui/aura/test/test_windows.h
+++ b/ui/aura/test/test_windows.h
@@ -16,6 +16,9 @@
namespace aura {
namespace test {
+// These functions expect a non-NULL parent. If you want to let the
+// StackingClient determine where to place the windows, there are equivalent
+// methods in AshTestBase.
Window* CreateTestWindowWithId(int id, Window* parent);
Window* CreateTestWindowWithBounds(const gfx::Rect& bounds, Window* parent);
Window* CreateTestWindow(SkColor color,
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index 27c9b33..def4327 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -346,13 +346,6 @@ void Window::StackChildBelow(Window* child, Window* target) {
}
void Window::AddChild(Window* child) {
- WindowObserver::HierarchyChangeParams params;
- params.target = child;
- params.new_parent = this;
- params.old_parent = child->parent();
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING;
- NotifyWindowHierarchyChange(params);
-
RootWindow* old_root = child->GetRootWindow();
DCHECK(std::find(children_.begin(), children_.end(), child) ==
@@ -374,31 +367,6 @@ void Window::AddChild(Window* child) {
root_window->OnWindowAddedToRootWindow(child);
child->NotifyAddedToRootWindow();
}
-
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED;
- NotifyWindowHierarchyChange(params);
-}
-
-void Window::RemoveChild(Window* child) {
- WindowObserver::HierarchyChangeParams params;
- params.target = child;
- params.new_parent = NULL;
- params.old_parent = this;
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING;
- NotifyWindowHierarchyChange(params);
-
- RemoveChildImpl(child, NULL);
-
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED;
- NotifyWindowHierarchyChange(params);
-}
-
-bool Window::Contains(const Window* other) const {
- for (const Window* parent = other; parent; parent = parent->parent_) {
- if (parent == this)
- return true;
- }
- return false;
}
void Window::AddTransientChild(Window* child) {
@@ -419,6 +387,18 @@ void Window::RemoveTransientChild(Window* child) {
child->transient_parent_ = NULL;
}
+void Window::RemoveChild(Window* child) {
+ RemoveChildImpl(child, NULL);
+}
+
+bool Window::Contains(const Window* other) const {
+ for (const Window* parent = other; parent; parent = parent->parent_) {
+ if (parent == this)
+ return true;
+ }
+ return false;
+}
+
Window* Window::GetChildById(int id) {
return const_cast<Window*>(const_cast<const Window*>(this)->GetChildById(id));
}
@@ -926,39 +906,6 @@ void Window::NotifyAddedToRootWindow() {
}
}
-void Window::NotifyWindowHierarchyChange(
- const WindowObserver::HierarchyChangeParams& params) {
- params.target->NotifyWindowHierarchyChangeDown(params);
- if (params.old_parent)
- params.old_parent->NotifyWindowHierarchyChangeUp(params);
- if (params.new_parent)
- params.new_parent->NotifyWindowHierarchyChangeUp(params);
-}
-
-void Window::NotifyWindowHierarchyChangeDown(
- const WindowObserver::HierarchyChangeParams& params) {
- NotifyWindowHierarchyChangeAtReceiver(params);
- for (Window::Windows::const_iterator it = children_.begin();
- it != children_.end(); ++it) {
- (*it)->NotifyWindowHierarchyChangeDown(params);
- }
-}
-
-void Window::NotifyWindowHierarchyChangeUp(
- const WindowObserver::HierarchyChangeParams& params) {
- for (Window* window = this; window; window = window->parent())
- window->NotifyWindowHierarchyChangeAtReceiver(params);
-}
-
-void Window::NotifyWindowHierarchyChangeAtReceiver(
- const WindowObserver::HierarchyChangeParams& params) {
- WindowObserver::HierarchyChangeParams local_params = params;
- local_params.receiver = this;
-
- FOR_EACH_OBSERVER(WindowObserver, observers_,
- OnWindowHierarchyChange(local_params));
-}
-
void Window::OnLayerBoundsChanged(const gfx::Rect& old_bounds,
bool contained_mouse) {
if (layout_manager_.get())
diff --git a/ui/aura/window.h b/ui/aura/window.h
index ec19ae4..af3ad89 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -16,7 +16,6 @@
#include "base/string16.h"
#include "ui/aura/aura_export.h"
#include "ui/aura/client/window_types.h"
-#include "ui/aura/window_observer.h"
#include "ui/base/events/event_constants.h"
#include "ui/base/events/event_target.h"
#include "ui/base/gestures/gesture_types.h"
@@ -421,20 +420,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
void NotifyRemovingFromRootWindow();
void NotifyAddedToRootWindow();
- // Methods implementing hierarchy change notifications. See WindowObserver for
- // more details.
- void NotifyWindowHierarchyChange(
- const WindowObserver::HierarchyChangeParams& params);
- // Notifies this window and its child hierarchy.
- void NotifyWindowHierarchyChangeDown(
- const WindowObserver::HierarchyChangeParams& params);
- // Notifies this window and its parent hierarchy.
- void NotifyWindowHierarchyChangeUp(
- const WindowObserver::HierarchyChangeParams& params);
- // Notifies this window's observers.
- void NotifyWindowHierarchyChangeAtReceiver(
- const WindowObserver::HierarchyChangeParams& params);
-
// Invoked from the closure returned by PrepareForLayerBoundsChange() after
// the bounds of the layer has changed. |old_bounds| is the previous bounds of
// the layer, and |contained_mouse| is true if the mouse was previously within
diff --git a/ui/aura/window_observer.h b/ui/aura/window_observer.h
index e519d45..0514c2c 100644
--- a/ui/aura/window_observer.h
+++ b/ui/aura/window_observer.h
@@ -18,29 +18,6 @@ class Window;
class AURA_EXPORT WindowObserver {
public:
- struct HierarchyChangeParams {
- enum HierarchyChangePhase {
- HIERARCHY_CHANGING,
- HIERARCHY_CHANGED
- };
-
- Window* target; // The window that was added or removed.
- Window* new_parent;
- Window* old_parent;
- HierarchyChangePhase phase;
- Window* receiver; // The window receiving the notification.
- };
-
- // Called when a window is added or removed. Notifications are sent to the
- // following hierarchies in this order:
- // 1. |target|.
- // 2. |target|'s child hierarchy.
- // 3. |target|'s parent hierarchy in its |old_parent|.
- // 4. |target|'s parent hierarchy in its |new_parent|.
- // This sequence is performed before and after the change is committed, with
- // differing values for |phase| in |params| (see above).
- virtual void OnWindowHierarchyChange(const HierarchyChangeParams& params) {}
-
// Invoked when |new_window| has been added as a child of this window.
virtual void OnWindowAdded(Window* new_window) {}
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 43a44c1..d7e1af6 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -2626,219 +2626,5 @@ TEST_F(WindowTest, DelegateDestroysSelfOnWindowDestroy) {
root_window()));
}
-class HierarchyObserver : public WindowObserver {
- public:
- HierarchyObserver(Window* target) : target_(target) {
- target_->AddObserver(this);
- }
- virtual ~HierarchyObserver() {
- target_->RemoveObserver(this);
- }
-
- void ValidateState(
- int index,
- const WindowObserver::HierarchyChangeParams& params) const {
- ParamsMatch(params_[index], params);
- }
-
- void Reset() {
- params_.clear();
- }
-
- private:
- // Overridden from WindowObserver:
- virtual void OnWindowHierarchyChange(
- const HierarchyChangeParams& params) OVERRIDE {
- params_.push_back(params);
- }
-
- void ParamsMatch(const WindowObserver::HierarchyChangeParams& p1,
- const WindowObserver::HierarchyChangeParams& p2) const {
- EXPECT_EQ(p1.phase, p2.phase);
- EXPECT_EQ(p1.target, p2.target);
- EXPECT_EQ(p1.new_parent, p2.new_parent);
- EXPECT_EQ(p1.old_parent, p2.old_parent);
- EXPECT_EQ(p1.receiver, p2.receiver);
- }
-
- Window* target_;
- std::vector<WindowObserver::HierarchyChangeParams> params_;
-
- DISALLOW_COPY_AND_ASSIGN(HierarchyObserver);
-};
-
-// Tests hierarchy change notifications.
-TEST_F(WindowTest, OnWindowHierarchyChange) {
- {
- // Simple add & remove.
- HierarchyObserver oroot(root_window());
-
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
- HierarchyObserver o1(w1.get());
-
- // Add.
- root_window()->AddChild(w1.get());
-
- WindowObserver::HierarchyChangeParams params;
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING;
- params.target = w1.get();
- params.old_parent = NULL;
- params.new_parent = root_window();
- params.receiver = w1.get();
- o1.ValidateState(0, params);
-
- params.receiver = root_window();
- oroot.ValidateState(0, params);
-
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED;
- params.receiver = w1.get();
- o1.ValidateState(1, params);
-
- params.receiver = root_window();
- oroot.ValidateState(1, params);
-
- // Remove.
- o1.Reset();
- oroot.Reset();
-
- root_window()->RemoveChild(w1.get());
-
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING;
- params.old_parent = root_window();
- params.new_parent = NULL;
- params.receiver = w1.get();
-
- o1.ValidateState(0, params);
-
- params.receiver = root_window();
- oroot.ValidateState(0, params);
-
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED;
- params.receiver = w1.get();
- o1.ValidateState(1, params);
-
- params.receiver = root_window();
- oroot.ValidateState(1, params);
- }
-
- {
- // Add & remove of hierarchy. Tests notification order per documentation in
- // WindowObserver.
- HierarchyObserver o(root_window());
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
- Window* w11 = CreateTestWindowWithId(11, w1.get());
- w1->AddObserver(&o);
- w11->AddObserver(&o);
-
- // Add.
- root_window()->AddChild(w1.get());
-
- // Dispatched to target first.
- int index = 0;
- WindowObserver::HierarchyChangeParams params;
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING;
- params.target = w1.get();
- params.old_parent = NULL;
- params.new_parent = root_window();
- params.receiver = w1.get();
- o.ValidateState(index++, params);
-
- // Dispatched to target's children.
- params.receiver = w11;
- o.ValidateState(index++, params);
-
- // Dispatched to target's parent(s).
- params.receiver = root_window();
- o.ValidateState(index++, params);
-
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED;
-
- // Now process the "changed" phase.
- params.receiver = w1.get();
- o.ValidateState(index++, params);
- params.receiver = w11;
- o.ValidateState(index++, params);
- params.receiver = root_window();
- o.ValidateState(index++, params);
-
- // Remove.
- root_window()->RemoveChild(w1.get());
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING;
- params.old_parent = root_window();
- params.new_parent = NULL;
- params.receiver = w1.get();
- o.ValidateState(index++, params);
- params.receiver = w11;
- o.ValidateState(index++, params);
- params.receiver = root_window();
- o.ValidateState(index++, params);
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED;
- params.receiver = w1.get();
- o.ValidateState(index++, params);
- params.receiver = w11;
- o.ValidateState(index++, params);
- params.receiver = root_window();
- o.ValidateState(index++, params);
- }
-
- {
- // Reparent. Tests notification order per documentation in WindowObserver.
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
- Window* w11 = CreateTestWindowWithId(11, w1.get());
- Window* w111 = CreateTestWindowWithId(111, w11);
- scoped_ptr<Window> w2(CreateTestWindowWithId(2, root_window()));
-
- HierarchyObserver o(root_window());
- w1->AddObserver(&o);
- w11->AddObserver(&o);
- w111->AddObserver(&o);
- w2->AddObserver(&o);
-
- w2->AddChild(w11);
-
- // Dispatched to target first.
- int index = 0;
- WindowObserver::HierarchyChangeParams params;
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING;
- params.target = w11;
- params.old_parent = w1.get();
- params.new_parent = w2.get();
- params.receiver = w11;
- o.ValidateState(index++, params);
-
- // Then to target's children.
- params.receiver = w111;
- o.ValidateState(index++, params);
-
- // Then to target's old parent chain.
- params.receiver = w1.get();
- o.ValidateState(index++, params);
- params.receiver = root_window();
- o.ValidateState(index++, params);
-
- // Then to target's new parent chain.
- params.receiver = w2.get();
- o.ValidateState(index++, params);
- params.receiver = root_window();
- o.ValidateState(index++, params);
-
- // "Changed" phase.
- params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED;
- params.receiver = w11;
- o.ValidateState(index++, params);
- params.receiver = w111;
- o.ValidateState(index++, params);
- params.receiver = w1.get();
- o.ValidateState(index++, params);
- params.receiver = root_window();
- o.ValidateState(index++, params);
- params.receiver = w2.get();
- o.ValidateState(index++, params);
- params.receiver = root_window();
- o.ValidateState(index++, params);
- }
-
-}
-
} // namespace test
} // namespace aura