Index: chrome/browser/ui/cocoa/location_bar/security_state_bubble_decoration.mm |
diff --git a/chrome/browser/ui/cocoa/location_bar/security_state_bubble_decoration.mm b/chrome/browser/ui/cocoa/location_bar/security_state_bubble_decoration.mm |
index 23824147629976fddb5a0816a2b0d5b6d6e242db..6e0d65ad0a7333ca836841a2cb5058baedb5bc06 100644 |
--- a/chrome/browser/ui/cocoa/location_bar/security_state_bubble_decoration.mm |
+++ b/chrome/browser/ui/cocoa/location_bar/security_state_bubble_decoration.mm |
@@ -8,6 +8,7 @@ |
#import "base/mac/mac_util.h" |
#include "base/strings/sys_string_conversions.h" |
+#include "chrome/browser/ui/cocoa/l10n_util.h" |
#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
#import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
#import "chrome/browser/ui/cocoa/themed_window.h" |
@@ -59,7 +60,7 @@ const NSTimeInterval kOutAnimationDuration = 250; |
// Transformation values at the beginning of the animation. |
const CGFloat kStartScale = 0.25; |
-const CGFloat kStartx_offset = -15.0; |
+const CGFloat kStartx_offset = 15.0; |
} // namespace |
@@ -150,7 +151,9 @@ CGFloat SecurityStateBubbleDecoration::GetWidthForSpace(CGFloat width) { |
void SecurityStateBubbleDecoration::DrawInFrame(NSRect frame, |
NSView* control_view) { |
const NSRect decoration_frame = NSInsetRect(frame, 0.0, kBackgroundYInset); |
- CGFloat text_offset = NSMinX(decoration_frame); |
+ CGFloat text_left_offset = NSMinX(decoration_frame); |
+ CGFloat text_right_offset = NSMaxX(decoration_frame); |
+ const BOOL is_rtl = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); |
if (image_) { |
// The image should fade in if we're animating in. |
CGFloat image_alpha = |
@@ -161,7 +164,12 @@ void SecurityStateBubbleDecoration::DrawInFrame(NSRect frame, |
NSRect image_rect = decoration_frame; |
image_rect.origin.y += |
std::floor((NSHeight(decoration_frame) - image_size.height) / 2.0); |
- image_rect.origin.x += kLeftSidePadding; |
+ if (is_rtl) { |
+ image_rect.origin.x = |
+ NSMaxX(decoration_frame) - image_size.width - kLeftSidePadding; |
+ } else { |
+ image_rect.origin.x += kLeftSidePadding; |
+ } |
image_rect.size = image_size; |
[image_ drawInRect:image_rect |
fromRect:NSZeroRect // Entire image |
@@ -169,7 +177,10 @@ void SecurityStateBubbleDecoration::DrawInFrame(NSRect frame, |
fraction:image_alpha |
respectFlipped:YES |
hints:nil]; |
- text_offset = NSMaxX(image_rect) + kIconLabelPadding; |
+ if (is_rtl) |
+ text_right_offset = NSMinX(image_rect) - kIconLabelPadding; |
+ else |
+ text_left_offset = NSMaxX(image_rect) + kIconLabelPadding; |
} |
// Set the text color and draw the text. |
@@ -198,9 +209,9 @@ void SecurityStateBubbleDecoration::DrawInFrame(NSRect frame, |
NSRect text_rect = frame; |
CGFloat textHeight = [text size].height; |
- text_rect.origin.x = text_offset; |
+ text_rect.origin.x = text_left_offset; |
text_rect.origin.y = std::round(NSMidY(text_rect) - textHeight / 2.0) - 1; |
- text_rect.size.width = NSMaxX(decoration_frame) - NSMinX(text_rect); |
+ text_rect.size.width = text_right_offset - text_left_offset; |
text_rect.size.height = textHeight; |
NSAffineTransform* transform = [NSAffineTransform transform]; |
@@ -215,8 +226,9 @@ void SecurityStateBubbleDecoration::DrawInFrame(NSRect frame, |
double x_origin_offset = NSMinX(text_rect) * (1 - scale); |
double y_origin_offset = NSMinY(text_rect) * (1 - scale); |
+ double start_x_offset = is_rtl ? -kStartx_offset : kStartx_offset; |
double x_offset = |
- gfx::Tween::DoubleValueBetween(progress, kStartx_offset, 0); |
+ gfx::Tween::DoubleValueBetween(progress, start_x_offset, 0); |
double y_offset = NSHeight(text_rect) * (1 - scale) / 2.0; |
[transform translateXBy:x_offset + x_origin_offset |
@@ -229,11 +241,14 @@ void SecurityStateBubbleDecoration::DrawInFrame(NSRect frame, |
// Draw the divider. |
if (state() == DecorationMouseState::NONE && !active()) { |
+ const CGFloat divider_x_position = |
+ is_rtl ? NSMinX(decoration_frame) + DividerPadding() |
+ : NSMaxX(decoration_frame) - DividerPadding(); |
NSBezierPath* line = [NSBezierPath bezierPath]; |
[line setLineWidth:line_width]; |
- [line moveToPoint:NSMakePoint(NSMaxX(decoration_frame) - DividerPadding(), |
+ [line moveToPoint:NSMakePoint(divider_x_position, |
NSMinY(decoration_frame))]; |
- [line lineToPoint:NSMakePoint(NSMaxX(decoration_frame) - DividerPadding(), |
+ [line lineToPoint:NSMakePoint(divider_x_position, |
NSMaxY(decoration_frame))]; |
NSColor* divider_color = GetDividerColor(in_dark_mode); |