Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Unified Diff: ui/views/view_unittest.cc

Issue 375693006: Snap layers in views to physical pixel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/views/view.cc ('K') | « ui/views/view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 0a4f3b69dbd4373f69c830d8da80fa421bbd4986..47817908943cb35aee0f82d06b650e8f0cf8069e 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -7,6 +7,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/rand_util.h"
#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "grit/ui_strings.h"
#include "ui/base/accelerators/accelerator.h"
@@ -3904,6 +3905,54 @@ TEST_F(ViewLayerTest, BoundsTreeMoveViewMovesBounds) {
EXPECT_EQ(1U, widget_view->last_cull_set_.count(v3));
}
+namespace {
+
+std::string ToString(const gfx::Vector2dF& vector) {
+ return base::StringPrintf("%.2f %0.2f", vector.x(), vector.y());
+}
+
+} // namespace
+
+TEST_F(ViewLayerTest, SnapLayerToPixel) {
+ View* v1 = new View;
+
+ View* v11 = new View;
+ v1->AddChildView(v11);
+
+ widget()->SetContentsView(v1);
+
+ const gfx::Size& size = GetRootLayer()->GetCompositor()->size();
+ GetRootLayer()->GetCompositor()->SetScaleAndSize(1.25f, size);
+
+ v11->SetBoundsRect(gfx::Rect(1, 1, 10, 10));
+ v1->SetBoundsRect(gfx::Rect(1, 1, 10, 10));
+ v11->SetPaintToLayer(true);
+
+ EXPECT_EQ("0.40 0.40", ToString(v11->layer()->subpixel_position_offset()));
+
+ // Creating a layer in parent should update the child view's layer offset.
+ v1->SetPaintToLayer(true);
+ EXPECT_EQ("-0.20 -0.20", ToString(v1->layer()->subpixel_position_offset()));
+ EXPECT_EQ("-0.20 -0.20", ToString(v11->layer()->subpixel_position_offset()));
+
+ // DSF change shoud get propagated and update offsets.
danakj 2014/07/15 21:11:02 should
oshima 2014/07/15 22:28:42 Done.
+ GetRootLayer()->GetCompositor()->SetScaleAndSize(1.5f, size);
+ EXPECT_EQ("0.33 0.33", ToString(v1->layer()->subpixel_position_offset()));
+ EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset()));
+
+ // Deleting parent' layer should update the child view's layer's offset.
danakj 2014/07/15 21:11:02 s/'//
oshima 2014/07/15 22:28:42 Done.
+ v1->SetPaintToLayer(false);
+ EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset()));
+
+ // Setting parent view should update the child view's layer's offset.
+ v1->SetBoundsRect(gfx::Rect(2, 2, 10, 10));
+ EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset()));
+
+ // Setting integral DSF should reset the offset.
+ GetRootLayer()->GetCompositor()->SetScaleAndSize(2.0f, size);
+ EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset()));
+}
+
TEST_F(ViewTest, FocusableAssertions) {
// View subclasses may change insets based on whether they are focusable,
// which effects the preferred size. To avoid preferred size changing around
« ui/views/view.cc ('K') | « ui/views/view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698