diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 01:04:24 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 01:04:24 +0000 |
commit | e050ef1444006c87364b8bede8a0df8e463525dc (patch) | |
tree | 204fe03296b7e8c8918945768fefcf5cd5ead7be /ui | |
parent | 4a4c337c42676cdb024fd943a7c97400abe58cad (diff) | |
download | chromium_src-e050ef1444006c87364b8bede8a0df8e463525dc.zip chromium_src-e050ef1444006c87364b8bede8a0df8e463525dc.tar.gz chromium_src-e050ef1444006c87364b8bede8a0df8e463525dc.tar.bz2 |
* MultiMonitorManager creates and manages mutliple monitor instance
* MonitorContrler controls root window <-> monitor mapping and resize/reposition root window to match monitor configuration.
* Moved use_fullscreen_host_window to MonitorManager
* Moved compositor initialize/terminate to Env as there can be more than one root window.
BUG=115510
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9701098
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/demo/demo_main.cc | 5 | ||||
-rw-r--r-- | ui/aura/env.cc | 6 | ||||
-rw-r--r-- | ui/aura/monitor_manager.cc | 45 | ||||
-rw-r--r-- | ui/aura/monitor_manager.h | 37 | ||||
-rw-r--r-- | ui/aura/root_window.cc | 27 | ||||
-rw-r--r-- | ui/aura/root_window.h | 21 | ||||
-rw-r--r-- | ui/aura/single_monitor_manager.cc | 25 | ||||
-rw-r--r-- | ui/aura/single_monitor_manager.h | 4 | ||||
-rw-r--r-- | ui/views/test/views_test_base.cc | 3 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura_unittest.cc | 5 |
10 files changed, 110 insertions, 68 deletions
diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc index 89bb411..75c9d27 100644 --- a/ui/aura/demo/demo_main.cc +++ b/ui/aura/demo/demo_main.cc @@ -9,7 +9,9 @@ #include "base/message_loop.h" #include "third_party/skia/include/core/SkXfermode.h" #include "ui/aura/client/stacking_client.h" +#include "ui/aura/env.h" #include "ui/aura/event.h" +#include "ui/aura/monitor_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" #include "ui/aura/window_delegate.h" @@ -110,7 +112,8 @@ int main(int argc, char** argv) { MessageLoop message_loop(MessageLoop::TYPE_UI); ui::CompositorTestSupport::Initialize(); - scoped_ptr<aura::RootWindow> root_window(new aura::RootWindow); + scoped_ptr<aura::RootWindow> root_window( + aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); scoped_ptr<DemoStackingClient> stacking_client(new DemoStackingClient( root_window.get())); diff --git a/ui/aura/env.cc b/ui/aura/env.cc index 61289f5..0e9222c 100644 --- a/ui/aura/env.cc +++ b/ui/aura/env.cc @@ -7,6 +7,7 @@ #include "ui/aura/single_monitor_manager.h" #include "ui/aura/root_window_host.h" #include "ui/aura/window.h" +#include "ui/gfx/compositor/compositor.h" namespace aura { @@ -25,9 +26,12 @@ Env::Env() #if !defined(OS_MACOSX) dispatcher_.reset(CreateDispatcher()); #endif + ui::Compositor::Initialize(false); } -Env::~Env() {} +Env::~Env() { + ui::Compositor::Terminate(); +} // static Env* Env::GetInstance() { diff --git a/ui/aura/monitor_manager.cc b/ui/aura/monitor_manager.cc index 542750f..bde77bd 100644 --- a/ui/aura/monitor_manager.cc +++ b/ui/aura/monitor_manager.cc @@ -4,7 +4,48 @@ #include "ui/aura/monitor_manager.h" +#include <stdio.h> + +#include "ui/aura/env.h" +#include "ui/aura/monitor.h" +#include "ui/aura/root_window_host.h" +#include "ui/gfx/rect.h" + namespace aura { +namespace { +// Default bounds for a monitor. +static const int kDefaultHostWindowX = 200; +static const int kDefaultHostWindowY = 200; +static const int kDefaultHostWindowWidth = 1280; +static const int kDefaultHostWindowHeight = 1024; +} // namespace + +// static +bool MonitorManager::use_fullscreen_host_window_ = false; + +// static +Monitor* MonitorManager::CreateMonitorFromSpec(const std::string& spec) { + gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, + kDefaultHostWindowWidth, kDefaultHostWindowHeight); + int x = 0, y = 0, width, height; + if (sscanf(spec.c_str(), "%dx%d", &width, &height) == 2) { + bounds.set_size(gfx::Size(width, height)); + } else if (sscanf(spec.c_str(), "%d+%d-%dx%d", &x, &y, &width, &height) + == 4) { + bounds = gfx::Rect(x, y, width, height); + } else if (use_fullscreen_host_window_) { + bounds = gfx::Rect(aura::RootWindowHost::GetNativeScreenSize()); + } + Monitor* monitor = new Monitor(); + monitor->set_bounds(bounds); + return monitor; +} + +// static +RootWindow* MonitorManager::CreateRootWindowForPrimaryMonitor() { + MonitorManager* manager = aura::Env::GetInstance()->monitor_manager(); + return manager->CreateRootWindowForMonitor(manager->GetMonitorAt(0)); +} MonitorManager::MonitorManager() { } @@ -20,10 +61,6 @@ void MonitorManager::RemoveObserver(MonitorObserver* observer) { observers_.RemoveObserver(observer); } -RootWindow* MonitorManager::CreateRootWindowForPrimaryMonitor() { - return CreateRootWindowForMonitor(GetPrimaryMonitor()); -} - void MonitorManager::NotifyBoundsChanged(const Monitor* monitor) { FOR_EACH_OBSERVER(MonitorObserver, observers_, OnMonitorBoundsChanged(monitor)); diff --git a/ui/aura/monitor_manager.h b/ui/aura/monitor_manager.h index 2b2471e..77ad274 100644 --- a/ui/aura/monitor_manager.h +++ b/ui/aura/monitor_manager.h @@ -6,6 +6,8 @@ #define UI_AURA_MONITOR_MANAGER_H_ #pragma once +#include <string> + #include "base/basictypes.h" #include "base/observer_list.h" #include "ui/aura/aura_export.h" @@ -33,6 +35,23 @@ class MonitorObserver { // any windows. class AURA_EXPORT MonitorManager { public: + static void set_use_fullscreen_host_window(bool use_fullscreen) { + use_fullscreen_host_window_ = use_fullscreen; + } + static bool use_fullscreen_host_window() { + return use_fullscreen_host_window_; + } + + // Creates a monitor from string spec. 100+200-1440x800 creates monitor + // whose size is 1440x800 at the location (100, 200) in screen's coordinates. + // The location can be omitted and be just "1440x800", which creates + // monitor at the origin of the screen. An empty string creates + // the monitor with default size. + static Monitor* CreateMonitorFromSpec(const std::string& spec); + + // A utility function to create a root window for primary monitor. + static RootWindow* CreateRootWindowForPrimaryMonitor(); + MonitorManager(); virtual ~MonitorManager(); @@ -44,8 +63,8 @@ class AURA_EXPORT MonitorManager { // TODO(oshima): multiple monitor support. virtual void OnNativeMonitorResized(const gfx::Size& size) = 0; - // Create a root window for primary monitor. - virtual RootWindow* CreateRootWindowForMonitor(const Monitor* monitor) = 0; + // Create a root window for given |monitor|. + virtual RootWindow* CreateRootWindowForMonitor(Monitor* monitor) = 0; // Returns the monitor object nearest given |window|. virtual const Monitor* GetMonitorNearestWindow( @@ -56,21 +75,23 @@ class AURA_EXPORT MonitorManager { virtual const Monitor* GetMonitorNearestPoint( const gfx::Point& point) const = 0; - // Returns the monitor that is consiered "primary". - virtual const Monitor* GetPrimaryMonitor() const = 0; + // Returns the monitor at |index|. The monitor at 0 is consiered + // "primary". + virtual Monitor* GetMonitorAt(size_t index) = 0; virtual size_t GetNumMonitors() const = 0; - // A utility function to create a root window for primary monitor. - RootWindow* CreateRootWindowForPrimaryMonitor(); - protected: // Calls observers' OnMonitorBoundsChanged methods. void NotifyBoundsChanged(const Monitor* monitor); private: - ObserverList<MonitorObserver> observers_; + // If set before the RootWindow is created, the host window will cover the + // entire monitor. Note that this can still be overridden via the + // switches::kAuraHostWindowSize flag. + static bool use_fullscreen_host_window_; + ObserverList<MonitorObserver> observers_; DISALLOW_COPY_AND_ASSIGN(MonitorManager); }; diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index 1ea9751..8050f5c 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -67,16 +67,14 @@ Window* GestureEventHandlerForConsumedGesture(const GestureEvent& event, } // namespace -RootWindow* RootWindow::instance_ = NULL; -bool RootWindow::use_fullscreen_host_window_ = false; bool RootWindow::hide_host_cursor_ = false; //////////////////////////////////////////////////////////////////////////////// // RootWindow, public: -RootWindow::RootWindow() +RootWindow::RootWindow(const gfx::Rect& initial_bounds) : Window(NULL), - host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), + host_(aura::RootWindowHost::Create(initial_bounds)), ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), mouse_button_flags_(0), @@ -103,7 +101,6 @@ RootWindow::RootWindow() should_hold_mouse_moves_ = !CommandLine::ForCurrentProcess()->HasSwitch( switches::kAuraDisableHoldMouseMoves); - ui::Compositor::Initialize(false); compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), host_->GetBounds().size())); DCHECK(compositor_.get()); @@ -122,9 +119,6 @@ RootWindow::~RootWindow() { // An observer may have been added by an animation on the RootWindow. layer()->GetAnimator()->RemoveObserver(this); - ui::Compositor::Terminate(); - if (instance_ == this) - instance_ = NULL; } void RootWindow::ShowRootWindow() { @@ -147,6 +141,14 @@ gfx::Size RootWindow::GetHostSize() const { return rect.size(); } +void RootWindow::SetHostBounds(const gfx::Rect& bounds) { + DispatchHeldMouseMove(); + host_->SetBounds(bounds); + // Requery the location to constrain it within the new root window size. + last_mouse_location_ = host_->QueryMouseLocation(); + synthesize_mouse_move_ = false; +} + void RootWindow::SetCursor(gfx::NativeCursor cursor) { last_cursor_ = cursor; // A lot of code seems to depend on NULL cursors actually showing an arrow, @@ -437,6 +439,10 @@ RootWindow* RootWindow::GetRootWindow() { return this; } +const RootWindow* RootWindow::GetRootWindow() const { + return this; +} + void RootWindow::SetTransform(const ui::Transform& transform) { Window::SetTransform(transform); @@ -834,11 +840,6 @@ void RootWindow::DispatchHeldMouseMove() { } } -gfx::Rect RootWindow::GetInitialHostWindowBounds() const { - return Env::GetInstance()->monitor_manager()-> - GetMonitorNearestWindow(this)->bounds(); -} - void RootWindow::PostMouseMoveEventAfterWindowChange() { if (synthesize_mouse_move_) return; diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h index 1d6c3bf..de38f8c 100644 --- a/ui/aura/root_window.h +++ b/ui/aura/root_window.h @@ -49,17 +49,9 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, public internal::FocusManager, public ui::LayerAnimationObserver { public: - RootWindow(); + explicit RootWindow(const gfx::Rect& initial_bounds); virtual ~RootWindow(); - // TODO(oshima): Move this to monitor manager. - static void set_use_fullscreen_host_window(bool use_fullscreen) { - use_fullscreen_host_window_ = use_fullscreen; - } - static bool use_fullscreen_host_window() { - return use_fullscreen_host_window_; - } - static void set_hide_host_cursor(bool hide) { hide_host_cursor_ = hide; } @@ -82,6 +74,9 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, void SetHostSize(const gfx::Size& size); gfx::Size GetHostSize() const; + // Sets the bounds of the host window. + void SetHostBounds(const gfx::Rect& size); + // Sets the currently-displayed cursor. If the cursor was previously hidden // via ShowCursor(false), it will remain hidden until ShowCursor(true) is // called, at which point the cursor that was last set via SetCursor() will be @@ -196,6 +191,7 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, // Overridden from Window: virtual RootWindow* GetRootWindow() OVERRIDE; + virtual const RootWindow* GetRootWindow() const OVERRIDE; virtual void SetTransform(const ui::Transform& transform) OVERRIDE; // Overridden from ui::CompositorDelegate: @@ -276,13 +272,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, scoped_ptr<RootWindowHost> host_; - static RootWindow* instance_; - - // If set before the RootWindow is created, the host window will cover the - // entire screen. Note that this can still be overridden via the - // switches::kAuraHostWindowSize flag. - static bool use_fullscreen_host_window_; - // If set before the RootWindow is created, the cursor will be drawn within // the Aura root window but hidden outside of it, and it'll remain hidden // after the Aura window is closed. diff --git a/ui/aura/single_monitor_manager.cc b/ui/aura/single_monitor_manager.cc index e0ce3c0..2e1d86d 100644 --- a/ui/aura/single_monitor_manager.cc +++ b/ui/aura/single_monitor_manager.cc @@ -38,17 +38,17 @@ SingleMonitorManager::~SingleMonitorManager() { } void SingleMonitorManager::OnNativeMonitorResized(const gfx::Size& size) { - if (RootWindow::use_fullscreen_host_window()) { + if (use_fullscreen_host_window()) { monitor_->set_size(size); NotifyBoundsChanged(monitor_.get()); } } RootWindow* SingleMonitorManager::CreateRootWindowForMonitor( - const Monitor* monitor) { + Monitor* monitor) { DCHECK(!root_window_); DCHECK_EQ(monitor_.get(), monitor); - root_window_ = new RootWindow(); + root_window_ = new RootWindow(monitor->bounds()); root_window_->AddObserver(this); return root_window_; } @@ -63,8 +63,8 @@ const Monitor* SingleMonitorManager::GetMonitorNearestPoint( return monitor_.get(); } -const Monitor* SingleMonitorManager::GetPrimaryMonitor() const { - return monitor_.get(); +Monitor* SingleMonitorManager::GetMonitorAt(size_t index) { + return !index ? monitor_.get() : NULL; } size_t SingleMonitorManager::GetNumMonitors() const { @@ -77,7 +77,7 @@ Monitor* SingleMonitorManager::GetMonitorNearestWindow(const Window* window) { void SingleMonitorManager::OnWindowBoundsChanged( Window* window, const gfx::Rect& bounds) { - if (!RootWindow::use_fullscreen_host_window()) { + if (!use_fullscreen_host_window()) { Update(bounds.size()); NotifyBoundsChanged(monitor_.get()); } @@ -89,20 +89,9 @@ void SingleMonitorManager::OnWindowDestroying(Window* window) { } void SingleMonitorManager::Init() { - gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, - kDefaultHostWindowWidth, kDefaultHostWindowHeight); const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kAuraHostWindowSize); - int x = 0, y = 0, width, height; - if (sscanf(size_str.c_str(), "%dx%d", &width, &height) == 2) { - bounds.set_size(gfx::Size(width, height)); - } else if (sscanf(size_str.c_str(), "%d+%d-%dx%d", &x, &y, &width, &height) - == 4) { - bounds = gfx::Rect(x, y, width, height); - } else if (RootWindow::use_fullscreen_host_window()) { - bounds = gfx::Rect(RootWindowHost::GetNativeScreenSize()); - } - monitor_->set_bounds(bounds); + monitor_.reset(CreateMonitorFromSpec(size_str)); } void SingleMonitorManager::Update(const gfx::Size size) { diff --git a/ui/aura/single_monitor_manager.h b/ui/aura/single_monitor_manager.h index 6fc0cdc..c13bc18 100644 --- a/ui/aura/single_monitor_manager.h +++ b/ui/aura/single_monitor_manager.h @@ -28,12 +28,12 @@ class SingleMonitorManager : public MonitorManager, // MonitorManager overrides: virtual void OnNativeMonitorResized(const gfx::Size& size) OVERRIDE; virtual RootWindow* CreateRootWindowForMonitor( - const Monitor* monitor) OVERRIDE; + Monitor* monitor) OVERRIDE; virtual const Monitor* GetMonitorNearestWindow( const Window* window) const OVERRIDE; virtual const Monitor* GetMonitorNearestPoint( const gfx::Point& point) const OVERRIDE; - virtual const Monitor* GetPrimaryMonitor() const OVERRIDE; + virtual Monitor* GetMonitorAt(size_t index) OVERRIDE; virtual size_t GetNumMonitors() const OVERRIDE; virtual Monitor* GetMonitorNearestWindow(const Window* window) OVERRIDE; diff --git a/ui/views/test/views_test_base.cc b/ui/views/test/views_test_base.cc index c41ea5b..e1999d8 100644 --- a/ui/views/test/views_test_base.cc +++ b/ui/views/test/views_test_base.cc @@ -79,8 +79,7 @@ void ViewsTestBase::SetUp() { if (!views_delegate_.get()) views_delegate_.reset(new TestViewsDelegate()); #if defined(USE_AURA) - root_window_.reset(aura::Env::GetInstance()->monitor_manager()-> - CreateRootWindowForPrimaryMonitor()); + root_window_.reset(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); root_window_->SetProperty( aura::client::kRootWindowInputMethodKey, diff --git a/ui/views/widget/native_widget_aura_unittest.cc b/ui/views/widget/native_widget_aura_unittest.cc index dd8759a..59f87a7 100644 --- a/ui/views/widget/native_widget_aura_unittest.cc +++ b/ui/views/widget/native_widget_aura_unittest.cc @@ -8,7 +8,6 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/aura/env.h" #include "ui/aura/layout_manager.h" #include "ui/aura/monitor_manager.h" #include "ui/aura/root_window.h" @@ -36,8 +35,8 @@ class NativeWidgetAuraTest : public testing::Test { // testing::Test overrides: virtual void SetUp() OVERRIDE { - root_window_.reset(aura::Env::GetInstance()->monitor_manager()-> - CreateRootWindowForPrimaryMonitor()); + root_window_.reset( + aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); root_window_->SetBounds(gfx::Rect(0, 0, 640, 480)); root_window_->SetHostSize(gfx::Size(640, 480)); |