summaryrefslogtreecommitdiffstats
path: root/ui/aura
diff options
context:
space:
mode:
Diffstat (limited to 'ui/aura')
-rw-r--r--ui/aura/aura.gyp4
-rw-r--r--ui/aura/desktop.cc37
-rw-r--r--ui/aura/desktop.h21
-rw-r--r--ui/aura/desktop_delegate.h28
-rw-r--r--ui/aura/event_filter.cc2
-rw-r--r--ui/aura/test_desktop_delegate.cc32
-rw-r--r--ui/aura/test_desktop_delegate.h38
-rw-r--r--ui/aura/toplevel_window_container.cc21
-rw-r--r--ui/aura/toplevel_window_container.h11
-rw-r--r--ui/aura/window.cc147
-rw-r--r--ui/aura/window.h31
-rw-r--r--ui/aura/window_types.h20
-rw-r--r--ui/aura/window_unittest.cc26
13 files changed, 289 insertions, 129 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 47823ec..683fe6b 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -30,6 +30,7 @@
'desktop_host_win.h',
'desktop.cc',
'desktop.h',
+ 'desktop_delegate.h',
'event.cc',
'event.h',
'event_filter.cc',
@@ -46,6 +47,7 @@
'window.cc',
'window.h',
'window_delegate.h',
+ 'window_type.h',
],
},
{
@@ -91,6 +93,8 @@
'sources': [
'window_unittest.cc',
'run_all_unittests.cc',
+ 'test_desktop_delegate.cc',
+ 'test_desktop_delegate.h',
'test_suite.cc',
'test_suite.h',
'<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc',
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc
index 64f481f..e28fcf6 100644
--- a/ui/aura/desktop.cc
+++ b/ui/aura/desktop.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/message_loop.h"
+#include "ui/aura/desktop_delegate.h"
#include "ui/aura/desktop_host.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
@@ -24,13 +25,11 @@ Desktop* Desktop::instance_ = NULL;
ui::Compositor*(*Desktop::compositor_factory_)() = NULL;
Desktop::Desktop()
- : default_parent_(NULL),
+ : delegate_(NULL),
host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1280, 1024))),
ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_(this)),
active_window_(NULL),
in_destructor_(false) {
- DCHECK(MessageLoopForUI::current())
- << "The UI message loop must be initialized first.";
if (compositor_factory_) {
compositor_ = (*Desktop::compositor_factory())();
} else {
@@ -48,6 +47,10 @@ Desktop::~Desktop() {
instance_ = NULL;
}
+void Desktop::SetDelegate(DesktopDelegate* delegate) {
+ delegate_.reset(delegate);
+}
+
void Desktop::Init() {
window_->Init();
window_->SetBounds(gfx::Rect(gfx::Point(), host_->GetSize()));
@@ -55,15 +58,6 @@ void Desktop::Init() {
compositor()->SetRootLayer(window_->layer());
}
-void Desktop::CreateDefaultParentForTesting() {
- Window* default_parent = new internal::ToplevelWindowContainer;
- default_parent->Init();
- default_parent->SetBounds(window_->bounds());
- default_parent->Show();
- window_->AddChild(default_parent);
- set_default_parent(default_parent);
-}
-
void Desktop::Show() {
host_->Show();
}
@@ -132,7 +126,7 @@ void Desktop::SetActiveWindow(Window* window, Window* to_focus) {
}
void Desktop::ActivateTopmostWindow() {
- SetActiveWindow(GetTopmostWindowToActivate(NULL), NULL);
+ SetActiveWindow(delegate_->GetTopmostWindowToActivate(NULL), NULL);
}
void Desktop::Deactivate(Window* window) {
@@ -146,7 +140,8 @@ void Desktop::Deactivate(Window* window) {
if (active_window() != toplevel_ancestor)
return; // Top level ancestor is already not active.
- Window* to_activate = GetTopmostWindowToActivate(toplevel_ancestor);
+ Window* to_activate =
+ delegate_->GetTopmostWindowToActivate(toplevel_ancestor);
if (to_activate)
SetActiveWindow(to_activate, NULL);
}
@@ -158,25 +153,13 @@ void Desktop::WindowDestroying(Window* window) {
// Reset active_window_ before invoking SetActiveWindow so that we don't
// attempt to notify it while running its destructor.
active_window_ = NULL;
- SetActiveWindow(GetTopmostWindowToActivate(window), NULL);
+ SetActiveWindow(delegate_->GetTopmostWindowToActivate(window), NULL);
}
MessageLoop::Dispatcher* Desktop::GetDispatcher() {
return host_.get();
}
-
-Window* Desktop::GetTopmostWindowToActivate(Window* ignore) {
- Window::Windows windows(default_parent_->children());
- for (Window::Windows::const_reverse_iterator i = windows.rbegin();
- i != windows.rend(); ++i) {
- if (*i != ignore && (*i)->IsVisible() &&
- (!(*i)->delegate() || (*i)->delegate()->ShouldActivate(NULL)))
- return *i;
- }
- return NULL;
-}
-
// static
Desktop* Desktop::GetInstance() {
if (!instance_) {
diff --git a/ui/aura/desktop.h b/ui/aura/desktop.h
index b6ae942..4aebaa2 100644
--- a/ui/aura/desktop.h
+++ b/ui/aura/desktop.h
@@ -23,6 +23,7 @@ class Size;
namespace aura {
+class DesktopDelegate;
class DesktopHost;
class MouseEvent;
@@ -32,12 +33,12 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate {
Desktop();
~Desktop();
+ DesktopDelegate* delegate() { return delegate_.get(); }
+ void SetDelegate(DesktopDelegate* delegate);
+
// Initializes the desktop.
void Init();
- // Initializes |default_parent()| for testing.
- void CreateDefaultParentForTesting();
-
// Shows the desktop host.
void Show();
@@ -68,13 +69,6 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate {
Window* window() { return window_.get(); }
- // The window where windows created without an explicitly specified parent are
- // parented.
- Window* default_parent() { return default_parent_; }
- void set_default_parent(Window* default_parent) {
- default_parent_ = default_parent;
- }
-
static void set_compositor_factory_for_testing(ui::Compositor*(*factory)()) {
compositor_factory_ = factory;
}
@@ -108,18 +102,15 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate {
static Desktop* GetInstance();
private:
- // Returns the topmost window to activate. This ignores |ignore|.
- Window* GetTopmostWindowToActivate(Window* ignore);
-
// Overridden from ui::CompositorDelegate
virtual void ScheduleDraw();
+ scoped_ptr<DesktopDelegate> delegate_;
+
scoped_refptr<ui::Compositor> compositor_;
scoped_ptr<internal::RootWindow> window_;
- Window* default_parent_;
-
scoped_ptr<DesktopHost> host_;
static Desktop* instance_;
diff --git a/ui/aura/desktop_delegate.h b/ui/aura/desktop_delegate.h
new file mode 100644
index 0000000..b968670
--- /dev/null
+++ b/ui/aura/desktop_delegate.h
@@ -0,0 +1,28 @@
+// 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_DESKTOP_DELEGATE_H_
+#define UI_AURA_DESKTOP_DELEGATE_H_
+#pragma once
+
+namespace aura {
+
+class Window;
+
+class DesktopDelegate {
+ public:
+ virtual ~DesktopDelegate() {}
+
+ // Called by the Window when its parent is set to NULL. The delegate is given
+ // an opportunity to inspect the window and add it to a default parent window
+ // of its choosing.
+ virtual void AddChildToDefaultParent(Window* window) = 0;
+
+ // Returns the window that should be activated other than |ignore|.
+ virtual Window* GetTopmostWindowToActivate(Window* ignore) const = 0;
+};
+
+} // namespace aura
+
+#endif // UI_AURA_DESKTOP_DELEGATE_H_
diff --git a/ui/aura/event_filter.cc b/ui/aura/event_filter.cc
index b6d7289..b0d39a0 100644
--- a/ui/aura/event_filter.cc
+++ b/ui/aura/event_filter.cc
@@ -42,7 +42,7 @@ void EventFilter::ActivateIfNecessary(
Window* toplevel_window = window;
while (toplevel_window && toplevel_window != active_window &&
toplevel_window->parent() &&
- !toplevel_window->parent()->IsToplevelWindowContainer()) {
+ !toplevel_window->parent()->AsToplevelWindowContainer()) {
toplevel_window = toplevel_window->parent();
}
if (toplevel_window == active_window) {
diff --git a/ui/aura/test_desktop_delegate.cc b/ui/aura/test_desktop_delegate.cc
new file mode 100644
index 0000000..73df23f
--- /dev/null
+++ b/ui/aura/test_desktop_delegate.cc
@@ -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.
+
+#include "ui/aura/test_desktop_delegate.h"
+
+#include "ui/aura/desktop.h"
+
+namespace aura {
+
+TestDesktopDelegate::TestDesktopDelegate()
+ : default_container_(new ToplevelWindowContainer) {
+ Desktop::GetInstance()->SetDelegate(this);
+ default_container_->Init();
+ default_container_->SetBounds(
+ gfx::Rect(gfx::Point(), Desktop::GetInstance()->GetSize()));
+ Desktop::GetInstance()->window()->AddChild(default_container_.get());
+ default_container_->Show();
+}
+
+TestDesktopDelegate::~TestDesktopDelegate() {
+}
+
+void TestDesktopDelegate::AddChildToDefaultParent(Window* window) {
+ default_container_->AddChild(window);
+}
+
+Window* TestDesktopDelegate::GetTopmostWindowToActivate(Window* ignore) const {
+ return default_container_->GetTopmostWindowToActivate(ignore);
+}
+
+} // namespace aura
diff --git a/ui/aura/test_desktop_delegate.h b/ui/aura/test_desktop_delegate.h
new file mode 100644
index 0000000..3376b83
--- /dev/null
+++ b/ui/aura/test_desktop_delegate.h
@@ -0,0 +1,38 @@
+// 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_TEST_DESKTOP_DELEGATE_H_
+#define UI_AURA_TEST_DESKTOP_DELEGATE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/aura/desktop_delegate.h"
+#include "ui/aura/toplevel_window_container.h"
+
+namespace aura {
+
+class ToplevelWindowContainer;
+
+class TestDesktopDelegate : public DesktopDelegate {
+ public:
+ TestDesktopDelegate();
+ virtual ~TestDesktopDelegate();
+
+ Window* default_container() { return default_container_.get(); }
+
+ private:
+ // Overridden from DesktopDelegate:
+ virtual void AddChildToDefaultParent(Window* window) OVERRIDE;
+ virtual Window* GetTopmostWindowToActivate(Window* ignore) const OVERRIDE;
+
+ scoped_ptr<ToplevelWindowContainer> default_container_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestDesktopDelegate);
+};
+
+} // namespace aura
+
+#endif // UI_AURA_TEST_DESKTOP_DELEGATE_H_
diff --git a/ui/aura/toplevel_window_container.cc b/ui/aura/toplevel_window_container.cc
index e171d9e..eeb8f04 100644
--- a/ui/aura/toplevel_window_container.cc
+++ b/ui/aura/toplevel_window_container.cc
@@ -8,7 +8,6 @@
#include "ui/aura/toplevel_window_event_filter.h"
namespace aura {
-namespace internal {
ToplevelWindowContainer::ToplevelWindowContainer()
: Window(NULL) {
@@ -19,9 +18,23 @@ ToplevelWindowContainer::ToplevelWindowContainer()
ToplevelWindowContainer::~ToplevelWindowContainer() {
}
-bool ToplevelWindowContainer::IsToplevelWindowContainer() const {
- return true;
+Window* ToplevelWindowContainer::GetTopmostWindowToActivate(
+ Window* ignore) const {
+ for (Window::Windows::const_reverse_iterator i = children().rbegin();
+ i != children().rend(); ++i) {
+ Window* w = *i;
+ if (*i != ignore && (*i)->CanActivate())
+ return *i;
+ }
+ return NULL;
}
-} // namespace internal
+ToplevelWindowContainer* ToplevelWindowContainer::AsToplevelWindowContainer() {
+ return this;
+}
+
+const ToplevelWindowContainer*
+ ToplevelWindowContainer::AsToplevelWindowContainer() const {
+ return this;
+}
} // namespace aura
diff --git a/ui/aura/toplevel_window_container.h b/ui/aura/toplevel_window_container.h
index 0b1f058..67c537a 100644
--- a/ui/aura/toplevel_window_container.h
+++ b/ui/aura/toplevel_window_container.h
@@ -10,9 +10,6 @@
#include "ui/aura/aura_export.h"
namespace aura {
-namespace internal {
-
-class FocusManager;
// A Window subclass that groups top-level windows.
class AURA_EXPORT ToplevelWindowContainer : public Window {
@@ -20,14 +17,18 @@ class AURA_EXPORT ToplevelWindowContainer : public Window {
ToplevelWindowContainer();
virtual ~ToplevelWindowContainer();
+ // Returns the topmost window to activate, ignoring |ignore|.
+ Window* GetTopmostWindowToActivate(Window* ignore) const;
+
// Overridden from Window:
- virtual bool IsToplevelWindowContainer() const OVERRIDE;
+ virtual ToplevelWindowContainer* AsToplevelWindowContainer() OVERRIDE;
+ virtual const ToplevelWindowContainer*
+ AsToplevelWindowContainer() 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.cc b/ui/aura/window.cc
index c6a7986..a38bb4e 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -8,10 +8,12 @@
#include "base/logging.h"
#include "ui/aura/desktop.h"
+#include "ui/aura/desktop_delegate.h"
#include "ui/aura/event.h"
#include "ui/aura/event_filter.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window_delegate.h"
+#include "ui/aura/window_types.h"
#include "ui/base/animation/multi_animation.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/compositor.h"
@@ -23,7 +25,8 @@ namespace aura {
using internal::RootWindow;
Window::Window(WindowDelegate* delegate)
- : delegate_(delegate),
+ : type_(kWindowType_Toplevel),
+ delegate_(delegate),
show_state_(ui::SHOW_STATE_NORMAL),
parent_(NULL),
id_(-1),
@@ -68,6 +71,12 @@ void Window::Init() {
layer_->set_delegate(this);
}
+void Window::SetType(int type) {
+ // Cannot change type after the window is initialized.
+ DCHECK(!layer());
+ type_ = type;
+}
+
void Window::Show() {
SetVisible(true);
}
@@ -85,6 +94,45 @@ bool Window::IsVisible() const {
return layer_->IsDrawn();
}
+void Window::Maximize() {
+ if (UpdateShowStateAndRestoreBounds(ui::SHOW_STATE_MAXIMIZED))
+ SetBounds(gfx::Screen::GetMonitorWorkAreaNearestWindow(this));
+}
+
+void Window::Fullscreen() {
+ if (UpdateShowStateAndRestoreBounds(ui::SHOW_STATE_FULLSCREEN))
+ SetBounds(gfx::Screen::GetMonitorAreaNearestWindow(this));
+}
+
+void Window::Restore() {
+ if (show_state_ != ui::SHOW_STATE_NORMAL) {
+ show_state_ = ui::SHOW_STATE_NORMAL;
+ SetBounds(restore_bounds_);
+ restore_bounds_.SetRect(0, 0, 0, 0);
+ }
+}
+
+void Window::Activate() {
+ // If we support minimization need to ensure this restores the window first.
+ aura::Desktop::GetInstance()->SetActiveWindow(this, this);
+}
+
+void Window::Deactivate() {
+ aura::Desktop::GetInstance()->Deactivate(this);
+}
+
+bool Window::IsActive() const {
+ return aura::Desktop::GetInstance()->active_window() == this;
+}
+
+ToplevelWindowContainer* Window::AsToplevelWindowContainer() {
+ return NULL;
+}
+
+const ToplevelWindowContainer* Window::AsToplevelWindowContainer() const {
+ return NULL;
+}
+
void Window::SetLayoutManager(LayoutManager* layout_manager) {
layout_manager_.reset(layout_manager);
}
@@ -126,43 +174,10 @@ void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) {
void Window::SetParent(Window* parent) {
if (parent)
parent->AddChild(this);
+ else if (Desktop::GetInstance()->delegate())
+ Desktop::GetInstance()->delegate()->AddChildToDefaultParent(this);
else
- Desktop::GetInstance()->default_parent()->AddChild(this);
-}
-
-void Window::Maximize() {
- if (UpdateShowStateAndRestoreBounds(ui::SHOW_STATE_MAXIMIZED))
- SetBounds(gfx::Screen::GetMonitorWorkAreaNearestWindow(this));
-}
-
-void Window::Fullscreen() {
- if (UpdateShowStateAndRestoreBounds(ui::SHOW_STATE_FULLSCREEN))
- SetBounds(gfx::Screen::GetMonitorAreaNearestWindow(this));
-}
-
-void Window::Restore() {
- if (show_state_ != ui::SHOW_STATE_NORMAL) {
- show_state_ = ui::SHOW_STATE_NORMAL;
- SetBounds(restore_bounds_);
- restore_bounds_.SetRect(0, 0, 0, 0);
- }
-}
-
-void Window::Activate() {
- // If we support minimization need to ensure this restores the window first.
- aura::Desktop::GetInstance()->SetActiveWindow(this, this);
-}
-
-void Window::Deactivate() {
- aura::Desktop::GetInstance()->Deactivate(this);
-}
-
-bool Window::IsActive() const {
- return aura::Desktop::GetInstance()->active_window() == this;
-}
-
-bool Window::IsToplevelWindowContainer() const {
- return false;
+ NOTREACHED();
}
void Window::MoveChildToFront(Window* child) {
@@ -179,6 +194,10 @@ void Window::MoveChildToFront(Window* child) {
child->layer()->parent()->MoveToFront(child->layer());
}
+bool Window::CanActivate() const {
+ return IsVisible() && delegate_ && delegate_->ShouldActivate(NULL);
+}
+
void Window::AddChild(Window* child) {
DCHECK(std::find(children_.begin(), children_.end(), child) ==
children_.end());
@@ -198,11 +217,15 @@ void Window::RemoveChild(Window* child) {
}
Window* Window::GetChildById(int id) {
+ return const_cast<Window*>(const_cast<const Window*>(this)->GetChildById(id));
+}
+
+const Window* Window::GetChildById(int id) const {
Windows::const_iterator i;
for (i = children_.begin(); i != children_.end(); ++i) {
if ((*i)->id() == id)
return *i;
- Window* result = (*i)->GetChildById(id);
+ const Window* result = (*i)->GetChildById(id);
if (result)
return result;
}
@@ -233,25 +256,6 @@ bool Window::OnMouseEvent(MouseEvent* event) {
delegate_->OnMouseEvent(event);
}
-// For a given window, we determine its focusability by inspecting each sibling
-// after it (i.e. drawn in front of it in the z-order) to see if it stops
-// propagation of events that would otherwise be targeted at windows behind it.
-// We then perform this same check on every window up to the root.
-bool Window::CanFocus() const {
- // TODO(beng): Figure out how to consult the delegate wrt. focusability also.
- if (!IsVisible() || !parent_)
- return false;
-
- Windows::const_iterator i = std::find(parent_->children().begin(),
- parent_->children().end(),
- this);
- for (++i; i != parent_->children().end(); ++i) {
- if ((*i)->StopsEventPropagation())
- return false;
- }
- return parent_->CanFocus();
-}
-
bool Window::OnKeyEvent(KeyEvent* event) {
return delegate_->OnKeyEvent(event);
}
@@ -291,6 +295,25 @@ void Window::Blur() {
GetFocusManager()->SetFocusedWindow(NULL);
}
+// For a given window, we determine its focusability by inspecting each sibling
+// after it (i.e. drawn in front of it in the z-order) to see if it stops
+// propagation of events that would otherwise be targeted at windows behind it.
+// We then perform this same check on every window up to the root.
+bool Window::CanFocus() const {
+ // TODO(beng): Figure out how to consult the delegate wrt. focusability also.
+ if (!IsVisible() || !parent_)
+ return false;
+
+ Windows::const_iterator i = std::find(parent_->children().begin(),
+ parent_->children().end(),
+ this);
+ for (++i; i != parent_->children().end(); ++i) {
+ if ((*i)->StopsEventPropagation())
+ return false;
+ }
+ return parent_->CanFocus();
+}
+
internal::FocusManager* Window::GetFocusManager() {
return parent_ ? parent_->GetFocusManager() : NULL;
}
@@ -322,7 +345,7 @@ bool Window::HasCapture() {
Window* Window::GetToplevelWindow() {
Window* window = this;
while (window && window->parent() &&
- !window->parent()->IsToplevelWindowContainer())
+ !window->parent()->AsToplevelWindowContainer())
window = window->parent();
return window && window->parent() ? window : NULL;
}
@@ -356,10 +379,6 @@ bool Window::StopsEventPropagation() const {
return stops_event_propagation_ && !children_.empty();
}
-void Window::OnPaintLayer(gfx::Canvas* canvas) {
- delegate_->OnPaint(canvas);
-}
-
bool Window::UpdateShowStateAndRestoreBounds(
ui::WindowShowState new_show_state) {
if (show_state_ == new_show_state)
@@ -370,4 +389,8 @@ bool Window::UpdateShowStateAndRestoreBounds(
return true;
}
+void Window::OnPaintLayer(gfx::Canvas* canvas) {
+ delegate_->OnPaint(canvas);
+}
+
} // namespace aura
diff --git a/ui/aura/window.h b/ui/aura/window.h
index ad5d7bc..73cbd67 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -32,6 +32,7 @@ class EventFilter;
class KeyEvent;
class LayoutManager;
class MouseEvent;
+class ToplevelWindowContainer;
class WindowDelegate;
namespace internal {
@@ -51,6 +52,12 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
void Init();
+ // A type is used to identify a class of Windows and customize behavior such
+ // as event handling and parenting. The value can be any of those in
+ // window_types.h or a user defined value.
+ int type() const { return type_; }
+ void SetType(int type);
+
int id() const { return id_; }
void set_id(int id) { id_ = id; }
@@ -75,6 +82,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// Restore the wnidow to its original bounds.
void Restore();
+ // Returns the window's show state.
+ ui::WindowShowState show_state() const { return show_state_; }
+
// Activates this window. Only top level windows can be activated. Requests
// to activate a non-top level window are ignored.
void Activate();
@@ -86,8 +96,10 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// Returns true if this window is active.
bool IsActive() const;
- // Returns the window's show state.
- ui::WindowShowState show_state() const { return show_state_; }
+ // RTTI to a container for top-level windows. Returns NULL if this window is
+ // not a top level window container.
+ virtual ToplevelWindowContainer* AsToplevelWindowContainer();
+ virtual const ToplevelWindowContainer* AsToplevelWindowContainer() const;
// Assigns a LayoutManager to size and place child windows.
// The Window takes ownership of the LayoutManager.
@@ -108,13 +120,13 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
void SetParent(Window* parent);
Window* parent() { return parent_; }
- // Returns true if this Window is the container for toplevel windows.
- virtual bool IsToplevelWindowContainer() const;
-
// Move the specified child of this Window to the front of the z-order.
// TODO(beng): this is (obviously) feeble.
void MoveChildToFront(Window* child);
+ // Returns true if this window can be activated.
+ bool CanActivate() const;
+
// Tree operations.
// TODO(beng): Child windows are currently not owned by the hierarchy. We
// should change this.
@@ -126,6 +138,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// Retrieves the first-level child with the specified id, or NULL if no first-
// level child is found matching |id|.
Window* GetChildById(int id);
+ const Window* GetChildById(int id) const;
static void ConvertPointToWindow(Window* source,
Window* target,
@@ -214,13 +227,15 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// it in the z-order.
bool StopsEventPropagation() const;
- // Overridden from ui::LayerDelegate:
- virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
-
// Update the show state and restore bounds. Returns false
// if |new_show_state| is same as current show state.
bool UpdateShowStateAndRestoreBounds(ui::WindowShowState new_show_state);
+ // Overridden from ui::LayerDelegate:
+ virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
+
+ int type_;
+
WindowDelegate* delegate_;
ui::WindowShowState show_state_;
diff --git a/ui/aura/window_types.h b/ui/aura/window_types.h
new file mode 100644
index 0000000..8b14184
--- /dev/null
+++ b/ui/aura/window_types.h
@@ -0,0 +1,20 @@
+// 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_WINDOW_TYPES_H_
+#define UI_AURA_WINDOW_TYPES_H_
+#pragma once
+
+namespace aura {
+
+const int kWindowType_Toplevel = 0;
+const int kWindowType_Control = 1;
+const int kWindowType_Menu = 2;
+const int kWindowType_Tooltip = 3;
+
+const int kWindowType_Max = 4;
+
+} // namespace aura
+
+#endif // UI_AURA_WINDOW_TYPES_H_
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 87f7ca9..ebb2cdf 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -10,6 +10,7 @@
#include "ui/aura/event.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
+#include "ui/aura/test_desktop_delegate.h"
#include "ui/aura/window_delegate.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/layer.h"
@@ -174,11 +175,11 @@ class TestWindowDelegate : public WindowDelegateImpl {
class WindowTest : public testing::Test {
public:
- WindowTest() : main_message_loop(MessageLoop::TYPE_UI) {
+ WindowTest()
+ : main_message_loop(MessageLoop::TYPE_UI),
+ desktop_delegate_(new TestDesktopDelegate) {
Desktop::GetInstance()->Show();
Desktop::GetInstance()->SetSize(gfx::Size(500, 500));
- if (!Desktop::GetInstance()->default_parent())
- Desktop::GetInstance()->CreateDefaultParentForTesting();
}
virtual ~WindowTest() {}
@@ -214,8 +215,14 @@ class WindowTest : public testing::Test {
return window;
}
+ protected:
+ Window* toplevel_container() {
+ return desktop_delegate_->default_container();
+ }
+
private:
MessageLoop main_message_loop;
+ TestDesktopDelegate* desktop_delegate_;
DISALLOW_COPY_AND_ASSIGN(WindowTest);
};
@@ -266,7 +273,7 @@ TEST_F(WindowTest, GetEventHandlerForPoint) {
CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get()));
Window* desktop = Desktop::GetInstance()->window();
- Desktop::GetInstance()->default_parent()->SetBounds(gfx::Rect(500, 500));
+ toplevel_container()->SetBounds(gfx::Rect(500, 500));
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)));
@@ -741,9 +748,14 @@ TEST_F(WindowTest, Maximized) {
// Various assertions for activating/deactivating.
TEST_F(WindowTest, Deactivate) {
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
- scoped_ptr<Window> w2(CreateTestWindowWithId(2, NULL));
+ WindowDelegateImpl d1;
+ WindowDelegateImpl d2;
+ scoped_ptr<Window> w1(
+ CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL));
+ scoped_ptr<Window> w2(
+ CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL));
Window* parent = w1->parent();
+ parent->Show();
ASSERT_TRUE(parent);
ASSERT_EQ(2u, parent->children().size());
// Activate w2 and make sure it's active and frontmost.
@@ -758,7 +770,7 @@ TEST_F(WindowTest, Deactivate) {
EXPECT_FALSE(w2->IsActive());
EXPECT_EQ(w1.get(), parent->children()[1]);
- // Dectivate w1 and make sure w2 becomes active and frontmost.
+ // Deactivate w1 and make sure w2 becomes active and frontmost.
w1->Deactivate();
EXPECT_FALSE(w1->IsActive());
EXPECT_TRUE(w2->IsActive());