| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/l10n_util.h" | 5 #import "chrome/browser/ui/cocoa/l10n_util.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/mac/mac_util.h" |
| 8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 10 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 11 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
| 11 | 12 |
| 12 namespace cocoa_l10n_util { | 13 namespace cocoa_l10n_util { |
| 13 | 14 |
| 14 NSInteger CompareFrameY(id view1, id view2, void* context) { | 15 NSInteger CompareFrameY(id view1, id view2, void* context) { |
| 15 CGFloat y1 = NSMinY([view1 frame]); | 16 CGFloat y1 = NSMinY([view1 frame]); |
| 16 CGFloat y2 = NSMinY([view2 frame]); | 17 CGFloat y2 = NSMinY([view2 frame]); |
| 17 if (y1 < y2) | 18 if (y1 < y2) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 85 } |
| 85 | 86 |
| 86 const base::Feature kExperimentalMacRTL{"ExperimentalMacRTL", | 87 const base::Feature kExperimentalMacRTL{"ExperimentalMacRTL", |
| 87 base::FEATURE_DISABLED_BY_DEFAULT}; | 88 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 88 | 89 |
| 89 bool ShouldDoExperimentalRTLLayout() { | 90 bool ShouldDoExperimentalRTLLayout() { |
| 90 return base::i18n::IsRTL() && | 91 return base::i18n::IsRTL() && |
| 91 base::FeatureList::IsEnabled(kExperimentalMacRTL); | 92 base::FeatureList::IsEnabled(kExperimentalMacRTL); |
| 92 } | 93 } |
| 93 | 94 |
| 95 #if !defined(MAC_OS_X_VERSION_10_12) || \ |
| 96 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12 |
| 97 NSCellImagePosition LeadingCellImagePosition() { |
| 98 return ShouldDoExperimentalRTLLayout() ? NSImageRight : NSImageLeft; |
| 99 } |
| 100 NSCellImagePosition TrailingCellImagePosition() { |
| 101 return ShouldDoExperimentalRTLLayout() ? NSImageLeft : NSImageRight; |
| 102 } |
| 103 #else |
| 104 NSCellImagePosition LeadingCellImagePosition() { |
| 105 return NSImageLeading; |
| 106 } |
| 107 NSCellImagePosition TrailingCellImagePosition() { |
| 108 return NSImageTrailing; |
| 109 } |
| 110 #endif // MAC_OS_X_VERSION_10_12 |
| 111 |
| 112 // Adapted from Apple's RTL docs (goo.gl/cBaFnT) |
| 113 NSImage* FlippedImage(NSImage* image) { |
| 114 NSImage* existingImage = image; |
| 115 NSSize existingSize = [existingImage size]; |
| 116 NSSize newSize = NSMakeSize(existingSize.width, existingSize.height); |
| 117 NSImage* flippedImage = [[[NSImage alloc] initWithSize:newSize] autorelease]; |
| 118 |
| 119 [flippedImage lockFocus]; |
| 120 [[NSGraphicsContext currentContext] |
| 121 setImageInterpolation:NSImageInterpolationHigh]; |
| 122 |
| 123 NSAffineTransform* transform = [NSAffineTransform transform]; |
| 124 [transform translateXBy:existingSize.width yBy:0]; |
| 125 [transform scaleXBy:-1 yBy:1]; |
| 126 [transform concat]; |
| 127 |
| 128 [existingImage drawAtPoint:NSZeroPoint |
| 129 fromRect:NSMakeRect(0, 0, newSize.width, newSize.height) |
| 130 operation:NSCompositeSourceOver |
| 131 fraction:1.0]; |
| 132 |
| 133 [flippedImage unlockFocus]; |
| 134 |
| 135 return flippedImage; |
| 136 } |
| 137 |
| 94 } // namespace cocoa_l10n_util | 138 } // namespace cocoa_l10n_util |
| OLD | NEW |