diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 20:03:41 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 20:03:41 +0000 |
commit | b82c42c45ee1b113377a2800b36d6e5e05b8b8e1 (patch) | |
tree | 6034126ffc720a18cabc0bdb211de7ca10233670 | |
parent | ce8d264d556f06a4b46b58b95bc82a884bb315d0 (diff) | |
download | chromium_src-b82c42c45ee1b113377a2800b36d6e5e05b8b8e1.zip chromium_src-b82c42c45ee1b113377a2800b36d6e5e05b8b8e1.tar.gz chromium_src-b82c42c45ee1b113377a2800b36d6e5e05b8b8e1.tar.bz2 |
* Separated implementation class from gfx::Screen
* Moved Monitor class to gfx/.
* Converted all use of gfx::Screen to match new API
BUG=115347,111990
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9960042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133961 0039d316-1c4b-4281-b951-d872f2087c98
101 files changed, 949 insertions, 922 deletions
diff --git a/ash/app_list/app_list.cc b/ash/app_list/app_list.cc index cfa35bc..cd56f6c 100644 --- a/ash/app_list/app_list.cc +++ b/ash/app_list/app_list.cc @@ -36,7 +36,7 @@ const int kSecondAnimationStartDelay = kAnimationDurationMs - 20; gfx::Rect GetPreferredBounds() { gfx::Point cursor = gfx::Screen::GetCursorScreenPoint(); // Use full monitor rect so that the app list shade goes behind the launcher. - return gfx::Screen::GetMonitorAreaNearestPoint(cursor); + return gfx::Screen::GetMonitorNearestPoint(cursor).bounds(); } ui::Layer* GetLayer(views::Widget* widget) { diff --git a/ash/app_list/app_list_view.cc b/ash/app_list/app_list_view.cc index 28b8110..84f68f5 100644 --- a/ash/app_list/app_list_view.cc +++ b/ash/app_list/app_list_view.cc @@ -124,8 +124,8 @@ void AppListView::Layout() { // Gets work area rect, which is in screen coordinates. gfx::Rect workarea = Shell::GetInstance()->shelf()->IsVisible() ? ScreenAsh::GetUnmaximizedWorkAreaBounds(GetWidget()->GetNativeView()) : - gfx::Screen::GetMonitorWorkAreaNearestWindow( - GetWidget()->GetNativeView()); + gfx::Screen::GetMonitorNearestWindow( + GetWidget()->GetNativeView()).work_area(); // Converts |workarea| into view's coordinates. gfx::Point origin(workarea.origin()); diff --git a/ash/monitor/monitor_controller.cc b/ash/monitor/monitor_controller.cc index 3ebfea4..145fa67 100644 --- a/ash/monitor/monitor_controller.cc +++ b/ash/monitor/monitor_controller.cc @@ -13,9 +13,9 @@ #include "base/stl_util.h" #include "base/time.h" #include "ui/aura/env.h" -#include "ui/aura/monitor.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" +#include "ui/gfx/monitor.h" namespace ash { namespace internal { @@ -46,38 +46,38 @@ MonitorController::MonitorController() { MonitorController::~MonitorController() { aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this); // Remove the root first. - aura::Monitor* monitor = Shell::GetRootWindow()->GetProperty(kMonitorKey); - DCHECK(monitor); - root_windows_.erase(monitor); + int monitor_id = Shell::GetRootWindow()->GetProperty(kMonitorIdKey); + DCHECK(monitor_id >= 0); + root_windows_.erase(monitor_id); STLDeleteContainerPairSecondPointers( root_windows_.begin(), root_windows_.end()); } -void MonitorController::OnMonitorBoundsChanged(const aura::Monitor* monitor) { - root_windows_[monitor]->SetHostBounds(monitor->bounds()); +void MonitorController::OnMonitorBoundsChanged(const gfx::Monitor& monitor) { + root_windows_[monitor.id()]->SetHostBounds(monitor.bounds()); } -void MonitorController::OnMonitorAdded(aura::Monitor* monitor) { +void MonitorController::OnMonitorAdded(const gfx::Monitor& monitor) { if (root_windows_.empty()) { - root_windows_[monitor] = Shell::GetRootWindow(); - Shell::GetRootWindow()->SetHostBounds(monitor->bounds()); + root_windows_[monitor.id()] = Shell::GetRootWindow(); + Shell::GetRootWindow()->SetHostBounds(monitor.bounds()); return; } aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> CreateRootWindowForMonitor(monitor); - root_windows_[monitor] = root; + root_windows_[monitor.id()] = root; SetupAsSecondaryMonitor(root); } -void MonitorController::OnMonitorRemoved(const aura::Monitor* monitor) { - aura::RootWindow* root = root_windows_[monitor]; +void MonitorController::OnMonitorRemoved(const gfx::Monitor& monitor) { + aura::RootWindow* root = root_windows_[monitor.id()]; DCHECK(root); // Primary monitor should never be removed by MonitorManager. DCHECK(root != Shell::GetRootWindow()); // Monitor for root window will be deleted when the Primary RootWindow // is deleted by the Shell. if (root != Shell::GetRootWindow()) { - root_windows_.erase(monitor); + root_windows_.erase(monitor.id()); delete root; } } @@ -86,16 +86,15 @@ void MonitorController::Init() { aura::MonitorManager* monitor_manager = aura::Env::GetInstance()->monitor_manager(); for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) { - aura::Monitor* monitor = monitor_manager->GetMonitorAt(i); - const aura::Monitor* key = monitor; + const gfx::Monitor& monitor = monitor_manager->GetMonitorAt(i); if (i == 0) { // Primary monitor - root_windows_[key] = Shell::GetRootWindow(); - Shell::GetRootWindow()->SetHostBounds(monitor->bounds()); + root_windows_[monitor.id()] = Shell::GetRootWindow(); + Shell::GetRootWindow()->SetHostBounds(monitor.bounds()); } else { aura::RootWindow* root = monitor_manager->CreateRootWindowForMonitor(monitor); - root_windows_[key] = root; + root_windows_[monitor.id()] = root; SetupAsSecondaryMonitor(root); } } diff --git a/ash/monitor/monitor_controller.h b/ash/monitor/monitor_controller.h index bfbd568..dabfa41 100644 --- a/ash/monitor/monitor_controller.h +++ b/ash/monitor/monitor_controller.h @@ -11,8 +11,10 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "ui/aura/monitor_manager.h" +#include "ui/aura/monitor_observer.h" namespace aura { +class Monitor; class RootWindow; } @@ -27,14 +29,15 @@ class MonitorController : public aura::MonitorObserver { virtual ~MonitorController(); // aura::MonitorObserver overrides: - virtual void OnMonitorBoundsChanged(const aura::Monitor* monitor) OVERRIDE; - virtual void OnMonitorAdded(aura::Monitor* monitor) OVERRIDE; - virtual void OnMonitorRemoved(const aura::Monitor* monitor) OVERRIDE; + virtual void OnMonitorBoundsChanged( + const gfx::Monitor& monitor) OVERRIDE; + virtual void OnMonitorAdded(const gfx::Monitor& monitor) OVERRIDE; + virtual void OnMonitorRemoved(const gfx::Monitor& monitor) OVERRIDE; private: void Init(); - std::map<const aura::Monitor*, aura::RootWindow*> root_windows_; + std::map<int, aura::RootWindow*> root_windows_; DISALLOW_COPY_AND_ASSIGN(MonitorController); }; diff --git a/ash/monitor/multi_monitor_manager.cc b/ash/monitor/multi_monitor_manager.cc index 46dddad..e03219d 100644 --- a/ash/monitor/multi_monitor_manager.cc +++ b/ash/monitor/multi_monitor_manager.cc @@ -12,40 +12,36 @@ #include "base/string_split.h" #include "ui/aura/aura_switches.h" #include "ui/aura/env.h" -#include "ui/aura/monitor.h" #include "ui/aura/root_window.h" #include "ui/aura/root_window_host.h" -#include "ui/gfx/rect.h" #include "ui/aura/window_property.h" +#include "ui/gfx/monitor.h" +#include "ui/gfx/rect.h" -DECLARE_WINDOW_PROPERTY_TYPE(aura::Monitor*); +DECLARE_WINDOW_PROPERTY_TYPE(int); namespace ash { namespace internal { namespace { - -aura::Monitor* Copy(aura::Monitor* m) { - aura::Monitor* monitor = new aura::Monitor; - monitor->set_bounds(m->bounds()); - return monitor; +gfx::Monitor& GetInvalidMonitor() { + static gfx::Monitor* invalid_monitor = new gfx::Monitor(); + return *invalid_monitor; } - } // namespace -DEFINE_WINDOW_PROPERTY_KEY(aura::Monitor*, kMonitorKey, NULL); - -using std::string; -using std::vector; -using aura::Monitor; using aura::RootWindow; using aura::Window; +using gfx::Monitor; +using std::string; +using std::vector; + +DEFINE_WINDOW_PROPERTY_KEY(int, kMonitorIdKey, -1); MultiMonitorManager::MultiMonitorManager() { Init(); } MultiMonitorManager::~MultiMonitorManager() { - STLDeleteContainerPointers(monitors_.begin(), monitors_.end()); } // static @@ -62,20 +58,22 @@ void MultiMonitorManager::CycleMonitor() { } void MultiMonitorManager::OnNativeMonitorsChanged( - const std::vector<const aura::Monitor*>& new_monitors) { + const std::vector<Monitor>& new_monitors) { size_t min = std::min(monitors_.size(), new_monitors.size()); // For m19, we only care about 1st monitor as primary, and // don't differentiate the rest of monitors as all secondary - // monitors have the same content. + // monitors have the same content. ID for primary monitor stays the same + // because we never remove it, we don't update IDs for other monitors + // , for now, because they're the same. // TODO(oshima): Fix this so that we can differentiate outputs // and keep a content on one monitor stays on the same monitor // when a monitor is added or removed. for (size_t i = 0; i < min; ++i) { - Monitor* current_monitor = monitors_[i]; - const Monitor* new_monitor = new_monitors[i]; - if (current_monitor->bounds() != new_monitor->bounds()) { - current_monitor->set_bounds(new_monitor->bounds()); + Monitor& current_monitor = monitors_[i]; + const Monitor& new_monitor = new_monitors[i]; + if (current_monitor.bounds() != new_monitor.bounds()) { + current_monitor.SetBoundsAndUpdateWorkArea(new_monitor.bounds()); NotifyBoundsChanged(current_monitor); } } @@ -83,9 +81,10 @@ void MultiMonitorManager::OnNativeMonitorsChanged( if (monitors_.size() < new_monitors.size()) { // New monitors added for (size_t i = min; i < new_monitors.size(); ++i) { - Monitor* monitor = new Monitor(); - monitor->set_bounds(new_monitors[i]->bounds()); - monitors_.push_back(monitor); + // + monitors_.push_back(Monitor(i)); + gfx::Monitor& monitor = monitors_.back(); + monitor.SetBoundsAndUpdateWorkArea(new_monitors[i].bounds()); NotifyMonitorAdded(monitor); } } else { @@ -93,35 +92,45 @@ void MultiMonitorManager::OnNativeMonitorsChanged( // monitor (at index 0) because it needs the monitor information // even if it doesn't exit. while (monitors_.size() > new_monitors.size() && monitors_.size() > 1) { - Monitor* monitor = monitors_.back(); - NotifyMonitorRemoved(monitor); - monitors_.erase(std::find(monitors_.begin(), monitors_.end(), monitor)); - delete monitor; + Monitors::reverse_iterator iter = monitors_.rbegin(); + NotifyMonitorRemoved(*iter); + monitors_.erase(iter.base() - 1); } } } RootWindow* MultiMonitorManager::CreateRootWindowForMonitor( - Monitor* monitor) { - RootWindow* root_window = new RootWindow(monitor->bounds()); + const Monitor& monitor) { + RootWindow* root_window = new RootWindow(monitor.bounds()); // No need to remove RootWindowObserver because // the MonitorManager object outlives RootWindow objects. root_window->AddRootWindowObserver(this); - root_window->SetProperty(kMonitorKey, monitor); + root_window->SetProperty(kMonitorIdKey, monitor.id()); return root_window; } -const Monitor* MultiMonitorManager::GetMonitorNearestWindow( +const Monitor& MultiMonitorManager::GetMonitorAt(size_t index) { + return index < monitors_.size() ? monitors_[index] : GetInvalidMonitor(); +} + +size_t MultiMonitorManager::GetNumMonitors() const { + return monitors_.size(); +} + +const Monitor& MultiMonitorManager::GetMonitorNearestWindow( const Window* window) const { if (!window) { MultiMonitorManager* manager = const_cast<MultiMonitorManager*>(this); return manager->GetMonitorAt(0); } const RootWindow* root = window->GetRootWindow(); - return root ? root->GetProperty(kMonitorKey) : NULL; + MultiMonitorManager* that = const_cast<MultiMonitorManager*>(this); + return root ? + that->FindMonitorById(root->GetProperty(kMonitorIdKey)) : + GetInvalidMonitor(); } -const Monitor* MultiMonitorManager::GetMonitorNearestPoint( +const Monitor& MultiMonitorManager::GetMonitorNearestPoint( const gfx::Point& point) const { // TODO(oshima): For m19, mouse is constrained within // the primary window. @@ -129,28 +138,26 @@ const Monitor* MultiMonitorManager::GetMonitorNearestPoint( return manager->GetMonitorAt(0); } -Monitor* MultiMonitorManager::GetMonitorAt(size_t index) { - return index < monitors_.size() ? monitors_[index] : NULL; -} - -size_t MultiMonitorManager::GetNumMonitors() const { - return monitors_.size(); -} - -Monitor* MultiMonitorManager::GetMonitorNearestWindow(const Window* window) { - const MonitorManager* manager = this; - return const_cast<Monitor*>(manager->GetMonitorNearestWindow(window)); -} - void MultiMonitorManager::OnRootWindowResized(const aura::RootWindow* root, const gfx::Size& old_size) { if (!use_fullscreen_host_window()) { - Monitor* monitor = root->GetProperty(kMonitorKey); - monitor->set_size(root->GetHostSize()); + int monitor_id = root->GetProperty(kMonitorIdKey); + Monitor& monitor = FindMonitorById(monitor_id); + monitor.SetSizeAndUpdateWorkArea(root->GetHostSize()); NotifyBoundsChanged(monitor); } } +bool MultiMonitorManager::UpdateWorkAreaOfMonitorNearestWindow( + const aura::Window* window, + const gfx::Insets& insets) { + const RootWindow* root = window->GetRootWindow(); + Monitor& monitor = FindMonitorById(root->GetProperty(kMonitorIdKey)); + gfx::Rect old_work_area = monitor.work_area(); + monitor.UpdateWorkAreaWithInsets(insets); + return old_work_area != monitor.work_area(); +} + void MultiMonitorManager::Init() { // TODO(oshima): Move this logic to MonitorChangeObserver. const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( @@ -166,35 +173,43 @@ void MultiMonitorManager::Init() { } void MultiMonitorManager::AddRemoveMonitorImpl() { - std::vector<const Monitor*> new_monitors; + std::vector<Monitor> new_monitors; if (monitors_.size() > 1) { // Remove if there is more than one monitor. int count = monitors_.size() - 1; for (Monitors::const_iterator iter = monitors_.begin(); count-- > 0; ++iter) - new_monitors.push_back(Copy(*iter)); + new_monitors.push_back(*iter); } else { // Add if there is only one monitor. - new_monitors.push_back(Copy(monitors_[0])); - aura::Monitor* extra_monitor = new Monitor; - extra_monitor->set_bounds(gfx::Rect(100, 100, 1440, 800)); - new_monitors.push_back(extra_monitor); + new_monitors.push_back(monitors_[0]); + new_monitors.push_back(CreateMonitorFromSpec("50+50-1280x768")); } if (new_monitors.size()) OnNativeMonitorsChanged(new_monitors); - STLDeleteContainerPointers(new_monitors.begin(), new_monitors.end()); } void MultiMonitorManager::CycleMonitorImpl() { if (monitors_.size() > 1) { - std::vector<const Monitor*> new_monitors; + std::vector<Monitor> new_monitors; for (Monitors::const_iterator iter = monitors_.begin() + 1; - iter != monitors_.end(); ++iter) - new_monitors.push_back(Copy(*iter)); - new_monitors.push_back(Copy(monitors_.front())); + iter != monitors_.end(); ++iter) { + gfx::Monitor monitor = *iter; + new_monitors.push_back(monitor); + } + new_monitors.push_back(monitors_.front()); OnNativeMonitorsChanged(new_monitors); - STLDeleteContainerPointers(new_monitors.begin(), new_monitors.end()); } } +gfx::Monitor& MultiMonitorManager::FindMonitorById(int id) { + for (Monitors::iterator iter = monitors_.begin(); + iter != monitors_.end(); ++iter) { + if ((*iter).id() == id) + return *iter; + } + DLOG(FATAL) << "Could not find monitor by id:" << id; + return GetInvalidMonitor(); +} + } // namespace internal } // namespace ash diff --git a/ash/monitor/multi_monitor_manager.h b/ash/monitor/multi_monitor_manager.h index 2bbfcbb..6ecd8a7 100644 --- a/ash/monitor/multi_monitor_manager.h +++ b/ash/monitor/multi_monitor_manager.h @@ -13,6 +13,11 @@ #include "ui/aura/root_window_observer.h" #include "ui/aura/window.h" +namespace gfx { +class Insets; +class Monitor; +} + namespace ash { namespace internal { @@ -33,37 +38,40 @@ class ASH_EXPORT MultiMonitorManager : public aura::MonitorManager, static void AddRemoveMonitor(); static void CycleMonitor(); + bool UpdateWorkAreaOfMonitorNearestWindow(const aura::Window* window, + const gfx::Insets& insets); + // MonitorManager overrides: virtual void OnNativeMonitorsChanged( - const std::vector<const aura::Monitor*>& monitors) OVERRIDE; + const std::vector<gfx::Monitor>& monitors) OVERRIDE; virtual aura::RootWindow* CreateRootWindowForMonitor( - aura::Monitor* monitor) OVERRIDE; - virtual const aura::Monitor* GetMonitorNearestWindow( - const aura::Window* window) const OVERRIDE; - virtual const aura::Monitor* GetMonitorNearestPoint( - const gfx::Point& point) const OVERRIDE; - virtual aura::Monitor* GetMonitorAt(size_t index) OVERRIDE; + const gfx::Monitor& monitor) OVERRIDE; + virtual const gfx::Monitor& GetMonitorAt(size_t index) OVERRIDE; + virtual size_t GetNumMonitors() const OVERRIDE; - virtual aura::Monitor* GetMonitorNearestWindow( - const aura::Window* window) OVERRIDE; + virtual const gfx::Monitor& GetMonitorNearestPoint( + const gfx::Point& point) const OVERRIDE; + virtual const gfx::Monitor& GetMonitorNearestWindow( + const aura::Window* window) const OVERRIDE; // RootWindowObserver overrides: virtual void OnRootWindowResized(const aura::RootWindow* root, const gfx::Size& new_size) OVERRIDE; private: - typedef std::vector<aura::Monitor*> Monitors; + typedef std::vector<gfx::Monitor> Monitors; void Init(); void AddRemoveMonitorImpl(); void CycleMonitorImpl(); + gfx::Monitor& FindMonitorById(int id); Monitors monitors_; DISALLOW_COPY_AND_ASSIGN(MultiMonitorManager); }; -extern const aura::WindowProperty<aura::Monitor*>* const kMonitorKey; +extern const aura::WindowProperty<int>* const kMonitorIdKey; } // namespace internal } // namespace ash diff --git a/ash/monitor/multi_monitor_manager_unittest.cc b/ash/monitor/multi_monitor_manager_unittest.cc index afd0013..905c0d4 100644 --- a/ash/monitor/multi_monitor_manager_unittest.cc +++ b/ash/monitor/multi_monitor_manager_unittest.cc @@ -7,26 +7,26 @@ #include "ash/shell.h" #include "ash/test/ash_test_base.h" #include "base/format_macros.h" -#include "base/stl_util.h" #include "base/string_split.h" #include "base/stringprintf.h" #include "ui/aura/env.h" -#include "ui/aura/monitor.h" +#include "ui/aura/monitor_observer.h" #include "ui/aura/root_window.h" #include "ui/aura/window_observer.h" +#include "ui/gfx/monitor.h" namespace ash { namespace test { using std::vector; using std::string; -using aura::Monitor; +using gfx::Monitor; namespace { -vector<const aura::Monitor*> CreateMonitorsFromString( +vector<Monitor> CreateMonitorsFromString( const std::string specs) { - vector<const aura::Monitor*> monitors; + vector<Monitor> monitors; vector<string> parts; base::SplitString(specs, ',', &parts); for (vector<string>::const_iterator iter = parts.begin(); @@ -62,8 +62,8 @@ class MultiMonitorManagerTest : public test::AshTestBase, aura::MonitorManager* monitor_manager() { return aura::Env::GetInstance()->monitor_manager(); } - const vector<const Monitor*>& changed() const { return changed_; } - const vector<const Monitor*>& added() const { return added_; } + const vector<Monitor>& changed() const { return changed_; } + const vector<Monitor>& added() const { return added_; } string GetCountSummary() const { return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS, @@ -82,13 +82,13 @@ class MultiMonitorManagerTest : public test::AshTestBase, } // aura::MonitorObserver overrides: - virtual void OnMonitorBoundsChanged(const Monitor* monitor) OVERRIDE { + virtual void OnMonitorBoundsChanged(const Monitor& monitor) OVERRIDE { changed_.push_back(monitor); } - virtual void OnMonitorAdded(Monitor* new_monitor) OVERRIDE { + virtual void OnMonitorAdded(const Monitor& new_monitor) OVERRIDE { added_.push_back(new_monitor); } - virtual void OnMonitorRemoved(const Monitor* old_monitor) OVERRIDE { + virtual void OnMonitorRemoved(const Monitor& old_monitor) OVERRIDE { ++removed_count_; } @@ -99,14 +99,13 @@ class MultiMonitorManagerTest : public test::AshTestBase, } void UpdateMonitor(const std::string str) { - vector<const aura::Monitor*> monitors = CreateMonitorsFromString(str); + vector<Monitor> monitors = CreateMonitorsFromString(str); monitor_manager()->OnNativeMonitorsChanged(monitors); - STLDeleteContainerPointers(monitors.begin(), monitors.end()); } private: - vector<const Monitor*> changed_; - vector<const Monitor*> added_; + vector<Monitor> changed_; + vector<Monitor> added_; size_t removed_count_; bool root_window_destroyed_; @@ -122,10 +121,10 @@ TEST_F(MultiMonitorManagerTest, NativeMonitorTest) { UpdateMonitor("0+0-500x500,0+501-400x400"); EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); EXPECT_EQ("1 1 0", GetCountSummary()); - EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); - EXPECT_EQ(monitor_manager()->GetMonitorAt(1), added()[0]); - EXPECT_EQ("0,0 500x500", changed()[0]->bounds().ToString()); - EXPECT_EQ("0,501 400x400", added()[0]->bounds().ToString()); + EXPECT_EQ(monitor_manager()->GetMonitorAt(0).id(), changed()[0].id()); + EXPECT_EQ(monitor_manager()->GetMonitorAt(1).id(), added()[0].id()); + EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString()); + EXPECT_EQ("0,501 400x400", added()[0].bounds().ToString()); reset(); // Delete secondary. @@ -136,35 +135,35 @@ TEST_F(MultiMonitorManagerTest, NativeMonitorTest) { // Change primary. UpdateMonitor("0+0-1000x600"); EXPECT_EQ("1 0 0", GetCountSummary()); - EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); - EXPECT_EQ("0,0 1000x600", changed()[0]->bounds().ToString()); + EXPECT_EQ(monitor_manager()->GetMonitorAt(0).id(), changed()[0].id()); + EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString()); reset(); // Add secondary. UpdateMonitor("0+0-1000x600,1001+0-600x400"); EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); EXPECT_EQ("0 1 0", GetCountSummary()); - EXPECT_EQ(monitor_manager()->GetMonitorAt(1), added()[0]); - EXPECT_EQ("1001,0 600x400", added()[0]->bounds().ToString()); + EXPECT_EQ(monitor_manager()->GetMonitorAt(1).id(), added()[0].id()); + EXPECT_EQ("1001,0 600x400", added()[0].bounds().ToString()); reset(); // Secondary removed, primary changed. UpdateMonitor("0+0-800x300"); EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); EXPECT_EQ("1 0 1", GetCountSummary()); - EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); - EXPECT_EQ("0,0 800x300", changed()[0]->bounds().ToString()); + EXPECT_EQ(monitor_manager()->GetMonitorAt(0).id(), changed()[0].id()); + EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString()); reset(); // # of monitor can go to zero when screen is off. - const vector<const Monitor*> empty; + const vector<Monitor> empty; monitor_manager()->OnNativeMonitorsChanged(empty); EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); EXPECT_EQ("0 0 0", GetCountSummary()); EXPECT_FALSE(root_window_destroyed()); // Monitor configuration stays the same EXPECT_EQ("0,0 800x300", - monitor_manager()->GetMonitorAt(0)->bounds().ToString()); + monitor_manager()->GetMonitorAt(0).bounds().ToString()); reset(); // Connect to monitor again @@ -172,7 +171,7 @@ TEST_F(MultiMonitorManagerTest, NativeMonitorTest) { EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); EXPECT_EQ("1 0 0", GetCountSummary()); EXPECT_FALSE(root_window_destroyed()); - EXPECT_EQ("100,100 500x400", changed()[0]->bounds().ToString()); + EXPECT_EQ("100,100 500x400", changed()[0].bounds().ToString()); reset(); // Go back to zero and wake up with multiple monitors. @@ -185,9 +184,9 @@ TEST_F(MultiMonitorManagerTest, NativeMonitorTest) { UpdateMonitor("0+0-1000x600,1000+0-600x400"); EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); EXPECT_EQ("0,0 1000x600", - monitor_manager()->GetMonitorAt(0)->bounds().ToString()); + monitor_manager()->GetMonitorAt(0).bounds().ToString()); EXPECT_EQ("1000,0 600x400", - monitor_manager()->GetMonitorAt(1)->bounds().ToString()); + monitor_manager()->GetMonitorAt(1).bounds().ToString()); reset(); aura::MonitorManager::set_use_fullscreen_host_window(false); diff --git a/ash/screen_ash.cc b/ash/screen_ash.cc index ad679a1..98a9f3c 100644 --- a/ash/screen_ash.cc +++ b/ash/screen_ash.cc @@ -8,16 +8,13 @@ #include "ash/wm/shelf_layout_manager.h" #include "base/logging.h" #include "ui/aura/env.h" -#include "ui/aura/monitor.h" #include "ui/aura/monitor_manager.h" #include "ui/aura/root_window.h" +#include "ui/gfx/monitor.h" +#include "ui/gfx/screen.h" 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 { aura::MonitorManager* GetMonitorManager() { return aura::Env::GetInstance()->monitor_manager(); @@ -41,45 +38,41 @@ gfx::Rect ScreenAsh::GetUnmaximizedWorkAreaBounds(aura::Window* window) { return Shell::GetInstance()->shelf()->GetUnmaximizedWorkAreaBounds(window); } -gfx::Point ScreenAsh::GetCursorScreenPointImpl() { +gfx::Point ScreenAsh::GetCursorScreenPoint() { return root_window_->last_mouse_location(); } -gfx::Rect ScreenAsh::GetMonitorWorkAreaNearestWindowImpl( - gfx::NativeWindow window) { - return GetMonitorManager()->GetMonitorNearestWindow(window)-> - GetWorkAreaBounds(); -} - -gfx::Rect ScreenAsh::GetMonitorAreaNearestWindowImpl( - gfx::NativeWindow window) { - // See the comment at the top. - return gfx::Rect( - GetMonitorManager()->GetMonitorNearestWindow(window)->size()); +gfx::NativeWindow ScreenAsh::GetWindowAtCursorScreenPoint() { + const gfx::Point point = gfx::Screen::GetCursorScreenPoint(); + return root_window_->GetTopWindowContainingPoint(point); } -gfx::Rect ScreenAsh::GetMonitorWorkAreaNearestPointImpl( - const gfx::Point& point) { - return GetMonitorManager()->GetMonitorNearestPoint(point)-> - GetWorkAreaBounds(); +int ScreenAsh::GetNumMonitors() { + return GetMonitorManager()->GetNumMonitors(); } -gfx::Rect ScreenAsh::GetMonitorAreaNearestPointImpl(const gfx::Point& point) { - // See the comment at the top. - return gfx::Rect(GetMonitorManager()->GetMonitorNearestPoint(point)->size()); -} -gfx::NativeWindow ScreenAsh::GetWindowAtCursorScreenPointImpl() { - const gfx::Point point = GetCursorScreenPoint(); - return root_window_->GetTopWindowContainingPoint(point); +gfx::Monitor ScreenAsh::GetMonitorNearestWindow(gfx::NativeView window) const { + gfx::Monitor monitor = GetMonitorManager()->GetMonitorNearestWindow(window); + // TODO(oshima): For m19, work area/monitor bounds that chrome/webapps sees + // has (0, 0) origin because it's simpler and enough. Fix this when + // real multi monitor support is implemented. + monitor.SetBoundsAndUpdateWorkArea(gfx::Rect(monitor.size())); + return monitor; } -gfx::Size ScreenAsh::GetPrimaryMonitorSizeImpl() { - return GetMonitorManager()->GetMonitorAt(0)->size(); +gfx::Monitor ScreenAsh::GetMonitorNearestPoint(const gfx::Point& point) const { + gfx::Monitor monitor = GetMonitorManager()->GetMonitorNearestPoint(point); + // See comment above. + monitor.SetBoundsAndUpdateWorkArea(gfx::Rect(monitor.size())); + return monitor; } -int ScreenAsh::GetNumMonitorsImpl() { - return GetMonitorManager()->GetNumMonitors(); +gfx::Monitor ScreenAsh::GetPrimaryMonitor() const { + gfx::Monitor monitor = GetMonitorManager()->GetMonitorAt(0); + // See comment above. + monitor.SetBoundsAndUpdateWorkArea(gfx::Rect(monitor.size())); + return monitor; } } // namespace ash diff --git a/ash/screen_ash.h b/ash/screen_ash.h index ea2021f..1b2dbbc 100644 --- a/ash/screen_ash.h +++ b/ash/screen_ash.h @@ -9,7 +9,8 @@ #include "base/compiler_specific.h" #include "ash/ash_export.h" #include "ui/gfx/insets.h" -#include "ui/gfx/screen.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/screen_impl.h" namespace aura { class RootWindow; @@ -19,7 +20,7 @@ namespace ash { // Aura implementation of gfx::Screen. Implemented here to avoid circular // dependencies. -class ASH_EXPORT ScreenAsh : public gfx::Screen { +class ASH_EXPORT ScreenAsh : public gfx::ScreenImpl { public: explicit ScreenAsh(aura::RootWindow* root_window); virtual ~ScreenAsh(); @@ -32,18 +33,15 @@ class ASH_EXPORT ScreenAsh : public gfx::Screen { static gfx::Rect GetUnmaximizedWorkAreaBounds(aura::Window* window); protected: - virtual gfx::Point GetCursorScreenPointImpl() OVERRIDE; - virtual gfx::Rect GetMonitorWorkAreaNearestWindowImpl( - gfx::NativeView view) OVERRIDE; - virtual gfx::Rect GetMonitorAreaNearestWindowImpl( - gfx::NativeView view) OVERRIDE; - virtual gfx::Rect GetMonitorWorkAreaNearestPointImpl( - const gfx::Point& point) OVERRIDE; - virtual gfx::Rect GetMonitorAreaNearestPointImpl( - const gfx::Point& point) OVERRIDE; - virtual gfx::NativeWindow GetWindowAtCursorScreenPointImpl() OVERRIDE; - virtual gfx::Size GetPrimaryMonitorSizeImpl() OVERRIDE; - virtual int GetNumMonitorsImpl() OVERRIDE; + virtual gfx::Point GetCursorScreenPoint() OVERRIDE; + virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE; + + virtual int GetNumMonitors() OVERRIDE; + virtual gfx::Monitor GetMonitorNearestWindow( + gfx::NativeView view) const OVERRIDE; + virtual gfx::Monitor GetMonitorNearestPoint( + const gfx::Point& point) const OVERRIDE; + virtual gfx::Monitor GetPrimaryMonitor() const OVERRIDE; private: aura::RootWindow* root_window_; diff --git a/ash/shell.cc b/ash/shell.cc index 38c7cb9..5d80ad2 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -63,7 +63,6 @@ #include "ui/aura/client/aura_constants.h" #include "ui/aura/env.h" #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" @@ -71,6 +70,8 @@ #include "ui/aura/window.h" #include "ui/gfx/compositor/layer.h" #include "ui/gfx/compositor/layer_animator.h" +#include "ui/gfx/monitor.h" +#include "ui/gfx/screen.h" #include "ui/gfx/size.h" #include "ui/ui_controls/ui_controls.h" #include "ui/views/widget/native_widget_aura.h" @@ -789,11 +790,11 @@ void Shell::RotateFocus(Direction direction) { void Shell::SetMonitorWorkAreaInsets(Window* contains, const gfx::Insets& insets) { - aura::Monitor* monitor = aura::Env::GetInstance()->monitor_manager()-> - GetMonitorNearestWindow(contains); - if (monitor->work_area_insets() == insets) + internal::MultiMonitorManager* monitor_manager = + static_cast<internal::MultiMonitorManager*>( + aura::Env::GetInstance()->monitor_manager()); + if (!monitor_manager->UpdateWorkAreaOfMonitorNearestWindow(contains, insets)) return; - monitor->set_work_area_insets(insets); FOR_EACH_OBSERVER(ShellObserver, observers_, OnMonitorWorkAreaInsetsChanged()); } diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc index 09a47bf..1ee493b1 100644 --- a/ash/system/tray/system_tray.cc +++ b/ash/system/tray/system_tray.cc @@ -329,7 +329,7 @@ class SystemTrayBubble : public views::BubbleDelegateView { kPaddingFromBottomOfScreen); return rect; } - gfx::Rect rect = gfx::Screen::GetPrimaryMonitorBounds(); + gfx::Rect rect = gfx::Screen::GetPrimaryMonitor().bounds(); return gfx::Rect(base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreen : rect.width() - kPaddingFromRightEdgeOfScreen, rect.height() - kPaddingFromBottomOfScreen, diff --git a/ash/tooltips/tooltip_controller.cc b/ash/tooltips/tooltip_controller.cc index 341128d..c1aaa0f 100644 --- a/ash/tooltips/tooltip_controller.cc +++ b/ash/tooltips/tooltip_controller.cc @@ -65,7 +65,7 @@ int GetMaxWidth(int x, int y) { // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure // out a way to merge. gfx::Rect monitor_bounds = - gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y)); + gfx::Screen::GetMonitorNearestPoint(gfx::Point(x, y)).bounds(); return (monitor_bounds.width() + 1) / 2; } @@ -155,7 +155,7 @@ class TooltipController::Tooltip { tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY); gfx::Rect monitor_bounds = - gfx::Screen::GetMonitorAreaNearestPoint(tooltip_rect.origin()); + gfx::Screen::GetMonitorNearestPoint(tooltip_rect.origin()).bounds(); // If tooltip is out of bounds on the x axis, we simply shift it // horizontally by the offset. diff --git a/ash/wm/base_layout_manager.cc b/ash/wm/base_layout_manager.cc index 4b9a906..6437a07 100644 --- a/ash/wm/base_layout_manager.cc +++ b/ash/wm/base_layout_manager.cc @@ -111,7 +111,7 @@ void BaseLayoutManager::SetChildBounds(aura::Window* child, if (wm::IsWindowMaximized(child)) child_bounds = ScreenAsh::GetMaximizedWindowBounds(child); else if (wm::IsWindowFullscreen(child)) - child_bounds = gfx::Screen::GetMonitorAreaNearestWindow(child); + child_bounds = gfx::Screen::GetMonitorNearestWindow(child).bounds(); SetChildBoundsDirect(child, child_bounds); } @@ -194,8 +194,8 @@ void BaseLayoutManager::UpdateBoundsFromShowState(aura::Window* window) { case ui::SHOW_STATE_FULLSCREEN: SetRestoreBoundsIfNotSet(window); - SetChildBoundsDirect(window, - gfx::Screen::GetMonitorAreaNearestWindow(window)); + SetChildBoundsDirect( + window, gfx::Screen::GetMonitorNearestWindow(window).bounds()); break; default: @@ -216,12 +216,12 @@ void BaseLayoutManager::AdjustWindowSizesForScreenChange() { if (wm::IsWindowMaximized(window)) { SetChildBoundsDirect(window, ScreenAsh::GetMaximizedWindowBounds(window)); } else if (wm::IsWindowFullscreen(window)) { - SetChildBoundsDirect(window, - gfx::Screen::GetMonitorAreaNearestWindow(window)); + SetChildBoundsDirect( + window, gfx::Screen::GetMonitorNearestWindow(window).bounds()); } else { // The work area may be smaller than the full screen. gfx::Rect monitor_rect = - gfx::Screen::GetMonitorWorkAreaNearestWindow(window); + gfx::Screen::GetMonitorNearestWindow(window).work_area(); // Put as much of the window as possible within the monitor area. window->SetBounds(window->bounds().AdjustToFit(monitor_rect)); } diff --git a/ash/wm/base_layout_manager_unittest.cc b/ash/wm/base_layout_manager_unittest.cc index 68c3695..831939a 100644 --- a/ash/wm/base_layout_manager_unittest.cc +++ b/ash/wm/base_layout_manager_unittest.cc @@ -16,6 +16,7 @@ #include "ui/aura/window.h" #include "ui/base/ui_base_types.h" #include "ui/gfx/insets.h" +#include "ui/gfx/screen.h" namespace ash { @@ -92,8 +93,9 @@ TEST_F(BaseLayoutManagerTest, Fullscreen) { scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); // Fullscreen window fills the whole monitor. - EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()).ToString(), - window->bounds().ToString()); + EXPECT_EQ( + gfx::Screen::GetMonitorNearestWindow(window.get()).bounds().ToString(), + window->bounds().ToString()); window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); } @@ -104,12 +106,14 @@ TEST_F(BaseLayoutManagerTest, FullscreenRootWindowResize) { scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); // Fullscreen window fills the whole monitor. window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); - EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()).ToString(), - window->bounds().ToString()); + EXPECT_EQ( + gfx::Screen::GetMonitorNearestWindow(window.get()).bounds().ToString(), + window->bounds().ToString()); // Enlarge the root window. We should still match the monitor size. Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600)); - EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()).ToString(), - window->bounds().ToString()); + EXPECT_EQ( + gfx::Screen::GetMonitorNearestWindow(window.get()).bounds().ToString(), + window->bounds().ToString()); } // Fails on Mac only. Need to be implemented. http://crbug.com/111279. @@ -124,20 +128,21 @@ TEST_F(BaseLayoutManagerTest, FullscreenRootWindowResize) { TEST_F(BaseLayoutManagerTest, MAYBE_RootWindowResizeShrinksWindows) { scoped_ptr<aura::Window> window( CreateTestWindow(gfx::Rect(10, 20, 500, 400))); - gfx::Rect work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get()); + gfx::Rect work_area = + gfx::Screen::GetMonitorNearestWindow(window.get()).work_area(); // Invariant: Window is smaller than work area. EXPECT_LE(window->bounds().width(), work_area.width()); EXPECT_LE(window->bounds().height(), work_area.height()); // Make the root window narrower than our window. Shell::GetRootWindow()->SetHostSize(gfx::Size(300, 400)); - work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get()); + work_area = gfx::Screen::GetMonitorNearestWindow(window.get()).work_area(); EXPECT_LE(window->bounds().width(), work_area.width()); EXPECT_LE(window->bounds().height(), work_area.height()); // Make the root window shorter than our window. Shell::GetRootWindow()->SetHostSize(gfx::Size(300, 200)); - work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get()); + work_area = gfx::Screen::GetMonitorNearestWindow(window.get()).work_area(); EXPECT_LE(window->bounds().width(), work_area.width()); EXPECT_LE(window->bounds().height(), work_area.height()); @@ -152,7 +157,7 @@ TEST_F(BaseLayoutManagerTest, MAYBE_RootWindowResizeShrinksWindows) { // to smaller than the full work area. TEST_F(BaseLayoutManagerTest, BoundsWithScreenEdgeVisible) { // Create a window with bounds that fill the screen. - gfx::Rect bounds = gfx::Screen::GetPrimaryMonitorBounds(); + gfx::Rect bounds = gfx::Screen::GetPrimaryMonitor().bounds(); scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); // Maximize it, which writes the old bounds to restore bounds. window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); diff --git a/ash/wm/root_window_event_filter_unittest.cc b/ash/wm/root_window_event_filter_unittest.cc index 136554c..812726a 100644 --- a/ash/wm/root_window_event_filter_unittest.cc +++ b/ash/wm/root_window_event_filter_unittest.cc @@ -440,8 +440,9 @@ TEST_F(RootWindowEventFilterTest, MAYBE_TransformActivate) { aura::RootWindow* root_window = Shell::GetRootWindow(); gfx::Size size = root_window->bounds().size(); - EXPECT_EQ(gfx::Rect(size), - gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point())); + EXPECT_EQ( + gfx::Rect(size).ToString(), + gfx::Screen::GetMonitorNearestPoint(gfx::Point()).bounds().ToString()); // Rotate it clock-wise 90 degrees. ui::Transform transform; diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc index dc6eee5..a118893 100644 --- a/ash/wm/shelf_layout_manager.cc +++ b/ash/wm/shelf_layout_manager.cc @@ -21,6 +21,7 @@ #include "ui/gfx/compositor/layer_animation_observer.h" #include "ui/gfx/compositor/layer_animator.h" #include "ui/gfx/compositor/scoped_layer_animation_settings.h" +#include "ui/gfx/screen.h" #include "ui/views/widget/widget.h" namespace ash { @@ -149,7 +150,7 @@ bool ShelfLayoutManager::IsVisible() const { gfx::Rect ShelfLayoutManager::GetMaximizedWindowBounds( aura::Window* window) const { // TODO: needs to be multi-mon aware. - gfx::Rect bounds(gfx::Screen::GetMonitorAreaNearestWindow(window)); + gfx::Rect bounds(gfx::Screen::GetMonitorNearestWindow(window).bounds()); if (auto_hide_behavior_ == SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT || auto_hide_behavior_ == SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS) { bounds.set_height(bounds.height() - kAutoHideHeight); @@ -162,7 +163,7 @@ gfx::Rect ShelfLayoutManager::GetMaximizedWindowBounds( gfx::Rect ShelfLayoutManager::GetUnmaximizedWorkAreaBounds( aura::Window* window) const { // TODO: needs to be multi-mon aware. - gfx::Rect bounds(gfx::Screen::GetMonitorAreaNearestWindow(window)); + gfx::Rect bounds(gfx::Screen::GetMonitorNearestWindow(window).bounds()); if (auto_hide_behavior_ == SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS) bounds.set_height(bounds.height() - kAutoHideHeight); else diff --git a/ash/wm/shelf_layout_manager_unittest.cc b/ash/wm/shelf_layout_manager_unittest.cc index 559316e..ea16d00 100644 --- a/ash/wm/shelf_layout_manager_unittest.cc +++ b/ash/wm/shelf_layout_manager_unittest.cc @@ -13,7 +13,6 @@ #include "ash/test/ash_test_base.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/env.h" -#include "ui/aura/monitor.h" #include "ui/aura/monitor_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/test/event_generator.h" @@ -21,6 +20,7 @@ #include "ui/base/animation/animation_container_element.h" #include "ui/gfx/compositor/layer_animator.h" #include "ui/gfx/compositor/layer.h" +#include "ui/gfx/monitor.h" #include "ui/gfx/screen.h" #include "ui/views/widget/widget.h" @@ -86,12 +86,12 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); const aura::MonitorManager* manager = aura::Env::GetInstance()->monitor_manager(); - const aura::Monitor* monitor = + const gfx::Monitor& monitor = manager->GetMonitorNearestWindow(Shell::GetRootWindow()); - ASSERT_TRUE(monitor); + ASSERT_NE(-1, monitor.id()); // Bottom inset should be the max of widget heights. EXPECT_EQ(shelf->shelf_height(), - monitor->work_area_insets().bottom()); + monitor.bounds().bottom() - monitor.work_area().bottom()); // Hide the shelf. SetState(shelf, ShelfLayoutManager::HIDDEN); @@ -99,13 +99,14 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); StepWidgetLayerAnimatorToEnd(shelf->status()); EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); - EXPECT_EQ(0, monitor->work_area_insets().bottom()); + EXPECT_EQ(0, + monitor.bounds().bottom() - monitor.work_area().bottom()); // Make sure the bounds of the two widgets changed. EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), - gfx::Screen::GetPrimaryMonitorBounds().bottom()); + gfx::Screen::GetPrimaryMonitor().bounds().bottom()); EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), - gfx::Screen::GetPrimaryMonitorBounds().bottom()); + gfx::Screen::GetPrimaryMonitor().bounds().bottom()); // And show it again. SetState(shelf, ShelfLayoutManager::VISIBLE); @@ -114,12 +115,12 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { StepWidgetLayerAnimatorToEnd(shelf->status()); EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); EXPECT_EQ(shelf->shelf_height(), - monitor->work_area_insets().bottom()); + monitor.bounds().bottom() - monitor.work_area().bottom()); // Make sure the bounds of the two widgets changed. gfx::Rect launcher_bounds( shelf->launcher_widget()->GetNativeView()->bounds()); - int bottom = gfx::Screen::GetPrimaryMonitorBounds().bottom() - + int bottom = gfx::Screen::GetPrimaryMonitor().bounds().bottom() - shelf->shelf_height(); EXPECT_EQ(launcher_bounds.y(), bottom + (shelf->shelf_height() - launcher_bounds.height()) / 2); @@ -137,19 +138,20 @@ TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { const aura::MonitorManager* manager = aura::Env::GetInstance()->monitor_manager(); - const aura::Monitor* monitor = + const gfx::Monitor& monitor = manager->GetMonitorNearestWindow(Shell::GetRootWindow()); // Hide the shelf. SetState(shelf, ShelfLayoutManager::HIDDEN); shelf->LayoutShelf(); EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); - EXPECT_EQ(0, monitor->work_area_insets().bottom()); + EXPECT_EQ(0, monitor.bounds().bottom() - monitor.work_area().bottom()); + // Make sure the bounds of the two widgets changed. EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), - gfx::Screen::GetPrimaryMonitorBounds().bottom()); + gfx::Screen::GetPrimaryMonitor().bounds().bottom()); EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), - gfx::Screen::GetPrimaryMonitorBounds().bottom()); + gfx::Screen::GetPrimaryMonitor().bounds().bottom()); } // Makes sure the launcher is initially sized correctly. @@ -211,7 +213,7 @@ TEST_F(ShelfLayoutManagerTest, AutoHide) { EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideHeight, shelf->launcher_widget()->GetWindowScreenBounds().y()); EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideHeight, - gfx::Screen::GetMonitorWorkAreaNearestWindow(root).bottom()); + gfx::Screen::GetMonitorNearestWindow(root).work_area().bottom()); // Move the mouse to the bottom of the screen. generator.MoveMouseTo(0, root->bounds().bottom() - 1); @@ -223,7 +225,7 @@ TEST_F(ShelfLayoutManagerTest, AutoHide) { EXPECT_EQ(root->bounds().bottom() - shelf->shelf_height(), shelf->launcher_widget()->GetWindowScreenBounds().y()); EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideHeight, - gfx::Screen::GetMonitorWorkAreaNearestWindow(root).bottom()); + gfx::Screen::GetMonitorNearestWindow(root).work_area().bottom()); // Move mouse back up. generator.MoveMouseTo(0, 0); @@ -315,7 +317,8 @@ TEST_F(ShelfLayoutManagerTest, SetAutoHideBehavior) { widget->Init(params); widget->Show(); aura::Window* window = widget->GetNativeWindow(); - gfx::Rect monitor_bounds(gfx::Screen::GetMonitorAreaNearestWindow(window)); + gfx::Rect monitor_bounds( + gfx::Screen::GetMonitorNearestWindow(window).bounds()); EXPECT_EQ(monitor_bounds.bottom() - ShelfLayoutManager::kAutoHideHeight, shelf->GetMaximizedWindowBounds(window).bottom()); EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); @@ -337,17 +340,17 @@ TEST_F(ShelfLayoutManagerTest, SetAutoHideBehavior) { widget->Maximize(); EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); - EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window).bottom(), + EXPECT_EQ(gfx::Screen::GetMonitorNearestWindow(window).work_area().bottom(), widget->GetWorkAreaBoundsInScreen().bottom()); shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state()); - EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window).bottom(), + EXPECT_EQ(gfx::Screen::GetMonitorNearestWindow(window).work_area().bottom(), widget->GetWorkAreaBoundsInScreen().bottom()); shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); - EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window).bottom(), + EXPECT_EQ(gfx::Screen::GetMonitorNearestWindow(window).work_area().bottom(), widget->GetWorkAreaBoundsInScreen().bottom()); } diff --git a/ash/wm/toplevel_window_event_filter_unittest.cc b/ash/wm/toplevel_window_event_filter_unittest.cc index 70b20cb..1a52a22 100644 --- a/ash/wm/toplevel_window_event_filter_unittest.cc +++ b/ash/wm/toplevel_window_event_filter_unittest.cc @@ -349,7 +349,7 @@ TEST_F(ToplevelWindowEventFilterTest, DoubleClickCaptionTogglesMaximize) { TEST_F(ToplevelWindowEventFilterTest, BottomRightWorkArea) { scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); gfx::Rect work_area = - gfx::Screen::GetMonitorWorkAreaNearestWindow(target.get()); + gfx::Screen::GetMonitorNearestWindow(target.get()).work_area(); gfx::Point position = target->bounds().origin(); // Drag further than work_area bottom. DragFromCenterBy(target.get(), 100, work_area.height()); @@ -363,7 +363,7 @@ TEST_F(ToplevelWindowEventFilterTest, BottomRightWorkArea) { TEST_F(ToplevelWindowEventFilterTest, BottomLeftWorkArea) { scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMLEFT)); gfx::Rect work_area = - gfx::Screen::GetMonitorWorkAreaNearestWindow(target.get()); + gfx::Screen::GetMonitorNearestWindow(target.get()).work_area(); gfx::Point position = target->bounds().origin(); // Drag further than work_area bottom. DragFromCenterBy(target.get(), -30, work_area.height()); @@ -378,7 +378,7 @@ TEST_F(ToplevelWindowEventFilterTest, BottomLeftWorkArea) { TEST_F(ToplevelWindowEventFilterTest, BottomWorkArea) { scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOM)); gfx::Rect work_area = - gfx::Screen::GetMonitorWorkAreaNearestWindow(target.get()); + gfx::Screen::GetMonitorNearestWindow(target.get()).work_area(); gfx::Point position = target->bounds().origin(); // Drag further than work_area bottom. DragFromCenterBy(target.get(), 0, work_area.height()); @@ -403,7 +403,8 @@ TEST_F(ToplevelWindowEventFilterTest, DontDragToNegativeY) { // Verifies we don't let windows go bigger than the monitor width. TEST_F(ToplevelWindowEventFilterTest, DontGotWiderThanScreen) { scoped_ptr<aura::Window> target(CreateWindow(HTRIGHT)); - gfx::Rect work_area = gfx::Screen::GetMonitorAreaNearestWindow(target.get()); + gfx::Rect work_area = + gfx::Screen::GetMonitorNearestWindow(target.get()).bounds(); DragFromCenterBy(target.get(), work_area.width() * 2, 0); // The y location and height should not have changed. EXPECT_EQ(work_area.width(), target->bounds().width()); diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc index de763f6..168b53d 100644 --- a/ash/wm/window_animations.cc +++ b/ash/wm/window_animations.cc @@ -346,7 +346,8 @@ gfx::Rect GetMinimizeRectForWindow(aura::Window* window) { if (target_bounds.IsEmpty()) { // Assume the launcher is overflowed, zoom off to the bottom right of the // work area. - gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow(window); + gfx::Rect work_area = + gfx::Screen::GetMonitorNearestWindow(window).work_area(); target_bounds.SetRect(work_area.right(), work_area.bottom(), 0, 0); } return target_bounds; diff --git a/ash/wm/window_resizer.cc b/ash/wm/window_resizer.cc index e48ee52..94d1891 100644 --- a/ash/wm/window_resizer.cc +++ b/ash/wm/window_resizer.cc @@ -203,8 +203,8 @@ gfx::Rect WindowResizer::CalculateBoundsForDrag( if (details.window_component == HTBOTTOM || details.window_component == HTBOTTOMRIGHT || details.window_component == HTBOTTOMLEFT) { - gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow( - details.window); + gfx::Rect work_area = gfx::Screen::GetMonitorNearestWindow( + details.window).work_area(); if (new_bounds.bottom() > work_area.bottom()) new_bounds.Inset(0, 0, 0, new_bounds.bottom() - work_area.bottom()); @@ -295,7 +295,7 @@ int WindowResizer::GetWidthForDrag(const Details& details, // And don't let the window go bigger than the monitor. int max_width = - gfx::Screen::GetMonitorAreaNearestWindow(details.window).width(); + gfx::Screen::GetMonitorNearestWindow(details.window).bounds().width(); if (width > max_width) { width = max_width; *delta_x = -x_multiplier * (details.initial_bounds.width() - max_width); @@ -329,7 +329,7 @@ int WindowResizer::GetHeightForDrag(const Details& details, // And don't let the window go bigger than the monitor. int max_height = - gfx::Screen::GetMonitorAreaNearestWindow(details.window).height(); + gfx::Screen::GetMonitorNearestWindow(details.window).bounds().height(); if (height > max_height) { height = max_height; *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); diff --git a/ash/wm/workspace/maximized_workspace.cc b/ash/wm/workspace/maximized_workspace.cc index d712448..329c48c 100644 --- a/ash/wm/workspace/maximized_workspace.cc +++ b/ash/wm/workspace/maximized_workspace.cc @@ -41,7 +41,7 @@ void MaximizedWorkspace::OnWindowRemoved(aura::Window* window) { void MaximizedWorkspace::ResetWindowBounds(aura::Window* window) { if (wm::IsWindowFullscreen(window)) { SetWindowBounds(window, - gfx::Screen::GetMonitorAreaNearestWindow(window)); + gfx::Screen::GetMonitorNearestWindow(window).bounds()); } else { SetWindowBounds(window, ScreenAsh::GetMaximizedWindowBounds(window)); } diff --git a/ash/wm/workspace/snap_sizer.cc b/ash/wm/workspace/snap_sizer.cc index 9b064e7..158fa3a 100644 --- a/ash/wm/workspace/snap_sizer.cc +++ b/ash/wm/workspace/snap_sizer.cc @@ -114,7 +114,7 @@ gfx::Rect SnapSizer::GetTargetBounds() const { bool SnapSizer::AlongEdge(int x) const { // TODO: need to support multi-monitor. - gfx::Rect area(gfx::Screen::GetMonitorAreaNearestWindow(window_)); + gfx::Rect area(gfx::Screen::GetMonitorNearestWindow(window_).bounds()); return (x <= area.x()) || (x >= area.right() - 1); } diff --git a/ash/wm/workspace/workspace_event_filter.cc b/ash/wm/workspace/workspace_event_filter.cc index 2012a66..0768834 100644 --- a/ash/wm/workspace/workspace_event_filter.cc +++ b/ash/wm/workspace/workspace_event_filter.cc @@ -4,7 +4,6 @@ #include "ash/wm/workspace/workspace_event_filter.h" -#include "ash/screen_ash.h" #include "ash/wm/property_util.h" #include "ash/wm/window_frame.h" #include "ash/wm/window_util.h" @@ -16,6 +15,7 @@ #include "ui/aura/window_delegate.h" #include "ui/base/hit_test.h" #include "ui/gfx/compositor/scoped_layer_animation_settings.h" +#include "ui/gfx/screen.h" namespace { @@ -128,7 +128,7 @@ void WorkspaceEventFilter::HandleVerticalResizeDoubleClick( int component = target->delegate()->GetNonClientComponent(event->location()); gfx::Rect work_area = - gfx::Screen::GetMonitorWorkAreaNearestWindow(target); + gfx::Screen::GetMonitorNearestWindow(target).work_area(); const gfx::Rect* restore_bounds = target->GetProperty(aura::client::kRestoreBoundsKey); if (component == HTBOTTOM || component == HTTOP) { diff --git a/ash/wm/workspace/workspace_event_filter_unittest.cc b/ash/wm/workspace/workspace_event_filter_unittest.cc index a02984c..14705a8d 100644 --- a/ash/wm/workspace/workspace_event_filter_unittest.cc +++ b/ash/wm/workspace/workspace_event_filter_unittest.cc @@ -52,7 +52,7 @@ TEST_F(WorkspaceEventFilterTest, DoubleClickSingleAxisResizeEdge) { scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds)); gfx::Rect work_area = - gfx::Screen::GetMonitorWorkAreaNearestWindow(window.get()); + gfx::Screen::GetMonitorNearestWindow(window.get()).work_area(); aura::test::EventGenerator generator(Shell::GetRootWindow(), window.get()); diff --git a/ash/wm/workspace/workspace_manager.cc b/ash/wm/workspace/workspace_manager.cc index 07a3008..bd70c98 100644 --- a/ash/wm/workspace/workspace_manager.cc +++ b/ash/wm/workspace/workspace_manager.cc @@ -20,8 +20,6 @@ #include "ui/aura/env.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/root_window.h" -#include "ui/aura/monitor.h" -#include "ui/aura/monitor_manager.h" #include "ui/aura/window.h" #include "ui/base/ui_base_types.h" #include "ui/gfx/compositor/layer.h" @@ -139,7 +137,8 @@ WorkspaceManager::WindowState WorkspaceManager::GetWindowState() { return WINDOW_STATE_DEFAULT; // TODO: this code needs to be made multi-monitor aware. - gfx::Rect bounds(gfx::Screen::GetMonitorAreaNearestWindow(contents_view_)); + gfx::Rect bounds( + gfx::Screen::GetMonitorNearestWindow(contents_view_).bounds()); bounds.set_height(bounds.height() - shelf_->shelf_height()); const aura::Window::Windows& windows(contents_view_->children()); bool window_overlaps_launcher = false; diff --git a/ash/wm/workspace/workspace_manager_unittest.cc b/ash/wm/workspace/workspace_manager_unittest.cc index 0fa1e59..008906a 100644 --- a/ash/wm/workspace/workspace_manager_unittest.cc +++ b/ash/wm/workspace/workspace_manager_unittest.cc @@ -59,7 +59,7 @@ class WorkspaceManagerTest : public test::AshTestBase { } gfx::Rect GetFullscreenBounds(aura::Window* window) { - return gfx::Screen::GetMonitorAreaNearestWindow(window); + return gfx::Screen::GetMonitorNearestWindow(window).bounds(); } Workspace* active_workspace() { diff --git a/ash/wm/workspace/workspace_window_resizer.cc b/ash/wm/workspace/workspace_window_resizer.cc index 89f24ab..df054be 100644 --- a/ash/wm/workspace/workspace_window_resizer.cc +++ b/ash/wm/workspace/workspace_window_resizer.cc @@ -212,7 +212,8 @@ gfx::Rect WorkspaceWindowResizer::GetFinalBounds( void WorkspaceWindowResizer::LayoutAttachedWindows( const gfx::Rect& bounds, int grid_size) { - gfx::Rect work_area(gfx::Screen::GetMonitorWorkAreaNearestWindow(window())); + gfx::Rect work_area( + gfx::Screen::GetMonitorNearestWindow(window()).work_area()); std::vector<int> sizes; CalculateAttachedSizes( PrimaryAxisSize(details_.initial_bounds.size()), @@ -281,7 +282,8 @@ void WorkspaceWindowResizer::CalculateAttachedSizes( void WorkspaceWindowResizer::AdjustBoundsForMainWindow( gfx::Rect* bounds, int grid_size) const { // Always keep kMinOnscreenHeight on the bottom. - gfx::Rect work_area(gfx::Screen::GetMonitorWorkAreaNearestWindow(window())); + gfx::Rect work_area( + gfx::Screen::GetMonitorNearestWindow(window()).work_area()); int max_y = AlignToGridRoundUp(work_area.bottom() - kMinOnscreenHeight, grid_size); if (bounds->y() > max_y) @@ -335,7 +337,7 @@ void WorkspaceWindowResizer::SnapToWorkAreaEdges( bool WorkspaceWindowResizer::TouchesBottomOfScreen() const { gfx::Rect work_area( - gfx::Screen::GetMonitorWorkAreaNearestWindow(details_.window)); + gfx::Screen::GetMonitorNearestWindow(details_.window).work_area()); return (attached_windows_.empty() && details_.window->bounds().bottom() == work_area.bottom()) || (!attached_windows_.empty() && @@ -422,7 +424,8 @@ WorkspaceWindowResizer::SnapType WorkspaceWindowResizer::GetSnapType( const gfx::Point& location) const { // TODO: this likely only wants total monitor area, not the area of a single // monitor. - gfx::Rect area(gfx::Screen::GetMonitorAreaNearestWindow(details_.window)); + gfx::Rect area( + gfx::Screen::GetMonitorNearestWindow(details_.window).bounds()); if (location.x() <= area.x()) return SNAP_LEFT_EDGE; if (location.x() >= area.right() - 1) diff --git a/chrome/browser/chromeos/input_method/candidate_window.cc b/chrome/browser/chromeos/input_method/candidate_window.cc index bfff28e..b6ae0cb 100644 --- a/chrome/browser/chromeos/input_method/candidate_window.cc +++ b/chrome/browser/chromeos/input_method/candidate_window.cc @@ -1205,8 +1205,8 @@ void CandidateWindowView::ResizeAndMoveParentFrame() { const int horizontal_offset = GetHorizontalOffset(); gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds(); - gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow( - parent_frame_->GetNativeView()); + gfx::Rect screen_bounds = gfx::Screen::GetMonitorNearestWindow( + parent_frame_->GetNativeView()).work_area(); // The size. gfx::Rect frame_bounds = old_bounds; frame_bounds.set_size(GetPreferredSize()); @@ -1478,8 +1478,8 @@ void InfolistWindowView::UpdateCandidates( void InfolistWindowView::ResizeAndMoveParentFrame() { int x, y; gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds(); - gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow( - parent_frame_->GetNativeView()); + gfx::Rect screen_bounds = gfx::Screen::GetMonitorNearestWindow( + parent_frame_->GetNativeView()).work_area(); // The size. gfx::Rect frame_bounds = old_bounds; frame_bounds.set_size(GetPreferredSize()); diff --git a/chrome/browser/chromeos/login/helper.cc b/chrome/browser/chromeos/login/helper.cc index b435243..439ccbb 100644 --- a/chrome/browser/chromeos/login/helper.cc +++ b/chrome/browser/chromeos/login/helper.cc @@ -54,7 +54,7 @@ views::Throbber* CreateDefaultThrobber() { } gfx::Rect CalculateScreenBounds(const gfx::Size& size) { - gfx::Rect bounds(gfx::Screen::GetMonitorAreaNearestWindow(NULL)); + gfx::Rect bounds(gfx::Screen::GetPrimaryMonitor().bounds()); if (!size.IsEmpty()) { int horizontal_diff = bounds.width() - size.width(); int vertical_diff = bounds.height() - size.height(); diff --git a/chrome/browser/chromeos/login/webui_screen_locker.cc b/chrome/browser/chromeos/login/webui_screen_locker.cc index 08f6b3d..7774ea5 100644 --- a/chrome/browser/chromeos/login/webui_screen_locker.cc +++ b/chrome/browser/chromeos/login/webui_screen_locker.cc @@ -44,7 +44,7 @@ WebUIScreenLocker::WebUIScreenLocker(ScreenLocker* screen_locker) } void WebUIScreenLocker::LockScreen(bool unlock_on_input) { - gfx::Rect bounds(gfx::Screen::GetMonitorAreaNearestWindow(NULL)); + gfx::Rect bounds(gfx::Screen::GetPrimaryMonitor().bounds()); LockWindow* lock_window = LockWindow::Create(); lock_window->set_observer(this); diff --git a/chrome/browser/chromeos/media/media_player.cc b/chrome/browser/chromeos/media/media_player.cc index 98ad62b..49447d0 100644 --- a/chrome/browser/chromeos/media/media_player.cc +++ b/chrome/browser/chromeos/media/media_player.cc @@ -124,7 +124,7 @@ void MediaPlayer::PopupMediaPlayer() { return; } - const gfx::Size screen = gfx::Screen::GetPrimaryMonitorSize(); + const gfx::Size screen = gfx::Screen::GetPrimaryMonitor().size(); const gfx::Rect bounds(screen.width() - kPopupRight - kPopupWidth, screen.height() - kPopupBottom - kPopupHeight, kPopupWidth, diff --git a/chrome/browser/chromeos/ui/setting_level_bubble.cc b/chrome/browser/chromeos/ui/setting_level_bubble.cc index 8635bcc..a673f47 100644 --- a/chrome/browser/chromeos/ui/setting_level_bubble.cc +++ b/chrome/browser/chromeos/ui/setting_level_bubble.cc @@ -82,7 +82,7 @@ gfx::Rect SettingLevelBubbleDelegateView::GetAnchorRect() { // Calculate the position in screen coordinates that the bubble should // "point" at (since we use BubbleBorder::FLOAT, this position actually // specifies the center of the bubble). - gfx::Rect monitor_area = gfx::Screen::GetMonitorAreaNearestWindow(NULL); + gfx::Rect monitor_area = gfx::Screen::GetPrimaryMonitor().bounds(); return (gfx::Rect( monitor_area.x() + kBubbleXRatio * monitor_area.width(), monitor_area.bottom() - view_size.height() / 2 - kBubbleBottomGap, 0, 0)); diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc index 58cdfa1..775787c 100644 --- a/chrome/browser/metrics/metrics_log.cc +++ b/chrome/browser/metrics/metrics_log.cc @@ -264,7 +264,7 @@ PrefService* MetricsLog::GetPrefService() { } gfx::Size MetricsLog::GetScreenSize() const { - return gfx::Screen::GetPrimaryMonitorSize(); + return gfx::Screen::GetPrimaryMonitor().size(); } int MetricsLog::GetScreenCount() const { diff --git a/chrome/browser/notifications/balloon_collection_impl.cc b/chrome/browser/notifications/balloon_collection_impl.cc index 01780c0..565aba4 100644 --- a/chrome/browser/notifications/balloon_collection_impl.cc +++ b/chrome/browser/notifications/balloon_collection_impl.cc @@ -486,7 +486,7 @@ bool BalloonCollectionImpl::Layout::RefreshSystemMetrics() { #if defined(OS_MACOSX) gfx::Rect new_work_area = GetMacWorkArea(); #else - gfx::Rect new_work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); + gfx::Rect new_work_area = gfx::Screen::GetPrimaryMonitor().work_area(); #endif if (!work_area_.Equals(new_work_area)) { work_area_.SetRect(new_work_area.x(), new_work_area.y(), diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index 6782e27..c30674c 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -2095,7 +2095,7 @@ void BrowserWindowGtk::SaveWindowPosition() { window_preferences->SetBoolean("maximized", IsMaximized()); gfx::Rect work_area( - gfx::Screen::GetMonitorWorkAreaMatching(restored_bounds_)); + gfx::Screen::GetMonitorMatching(restored_bounds_).work_area()); window_preferences->SetInteger("work_area_left", work_area.x()); window_preferences->SetInteger("work_area_top", work_area.y()); window_preferences->SetInteger("work_area_right", work_area.right()); diff --git a/chrome/browser/ui/panels/display_settings_provider.cc b/chrome/browser/ui/panels/display_settings_provider.cc index b2fed3f..61f7709 100644 --- a/chrome/browser/ui/panels/display_settings_provider.cc +++ b/chrome/browser/ui/panels/display_settings_provider.cc @@ -72,9 +72,9 @@ gfx::Rect DisplaySettingsProvider::GetWorkArea() const { #if defined(OS_MACOSX) // On OSX, panels should be dropped all the way to the bottom edge of the // screen (and overlap Dock). - gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorBounds(); + gfx::Rect work_area = gfx::Screen::GetPrimaryMonitor().bounds(); #else - gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); + gfx::Rect work_area = gfx::Screen::GetPrimaryMonitor().work_area(); #endif return work_area; } diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc index 9306b53..137eb15 100644 --- a/chrome/browser/ui/panels/panel_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browsertest.cc @@ -1634,7 +1634,7 @@ class PanelAndNotificationTest : public PanelBrowserTest { // The position returned by the notification balloon is based on Mac's // vertically inverted orientation. We need to flip it so that it can // be compared against the position returned by the panel. - gfx::Size screen_size = gfx::Screen::GetPrimaryMonitorSize(); + gfx::Size screen_size = gfx::Screen::GetPrimaryMonitor().size(); return screen_size.height() - balloon->GetPosition().y(); #else return balloon->GetPosition().y() + balloon->GetViewSize().height(); diff --git a/chrome/browser/ui/pdf/pdf_browsertest.cc b/chrome/browser/ui/pdf/pdf_browsertest.cc index 1a1cbcf..bbeed83 100644 --- a/chrome/browser/ui/pdf/pdf_browsertest.cc +++ b/chrome/browser/ui/pdf/pdf_browsertest.cc @@ -69,7 +69,7 @@ class PDFBrowserTest : public InProcessBrowserTest, // to a smaller window and then expanding leads to slight anti-aliasing // differences of the text and the pixel comparison fails. gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight)); - gfx::Rect screen_bounds = gfx::Screen::GetPrimaryMonitorBounds(); + gfx::Rect screen_bounds = gfx::Screen::GetPrimaryMonitor().bounds(); ASSERT_GT(screen_bounds.width(), kBrowserWidth); ASSERT_GT(screen_bounds.height(), kBrowserHeight); browser()->window()->SetBounds(bounds); diff --git a/chrome/browser/ui/tabs/dock_info_win.cc b/chrome/browser/ui/tabs/dock_info_win.cc index d243842..5afa6f6 100644 --- a/chrome/browser/ui/tabs/dock_info_win.cc +++ b/chrome/browser/ui/tabs/dock_info_win.cc @@ -242,8 +242,8 @@ class DockToWindowFinder : public BaseWindowFinder { const std::set<HWND>& ignore) : BaseWindowFinder(ignore), screen_loc_(screen_loc) { - gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestPoint( - screen_loc); + gfx::Rect work_area = gfx::Screen::GetMonitorNearestPoint( + screen_loc).bounds(); if (!work_area.IsEmpty()) { result_.set_monitor_bounds(work_area); EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, as_lparam()); 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 9b01b46..981db9b 100644 --- a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc +++ b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc @@ -31,6 +31,7 @@ #include "ui/aura/single_monitor_manager.h" #include "ui/aura/test/test_screen.h" #include "ui/aura/test/test_stacking_client.h" +#include "ui/gfx/screen.h" #endif #if defined(TOOLKIT_VIEWS) @@ -138,7 +139,7 @@ class AccessibilityEventRouterViewsTest aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); root_window_.reset( aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); -#if defined(USE_ASH) +#if defined(USE_AURA) gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); #endif // USE_ASH test_stacking_client_.reset( diff --git a/chrome/browser/ui/views/ash/window_positioner.cc b/chrome/browser/ui/views/ash/window_positioner.cc index 2780060..46d4c2b 100644 --- a/chrome/browser/ui/views/ash/window_positioner.cc +++ b/chrome/browser/ui/views/ash/window_positioner.cc @@ -48,8 +48,8 @@ gfx::Rect WindowPositioner::GetPopupPosition(const gfx::Rect& old_pos) { // work area. aura::Window* window = ash::wm::GetActiveWindow(); const gfx::Rect work_area = window && window->IsVisible() ? - gfx::Screen::GetMonitorWorkAreaNearestWindow(window) : - gfx::Screen::GetPrimaryMonitorWorkArea(); + gfx::Screen::GetMonitorNearestWindow(window).work_area() : + gfx::Screen::GetPrimaryMonitor().work_area(); // Only try to reposition the popup when it is not spanning the entire // screen. if ((old_pos.width() + popup_position_offset_from_screen_corner_x >= diff --git a/chrome/browser/ui/views/ash/window_positioner_unittest.cc b/chrome/browser/ui/views/ash/window_positioner_unittest.cc index 3e1b18c..f877069 100644 --- a/chrome/browser/ui/views/ash/window_positioner_unittest.cc +++ b/chrome/browser/ui/views/ash/window_positioner_unittest.cc @@ -194,7 +194,7 @@ void WindowPositionerTest::TearDown() { } // namespace TEST_F(WindowPositionerTest, cascading) { - const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); + const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitor().work_area(); // First see that the window will cascade down when there is no space. window()->SetBounds(work_area); @@ -254,7 +254,7 @@ TEST_F(WindowPositionerTest, cascading) { } TEST_F(WindowPositionerTest, filling) { - const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); + const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitor().work_area(); int grid = ash::Shell::GetInstance()->GetGridSize(); gfx::Rect popup_position(0, 0, 256, 128); // Leave space on the left and the right and see if we fill top to bottom. @@ -309,7 +309,7 @@ TEST_F(WindowPositionerTest, filling) { } TEST_F(WindowPositionerTest, blockedByPanel) { - const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); + const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitor().work_area(); gfx::Rect pop_position(0, 0, 200, 200); // Let the panel cover everything. @@ -324,7 +324,7 @@ TEST_F(WindowPositionerTest, blockedByPanel) { } TEST_F(WindowPositionerTest, biggerThenBorder) { - const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); + const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitor().work_area(); gfx::Rect pop_position(0, 0, work_area.width(), work_area.height()); diff --git a/chrome/browser/ui/views/chrome_views_delegate.cc b/chrome/browser/ui/views/chrome_views_delegate.cc index 8813ef0..51c573e 100644 --- a/chrome/browser/ui/views/chrome_views_delegate.cc +++ b/chrome/browser/ui/views/chrome_views_delegate.cc @@ -74,8 +74,8 @@ void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, window_preferences->SetInteger("bottom", bounds.bottom()); window_preferences->SetBoolean("maximized", show_state == ui::SHOW_STATE_MAXIMIZED); - - gfx::Rect work_area(gfx::Screen::GetMonitorWorkAreaMatching(bounds)); + gfx::Rect work_area( + gfx::Screen::GetMonitorMatching(bounds).work_area()); window_preferences->SetInteger("work_area_left", work_area.x()); window_preferences->SetInteger("work_area_top", work_area.y()); window_preferences->SetInteger("work_area_right", work_area.right()); diff --git a/chrome/browser/ui/views/extensions/extension_dialog.cc b/chrome/browser/ui/views/extensions/extension_dialog.cc index 7985dbb..94cea11 100644 --- a/chrome/browser/ui/views/extensions/extension_dialog.cc +++ b/chrome/browser/ui/views/extensions/extension_dialog.cc @@ -134,7 +134,7 @@ ExtensionHost* ExtensionDialog::CreateExtensionHost(const GURL& url, void ExtensionDialog::InitWindowFullscreen() { aura::RootWindow* root_window = ash::Shell::GetRootWindow(); gfx::Rect screen_rect = - gfx::Screen::GetMonitorAreaNearestWindow(root_window); + gfx::Screen::GetMonitorNearestWindow(root_window).bounds(); // We want to be the fullscreen topmost child of the root window. window_ = browser::CreateFramelessViewsWindow(root_window, this); diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index ee91a9e..3f232fd 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -1321,7 +1321,7 @@ gfx::Rect BrowserView::GetInstantBounds() { WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( const gfx::Rect& bounds) { #if defined(USE_AURA) - gfx::Size window_size = gfx::Screen::GetMonitorAreaNearestWindow( + gfx::Size window_size = gfx::Screen::GetMonitorNearestWindow( GetWidget()->GetNativeView()).size(); return browser::DispositionForPopupBounds( bounds, window_size.width(), window_size.height()); diff --git a/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc b/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc index 7263f8f..75c2fe0 100644 --- a/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc +++ b/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc @@ -340,8 +340,8 @@ gfx::Rect FullscreenExitBubbleViews::GetPopupRect( gfx::Size size(view_->GetPreferredSize()); // NOTE: don't use the bounds of the root_view_. On linux changing window // size is async. Instead we use the size of the screen. - gfx::Rect screen_bounds = gfx::Screen::GetMonitorAreaNearestWindow( - root_view_->GetWidget()->GetNativeView()); + gfx::Rect screen_bounds = gfx::Screen::GetMonitorNearestWindow( + root_view_->GetWidget()->GetNativeView()).bounds(); gfx::Point origin(screen_bounds.x() + (screen_bounds.width() - size.width()) / 2, kPopupTopPx + screen_bounds.y()); diff --git a/chrome/browser/ui/views/keyboard_overlay_delegate.cc b/chrome/browser/ui/views/keyboard_overlay_delegate.cc index e40749e..e2fac02 100644 --- a/chrome/browser/ui/views/keyboard_overlay_delegate.cc +++ b/chrome/browser/ui/views/keyboard_overlay_delegate.cc @@ -57,8 +57,8 @@ void KeyboardOverlayDelegate::GetDialogSize( gfx::Size* size) const { using std::min; DCHECK(view_); - gfx::Rect rect = gfx::Screen::GetMonitorAreaNearestWindow( - view_->GetWidget()->GetNativeView()); + gfx::Rect rect = gfx::Screen::GetMonitorNearestWindow( + view_->GetWidget()->GetNativeView()).bounds(); const int width = min(kBaseWidth, rect.width() - kHorizontalMargin); const int height = width * kBaseHeight / kBaseWidth; size->SetSize(width, height); diff --git a/chrome/browser/ui/views/keyboard_overlay_dialog_view.cc b/chrome/browser/ui/views/keyboard_overlay_dialog_view.cc index b1f9103..1328fad 100644 --- a/chrome/browser/ui/views/keyboard_overlay_dialog_view.cc +++ b/chrome/browser/ui/views/keyboard_overlay_dialog_view.cc @@ -97,8 +97,8 @@ void KeyboardOverlayDialogView::ShowDialog( // Show the widget at the bottom of the work area. gfx::Size size; delegate->GetDialogSize(&size); - gfx::Rect rect = gfx::Screen::GetMonitorWorkAreaNearestWindow( - html_view->GetWidget()->GetNativeView()); + gfx::Rect rect = gfx::Screen::GetMonitorNearestWindow( + html_view->GetWidget()->GetNativeView()).work_area(); gfx::Rect bounds((rect.width() - size.width()) / 2, rect.height() - size.height(), size.width(), diff --git a/chrome/browser/ui/views/status_bubble_views.cc b/chrome/browser/ui/views/status_bubble_views.cc index 7f36dea..8648f11 100644 --- a/chrome/browser/ui/views/status_bubble_views.cc +++ b/chrome/browser/ui/views/status_bubble_views.cc @@ -768,7 +768,7 @@ void StatusBubbleViews::AvoidMouse(const gfx::Point& location) { // download shelf. gfx::NativeView widget = base_view_->GetWidget()->GetNativeView(); gfx::Rect monitor_rect = - gfx::Screen::GetMonitorWorkAreaNearestWindow(widget); + gfx::Screen::GetMonitorNearestWindow(widget).work_area(); const int bubble_bottom_y = top_left.y() + position_.y() + size_.height(); if (bubble_bottom_y + offset > monitor_rect.height() || diff --git a/chrome/browser/ui/views/tabs/default_tab_drag_controller.cc b/chrome/browser/ui/views/tabs/default_tab_drag_controller.cc index 4681c9f..9ee3bb7 100644 --- a/chrome/browser/ui/views/tabs/default_tab_drag_controller.cc +++ b/chrome/browser/ui/views/tabs/default_tab_drag_controller.cc @@ -564,8 +564,8 @@ gfx::Point DefaultTabDragController::GetWindowCreatePoint() const { } // If the cursor is outside the monitor area, move it inside. For example, // dropping a tab onto the task bar on Windows produces this situation. - gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestPoint( - cursor_point); + gfx::Rect work_area = gfx::Screen::GetMonitorNearestPoint( + cursor_point).work_area(); if (!work_area.IsEmpty()) { if (cursor_point.x() < work_area.x()) cursor_point.set_x(work_area.x()); diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller2.cc b/chrome/browser/ui/views/tabs/tab_drag_controller2.cc index a664f83..05bb2d2 100644 --- a/chrome/browser/ui/views/tabs/tab_drag_controller2.cc +++ b/chrome/browser/ui/views/tabs/tab_drag_controller2.cc @@ -502,8 +502,8 @@ gfx::Point TabDragController2::GetWindowCreatePoint() const { } // If the cursor is outside the monitor area, move it inside. For example, // dropping a tab onto the task bar on Windows produces this situation. - gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestPoint( - cursor_point); + gfx::Rect work_area = gfx::Screen::GetMonitorNearestPoint( + cursor_point).work_area(); if (!work_area.IsEmpty()) { if (cursor_point.x() < work_area.x()) cursor_point.set_x(work_area.x()); diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller2_interactive_uitest.cc b/chrome/browser/ui/views/tabs/tab_drag_controller2_interactive_uitest.cc index 1daa5a6..3e0390a 100644 --- a/chrome/browser/ui/views/tabs/tab_drag_controller2_interactive_uitest.cc +++ b/chrome/browser/ui/views/tabs/tab_drag_controller2_interactive_uitest.cc @@ -130,8 +130,8 @@ class TabDragController2Test : public InProcessBrowserTest { ResetIDs(browser2->tabstrip_model(), 100); // Resize the two windows so they're right next to each other. - gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow( - browser()->window()->GetNativeHandle()); + gfx::Rect work_area = gfx::Screen::GetMonitorNearestWindow( + browser()->window()->GetNativeHandle()).work_area(); gfx::Size half_size = gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10); browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size)); diff --git a/chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.cc b/chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.cc index 4d125be..abb69ea 100644 --- a/chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.cc +++ b/chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.cc @@ -56,7 +56,7 @@ const char kOnTextInputTypeChanged[] = // The default position of the keyboard widget should be at the bottom, // spanning the entire width of the root window. gfx::Rect GetKeyboardPosition(int height) { - gfx::Rect area = gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()); + gfx::Rect area = gfx::Screen::GetPrimaryMonitor().bounds(); return gfx::Rect(area.x(), area.y() + area.height() - height, area.width(), height); } diff --git a/chrome/browser/ui/window_sizer.cc b/chrome/browser/ui/window_sizer.cc index 5c2da7f..0dffea6 100644 --- a/chrome/browser/ui/window_sizer.cc +++ b/chrome/browser/ui/window_sizer.cc @@ -23,14 +23,14 @@ class DefaultMonitorInfoProvider : public MonitorInfoProvider { public: // Overridden from MonitorInfoProvider: virtual gfx::Rect GetPrimaryMonitorWorkArea() const OVERRIDE { - return gfx::Screen::GetPrimaryMonitorWorkArea(); + return gfx::Screen::GetPrimaryMonitor().work_area(); } virtual gfx::Rect GetPrimaryMonitorBounds() const OVERRIDE { - return gfx::Screen::GetPrimaryMonitorBounds(); + return gfx::Screen::GetPrimaryMonitor().bounds(); } virtual gfx::Rect GetMonitorWorkAreaMatching( const gfx::Rect& match_rect) const OVERRIDE { - return gfx::Screen::GetMonitorWorkAreaMatching(match_rect); + return gfx::Screen::GetMonitorMatching(match_rect).work_area(); } }; diff --git a/chrome/browser/ui/window_sizer_gtk.cc b/chrome/browser/ui/window_sizer_gtk.cc index 133fb0c..0b0a5a0 100644 --- a/chrome/browser/ui/window_sizer_gtk.cc +++ b/chrome/browser/ui/window_sizer_gtk.cc @@ -20,7 +20,7 @@ const int WindowSizer::kWindowTilePixels = 10; // static gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) { - gfx::Rect monitor_bounds = gfx::Screen::GetPrimaryMonitorWorkArea(); + gfx::Rect monitor_bounds = gfx::Screen::GetPrimaryMonitor().work_area(); gfx::Point corner(monitor_bounds.x(), monitor_bounds.y()); if (Browser* browser = BrowserList::GetLastActive()) { GtkWindow* window = diff --git a/chrome/test/base/browser_with_test_window_test.cc b/chrome/test/base/browser_with_test_window_test.cc index ca71fb5..0edf9fc 100644 --- a/chrome/test/base/browser_with_test_window_test.cc +++ b/chrome/test/base/browser_with_test_window_test.cc @@ -15,17 +15,15 @@ #include "content/public/common/page_transition_types.h" #include "content/test/test_renderer_host.h" -#if defined(USE_ASH) -#include "ui/aura/test/test_screen.h" -#endif - #if defined(USE_AURA) #include "ui/aura/env.h" #include "ui/aura/monitor_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/single_monitor_manager.h" #include "ui/aura/test/test_activation_client.h" +#include "ui/aura/test/test_screen.h" #include "ui/aura/test/test_stacking_client.h" +#include "ui/gfx/screen.h" #endif using content::BrowserThread; @@ -51,9 +49,7 @@ void BrowserWithTestWindowTest::SetUp() { #if defined(USE_AURA) aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); root_window_.reset(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); -#if defined(USE_ASH) gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); -#endif // USE_ASH test_activation_client_.reset( new aura::test::TestActivationClient(root_window_.get())); test_stacking_client_.reset( diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index 789b9dbe..f21e8f9 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -27,8 +27,6 @@ #include "ui/aura/client/window_types.h" #include "ui/aura/env.h" #include "ui/aura/event.h" -#include "ui/aura/monitor.h" -#include "ui/aura/monitor_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" #include "ui/aura/window_observer.h" @@ -39,6 +37,7 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/compositor/compositor.h" #include "ui/gfx/compositor/layer.h" +#include "ui/gfx/monitor.h" #include "ui/gfx/screen.h" #include "ui/gfx/skia_util.h" @@ -120,20 +119,17 @@ content::GLHelper* CreateGLHelper(ui::Compositor* compositor) { } void GetScreenInfoForWindow(WebKit::WebScreenInfo* results, - const aura::Window* window) { - aura::MonitorManager* monitor_manager = - aura::Env::GetInstance()->monitor_manager(); - const aura::Monitor* monitor = window ? - monitor_manager->GetMonitorNearestWindow(window) : - monitor_manager->GetMonitorAt(0); - - const gfx::Size size = monitor->size(); + aura::Window* window) { + const gfx::Monitor monitor = window ? + gfx::Screen::GetMonitorNearestWindow(window) : + gfx::Screen::GetPrimaryMonitor(); + const gfx::Size size = monitor.size(); results->rect = WebKit::WebRect(0, 0, size.width(), size.height()); results->availableRect = results->rect; // TODO(derat): Don't hardcode this? results->depth = 24; results->depthPerComponent = 8; - int default_dpi = monitor->GetDeviceScaleFactor() * 160; + int default_dpi = monitor.device_scale_factor() * 160; // TODO(fsamuel): This is a temporary hack until Monitor code is complete. const CommandLine& command_line = *CommandLine::ForCurrentProcess(); if (command_line.HasSwitch(switches::kDefaultDeviceScaleFactor)) { diff --git a/content/browser/renderer_host/render_widget_host_view_win.cc b/content/browser/renderer_host/render_widget_host_view_win.cc index cad5c9b..288439e 100644 --- a/content/browser/renderer_host/render_widget_host_view_win.cc +++ b/content/browser/renderer_host/render_widget_host_view_win.cc @@ -389,8 +389,8 @@ void RenderWidgetHostViewWin::InitAsPopup( void RenderWidgetHostViewWin::InitAsFullscreen( RenderWidgetHostView* reference_host_view) { - gfx::Rect pos = gfx::Screen::GetMonitorAreaNearestWindow( - reference_host_view->GetNativeView()); + gfx::Rect pos = gfx::Screen::GetMonitorNearestWindow( + reference_host_view->GetNativeView()).bounds(); is_fullscreen_ = true; DoPopupOrFullscreenInit(GetDesktopWindow(), pos, 0); } diff --git a/content/test/test_renderer_host.cc b/content/test/test_renderer_host.cc index 2f5aa25..cd9aa34 100644 --- a/content/test/test_renderer_host.cc +++ b/content/test/test_renderer_host.cc @@ -13,16 +13,14 @@ #include "content/test/mock_render_process_host.h" #include "content/test/test_browser_context.h" -#if defined(USE_ASH) -#include "ui/aura/test/test_screen.h" -#endif - #if defined(USE_AURA) #include "ui/aura/env.h" #include "ui/aura/monitor_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/single_monitor_manager.h" +#include "ui/aura/test/test_screen.h" #include "ui/aura/test/test_stacking_client.h" +#include "ui/gfx/screen.h" #endif namespace content { @@ -197,9 +195,7 @@ void RenderViewHostTestHarness::SetUp() { #if defined(USE_AURA) aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); root_window_.reset(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); -#if defined(USE_ASH) gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); -#endif // USE_ASH test_stacking_client_.reset( new aura::test::TestStackingClient(root_window_.get())); #endif // USE_AURA diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp index 48a8122..cf1eab5 100644 --- a/ui/aura/aura.gyp +++ b/ui/aura/aura.gyp @@ -73,12 +73,12 @@ 'focus_manager.h', 'layout_manager.cc', 'layout_manager.h', - 'monitor.cc', - 'monitor.h', 'monitor_change_observer_x11.cc', 'monitor_change_observer_x11.h', 'monitor_manager.cc', 'monitor_manager.h', + 'monitor_observer.cc', + 'monitor_observer.h', 'root_window_host.h', 'root_window_host_linux.cc', 'root_window_host_linux.h', diff --git a/ui/aura/monitor.cc b/ui/aura/monitor.cc deleted file mode 100644 index 52d64f0..0000000 --- a/ui/aura/monitor.cc +++ /dev/null @@ -1,24 +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.h" - -namespace aura { - -Monitor::Monitor() : device_scale_factor_(1.0f) { -} - -Monitor::~Monitor() { -} - -gfx::Rect Monitor::GetWorkAreaBounds() const { - // 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; -} - -} // namespace aura diff --git a/ui/aura/monitor.h b/ui/aura/monitor.h deleted file mode 100644 index f62a781..0000000 --- a/ui/aura/monitor.h +++ /dev/null @@ -1,72 +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. - -#ifndef UI_AURA_MONITOR_H_ -#define UI_AURA_MONITOR_H_ -#pragma once - -#include "base/basictypes.h" -#include "ui/aura/aura_export.h" -#include "ui/gfx/insets.h" -#include "ui/gfx/rect.h" - -namespace aura { - -// Note: The screen and monitor currently uses pixels coordinate -// system. ENABLE_DIP macro (which is enabled with enable_dip=1 gyp -// flag) will make this inconsistent with views' coordinate system -// because views will use DIP coordinate system, which uses -// (1.0/device_scale_factor) scale of the pixel coordinate system. -// TODO(oshima): Change aura/screen to DIP coordinate system and -// update this comment. -class AURA_EXPORT Monitor { - public: - Monitor(); - ~Monitor(); - - // Sets/gets monitor's bounds in |gfx::screen|'s coordinates, - // which is relative to the primary screen's origin. - 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_; } - - // Output device's pixel scale factor. This specifies how much the - // UI should be scaled when the actual output has more pixels than - // standard monitors (which is around 100~120dpi.) For aura, this - // value is either 1.0 or 2.0, but may return different values on - // other platforms. - float GetDeviceScaleFactor() const { - return device_scale_factor_; - } - - void set_device_scale_factor(float scale) { - device_scale_factor_ = scale; - } - - // Returns the monitor's work area. - gfx::Rect GetWorkAreaBounds() const; - - private: - // Insets for the work area. - gfx::Insets work_area_insets_; - - gfx::Rect bounds_; - - float device_scale_factor_; - - DISALLOW_COPY_AND_ASSIGN(Monitor); -}; - -} // namespace aura - -#endif // UI_AURA_MONITOR_H_ diff --git a/ui/aura/monitor_change_observer_x11.cc b/ui/aura/monitor_change_observer_x11.cc index bb2904f..3239022 100644 --- a/ui/aura/monitor_change_observer_x11.cc +++ b/ui/aura/monitor_change_observer_x11.cc @@ -12,11 +12,10 @@ #include <X11/extensions/Xrandr.h> #include "base/message_pump_x.h" -#include "base/stl_util.h" #include "ui/aura/env.h" #include "ui/aura/dispatcher_linux.h" -#include "ui/aura/monitor.h" #include "ui/aura/monitor_manager.h" +#include "ui/gfx/monitor.h" namespace aura { namespace internal { @@ -31,8 +30,8 @@ XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) { return NULL; } -bool CompareMonitorY(const Monitor* lhs, const Monitor* rhs) { - return lhs->bounds().y() < rhs->bounds().y(); +bool CompareMonitorY(gfx::Monitor lhs, gfx::Monitor rhs) { + return lhs.bounds().y() < rhs.bounds().y(); } } // namespace @@ -77,7 +76,7 @@ void MonitorChangeObserverX11::NotifyMonitorChange() { crtc_info_map[crtc_id] = crtc_info; } - std::vector<const Monitor*> monitors; + std::vector<gfx::Monitor> monitors; std::set<int> y_coords; for (int o = 0; o < screen_resources->noutput; o++) { XRROutputInfo *output_info = @@ -98,10 +97,10 @@ void MonitorChangeObserverX11::NotifyMonitorChange() { // Mirrored monitors have the same y coordinates. if (y_coords.find(crtc_info->y) != y_coords.end()) continue; - Monitor* monitor = new Monitor; - monitor->set_bounds(gfx::Rect(crtc_info->x, crtc_info->y, - mode->width, mode->height)); - monitors.push_back(monitor); + // TODO(oshima): Create unique ID for the monitor. + monitors.push_back(gfx::Monitor( + 0, + gfx::Rect(crtc_info->x, crtc_info->y, mode->width, mode->height))); y_coords.insert(crtc_info->y); XRRFreeOutputInfo(output_info); } @@ -116,9 +115,14 @@ void MonitorChangeObserverX11::NotifyMonitorChange() { // PowerManager lays out the outputs vertically. Sort them by Y // coordinates. std::sort(monitors.begin(), monitors.end(), CompareMonitorY); + // TODO(oshima): Assisgn index as ID for now. Use unique ID. + int id = 0; + for (std::vector<gfx::Monitor>::iterator iter = monitors.begin(); + iter != monitors.end(); ++iter, ++id) + (*iter).set_id(id); + Env::GetInstance()->monitor_manager() ->OnNativeMonitorsChanged(monitors); - STLDeleteContainerPointers(monitors.begin(), monitors.end()); } } // namespace internal diff --git a/ui/aura/monitor_manager.cc b/ui/aura/monitor_manager.cc index c884c6d..8cf70bc 100644 --- a/ui/aura/monitor_manager.cc +++ b/ui/aura/monitor_manager.cc @@ -8,9 +8,10 @@ #include "base/logging.h" #include "ui/aura/env.h" -#include "ui/aura/monitor.h" +#include "ui/aura/monitor_observer.h" #include "ui/aura/root_window.h" #include "ui/aura/root_window_host.h" +#include "ui/gfx/monitor.h" #include "ui/gfx/rect.h" namespace aura { @@ -26,7 +27,8 @@ static const int kDefaultHostWindowHeight = 1024; bool MonitorManager::use_fullscreen_host_window_ = false; // static -Monitor* MonitorManager::CreateMonitorFromSpec(const std::string& spec) { +gfx::Monitor MonitorManager::CreateMonitorFromSpec(const std::string& spec) { + static int synthesized_monitor_id = 1000; gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, kDefaultHostWindowWidth, kDefaultHostWindowHeight); int x = 0, y = 0, width, height; @@ -39,9 +41,8 @@ Monitor* MonitorManager::CreateMonitorFromSpec(const std::string& spec) { } else if (use_fullscreen_host_window_) { bounds = gfx::Rect(aura::RootWindowHost::GetNativeScreenSize()); } - Monitor* monitor = new Monitor(); - monitor->set_bounds(bounds); - monitor->set_device_scale_factor(scale); + gfx::Monitor monitor(synthesized_monitor_id++, bounds); + monitor.set_device_scale_factor(scale); DVLOG(1) << "Monitor bounds=" << bounds.ToString() << ", scale=" << scale; return monitor; } @@ -70,17 +71,17 @@ void MonitorManager::RemoveObserver(MonitorObserver* observer) { observers_.RemoveObserver(observer); } -void MonitorManager::NotifyBoundsChanged(const Monitor* monitor) { +void MonitorManager::NotifyBoundsChanged(const gfx::Monitor& monitor) { FOR_EACH_OBSERVER(MonitorObserver, observers_, OnMonitorBoundsChanged(monitor)); } -void MonitorManager::NotifyMonitorAdded(Monitor* monitor) { +void MonitorManager::NotifyMonitorAdded(const gfx::Monitor& monitor) { FOR_EACH_OBSERVER(MonitorObserver, observers_, OnMonitorAdded(monitor)); } -void MonitorManager::NotifyMonitorRemoved(const Monitor* monitor) { +void MonitorManager::NotifyMonitorRemoved(const gfx::Monitor& monitor) { FOR_EACH_OBSERVER(MonitorObserver, observers_, OnMonitorRemoved(monitor)); } diff --git a/ui/aura/monitor_manager.h b/ui/aura/monitor_manager.h index 9bbd028..b3886cf 100644 --- a/ui/aura/monitor_manager.h +++ b/ui/aura/monitor_manager.h @@ -14,24 +14,16 @@ #include "ui/aura/aura_export.h" namespace gfx { +class Monitor; class Point; class Size; } namespace aura { -class Monitor; +class MonitorObserver; class RootWindow; class Window; -// Observers for monitor configuration changes. -// TODO(oshima): multiple monitor support. -class MonitorObserver { - public: - virtual void OnMonitorBoundsChanged(const Monitor* monitor) = 0; - virtual void OnMonitorAdded(Monitor* new_monitor) = 0; - virtual void OnMonitorRemoved(const Monitor* old_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 @@ -50,7 +42,7 @@ class AURA_EXPORT MonitorManager { // 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); + static gfx::Monitor CreateMonitorFromSpec(const std::string& spec); // A utility function to create a root window for primary monitor. static RootWindow* CreateRootWindowForPrimaryMonitor(); @@ -66,31 +58,31 @@ class AURA_EXPORT MonitorManager { // configurations is passed as a vector of Monitor object, which // contains each monitor's new infomration. virtual void OnNativeMonitorsChanged( - const std::vector<const Monitor*>& monitors) = 0; + const std::vector<gfx::Monitor>& monitors) = 0; // Create a root window for given |monitor|. - virtual RootWindow* CreateRootWindowForMonitor(Monitor* monitor) = 0; + virtual RootWindow* CreateRootWindowForMonitor( + const gfx::Monitor& monitor) = 0; + + // Returns the monitor at |index|. The monitor at 0 is considered + // "primary". + virtual const gfx::Monitor& GetMonitorAt(size_t index) = 0; + + virtual size_t GetNumMonitors() const = 0; // Returns the monitor object nearest given |window|. - virtual const Monitor* GetMonitorNearestWindow( + virtual const gfx::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( + virtual const gfx::Monitor& GetMonitorNearestPoint( const gfx::Point& point) const = 0; - // Returns the monitor at |index|. The monitor at 0 is considered - // "primary". - virtual Monitor* GetMonitorAt(size_t index) = 0; - - virtual size_t GetNumMonitors() const = 0; - protected: // Calls observers' OnMonitorBoundsChanged methods. - void NotifyBoundsChanged(const Monitor* monitor); - void NotifyMonitorAdded(Monitor* monitor); - void NotifyMonitorRemoved(const Monitor* monitor); + void NotifyBoundsChanged(const gfx::Monitor& monitor); + void NotifyMonitorAdded(const gfx::Monitor& monitor); + void NotifyMonitorRemoved(const gfx::Monitor& monitor); private: // If set before the RootWindow is created, the host window will cover the diff --git a/ui/aura/monitor_observer.cc b/ui/aura/monitor_observer.cc new file mode 100644 index 0000000..aa1cf0f --- /dev/null +++ b/ui/aura/monitor_observer.cc @@ -0,0 +1,12 @@ +// 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_observer.h" + +namespace aura { + +MonitorObserver::~MonitorObserver() { +} + +} // namespace aura diff --git a/ui/aura/monitor_observer.h b/ui/aura/monitor_observer.h new file mode 100644 index 0000000..dbbc53a --- /dev/null +++ b/ui/aura/monitor_observer.h @@ -0,0 +1,35 @@ +// 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_MONITOR_OBSERVER_H_ +#define UI_AURA_MONITOR_OBSERVER_H_ +#pragma once + +#include "ui/aura/aura_export.h" + +namespace gfx { +class Monitor; +} + +namespace aura { + +// Observers for monitor configuration changes. +class AURA_EXPORT MonitorObserver { + public: + // Called when the |monitor|'s bound has changed. + virtual void OnMonitorBoundsChanged(const gfx::Monitor& monitor) = 0; + + // Called when |new_monitor| has been added. + virtual void OnMonitorAdded(const gfx::Monitor& new_monitor) = 0; + + // Called when |old_monitor| has been removed. + virtual void OnMonitorRemoved(const gfx::Monitor& old_monitor) = 0; + + protected: + virtual ~MonitorObserver(); +}; + +} // namespace aura + +#endif // UI_AURA_MONITOR_OBSERVER_H_ diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index 5fe70da..37cdb53 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -18,8 +18,6 @@ #include "ui/aura/event.h" #include "ui/aura/event_filter.h" #include "ui/aura/focus_manager.h" -#include "ui/aura/monitor.h" -#include "ui/aura/monitor_manager.h" #include "ui/aura/root_window_host.h" #include "ui/aura/root_window_observer.h" #include "ui/aura/window.h" diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc index f5c734b..fc2206f 100644 --- a/ui/aura/root_window_host_linux.cc +++ b/ui/aura/root_window_host_linux.cc @@ -18,8 +18,6 @@ #include "ui/aura/dispatcher_linux.h" #include "ui/aura/env.h" #include "ui/aura/event.h" -#include "ui/aura/monitor.h" -#include "ui/aura/monitor_manager.h" #include "ui/aura/root_window.h" #include "ui/base/cursor/cursor.h" #include "ui/base/keycodes/keyboard_codes.h" diff --git a/ui/aura/single_monitor_manager.cc b/ui/aura/single_monitor_manager.cc index 4797327..aaeae07 100644 --- a/ui/aura/single_monitor_manager.cc +++ b/ui/aura/single_monitor_manager.cc @@ -8,9 +8,9 @@ #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/monitor.h" #include "ui/gfx/rect.h" namespace aura { @@ -36,50 +36,46 @@ SingleMonitorManager::~SingleMonitorManager() { } void SingleMonitorManager::OnNativeMonitorsChanged( - const std::vector<const Monitor*>& monitors) { + const std::vector<gfx::Monitor>& monitors) { DCHECK(monitors.size() > 0); if (use_fullscreen_host_window()) { - monitor_->set_size(monitors[0]->bounds().size()); - NotifyBoundsChanged(monitor_.get()); + monitor_.SetSizeAndUpdateWorkArea(monitors[0].bounds().size()); + NotifyBoundsChanged(monitor_); } } RootWindow* SingleMonitorManager::CreateRootWindowForMonitor( - Monitor* monitor) { + const gfx::Monitor& monitor) { DCHECK(!root_window_); - DCHECK_EQ(monitor_.get(), monitor); - root_window_ = new RootWindow(monitor->bounds()); + DCHECK_EQ(monitor_.id(), monitor.id()); + root_window_ = new RootWindow(monitor.bounds()); 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(); -} - -Monitor* SingleMonitorManager::GetMonitorAt(size_t index) { - return !index ? monitor_.get() : NULL; +const gfx::Monitor& SingleMonitorManager::GetMonitorAt(size_t index) { + return monitor_; } size_t SingleMonitorManager::GetNumMonitors() const { return 1; } -Monitor* SingleMonitorManager::GetMonitorNearestWindow(const Window* window) { - return monitor_.get(); +const gfx::Monitor& SingleMonitorManager::GetMonitorNearestWindow( + const Window* window) const { + return monitor_; +} + +const gfx::Monitor& SingleMonitorManager::GetMonitorNearestPoint( + const gfx::Point& point) const { + return monitor_; } void SingleMonitorManager::OnWindowBoundsChanged( Window* window, const gfx::Rect& bounds) { if (!use_fullscreen_host_window()) { Update(bounds.size()); - NotifyBoundsChanged(monitor_.get()); + NotifyBoundsChanged(monitor_); } } @@ -91,11 +87,11 @@ void SingleMonitorManager::OnWindowDestroying(Window* window) { void SingleMonitorManager::Init() { const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kAuraHostWindowSize); - monitor_.reset(CreateMonitorFromSpec(size_str)); + monitor_ = CreateMonitorFromSpec(size_str); } void SingleMonitorManager::Update(const gfx::Size size) { - monitor_->set_size(size); + monitor_.SetSizeAndUpdateWorkArea(size); } } // namespace aura diff --git a/ui/aura/single_monitor_manager.h b/ui/aura/single_monitor_manager.h index 85dfffa..8b1494c 100644 --- a/ui/aura/single_monitor_manager.h +++ b/ui/aura/single_monitor_manager.h @@ -11,6 +11,7 @@ #include "ui/aura/aura_export.h" #include "ui/aura/monitor_manager.h" #include "ui/aura/window_observer.h" +#include "ui/gfx/monitor.h" namespace gfx { class Rect; @@ -27,16 +28,17 @@ class AURA_EXPORT SingleMonitorManager : public MonitorManager, // MonitorManager overrides: virtual void OnNativeMonitorsChanged( - const std::vector<const Monitor*>& monitors) OVERRIDE; + const std::vector<gfx::Monitor>& monitors) OVERRIDE; virtual RootWindow* CreateRootWindowForMonitor( - Monitor* monitor) OVERRIDE; - virtual const Monitor* GetMonitorNearestWindow( + const gfx::Monitor& monitor) OVERRIDE; + virtual const gfx::Monitor& GetMonitorAt(size_t index) OVERRIDE; + + virtual size_t GetNumMonitors() const OVERRIDE; + + virtual const gfx::Monitor& GetMonitorNearestWindow( const Window* window) const OVERRIDE; - virtual const Monitor* GetMonitorNearestPoint( + virtual const gfx::Monitor& GetMonitorNearestPoint( const gfx::Point& point) const OVERRIDE; - virtual Monitor* GetMonitorAt(size_t index) OVERRIDE; - virtual size_t GetNumMonitors() const OVERRIDE; - virtual Monitor* GetMonitorNearestWindow(const Window* window) OVERRIDE; // WindowObserver overrides: virtual void OnWindowBoundsChanged(Window* window, @@ -48,7 +50,7 @@ class AURA_EXPORT SingleMonitorManager : public MonitorManager, void Update(const gfx::Size size); RootWindow* root_window_; - scoped_ptr<Monitor> monitor_; + gfx::Monitor monitor_; DISALLOW_COPY_AND_ASSIGN(SingleMonitorManager); }; diff --git a/ui/aura/test/aura_test_base.cc b/ui/aura/test/aura_test_base.cc index 9a0a7ae..9784981 100644 --- a/ui/aura/test/aura_test_base.cc +++ b/ui/aura/test/aura_test_base.cc @@ -8,15 +8,13 @@ #include "ui/aura/monitor_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/single_monitor_manager.h" +#include "ui/aura/test/test_screen.h" #include "ui/aura/test/test_stacking_client.h" #include "ui/aura/ui_controls_aura.h" #include "ui/base/gestures/gesture_configuration.h" +#include "ui/gfx/screen.h" #include "ui/ui_controls/ui_controls.h" -#if defined(USE_ASH) -#include "ui/aura/test/test_screen.h" -#endif - namespace aura { namespace test { @@ -53,9 +51,7 @@ void AuraTestBase::SetUp() { Env::GetInstance()->SetMonitorManager(new SingleMonitorManager); root_window_.reset(Env::GetInstance()->monitor_manager()-> CreateRootWindowForPrimaryMonitor()); -#if defined(USE_ASH) gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); -#endif ui_controls::InstallUIControlsAura(CreateUIControlsAura(root_window_.get())); helper_.InitRootWindow(root_window()); helper_.SetUp(); diff --git a/ui/aura/test/test_screen.cc b/ui/aura/test/test_screen.cc index e61db9f..d242d78 100644 --- a/ui/aura/test/test_screen.cc +++ b/ui/aura/test/test_screen.cc @@ -8,6 +8,7 @@ #include "ui/aura/root_window.h" #include "ui/aura/window.h" #include "ui/gfx/native_widget_types.h" +#include "ui/gfx/screen.h" namespace aura { @@ -18,44 +19,34 @@ TestScreen::TestScreen(aura::RootWindow* root_window) TestScreen::~TestScreen() { } -gfx::Point TestScreen::GetCursorScreenPointImpl() { +gfx::Point TestScreen::GetCursorScreenPoint() { return root_window_->last_mouse_location(); } -gfx::Rect TestScreen::GetMonitorWorkAreaNearestWindowImpl( - gfx::NativeWindow window) { - return GetBounds(); -} - -gfx::Rect TestScreen::GetMonitorAreaNearestWindowImpl( - gfx::NativeWindow window) { - return GetBounds(); -} - -gfx::Rect TestScreen::GetMonitorWorkAreaNearestPointImpl( - const gfx::Point& point) { - return GetBounds(); +gfx::NativeWindow TestScreen::GetWindowAtCursorScreenPoint() { + const gfx::Point point = gfx::Screen::GetCursorScreenPoint(); + return root_window_->GetTopWindowContainingPoint(point); } -gfx::Rect TestScreen::GetMonitorAreaNearestPointImpl(const gfx::Point& point) { - return GetBounds(); +int TestScreen::GetNumMonitors() { + return 1; } -gfx::NativeWindow TestScreen::GetWindowAtCursorScreenPointImpl() { - const gfx::Point point = GetCursorScreenPoint(); - return root_window_->GetTopWindowContainingPoint(point); +gfx::Monitor TestScreen::GetMonitorNearestWindow( + gfx::NativeWindow window) const { + return GetMonitor(); } -gfx::Rect TestScreen::GetBounds() { - return gfx::Rect(root_window_->bounds().size()); +gfx::Monitor TestScreen::GetMonitorNearestPoint(const gfx::Point& point) const { + return GetMonitor(); } -gfx::Size TestScreen::GetPrimaryMonitorSizeImpl() { - return GetBounds().size(); +gfx::Monitor TestScreen::GetPrimaryMonitor() const { + return GetMonitor(); } -int TestScreen::GetNumMonitorsImpl() { - return 1; +gfx::Monitor TestScreen::GetMonitor() const { + return gfx::Monitor(0, root_window_->bounds()); } } // namespace aura diff --git a/ui/aura/test/test_screen.h b/ui/aura/test/test_screen.h index 59fe63d..46c24c6 100644 --- a/ui/aura/test/test_screen.h +++ b/ui/aura/test/test_screen.h @@ -7,36 +7,31 @@ #pragma once #include "base/compiler_specific.h" -#include "ui/gfx/insets.h" -#include "ui/gfx/screen.h" +#include "base/memory/scoped_ptr.h" +#include "ui/gfx/screen_impl.h" namespace aura { class RootWindow; // A minimal, testing Aura implementation of gfx::Screen. -class TestScreen : public gfx::Screen { +class TestScreen : public gfx::ScreenImpl { public: explicit TestScreen(aura::RootWindow* root_window); virtual ~TestScreen(); protected: - virtual gfx::Point GetCursorScreenPointImpl() OVERRIDE; - virtual gfx::Rect GetMonitorWorkAreaNearestWindowImpl( - gfx::NativeView view) OVERRIDE; - virtual gfx::Rect GetMonitorAreaNearestWindowImpl( - gfx::NativeView view) OVERRIDE; - virtual gfx::Rect GetMonitorWorkAreaNearestPointImpl( - const gfx::Point& point) OVERRIDE; - virtual gfx::Rect GetMonitorAreaNearestPointImpl( - const gfx::Point& point) OVERRIDE; - virtual gfx::NativeWindow GetWindowAtCursorScreenPointImpl() OVERRIDE; - virtual gfx::Size GetPrimaryMonitorSizeImpl() OVERRIDE; - virtual int GetNumMonitorsImpl() OVERRIDE; + // gfx::ScreenImpl overrides: + virtual gfx::Point GetCursorScreenPoint() OVERRIDE; + virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE; + virtual int GetNumMonitors() OVERRIDE; + virtual gfx::Monitor GetMonitorNearestWindow( + gfx::NativeView view) const OVERRIDE; + virtual gfx::Monitor GetMonitorNearestPoint( + const gfx::Point& point) const OVERRIDE; + virtual gfx::Monitor GetPrimaryMonitor() const OVERRIDE; private: - // We currently support only one monitor. These two methods return the bounds - // and work area. - gfx::Rect GetBounds(); + gfx::Monitor GetMonitor() const; aura::RootWindow* root_window_; diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index a3401f6..5a011d4 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -974,7 +974,7 @@ TEST_F(WindowTest, IgnoreEventsTest) { TEST_F(WindowTest, Transform) { gfx::Size size = root_window()->GetHostSize(); EXPECT_EQ(gfx::Rect(size), - gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point())); + gfx::Screen::GetMonitorNearestPoint(gfx::Point()).bounds()); // Rotate it clock-wise 90 degrees. ui::Transform transform; @@ -986,8 +986,9 @@ TEST_F(WindowTest, Transform) { gfx::Size transformed_size(size.height(), size.width()); EXPECT_EQ(transformed_size.ToString(), root_window()->bounds().size().ToString()); - EXPECT_EQ(gfx::Rect(transformed_size).ToString(), - gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()).ToString()); + EXPECT_EQ( + gfx::Rect(transformed_size).ToString(), + gfx::Screen::GetMonitorNearestPoint(gfx::Point()).bounds().ToString()); // Host size shouldn't change. EXPECT_EQ(size.ToString(), diff --git a/ui/gfx/monitor.cc b/ui/gfx/monitor.cc new file mode 100644 index 0000000..8e56e0f --- /dev/null +++ b/ui/gfx/monitor.cc @@ -0,0 +1,45 @@ +// 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/gfx/monitor.h" + +#include "ui/gfx/insets.h" + +namespace gfx { + +Monitor::Monitor() : id_(-1), device_scale_factor_(1.0) { +} + +Monitor::Monitor(int id) : id_(id), device_scale_factor_(1.0) { +} + +Monitor::Monitor(int id, const gfx::Rect& bounds) + : id_(id), + bounds_(bounds), + work_area_(bounds), + device_scale_factor_(1.0) { +} + +Monitor::~Monitor() { +} + +void Monitor::SetBoundsAndUpdateWorkArea(const gfx::Rect& bounds) { + Insets insets(work_area_.y() - bounds_.y(), + work_area_.x() - bounds_.x(), + bounds_.bottom() - work_area_.bottom(), + bounds_.right() - work_area_.right()); + bounds_ = bounds; + UpdateWorkAreaWithInsets(insets); +} + +void Monitor::SetSizeAndUpdateWorkArea(const gfx::Size& size) { + SetBoundsAndUpdateWorkArea(gfx::Rect(bounds_.origin(), size)); +} + +void Monitor::UpdateWorkAreaWithInsets(const gfx::Insets& insets) { + work_area_ = bounds_; + work_area_.Inset(insets); +} + +} // namespace gfx diff --git a/ui/gfx/monitor.h b/ui/gfx/monitor.h new file mode 100644 index 0000000..3110acd --- /dev/null +++ b/ui/gfx/monitor.h @@ -0,0 +1,76 @@ +// 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_GFX_MONITOR_H_ +#define UI_GFX_MONITOR_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ui/base/ui_export.h" +#include "ui/gfx/rect.h" + +namespace gfx { + +// Note: The screen and monitor currently uses pixel coordinate +// system. ENABLE_DIP macro (which is enabled with enable_dip=1 gyp +// flag) will make this inconsistent with views' coordinate system +// because views will use DIP coordinate system, which uses +// (1.0/device_scale_factor) scale of the pixel coordinate system. +// TODO(oshima): Change aura/screen to DIP coordinate system and +// update this comment. +class UI_EXPORT Monitor { + public: + // Creates a monitor with invalid id(-1) as default. + Monitor(); + explicit Monitor(int id); + Monitor(int id, const Rect& bounds); + ~Monitor(); + + // Sets/Gets unique identifier associated with the monitor. + int id() const { return id_; } + void set_id(int id) { id_ = id; } + + // Gets/Sets the monitor's bounds in gfx::Screen's coordinates. + // -1 means invalid monitor and it doesn't not exit. + const Rect& bounds() const { return bounds_; } + void set_bounds(const Rect& bounds) { bounds_ = bounds; } + + // Gets/Sets the monitor's work area in gfx::Screen's coordinates. + const Rect& work_area() const { return work_area_; } + void set_work_area(const Rect& work_area) { work_area_ = work_area; } + + // Output device's pixel scale factor. This specifies how much the + // UI should be scaled when the actual output has more pixels than + // standard monitors (which is around 100~120dpi.) The potential return + // values depend on each platforms. + float device_scale_factor() const { return device_scale_factor_; } + void set_device_scale_factor(float scale) { device_scale_factor_ = scale; } + + // Utility functions that just return the size of monitor and + // work area. + const Size& size() const { return bounds_.size(); } + const Size& work_area_size() const { return work_area_.size(); } + + // Sets the monitor bounds and updates the work are using the same insets + // between old bounds and work area. + void SetBoundsAndUpdateWorkArea(const gfx::Rect& bounds); + + // Sets the monitor size and updates the work are using the same insets + // between old bounds and work area. + void SetSizeAndUpdateWorkArea(const gfx::Size& size); + + // Computes and updates the monitor's work are using insets and the bounds. + void UpdateWorkAreaWithInsets(const gfx::Insets& work_area_insets); + + private: + int id_; + Rect bounds_; + Rect work_area_; + float device_scale_factor_; +}; + +} // namespace gfx + +#endif // UI_GFX_MONITOR_H_ diff --git a/ui/gfx/monitor_unittest.cc b/ui/gfx/monitor_unittest.cc new file mode 100644 index 0000000..24f179b --- /dev/null +++ b/ui/gfx/monitor_unittest.cc @@ -0,0 +1,29 @@ +// 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/gfx/monitor.h" + +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/insets.h" + +namespace { + +TEST(MonitorTest, WorkArea) { + gfx::Monitor monitor(0, gfx::Rect(0, 0, 100, 100)); + EXPECT_EQ("0,0 100x100", monitor.work_area().ToString()); + + monitor.set_work_area(gfx::Rect(3, 4, 90, 80)); + EXPECT_EQ("3,4 90x80", monitor.work_area().ToString()); + + monitor.SetBoundsAndUpdateWorkArea(gfx::Rect(10, 20, 50, 50)); + EXPECT_EQ("13,24 40x30", monitor.work_area().ToString()); + + monitor.SetSizeAndUpdateWorkArea(gfx::Size(200, 200)); + EXPECT_EQ("13,24 190x180", monitor.work_area().ToString()); + + monitor.UpdateWorkAreaWithInsets(gfx::Insets(3, 4, 5, 6)); + EXPECT_EQ("14,23 190x192", monitor.work_area().ToString()); +} + +} diff --git a/ui/gfx/screen.h b/ui/gfx/screen.h index a451130..8e5d273 100644 --- a/ui/gfx/screen.h +++ b/ui/gfx/screen.h @@ -7,82 +7,48 @@ #pragma once #include "ui/gfx/native_widget_types.h" +#include "ui/gfx/monitor.h" #include "ui/gfx/point.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" namespace gfx { +class Rect; +class ScreenImpl; // A utility class for getting various info about screen size, monitors, // cursor position, etc. -// TODO(erikkay) add more of those methods here class UI_EXPORT Screen { public: virtual ~Screen() {} -#if defined(USE_ASH) +#if defined(USE_AURA) // Sets the instance to use. This takes owernship of |screen|, deleting the // old instance. This is used on aura to avoid circular dependencies between // ui and aura. - static void SetInstance(Screen* screen); + static void SetInstance(ScreenImpl* screen); #endif // Returns the current absolute position of the mouse pointer. static gfx::Point GetCursorScreenPoint(); - // Returns the work area of the monitor nearest the specified window. - static gfx::Rect GetMonitorWorkAreaNearestWindow(gfx::NativeView view); - - // Returns the bounds of the monitor nearest the specified window. - static gfx::Rect GetMonitorAreaNearestWindow(gfx::NativeView view); - - // Returns the work area of the monitor nearest the specified point. - static gfx::Rect GetMonitorWorkAreaNearestPoint(const gfx::Point& point); - - // Returns the monitor area (not the work area, but the complete bounds) of - // the monitor nearest the specified point. - static gfx::Rect GetMonitorAreaNearestPoint(const gfx::Point& point); - - // Returns the bounds of the work area of the primary monitor. - static gfx::Rect GetPrimaryMonitorWorkArea(); - - // Returns the bounds of the primary monitor. - static gfx::Rect GetPrimaryMonitorBounds(); - - // Returns the bounds of the work area of the monitor that most closely - // intersects the provided bounds. - static gfx::Rect GetMonitorWorkAreaMatching( - const gfx::Rect& match_rect); - // Returns the window under the cursor. static gfx::NativeWindow GetWindowAtCursorScreenPoint(); - // Returns the dimensions of the primary monitor in pixels. - static gfx::Size GetPrimaryMonitorSize(); - // Returns the number of monitors. // Mirrored displays are excluded; this method is intended to return the // number of distinct, usable displays. static int GetNumMonitors(); - protected: - virtual gfx::Point GetCursorScreenPointImpl() = 0; - virtual gfx::Rect GetMonitorWorkAreaNearestWindowImpl( - gfx::NativeView view) = 0; - virtual gfx::Rect GetMonitorAreaNearestWindowImpl( - gfx::NativeView view) = 0; - virtual gfx::Rect GetMonitorWorkAreaNearestPointImpl( - const gfx::Point& point) = 0; - virtual gfx::Rect GetMonitorAreaNearestPointImpl(const gfx::Point& point) = 0; - virtual gfx::NativeWindow GetWindowAtCursorScreenPointImpl() = 0; - virtual gfx::Size GetPrimaryMonitorSizeImpl() = 0; - virtual int GetNumMonitorsImpl() = 0; + // Returns the monitor nearest the specified window. + static gfx::Monitor GetMonitorNearestWindow(gfx::NativeView view); -private: -#if defined(USE_AURA) - // The singleton screen instance. Only used on aura. - static Screen* instance_; -#endif + // Returns the the monitor nearest the specified point. + static gfx::Monitor GetMonitorNearestPoint(const gfx::Point& point); + + // Returns the bounds of the work area of the primary monitor. + static gfx::Monitor GetPrimaryMonitor(); + + // Returns the monitor that most closely intersects the provided bounds. + static gfx::Monitor GetMonitorMatching(const gfx::Rect& match_rect); }; } // namespace gfx diff --git a/ui/gfx/screen_android.cc b/ui/gfx/screen_android.cc index 27a60c1..2d1fd91 100644 --- a/ui/gfx/screen_android.cc +++ b/ui/gfx/screen_android.cc @@ -5,13 +5,14 @@ #include "ui/gfx/screen.h" #include "base/logging.h" +#include "ui/gfx/monitor.h" namespace gfx { // static -gfx::Size Screen::GetPrimaryMonitorSize() { +gfx::Monitor Screen::GetPrimaryMonitor() { NOTIMPLEMENTED() << "crbug.com/117839 tracks implementation"; - return gfx::Size(1, 1); + return gfx::Monitor(0, gfx::Rect(0, 0, 1, 1)); } // static diff --git a/ui/gfx/screen_ash.cc b/ui/gfx/screen_ash.cc deleted file mode 100644 index 091c2b0..0000000 --- a/ui/gfx/screen_ash.cc +++ /dev/null @@ -1,104 +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/gfx/screen.h" - -#include "base/logging.h" -#include "ui/gfx/native_widget_types.h" - -namespace gfx { - -// gfx can't depend upon ash, otherwise we have circular dependencies. So, -// gfx::Screen is pluggable and Desktop plugs in the real implementation. - -// static -Screen* Screen::instance_ = NULL; - -// static -void Screen::SetInstance(Screen* screen) { - delete instance_; - instance_ = screen; -} - -// static -gfx::Point Screen::GetCursorScreenPoint() { - // TODO(erg): Figure out what to do about the Screen class. For now, I've - // added default values for when a Screen instance class isn't passed in, but - // this is the wrong thing. - if (!instance_) - return gfx::Point(); - return instance_->GetCursorScreenPointImpl(); -} - -// static -gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeWindow window) { - if (!instance_) - return gfx::Rect(0, 0, 800, 800); - return instance_->GetMonitorWorkAreaNearestWindowImpl(window); -} - -// static -gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeWindow window) { - if (!instance_) - return gfx::Rect(0, 0, 800, 800); - return instance_->GetMonitorAreaNearestWindowImpl(window); -} - -// static -gfx::Rect Screen::GetMonitorWorkAreaNearestPoint(const gfx::Point& point) { - if (!instance_) - return gfx::Rect(0, 0, 800, 800); - return instance_->GetMonitorWorkAreaNearestPointImpl(point); -} - -// static -gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) { - if (!instance_) - return gfx::Rect(0, 0, 800, 800); - return instance_->GetMonitorAreaNearestPointImpl(point); -} - -// static -gfx::Rect Screen::GetPrimaryMonitorWorkArea() { - if (!instance_) - return gfx::Rect(0, 0, 800, 800); - return instance_->GetMonitorWorkAreaNearestPoint(gfx::Point()); -} - -// static -gfx::Rect Screen::GetPrimaryMonitorBounds() { - if (!instance_) - return gfx::Rect(0, 0, 800, 800); - return instance_->GetMonitorAreaNearestPoint(gfx::Point()); -} - -// static -gfx::Rect Screen::GetMonitorWorkAreaMatching(const gfx::Rect& match_rect) { - if (!instance_) - return gfx::Rect(0, 0, 800, 800); - return instance_->GetMonitorWorkAreaNearestPoint(gfx::Point()); -} - -// static -gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { - if (!instance_) - return NULL; - return instance_->GetWindowAtCursorScreenPointImpl(); -} - -// static -gfx::Size Screen::GetPrimaryMonitorSize() { - if (!instance_) - return gfx::Size(800, 800); - return instance_->GetPrimaryMonitorSizeImpl(); -} - -// static -int Screen::GetNumMonitors() { - if (!instance_) - return 1; - return instance_->GetNumMonitorsImpl(); -} - -} // namespace gfx diff --git a/ui/gfx/screen_aura.cc b/ui/gfx/screen_aura.cc new file mode 100644 index 0000000..1631095 --- /dev/null +++ b/ui/gfx/screen_aura.cc @@ -0,0 +1,67 @@ +// 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/gfx/screen.h" + +#include "base/logging.h" +#include "ui/gfx/monitor.h" +#include "ui/gfx/native_widget_types.h" +#include "ui/gfx/screen_impl.h" + +namespace gfx { + +// gfx can't depend upon aura, otherwise we have circular dependencies. So, +// gfx::Screen is pluggable and Desktop plugs in the real implementation. +namespace { +ScreenImpl* g_instance_ = NULL; +} + +// static +void Screen::SetInstance(ScreenImpl* screen) { + delete g_instance_; + g_instance_ = screen; +} + +#if defined(USE_ASH) +// TODO(oshima): Implement ScreenImpl for Linux/aura and remove this +// ifdef. + +// static +Point Screen::GetCursorScreenPoint() { + return g_instance_->GetCursorScreenPoint(); +} + +// static +NativeWindow Screen::GetWindowAtCursorScreenPoint() { + return g_instance_->GetWindowAtCursorScreenPoint(); +} + +// static +int Screen::GetNumMonitors() { + return g_instance_->GetNumMonitors(); +} + +// static +Monitor Screen::GetMonitorNearestWindow(NativeView window) { + return g_instance_->GetMonitorNearestWindow(window); +} + +// static +Monitor Screen::GetMonitorNearestPoint(const Point& point) { + return g_instance_->GetMonitorNearestPoint(point); +} + +// static +Monitor Screen::GetPrimaryMonitor() { + return g_instance_->GetPrimaryMonitor(); +} + +// static +Monitor Screen::GetMonitorMatching(const gfx::Rect& match_rect) { + return g_instance_->GetMonitorNearestPoint(match_rect.CenterPoint()); +} + +#endif + +} // namespace gfx diff --git a/ui/gfx/screen_aurax11.cc b/ui/gfx/screen_aurax11.cc index 03b4e4e..0f16bfe 100644 --- a/ui/gfx/screen_aurax11.cc +++ b/ui/gfx/screen_aurax11.cc @@ -12,10 +12,21 @@ #if !defined(USE_ASH) namespace gfx { +namespace { +gfx::Size Screen::GetPrimaryMonitorSize() { + ::Display* display = ui::GetXDisplay(); + ::Screen* screen = DefaultScreenOfDisplay(display); + int width = WidthOfScreen(screen); + int height = HeightOfScreen(screen); + + return gfx::Size(width, height); +} +} // namespace // TODO(piman,erg): This file needs to be rewritten by someone who understands // the subtlety of X11. That is not erg. +// static gfx::Point Screen::GetCursorScreenPoint() { Display* display = ui::GetXDisplay(); @@ -36,67 +47,45 @@ gfx::Point Screen::GetCursorScreenPoint() { return gfx::Point(root_x, root_y); } -gfx::Rect Screen::GetMonitorWorkAreaNearestWindow( - gfx::NativeView view) { - // TODO(erg): There was a comment about how we shouldn't use _NET_WORKAREA - // here by danakj@. - return GetMonitorAreaNearestWindow(view); -} - -gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeView view) { - // TODO(erg): Yet another stub. - return GetPrimaryMonitorBounds(); -} - // static -gfx::Rect Screen::GetMonitorWorkAreaNearestPoint(const gfx::Point& point) { - // TODO(jamiewalch): Restrict this to the work area of the monitor. - return GetMonitorAreaNearestPoint(point); +gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { + // TODO(erg): I have no clue. May need collaboration with + // RootWindowHostLinux? + return NULL; } // static -gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) { - // TODO(erg): gdk actually has a description for this! We can implement this - // one. - return GetPrimaryMonitorBounds(); -} - -gfx::Rect Screen::GetPrimaryMonitorWorkArea() { - // TODO(erg): Also needs a real implementation. - return gfx::Rect(gfx::Point(0, 0), GetPrimaryMonitorSize()); -} - -gfx::Rect Screen::GetPrimaryMonitorBounds() { - // TODO(erg): Probably needs to be smarter? - return gfx::Rect(gfx::Point(0, 0), GetPrimaryMonitorSize()); +int Screen::GetNumMonitors() { + // TODO(erg): Figure this out with oshima or piman because I have no clue + // about the Xinerama implications here. + return 1; } -gfx::Rect Screen::GetMonitorWorkAreaMatching(const gfx::Rect& match_rect) { +// static +Monitor Screen::GetMonitorNearestWindow(NativeWindow window) { // TODO(erg): We need to eventually support multiple monitors. - return GetPrimaryMonitorWorkArea(); + return GetPrimaryMonitor(); } -gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { - // TODO(erg): I have no clue. May need collaboration with - // RootWindowHostLinux? - return NULL; +// static +Monitor Screen::GetMonitorNearestPoint(const Point& point) { + // TODO(erg): We need to eventually support multiple monitors. + return GetPrimaryMonitor(); } -gfx::Size Screen::GetPrimaryMonitorSize() { - ::Display* display = ui::GetXDisplay(); - ::Screen* screen = DefaultScreenOfDisplay(display); - int width = WidthOfScreen(screen); - int height = HeightOfScreen(screen); - - return gfx::Size(width, height); +// static +Monitor Screen::GetPrimaryMonitor() { + // TODO(erg): There was a comment about how we shouldn't use _NET_WORKAREA + // for work area by danakj@. + // TODO(jamiewalch): Restrict work area to the actual work area of + // the monitor. + return Monitor(gfx::Rect(GetPrimaryMonitorSize())); } -int Screen::GetNumMonitors() { - // TODO(erg): Figure this out with oshima or piman because I have no clue - // about the Xinerama implications here. - return 1; +// static +Monitor Screen::GetMonitorMatching(const gfx::Rect& match_rect) { + return GetPrimaryMonitor(); } } // namespace gfx - #endif // !defined(USE_ASH) diff --git a/ui/gfx/screen_gtk.cc b/ui/gfx/screen_gtk.cc index 1607cc8..1ae8261 100644 --- a/ui/gfx/screen_gtk.cc +++ b/ui/gfx/screen_gtk.cc @@ -8,6 +8,7 @@ #include <gtk/gtk.h> #include "base/logging.h" +#include "ui/gfx/monitor.h" namespace { @@ -46,33 +47,14 @@ bool GetScreenWorkArea(gfx::Rect* out_rect) { return true; } -} // namespace - -namespace gfx { - -// static -gfx::Point Screen::GetCursorScreenPoint() { - gint x, y; - gdk_display_get_pointer(gdk_display_get_default(), NULL, &x, &y, NULL); - return gfx::Point(x, y); -} - -// static -gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeView view) { - // Do not use the _NET_WORKAREA here, this is supposed to be an area on a - // specific monitor, and _NET_WORKAREA is a hint from the WM that generally - // spans across all monitors. This would make the work area larger than the - // monitor. - // TODO(danakj) This is a work-around as there is no standard way to get this - // area, but it is a rect that we should be computing. The standard means - // to compute this rect would be to watch all windows with - // _NET_WM_STRUT(_PARTIAL) hints, and subtract their space from the physical - // area of the monitor to construct a work area. - return GetMonitorAreaNearestWindow(view); +gfx::Rect NativePrimaryMonitorBounds() { + GdkScreen* screen = gdk_screen_get_default(); + GdkRectangle rect; + gdk_screen_get_monitor_geometry(screen, 0, &rect); + return gfx::Rect(rect); } -// static -gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeView view) { +gfx::Rect GetMonitorAreaNearestWindow(gfx::NativeView view) { GdkScreen* screen = gdk_screen_get_default(); gint monitor_num = 0; if (view) { @@ -89,43 +71,15 @@ gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeView view) { return gfx::Rect(bounds); } -// static -gfx::Rect Screen::GetMonitorWorkAreaNearestPoint(const gfx::Point& point) { - // TODO(jamiewalch): Restrict this to the work area of the monitor. - return GetMonitorAreaNearestPoint(point); -} - -// static -gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) { - GdkScreen* screen = gdk_screen_get_default(); - gint monitor = gdk_screen_get_monitor_at_point(screen, point.x(), point.y()); - GdkRectangle bounds; - gdk_screen_get_monitor_geometry(screen, monitor, &bounds); - return gfx::Rect(bounds); -} - -// static -gfx::Rect Screen::GetPrimaryMonitorWorkArea() { - gfx::Rect rect; - if (GetScreenWorkArea(&rect)) - return rect.Intersect(GetPrimaryMonitorBounds()); - - // Return the best we've got. - return GetPrimaryMonitorBounds(); -} +} // namespace -// static -gfx::Rect Screen::GetPrimaryMonitorBounds() { - GdkScreen* screen = gdk_screen_get_default(); - GdkRectangle rect; - gdk_screen_get_monitor_geometry(screen, 0, &rect); - return gfx::Rect(rect); -} +namespace gfx { // static -gfx::Rect Screen::GetMonitorWorkAreaMatching(const gfx::Rect& match_rect) { - // TODO(thestig) Implement multi-monitor support. - return GetPrimaryMonitorWorkArea(); +gfx::Point Screen::GetCursorScreenPoint() { + gint x, y; + gdk_display_get_pointer(gdk_display_get_default(), NULL, &x, &y, NULL); + return gfx::Point(x, y); } // static @@ -144,9 +98,50 @@ gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { } // static -gfx::Size Screen::GetPrimaryMonitorSize() { +gfx::Monitor Screen::GetMonitorNearestWindow(gfx::NativeView view) { + gfx::Rect bounds = GetMonitorAreaNearestWindow(view); + // Do not use the _NET_WORKAREA here, this is supposed to be an area on a + // specific monitor, and _NET_WORKAREA is a hint from the WM that generally + // spans across all monitors. This would make the work area larger than the + // monitor. + // TODO(danakj) This is a work-around as there is no standard way to get this + // area, but it is a rect that we should be computing. The standard means + // to compute this rect would be to watch all windows with + // _NET_WM_STRUT(_PARTIAL) hints, and subtract their space from the physical + // area of the monitor to construct a work area. + // TODO(oshima): Implement ID and Observer. + return gfx::Monitor(0, bounds); +} + +// static +gfx::Monitor Screen::GetMonitorNearestPoint(const gfx::Point& point) { GdkScreen* screen = gdk_screen_get_default(); - return gfx::Size(gdk_screen_get_width(screen), gdk_screen_get_height(screen)); + gint monitor = gdk_screen_get_monitor_at_point(screen, point.x(), point.y()); + GdkRectangle bounds; + gdk_screen_get_monitor_geometry(screen, monitor, &bounds); + // TODO(oshima): Implement ID and Observer. + return gfx::Monitor(0, gfx::Rect(bounds)); +} + +// static +gfx::Monitor Screen::GetPrimaryMonitor() { + gfx::Rect bounds = NativePrimaryMonitorBounds(); + // TODO(oshima): Implement ID and Observer. + gfx::Monitor monitor(0, bounds); + gfx::Rect rect; + if (GetScreenWorkArea(&rect)) { + monitor.set_work_area(rect.Intersect(bounds)); + } else { + // Return the best we've got. + monitor.set_work_area(bounds); + } + return monitor; +} + +// static +gfx::Monitor Screen::GetMonitorMatching(const gfx::Rect& match_rect) { + // TODO(thestig) Implement multi-monitor support. + return GetPrimaryMonitor(); } // static diff --git a/ui/gfx/screen_impl.h b/ui/gfx/screen_impl.h new file mode 100644 index 0000000..2511541 --- /dev/null +++ b/ui/gfx/screen_impl.h @@ -0,0 +1,33 @@ +// 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_GFX_SCREEN_IMPL_H_ +#define UI_GFX_SCREEN_IMPL_H_ +#pragma once + +#include "ui/gfx/native_widget_types.h" +#include "ui/gfx/monitor.h" +#include "ui/gfx/point.h" + +namespace gfx { + +// A class that provides |gfx::Screen|'s implementation on aura. +class UI_EXPORT ScreenImpl { + public: + virtual ~ScreenImpl() {} + + virtual gfx::Point GetCursorScreenPoint() = 0; + virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() = 0; + + virtual int GetNumMonitors() = 0; + virtual gfx::Monitor GetMonitorNearestWindow( + gfx::NativeView window) const = 0; + virtual gfx::Monitor GetMonitorNearestPoint( + const gfx::Point& point) const = 0; + virtual gfx::Monitor GetPrimaryMonitor() const = 0; +}; + +} // namespace gfx + +#endif // UI_GFX_SCREEN_IMPL_H_ diff --git a/ui/gfx/screen_mac.mm b/ui/gfx/screen_mac.mm index a3b7306d..64dbf86 100644 --- a/ui/gfx/screen_mac.mm +++ b/ui/gfx/screen_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -7,6 +7,9 @@ #import <ApplicationServices/ApplicationServices.h> #import <Cocoa/Cocoa.h> +#include "base/logging.h" +#include "ui/gfx/monitor.h" + namespace { gfx::Rect ConvertCoordinateSystem(NSRect ns_rect) { @@ -38,6 +41,25 @@ NSScreen* GetMatchingScreen(const gfx::Rect& match_rect) { return max_screen; } +gfx::Monitor GetMonitorForScreen(NSScreen* screen, bool is_primary) { + NSRect frame = [screen frame]; + // TODO(oshima): Implement ID and Observer. + gfx::Monitor monitor(0, gfx::Rect(NSRectToCGRect(frame))); + + NSRect visible_frame = [screen visibleFrame]; + + // Convert work area's coordinate systems. + if (is_primary) { + gfx::Rect work_area = gfx::Rect(NSRectToCGRect(visible_frame)); + work_area.set_y(frame.size.height - visible_frame.origin.y - + visible_frame.size.height); + monitor.set_work_area(work_area); + } else { + monitor.set_work_area(ConvertCoordinateSystem(visible_frame)); + } + return monitor; +} + } // namespace namespace gfx { @@ -52,39 +74,24 @@ gfx::Point Screen::GetCursorScreenPoint() { } // static -gfx::Rect Screen::GetPrimaryMonitorWorkArea() { +gfx::Monitor Screen::GetPrimaryMonitor() { // Primary monitor is defined as the monitor with the menubar, // which is always at index 0. NSScreen* primary = [[NSScreen screens] objectAtIndex:0]; - NSRect frame = [primary frame]; - NSRect visible_frame = [primary visibleFrame]; + gfx::Monitor monitor = GetMonitorForScreen(primary, true /* primary */); - // Convert coordinate systems. - gfx::Rect rect = gfx::Rect(NSRectToCGRect(visible_frame)); - rect.set_y(frame.size.height - visible_frame.origin.y - - visible_frame.size.height); - return rect; -} - -// static -gfx::Rect Screen::GetPrimaryMonitorBounds() { - // Primary monitor is defined as the monitor with the menubar, - // which is always at index 0. - NSScreen* primary = [[NSScreen screens] objectAtIndex:0]; - return gfx::Rect(NSRectToCGRect([primary frame])); + CGDirectDisplayID main_display = CGMainDisplayID(); + CHECK_EQ(static_cast<const int>(CGDisplayPixelsWide(main_display)), + monitor.size().width()); + CHECK_EQ(static_cast<const int>(CGDisplayPixelsHigh(main_display)), + monitor.size().height()); + return monitor; } // static -gfx::Rect Screen::GetMonitorWorkAreaMatching(const gfx::Rect& match_rect) { +gfx::Monitor Screen::GetMonitorMatching(const gfx::Rect& match_rect) { NSScreen* match_screen = GetMatchingScreen(match_rect); - return ConvertCoordinateSystem([match_screen visibleFrame]); -} - -// static -gfx::Size Screen::GetPrimaryMonitorSize() { - CGDirectDisplayID main_display = CGMainDisplayID(); - return gfx::Size(CGDisplayPixelsWide(main_display), - CGDisplayPixelsHigh(main_display)); + return GetMonitorForScreen(match_screen, false /* may not be primary */); } // static diff --git a/ui/gfx/screen_unittest.cc b/ui/gfx/screen_unittest.cc index 6d1f9f2..5406697 100644 --- a/ui/gfx/screen_unittest.cc +++ b/ui/gfx/screen_unittest.cc @@ -1,17 +1,18 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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 "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/screen.h" +#include "testing/gtest/include/gtest/gtest.h" + namespace { typedef testing::Test ScreenTest; TEST_F(ScreenTest, GetPrimaryMonitorSize) { // We aren't actually testing that it's correct, just that it's sane. - const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize(); + const gfx::Size size = gfx::Screen::GetPrimaryMonitor().size(); EXPECT_GE(size.width(), 1); EXPECT_GE(size.height(), 1); } diff --git a/ui/gfx/screen_win.cc b/ui/gfx/screen_win.cc index ea74c82..4487c61 100644 --- a/ui/gfx/screen_win.cc +++ b/ui/gfx/screen_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -6,6 +6,9 @@ #include <windows.h> +#include "base/logging.h" +#include "ui/gfx/monitor.h" + namespace { MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor) { @@ -15,6 +18,13 @@ MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor) { return monitor_info; } +gfx::Monitor GetMonitor(MONITORINFO& monitor_info) { + // TODO(oshima): Implement ID and Observer. + gfx::Monitor monitor(0, gfx::Rect(monitor_info.rcMonitor)); + monitor.set_work_area(gfx::Rect(monitor_info.rcWork)); + return monitor; +} + } // namespace namespace gfx { @@ -27,79 +37,52 @@ gfx::Point Screen::GetCursorScreenPoint() { } // static -gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeWindow window) { - MONITORINFO monitor_info; - monitor_info.cbSize = sizeof(monitor_info); - GetMonitorInfo(MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST), - &monitor_info); - return gfx::Rect(monitor_info.rcWork); +gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { + POINT location; + return GetCursorPos(&location) ? WindowFromPoint(location) : NULL; } // static -gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeWindow window) { +int Screen::GetNumMonitors() { + return GetSystemMetrics(SM_CMONITORS); +} + +// static +gfx::Monitor Screen::GetMonitorNearestWindow(gfx::NativeWindow window) { MONITORINFO monitor_info; monitor_info.cbSize = sizeof(monitor_info); GetMonitorInfo(MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST), &monitor_info); - return gfx::Rect(monitor_info.rcMonitor); + return GetMonitor(monitor_info); } -static gfx::Rect GetMonitorAreaOrWorkAreaNearestPoint(const gfx::Point& point, - bool work_area) { +// static +gfx::Monitor Screen::GetMonitorNearestPoint(const gfx::Point& point) { POINT initial_loc = { point.x(), point.y() }; HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); MONITORINFO mi = {0}; mi.cbSize = sizeof(mi); if (monitor && GetMonitorInfo(monitor, &mi)) - return gfx::Rect(work_area ? mi.rcWork : mi.rcMonitor); - return gfx::Rect(); + return GetMonitor(mi); + return gfx::Monitor(); } // static -gfx::Rect Screen::GetMonitorWorkAreaNearestPoint(const gfx::Point& point) { - return GetMonitorAreaOrWorkAreaNearestPoint(point, true); +gfx::Monitor Screen::GetPrimaryMonitor() { + MONITORINFO mi = GetMonitorInfoForMonitor( + MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY)); + gfx::Monitor monitor = GetMonitor(mi); + DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), monitor.size().width()); + DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), monitor.size().height()); + return monitor; } // static -gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) { - return GetMonitorAreaOrWorkAreaNearestPoint(point, false); -} - -// static -gfx::Rect Screen::GetPrimaryMonitorWorkArea() { - return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL, - MONITOR_DEFAULTTOPRIMARY)).rcWork); -} - -// static -gfx::Rect Screen::GetPrimaryMonitorBounds() { - return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL, - MONITOR_DEFAULTTOPRIMARY)).rcMonitor); -} - -// static -gfx::Rect Screen::GetMonitorWorkAreaMatching(const gfx::Rect& match_rect) { +gfx::Monitor Screen::GetMonitorMatching(const gfx::Rect& match_rect) { RECT other_bounds_rect = match_rect.ToRECT(); MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( &other_bounds_rect, MONITOR_DEFAULTTONEAREST)); - return gfx::Rect(monitor_info.rcWork); -} - -// static -gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { - POINT location; - return GetCursorPos(&location) ? WindowFromPoint(location) : NULL; -} - -// static -gfx::Size Screen::GetPrimaryMonitorSize() { - return gfx::Size(GetSystemMetrics(SM_CXSCREEN), - GetSystemMetrics(SM_CYSCREEN)); -} - -// static -int Screen::GetNumMonitors() { - return GetSystemMetrics(SM_CMONITORS); + return GetMonitor(monitor_info); } } // namespace gfx @@ -328,6 +328,8 @@ 'gfx/mac/nsimage_cache.h', 'gfx/mac/nsimage_cache.mm', 'gfx/mac/scoped_ns_disable_screen_updates.h', + 'gfx/monitor.cc', + 'gfx/monitor.h', 'gfx/native_theme.cc', 'gfx/native_theme.h', 'gfx/native_theme_android.cc', @@ -371,9 +373,10 @@ 'gfx/render_text_win.h', 'gfx/screen.h', 'gfx/screen_android.cc', - 'gfx/screen_ash.cc', + 'gfx/screen_aura.cc', 'gfx/screen_aurax11.cc', 'gfx/screen_gtk.cc', + 'gfx/screen_impl.h', 'gfx/screen_mac.mm', 'gfx/screen_win.cc', 'gfx/scoped_cg_context_save_gstate_mac.h', diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi index d68c9c7..878127e 100644 --- a/ui/ui_unittests.gypi +++ b/ui/ui_unittests.gypi @@ -89,6 +89,7 @@ 'gfx/image/image_unittest_util.cc', 'gfx/image/image_unittest_util.h', 'gfx/insets_unittest.cc', + 'gfx/monitor_unittest.cc', 'gfx/rect_unittest.cc', 'gfx/screen_unittest.cc', 'gfx/shadow_value_unittest.cc', diff --git a/ui/views/bubble/bubble_frame_view.cc b/ui/views/bubble/bubble_frame_view.cc index 176c010..ab88cba 100644 --- a/ui/views/bubble/bubble_frame_view.cc +++ b/ui/views/bubble/bubble_frame_view.cc @@ -97,7 +97,7 @@ gfx::Rect BubbleFrameView::GetUpdatedWindowBounds(const gfx::Rect& anchor_rect, } gfx::Rect BubbleFrameView::GetMonitorBounds(const gfx::Rect& rect) { - return gfx::Screen::GetMonitorWorkAreaNearestPoint(rect.CenterPoint()); + return gfx::Screen::GetMonitorNearestPoint(rect.CenterPoint()).work_area(); } void BubbleFrameView::MirrorArrowIfOffScreen( diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc index 4dd0f06..8a4e112 100644 --- a/ui/views/controls/menu/menu_controller.cc +++ b/ui/views/controls/menu/menu_controller.cc @@ -1072,14 +1072,14 @@ void MenuController::UpdateInitialLocation( // Calculate the bounds of the monitor we'll show menus on. Do this once to // avoid repeated system queries for the info. - pending_state_.monitor_bounds = gfx::Screen::GetMonitorWorkAreaNearestPoint( - bounds.origin()); + pending_state_.monitor_bounds = gfx::Screen::GetMonitorNearestPoint( + bounds.origin()).work_area(); #if defined(USE_ASH) if (!pending_state_.monitor_bounds.Contains(bounds)) { // Use the monitor area if the work area doesn't contain the bounds. This // handles showing a menu from the launcher. gfx::Rect monitor_area = - gfx::Screen::GetMonitorAreaNearestPoint(bounds.origin()); + gfx::Screen::GetMonitorNearestPoint(bounds.origin()).bounds(); if (monitor_area.Contains(bounds)) pending_state_.monitor_bounds = monitor_area; } diff --git a/ui/views/test/views_test_base.cc b/ui/views/test/views_test_base.cc index 996582f..00a7cb3 100644 --- a/ui/views/test/views_test_base.cc +++ b/ui/views/test/views_test_base.cc @@ -4,10 +4,6 @@ #include "ui/views/test/views_test_base.h" -#if defined(USE_ASH) -#include "ui/aura/test/test_screen.h" -#endif - #if defined(USE_AURA) #include "base/compiler_specific.h" #include "ui/aura/client/aura_constants.h" @@ -16,8 +12,10 @@ #include "ui/aura/root_window.h" #include "ui/aura/single_monitor_manager.h" #include "ui/aura/test/test_activation_client.h" +#include "ui/aura/test/test_screen.h" #include "ui/aura/test/test_stacking_client.h" #include "ui/base/ime/input_method.h" +#include "ui/gfx/screen.h" namespace { @@ -85,9 +83,7 @@ void ViewsTestBase::SetUp() { #if defined(USE_AURA) aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); root_window_.reset(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); -#if defined(USE_ASH) gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); -#endif // USE_ASH root_window_->SetProperty( aura::client::kRootWindowInputMethodKey, test_input_method_.get()); diff --git a/ui/views/touchui/touch_selection_controller_impl.cc b/ui/views/touchui/touch_selection_controller_impl.cc index b5d5d2d..c9e9c07 100644 --- a/ui/views/touchui/touch_selection_controller_impl.cc +++ b/ui/views/touchui/touch_selection_controller_impl.cc @@ -311,7 +311,7 @@ class TouchSelectionControllerImpl::TouchContextMenuView total_width, height); gfx::Rect monitor_bounds = - gfx::Screen::GetMonitorAreaNearestPoint(position); + gfx::Screen::GetMonitorNearestPoint(position).bounds(); widget_->SetBounds(widget_bounds.AdjustToFit(monitor_bounds)); Layout(); } diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index 0b10f0ab..7b99e74 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -40,8 +40,7 @@ #endif #if defined(ENABLE_DIP) -#include "ui/aura/monitor.h" -#include "ui/aura/monitor_manager.h" +#include "ui/gfx/monitor.h" #endif namespace views { @@ -353,7 +352,8 @@ void NativeWidgetAura::CenterWindow(const gfx::Size& size) { // When centering window, we take the intersection of the host and // the parent. We assume the root window represents the visible // rect of a single screen. - gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow(window_); + gfx::Rect work_area = + gfx::Screen::GetMonitorNearestWindow(window_).work_area(); parent_bounds = parent_bounds.Intersect(work_area); // If |window_|'s transient parent's bounds are big enough to fit it, then we @@ -672,7 +672,7 @@ void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) { } gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { - return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); + return gfx::Screen::GetMonitorNearestWindow(GetNativeView()).work_area(); } void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { @@ -829,9 +829,8 @@ void NativeWidgetAura::OnCaptureLost() { void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { #if defined(ENABLE_DIP) - aura::Monitor* monitor = GetMonitor(); canvas->Save(); - float scale = monitor->GetDeviceScaleFactor(); + float scale = GetMonitorScaleFactor(); canvas->sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale)); #endif delegate_->OnNativeWidgetPaint(canvas); @@ -919,33 +918,32 @@ void NativeWidgetAura::SetInitialFocus() { } #if defined(ENABLE_DIP) -aura::Monitor* NativeWidgetAura::GetMonitor() const { - return aura::Env::GetInstance()->monitor_manager()-> - GetMonitorNearestWindow(window_); +float NativeWidgetAura::GetMonitorScaleFactor() const { + return gfx::Screen::GetMonitorNearestWindow(window_).device_scale_factor(); } gfx::Point NativeWidgetAura::ConvertPointFromMonitor( const gfx::Point& point) const { - return point.Scale(1.0f / GetMonitor()->GetDeviceScaleFactor()); + return point.Scale(1.0f / GetMonitorScaleFactor()); } gfx::Size NativeWidgetAura::ConvertSizeFromMonitor( const gfx::Size& size) const { - return size.Scale(1.0f / GetMonitor()->GetDeviceScaleFactor()); + return size.Scale(1.0f / GetMonitorScaleFactor()); } gfx::Rect NativeWidgetAura::ConvertRectFromMonitor( const gfx::Rect& rect) const { - float scale = 1.0f / GetMonitor()->GetDeviceScaleFactor(); + float scale = 1.0f / GetMonitorScaleFactor(); return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); } gfx::Size NativeWidgetAura::ConvertSizeToMonitor(const gfx::Size& size) const { - return size.Scale(GetMonitor()->GetDeviceScaleFactor()); + return size.Scale(GetMonitorScaleFactor()); } gfx::Rect NativeWidgetAura::ConvertRectToMonitor(const gfx::Rect& rect) const { - float scale = GetMonitor()->GetDeviceScaleFactor(); + float scale = GetMonitorScaleFactor(); return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); } #endif diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h index 388da85..af51428 100644 --- a/ui/views/widget/native_widget_aura.h +++ b/ui/views/widget/native_widget_aura.h @@ -168,11 +168,12 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate, void SetInitialFocus(); #if defined(ENABLE_DIP) - // Returns the monitor in which this widget is placed. - aura::Monitor* GetMonitor() const; + // Returns the scale factor of the monitor in which this widget is placed. + float GetMonitorScaleFactor() const; // Utility functions that convert point/size/rect between // the monitor's coordinate system and the widget's coordinate system. + // TODO(oshima): Remove these once aura supports DIP coordinate system. gfx::Point ConvertPointFromMonitor(const gfx::Point& point) const; gfx::Size ConvertSizeFromMonitor(const gfx::Size& size) const; gfx::Rect ConvertRectFromMonitor(const gfx::Rect& rect) const; diff --git a/ui/views/widget/native_widget_aura_unittest.cc b/ui/views/widget/native_widget_aura_unittest.cc index 51d4bc9..84fc2aa 100644 --- a/ui/views/widget/native_widget_aura_unittest.cc +++ b/ui/views/widget/native_widget_aura_unittest.cc @@ -13,15 +13,13 @@ #include "ui/aura/monitor_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/single_monitor_manager.h" +#include "ui/aura/test/test_screen.h" #include "ui/aura/test/test_stacking_client.h" #include "ui/aura/window.h" +#include "ui/gfx/screen.h" #include "ui/views/widget/root_view.h" #include "ui/views/widget/widget_delegate.h" -#if defined(USE_ASH) -#include "ui/aura/test/test_screen.h" -#endif - namespace views { namespace { @@ -43,9 +41,7 @@ class NativeWidgetAuraTest : public testing::Test { aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); root_window_.reset( aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); -#if defined(USE_ASH) gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); -#endif root_window_->SetBounds(gfx::Rect(0, 0, 640, 480)); root_window_->SetHostSize(gfx::Size(640, 480)); test_stacking_client_.reset( diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc index ede049e..52fd39a 100644 --- a/ui/views/widget/native_widget_win.cc +++ b/ui/views/widget/native_widget_win.cc @@ -1122,7 +1122,7 @@ void NativeWidgetWin::FocusNativeView(gfx::NativeView native_view) { } gfx::Rect NativeWidgetWin::GetWorkAreaBoundsInScreen() const { - return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); + return gfx::Screen::GetMonitorNearestWindow(GetNativeView()).work_area(); } void NativeWidgetWin::SetInactiveRenderingDisabled(bool value) { diff --git a/ui/views/widget/tooltip_manager_aura.cc b/ui/views/widget/tooltip_manager_aura.cc index 01e3e60..7a56608 100644 --- a/ui/views/widget/tooltip_manager_aura.cc +++ b/ui/views/widget/tooltip_manager_aura.cc @@ -30,7 +30,7 @@ gfx::Font TooltipManager::GetDefaultFont() { // static int TooltipManager::GetMaxWidth(int x, int y) { gfx::Rect monitor_bounds = - gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y)); + gfx::Screen::GetMonitorNearestPoint(gfx::Point(x, y)).bounds(); return (monitor_bounds.width() + 1) / 2; } diff --git a/ui/views/widget/tooltip_manager_win.cc b/ui/views/widget/tooltip_manager_win.cc index b805f17..0e5ea79 100644 --- a/ui/views/widget/tooltip_manager_win.cc +++ b/ui/views/widget/tooltip_manager_win.cc @@ -61,7 +61,7 @@ gfx::Font TooltipManager::GetDefaultFont() { // static int TooltipManager::GetMaxWidth(int x, int y) { gfx::Rect monitor_bounds = - gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y)); + gfx::Screen::GetMonitorNearestPoint(gfx::Point(x, y)).bounds(); // Allow the tooltip to be almost as wide as the screen. // Otherwise, we would truncate important text, since we're not word-wrapping // the text onto multiple lines. diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc index 3f780b7..cbde2a2 100644 --- a/ui/views/widget/widget.cc +++ b/ui/views/widget/widget.cc @@ -424,7 +424,7 @@ void Widget::CenterWindow(const gfx::Size& size) { void Widget::SetBoundsConstrained(const gfx::Rect& bounds) { gfx::Rect work_area = - gfx::Screen::GetMonitorWorkAreaNearestPoint(bounds.origin()); + gfx::Screen::GetMonitorNearestPoint(bounds.origin()).work_area(); if (work_area.IsEmpty()) { SetBounds(bounds); } else { |