summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/screen_ash.cc11
-rw-r--r--ash/shell.cc16
-rw-r--r--ash/shell.h6
-rw-r--r--chrome/browser/ui/views/accessibility_event_router_views_unittest.cc5
-rw-r--r--chrome/test/base/browser_with_test_window_test.cc5
-rw-r--r--ui/aura/aura.gyp2
-rw-r--r--ui/aura/env.cc3
-rw-r--r--ui/aura/monitor.cc5
-rw-r--r--ui/aura/monitor.h9
-rw-r--r--ui/aura/monitor_manager.cc82
-rw-r--r--ui/aura/monitor_manager.h41
-rw-r--r--ui/aura/monitor_manager_x11.cc51
-rw-r--r--ui/aura/root_window.cc52
-rw-r--r--ui/aura/root_window.h4
-rw-r--r--ui/aura/root_window_host.h4
-rw-r--r--ui/aura/root_window_host_linux.cc24
-rw-r--r--ui/aura/root_window_host_linux.h4
-rw-r--r--ui/aura/root_window_host_win.cc20
-rw-r--r--ui/aura/root_window_host_win.h4
-rw-r--r--ui/aura/single_monitor_manager.cc113
-rw-r--r--ui/aura/single_monitor_manager.h58
-rw-r--r--ui/aura/test/aura_test_base.cc6
-rw-r--r--ui/aura/window_unittest.cc4
-rw-r--r--ui/views/test/views_test_base.cc5
-rw-r--r--ui/views/widget/native_widget_aura_unittest.cc5
25 files changed, 317 insertions, 222 deletions
diff --git a/ash/screen_ash.cc b/ash/screen_ash.cc
index 9847480..c884a15 100644
--- a/ash/screen_ash.cc
+++ b/ash/screen_ash.cc
@@ -12,6 +12,10 @@
namespace ash {
+// TODO(oshima): For m19, the origin of work area/monitor bounds for
+// views/aura is (0,0) because it's simple and enough. Fix this when
+// real multi monitor support is implemented.
+
namespace {
const aura::MonitorManager* GetMonitorManager() {
return aura::Env::GetInstance()->monitor_manager();
@@ -37,7 +41,9 @@ gfx::Rect ScreenAsh::GetMonitorWorkAreaNearestWindowImpl(
gfx::Rect ScreenAsh::GetMonitorAreaNearestWindowImpl(
gfx::NativeWindow window) {
- return GetMonitorManager()->GetMonitorNearestWindow(window)->bounds();
+ // See the comment at the top.
+ return gfx::Rect(
+ GetMonitorManager()->GetMonitorNearestWindow(window)->size());
}
gfx::Rect ScreenAsh::GetMonitorWorkAreaNearestPointImpl(
@@ -47,7 +53,8 @@ gfx::Rect ScreenAsh::GetMonitorWorkAreaNearestPointImpl(
}
gfx::Rect ScreenAsh::GetMonitorAreaNearestPointImpl(const gfx::Point& point) {
- return GetMonitorManager()->GetMonitorNearestPoint(point)->bounds();
+ // See the comment at the top.
+ return gfx::Rect(GetMonitorManager()->GetMonitorNearestPoint(point)->size());
}
gfx::NativeWindow ScreenAsh::GetWindowAtCursorScreenPointImpl() {
diff --git a/ash/shell.cc b/ash/shell.cc
index 0bac7f1..5aec3bd 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -65,6 +65,7 @@
#include "ui/aura/layout_manager.h"
#include "ui/aura/monitor.h"
#include "ui/aura/monitor_manager.h"
+#include "ui/aura/monitor_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/ui_controls_aura.h"
#include "ui/aura/window.h"
@@ -392,20 +393,21 @@ internal::WorkspaceController* Shell::TestApi::workspace_controller() {
// Shell, public:
Shell::Shell(ShellDelegate* delegate)
- : root_window_(new aura::RootWindow),
+ : root_window_(aura::Env::GetInstance()->monitor_manager()->
+ CreateRootWindowForPrimaryMonitor()),
screen_(new ScreenAsh(root_window_.get())),
root_filter_(NULL),
delegate_(delegate),
shelf_(NULL),
root_window_layout_(NULL),
status_widget_(NULL) {
- aura::Env::GetInstance()->SetMonitorManager(
- aura::CreateSingleMonitorManager(root_window_.get()));
gfx::Screen::SetInstance(screen_);
ui_controls::InstallUIControlsAura(CreateUIControlsAura(root_window_.get()));
+ aura::Env::GetInstance()->monitor_manager()->AddObserver(this);
}
Shell::~Shell() {
+ aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this);
RemoveRootWindowEventFilter(partial_screenshot_filter_.get());
RemoveRootWindowEventFilter(input_method_filter_.get());
RemoveRootWindowEventFilter(window_modality_controller_.get());
@@ -693,6 +695,14 @@ int Shell::GetGridSize() const {
}
////////////////////////////////////////////////////////////////////////////////
+// Shell, aura::MonitorObserver implementation:
+
+void Shell::OnMonitorBoundsChanged(const aura::Monitor* monitor) {
+ if (aura::RootWindow::use_fullscreen_host_window())
+ root_window_->SetHostSize(monitor->size());
+}
+
+////////////////////////////////////////////////////////////////////////////////
// Shell, private:
void Shell::InitLayoutManagers() {
diff --git a/ash/shell.h b/ash/shell.h
index 29e6e2b..ff52a12 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -15,6 +15,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
+#include "ui/aura/monitor_manager.h"
#include "ui/gfx/size.h"
#include "ui/gfx/insets.h"
@@ -77,7 +78,7 @@ class WorkspaceController;
//
// Upon creation, the Shell sets itself as the RootWindow's delegate, which
// takes ownership of the Shell.
-class ASH_EXPORT Shell {
+class ASH_EXPORT Shell : public aura::MonitorObserver {
public:
enum Direction {
FORWARD,
@@ -200,6 +201,9 @@ class ASH_EXPORT Shell {
// Returns the size of the grid.
int GetGridSize() const;
+ // aura::MonitorObserver overrides:
+ virtual void OnMonitorBoundsChanged(const aura::Monitor* monitor) OVERRIDE;
+
static void set_initially_hide_cursor(bool hide) {
initially_hide_cursor_ = hide;
}
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 b823553..1ac858a 100644
--- a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
+++ b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
@@ -127,9 +127,8 @@ class AccessibilityEventRouterViewsTest
virtual void SetUp() {
views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate();
#if defined(USE_AURA)
- root_window_.reset(new aura::RootWindow);
- aura::Env::GetInstance()->SetMonitorManager(
- aura::CreateSingleMonitorManager(root_window_.get()));
+ root_window_.reset(aura::Env::GetInstance()->monitor_manager()->
+ CreateRootWindowForPrimaryMonitor());
gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get()));
test_stacking_client_.reset(
new aura::test::TestStackingClient(root_window_.get()));
diff --git a/chrome/test/base/browser_with_test_window_test.cc b/chrome/test/base/browser_with_test_window_test.cc
index 9d80d9a..e03cce5 100644
--- a/chrome/test/base/browser_with_test_window_test.cc
+++ b/chrome/test/base/browser_with_test_window_test.cc
@@ -45,9 +45,8 @@ void BrowserWithTestWindowTest::SetUp() {
window_.reset(new TestBrowserWindow(browser()));
browser_->SetWindowForTesting(window_.get());
#if defined(USE_AURA)
- root_window_.reset(new aura::RootWindow);
- aura::Env::GetInstance()->SetMonitorManager(
- aura::CreateSingleMonitorManager(root_window_.get()));
+ root_window_.reset(aura::Env::GetInstance()->monitor_manager()->
+ CreateRootWindowForPrimaryMonitor());
gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get()));
test_activation_client_.reset(
new aura::test::TestActivationClient(root_window_.get()));
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 8d57ded..e46a883 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -77,6 +77,8 @@
'monitor.h',
'monitor_manager.cc',
'monitor_manager.h',
+ 'single_monitor_manager.h',
+ 'single_monitor_manager.cc',
'root_window_host.h',
'root_window_host_linux.cc',
'root_window_host_linux.h',
diff --git a/ui/aura/env.cc b/ui/aura/env.cc
index 006400f..61289f5 100644
--- a/ui/aura/env.cc
+++ b/ui/aura/env.cc
@@ -4,7 +4,7 @@
#include "ui/aura/env.h"
#include "ui/aura/env_observer.h"
-#include "ui/aura/monitor_manager.h"
+#include "ui/aura/single_monitor_manager.h"
#include "ui/aura/root_window_host.h"
#include "ui/aura/window.h"
@@ -21,6 +21,7 @@ Env::Env()
stacking_client_(NULL),
monitor_manager_(NULL)
{
+ SetMonitorManager(new internal::SingleMonitorManager());
#if !defined(OS_MACOSX)
dispatcher_.reset(CreateDispatcher());
#endif
diff --git a/ui/aura/monitor.cc b/ui/aura/monitor.cc
index 9566615..d631ffb 100644
--- a/ui/aura/monitor.cc
+++ b/ui/aura/monitor.cc
@@ -10,7 +10,10 @@ Monitor::Monitor() {
}
gfx::Rect Monitor::GetWorkAreaBounds() const {
- gfx::Rect bounds(bounds_);
+ // TODO(oshima): For m19, work area/monitor bounds has (0,0) origin
+ // because it's simpler and enough. Fix this when real multi monitor
+ // support is implemented.
+ gfx::Rect bounds(bounds_.size());
bounds.Inset(work_area_insets_);
return bounds;
}
diff --git a/ui/aura/monitor.h b/ui/aura/monitor.h
index a485b2b..b10bc19 100644
--- a/ui/aura/monitor.h
+++ b/ui/aura/monitor.h
@@ -19,18 +19,19 @@ class AURA_EXPORT Monitor {
// Sets/gets monitor's bounds in |gfx::screen|'s coordinates,
// which is relative to the primary screen's origin.
- void set_bounds(gfx::Rect& bounds) { bounds_ = bounds;}
+ void set_bounds(const gfx::Rect& bounds) { bounds_ = bounds;}
const gfx::Rect& bounds() const { return bounds_; };
+ // Sets/gets monitor's size.
+ void set_size(const gfx::Size& size) { bounds_.set_size(size); }
+ const gfx::Size& size() const { return bounds_.size(); }
+
// Sets/gets monitor's workarea insets.
void set_work_area_insets(const gfx::Insets& insets) {
work_area_insets_ = insets;
}
const gfx::Insets& work_area_insets() const { return work_area_insets_; }
- // Returns the monitor's size.
- const gfx::Size& size() const { return bounds_.size(); }
-
// Returns the monitor's work area.
gfx::Rect GetWorkAreaBounds() const;
diff --git a/ui/aura/monitor_manager.cc b/ui/aura/monitor_manager.cc
index 62b59b9..542750f 100644
--- a/ui/aura/monitor_manager.cc
+++ b/ui/aura/monitor_manager.cc
@@ -4,83 +4,29 @@
#include "ui/aura/monitor_manager.h"
-#include "base/basictypes.h"
-#include "base/stl_util.h"
-#include "ui/aura/monitor.h"
-#include "ui/aura/root_window.h"
-#include "ui/aura/window.h"
-#include "ui/aura/window_observer.h"
-#include "ui/gfx/rect.h"
-
namespace aura {
-namespace {
-
-// A monitor manager assuming there is one monitor.
-class SingleMonitorManager : public MonitorManager,
- public WindowObserver {
- public:
- SingleMonitorManager(RootWindow* root_window)
- : root_window_(root_window),
- monitor_(new Monitor()) {
- root_window_->AddObserver(this);
- Update(root_window_->bounds().size());
- }
-
- virtual ~SingleMonitorManager() {
- if (root_window_)
- root_window_->RemoveObserver(this);
- }
-
- // MonitorManager overrides:
- virtual const Monitor* GetMonitorNearestWindow(const Window* window) const {
- return monitor_.get();
- }
- virtual const Monitor* GetMonitorNearestPoint(const gfx::Point& point) const {
- return monitor_.get();
- }
- virtual const Monitor* GetPrimaryMonitor() const {
- return monitor_.get();
- }
- virtual size_t GetNumMonitors() const {
- return 1;
- }
- virtual Monitor* GetMonitorNearestWindow(const Window* window) {
- return monitor_.get();
- }
- // WindowObserver overrides:
- virtual void OnWindowBoundsChanged(Window* window, const gfx::Rect& bounds)
- OVERRIDE {
- Update(bounds.size());
- }
- virtual void OnWindowDestroying(Window* window) {
- if (root_window_ == window)
- root_window_ = NULL;
- }
-
- private:
- void Update(const gfx::Size size) {
- gfx::Rect new_bounds(size);
- monitor_->set_bounds(new_bounds);
- }
-
- RootWindow* root_window_;
- scoped_ptr<Monitor> monitor_;
+MonitorManager::MonitorManager() {
+}
- DISALLOW_COPY_AND_ASSIGN(SingleMonitorManager);
-};
+MonitorManager::~MonitorManager() {
+}
-} // namespace
+void MonitorManager::AddObserver(MonitorObserver* observer) {
+ observers_.AddObserver(observer);
+}
-MonitorManager::MonitorManager() {
+void MonitorManager::RemoveObserver(MonitorObserver* observer) {
+ observers_.RemoveObserver(observer);
}
-MonitorManager::~MonitorManager() {
+RootWindow* MonitorManager::CreateRootWindowForPrimaryMonitor() {
+ return CreateRootWindowForMonitor(GetPrimaryMonitor());
}
-// static
-MonitorManager* CreateSingleMonitorManager(RootWindow* root_window) {
- return new SingleMonitorManager(root_window);
+void MonitorManager::NotifyBoundsChanged(const Monitor* monitor) {
+ FOR_EACH_OBSERVER(MonitorObserver, observers_,
+ OnMonitorBoundsChanged(monitor));
}
} // namespace aura
diff --git a/ui/aura/monitor_manager.h b/ui/aura/monitor_manager.h
index a6775f5..2b2471e 100644
--- a/ui/aura/monitor_manager.h
+++ b/ui/aura/monitor_manager.h
@@ -6,13 +6,13 @@
#define UI_AURA_MONITOR_MANAGER_H_
#pragma once
-#include <vector>
-
#include "base/basictypes.h"
+#include "base/observer_list.h"
#include "ui/aura/aura_export.h"
-#include "ui/gfx/insets.h"
+
namespace gfx {
class Point;
+class Size;
}
namespace aura {
@@ -20,31 +20,60 @@ class Monitor;
class RootWindow;
class Window;
+// Observers for monitor configuration changes.
+// TODO(oshima): multiple monitor support.
+class MonitorObserver {
+ public:
+ virtual void OnMonitorBoundsChanged(const Monitor* monitor) = 0;
+};
+
+// MonitorManager creates, deletes and updates Monitor objects when
+// monitor configuration changes, and notifies MonitorObservers about
+// the change. This is owned by Env and its lifetime is longer than
+// any windows.
class AURA_EXPORT MonitorManager {
public:
MonitorManager();
virtual ~MonitorManager();
+ // Adds/removes MonitorObservers.
+ void AddObserver(MonitorObserver* observer);
+ void RemoveObserver(MonitorObserver* observer);
+
+ // Called when native window's monitor size has changed.
+ // 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;
+
// Returns the monitor object nearest given |window|.
virtual const Monitor* GetMonitorNearestWindow(
const Window* window) const = 0;
virtual Monitor* GetMonitorNearestWindow(const Window* window) = 0;
+
// Returns the monitor object nearest given |pint|.
virtual const Monitor* GetMonitorNearestPoint(
const gfx::Point& point) const = 0;
+
// Returns the monitor that is consiered "primary".
virtual const Monitor* GetPrimaryMonitor() const = 0;
+
virtual size_t GetNumMonitors() const = 0;
+ // A utility function to create a root window for primary monitor.
+ RootWindow* CreateRootWindowForPrimaryMonitor();
+
protected:
- friend class RootWindow;
+ // Calls observers' OnMonitorBoundsChanged methods.
+ void NotifyBoundsChanged(const Monitor* monitor);
private:
+ ObserverList<MonitorObserver> observers_;
+
DISALLOW_COPY_AND_ASSIGN(MonitorManager);
};
-AURA_EXPORT MonitorManager* CreateSingleMonitorManager(RootWindow* root_window);
-
} // namespace aura
#endif // UI_AURA_MONITOR_MANAGER_H_
diff --git a/ui/aura/monitor_manager_x11.cc b/ui/aura/monitor_manager_x11.cc
deleted file mode 100644
index 71fe23f..0000000
--- a/ui/aura/monitor_manager_x11.cc
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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/monitor_manager.h"
-
-namespace arua {
-namespace internal {
-
-class MonitorManagerX11 : public MonitorManager {
- SingleMonitorManager::SingleMonitorManager(RootWindow* root_window)
- : root_window_(root_window) {
- Update();
- }
- MonitorManagerX11::~MonitorManager() {
- STLDeleteContainerPointers(monitors_.begin(), monitors_.end());
- }
-
- void MonitorManager::Update() {
- }
-
-const Monitor* SingleMonitorManager::GetMonitorNearestWindow(
- const aura::Window* window) const {
- return GetMonitorNearestPoint(window->bounds().origin());
-}
-
-const Monitor* SingleMonitorManager::GetMonitorNearestPoint(
- const gfx::Point& point) const {
- for (Monitors::const_iterator iter = monitors_.begin();
- iter != monitors_.end(); ++iter) {
- if ((*iter)->bounds().Contains(point))
- return *iter;
- }
- return ;
-}
-
-const Monitor* SingleMonitorManager::GetPrimaryMonitor() const {
- return monitors_[0];
-}
-
-size_t MonitorManager::GetNumMonitors() const {
- return monitors_.size();
-}
-
-Monitor* MonitorManager::GetMonitorNearestWindow(const Window* window) {
- return const_cast<Monitor*>(
- GetMonitorNearestPoint(window->bounds().origin()));
-}
-
-} // namespace internal
-} // namespace aura
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 34c4793..1ea9751 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -4,15 +4,12 @@
#include "ui/aura/root_window.h"
-#include <string>
#include <vector>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop.h"
-#include "base/string_number_conversions.h"
-#include "base/string_split.h"
#include "ui/aura/aura_switches.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/env.h"
@@ -22,6 +19,8 @@
#include "ui/aura/event_filter.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/gestures/gesture_recognizer.h"
+#include "ui/aura/monitor.h"
+#include "ui/aura/monitor_manager.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/hit_test.h"
@@ -29,19 +28,12 @@
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/compositor/layer_animator.h"
-using std::string;
using std::vector;
namespace aura {
namespace {
-// Default bounds for the host window.
-static const int kDefaultHostWindowX = 200;
-static const int kDefaultHostWindowY = 200;
-static const int kDefaultHostWindowWidth = 1280;
-static const int kDefaultHostWindowHeight = 1024;
-
// Returns true if |target| has a non-client (frame) component at |location|,
// in window coordinates.
bool IsNonClientLocation(Window* target, const gfx::Point& location) {
@@ -113,7 +105,7 @@ RootWindow::RootWindow()
ui::Compositor::Initialize(false);
compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(),
- host_->GetSize()));
+ host_->GetBounds().size()));
DCHECK(compositor_.get());
compositor_->AddObserver(this);
Init();
@@ -140,14 +132,17 @@ void RootWindow::ShowRootWindow() {
}
void RootWindow::SetHostSize(const gfx::Size& size) {
- host_->SetSize(size);
+ DispatchHeldMouseMove();
+ gfx::Rect bounds = host_->GetBounds();
+ bounds.set_size(size);
+ host_->SetBounds(bounds);
// Requery the location to constrain it within the new root window size.
last_mouse_location_ = host_->QueryMouseLocation();
synthesize_mouse_move_ = false;
}
gfx::Size RootWindow::GetHostSize() const {
- gfx::Rect rect(host_->GetSize());
+ gfx::Rect rect(host_->GetBounds().size());
layer()->transform().TransformRect(&rect);
return rect.size();
}
@@ -309,12 +304,6 @@ void RootWindow::OnHostResized(const gfx::Size& size) {
OnRootWindowResized(bounds.size()));
}
-void RootWindow::OnNativeScreenResized(const gfx::Size& size) {
- DispatchHeldMouseMove();
- if (use_fullscreen_host_window_)
- SetHostSize(size);
-}
-
void RootWindow::OnWindowDestroying(Window* window) {
OnWindowHidden(window, true);
@@ -454,7 +443,7 @@ void RootWindow::SetTransform(const ui::Transform& transform) {
// If the layer is not animating, then we need to update the host size
// immediately.
if (!layer()->GetAnimator()->is_animating())
- OnHostResized(host_->GetSize());
+ OnHostResized(host_->GetBounds().size());
}
////////////////////////////////////////////////////////////////////////////////
@@ -736,7 +725,7 @@ internal::FocusManager* RootWindow::GetFocusManager() {
void RootWindow::OnLayerAnimationEnded(
ui::LayerAnimationSequence* animation) {
- OnHostResized(host_->GetSize());
+ OnHostResized(host_->GetBounds().size());
}
void RootWindow::OnLayerAnimationScheduled(
@@ -784,7 +773,7 @@ bool RootWindow::IsFocusedWindow(const Window* window) const {
void RootWindow::Init() {
Window::Init(ui::Layer::LAYER_NOT_DRAWN);
- SetBounds(gfx::Rect(host_->GetSize()));
+ SetBounds(gfx::Rect(host_->GetBounds().size()));
Show();
compositor()->SetRootLayer(layer());
host_->SetRootWindow(this);
@@ -846,23 +835,8 @@ void RootWindow::DispatchHeldMouseMove() {
}
gfx::Rect RootWindow::GetInitialHostWindowBounds() const {
- gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY,
- kDefaultHostWindowWidth, kDefaultHostWindowHeight);
-
- const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kAuraHostWindowSize);
- vector<string> parts;
- base::SplitString(size_str, 'x', &parts);
- int parsed_width = 0, parsed_height = 0;
- if (parts.size() == 2 &&
- base::StringToInt(parts[0], &parsed_width) && parsed_width > 0 &&
- base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) {
- bounds.set_size(gfx::Size(parsed_width, parsed_height));
- } else if (use_fullscreen_host_window_) {
- bounds = gfx::Rect(RootWindowHost::GetNativeScreenSize());
- }
-
- return bounds;
+ return Env::GetInstance()->monitor_manager()->
+ GetMonitorNearestWindow(this)->bounds();
}
void RootWindow::PostMouseMoveEventAfterWindowChange() {
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 7d12031..1d6c3bf 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -52,6 +52,7 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
RootWindow();
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;
}
@@ -124,9 +125,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// Called when the host changes size.
void OnHostResized(const gfx::Size& size);
- // Called when the native screen's resolution changes.
- void OnNativeScreenResized(const gfx::Size& size);
-
// Invoked when |window| is being destroyed.
void OnWindowDestroying(Window* window);
diff --git a/ui/aura/root_window_host.h b/ui/aura/root_window_host.h
index e41e8fd..2eb29b9 100644
--- a/ui/aura/root_window_host.h
+++ b/ui/aura/root_window_host.h
@@ -48,8 +48,8 @@ class RootWindowHost {
virtual void ToggleFullScreen() = 0;
// Gets/Sets the size of the RootWindowHost.
- virtual gfx::Size GetSize() const = 0;
- virtual void SetSize(const gfx::Size& size) = 0;
+ virtual gfx::Rect GetBounds() const = 0;
+ virtual void SetBounds(const gfx::Rect& bounds) = 0;
// Returns the location of the RootWindow on native screen.
virtual gfx::Point GetLocationOnNativeScreen() const = 0;
diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc
index a6c4e5a..3a91aea 100644
--- a/ui/aura/root_window_host_linux.cc
+++ b/ui/aura/root_window_host_linux.cc
@@ -13,13 +13,13 @@
#include "ui/aura/dispatcher_linux.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/base/keycodes/keyboard_codes.h"
#include "ui/base/touch/touch_factory.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/compositor/layer.h"
-
using std::max;
using std::min;
@@ -362,7 +362,7 @@ base::MessagePumpDispatcher::DispatchStatus RootWindowHostLinux::Dispatch(
break;
case ConfigureNotify: {
if (xev->xconfigure.window == x_root_window_) {
- root_window_->OnNativeScreenResized(
+ Env::GetInstance()->monitor_manager()->OnNativeMonitorResized(
gfx::Size(xev->xconfigure.width, xev->xconfigure.height));
handled = true;
break;
@@ -502,23 +502,27 @@ void RootWindowHostLinux::ToggleFullScreen() {
NOTIMPLEMENTED();
}
-gfx::Size RootWindowHostLinux::GetSize() const {
- return bounds_.size();
+gfx::Rect RootWindowHostLinux::GetBounds() const {
+ return bounds_;
}
-void RootWindowHostLinux::SetSize(const gfx::Size& size) {
- if (size == bounds_.size())
+void RootWindowHostLinux::SetBounds(const gfx::Rect& bounds) {
+ bool size_changed = bounds_.size() != bounds.size();
+ if (bounds == bounds_)
return;
-
- XResizeWindow(xdisplay_, xwindow_, size.width(), size.height());
+ if (bounds.size() != bounds_.size())
+ XResizeWindow(xdisplay_, xwindow_, bounds.width(), bounds.height());
+ if (bounds.origin() != bounds_.origin())
+ XMoveWindow(xdisplay_, xwindow_, bounds.x(), bounds.y());
// Assume that the resize will go through as requested, which should be the
// case if we're running without a window manager. If there's a window
// manager, it can modify or ignore the request, but (per ICCCM) we'll get a
// (possibly synthetic) ConfigureNotify about the actual size and correct
// |bounds_| later.
- bounds_.set_size(size);
- root_window_->OnHostResized(size);
+ bounds_ = bounds;
+ if (size_changed)
+ root_window_->OnHostResized(bounds.size());
}
gfx::Point RootWindowHostLinux::GetLocationOnNativeScreen() const {
diff --git a/ui/aura/root_window_host_linux.h b/ui/aura/root_window_host_linux.h
index 2ad9fe7..a045a52 100644
--- a/ui/aura/root_window_host_linux.h
+++ b/ui/aura/root_window_host_linux.h
@@ -31,8 +31,8 @@ class RootWindowHostLinux : public RootWindowHost {
virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
virtual void Show() OVERRIDE;
virtual void ToggleFullScreen() OVERRIDE;
- virtual gfx::Size GetSize() const OVERRIDE;
- virtual void SetSize(const gfx::Size& size) OVERRIDE;
+ virtual gfx::Rect GetBounds() const OVERRIDE;
+ virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
virtual void SetCapture() OVERRIDE;
virtual void ReleaseCapture() OVERRIDE;
diff --git a/ui/aura/root_window_host_win.cc b/ui/aura/root_window_host_win.cc
index 84f5103..868173c 100644
--- a/ui/aura/root_window_host_win.cc
+++ b/ui/aura/root_window_host_win.cc
@@ -171,23 +171,23 @@ void RootWindowHostWin::ToggleFullScreen() {
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}
-gfx::Size RootWindowHostWin::GetSize() const {
+gfx::Rect RootWindowHostWin::GetBounds() const {
RECT r;
GetClientRect(hwnd(), &r);
- return gfx::Rect(r).size();
+ return gfx::Rect(r);
}
-void RootWindowHostWin::SetSize(const gfx::Size& size) {
+void RootWindowHostWin::SetBounds(const gfx::Rect& bounds) {
if (fullscreen_) {
- saved_window_rect_.right = saved_window_rect_.left + size.width();
- saved_window_rect_.bottom = saved_window_rect_.top + size.height();
+ saved_window_rect_.right = saved_window_rect_.left + bounds.width();
+ saved_window_rect_.bottom = saved_window_rect_.top + bounds.height();
return;
}
RECT window_rect;
- window_rect.left = 0;
- window_rect.top = 0;
- window_rect.right = size.width();
- window_rect.bottom = size.height();
+ window_rect.left = bounds.x();
+ window_rect.top = bounds.y();
+ window_rect.right = bounds.width();
+ window_rect.bottom = bounds.height();
AdjustWindowRectEx(&window_rect,
GetWindowLong(hwnd(), GWL_STYLE),
FALSE,
@@ -241,7 +241,7 @@ gfx::Point RootWindowHostWin::QueryMouseLocation() {
POINT pt;
GetCursorPos(&pt);
ScreenToClient(hwnd(), &pt);
- const gfx::Size size = GetSize();
+ const gfx::Size size = GetBounds().size();
return gfx::Point(max(0, min(size.width(), static_cast<int>(pt.x))),
max(0, min(size.height(), static_cast<int>(pt.y))));
}
diff --git a/ui/aura/root_window_host_win.h b/ui/aura/root_window_host_win.h
index 1c1a25a..e64c40b 100644
--- a/ui/aura/root_window_host_win.h
+++ b/ui/aura/root_window_host_win.h
@@ -22,8 +22,8 @@ class RootWindowHostWin : public RootWindowHost, public ui::WindowImpl {
virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
virtual void Show() OVERRIDE;
virtual void ToggleFullScreen() OVERRIDE;
- virtual gfx::Size GetSize() const OVERRIDE;
- virtual void SetSize(const gfx::Size& size) OVERRIDE;
+ virtual gfx::Rect GetBounds() const OVERRIDE;
+ virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
virtual void SetCapture() OVERRIDE;
virtual void ReleaseCapture() OVERRIDE;
diff --git a/ui/aura/single_monitor_manager.cc b/ui/aura/single_monitor_manager.cc
new file mode 100644
index 0000000..e0ce3c0
--- /dev/null
+++ b/ui/aura/single_monitor_manager.cc
@@ -0,0 +1,113 @@
+// 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/single_monitor_manager.h"
+
+#include <string>
+
+#include "base/command_line.h"
+#include "ui/aura/aura_switches.h"
+#include "ui/aura/monitor.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/root_window_host.h"
+#include "ui/gfx/rect.h"
+
+namespace aura {
+namespace internal {
+
+using std::string;
+
+namespace {
+// Default bounds for the primary monitor.
+static const int kDefaultHostWindowX = 200;
+static const int kDefaultHostWindowY = 200;
+static const int kDefaultHostWindowWidth = 1280;
+static const int kDefaultHostWindowHeight = 1024;
+}
+
+SingleMonitorManager::SingleMonitorManager()
+ : root_window_(NULL),
+ monitor_(new Monitor()) {
+ Init();
+}
+
+SingleMonitorManager::~SingleMonitorManager() {
+ if (root_window_)
+ root_window_->RemoveObserver(this);
+}
+
+void SingleMonitorManager::OnNativeMonitorResized(const gfx::Size& size) {
+ if (RootWindow::use_fullscreen_host_window()) {
+ monitor_->set_size(size);
+ NotifyBoundsChanged(monitor_.get());
+ }
+}
+
+RootWindow* SingleMonitorManager::CreateRootWindowForMonitor(
+ const Monitor* monitor) {
+ DCHECK(!root_window_);
+ DCHECK_EQ(monitor_.get(), monitor);
+ root_window_ = new RootWindow();
+ root_window_->AddObserver(this);
+ return root_window_;
+}
+
+const Monitor* SingleMonitorManager::GetMonitorNearestWindow(
+ const Window* window) const {
+ return monitor_.get();
+}
+
+const Monitor* SingleMonitorManager::GetMonitorNearestPoint(
+ const gfx::Point& point) const {
+ return monitor_.get();
+}
+
+const Monitor* SingleMonitorManager::GetPrimaryMonitor() const {
+ return monitor_.get();
+}
+
+size_t SingleMonitorManager::GetNumMonitors() const {
+ return 1;
+}
+
+Monitor* SingleMonitorManager::GetMonitorNearestWindow(const Window* window) {
+ return monitor_.get();
+}
+
+void SingleMonitorManager::OnWindowBoundsChanged(
+ Window* window, const gfx::Rect& bounds) {
+ if (!RootWindow::use_fullscreen_host_window()) {
+ Update(bounds.size());
+ NotifyBoundsChanged(monitor_.get());
+ }
+}
+
+void SingleMonitorManager::OnWindowDestroying(Window* window) {
+ if (root_window_ == window)
+ root_window_ = NULL;
+}
+
+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);
+}
+
+void SingleMonitorManager::Update(const gfx::Size size) {
+ monitor_->set_size(size);
+}
+
+} // namespace inernal
+} // namespace aura
diff --git a/ui/aura/single_monitor_manager.h b/ui/aura/single_monitor_manager.h
new file mode 100644
index 0000000..b479d7f
--- /dev/null
+++ b/ui/aura/single_monitor_manager.h
@@ -0,0 +1,58 @@
+// 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_SINGLE_MONITOR_MANAGER_H_
+#define UI_AURA_SINGLE_MONITOR_MANAGER_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/aura/monitor_manager.h"
+#include "ui/aura/window_observer.h"
+
+namespace gfx {
+class Rect;
+}
+
+namespace aura {
+namespace internal {
+
+// A monitor manager assuming there is one monitor.
+class SingleMonitorManager : public MonitorManager,
+ public WindowObserver {
+ public:
+ SingleMonitorManager();
+ virtual ~SingleMonitorManager();
+
+ // MonitorManager overrides:
+ virtual void OnNativeMonitorResized(const gfx::Size& size);
+ virtual RootWindow* CreateRootWindowForMonitor(
+ const 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 size_t GetNumMonitors() const OVERRIDE;
+ virtual Monitor* GetMonitorNearestWindow(const Window* window) OVERRIDE;
+
+ // WindowObserver overrides:
+ virtual void OnWindowBoundsChanged(Window* window,
+ const gfx::Rect& bounds) OVERRIDE;
+ virtual void OnWindowDestroying(Window* window) OVERRIDE;
+
+ private:
+ void Init();
+ void Update(const gfx::Size size);
+
+ RootWindow* root_window_;
+ scoped_ptr<Monitor> monitor_;
+
+ DISALLOW_COPY_AND_ASSIGN(SingleMonitorManager);
+};
+
+} // namespace internal
+} // namespace aura
+
+#endif // UI_AURA_SINGLE_MONITOR_MANAGER_H_
diff --git a/ui/aura/test/aura_test_base.cc b/ui/aura/test/aura_test_base.cc
index dee54f6..592c780 100644
--- a/ui/aura/test/aura_test_base.cc
+++ b/ui/aura/test/aura_test_base.cc
@@ -6,6 +6,7 @@
#include "ui/aura/env.h"
#include "ui/aura/monitor_manager.h"
+#include "ui/aura/single_monitor_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_stacking_client.h"
@@ -23,10 +24,9 @@ AuraTestBase::~AuraTestBase() {
void AuraTestBase::SetUp() {
testing::Test::SetUp();
- root_window_.reset(new aura::RootWindow);
+ root_window_.reset(Env::GetInstance()->monitor_manager()->
+ CreateRootWindowForPrimaryMonitor());
gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get()));
- Env::GetInstance()->SetMonitorManager(
- CreateSingleMonitorManager(root_window_.get()));
ui_controls::InstallUIControlsAura(CreateUIControlsAura(root_window_.get()));
helper_.InitRootWindow(root_window());
helper_.SetUp();
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index b2cb6715..c55e534 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -906,8 +906,8 @@ TEST_F(WindowTest, Transform) {
gfx::Size transformed_size(size.height(), size.width());
EXPECT_EQ(transformed_size.ToString(),
root_window()->GetHostSize().ToString());
- EXPECT_EQ(gfx::Rect(transformed_size).ToString(),
- root_window()->bounds().ToString());
+ EXPECT_EQ(transformed_size.ToString(),
+ root_window()->bounds().size().ToString());
EXPECT_EQ(gfx::Rect(transformed_size).ToString(),
gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()).ToString());
}
diff --git a/ui/views/test/views_test_base.cc b/ui/views/test/views_test_base.cc
index 42ae3dd..c41ea5b 100644
--- a/ui/views/test/views_test_base.cc
+++ b/ui/views/test/views_test_base.cc
@@ -79,9 +79,8 @@ void ViewsTestBase::SetUp() {
if (!views_delegate_.get())
views_delegate_.reset(new TestViewsDelegate());
#if defined(USE_AURA)
- root_window_.reset(new aura::RootWindow);
- aura::Env::GetInstance()->SetMonitorManager(
- aura::CreateSingleMonitorManager(root_window_.get()));
+ root_window_.reset(aura::Env::GetInstance()->monitor_manager()->
+ 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 382e389..dd8759a 100644
--- a/ui/views/widget/native_widget_aura_unittest.cc
+++ b/ui/views/widget/native_widget_aura_unittest.cc
@@ -36,9 +36,8 @@ class NativeWidgetAuraTest : public testing::Test {
// testing::Test overrides:
virtual void SetUp() OVERRIDE {
- root_window_.reset(new aura::RootWindow);
- aura::Env::GetInstance()->SetMonitorManager(
- aura::CreateSingleMonitorManager(root_window_.get()));
+ root_window_.reset(aura::Env::GetInstance()->monitor_manager()->
+ 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));