Commit 2ec7f4ea authored by ellyjones's avatar ellyjones Committed by Commit bot

cocoa: flip window controls and profile switcher for RTL

This change:
1) Reflects the window controls horizontally for RTL
2) Reflects the profile switcher horizontally for RTL
3) Adjusts the left and right indents for the tabstrip itself to account for
   those reflections

BUG=642732

Review-Url: https://codereview.chromium.org/2313723004
Cr-Commit-Position: refs/heads/master@{#417339}
parent 2cbd2420
......@@ -7,8 +7,10 @@
#include <math.h>
#include <string.h>
#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/mac/mac_util.h"
#include "chrome/browser/ui/cocoa/l10n_util.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
namespace chrome {
......@@ -248,6 +250,12 @@ const CGFloat kLocationBarRightOffset = 35;
}
layout.rightIndent = width - maxX;
if (cocoa_l10n_util::ExperimentalMacRTLIsEnabled() && base::i18n::IsRTL()) {
std::swap(layout.leftIndent, layout.rightIndent);
layout.avatarFrame.origin.x =
width - parameters_.avatarSize.width - layout.avatarFrame.origin.x;
}
output_.tabStripLayout = layout;
}
......
......@@ -6,6 +6,7 @@
#include <stddef.h>
#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/mac/sdk_forward_declarations.h"
#include "chrome/browser/global_keyboard_shortcuts_mac.h"
......@@ -14,6 +15,7 @@
#include "chrome/browser/themes/theme_service.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/browser_window_utils.h"
#include "chrome/browser/ui/cocoa/l10n_util.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#include "chrome/grit/theme_resources.h"
......@@ -160,6 +162,11 @@ const CGFloat kWindowGradientHeight = 24.0;
break;
}
if (cocoa_l10n_util::ExperimentalMacRTLIsEnabled() && base::i18n::IsRTL()) {
buttonFrame.origin.x =
NSWidth([self frame]) - buttonFrame.origin.x - NSWidth([button frame]);
}
BOOL didPost = [button postsBoundsChangedNotifications];
[button setPostsFrameChangedNotifications:NO];
[button setFrame:buttonFrame];
......
......@@ -33,4 +33,8 @@ NSString* ReplaceNSStringPlaceholders(NSString* formatString,
// Generates a tooltip string for a given URL and title.
NSString* TooltipForURLAndTitle(NSString* url, NSString* title);
// Returns whether experimental Mac RTL support is enabled via
// --enable-features=ExperimentalMacRTL.
bool ExperimentalMacRTLIsEnabled();
} // namespace cocoa_l10n_util
......@@ -4,6 +4,7 @@
#import "chrome/browser/ui/cocoa/l10n_util.h"
#include "base/feature_list.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
......@@ -82,4 +83,11 @@ NSString* TooltipForURLAndTitle(NSString* url, NSString* title) {
return [NSString stringWithFormat:@"%@\n%@", title, url];
}
const base::Feature kExperimentalMacRTL{"ExperimentalMacRTL",
base::FEATURE_DISABLED_BY_DEFAULT};
bool ExperimentalMacRTLIsEnabled() {
return base::FeatureList::IsEnabled(kExperimentalMacRTL);
}
} // namespace cocoa_l10n_util
......@@ -4,9 +4,11 @@
#import "chrome/browser/ui/cocoa/new_tab_button.h"
#include "base/i18n/rtl.h"
#include "base/mac/foundation_util.h"
#include "base/mac/sdk_forward_declarations.h"
#import "chrome/browser/ui/cocoa/image_button_cell.h"
#include "chrome/browser/ui/cocoa/l10n_util.h"
#include "chrome/browser/ui/cocoa/tabs/tab_view.h"
#include "chrome/grit/theme_resources.h"
#include "ui/base/cocoa/nsgraphics_context_additions.h"
......@@ -412,12 +414,16 @@ CGFloat LineWidthFromContext(CGContextRef context) {
[bezierPath closePath];
// The SVG path is flipped for some reason, so flip it back.
const CGFloat kSVGHeight = 32;
NSAffineTransformStruct flipStruct = { 1, 0, 0, -1, 0, kSVGHeight };
NSAffineTransform* flipTransform = [NSAffineTransform transform];
[flipTransform setTransformStruct:flipStruct];
[bezierPath transformUsingAffineTransform:flipTransform];
// The SVG path is flipped for some reason, so flip it back. However, in RTL,
// we'd need to flip it again below, so when in RTL mode just leave the flip
// out altogether.
if (!cocoa_l10n_util::ExperimentalMacRTLIsEnabled() || !base::i18n::IsRTL()) {
const CGFloat kSVGHeight = 32;
NSAffineTransformStruct flipStruct = {1, 0, 0, -1, 0, kSVGHeight};
NSAffineTransform* flipTransform = [NSAffineTransform transform];
[flipTransform setTransformStruct:flipStruct];
[bezierPath transformUsingAffineTransform:flipTransform];
}
// The SVG data is for the 2x version so scale it down.
NSAffineTransform* scaleTransform = [NSAffineTransform transform];
......
......@@ -11,6 +11,7 @@
#include <string>
#include "base/command_line.h"
#include "base/i18n/rtl.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/mac/sdk_forward_declarations.h"
......@@ -31,6 +32,7 @@
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/drag_util.h"
#import "chrome/browser/ui/cocoa/image_button_cell.h"
#include "chrome/browser/ui/cocoa/l10n_util.h"
#import "chrome/browser/ui/cocoa/new_tab_button.h"
#import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h"
#import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
......@@ -136,6 +138,12 @@ private:
DISALLOW_COPY_AND_ASSIGN(ScopedNSAnimationContextGroup);
};
CGFloat FlipXInView(NSView* view, CGFloat width, CGFloat x) {
if (cocoa_l10n_util::ExperimentalMacRTLIsEnabled() && base::i18n::IsRTL())
return [view frame].size.width - x - width;
return x;
}
} // namespace
@interface TabStripController (Private)
......@@ -999,7 +1007,10 @@ private:
BOOL visible = [[tabStripView_ window] isVisible];
CGFloat offset = [self leftIndentForControls];
CGFloat offset =
cocoa_l10n_util::ExperimentalMacRTLIsEnabled() && base::i18n::IsRTL()
? [self rightIndentForControls]
: [self leftIndentForControls];
bool hasPlaceholderGap = false;
// Whether or not the last tab processed by the loop was a pinned tab.
BOOL isLastTabPinned = NO;
......@@ -1108,6 +1119,9 @@ private:
}
}
tabFrame.origin.x =
FlipXInView(tabStripView_, tabFrame.size.width, tabFrame.origin.x);
// Check the frame by identifier to avoid redundant calls to animator.
id frameTarget = visible && animate ? [[tab view] animator] : [tab view];
NSValue* identifier = [NSValue valueWithPointer:[tab view]];
......@@ -1148,6 +1162,11 @@ private:
// so we don't have to check it against the available space. We do need
// to make sure we put it after any placeholder.
CGFloat maxTabX = MAX(offset, NSMaxX(placeholderFrame_) - kTabOverlap);
if (cocoa_l10n_util::ExperimentalMacRTLIsEnabled() && base::i18n::IsRTL()) {
maxTabX = FlipXInView(tabStripView_, [newTabButton_ frame].size.width,
maxTabX) -
(2 * kNewTabButtonOffset);
}
newTabNewFrame.origin = NSMakePoint(maxTabX + kNewTabButtonOffset, 0);
if ([tabContentsArray_ count])
[newTabButton_ setHidden:NO];
......
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