Commit bf6e249f authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

Fix RTL layout issues with dangerous downloads under MD downloads.

See the bug for screenshots of the problem.

Change-Id: I1db68491c72833efd979696cc98359e1c59acdfb
Bug: 825848
Reviewed-on: https://chromium-review.googlesource.com/979194
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Reviewed-by: default avatarLeonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545979}
parent 1117cae0
...@@ -172,7 +172,9 @@ NSTextField* MakeLabel( ...@@ -172,7 +172,9 @@ NSTextField* MakeLabel(
[self addSubview:iconView_]; [self addSubview:iconView_];
label_ = MakeLabel([NSFont systemFontOfSize:10], NSLineBreakByWordWrapping); label_ = MakeLabel([NSFont systemFontOfSize:10], NSLineBreakByWordWrapping);
label_.frame = NSInsetRect(self.bounds, 0, kDangerousDownloadLabelYInset); label_.frame =
[self cr_localizedRect:NSInsetRect(self.bounds, 0,
kDangerousDownloadLabelYInset)];
label_.autoresizingMask = label_.autoresizingMask =
[NSView cr_localizedAutoresizingMask:NSViewMaxXMargin]; [NSView cr_localizedAutoresizingMask:NSViewMaxXMargin];
[self addSubview:label_]; [self addSubview:label_];
...@@ -183,7 +185,7 @@ NSTextField* MakeLabel( ...@@ -183,7 +185,7 @@ NSTextField* MakeLabel(
discardButton_.title = l10n_util::GetNSString(IDS_DISCARD_DOWNLOAD); discardButton_.title = l10n_util::GetNSString(IDS_DISCARD_DOWNLOAD);
[discardButton_ sizeToFit]; [discardButton_ sizeToFit];
discardButton_.autoresizingMask = discardButton_.autoresizingMask =
[NSView cr_localizedAutoresizingMask:NSViewMinXMargin]; [NSView cr_localizedAutoresizingMask:NSViewMaxXMargin];
[self addSubview:discardButton_]; [self addSubview:discardButton_];
base::scoped_nsobject<HarmonyButton> saveButton( base::scoped_nsobject<HarmonyButton> saveButton(
...@@ -191,7 +193,7 @@ NSTextField* MakeLabel( ...@@ -191,7 +193,7 @@ NSTextField* MakeLabel(
saveButton_ = saveButton; saveButton_ = saveButton;
[saveButton_ sizeToFit]; [saveButton_ sizeToFit];
saveButton_.autoresizingMask = saveButton_.autoresizingMask =
[NSView cr_localizedAutoresizingMask:NSViewMinXMargin]; [NSView cr_localizedAutoresizingMask:NSViewMaxXMargin];
saveButton_.hidden = YES; saveButton_.hidden = YES;
[self addSubview:saveButton_]; [self addSubview:saveButton_];
} }
...@@ -215,12 +217,19 @@ NSTextField* MakeLabel( ...@@ -215,12 +217,19 @@ NSTextField* MakeLabel(
[GTMUILocalizerAndLayoutTweaker [GTMUILocalizerAndLayoutTweaker
sizeToFitFixedHeightTextField:label_ sizeToFitFixedHeightTextField:label_
minWidth:kDangerousDownloadLabelMinWidth]; minWidth:kDangerousDownloadLabelMinWidth];
NSRect labelRect = label_.frame;
// Flip the rect back to LTR if applicable.
NSRect labelRect = [self cr_localizedRect:label_.frame];
labelRect.origin.x = kDangerousDownloadLabelX; labelRect.origin.x = kDangerousDownloadLabelX;
labelRect.origin.y = NSMidY(self.bounds) - NSMidY(label_.bounds); labelRect.origin.y = NSMidY(self.bounds) - NSMidY(label_.bounds);
label_.frame = [self cr_localizedRect:labelRect]; label_.frame = [self cr_localizedRect:labelRect];
CGFloat maxX = NSMaxX(self.bounds); NSRect discardButtonRect = [self cr_localizedRect:discardButton_.frame];
discardButtonRect.origin.x =
NSMaxX(labelRect) + kDangerousDownloadLabelButtonSpacing;
discardButtonRect.origin.y =
NSMidY(self.bounds) - NSMidY(discardButton_.bounds);
discardButton_.frame = [self cr_localizedRect:discardButtonRect];
if (downloadModel->MightBeMalicious()) { if (downloadModel->MightBeMalicious()) {
saveButton_.hidden = YES; saveButton_.hidden = YES;
...@@ -229,18 +238,12 @@ NSTextField* MakeLabel( ...@@ -229,18 +238,12 @@ NSTextField* MakeLabel(
saveButton_.title = saveButton_.title =
base::SysUTF16ToNSString(downloadModel->GetWarningConfirmButtonText()); base::SysUTF16ToNSString(downloadModel->GetWarningConfirmButtonText());
[saveButton_ sizeToFit]; [saveButton_ sizeToFit];
NSRect saveButtonRect = saveButton_.frame; NSRect saveButtonRect = [self cr_localizedRect:saveButton_.frame];
saveButtonRect.origin.x = maxX - NSWidth(saveButtonRect); saveButtonRect.origin.x =
NSMaxX(discardButtonRect) + kDangerousDownloadLabelButtonSpacing;
saveButtonRect.origin.y = NSMidY(self.bounds) - NSMidY(saveButton_.bounds); saveButtonRect.origin.y = NSMidY(self.bounds) - NSMidY(saveButton_.bounds);
saveButton_.frame = [self cr_localizedRect:saveButtonRect]; saveButton_.frame = [self cr_localizedRect:saveButtonRect];
maxX = NSMinX(saveButtonRect) - kDangerousDownloadLabelButtonSpacing;
} }
NSRect discardButtonRect = discardButton_.frame;
discardButtonRect.origin.x = maxX - NSWidth(discardButtonRect);
discardButtonRect.origin.y =
NSMidY(self.bounds) - NSMidY(discardButton_.bounds);
discardButton_.frame = [self cr_localizedRect:discardButtonRect];
} }
// NSView overrides // NSView overrides
...@@ -521,8 +524,9 @@ NSTextField* MakeLabel( ...@@ -521,8 +524,9 @@ NSTextField* MakeLabel(
[self addSubview:dangerView_]; [self addSubview:dangerView_];
} }
[dangerView_ setStateFromDownload:downloadModel]; [dangerView_ setStateFromDownload:downloadModel];
[dangerView_ setFrameSize:NSMakeSize(dangerView_.preferredWidth, dangerView_.frame =
NSHeight(dangerView_.frame))]; [self cr_localizedRect:NSMakeRect(0, 0, dangerView_.preferredWidth,
NSHeight(self.bounds))];
return; return;
} else if (dangerView_) { } else if (dangerView_) {
for (NSView* view in [self normalViews]) { for (NSView* view in [self normalViews]) {
...@@ -565,17 +569,11 @@ NSTextField* MakeLabel( ...@@ -565,17 +569,11 @@ NSTextField* MakeLabel(
setState:MDDownloadItemProgressIndicatorState::kComplete setState:MDDownloadItemProgressIndicatorState::kComplete
progress:1 progress:1
animations:^{ animations:^{
// Explicitly animate position.y so that x position isn't animated NSRect filenameRect = [self cr_localizedRect:filenameView_.frame];
// for a new download (which would happen with view.animator). filenameRect.origin = NSMakePoint(
[filenameView_.layer NSMinX(filenameView_.frame),
addAnimation:[CABasicAnimation statusString.length ? kFilenameWithStatusY : kFilenameY);
animationWithKeyPath:@"position.y"] filenameView_.animator.frame = [self cr_localizedRect:filenameRect];
forKey:nil];
[filenameView_
setFrameOrigin:NSMakePoint(NSMinX(filenameView_.frame),
statusString.length
? kFilenameWithStatusY
: kFilenameY)];
statusTextView_.animator.hidden = !statusString.length; statusTextView_.animator.hidden = !statusString.length;
} }
completion:^{ completion:^{
......
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