Commit db2f9075 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

back gesture nuge: support rtl.

Bug: 1031766
Change-Id: Ie810de835b2abccaff53bed44ea007836e7fb667
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2151245Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759771}
parent 6fb05bb3
...@@ -2370,6 +2370,9 @@ This file contains the strings for ash. ...@@ -2370,6 +2370,9 @@ This file contains the strings for ash.
<message name="IDS_ASH_BACK_GESTURE_CONTEXTUAL_NUDGE" desc="Information shown in the suggestion label for the contextual nudge of the back gesture in tablet mode"> <message name="IDS_ASH_BACK_GESTURE_CONTEXTUAL_NUDGE" desc="Information shown in the suggestion label for the contextual nudge of the back gesture in tablet mode">
Swipe from the left to go back Swipe from the left to go back
</message> </message>
<message name="IDS_ASH_BACK_GESTURE_CONTEXTUAL_NUDGE_RTL" desc="Information shown in the suggestion label for the contextual nudge of the back gesture in tablet mode in RTL language">
Swipe from the right to go back
</message>
</messages> </messages>
</release> </release>
</grit> </grit>
3fe89d379b95098c8f85967d17475bee04a9a0ae
\ No newline at end of file
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/i18n/rtl.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
...@@ -104,8 +105,15 @@ std::unique_ptr<views::Widget> CreateWidget() { ...@@ -104,8 +105,15 @@ std::unique_ptr<views::Widget> CreateWidget() {
// nudge, which may based on the conditions to show the nudge. // nudge, which may based on the conditions to show the nudge.
const gfx::Rect display_bounds = const gfx::Rect display_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
gfx::Rect widget_bounds(-kBackgroundWidth, display_bounds.y(), gfx::Rect widget_bounds;
kBackgroundWidth, display_bounds.height()); if (base::i18n::IsRTL()) {
widget_bounds = gfx::Rect(display_bounds.right(), display_bounds.y(),
kBackgroundWidth, display_bounds.height());
} else {
widget_bounds =
gfx::Rect(display_bounds.x() - kBackgroundWidth, display_bounds.y(),
kBackgroundWidth, display_bounds.height());
}
widget->SetBounds(widget_bounds); widget->SetBounds(widget_bounds);
return widget; return widget;
} }
...@@ -182,9 +190,9 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -182,9 +190,9 @@ class BackGestureContextualNudge::ContextualNudgeView
label_ = AddChildView(std::make_unique<views::Label>()); label_ = AddChildView(std::make_unique<views::Label>());
label_->SetBackgroundColor(SK_ColorTRANSPARENT); label_->SetBackgroundColor(SK_ColorTRANSPARENT);
label_->SetEnabledColor(kLabelColor); label_->SetEnabledColor(kLabelColor);
label_->SetText( label_->SetText(l10n_util::GetStringUTF16(
l10n_util::GetStringUTF16(IDS_ASH_BACK_GESTURE_CONTEXTUAL_NUDGE)); base::i18n::IsRTL() ? IDS_ASH_BACK_GESTURE_CONTEXTUAL_NUDGE_RTL
label_->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT); : IDS_ASH_BACK_GESTURE_CONTEXTUAL_NUDGE));
label_->SetLineHeight(kLabelLineHeight); label_->SetLineHeight(kLabelLineHeight);
label_->SetFontList( label_->SetFontList(
gfx::FontList().DeriveWithWeight(gfx::Font::Weight::MEDIUM)); gfx::FontList().DeriveWithWeight(gfx::Font::Weight::MEDIUM));
...@@ -195,9 +203,10 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -195,9 +203,10 @@ class BackGestureContextualNudge::ContextualNudgeView
~SuggestionView() override { StopObservingImplicitAnimations(); } ~SuggestionView() override { StopObservingImplicitAnimations(); }
void ScheduleBounceAnimation() { void ScheduleBounceAnimation() {
const bool is_rtl = base::i18n::IsRTL();
gfx::Transform transform; gfx::Transform transform;
const int x_offset = kCircleRadius - kCircleInsideScreenWidth; const int x_offset = kCircleRadius - kCircleInsideScreenWidth;
transform.Translate(-x_offset, 0); transform.Translate(is_rtl ? x_offset : -x_offset, 0);
ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
animation.AddObserver(this); animation.AddObserver(this);
animation.SetTransitionDuration(kSuggestionBounceAnimationDuration); animation.SetTransitionDuration(kSuggestionBounceAnimationDuration);
...@@ -206,7 +215,7 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -206,7 +215,7 @@ class BackGestureContextualNudge::ContextualNudgeView
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
layer()->SetTransform(transform); layer()->SetTransform(transform);
transform.Translate(x_offset, 0); transform.Translate(is_rtl ? -x_offset : x_offset, 0);
animation.SetTransitionDuration(kSuggestionBounceAnimationDuration); animation.SetTransitionDuration(kSuggestionBounceAnimationDuration);
animation.SetTweenType(gfx::Tween::EASE_IN_OUT_2); animation.SetTweenType(gfx::Tween::EASE_IN_OUT_2);
animation.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); animation.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
...@@ -231,7 +240,7 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -231,7 +240,7 @@ class BackGestureContextualNudge::ContextualNudgeView
const gfx::Rect bounds = GetLocalBounds(); const gfx::Rect bounds = GetLocalBounds();
gfx::Rect label_rect(bounds); gfx::Rect label_rect(bounds);
label_rect.ClampToCenteredSize(label_->GetPreferredSize()); label_rect.ClampToCenteredSize(label_->GetPreferredSize());
label_rect.set_x(bounds.left_center().x() + 2 * kCircleRadius + label_rect.set_x(bounds.x() + 2 * kCircleRadius +
kPaddingBetweenCircleAndLabel + kLabelCornerRadius); kPaddingBetweenCircleAndLabel + kLabelCornerRadius);
label_->SetBoundsRect(label_rect); label_->SetBoundsRect(label_rect);
} }
...@@ -251,17 +260,24 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -251,17 +260,24 @@ class BackGestureContextualNudge::ContextualNudgeView
gfx::Vector2d(0, kBackNudgeShadowOffsetY2), gfx::Vector2d(0, kBackNudgeShadowOffsetY2),
kBackNudgeShadowBlurRadius2, kBackNudgeShadowColor2)); kBackNudgeShadowBlurRadius2, kBackNudgeShadowColor2));
circle_flags.setLooper(gfx::CreateShadowDrawLooper(shadows)); circle_flags.setLooper(gfx::CreateShadowDrawLooper(shadows));
const gfx::Point left_center = GetLocalBounds().left_center(); if (base::i18n::IsRTL()) {
canvas->DrawCircle( const gfx::Point right_center = GetLocalBounds().right_center();
gfx::Point(left_center.x() + kCircleRadius, left_center.y()), canvas->DrawCircle(
kCircleRadius, circle_flags); gfx::Point(right_center.x() - kCircleRadius, right_center.y()),
kCircleRadius, circle_flags);
} else {
const gfx::Point left_center = GetLocalBounds().left_center();
canvas->DrawCircle(
gfx::Point(left_center.x() + kCircleRadius, left_center.y()),
kCircleRadius, circle_flags);
}
// Draw the black round rectangle around the text. // Draw the black round rectangle around the text.
cc::PaintFlags round_rect_flags; cc::PaintFlags round_rect_flags;
round_rect_flags.setStyle(cc::PaintFlags::kFill_Style); round_rect_flags.setStyle(cc::PaintFlags::kFill_Style);
round_rect_flags.setAntiAlias(true); round_rect_flags.setAntiAlias(true);
round_rect_flags.setColor(kLabelBackgroundColor); round_rect_flags.setColor(kLabelBackgroundColor);
gfx::Rect label_bounds(label_->bounds()); gfx::Rect label_bounds(label_->GetMirroredBounds());
label_bounds.Inset(/*horizontal=*/-kLabelCornerRadius, label_bounds.Inset(/*horizontal=*/-kLabelCornerRadius,
/*vertical=*/-kLabelTopBottomInset); /*vertical=*/-kLabelTopBottomInset);
canvas->DrawRoundRect(label_bounds, kLabelCornerRadius, round_rect_flags); canvas->DrawRoundRect(label_bounds, kLabelCornerRadius, round_rect_flags);
...@@ -290,7 +306,9 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -290,7 +306,9 @@ class BackGestureContextualNudge::ContextualNudgeView
void ScheduleOffScreenToStartPositionAnimation() { void ScheduleOffScreenToStartPositionAnimation() {
animation_stage_ = AnimationStage::kSlidingIn; animation_stage_ = AnimationStage::kSlidingIn;
gfx::Transform transform; gfx::Transform transform;
transform.Translate(kBackgroundWidth, 0); transform.Translate(base::i18n::IsRTL() ? -kBackgroundWidth + kCircleRadius
: kBackgroundWidth - kCircleRadius,
0);
ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
animation.AddObserver(this); animation.AddObserver(this);
animation.SetTransitionDuration(kNudgeShowAnimationDuration); animation.SetTransitionDuration(kNudgeShowAnimationDuration);
...@@ -302,7 +320,9 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -302,7 +320,9 @@ class BackGestureContextualNudge::ContextualNudgeView
void ScheduleStartPositionToOffScreenAnimation() { void ScheduleStartPositionToOffScreenAnimation() {
animation_stage_ = AnimationStage::kSlidingOut; animation_stage_ = AnimationStage::kSlidingOut;
gfx::Transform transform; gfx::Transform transform;
transform.Translate(-kBackgroundWidth, 0); transform.Translate(base::i18n::IsRTL() ? kBackgroundWidth - kCircleRadius
: -kBackgroundWidth + kCircleRadius,
0);
ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
animation.SetTransitionDuration(kNudgeHideAnimationDuration); animation.SetTransitionDuration(kNudgeHideAnimationDuration);
animation.SetTweenType(gfx::Tween::EASE_OUT_2); animation.SetTweenType(gfx::Tween::EASE_OUT_2);
...@@ -311,12 +331,7 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -311,12 +331,7 @@ class BackGestureContextualNudge::ContextualNudgeView
} }
// views::View: // views::View:
void Layout() override { void Layout() override { suggestion_view_->SetBoundsRect(GetLocalBounds()); }
gfx::Rect rect = GetLocalBounds();
rect.ClampToCenteredSize(gfx::Size(kBackgroundWidth, kBackgroundWidth));
rect.set_x(-kCircleRadius);
suggestion_view_->SetBoundsRect(rect);
}
// ui::ImplicitAnimationObserver: // ui::ImplicitAnimationObserver:
void OnImplicitAnimationsCompleted() override { void OnImplicitAnimationsCompleted() override {
......
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