diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-18 20:32:14 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-18 20:32:14 +0000 |
commit | 1422809c9c890fb145978b73d3ace532ee31c521 (patch) | |
tree | ebe9893baeac2532ade814c5e504a71c045a32da | |
parent | ab6697bbd446c43094ea3593f857e7c3f3c9327f (diff) | |
download | chromium_src-1422809c9c890fb145978b73d3ace532ee31c521.zip chromium_src-1422809c9c890fb145978b73d3ace532ee31c521.tar.gz chromium_src-1422809c9c890fb145978b73d3ace532ee31c521.tar.bz2 |
Aura/ash split: Remove hacks and get chrome linking without ash.
For the first time now, you can do:
> build/gyp_chromium -Duse_aura=1 -Duse_ash=0
And get a running chrome. It has lots of issues, especially related to
window placement, tab handling, etc, but it pops up and renders web content.
Also consolidates most of the desktop behavior into its own class.
Also makes views_examples_exe work again. Several of the hacks are no longer
needed after Ben's refactoring to support WebView.
BUG=116458,119759
TEST=none
Review URL: http://codereview.chromium.org/10081022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132856 0039d316-1c4b-4281-b951-d872f2087c98
28 files changed, 486 insertions, 163 deletions
diff --git a/ash/shell/content_client/shell_browser_main_parts.cc b/ash/shell/content_client/shell_browser_main_parts.cc index 2aaaed2..0d4a1a5 100644 --- a/ash/shell/content_client/shell_browser_main_parts.cc +++ b/ash/shell/content_client/shell_browser_main_parts.cc @@ -52,6 +52,13 @@ class ShellViewsDelegate : public views::TestViewsDelegate { return true; } + views::NativeWidgetHelperAura* CreateNativeWidgetHelper( + views::NativeWidgetAura* native_widget) OVERRIDE { + // The default behavior of the test delegate is to work in desktop + // mode. Return NULL here so NativeWidgetAura uses our RootWindow instead. + return NULL; + } + private: DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate); }; diff --git a/chrome/browser/chrome_browser_main_extra_parts_aura.cc b/chrome/browser/chrome_browser_main_extra_parts_aura.cc index 97e9dc6..693b5f3 100644 --- a/chrome/browser/chrome_browser_main_extra_parts_aura.cc +++ b/chrome/browser/chrome_browser_main_extra_parts_aura.cc @@ -6,11 +6,26 @@ #include "ui/aura/env.h" +#if !defined(USE_ASH) +#include "ui/aura/desktop/desktop_stacking_client.h" +#include "ui/views/widget/native_widget_aura.h" +#endif // !USE_ASH + ChromeBrowserMainExtraPartsAura::ChromeBrowserMainExtraPartsAura() : ChromeBrowserMainExtraParts() { } +void ChromeBrowserMainExtraPartsAura::PreProfileInit() { +#if !defined(USE_ASH) + stacking_client_.reset(new aura::DesktopStackingClient); +#endif // !USE_ASH +} + void ChromeBrowserMainExtraPartsAura::PostMainMessageLoopRun() { +#if !defined(USE_ASH) + stacking_client_.reset(); +#endif + // aura::Env instance is deleted in BrowserProcessImpl::StartTearDown // after the metrics service is deleted. } diff --git a/chrome/browser/chrome_browser_main_extra_parts_aura.h b/chrome/browser/chrome_browser_main_extra_parts_aura.h index e92a679..4fe4e7e 100644 --- a/chrome/browser/chrome_browser_main_extra_parts_aura.h +++ b/chrome/browser/chrome_browser_main_extra_parts_aura.h @@ -9,13 +9,26 @@ #include "base/compiler_specific.h" #include "chrome/browser/chrome_browser_main_extra_parts.h" +#if !defined(USE_ASH) +#include "base/memory/scoped_ptr.h" +#endif + +namespace aura { +class DesktopStackingClient; +} + class ChromeBrowserMainExtraPartsAura : public ChromeBrowserMainExtraParts { public: ChromeBrowserMainExtraPartsAura(); + virtual void PreProfileInit() OVERRIDE; virtual void PostMainMessageLoopRun() OVERRIDE; private: +#if !defined(USE_ASH) + scoped_ptr<aura::DesktopStackingClient> stacking_client_; +#endif + DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsAura); }; diff --git a/chrome/browser/fullscreen_ash.cc b/chrome/browser/fullscreen_ash.cc new file mode 100644 index 0000000..08b1419 --- /dev/null +++ b/chrome/browser/fullscreen_ash.cc @@ -0,0 +1,37 @@ +// 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 "chrome/browser/fullscreen.h" + +#include "ash/shell.h" +#include "base/logging.h" +#include "ui/aura/client/aura_constants.h" +#include "ui/aura/root_window.h" +#include "ui/aura/window.h" +#include "ui/base/ui_base_types.h" + +namespace { + +bool CheckIfFullscreenWindowExists(aura::Window* window) { + if (window->GetProperty(aura::client::kShowStateKey) == + ui::SHOW_STATE_FULLSCREEN) + return true; + aura::Window::Windows children = window->children(); + for (aura::Window::Windows::const_iterator i = children.begin(); + i != children.end(); + ++i) { + if (CheckIfFullscreenWindowExists(*i)) + return true; + } + return false; +} + +} // namespace + +bool IsFullScreenMode() { + // This is used only by notification_ui_manager.cc. On aura, notification + // will be managed in panel. This is temporary to get certain feature running + // until we implement it for aura. + return CheckIfFullscreenWindowExists(ash::Shell::GetRootWindow()); +} diff --git a/chrome/browser/fullscreen_aura.cc b/chrome/browser/fullscreen_aura.cc index 08b1419..db768be 100644 --- a/chrome/browser/fullscreen_aura.cc +++ b/chrome/browser/fullscreen_aura.cc @@ -4,34 +4,16 @@ #include "chrome/browser/fullscreen.h" -#include "ash/shell.h" #include "base/logging.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/base/ui_base_types.h" -namespace { +#if !defined(USE_ASH) -bool CheckIfFullscreenWindowExists(aura::Window* window) { - if (window->GetProperty(aura::client::kShowStateKey) == - ui::SHOW_STATE_FULLSCREEN) - return true; - aura::Window::Windows children = window->children(); - for (aura::Window::Windows::const_iterator i = children.begin(); - i != children.end(); - ++i) { - if (CheckIfFullscreenWindowExists(*i)) - return true; - } +bool IsFullScreenMode() { + // TODO(erg): An implementation here would have to check all existing + // RootWindows instead of just recursively walking the Shell's RootWindow as + // in the ash implementaiton. + NOTIMPLEMENTED(); return false; } -} // namespace - -bool IsFullScreenMode() { - // This is used only by notification_ui_manager.cc. On aura, notification - // will be managed in panel. This is temporary to get certain feature running - // until we implement it for aura. - return CheckIfFullscreenWindowExists(ash::Shell::GetRootWindow()); -} +#endif diff --git a/chrome/browser/ui/tabs/dock_info_ash.cc b/chrome/browser/ui/tabs/dock_info_ash.cc new file mode 100644 index 0000000..f058680 --- /dev/null +++ b/chrome/browser/ui/tabs/dock_info_ash.cc @@ -0,0 +1,70 @@ +// 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 "chrome/browser/ui/tabs/dock_info.h" + +#include "ash/shell.h" +#include "ui/aura/root_window.h" +#include "ui/aura/window.h" +#include "ui/gfx/compositor/layer.h" + +// DockInfo ------------------------------------------------------------------- + +namespace { + +aura::Window* GetLocalProcessWindowAtPointImpl( + const gfx::Point& screen_point, + const std::set<gfx::NativeView>& ignore, + aura::Window* window) { + if (ignore.find(window) != ignore.end()) + return NULL; + + if (!window->IsVisible()) + return NULL; + + if (window->layer()->type() == ui::LAYER_TEXTURED) { + gfx::Point window_point(screen_point); + aura::Window::ConvertPointToWindow(ash::Shell::GetRootWindow(), window, + &window_point); + return gfx::Rect(window->bounds().size()).Contains(window_point) ? + window : NULL; + } + for (aura::Window::Windows::const_reverse_iterator i = + window->children().rbegin(); i != window->children().rend(); ++i) { + aura::Window* result = + GetLocalProcessWindowAtPointImpl(screen_point, ignore, *i); + if (result) + return result; + } + return NULL; +} + +} // namespace + +// static +DockInfo DockInfo::GetDockInfoAtPoint(const gfx::Point& screen_point, + const std::set<gfx::NativeView>& ignore) { + // TODO(beng): + NOTIMPLEMENTED(); + return DockInfo(); +} + +// static +gfx::NativeView DockInfo::GetLocalProcessWindowAtPoint( + const gfx::Point& screen_point, + const std::set<gfx::NativeView>& ignore) { + return GetLocalProcessWindowAtPointImpl( + screen_point, ignore, ash::Shell::GetRootWindow()); +} + +bool DockInfo::GetWindowBounds(gfx::Rect* bounds) const { + if (!window()) + return false; + *bounds = window_->bounds(); + return true; +} + +void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const { + window_->SetBounds(bounds); +} diff --git a/chrome/browser/ui/tabs/dock_info_aura.cc b/chrome/browser/ui/tabs/dock_info_aura.cc index f058680..bf500de 100644 --- a/chrome/browser/ui/tabs/dock_info_aura.cc +++ b/chrome/browser/ui/tabs/dock_info_aura.cc @@ -4,43 +4,9 @@ #include "chrome/browser/ui/tabs/dock_info.h" -#include "ash/shell.h" -#include "ui/aura/root_window.h" #include "ui/aura/window.h" -#include "ui/gfx/compositor/layer.h" -// DockInfo ------------------------------------------------------------------- - -namespace { - -aura::Window* GetLocalProcessWindowAtPointImpl( - const gfx::Point& screen_point, - const std::set<gfx::NativeView>& ignore, - aura::Window* window) { - if (ignore.find(window) != ignore.end()) - return NULL; - - if (!window->IsVisible()) - return NULL; - - if (window->layer()->type() == ui::LAYER_TEXTURED) { - gfx::Point window_point(screen_point); - aura::Window::ConvertPointToWindow(ash::Shell::GetRootWindow(), window, - &window_point); - return gfx::Rect(window->bounds().size()).Contains(window_point) ? - window : NULL; - } - for (aura::Window::Windows::const_reverse_iterator i = - window->children().rbegin(); i != window->children().rend(); ++i) { - aura::Window* result = - GetLocalProcessWindowAtPointImpl(screen_point, ignore, *i); - if (result) - return result; - } - return NULL; -} - -} // namespace +#if !defined(USE_ASH) // static DockInfo DockInfo::GetDockInfoAtPoint(const gfx::Point& screen_point, @@ -54,8 +20,8 @@ DockInfo DockInfo::GetDockInfoAtPoint(const gfx::Point& screen_point, gfx::NativeView DockInfo::GetLocalProcessWindowAtPoint( const gfx::Point& screen_point, const std::set<gfx::NativeView>& ignore) { - return GetLocalProcessWindowAtPointImpl( - screen_point, ignore, ash::Shell::GetRootWindow()); + NOTIMPLEMENTED(); + return NULL; } bool DockInfo::GetWindowBounds(gfx::Rect* bounds) const { @@ -68,3 +34,5 @@ bool DockInfo::GetWindowBounds(gfx::Rect* bounds) const { void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const { window_->SetBounds(bounds); } + +#endif diff --git a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc index 6a1121e..9b01b46 100644 --- a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc +++ b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc @@ -82,6 +82,13 @@ class AccessibilityViewsDelegate : public views::ViewsDelegate { return 0; } +#if defined(USE_AURA) + virtual views::NativeWidgetHelperAura* CreateNativeWidgetHelper( + views::NativeWidgetAura* native_widget) OVERRIDE { + return NULL; + } +#endif + DISALLOW_COPY_AND_ASSIGN(AccessibilityViewsDelegate); }; diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc index f331a6e..7944ede 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc @@ -120,6 +120,13 @@ class ViewsDelegateImpl : public views::ViewsDelegate { return 0; } +#if defined(USE_AURA) + virtual views::NativeWidgetHelperAura* CreateNativeWidgetHelper( + views::NativeWidgetAura* native_widget) OVERRIDE { + return NULL; + } +#endif + private: DISALLOW_COPY_AND_ASSIGN(ViewsDelegateImpl); }; diff --git a/chrome/browser/ui/views/chrome_views_delegate.cc b/chrome/browser/ui/views/chrome_views_delegate.cc index bf99c47..8813ef0 100644 --- a/chrome/browser/ui/views/chrome_views_delegate.cc +++ b/chrome/browser/ui/views/chrome_views_delegate.cc @@ -26,6 +26,8 @@ #if defined(USE_ASH) #include "ash/shell.h" +#elif defined(USE_AURA) +#include "ui/views/widget/desktop_native_widget_helper_aura.h" #endif namespace { @@ -157,3 +159,14 @@ void ChromeViewsDelegate::ReleaseRef() { int ChromeViewsDelegate::GetDispositionForEvent(int event_flags) { return event_utils::DispositionFromEventFlags(event_flags); } + +#if defined(USE_AURA) +views::NativeWidgetHelperAura* ChromeViewsDelegate::CreateNativeWidgetHelper( + views::NativeWidgetAura* native_widget) { +#if !defined(USE_ASH) + return new views::DesktopNativeWidgetHelperAura(native_widget); +#else + return NULL; +#endif +} +#endif diff --git a/chrome/browser/ui/views/chrome_views_delegate.h b/chrome/browser/ui/views/chrome_views_delegate.h index 315f7ab..c7e4b7c 100644 --- a/chrome/browser/ui/views/chrome_views_delegate.h +++ b/chrome/browser/ui/views/chrome_views_delegate.h @@ -46,6 +46,11 @@ class ChromeViewsDelegate : public views::ViewsDelegate { virtual int GetDispositionForEvent(int event_flags) OVERRIDE; +#if defined(USE_AURA) + virtual views::NativeWidgetHelperAura* CreateNativeWidgetHelper( + views::NativeWidgetAura* native_widget) OVERRIDE; +#endif + private: DISALLOW_COPY_AND_ASSIGN(ChromeViewsDelegate); }; diff --git a/chrome/browser/ui/views/ash/color_chooser_aura.cc b/chrome/browser/ui/views/color_chooser_aura.cc index b108796..b108796 100644 --- a/chrome/browser/ui/views/ash/color_chooser_aura.cc +++ b/chrome/browser/ui/views/color_chooser_aura.cc diff --git a/chrome/browser/ui/views/menu_model_adapter_test.cc b/chrome/browser/ui/views/menu_model_adapter_test.cc index d98966a..740ec42 100644 --- a/chrome/browser/ui/views/menu_model_adapter_test.cc +++ b/chrome/browser/ui/views/menu_model_adapter_test.cc @@ -88,6 +88,13 @@ class TestViewsDelegate : public views::ViewsDelegate { return 0; } +#if defined(USE_AURA) + virtual views::NativeWidgetHelperAura* CreateNativeWidgetHelper( + views::NativeWidgetAura* native_widget) OVERRIDE { + return NULL; + } +#endif + private: DISALLOW_COPY_AND_ASSIGN(TestViewsDelegate); }; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index f03e8d3..a0cbbb8 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1010,6 +1010,7 @@ 'browser/first_run/upgrade_util_win.cc', 'browser/first_run/upgrade_util_win.h', 'browser/fullscreen.h', + 'browser/fullscreen_ash.cc', 'browser/fullscreen_aura.cc', 'browser/fullscreen_gtk.cc', 'browser/fullscreen_mac.mm', @@ -3153,6 +3154,7 @@ 'browser/ui/tab_modal_confirm_dialog_delegate.h', 'browser/ui/tabs/dock_info.cc', 'browser/ui/tabs/dock_info.h', + 'browser/ui/tabs/dock_info_ash.cc', 'browser/ui/tabs/dock_info_aura.cc', 'browser/ui/tabs/dock_info_gtk.cc', 'browser/ui/tabs/dock_info_mac.cc', @@ -3482,7 +3484,7 @@ 'browser/ui/views/select_file_dialog_extension.cc', 'browser/ui/views/select_file_dialog_extension.h', 'browser/ui/views/select_file_dialog_win.cc', - 'browser/ui/views/ash/color_chooser_aura.cc', + 'browser/ui/views/color_chooser_aura.cc', 'browser/ui/views/color_chooser_win.cc', 'browser/ui/views/color_chooser_dialog.cc', 'browser/ui/views/color_chooser_dialog.h', @@ -4816,6 +4818,7 @@ ['include', '^browser/ui/views/chrome_views_delegate.cc'], ['include', '^browser/ui/views/collected_cookies_views.cc'], ['include', '^browser/ui/views/collected_cookies_views.h'], + ['include', '^browser/ui/views/color_chooser_aura.cc'], ['include', '^browser/ui/views/confirm_bubble_view.cc'], ['include', '^browser/ui/views/confirm_bubble_view.h'], ['include', '^browser/ui/views/constrained_html_delegate_views.cc'], diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp index aa46a9f..48a8122 100644 --- a/ui/aura/aura.gyp +++ b/ui/aura/aura.gyp @@ -57,6 +57,8 @@ 'desktop/desktop_dispatcher_client.h', 'desktop/desktop_root_window_event_filter.cc', 'desktop/desktop_root_window_event_filter.h', + 'desktop/desktop_stacking_client.cc', + 'desktop/desktop_stacking_client.h', 'dispatcher_linux.cc', 'dispatcher_linux.h', 'dispatcher_win.cc', diff --git a/ui/aura/desktop/desktop_stacking_client.cc b/ui/aura/desktop/desktop_stacking_client.cc new file mode 100644 index 0000000..cbe6c27 --- /dev/null +++ b/ui/aura/desktop/desktop_stacking_client.cc @@ -0,0 +1,24 @@ +// 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/aura/desktop/desktop_stacking_client.h" + +#include "ui/aura/root_window.h" +#include "ui/aura/window.h" + +namespace aura { + +DesktopStackingClient::DesktopStackingClient() { + aura::client::SetStackingClient(this); +} + +DesktopStackingClient::~DesktopStackingClient() { + aura::client::SetStackingClient(NULL); +} + +Window* DesktopStackingClient::GetDefaultParent(Window* window) { + return window->GetRootWindow(); +} + +} // namespace aura diff --git a/ui/aura/desktop/desktop_stacking_client.h b/ui/aura/desktop/desktop_stacking_client.h new file mode 100644 index 0000000..34b8a67 --- /dev/null +++ b/ui/aura/desktop/desktop_stacking_client.h @@ -0,0 +1,32 @@ +// 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_AURA_DESKTOP_DESKTOP_STACKING_CLIENT_H_ +#define UI_AURA_DESKTOP_DESKTOP_STACKING_CLIENT_H_ + +#include "ui/aura/client/stacking_client.h" + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ui/aura/aura_export.h" + +namespace aura { +class Window; + +// A stacking client for the desktop; always sets the default parent to the +// RootWindow of the passed in Window. +class AURA_EXPORT DesktopStackingClient : public client::StackingClient { + public: + DesktopStackingClient(); + virtual ~DesktopStackingClient(); + + // Overridden from client::StackingClient: + virtual Window* GetDefaultParent(Window* window) OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(DesktopStackingClient); +}; + +} // namespace aura + +#endif // UI_AURA_DESKTOP_DESKTOP_STACKING_CLIENT_H_ diff --git a/ui/views/examples/content_client/examples_browser_main_parts.cc b/ui/views/examples/content_client/examples_browser_main_parts.cc index 62d3686..64725ce 100644 --- a/ui/views/examples/content_client/examples_browser_main_parts.cc +++ b/ui/views/examples/content_client/examples_browser_main_parts.cc @@ -23,39 +23,13 @@ #include "ui/views/focus/accelerator_handler.h" #if defined(USE_AURA) -#include "ui/aura/client/stacking_client.h" +#include "ui/aura/desktop/desktop_stacking_client.h" #include "ui/aura/env.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/gfx/compositor/compositor.h" -#include "ui/gfx/compositor/test/compositor_test_support.h" #include "ui/views/widget/native_widget_aura.h" #endif namespace views { namespace examples { -namespace { -#if defined(USE_AURA) -class RootWindowStackingClient : public aura::client::StackingClient { - public: - explicit RootWindowStackingClient() { - aura::client::SetStackingClient(this); - } - - virtual ~RootWindowStackingClient() { - aura::client::SetStackingClient(NULL); - } - - // Overridden from aura::client::StackingClient: - virtual aura::Window* GetDefaultParent(aura::Window* window) OVERRIDE { - return window->GetRootWindow(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(RootWindowStackingClient); -}; -#endif -} ExamplesBrowserMainParts::ExamplesBrowserMainParts( const content::MainFunctionParams& parameters) @@ -79,10 +53,7 @@ void ExamplesBrowserMainParts::PreMainMessageLoopRun() { browser_context_.reset(new content::ShellBrowserContext); #if defined(USE_AURA) - // TURN ON THE HAX. - views::NativeWidgetAura::set_aura_desktop_hax(); - ui::CompositorTestSupport::Initialize(); - root_window_stacking_client_.reset(new RootWindowStackingClient); + stacking_client_.reset(new aura::DesktopStackingClient); #endif views_delegate_.reset(new views::TestViewsDelegate); @@ -96,9 +67,8 @@ void ExamplesBrowserMainParts::PostMainMessageLoopRun() { browser_context_.reset(); views_delegate_.reset(); #if defined(USE_AURA) - root_window_stacking_client_.reset(); + stacking_client_.reset(); aura::Env::DeleteInstance(); - ui::CompositorTestSupport::Terminate(); #endif } diff --git a/ui/views/examples/content_client/examples_browser_main_parts.h b/ui/views/examples/content_client/examples_browser_main_parts.h index bdbcbc9..ea4e959 100644 --- a/ui/views/examples/content_client/examples_browser_main_parts.h +++ b/ui/views/examples/content_client/examples_browser_main_parts.h @@ -10,6 +10,12 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_main_parts.h" +namespace aura { +namespace client { +class StackingClient; +} +} + namespace base { class Thread; } @@ -63,7 +69,7 @@ class ExamplesBrowserMainParts : public content::BrowserMainParts { content::ShellDevToolsDelegate* devtools_delegate_; scoped_ptr<views::ViewsDelegate> views_delegate_; #if defined(USE_AURA) - scoped_ptr<aura::client::StackingClient> root_window_stacking_client_; + scoped_ptr<aura::client::StackingClient> stacking_client_; #endif DISALLOW_COPY_AND_ASSIGN(ExamplesBrowserMainParts); diff --git a/ui/views/test/test_views_delegate.cc b/ui/views/test/test_views_delegate.cc index 6fa6bb7..2b562f4 100644 --- a/ui/views/test/test_views_delegate.cc +++ b/ui/views/test/test_views_delegate.cc @@ -7,6 +7,10 @@ #include "base/logging.h" #include "ui/base/clipboard/clipboard.h" +#if defined(USE_AURA) +#include "ui/views/widget/desktop_native_widget_helper_aura.h" +#endif + namespace views { TestViewsDelegate::TestViewsDelegate() @@ -57,4 +61,11 @@ int TestViewsDelegate::GetDispositionForEvent(int event_flags) { return 0; } +#if defined(USE_AURA) +views::NativeWidgetHelperAura* TestViewsDelegate::CreateNativeWidgetHelper( + views::NativeWidgetAura* native_widget) { + return new views::DesktopNativeWidgetHelperAura(native_widget); +} +#endif + } // namespace views diff --git a/ui/views/test/test_views_delegate.h b/ui/views/test/test_views_delegate.h index 99976a2..1ea5cdf 100644 --- a/ui/views/test/test_views_delegate.h +++ b/ui/views/test/test_views_delegate.h @@ -59,6 +59,11 @@ class TestViewsDelegate : public ViewsDelegate { virtual int GetDispositionForEvent(int event_flags) OVERRIDE; +#if defined(USE_AURA) + virtual views::NativeWidgetHelperAura* CreateNativeWidgetHelper( + views::NativeWidgetAura* native_widget) OVERRIDE; +#endif + private: mutable scoped_ptr<ui::Clipboard> clipboard_; bool use_transparent_windows_; diff --git a/ui/views/views.gyp b/ui/views/views.gyp index d30c4a6..f28e810 100644 --- a/ui/views/views.gyp +++ b/ui/views/views.gyp @@ -316,6 +316,8 @@ 'widget/child_window_message_processor.h', 'widget/default_theme_provider.cc', 'widget/default_theme_provider.h', + 'widget/desktop_native_widget_helper_aura.cc', + 'widget/desktop_native_widget_helper_aura.h', 'widget/drop_helper.cc', 'widget/drop_helper.h', 'widget/drop_target_win.cc', @@ -334,6 +336,7 @@ 'widget/native_widget_aura.cc', 'widget/native_widget_aura.h', 'widget/native_widget_delegate.h', + 'widget/native_widget_helper_aura.h', 'widget/native_widget_private.h', 'widget/native_widget_win.cc', 'widget/native_widget_win.h', diff --git a/ui/views/views_delegate.h b/ui/views/views_delegate.h index af9c665..d1fc739 100644 --- a/ui/views/views_delegate.h +++ b/ui/views/views_delegate.h @@ -31,6 +31,11 @@ class NonClientFrameView; class View; class Widget; +#if defined(USE_AURA) +class NativeWidgetAura; +class NativeWidgetHelperAura; +#endif + // ViewsDelegate is an interface implemented by an object using the views // framework. It is used to obtain various high level application utilities // and perform some actions such as window placement saving. @@ -96,6 +101,13 @@ class VIEWS_EXPORT ViewsDelegate { // Converts views::Event::flags to a WindowOpenDisposition. virtual int GetDispositionForEvent(int event_flags) = 0; + +#if defined(USE_AURA) + // Creates an object that implements desktop integration behavior. Returned + // object is owned by the NativeWidgetAura passed in. May return NULL. + virtual NativeWidgetHelperAura* CreateNativeWidgetHelper( + NativeWidgetAura* native_widget) = 0; +#endif }; } // namespace views 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 9de1e78..bb97eca 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_ |