diff options
Diffstat (limited to 'ui')
42 files changed, 618 insertions, 610 deletions
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 { |