diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-27 23:33:48 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-27 23:33:48 +0000 |
commit | 3f6ffb8f5a4a78d63a53526c220e74a500fa8eba (patch) | |
tree | d07b13f007134878d268db46087f80c19dd8c088 /ui/gfx | |
parent | 084d97a144cba94376a578190839aa96ddb7d78c (diff) | |
download | chromium_src-3f6ffb8f5a4a78d63a53526c220e74a500fa8eba.zip chromium_src-3f6ffb8f5a4a78d63a53526c220e74a500fa8eba.tar.gz chromium_src-3f6ffb8f5a4a78d63a53526c220e74a500fa8eba.tar.bz2 |
This change makes Aura/Views to use DIP, while keeping layer to use Pixels. This allow chrome/ash to run on high density screen in High Density Incompatible mode (everything scaled to 2x), except for web contents.
I put this behind ENABLE_DIP to avoid regression. I'll make it runtime flag next week when we get render working.
BUG=114666
TEST=manual: run with --aura-host-window-size=1000x800*2.
Review URL: https://chromiumcodereview.appspot.com/10081011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134391 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/insets.h | 11 | ||||
-rw-r--r-- | ui/gfx/monitor.cc | 49 | ||||
-rw-r--r-- | ui/gfx/monitor.h | 41 | ||||
-rw-r--r-- | ui/gfx/monitor_unittest.cc | 34 | ||||
-rw-r--r-- | ui/gfx/rect_base.h | 17 |
5 files changed, 123 insertions, 29 deletions
diff --git a/ui/gfx/insets.h b/ui/gfx/insets.h index d9d7ad8..7c09f61 100644 --- a/ui/gfx/insets.h +++ b/ui/gfx/insets.h @@ -53,6 +53,17 @@ class UI_EXPORT Insets { // top and bottom insets. int height() const { return top_ + bottom_; } + Insets Scale(float scale) const { + return Scale(scale, scale); + } + + Insets Scale(float x_scale, float y_scale) const { + return Insets(static_cast<int>(top_ * y_scale), + static_cast<int>(left_ * x_scale), + static_cast<int>(bottom_ * y_scale), + static_cast<int>(right_ * x_scale)); + } + // Returns true if the insets are empty. bool empty() const { return width() == 0 && height() == 0; } diff --git a/ui/gfx/monitor.cc b/ui/gfx/monitor.cc index 8e56e0f..242abce 100644 --- a/ui/gfx/monitor.cc +++ b/ui/gfx/monitor.cc @@ -5,6 +5,7 @@ #include "ui/gfx/monitor.h" #include "ui/gfx/insets.h" +#include "base/stringprintf.h" namespace gfx { @@ -19,27 +20,55 @@ Monitor::Monitor(int id, const gfx::Rect& bounds) bounds_(bounds), work_area_(bounds), device_scale_factor_(1.0) { +#if defined(USE_ASH) + SetScaleAndBounds(device_scale_factor_, bounds); +#endif } 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::SetScaleAndBounds( + float device_scale_factor, + const gfx::Rect& bounds_in_pixel) { + Insets insets = bounds_.InsetsFrom(work_area_); + device_scale_factor_ = device_scale_factor; +#if defined(USE_ASH) + bounds_in_pixel_ = bounds_in_pixel; +#endif + // 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. +#if defined(ENABLE_DIP) + bounds_ = gfx::Rect( + bounds_in_pixel.size().Scale(1.0f / device_scale_factor_)); +#else + bounds_ = gfx::Rect(bounds_in_pixel.size()); +#endif + UpdateWorkAreaFromInsets(insets); } -void Monitor::SetSizeAndUpdateWorkArea(const gfx::Size& size) { - SetBoundsAndUpdateWorkArea(gfx::Rect(bounds_.origin(), size)); +void Monitor::SetSize(const gfx::Size& size_in_pixel) { + SetScaleAndBounds( + device_scale_factor_, +#if defined(USE_ASH) + gfx::Rect(bounds_in_pixel_.origin(), size_in_pixel)); +#else + gfx::Rect(bounds_.origin(), size_in_pixel)); +#endif } -void Monitor::UpdateWorkAreaWithInsets(const gfx::Insets& insets) { +void Monitor::UpdateWorkAreaFromInsets(const gfx::Insets& insets) { work_area_ = bounds_; work_area_.Inset(insets); } +std::string Monitor::ToString() const { + return base::StringPrintf("Monitor[%d] bounds=%s, workarea=%s, scale=%f", + id_, + bounds_.ToString().c_str(), + work_area_.ToString().c_str(), + device_scale_factor_); +} + } // namespace gfx diff --git a/ui/gfx/monitor.h b/ui/gfx/monitor.h index 3110acd..f9bf86c 100644 --- a/ui/gfx/monitor.h +++ b/ui/gfx/monitor.h @@ -14,12 +14,10 @@ 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. +// system. With ENABLE_DIP macro (which is enabled with enable_dip=1 +// gyp flag), |bounds()| and |work_area| will return values in DIP +// coordinate system, not in backing pixels. +// TODO(oshima): Update the comment when ENABLE_DIP macro is removed. class UI_EXPORT Monitor { public: // Creates a monitor with invalid id(-1) as default. @@ -53,21 +51,38 @@ class UI_EXPORT Monitor { 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 device scale factor and monitor bounds in pixel. This + // updates the work are using the same insets between old bounds and + // work area. + void SetScaleAndBounds(float device_scale_factor, + const gfx::Rect& bounds_in_pixel); - // Sets the monitor size and updates the work are using the same insets + // Sets the monitor's size. This updates the work area using the same insets // between old bounds and work area. - void SetSizeAndUpdateWorkArea(const gfx::Size& size); + void SetSize(const gfx::Size& size_in_pixel); + + // Computes and updates the monitor's work are using + // |work_area_insets| and the bounds. + void UpdateWorkAreaFromInsets(const gfx::Insets& work_area_insets); + +#if defined(USE_ASH) + // TODO(oshima): |bounds()| on ash is not screen's coordinate and + // this is an workaround for this. This will be removed when ash + // has true multi monitor support. crbug.com/119268. + // Returns the monitor's bounds in pixel coordinates. + const Rect& bounds_in_pixel() const { return bounds_in_pixel_; } +#endif - // Computes and updates the monitor's work are using insets and the bounds. - void UpdateWorkAreaWithInsets(const gfx::Insets& work_area_insets); + // Returns a string representation of the monitor; + std::string ToString() const; private: int id_; Rect bounds_; Rect work_area_; +#if defined(USE_ASH) + Rect bounds_in_pixel_; +#endif float device_scale_factor_; }; diff --git a/ui/gfx/monitor_unittest.cc b/ui/gfx/monitor_unittest.cc index 24f179b..a6f8c05 100644 --- a/ui/gfx/monitor_unittest.cc +++ b/ui/gfx/monitor_unittest.cc @@ -11,19 +11,41 @@ namespace { TEST(MonitorTest, WorkArea) { gfx::Monitor monitor(0, gfx::Rect(0, 0, 100, 100)); + EXPECT_EQ("0,0 100x100", monitor.bounds().ToString()); EXPECT_EQ("0,0 100x100", monitor.work_area().ToString()); monitor.set_work_area(gfx::Rect(3, 4, 90, 80)); + EXPECT_EQ("0,0 100x100", monitor.bounds().ToString()); 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.SetScaleAndBounds(1.0f, gfx::Rect(10, 20, 50, 50)); + EXPECT_EQ("0,0 50x50", monitor.bounds().ToString()); + EXPECT_EQ("3,4 40x30", monitor.work_area().ToString()); - monitor.SetSizeAndUpdateWorkArea(gfx::Size(200, 200)); - EXPECT_EQ("13,24 190x180", monitor.work_area().ToString()); + monitor.SetSize(gfx::Size(200, 200)); + EXPECT_EQ("3,4 190x180", monitor.work_area().ToString()); - monitor.UpdateWorkAreaWithInsets(gfx::Insets(3, 4, 5, 6)); - EXPECT_EQ("14,23 190x192", monitor.work_area().ToString()); + monitor.UpdateWorkAreaFromInsets(gfx::Insets(3, 4, 5, 6)); + EXPECT_EQ("4,3 190x192", monitor.work_area().ToString()); } +#if defined(ENABLE_DIP) +TEST(MonitorTest, Scale) { + gfx::Monitor monitor(0, gfx::Rect(0, 0, 100, 100)); + monitor.set_work_area(gfx::Rect(10, 10, 80, 80)); + EXPECT_EQ("0,0 100x100", monitor.bounds().ToString()); + EXPECT_EQ("10,10 80x80", monitor.work_area().ToString()); + + // Scale it back to 2x + monitor.SetScaleAndBounds(2.0f, gfx::Rect(0, 0, 140, 140)); + EXPECT_EQ("0,0 70x70", monitor.bounds().ToString()); + EXPECT_EQ("10,10 50x50", monitor.work_area().ToString()); + + // Scale it back to 1x + monitor.SetScaleAndBounds(1.0f, gfx::Rect(0, 0, 100, 100)); + EXPECT_EQ("0,0 100x100", monitor.bounds().ToString()); + EXPECT_EQ("10,10 80x80", monitor.work_area().ToString()); +} +#endif + } diff --git a/ui/gfx/rect_base.h b/ui/gfx/rect_base.h index 3a273fe2..0cb346f 100644 --- a/ui/gfx/rect_base.h +++ b/ui/gfx/rect_base.h @@ -64,6 +64,23 @@ class UI_EXPORT RectBase { Offset(point.x(), point.y()); } + /// Scales the rectangle by |scale|. + Class Scale(float scale) const { + return Scale(scale, scale); + } + + Class Scale(float x_scale, float y_scale) const { + return Class(origin_.Scale(x_scale, y_scale), + size_.Scale(x_scale, y_scale)); + } + + InsetsClass InsetsFrom(const Class& inner) const { + return InsetsClass(inner.y() - y(), + inner.x() - x(), + bottom() - inner.bottom(), + right() - inner.right()); + } + // Returns true if the area of the rectangle is zero. bool IsEmpty() const { return size_.IsEmpty(); } |