Commit 2487c453 authored by sadrul@chromium.org's avatar sadrul@chromium.org

views: Fix painting views with layers in RTL locale.

This fixes RTL painting in the launcher.

BUG=112070
TEST=none

Review URL: https://chromiumcodereview.appspot.com/10081037

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132409 0039d316-1c4b-4281-b951-d872f2087c98
parent bdd34454
...@@ -1179,7 +1179,7 @@ void View::CalculateOffsetToAncestorWithLayer(gfx::Point* offset, ...@@ -1179,7 +1179,7 @@ void View::CalculateOffsetToAncestorWithLayer(gfx::Point* offset,
if (!parent_) if (!parent_)
return; return;
offset->Offset(x(), y()); offset->Offset(GetMirroredX(), y());
parent_->CalculateOffsetToAncestorWithLayer(offset, layer_parent); parent_->CalculateOffsetToAncestorWithLayer(offset, layer_parent);
} }
...@@ -1187,7 +1187,7 @@ void View::MoveLayerToParent(ui::Layer* parent_layer, ...@@ -1187,7 +1187,7 @@ void View::MoveLayerToParent(ui::Layer* parent_layer,
const gfx::Point& point) { const gfx::Point& point) {
gfx::Point local_point(point); gfx::Point local_point(point);
if (parent_layer != layer()) if (parent_layer != layer())
local_point.Offset(x(), y()); local_point.Offset(GetMirroredX(), y());
if (layer() && parent_layer != layer()) { if (layer() && parent_layer != layer()) {
parent_layer->Add(layer()); parent_layer->Add(layer());
layer()->SetBounds(gfx::Rect(local_point.x(), local_point.y(), layer()->SetBounds(gfx::Rect(local_point.x(), local_point.y(),
...@@ -1222,7 +1222,7 @@ void View::UpdateChildLayerBounds(const gfx::Point& offset) { ...@@ -1222,7 +1222,7 @@ void View::UpdateChildLayerBounds(const gfx::Point& offset) {
layer()->SetBounds(gfx::Rect(offset.x(), offset.y(), width(), height())); layer()->SetBounds(gfx::Rect(offset.x(), offset.y(), width(), height()));
} else { } else {
for (int i = 0, count = child_count(); i < count; ++i) { for (int i = 0, count = child_count(); i < count; ++i) {
gfx::Point new_offset(offset.x() + child_at(i)->x(), gfx::Point new_offset(offset.x() + child_at(i)->GetMirroredX(),
offset.y() + child_at(i)->y()); offset.y() + child_at(i)->y());
child_at(i)->UpdateChildLayerBounds(new_offset); child_at(i)->UpdateChildLayerBounds(new_offset);
} }
...@@ -1637,7 +1637,7 @@ void View::BoundsChanged(const gfx::Rect& previous_bounds) { ...@@ -1637,7 +1637,7 @@ void View::BoundsChanged(const gfx::Rect& previous_bounds) {
if (parent_) { if (parent_) {
gfx::Point offset; gfx::Point offset;
parent_->CalculateOffsetToAncestorWithLayer(&offset, NULL); parent_->CalculateOffsetToAncestorWithLayer(&offset, NULL);
offset.Offset(x(), y()); offset.Offset(GetMirroredX(), y());
layer()->SetBounds(gfx::Rect(offset, size())); layer()->SetBounds(gfx::Rect(offset, size()));
} else { } else {
layer()->SetBounds(bounds_); layer()->SetBounds(bounds_);
...@@ -1809,7 +1809,7 @@ void View::UpdateParentLayer() { ...@@ -1809,7 +1809,7 @@ void View::UpdateParentLayer() {
return; return;
ui::Layer* parent_layer = NULL; ui::Layer* parent_layer = NULL;
gfx::Point offset(x(), y()); gfx::Point offset(GetMirroredX(), y());
// TODO(sad): The NULL check here for parent_ essentially is to check if this // TODO(sad): The NULL check here for parent_ essentially is to check if this
// is the RootView. Instead of doing this, this function should be made // is the RootView. Instead of doing this, this function should be made
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ui/base/accelerators/accelerator.h" #include "ui/base/accelerators/accelerator.h"
#include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/clipboard.h"
#include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/compositor/compositor.h" #include "ui/gfx/compositor/compositor.h"
...@@ -2868,6 +2869,65 @@ TEST_F(ViewLayerTest, BoundsChangeWithLayer) { ...@@ -2868,6 +2869,65 @@ TEST_F(ViewLayerTest, BoundsChangeWithLayer) {
EXPECT_EQ(gfx::Rect(30, 41, 20, 30), v2->layer()->bounds()); EXPECT_EQ(gfx::Rect(30, 41, 20, 30), v2->layer()->bounds());
} }
// Make sure layers are positioned correctly in RTL.
TEST_F(ViewLayerTest, BoundInRTL) {
std::string locale = l10n_util::GetApplicationLocale(std::string());
base::i18n::SetICUDefaultLocale("he");
View* view = new View;
widget()->SetContentsView(view);
int content_width = view->width();
// |v1| is initially not attached to anything. So its layer will have the same
// bounds as the view.
View* v1 = new View;
v1->SetPaintToLayer(true);
v1->SetBounds(10, 10, 20, 10);
EXPECT_EQ(gfx::Rect(10, 10, 20, 10),
v1->layer()->bounds());
// Once |v1| is attached to the widget, its layer will get RTL-appropriate
// bounds.
view->AddChildView(v1);
EXPECT_EQ(gfx::Rect(content_width - 30, 10, 20, 10),
v1->layer()->bounds());
gfx::Rect l1bounds = v1->layer()->bounds();
// Now attach a View to the widget first, then create a layer for it. Make
// sure the bounds are correct.
View* v2 = new View;
v2->SetBounds(50, 10, 30, 10);
EXPECT_FALSE(v2->layer());
view->AddChildView(v2);
v2->SetPaintToLayer(true);
EXPECT_EQ(gfx::Rect(content_width - 80, 10, 30, 10),
v2->layer()->bounds());
gfx::Rect l2bounds = v2->layer()->bounds();
view->SetPaintToLayer(true);
EXPECT_EQ(l1bounds, v1->layer()->bounds());
EXPECT_EQ(l2bounds, v2->layer()->bounds());
// Move one of the views. Make sure the layer is positioned correctly
// afterwards.
v1->SetBounds(v1->x() - 5, v1->y(), v1->width(), v1->height());
l1bounds.set_x(l1bounds.x() + 5);
EXPECT_EQ(l1bounds, v1->layer()->bounds());
view->SetPaintToLayer(false);
EXPECT_EQ(l1bounds, v1->layer()->bounds());
EXPECT_EQ(l2bounds, v2->layer()->bounds());
// Move a view again.
v2->SetBounds(v2->x() + 5, v2->y(), v2->width(), v2->height());
l2bounds.set_x(l2bounds.x() - 5);
EXPECT_EQ(l2bounds, v2->layer()->bounds());
// Reset locale.
base::i18n::SetICUDefaultLocale(locale);
}
// Makes sure a transform persists after toggling the visibility. // Makes sure a transform persists after toggling the visibility.
TEST_F(ViewLayerTest, ToggleVisibilityWithTransform) { TEST_F(ViewLayerTest, ToggleVisibilityWithTransform) {
View* view = new View; View* view = new View;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment