summaryrefslogtreecommitdiffstats
path: root/ui/aura
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-20 17:16:21 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-20 17:16:21 +0000
commita42a7ee454165d73e161448383cdf3dc3b1f164a (patch)
tree7b86ca4d25951d89ccf371de8c0dc101c50c5ba4 /ui/aura
parent687bc8a9e767e8eebbc287b8785bc4ed1302d446 (diff)
downloadchromium_src-a42a7ee454165d73e161448383cdf3dc3b1f164a.zip
chromium_src-a42a7ee454165d73e161448383cdf3dc3b1f164a.tar.gz
chromium_src-a42a7ee454165d73e161448383cdf3dc3b1f164a.tar.bz2
A bunch of changes related to window z-index:
- Keeps toplevel windows constrained in z-index between the desktop background (bottom-most) and the launcher (topmost). - Renames WindowManager to EventFilter, and moves it to the parent Window... i.e. when a window receives a mouse event its parent's event filter will get the opportunity to process it before that window's delegate does. - WindowManager's content was mostly specific to toplevel window movement, so this content moved to an EventFilter subclass called ToplevelEventFilter. - Adds a name property to aura::Windows useful for debugging. - Prevent Windows with no delegate from taking part in event processing. - Initialize the Aura_Shell in DesktopWindow, provide a single exported method - aura_shell::InitDesktopWindow() - to initialize it from the exe main. BUG=none TEST=none Review URL: http://codereview.chromium.org/7970001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101974 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r--ui/aura/aura.gyp8
-rw-r--r--ui/aura/desktop.cc3
-rw-r--r--ui/aura/desktop.h6
-rw-r--r--ui/aura/event_filter.cc19
-rw-r--r--ui/aura/event_filter.h (renamed from ui/aura/window_manager.h)29
-rw-r--r--ui/aura/root_window.cc5
-rw-r--r--ui/aura/root_window.h1
-rw-r--r--ui/aura/toplevel_window_container.cc26
-rw-r--r--ui/aura/toplevel_window_container.h32
-rw-r--r--ui/aura/toplevel_window_event_filter.cc (renamed from ui/aura/window_manager.cc)33
-rw-r--r--ui/aura/toplevel_window_event_filter.h40
-rw-r--r--ui/aura/window.cc36
-rw-r--r--ui/aura/window.h14
13 files changed, 197 insertions, 55 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index f4f794e..765d5a5 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -31,6 +31,8 @@
'desktop.h',
'event.cc',
'event.h',
+ 'event_filter.cc',
+ 'event_filter.h',
'event_win.cc',
'event_x.cc',
'focus_manager.cc',
@@ -39,11 +41,13 @@
'layout_manager.h',
'root_window.cc',
'root_window.h',
+ 'toplevel_window_container.cc',
+ 'toplevel_window_container.h',
+ 'toplevel_window_event_filter.cc',
+ 'toplevel_window_event_filter.h',
'window.cc',
'window.h',
'window_delegate.h',
- 'window_manager.cc',
- 'window_manager.h',
],
},
{
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc
index cbf9d19..e4e1ea8c 100644
--- a/ui/aura/desktop.cc
+++ b/ui/aura/desktop.cc
@@ -18,7 +18,8 @@ namespace aura {
Desktop* Desktop::instance_ = NULL;
Desktop::Desktop()
- : host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1280, 1024))),
+ : toplevel_window_container_(NULL),
+ host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1280, 1024))),
ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_(this)) {
DCHECK(MessageLoopForUI::current())
<< "The UI message loop must be initialized first.";
diff --git a/ui/aura/desktop.h b/ui/aura/desktop.h
index aea93e1..41826c6d 100644
--- a/ui/aura/desktop.h
+++ b/ui/aura/desktop.h
@@ -58,6 +58,11 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate {
Window* window() { return window_.get(); }
+ Window* toplevel_window_container() { return toplevel_window_container_; }
+ void set_toplevel_window_container(Window* toplevel_window_container) {
+ toplevel_window_container_ = toplevel_window_container;
+ }
+
static Desktop* GetInstance();
private:
@@ -67,6 +72,7 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate {
scoped_refptr<ui::Compositor> compositor_;
scoped_ptr<internal::RootWindow> window_;
+ Window* toplevel_window_container_;
scoped_ptr<DesktopHost> host_;
diff --git a/ui/aura/event_filter.cc b/ui/aura/event_filter.cc
new file mode 100644
index 0000000..68748fb
--- /dev/null
+++ b/ui/aura/event_filter.cc
@@ -0,0 +1,19 @@
+// Copyright (c) 2011 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.
+
+#include "ui/aura/event_filter.h"
+
+namespace aura {
+
+EventFilter::EventFilter(Window* owner) : owner_(owner) {
+}
+
+EventFilter::~EventFilter() {
+}
+
+bool EventFilter::OnMouseEvent(Window* target, MouseEvent* event) {
+ return false;
+}
+
+} // namespace aura
diff --git a/ui/aura/window_manager.h b/ui/aura/event_filter.h
index af7563d..432c163 100644
--- a/ui/aura/window_manager.h
+++ b/ui/aura/event_filter.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef UI_AURA_WINDOW_MANAGER_H_
-#define UI_AURA_WINDOW_MANAGER_H_
+#ifndef UI_AURA_EVENT_FILTER_H_
+#define UI_AURA_EVENT_FILTER_H_
#pragma once
#include "base/logging.h"
@@ -16,32 +16,25 @@ class MouseEvent;
// An object that filters events sent to an owner window, potentially performing
// adjustments to the window's position, size and z-index.
-//
-// TODO(beng): Make this into an interface so we can have specializations for
-// different types of Window and product.
-class WindowManager {
+class EventFilter {
public:
- explicit WindowManager(Window* owner);
- ~WindowManager();
+ explicit EventFilter(Window* owner);
+ virtual ~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.
- bool OnMouseEvent(MouseEvent* event);
+ virtual bool OnMouseEvent(Window* target, MouseEvent* event);
- private:
- // Moves the owner window and all of its parents to the front of their
- // respective z-orders.
- void MoveWindowToFront();
+ protected:
+ Window* owner() { return owner_; }
+ private:
Window* owner_;
- gfx::Point mouse_down_offset_;
- gfx::Point window_location_;
- int window_component_;
- DISALLOW_COPY_AND_ASSIGN(WindowManager);
+ DISALLOW_COPY_AND_ASSIGN(EventFilter);
};
} // namespace aura
-#endif // UI_AURA_WINDOW_MANAGER_H_
+#endif // UI_AURA_EVENT_FILTER_H_
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 1f39440..93362ff 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -17,6 +17,7 @@ RootWindow::RootWindow()
: Window(NULL),
mouse_pressed_handler_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(focus_manager_(new FocusManager(this))) {
+ set_name(L"RootWindow");
}
RootWindow::~RootWindow() {
@@ -46,10 +47,6 @@ bool RootWindow::HandleKeyEvent(const KeyEvent& event) {
return false;
}
-bool RootWindow::IsTopLevelWindowContainer() const {
- return true;
-}
-
FocusManager* RootWindow::GetFocusManager() {
return focus_manager_.get();
}
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index a985ab2..d709ce3 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -27,7 +27,6 @@ class RootWindow : public Window {
bool HandleKeyEvent(const KeyEvent& event);
// Overridden from Window:
- virtual bool IsTopLevelWindowContainer() const OVERRIDE;
virtual FocusManager* GetFocusManager() OVERRIDE;
private:
diff --git a/ui/aura/toplevel_window_container.cc b/ui/aura/toplevel_window_container.cc
new file mode 100644
index 0000000..b040fcf
--- /dev/null
+++ b/ui/aura/toplevel_window_container.cc
@@ -0,0 +1,26 @@
+// Copyright (c) 2011 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.
+
+#include "ui/aura/toplevel_window_container.h"
+
+#include "ui/aura/toplevel_window_event_filter.h"
+
+namespace aura {
+namespace internal {
+
+ToplevelWindowContainer::ToplevelWindowContainer()
+ : Window(NULL) {
+ set_name(L"ToplevelWindowContainer");
+ SetEventFilter(new ToplevelWindowEventFilter(this));
+}
+
+ToplevelWindowContainer::~ToplevelWindowContainer() {
+}
+
+bool ToplevelWindowContainer::IsToplevelWindowContainer() const {
+ return true;
+}
+
+} // namespace internal
+} // namespace aura
diff --git a/ui/aura/toplevel_window_container.h b/ui/aura/toplevel_window_container.h
new file mode 100644
index 0000000..936fb3d
--- /dev/null
+++ b/ui/aura/toplevel_window_container.h
@@ -0,0 +1,32 @@
+// Copyright (c) 2011 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_AURA_TOPLEVEL_WINDOW_CONTAINER_H_
+#define UI_AURA_TOPLEVEL_WINDOW_CONTAINER_H_
+#pragma once
+
+#include "ui/aura/window.h"
+
+namespace aura {
+namespace internal {
+
+class FocusManager;
+
+// A Window subclass that groups top-level windows.
+class ToplevelWindowContainer : public Window {
+ public:
+ ToplevelWindowContainer();
+ virtual ~ToplevelWindowContainer();
+
+ // Overridden from Window:
+ virtual bool IsToplevelWindowContainer() const OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ToplevelWindowContainer);
+};
+
+} // namespace internal
+} // namespace aura
+
+#endif // UI_AURA_TOPLEVEL_WINDOW_CONTAINER_H_
diff --git a/ui/aura/window_manager.cc b/ui/aura/toplevel_window_event_filter.cc
index 3f5905c..bf4395f 100644
--- a/ui/aura/window_manager.cc
+++ b/ui/aura/toplevel_window_event_filter.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ui/aura/window_manager.h"
+#include "ui/aura/toplevel_window_event_filter.h"
#include "ui/aura/event.h"
#include "ui/aura/focus_manager.h"
@@ -15,32 +15,35 @@
namespace aura {
-WindowManager::WindowManager(Window* owner)
- : owner_(owner),
+ToplevelWindowEventFilter::ToplevelWindowEventFilter(Window* owner)
+ : EventFilter(owner),
window_component_(HTNOWHERE) {
}
-WindowManager::~WindowManager() {
+ToplevelWindowEventFilter::~ToplevelWindowEventFilter() {
}
-bool WindowManager::OnMouseEvent(MouseEvent* event) {
+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.
- owner_->GetFocusManager()->SetFocusedWindow(owner_);
+ target->GetFocusManager()->SetFocusedWindow(target);
window_component_ =
- owner_->delegate()->GetNonClientComponent(event->location());
- MoveWindowToFront();
+ target->delegate()->GetNonClientComponent(event->location());
+ MoveWindowToFront(target);
mouse_down_offset_ = event->location();
- window_location_ = owner_->bounds().origin();
+ window_location_ = target->bounds().origin();
+ if (window_component_ == HTCAPTION)
+ return true;
break;
case ui::ET_MOUSE_DRAGGED:
if (window_component_ == HTCAPTION) {
gfx::Point new_origin(event->location());
new_origin.Offset(-mouse_down_offset_.x(), -mouse_down_offset_.y());
- new_origin.Offset(owner_->bounds().x(), owner_->bounds().y());
- owner_->SetBounds(gfx::Rect(new_origin, owner_->bounds().size()), 0);
+ new_origin.Offset(target->bounds().x(), target->bounds().y());
+ target->SetBounds(gfx::Rect(new_origin, target->bounds().size()), 0);
return true;
}
break;
@@ -53,11 +56,13 @@ bool WindowManager::OnMouseEvent(MouseEvent* event) {
return false;
}
-void WindowManager::MoveWindowToFront() {
- Window* parent = owner_->parent();
- Window* child = owner_;
+void ToplevelWindowEventFilter::MoveWindowToFront(Window* target) {
+ Window* parent = target->parent();
+ Window* child = target;
while (parent) {
parent->MoveChildToFront(child);
+ if (parent == owner())
+ break;
parent = parent->parent();
child = child->parent();
}
diff --git a/ui/aura/toplevel_window_event_filter.h b/ui/aura/toplevel_window_event_filter.h
new file mode 100644
index 0000000..33cc092
--- /dev/null
+++ b/ui/aura/toplevel_window_event_filter.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2011 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_AURA_TOPLEVEL_WINDOW_EVENT_FILTER_H_
+#define UI_AURA_TOPLEVEL_WINDOW_EVENT_FILTER_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "ui/aura/event_filter.h"
+#include "ui/gfx/point.h"
+
+namespace aura {
+
+class Window;
+class MouseEvent;
+
+class ToplevelWindowEventFilter : public EventFilter {
+ public:
+ explicit ToplevelWindowEventFilter(Window* owner);
+ ~ToplevelWindowEventFilter();
+
+ // Overridden from EventFilter:
+ virtual bool OnMouseEvent(Window* target, MouseEvent* event) OVERRIDE;
+
+ private:
+ // Moves the target window and all of its parents to the front of their
+ // respective z-orders.
+ void MoveWindowToFront(Window* target);
+
+ gfx::Point mouse_down_offset_;
+ gfx::Point window_location_;
+ int window_component_;
+
+ DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventFilter);
+};
+
+} // namespace aura
+
+#endif // UI_AURA_TOPLEVEL_WINDOW_EVENT_FILTER_H_
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index fc9209c..412bd1a 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -9,10 +9,10 @@
#include "base/logging.h"
#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
+#include "ui/aura/event_filter.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window_delegate.h"
-#include "ui/aura/window_manager.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
@@ -55,7 +55,10 @@ Window::~Window() {
}
void Window::Init() {
- layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor()));
+ ui::Layer::TextureParam param = ui::Layer::LAYER_HAS_NO_TEXTURE;
+ if (delegate_)
+ param = ui::Layer::LAYER_HAS_TEXTURE;
+ layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor(), param));
layer_->set_delegate(this);
}
@@ -106,10 +109,10 @@ void Window::SetParent(Window* parent) {
if (parent)
parent->AddChild(this);
else
- Desktop::GetInstance()->window()->AddChild(this);
+ Desktop::GetInstance()->toplevel_window_container()->AddChild(this);
}
-bool Window::IsTopLevelWindowContainer() const {
+bool Window::IsToplevelWindowContainer() const {
return false;
}
@@ -148,10 +151,17 @@ void Window::ConvertPointToWindow(Window* source,
ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point);
}
+void Window::SetEventFilter(EventFilter* event_filter) {
+ event_filter_.reset(event_filter);
+}
+
bool Window::OnMouseEvent(MouseEvent* event) {
- if (!window_manager_.get())
- window_manager_.reset(new WindowManager(this));
- return window_manager_->OnMouseEvent(event) || delegate_->OnMouseEvent(event);
+ if (!parent_)
+ return false;
+ if (!parent_->event_filter_.get())
+ parent_->SetEventFilter(new EventFilter(parent_));
+ return parent_->event_filter_->OnMouseEvent(this, event) ||
+ delegate_->OnMouseEvent(event);
}
bool Window::OnKeyEvent(KeyEvent* event) {
@@ -172,10 +182,13 @@ Window* Window::GetEventHandlerForPoint(const gfx::Point& point) {
continue;
gfx::Point point_in_child_coords(point);
Window::ConvertPointToWindow(this, child, &point_in_child_coords);
- if (child->HitTest(point_in_child_coords))
- return child->GetEventHandlerForPoint(point_in_child_coords);
+ if (child->HitTest(point_in_child_coords)) {
+ Window* handler = child->GetEventHandlerForPoint(point_in_child_coords);
+ if (handler)
+ return handler;
+ }
}
- return this;
+ return delegate_ ? this : NULL;
}
internal::FocusManager* Window::GetFocusManager() {
@@ -187,8 +200,7 @@ void Window::SchedulePaint() {
}
void Window::OnPaintLayer(gfx::Canvas* canvas) {
- if (delegate_)
- delegate_->OnPaint(canvas);
+ delegate_->OnPaint(canvas);
}
} // namespace aura
diff --git a/ui/aura/window.h b/ui/aura/window.h
index 548991e..a0221c4 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "base/string16.h"
#include "ui/aura/aura_export.h"
#include "ui/gfx/compositor/layer_delegate.h"
#include "ui/gfx/rect.h"
@@ -28,7 +29,7 @@ class KeyEvent;
class LayoutManager;
class MouseEvent;
class WindowDelegate;
-class WindowManager;
+class EventFilter;
namespace internal {
class FocusManager;
@@ -59,6 +60,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
int id() const { return id_; }
void set_id(int id) { id_ = id; }
+ const string16& name() const { return name_; }
+ void set_name(const string16& name) { name_ = name; }
+
ui::Layer* layer() { return layer_.get(); }
const ui::Layer* layer() const { return layer_.get(); }
@@ -86,7 +90,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
Window* parent() { return parent_; }
// Returns true if this Window is the container for toplevel windows.
- virtual bool IsTopLevelWindowContainer() const;
+ virtual bool IsToplevelWindowContainer() const;
// Move the specified child of this Window to the front of the z-order.
// TODO(beng): this is (obviously) feeble.
@@ -102,6 +106,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
Window* target,
gfx::Point* point);
+ // Window takes ownership of the EventFilter.
+ void SetEventFilter(EventFilter* event_filter);
+
// Handles a mouse event. Returns true if handled.
bool OnMouseEvent(MouseEvent* event);
@@ -158,8 +165,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
Windows children_;
int id_;
+ string16 name_;
- scoped_ptr<WindowManager> window_manager_;
+ scoped_ptr<EventFilter> event_filter_;
scoped_ptr<LayoutManager> layout_manager_;
void* user_data_;