summaryrefslogtreecommitdiffstats
path: root/ui/views/widget
diff options
context:
space:
mode:
Diffstat (limited to 'ui/views/widget')
-rw-r--r--ui/views/widget/desktop_native_widget_helper_aura.cc78
-rw-r--r--ui/views/widget/desktop_native_widget_helper_aura.h54
-rw-r--r--ui/views/widget/native_widget_aura.cc70
-rw-r--r--ui/views/widget/native_widget_aura.h16
-rw-r--r--ui/views/widget/native_widget_helper_aura.h38
5 files changed, 190 insertions, 66 deletions
diff --git a/ui/views/widget/desktop_native_widget_helper_aura.cc b/ui/views/widget/desktop_native_widget_helper_aura.cc
new file mode 100644
index 0000000..d05c062
--- /dev/null
+++ b/ui/views/widget/desktop_native_widget_helper_aura.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2012 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/views/widget/desktop_native_widget_helper_aura.h"
+
+#include "ui/views/widget/native_widget_aura.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/desktop/desktop_activation_client.h"
+#include "ui/aura/desktop/desktop_dispatcher_client.h"
+#include "ui/aura/desktop/desktop_root_window_event_filter.h"
+#include "ui/aura/client/dispatcher_client.h"
+
+namespace views {
+
+DesktopNativeWidgetHelperAura::DesktopNativeWidgetHelperAura(
+ NativeWidgetAura* widget)
+ : widget_(widget) {
+}
+
+DesktopNativeWidgetHelperAura::~DesktopNativeWidgetHelperAura() {}
+
+void DesktopNativeWidgetHelperAura::PreInitialize(
+ const Widget::InitParams& params) {
+ gfx::Rect bounds = params.bounds;
+ if (bounds.IsEmpty()) {
+ // We must pass some non-zero value when we initialize a RootWindow. This
+ // will probably be SetBounds()ed soon.
+ bounds.set_size(gfx::Size(100, 100));
+ }
+ root_window_.reset(new aura::RootWindow(bounds));
+ root_window_->SetEventFilter(
+ new aura::DesktopRootWindowEventFilter(root_window_.get()));
+ root_window_->AddRootWindowObserver(this);
+
+ aura::client::SetActivationClient(
+ root_window_.get(),
+ new aura::DesktopActivationClient(root_window_.get()));
+ aura::client::SetDispatcherClient(root_window_.get(),
+ new aura::DesktopDispatcherClient);
+}
+
+void DesktopNativeWidgetHelperAura::ShowRootWindow() {
+ if (root_window_.get())
+ root_window_->ShowRootWindow();
+}
+
+aura::RootWindow* DesktopNativeWidgetHelperAura::GetRootWindow() {
+ return root_window_.get();
+}
+
+gfx::Rect DesktopNativeWidgetHelperAura::ModifyAndSetBounds(gfx::Rect bounds) {
+ if (root_window_.get() && !bounds.IsEmpty()) {
+ root_window_->SetHostBounds(bounds);
+ bounds.set_x(0);
+ bounds.set_y(0);
+ }
+
+ return bounds;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopNativeWidgetHelperAura, aura::RootWindowObserver implementation:
+
+void DesktopNativeWidgetHelperAura::OnRootWindowResized(
+ const aura::RootWindow* root,
+ const gfx::Size& old_size) {
+ DCHECK_EQ(root, root_window_.get());
+ widget_->SetBounds(gfx::Rect(root->GetHostSize()));
+}
+
+void DesktopNativeWidgetHelperAura::OnRootWindowHostClosed(
+ const aura::RootWindow* root) {
+ DCHECK_EQ(root, root_window_.get());
+ widget_->GetWidget()->Close();
+}
+
+} // namespace views
diff --git a/ui/views/widget/desktop_native_widget_helper_aura.h b/ui/views/widget/desktop_native_widget_helper_aura.h
new file mode 100644
index 0000000..72c169d
--- /dev/null
+++ b/ui/views/widget/desktop_native_widget_helper_aura.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2012 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_VIEWS_WIDGET_DESKTOP_NATIVE_WIDGET_HELPER_AURA_H_
+#define UI_VIEWS_WIDGET_DESKTOP_NATIVE_WIDGET_HELPER_AURA_H_
+#pragma once
+
+#include "ui/aura/root_window_observer.h"
+#include "ui/gfx/rect.h"
+#include "ui/views/views_export.h"
+#include "ui/views/widget/native_widget_helper_aura.h"
+#include "ui/views/widget/widget.h"
+
+namespace aura {
+class RootWindow;
+}
+
+namespace views {
+class NativeWidgetAura;
+
+// Implementation of non-Ash desktop integration code, allowing
+// NativeWidgetAuras to work in a traditional desktop environment.
+class VIEWS_EXPORT DesktopNativeWidgetHelperAura
+ : public NativeWidgetHelperAura,
+ public aura::RootWindowObserver {
+ public:
+ explicit DesktopNativeWidgetHelperAura(NativeWidgetAura* widget);
+ virtual ~DesktopNativeWidgetHelperAura();
+
+ // Overridden from aura::NativeWidgetHelperAura:
+ virtual void PreInitialize(const Widget::InitParams& params) OVERRIDE;
+ virtual void ShowRootWindow() OVERRIDE;
+ virtual aura::RootWindow* GetRootWindow() OVERRIDE;
+ virtual gfx::Rect ModifyAndSetBounds(gfx::Rect bounds) OVERRIDE;
+
+ // Overridden from aura::RootWindowObserver:
+ virtual void OnRootWindowResized(const aura::RootWindow* root,
+ const gfx::Size& old_size) OVERRIDE;
+ virtual void OnRootWindowHostClosed(const aura::RootWindow* root) OVERRIDE;
+
+ private:
+ // A weak pointer back to our owning widget.
+ NativeWidgetAura* widget_;
+
+ // Optionally, a RootWindow that we attach ourselves to.
+ scoped_ptr<aura::RootWindow> root_window_;
+
+ DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetHelperAura);
+};
+
+} // namespace views
+
+#endif // UI_VIEWS_WIDGET_DESKTOP_NATIVE_WIDGET_HELPER_AURA_H_
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc
index 1f8e15e..202caa8 100644
--- a/ui/views/widget/native_widget_aura.cc
+++ b/ui/views/widget/native_widget_aura.cc
@@ -9,13 +9,9 @@
#include "third_party/skia/include/core/SkRegion.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/client/dispatcher_client.h"
#include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/window_move_client.h"
#include "ui/aura/client/window_types.h"
-#include "ui/aura/desktop/desktop_activation_client.h"
-#include "ui/aura/desktop/desktop_dispatcher_client.h"
-#include "ui/aura/desktop/desktop_root_window_event_filter.h"
#include "ui/aura/env.h"
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
@@ -29,8 +25,10 @@
#include "ui/gfx/screen.h"
#include "ui/views/drag_utils.h"
#include "ui/views/ime/input_method_bridge.h"
+#include "ui/views/views_delegate.h"
#include "ui/views/widget/drop_helper.h"
#include "ui/views/widget/native_widget_delegate.h"
+#include "ui/views/widget/native_widget_helper_aura.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/tooltip_manager_aura.h"
#include "ui/views/widget/widget_delegate.h"
@@ -48,8 +46,6 @@
namespace views {
-bool NativeWidgetAura::g_aura_desktop_hax = false;
-
namespace {
aura::client::WindowType GetAuraWindowTypeForWidgetType(
@@ -139,7 +135,10 @@ class NativeWidgetAura::ActiveWindowObserver : public aura::WindowObserver {
NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate)
: delegate_(delegate),
- root_window_(NULL),
+ ALLOW_THIS_IN_INITIALIZER_LIST(desktop_helper_(
+ ViewsDelegate::views_delegate ?
+ ViewsDelegate::views_delegate->CreateNativeWidgetHelper(this) :
+ NULL)),
ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
@@ -173,25 +172,9 @@ gfx::Font NativeWidgetAura::GetWindowTitleFont() {
void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
ownership_ = params.ownership;
- // TODO(erg): What kind of windows do we want to have their own root windows?
- if (g_aura_desktop_hax) {
- gfx::Rect bounds = params.bounds;
- if (bounds.IsEmpty()) {
- // We must pass some non-zero value when we initialize a RootWindow. This
- // will probably be SetBounds()ed soon.
- bounds.set_size(gfx::Size(100, 100));
- }
- root_window_.reset(new aura::RootWindow(bounds));
- root_window_->SetEventFilter(
- new aura::DesktopRootWindowEventFilter(root_window_.get()));
- root_window_->AddRootWindowObserver(this);
-
- aura::client::SetActivationClient(
- root_window_.get(),
- new aura::DesktopActivationClient(root_window_.get()));
- aura::client::SetDispatcherClient(root_window_.get(),
- new aura::DesktopDispatcherClient);
- }
+
+ if (desktop_helper_.get())
+ desktop_helper_->PreInitialize(params);
window_->set_user_data(this);
window_->SetType(GetAuraWindowTypeForWidgetType(params.type));
@@ -204,8 +187,8 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
window_->Show();
delegate_->OnNativeWidgetCreated();
- if (root_window_.get()) {
- window_->SetParent(root_window_.get());
+ if (desktop_helper_.get() && desktop_helper_->GetRootWindow()) {
+ window_->SetParent(desktop_helper_->GetRootWindow());
} else if (params.child) {
window_->SetParent(params.GetParent());
} else {
@@ -220,7 +203,7 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
// client per root window instead. For now, we hax our way around this by
// forcing the parent to be the root window instead of passing NULL as
// the parent which will dispatch to the stacking client.
- if (g_aura_desktop_hax)
+ if (desktop_helper_.get())
parent = parent->GetRootWindow();
else
parent = NULL;
@@ -253,8 +236,9 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
aura::client::SetActivationDelegate(window_, this);
- if (root_window_.get())
- root_window_->ShowRootWindow();
+ // TODO(erg): Move this somewhere else?
+ if (desktop_helper_.get())
+ desktop_helper_->ShowRootWindow();
}
NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() {
@@ -471,11 +455,8 @@ gfx::Rect NativeWidgetAura::GetRestoredBounds() const {
void NativeWidgetAura::SetBounds(const gfx::Rect& in_bounds) {
gfx::Rect bounds = in_bounds;
- if (root_window_.get() && !bounds.IsEmpty()) {
- root_window_->SetHostBounds(bounds);
- bounds.set_x(0);
- bounds.set_y(0);
- }
+ if (desktop_helper_.get())
+ bounds = desktop_helper_->ModifyAndSetBounds(bounds);
#if defined(ENABLE_DIP)
bounds = ConvertRectToMonitor(bounds);
#endif
@@ -873,23 +854,6 @@ void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) {
}
////////////////////////////////////////////////////////////////////////////////
-// NativeWidgetAura, aura::RootWindowObserver implementation:
-
-void NativeWidgetAura::OnRootWindowResized(const aura::RootWindow* root,
- const gfx::Size& old_size) {
- // This case can only happen if we have our own aura::RootWindow*. When that
- // happens, our main window should be at the origin and sized to the
- // RootWindow.
- DCHECK_EQ(root, root_window_.get());
- SetBounds(gfx::Rect(root->GetHostSize()));
-}
-
-void NativeWidgetAura::OnRootWindowHostClosed(const aura::RootWindow* root) {
- DCHECK_EQ(root, root_window_.get());
- GetWidget()->Close();
-}
-
-////////////////////////////////////////////////////////////////////////////////
// NativeWidgetAura, aura::ActivationDelegate implementation:
bool NativeWidgetAura::ShouldActivate(const aura::Event* event) {
diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h
index d09a77d..388da85 100644
--- a/ui/views/widget/native_widget_aura.h
+++ b/ui/views/widget/native_widget_aura.h
@@ -10,7 +10,6 @@
#include "base/memory/weak_ptr.h"
#include "ui/aura/client/activation_delegate.h"
#include "ui/aura/client/drag_drop_delegate.h"
-#include "ui/aura/root_window_observer.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/events.h"
#include "ui/views/views_export.h"
@@ -18,7 +17,6 @@
namespace aura {
class Monitor;
-class RootWindow;
class Window;
}
namespace gfx {
@@ -28,19 +26,17 @@ class Font;
namespace views {
class DropHelper;
+class NativeWidgetHelperAura;
class TooltipManagerAura;
class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
public aura::WindowDelegate,
- public aura::RootWindowObserver,
public aura::client::ActivationDelegate,
public aura::client::DragDropDelegate {
public:
explicit NativeWidgetAura(internal::NativeWidgetDelegate* delegate);
virtual ~NativeWidgetAura();
- static void set_aura_desktop_hax() { g_aura_desktop_hax = true; }
-
// TODO(beng): Find a better place for this, and the similar method on
// NativeWidgetWin.
static gfx::Font GetWindowTitleFont();
@@ -152,11 +148,6 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
virtual void OnWindowDestroyed() OVERRIDE;
virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE;
- // Overridden from aura::RootWindowObserver:
- virtual void OnRootWindowResized(const aura::RootWindow* root,
- const gfx::Size& old_size) OVERRIDE;
- virtual void OnRootWindowHostClosed(const aura::RootWindow* root) OVERRIDE;
-
// Overridden from aura::client::ActivationDelegate:
virtual bool ShouldActivate(const aura::Event* event) OVERRIDE;
virtual void OnActivated() OVERRIDE;
@@ -191,7 +182,8 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
internal::NativeWidgetDelegate* delegate_;
- scoped_ptr<aura::RootWindow> root_window_;
+ scoped_ptr<NativeWidgetHelperAura> desktop_helper_;
+
aura::Window* window_;
// See class documentation for Widget in widget.h for a note about ownership.
@@ -216,8 +208,6 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
scoped_ptr<DropHelper> drop_helper_;
int last_drop_operation_;
- static bool g_aura_desktop_hax;
-
DISALLOW_COPY_AND_ASSIGN(NativeWidgetAura);
};
diff --git a/ui/views/widget/native_widget_helper_aura.h b/ui/views/widget/native_widget_helper_aura.h
new file mode 100644
index 0000000..4d73932
--- /dev/null
+++ b/ui/views/widget/native_widget_helper_aura.h
@@ -0,0 +1,38 @@
+// Copyright (c) 2012 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_VIEWS_WIDGET_NATIVE_WIDGET_HELPER_AURA_H_
+#define UI_VIEWS_WIDGET_NATIVE_WIDGET_HELPER_AURA_H_
+#pragma once
+
+#include "ui/views/views_export.h"
+#include "ui/views/widget/widget.h"
+
+namespace views {
+
+// A special delegate that encapsulates all logic for use of NativeWidgetAura
+// on the desktop.
+class VIEWS_EXPORT NativeWidgetHelperAura {
+ public:
+ virtual ~NativeWidgetHelperAura() {}
+
+ // Called at the start of InitNativeWidget; determines whether we should
+ // set up a root_window_ for this widget.
+ virtual void PreInitialize(const Widget::InitParams& params) = 0;
+
+ // Passes through a message to show the RootWindow, if it exists.
+ virtual void ShowRootWindow() = 0;
+
+ // If we own a RootWindow, return it. Otherwise NULL.
+ virtual aura::RootWindow* GetRootWindow() = 0;
+
+ // If this NativeWidgetAura has its own RootWindow, sets the position at the
+ // |root_window_|, and returns modified bounds to set the origin to
+ // zero. Otherwise, pass through in_bounds.
+ virtual gfx::Rect ModifyAndSetBounds(gfx::Rect bounds) = 0;
+};
+
+} // namespace views
+
+#endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_HELPER_AURA_H_