summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-20 23:58:26 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-20 23:58:26 +0000
commitbf1734063e3091984b53bb3baadcae42a976b0a6 (patch)
tree5f5ffa2ebfd7b8ed173e56070fd0e145b347cda9 /ui
parent7d77085e247b984df8cf249a9919c3dab4949793 (diff)
downloadchromium_src-bf1734063e3091984b53bb3baadcae42a976b0a6.zip
chromium_src-bf1734063e3091984b53bb3baadcae42a976b0a6.tar.gz
chromium_src-bf1734063e3091984b53bb3baadcae42a976b0a6.tar.bz2
Fixes aura unit tests. There were a couple of problems:
. Child windows weren't getting focused correctly. . ToplevelWindowContainer needed to be created in Desktop constructor. . MoveChildToFront needed to move layers too. BUG=none TEST=none R=ben@chromium.org Review URL: http://codereview.chromium.org/7980023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102057 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/desktop.cc7
-rw-r--r--ui/aura/event_filter.cc9
-rw-r--r--ui/aura/event_filter.h1
-rw-r--r--ui/aura/toplevel_window_event_filter.cc6
-rw-r--r--ui/aura/window.cc4
-rw-r--r--ui/aura/window.h6
-rw-r--r--ui/aura/window_unittest.cc30
-rw-r--r--ui/aura_shell/desktop_layout_manager.cc1
-rw-r--r--ui/aura_shell/desktop_window.cc18
9 files changed, 58 insertions, 24 deletions
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc
index e4e1ea8c..50b3802 100644
--- a/ui/aura/desktop.cc
+++ b/ui/aura/desktop.cc
@@ -8,6 +8,7 @@
#include "base/message_loop.h"
#include "ui/aura/desktop_host.h"
#include "ui/aura/root_window.h"
+#include "ui/aura/toplevel_window_container.h"
#include "ui/aura/window.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
@@ -18,7 +19,7 @@ namespace aura {
Desktop* Desktop::instance_ = NULL;
Desktop::Desktop()
- : toplevel_window_container_(NULL),
+ : toplevel_window_container_(new aura::internal::ToplevelWindowContainer),
host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1280, 1024))),
ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_(this)) {
DCHECK(MessageLoopForUI::current())
@@ -38,6 +39,10 @@ Desktop::~Desktop() {
void Desktop::Init() {
window_->Init();
compositor()->set_root_layer(window_->layer());
+ toplevel_window_container_->Init();
+ toplevel_window_container_->SetBounds(gfx::Rect(0, 0, 1280, 1024), 0);
+ toplevel_window_container_->SetVisibility(aura::Window::VISIBILITY_SHOWN);
+ toplevel_window_container_->SetParent(window_.get());
#if defined(USE_X11)
// TODO(oshima): Implement configure notify and remove this.
OnHostResized(host_->GetSize());
diff --git a/ui/aura/event_filter.cc b/ui/aura/event_filter.cc
index 68748fb..41436b3 100644
--- a/ui/aura/event_filter.cc
+++ b/ui/aura/event_filter.cc
@@ -4,6 +4,10 @@
#include "ui/aura/event_filter.h"
+#include "ui/aura/event.h"
+#include "ui/aura/focus_manager.h"
+#include "ui/aura/window.h"
+
namespace aura {
EventFilter::EventFilter(Window* owner) : owner_(owner) {
@@ -13,6 +17,11 @@ EventFilter::~EventFilter() {
}
bool EventFilter::OnMouseEvent(Window* target, MouseEvent* event) {
+ if (event->type() == ui::ET_MOUSE_PRESSED) {
+ // TODO(beng): some windows (e.g. disabled ones, tooltips, etc) may not be
+ // focusable.
+ target->GetFocusManager()->SetFocusedWindow(target);
+ }
return false;
}
diff --git a/ui/aura/event_filter.h b/ui/aura/event_filter.h
index 6d8ca27..19c0586 100644
--- a/ui/aura/event_filter.h
+++ b/ui/aura/event_filter.h
@@ -23,6 +23,7 @@ class EventFilter {
// Try to handle |event| (before the owner's delegate gets a chance to).
// Returns true if the event was handled by the WindowManager and should not
// be forwarded to the owner's delegate.
+ // Default implementation for ET_MOUSE_PRESSED focuses the window.
virtual bool OnMouseEvent(Window* target, MouseEvent* event);
protected:
diff --git a/ui/aura/toplevel_window_event_filter.cc b/ui/aura/toplevel_window_event_filter.cc
index bf4395f..be648c8 100644
--- a/ui/aura/toplevel_window_event_filter.cc
+++ b/ui/aura/toplevel_window_event_filter.cc
@@ -5,7 +5,6 @@
#include "ui/aura/toplevel_window_event_filter.h"
#include "ui/aura/event.h"
-#include "ui/aura/focus_manager.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
@@ -27,9 +26,6 @@ bool ToplevelWindowEventFilter::OnMouseEvent(Window* target,
MouseEvent* event) {
switch (event->type()) {
case ui::ET_MOUSE_PRESSED:
- // TODO(beng): some windows (e.g. disabled ones, tooltips, etc) may not be
- // focusable.
- target->GetFocusManager()->SetFocusedWindow(target);
window_component_ =
target->delegate()->GetNonClientComponent(event->location());
MoveWindowToFront(target);
@@ -53,7 +49,7 @@ bool ToplevelWindowEventFilter::OnMouseEvent(Window* target,
default:
break;
}
- return false;
+ return EventFilter::OnMouseEvent(target, event);
}
void ToplevelWindowEventFilter::MoveWindowToFront(Window* target) {
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index 412bd1a..6ccf808 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -126,6 +126,10 @@ void Window::MoveChildToFront(Window* child) {
// TODO(beng): this obviously has to handle different window types.
children_.insert(children_.begin() + children_.size(), child);
SchedulePaintInRect(gfx::Rect());
+
+ ui::Layer* parent_layer = child->layer()->parent();
+ parent_layer->Remove(child->layer());
+ parent_layer->Add(child->layer());
}
void Window::AddChild(Window* child) {
diff --git a/ui/aura/window.h b/ui/aura/window.h
index a0221c4..15573f4 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -40,6 +40,8 @@ class FocusManager;
// TODO(beng): resolve ownership.
class AURA_EXPORT Window : public ui::LayerDelegate {
public:
+ typedef std::vector<Window*> Windows;
+
enum Visibility {
// Don't display the window onscreen and don't let it receive mouse
// events. This is the default.
@@ -102,6 +104,8 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
void AddChild(Window* child);
void RemoveChild(Window* child);
+ const Windows& children() const { return children_; }
+
static void ConvertPointToWindow(Window* source,
Window* target,
gfx::Point* point);
@@ -137,8 +141,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
void* user_data() const { return user_data_; }
private:
- typedef std::vector<Window*> Windows;
-
// If SchedulePaint has been invoked on the Window the delegate is notified.
void UpdateLayerCanvas();
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 1025d44..2c8918f 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -12,6 +12,7 @@
#include "ui/aura/root_window.h"
#include "ui/aura/window_delegate.h"
#include "ui/gfx/canvas_skia.h"
+#include "ui/gfx/compositor/layer.h"
#include "ui/base/keycodes/keyboard_codes.h"
#if !defined(OS_WIN)
@@ -218,7 +219,7 @@ TEST_F(WindowTest, GetEventHandlerForPoint) {
CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get()));
Window* desktop = Desktop::GetInstance()->window();
- EXPECT_EQ(desktop, desktop->GetEventHandlerForPoint(gfx::Point(5, 5)));
+ EXPECT_EQ(NULL, desktop->GetEventHandlerForPoint(gfx::Point(5, 5)));
EXPECT_EQ(w1.get(), desktop->GetEventHandlerForPoint(gfx::Point(11, 11)));
EXPECT_EQ(w11.get(), desktop->GetEventHandlerForPoint(gfx::Point(16, 16)));
EXPECT_EQ(w111.get(), desktop->GetEventHandlerForPoint(gfx::Point(21, 21)));
@@ -277,6 +278,33 @@ TEST_F(WindowTest, DestroyTest) {
EXPECT_EQ(1, child_delegate.destroyed_count());
}
+// Make sure MoveChildToFront moves both the window and layer to the front.
+TEST_F(WindowTest, MoveChildToFront) {
+ Window parent(NULL);
+ parent.Init();
+ Window child1(NULL);
+ child1.Init();
+ Window child2(NULL);
+ child2.Init();
+
+ child1.SetParent(&parent);
+ child2.SetParent(&parent);
+ ASSERT_EQ(2u, parent.children().size());
+ EXPECT_EQ(&child1, parent.children()[0]);
+ EXPECT_EQ(&child2, parent.children()[1]);
+ ASSERT_EQ(2u, parent.layer()->children().size());
+ EXPECT_EQ(child1.layer(), parent.layer()->children()[0]);
+ EXPECT_EQ(child2.layer(), parent.layer()->children()[1]);
+
+ parent.MoveChildToFront(&child1);
+ ASSERT_EQ(2u, parent.children().size());
+ EXPECT_EQ(&child1, parent.children()[1]);
+ EXPECT_EQ(&child2, parent.children()[0]);
+ ASSERT_EQ(2u, parent.layer()->children().size());
+ EXPECT_EQ(child1.layer(), parent.layer()->children()[1]);
+ EXPECT_EQ(child2.layer(), parent.layer()->children()[0]);
+}
+
} // namespace internal
} // namespace aura
diff --git a/ui/aura_shell/desktop_layout_manager.cc b/ui/aura_shell/desktop_layout_manager.cc
index 992805f..4585f58 100644
--- a/ui/aura_shell/desktop_layout_manager.cc
+++ b/ui/aura_shell/desktop_layout_manager.cc
@@ -15,6 +15,7 @@ namespace internal {
DesktopLayoutManager::DesktopLayoutManager(aura::Window* owner)
: owner_(owner),
+ toplevel_window_container_(NULL),
background_widget_(NULL),
launcher_widget_(NULL),
status_area_widget_(NULL) {
diff --git a/ui/aura_shell/desktop_window.cc b/ui/aura_shell/desktop_window.cc
index 9feb0ae..6f159f9 100644
--- a/ui/aura_shell/desktop_window.cc
+++ b/ui/aura_shell/desktop_window.cc
@@ -10,20 +10,6 @@
namespace aura_shell {
-namespace internal {
-
-aura::Window* CreateToplevelWindowContainer() {
- aura::Window* container = new aura::internal::ToplevelWindowContainer;
- container->Init();
- container->SetBounds(gfx::Rect(0, 0, 1024, 768), 0);
- container->SetVisibility(aura::Window::VISIBILITY_SHOWN);
- container->SetParent(aura::Desktop::GetInstance()->window());
- aura::Desktop::GetInstance()->set_toplevel_window_container(container);
- return container;
-}
-
-} // namespace internal
-
void InitDesktopWindow() {
aura::Window* desktop_window = aura::Desktop::GetInstance()->window();
internal::DesktopLayoutManager* desktop_layout =
@@ -33,7 +19,9 @@ void InitDesktopWindow() {
// The order of creation here is important to establish the z-index:
desktop_layout->set_background_widget(internal::CreateDesktopBackground());
desktop_layout->set_toplevel_window_container(
- internal::CreateToplevelWindowContainer());
+ aura::Desktop::GetInstance()->toplevel_window_container());
+ desktop_window->MoveChildToFront(
+ aura::Desktop::GetInstance()->toplevel_window_container());
desktop_layout->set_launcher_widget(internal::CreateLauncher());
desktop_layout->set_status_area_widget(internal::CreateStatusArea());
}