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(
[self addSubview:iconView_];
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 =
[NSView cr_localizedAutoresizingMask:NSViewMaxXMargin];
[self addSubview:label_];
......@@ -183,7 +185,7 @@ NSTextField* MakeLabel(
discardButton_.title = l10n_util::GetNSString(IDS_DISCARD_DOWNLOAD);
[discardButton_ sizeToFit];
discardButton_.autoresizingMask =
[NSView cr_localizedAutoresizingMask:NSViewMinXMargin];
[NSView cr_localizedAutoresizingMask:NSViewMaxXMargin];
[self addSubview:discardButton_];
base::scoped_nsobject<HarmonyButton> saveButton(
......@@ -191,7 +193,7 @@ NSTextField* MakeLabel(
saveButton_ = saveButton;
[saveButton_ sizeToFit];
saveButton_.autoresizingMask =
[NSView cr_localizedAutoresizingMask:NSViewMinXMargin];
[NSView cr_localizedAutoresizingMask:NSViewMaxXMargin];
saveButton_.hidden = YES;
[self addSubview:saveButton_];
}
......@@ -215,12 +217,19 @@ NSTextField* MakeLabel(
[GTMUILocalizerAndLayoutTweaker
sizeToFitFixedHeightTextField:label_
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.y = NSMidY(self.bounds) - NSMidY(label_.bounds);
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()) {
saveButton_.hidden = YES;
......@@ -229,18 +238,12 @@ NSTextField* MakeLabel(
saveButton_.title =
base::SysUTF16ToNSString(downloadModel->GetWarningConfirmButtonText());
[saveButton_ sizeToFit];
NSRect saveButtonRect = saveButton_.frame;
saveButtonRect.origin.x = maxX - NSWidth(saveButtonRect);
NSRect saveButtonRect = [self cr_localizedRect:saveButton_.frame];
saveButtonRect.origin.x =
NSMaxX(discardButtonRect) + kDangerousDownloadLabelButtonSpacing;
saveButtonRect.origin.y = NSMidY(self.bounds) - NSMidY(saveButton_.bounds);
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
......@@ -521,8 +524,9 @@ NSTextField* MakeLabel(
[self addSubview:dangerView_];
}
[dangerView_ setStateFromDownload:downloadModel];
[dangerView_ setFrameSize:NSMakeSize(dangerView_.preferredWidth,
NSHeight(dangerView_.frame))];
dangerView_.frame =
[self cr_localizedRect:NSMakeRect(0, 0, dangerView_.preferredWidth,
NSHeight(self.bounds))];
return;
} else if (dangerView_) {
for (NSView* view in [self normalViews]) {
......@@ -565,17 +569,11 @@ NSTextField* MakeLabel(
setState:MDDownloadItemProgressIndicatorState::kComplete
progress:1
animations:^{
// Explicitly animate position.y so that x position isn't animated
// for a new download (which would happen with view.animator).
[filenameView_.layer
addAnimation:[CABasicAnimation
animationWithKeyPath:@"position.y"]
forKey:nil];
[filenameView_
setFrameOrigin:NSMakePoint(NSMinX(filenameView_.frame),
statusString.length
? kFilenameWithStatusY
: kFilenameY)];
NSRect filenameRect = [self cr_localizedRect:filenameView_.frame];
filenameRect.origin = NSMakePoint(
NSMinX(filenameView_.frame),
statusString.length ? kFilenameWithStatusY : kFilenameY);
filenameView_.animator.frame = [self cr_localizedRect:filenameRect];
statusTextView_.animator.hidden = !statusString.length;
}
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