summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 21:02:59 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 21:02:59 +0000
commit87b0d82e3a7323306b3a5b7c94a01226ab601254 (patch)
tree54f9d25c8e9e71ba1fb2bdbbfad23d7e94f46190
parent39944f52a7d6495574b27443f9d935a76c5d488a (diff)
downloadchromium_src-87b0d82e3a7323306b3a5b7c94a01226ab601254.zip
chromium_src-87b0d82e3a7323306b3a5b7c94a01226ab601254.tar.gz
chromium_src-87b0d82e3a7323306b3a5b7c94a01226ab601254.tar.bz2
Changes the way windows are parented when their parent is set to NULL.. Adds a DesktopDelegate interface implemented by the aura client. The implementor handles parenting of windows when their parent is set to NULL, and also figures out how to activate windows.. Replaces Desktop::default_parent() with this. Requires adjusting some of the tests and adding a TestDesktopDelegate implementation that reconstructs what default_parent did.BUG=noneTEST=existing unit tests
Review URL: http://codereview.chromium.org/8194004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104558 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chrome_browser_main.cc6
-rw-r--r--chrome/browser/ui/views/aura/aura_init.cc15
-rw-r--r--chrome/browser/ui/views/aura/aura_init.h16
-rw-r--r--chrome/chrome_browser.gypi2
-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
-rw-r--r--ui/aura_shell/aura_shell.gyp2
-rw-r--r--ui/aura_shell/aura_shell_main.cc4
-rw-r--r--ui/aura_shell/desktop_background_view.cc6
-rw-r--r--ui/aura_shell/desktop_window.cc6
-rw-r--r--ui/aura_shell/launcher/launcher_view.cc13
-rw-r--r--ui/aura_shell/shell.cc116
-rw-r--r--ui/aura_shell/shell.h44
-rw-r--r--ui/aura_shell/shell_factory.h4
-rw-r--r--ui/aura_shell/shell_window_ids.h3
-rw-r--r--ui/aura_shell/status_area_view.cc5
-rw-r--r--views/bubble/bubble_delegate_unittest.cc9
-rw-r--r--views/bubble/bubble_frame_view_unittest.cc14
-rw-r--r--views/bubble/bubble_view_unittest.cc15
-rw-r--r--views/test/views_test_base.cc6
-rw-r--r--views/views.gyp7
-rw-r--r--views/widget/native_widget_aura.cc31
33 files changed, 539 insertions, 203 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 452974f..e15fe6f 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -202,8 +202,7 @@
#if defined(USE_AURA)
#include "ui/aura/desktop.h"
-#include "ui/aura_shell/shell_factory.h"
-#include "ui/aura/desktop.h"
+#include "ui/aura_shell/shell.h"
#endif
namespace net {
@@ -1368,7 +1367,8 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunInternal() {
child_process_logging::SetCommandLine(CommandLine::ForCurrentProcess());
#if defined(USE_AURA)
- aura_shell::InitDesktopWindow();
+ aura_shell::Shell* shell = new aura_shell::Shell;
+ shell->Init();
#elif defined(TOOLKIT_VIEWS)
views::Widget::SetPureViews(
CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePureViews));
diff --git a/chrome/browser/ui/views/aura/aura_init.cc b/chrome/browser/ui/views/aura/aura_init.cc
deleted file mode 100644
index 571176c..0000000
--- a/chrome/browser/ui/views/aura/aura_init.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-// 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 "chrome/browser/ui/views/aura/aura_init.h"
-
-#include "ui/aura_shell/shell_factory.h"
-
-namespace browser {
-
-void InitAuraDesktop() {
- aura_shell::InitDesktopWindow();
-}
-
-} // namespace browser
diff --git a/chrome/browser/ui/views/aura/aura_init.h b/chrome/browser/ui/views/aura/aura_init.h
deleted file mode 100644
index d516e67..0000000
--- a/chrome/browser/ui/views/aura/aura_init.h
+++ /dev/null
@@ -1,16 +0,0 @@
-// 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 CHROME_BROWSER_UI_VIEWS_AURA_AURA_INIT_H_
-#define CHROME_BROWSER_UI_VIEWS_AURA_AURA_INIT_H_
-#pragma once
-
-namespace browser {
-
-// Creates and shows the Aura Desktop. Called from BrowserMain().
-void InitAuraDesktop();
-
-}
-
-#endif // CHROME_BROWSER_UI_VIEWS_AURA_AURA_INIT_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 9c656e3..6378c61 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -3179,8 +3179,6 @@
'browser/ui/views/app_menu_button_win.h',
'browser/ui/views/appcache_info_view.cc',
'browser/ui/views/appcache_info_view.h',
- 'browser/ui/views/aura/aura_init.cc',
- 'browser/ui/views/aura/aura_init.h',
'browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc',
'browser/ui/views/autocomplete/autocomplete_popup_contents_view.h',
'browser/ui/views/autocomplete/autocomplete_result_view.cc',
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());
diff --git a/ui/aura_shell/aura_shell.gyp b/ui/aura_shell/aura_shell.gyp
index edd2d1f..cbae29f 100644
--- a/ui/aura_shell/aura_shell.gyp
+++ b/ui/aura_shell/aura_shell.gyp
@@ -39,6 +39,8 @@
'launcher/launcher_view.h',
'launcher/launcher_button.cc',
'launcher/launcher_button.h',
+ 'shell.cc',
+ 'shell.h',
'shell_factory.h',
'shell_window_ids.h',
'status_area_view.cc',
diff --git a/ui/aura_shell/aura_shell_main.cc b/ui/aura_shell/aura_shell_main.cc
index baa1f67..e0bc660 100644
--- a/ui/aura_shell/aura_shell_main.cc
+++ b/ui/aura_shell/aura_shell_main.cc
@@ -8,6 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "ui/aura/desktop.h"
+#include "ui/aura_shell/shell.h"
#include "ui/aura_shell/shell_factory.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
@@ -25,7 +26,8 @@ int main(int argc, char** argv) {
// Create the message-loop here before creating the desktop.
MessageLoop message_loop(MessageLoop::TYPE_UI);
- aura_shell::InitDesktopWindow();
+ aura_shell::Shell shell;
+ shell.Init();
aura_shell::examples::InitWindowTypeLauncher();
diff --git a/ui/aura_shell/desktop_background_view.cc b/ui/aura_shell/desktop_background_view.cc
index 3769881..f4acf63 100644
--- a/ui/aura_shell/desktop_background_view.cc
+++ b/ui/aura_shell/desktop_background_view.cc
@@ -8,6 +8,7 @@
#include "grit/ui_resources.h"
#include "ui/aura/desktop.h"
#include "ui/aura_shell/aura_shell_export.h"
+#include "ui/aura_shell/shell_window_ids.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "views/widget/widget.h"
@@ -33,10 +34,11 @@ void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {
canvas->TileImageInt(wallpaper_, 0, 0, width(), height());
}
-AURA_SHELL_EXPORT views::Widget* CreateDesktopBackground() {
+views::Widget* CreateDesktopBackground() {
views::Widget* desktop_widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
- params.bounds = gfx::Rect(0, 0, 1024, 768);
+ params.parent = aura::Desktop::GetInstance()->window()->GetChildById(
+ aura_shell::internal::kShellWindowId_DesktopBackgroundContainer);
DesktopBackgroundView* view = new DesktopBackgroundView;
params.delegate = view;
desktop_widget->Init(params);
diff --git a/ui/aura_shell/desktop_window.cc b/ui/aura_shell/desktop_window.cc
index 373f647..616ba28 100644
--- a/ui/aura_shell/desktop_window.cc
+++ b/ui/aura_shell/desktop_window.cc
@@ -21,13 +21,11 @@ void CreateSpecialContainers(aura::Window::Windows* containers) {
internal::kShellWindowId_DesktopBackgroundContainer);
containers->push_back(background_container);
- aura::Window* default_container = new aura::internal::ToplevelWindowContainer;
+ aura::Window* default_container = new aura::ToplevelWindowContainer;
default_container->set_id(internal::kShellWindowId_DefaultContainer);
- aura::Desktop::GetInstance()->set_default_parent(default_container);
containers->push_back(default_container);
- aura::Window* always_on_top_container =
- new aura::internal::ToplevelWindowContainer;
+ aura::Window* always_on_top_container = new aura::ToplevelWindowContainer;
always_on_top_container->set_id(
internal::kShellWindowId_AlwaysOnTopContainer);
containers->push_back(always_on_top_container);
diff --git a/ui/aura_shell/launcher/launcher_view.cc b/ui/aura_shell/launcher/launcher_view.cc
index 4bc81c5..c685ae1 100644
--- a/ui/aura_shell/launcher/launcher_view.cc
+++ b/ui/aura_shell/launcher/launcher_view.cc
@@ -8,6 +8,7 @@
#include "ui/aura/desktop.h"
#include "ui/aura_shell/aura_shell_export.h"
#include "ui/aura_shell/launcher/launcher_button.h"
+#include "ui/aura_shell/shell_window_ids.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/compositor/layer.h"
#include "views/widget/widget.h"
@@ -36,13 +37,15 @@ void LauncherView::ButtonPressed(views::Button* sender,
const views::Event& event) {
}
-AURA_SHELL_EXPORT views::Widget* CreateLauncher() {
+views::Widget* CreateLauncher() {
views::Widget* launcher_widget = new views::Widget;
- views::Widget::InitParams params2(views::Widget::InitParams::TYPE_CONTROL);
- params2.bounds = gfx::Rect(0, 0, 300, 64);
+ views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
+ params.bounds = gfx::Rect(0, 0, 300, 64);
+ params.parent = aura::Desktop::GetInstance()->window()->GetChildById(
+ aura_shell::internal::kShellWindowId_LauncherContainer);
LauncherView* launcher_view = new LauncherView;
- params2.delegate = launcher_view;
- launcher_widget->Init(params2);
+ params.delegate = launcher_view;
+ launcher_widget->Init(params);
launcher_widget->GetNativeWindow()->layer()->SetOpacity(0.2f);
launcher_widget->SetContentsView(launcher_view);
launcher_widget->Show();
diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc
new file mode 100644
index 0000000..a0958db
--- /dev/null
+++ b/ui/aura_shell/shell.cc
@@ -0,0 +1,116 @@
+// 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_shell/shell.h"
+
+#include "ui/aura/desktop.h"
+#include "ui/aura/toplevel_window_container.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_types.h"
+#include "ui/aura_shell/desktop_layout_manager.h"
+#include "ui/aura_shell/shell_factory.h"
+#include "ui/aura_shell/shell_window_ids.h"
+#include "views/widget/widget.h"
+
+namespace aura_shell {
+
+namespace {
+// Creates each of the special window containers that holds windows of various
+// types in the shell UI. They are added to |containers| from back to front in
+// the z-index.
+void CreateSpecialContainers(aura::Window::Windows* containers) {
+ aura::Window* background_container = new aura::Window(NULL);
+ background_container->set_id(
+ internal::kShellWindowId_DesktopBackgroundContainer);
+ containers->push_back(background_container);
+
+ aura::Window* default_container = new aura::ToplevelWindowContainer;
+ default_container->set_id(internal::kShellWindowId_DefaultContainer);
+ containers->push_back(default_container);
+
+ aura::Window* always_on_top_container = new aura::ToplevelWindowContainer;
+ always_on_top_container->set_id(
+ internal::kShellWindowId_AlwaysOnTopContainer);
+ containers->push_back(always_on_top_container);
+
+ aura::Window* launcher_container = new aura::Window(NULL);
+ launcher_container->set_id(internal::kShellWindowId_LauncherContainer);
+ containers->push_back(launcher_container);
+
+ aura::Window* lock_container = new aura::Window(NULL);
+ lock_container->set_stops_event_propagation(true);
+ lock_container->set_id(internal::kShellWindowId_LockScreenContainer);
+ containers->push_back(lock_container);
+
+ aura::Window* status_container = new aura::Window(NULL);
+ status_container->set_id(internal::kShellWindowId_StatusContainer);
+ containers->push_back(status_container);
+
+ aura::Window* menu_container = new aura::Window(NULL);
+ menu_container->set_id(internal::kShellWindowId_MenusAndTooltipsContainer);
+ containers->push_back(menu_container);
+}
+} // namespace
+
+Shell::Shell() {
+ aura::Desktop::GetInstance()->SetDelegate(this);
+}
+
+Shell::~Shell() {
+}
+
+void Shell::Init() {
+ aura::Window::Windows containers;
+ CreateSpecialContainers(&containers);
+ aura::Window::Windows::const_iterator i;
+ for (i = containers.begin(); i != containers.end(); ++i) {
+ (*i)->Init();
+ aura::Desktop::GetInstance()->window()->AddChild(*i);
+ (*i)->Show();
+ }
+
+ aura::Window* root_window = aura::Desktop::GetInstance()->window();
+ internal::DesktopLayoutManager* desktop_layout =
+ new internal::DesktopLayoutManager(root_window);
+ root_window->SetLayoutManager(desktop_layout);
+
+ desktop_layout->set_background_widget(internal::CreateDesktopBackground());
+ desktop_layout->set_launcher_widget(internal::CreateLauncher());
+ desktop_layout->set_status_area_widget(internal::CreateStatusArea());
+}
+
+aura::Window* Shell::GetContainer(int container_id) {
+ return const_cast<aura::Window*>(
+ const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id));
+}
+
+const aura::Window* Shell::GetContainer(int container_id) const {
+ return aura::Desktop::GetInstance()->window()->GetChildById(container_id);
+}
+
+void Shell::AddChildToDefaultParent(aura::Window* window) {
+ aura::Window* parent = NULL;
+ switch (window->type()) {
+ case aura::kWindowType_Toplevel:
+ parent = GetContainer(internal::kShellWindowId_DefaultContainer);
+ break;
+ case aura::kWindowType_Menu:
+ case aura::kWindowType_Tooltip:
+ parent = GetContainer(internal::kShellWindowId_MenusAndTooltipsContainer);
+ break;
+ default:
+ // This will crash for controls, since they can't be parented to anything.
+ break;
+ }
+ parent->AddChild(window);
+}
+
+aura::Window* Shell::GetTopmostWindowToActivate(aura::Window* ignore) const {
+ const aura::ToplevelWindowContainer* container =
+ GetContainer(internal::kShellWindowId_DefaultContainer)->
+ AsToplevelWindowContainer();
+ return container->GetTopmostWindowToActivate(ignore);
+}
+
+} // namespace aura_shell
diff --git a/ui/aura_shell/shell.h b/ui/aura_shell/shell.h
new file mode 100644
index 0000000..1b67eaa
--- /dev/null
+++ b/ui/aura_shell/shell.h
@@ -0,0 +1,44 @@
+// 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_SHELL_SHELL_H_
+#define UI_AURA_SHELL_SHELL_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/aura/desktop_delegate.h"
+
+namespace aura {
+class Window;
+}
+
+namespace aura_shell {
+
+// Shell is a singleton object that presents the Shell API and implements the
+// Desktop's delegate interface.
+class Shell : public aura::DesktopDelegate {
+ public:
+ // Upon creation, the Shell sets itself as the Desktop's delegate, which takes
+ // ownership of the Shell.
+ Shell();
+ virtual ~Shell();
+
+ void Init();
+
+ private:
+ aura::Window* GetContainer(int container_id);
+ const aura::Window* GetContainer(int container_id) const;
+
+ // Overridden from aura::DesktopDelegate:
+ virtual void AddChildToDefaultParent(aura::Window* window) OVERRIDE;
+ virtual aura::Window* GetTopmostWindowToActivate(
+ aura::Window* ignore) const OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(Shell);
+};
+
+} // namespace aura_shell
+
+#endif // UI_AURA_SHELL_SHELL_H_
diff --git a/ui/aura_shell/shell_factory.h b/ui/aura_shell/shell_factory.h
index cc539ab..2d58a92 100644
--- a/ui/aura_shell/shell_factory.h
+++ b/ui/aura_shell/shell_factory.h
@@ -6,8 +6,6 @@
#define UI_AURA_SHELL_SHELL_FACTORY_H_
#pragma once
-#include "ui/aura_shell/aura_shell_export.h"
-
namespace views {
class Widget;
}
@@ -16,8 +14,6 @@ class Widget;
namespace aura_shell {
-AURA_SHELL_EXPORT void InitDesktopWindow();
-
namespace examples {
void InitWindowTypeLauncher();
} // namespace examples
diff --git a/ui/aura_shell/shell_window_ids.h b/ui/aura_shell/shell_window_ids.h
index 06c3eef..f62b82b 100644
--- a/ui/aura_shell/shell_window_ids.h
+++ b/ui/aura_shell/shell_window_ids.h
@@ -30,6 +30,9 @@ const int kShellWindowId_LockScreenContainer = 4;
// The container for the status area.
const int kShellWindowId_StatusContainer = 5;
+// The container for menus and tooltips.
+const int kShellWindowId_MenusAndTooltipsContainer = 6;
+
} // namespace internal
} // namespace aura_shell
diff --git a/ui/aura_shell/status_area_view.cc b/ui/aura_shell/status_area_view.cc
index 61397cd..c4cea33 100644
--- a/ui/aura_shell/status_area_view.cc
+++ b/ui/aura_shell/status_area_view.cc
@@ -8,6 +8,7 @@
#include "grit/ui_resources.h"
#include "ui/aura/desktop.h"
#include "ui/aura_shell/aura_shell_export.h"
+#include "ui/aura_shell/shell_window_ids.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "views/widget/widget.h"
@@ -30,12 +31,14 @@ void StatusAreaView::OnPaint(gfx::Canvas* canvas) {
canvas->DrawBitmapInt(status_mock_, 0, 0);
}
-AURA_SHELL_EXPORT views::Widget* CreateStatusArea() {
+views::Widget* CreateStatusArea() {
StatusAreaView* status_area_view = new StatusAreaView;
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
gfx::Size ps = status_area_view->GetPreferredSize();
params.bounds = gfx::Rect(0, 0, ps.width(), ps.height());
+ params.parent = aura::Desktop::GetInstance()->window()->GetChildById(
+ aura_shell::internal::kShellWindowId_StatusContainer);
params.delegate = status_area_view;
widget->Init(params);
widget->SetContentsView(status_area_view);
diff --git a/views/bubble/bubble_delegate_unittest.cc b/views/bubble/bubble_delegate_unittest.cc
index c8a05e8..b7de55a 100644
--- a/views/bubble/bubble_delegate_unittest.cc
+++ b/views/bubble/bubble_delegate_unittest.cc
@@ -3,19 +3,21 @@
// found in the LICENSE file.
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop.h"
#include "third_party/skia/include/core/SkColor.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/animation/slide_animation.h"
#include "views/bubble/bubble_border.h"
#include "views/bubble/bubble_delegate.h"
#include "views/bubble/bubble_view.h"
+#include "views/test/views_test_base.h"
#include "views/widget/widget.h"
namespace views {
namespace {
+typedef ViewsTestBase BubbleDelegateTest;
+
class TestBubbleDelegate : public BubbleDelegateView {
public:
explicit TestBubbleDelegate(Widget *frame): BubbleDelegateView(frame) {}
@@ -29,8 +31,7 @@ class TestBubbleDelegate : public BubbleDelegateView {
View view_;
};
-TEST(BubbleDelegateTest, CreateDelegate) {
- MessageLoopForUI message_loop;
+TEST_F(BubbleDelegateTest, CreateDelegate) {
scoped_ptr<Widget> bubble_widget(new Widget());
Widget::InitParams params(Widget::InitParams::TYPE_BUBBLE);
TestBubbleDelegate delegate(bubble_widget.get());
@@ -41,7 +42,7 @@ TEST(BubbleDelegateTest, CreateDelegate) {
EXPECT_EQ(bubble_widget, delegate.GetWidget());
bubble_widget->CloseNow();
bubble_widget.reset(NULL);
- MessageLoop::current()->RunAllPending();
+ RunPendingMessages();
}
} // namespace
diff --git a/views/bubble/bubble_frame_view_unittest.cc b/views/bubble/bubble_frame_view_unittest.cc
index b7153bd..d5cd874 100644
--- a/views/bubble/bubble_frame_view_unittest.cc
+++ b/views/bubble/bubble_frame_view_unittest.cc
@@ -9,20 +9,23 @@
#include "views/bubble/bubble_border.h"
#include "views/bubble/bubble_frame_view.h"
#include "views/bubble/bubble_delegate.h"
+#include "views/test/views_test_base.h"
#include "views/widget/widget.h"
#if !defined(OS_WIN)
#include "views/window/hit_test.h"
#endif
+
namespace views {
namespace {
+typedef ViewsTestBase BubbleFrameViewBasicTest;
+
gfx::Rect kBound = gfx::Rect(10, 10, 200, 200);
SkColor kBackgroundColor = SK_ColorRED;
BubbleBorder::ArrowLocation kArrow = BubbleBorder::LEFT_BOTTOM;
-TEST(BubbleFrameViewBasicTest, GetBoundsForClientView) {
- MessageLoopForUI message_loop;
+TEST_F(BubbleFrameViewBasicTest, GetBoundsForClientView) {
scoped_ptr<Widget> widget(new views::Widget());
views::Widget::InitParams params(views::Widget::InitParams::TYPE_BUBBLE);
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
@@ -40,7 +43,7 @@ TEST(BubbleFrameViewBasicTest, GetBoundsForClientView) {
EXPECT_EQ(expected_insets.top(), frame.GetBoundsForClientView().y());
widget->CloseNow();
widget.reset(NULL);
- MessageLoop::current()->RunAllPending();
+ RunPendingMessages();
}
class TestBubbleDelegate : public BubbleDelegateView {
@@ -54,8 +57,7 @@ class TestBubbleDelegate : public BubbleDelegateView {
View view_;
};
-TEST(BubbleFrameViewBasicTest, NonClientHitTest) {
- MessageLoopForUI message_loop;
+TEST_F(BubbleFrameViewBasicTest, NonClientHitTest) {
scoped_ptr<Widget> widget(new Widget());
views::Widget::InitParams params(views::Widget::InitParams::TYPE_BUBBLE);
TestBubbleDelegate delegate(widget.get());
@@ -69,7 +71,7 @@ TEST(BubbleFrameViewBasicTest, NonClientHitTest) {
widget->non_client_view()->NonClientHitTest(kPtOutsideBound));
widget->CloseNow();
widget.reset(NULL);
- MessageLoop::current()->RunAllPending();
+ RunPendingMessages();
}
} // namespace
diff --git a/views/bubble/bubble_view_unittest.cc b/views/bubble/bubble_view_unittest.cc
index d64fbb6..9fac7f4 100644
--- a/views/bubble/bubble_view_unittest.cc
+++ b/views/bubble/bubble_view_unittest.cc
@@ -9,12 +9,16 @@
#include "views/bubble/bubble_border.h"
#include "views/bubble/bubble_delegate.h"
#include "views/bubble/bubble_view.h"
+#include "views/test/views_test_base.h"
#include "views/widget/widget.h"
namespace views {
namespace {
+typedef ViewsTestBase BubbleViewBasicTest;
+typedef ViewsTestBase BubbleViewTest;
+
class TestBubbleDelegate : public BubbleDelegateView {
public:
explicit TestBubbleDelegate(Widget *frame): BubbleDelegateView(frame) {}
@@ -42,8 +46,7 @@ class TestAnimationDelegate : public ui::AnimationDelegate {
};
-TEST(BubbleViewBasicTest, CreateArrowBubble) {
- MessageLoopForUI message_loop;
+TEST_F(BubbleViewBasicTest, CreateArrowBubble) {
scoped_ptr<Widget> bubble_widget(new Widget());
Widget::InitParams params(Widget::InitParams::TYPE_BUBBLE);
TestBubbleDelegate delegate(bubble_widget.get());
@@ -57,14 +60,12 @@ TEST(BubbleViewBasicTest, CreateArrowBubble) {
EXPECT_EQ(delegate.GetFrameArrowLocation(), border->arrow_location());
bubble_widget->CloseNow();
bubble_widget.reset(NULL);
- MessageLoop::current()->RunAllPending();
+ RunPendingMessages();
}
} // namespace
-TEST(BubbleViewTest, FadeAnimation) {
- MessageLoopForUI message_loop;
-
+TEST_F(BubbleViewTest, FadeAnimation) {
scoped_ptr<Widget> bubble_widget(new Widget());
Widget::InitParams params(Widget::InitParams::TYPE_BUBBLE);
TestBubbleDelegate delegate(bubble_widget.get());
@@ -84,7 +85,7 @@ TEST(BubbleViewTest, FadeAnimation) {
EXPECT_EQ(1, test_animation_delegate.animation_ended_);
bubble_widget->CloseNow();
bubble_widget.reset(NULL);
- MessageLoop::current()->RunAllPending();
+ RunPendingMessages();
}
} // namespace views
diff --git a/views/test/views_test_base.cc b/views/test/views_test_base.cc
index ae20b43..bbd8e75 100644
--- a/views/test/views_test_base.cc
+++ b/views/test/views_test_base.cc
@@ -13,6 +13,7 @@
#if defined(USE_AURA)
#include "ui/aura/desktop.h"
+#include "ui/aura/test_desktop_delegate.h"
#endif
namespace views {
@@ -27,6 +28,9 @@ ViewsTestBase::ViewsTestBase()
#if defined(OS_WIN)
OleInitialize(NULL);
#endif
+#if defined(USE_AURA)
+ new aura::TestDesktopDelegate;
+#endif
}
ViewsTestBase::~ViewsTestBase() {
@@ -44,8 +48,6 @@ void ViewsTestBase::SetUp() {
setup_called_ = true;
#if defined(USE_AURA)
aura::Desktop::set_compositor_factory_for_testing(&TestCreateCompositor);
- if (!aura::Desktop::GetInstance()->default_parent())
- aura::Desktop::GetInstance()->CreateDefaultParentForTesting();
#else
Widget::set_compositor_factory_for_testing(&TestCreateCompositor);
#endif
diff --git a/views/views.gyp b/views/views.gyp
index 8c1ef7c..d71f21e 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -602,6 +602,8 @@
'../ui/gfx/compositor/test_compositor.h',
'../ui/gfx/compositor/test_texture.cc',
'../ui/gfx/compositor/test_texture.h',
+ '../ui/aura/test_desktop_delegate.cc',
+ '../ui/aura/test_desktop_delegate.h',
'<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc',
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources.rc',
@@ -656,6 +658,11 @@
['exclude', 'controls/table/table_view_unittest.cc'],
['exclude', 'controls/tabbed_pane/tabbed_pane_unittest.cc'],
],
+ }, {
+ 'sources/': [
+ ['exclude', '../ui/aura/test_desktop_delegate.cc'],
+ ['exclude', '../ui/aura/test_desktop_delegate.h'],
+ ],
}],
['OS!="mac"', {
'dependencies': [
diff --git a/views/widget/native_widget_aura.cc b/views/widget/native_widget_aura.cc
index d5c1190..2a418ad 100644
--- a/views/widget/native_widget_aura.cc
+++ b/views/widget/native_widget_aura.cc
@@ -8,6 +8,7 @@
#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
#include "ui/aura/window.h"
+#include "ui/aura/window_types.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/compositor/layer.h"
@@ -29,6 +30,30 @@
namespace views {
+namespace {
+
+int GetAuraWindowTypeForWidgetType(Widget::InitParams::Type type) {
+ switch (type) {
+ case Widget::InitParams::TYPE_WINDOW:
+ case Widget::InitParams::TYPE_WINDOW_FRAMELESS:
+ case Widget::InitParams::TYPE_POPUP:
+ case Widget::InitParams::TYPE_BUBBLE:
+ return aura::kWindowType_Toplevel;
+ case Widget::InitParams::TYPE_CONTROL:
+ return aura::kWindowType_Control;
+ case Widget::InitParams::TYPE_MENU:
+ return aura::kWindowType_Menu;
+ case Widget::InitParams::TYPE_TOOLTIP:
+ return aura::kWindowType_Tooltip;
+ default:
+ NOTREACHED();
+ break;
+ }
+ return aura::kWindowType_Toplevel;
+}
+
+} // namespace
+
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetAura, public:
@@ -67,12 +92,14 @@ gfx::Font NativeWidgetAura::GetWindowTitleFont() {
void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
ownership_ = params.ownership;
window_->set_user_data(this);
+ window_->SetType(GetAuraWindowTypeForWidgetType(params.type));
window_->Init();
// TODO(beng): respect |params| authoritah wrt transparency.
window_->layer()->SetFillsBoundsOpaquely(false);
delegate_->OnNativeWidgetCreated();
window_->SetBounds(params.bounds);
- window_->SetParent(params.parent);
+ window_->SetParent(
+ params.type == Widget::InitParams::TYPE_MENU ? NULL : params.parent);
// TODO(beng): do this some other way.
delegate_->OnNativeWidgetSizeChanged(params.bounds.size());
can_activate_ = params.can_activate;
@@ -550,7 +577,7 @@ NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget(
aura::Window* toplevel = native_view;
aura::Window* parent = native_view->parent();
while (parent) {
- if (parent->IsToplevelWindowContainer())
+ if (parent->AsToplevelWindowContainer())
return GetNativeWidgetForNativeView(toplevel);
toplevel = parent;
parent = parent->parent();