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

Side by Side Diff: ui/views/view_unittest.cc

Issue 10081037: views: Fix painting views with layers in RTL locale. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <map> 5 #include <map>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "ui/base/accelerators/accelerator.h" 12 #include "ui/base/accelerators/accelerator.h"
13 #include "ui/base/clipboard/clipboard.h" 13 #include "ui/base/clipboard/clipboard.h"
14 #include "ui/base/keycodes/keyboard_codes.h" 14 #include "ui/base/keycodes/keyboard_codes.h"
15 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/models/simple_menu_model.h" 16 #include "ui/base/models/simple_menu_model.h"
16 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/compositor/compositor.h" 18 #include "ui/gfx/compositor/compositor.h"
18 #include "ui/gfx/compositor/layer.h" 19 #include "ui/gfx/compositor/layer.h"
19 #include "ui/gfx/compositor/layer_animator.h" 20 #include "ui/gfx/compositor/layer_animator.h"
20 #include "ui/gfx/path.h" 21 #include "ui/gfx/path.h"
21 #include "ui/gfx/transform.h" 22 #include "ui/gfx/transform.h"
22 #include "ui/views/background.h" 23 #include "ui/views/background.h"
23 #include "ui/views/controls/button/button_dropdown.h" 24 #include "ui/views/controls/button/button_dropdown.h"
24 #include "ui/views/controls/button/checkbox.h" 25 #include "ui/views/controls/button/checkbox.h"
(...skipping 2837 matching lines...) Expand 10 before | Expand all | Expand 10 after
2862 // Bounds of the layer should change even if the view is not invisible. 2863 // Bounds of the layer should change even if the view is not invisible.
2863 v1->SetVisible(false); 2864 v1->SetVisible(false);
2864 v1->SetPosition(gfx::Point(20, 30)); 2865 v1->SetPosition(gfx::Point(20, 30));
2865 EXPECT_EQ(gfx::Rect(31, 42, 40, 50), v2->layer()->bounds()); 2866 EXPECT_EQ(gfx::Rect(31, 42, 40, 50), v2->layer()->bounds());
2866 2867
2867 v2->SetVisible(false); 2868 v2->SetVisible(false);
2868 v2->SetBoundsRect(gfx::Rect(10, 11, 20, 30)); 2869 v2->SetBoundsRect(gfx::Rect(10, 11, 20, 30));
2869 EXPECT_EQ(gfx::Rect(30, 41, 20, 30), v2->layer()->bounds()); 2870 EXPECT_EQ(gfx::Rect(30, 41, 20, 30), v2->layer()->bounds());
2870 } 2871 }
2871 2872
2873 // Make sure layers are positioned correctly in RTL.
2874 TEST_F(ViewLayerTest, BoundInRTL) {
2875 std::string locale = l10n_util::GetApplicationLocale("");
sky 2012/04/16 14:37:41 "" -> std::string()
2876 base::i18n::SetICUDefaultLocale("he");
2877
2878 View* view = new View;
2879 widget()->SetContentsView(view);
2880
2881 int content_width = view->width();
2882
2883 // |v1| is initially not attached to anything. So its layer will have the same
2884 // bounds as the view.
2885 View* v1 = new View;
2886 v1->SetPaintToLayer(true);
2887 v1->SetBounds(10, 10, 20, 10);
2888 EXPECT_EQ(gfx::Rect(10, 10, 20, 10),
2889 v1->layer()->bounds());
2890
2891 // Once |v1| is attached to the widget, its layer will get RTL-appropriate
2892 // bounds.
2893 view->AddChildView(v1);
2894 EXPECT_EQ(gfx::Rect(content_width - 30, 10, 20, 10),
2895 v1->layer()->bounds());
2896 gfx::Rect l1bounds = v1->layer()->bounds();
2897
2898 // Now attach a View to the widget first, then create a layer for it. Make
2899 // sure the bounds are correct.
2900 View* v2 = new View;
2901 v2->SetBounds(50, 10, 30, 10);
2902 EXPECT_FALSE(v2->layer());
2903 view->AddChildView(v2);
2904 v2->SetPaintToLayer(true);
2905 EXPECT_EQ(gfx::Rect(content_width - 80, 10, 30, 10),
2906 v2->layer()->bounds());
2907 gfx::Rect l2bounds = v2->layer()->bounds();
2908
2909 view->SetPaintToLayer(true);
2910 EXPECT_EQ(l1bounds, v1->layer()->bounds());
2911 EXPECT_EQ(l2bounds, v2->layer()->bounds());
2912
2913 // Move one of the views. Make sure the layer is positioned correctly
2914 // afterwards.
2915 v1->SetBounds(v1->x() - 5, v1->y(), v1->width(), v1->height());
2916 l1bounds.set_x(l1bounds.x() + 5);
2917 EXPECT_EQ(l1bounds, v1->layer()->bounds());
2918
2919 view->SetPaintToLayer(false);
2920 EXPECT_EQ(l1bounds, v1->layer()->bounds());
2921 EXPECT_EQ(l2bounds, v2->layer()->bounds());
2922
2923 // Move a view again.
2924 v2->SetBounds(v2->x() + 5, v2->y(), v2->width(), v2->height());
2925 l2bounds.set_x(l2bounds.x() - 5);
2926 EXPECT_EQ(l2bounds, v2->layer()->bounds());
2927
2928 // Reset locale.
2929 base::i18n::SetICUDefaultLocale(locale);
2930 }
2931
2872 // Makes sure a transform persists after toggling the visibility. 2932 // Makes sure a transform persists after toggling the visibility.
2873 TEST_F(ViewLayerTest, ToggleVisibilityWithTransform) { 2933 TEST_F(ViewLayerTest, ToggleVisibilityWithTransform) {
2874 View* view = new View; 2934 View* view = new View;
2875 ui::Transform transform; 2935 ui::Transform transform;
2876 transform.SetScale(2.0f, 2.0f); 2936 transform.SetScale(2.0f, 2.0f);
2877 view->SetTransform(transform); 2937 view->SetTransform(transform);
2878 widget()->SetContentsView(view); 2938 widget()->SetContentsView(view);
2879 EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0)); 2939 EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0));
2880 2940
2881 view->SetVisible(false); 2941 view->SetVisible(false);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
3097 3157
3098 // Move c1 to the front. The layers should have moved too. 3158 // Move c1 to the front. The layers should have moved too.
3099 content->ReorderChildView(c1, -1); 3159 content->ReorderChildView(c1, -1);
3100 EXPECT_EQ(c1->layer(), parent_layer->children()[1]); 3160 EXPECT_EQ(c1->layer(), parent_layer->children()[1]);
3101 EXPECT_EQ(c2->layer(), parent_layer->children()[0]); 3161 EXPECT_EQ(c2->layer(), parent_layer->children()[0]);
3102 } 3162 }
3103 3163
3104 #endif // USE_AURA 3164 #endif // USE_AURA
3105 3165
3106 } // namespace views 3166 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698