Commit 0d2ad84f authored by lgrey's avatar lgrey Committed by Commit bot

[Mac] Make bubble arrow location/position RTL-aware

Instead of left and right, callers now specify leading and trailing. For
LTR, leading = left, and trailing = right, and in RTL they are reversed.

BUG=678257

Review-Url: https://codereview.chromium.org/2717603003
Cr-Commit-Position: refs/heads/master@{#453232}
parent 1af02e1b
...@@ -494,7 +494,7 @@ void CardUnmaskPromptViewBridge::PerformClose() { ...@@ -494,7 +494,7 @@ void CardUnmaskPromptViewBridge::PerformClose() {
// Add "?" icon with tooltip. // Add "?" icon with tooltip.
storageTooltip_.reset([[AutofillTooltipController alloc] storageTooltip_.reset([[AutofillTooltipController alloc]
initWithArrowLocation:info_bubble::kTopRight]); initWithArrowLocation:info_bubble::kTopTrailing]);
[storageTooltip_ setImage:ui::ResourceBundle::GetSharedInstance() [storageTooltip_ setImage:ui::ResourceBundle::GetSharedInstance()
.GetNativeImageNamed(IDR_AUTOFILL_TOOLTIP_ICON) .GetNativeImageNamed(IDR_AUTOFILL_TOOLTIP_ICON)
.ToNSImage()]; .ToNSImage()];
......
...@@ -114,7 +114,7 @@ ...@@ -114,7 +114,7 @@
self)); self));
} }
[bubble_ setArrowLocation:info_bubble::kTopRight]; [bubble_ setArrowLocation:info_bubble::kTopTrailing];
} }
- (void)dealloc { - (void)dealloc {
...@@ -411,11 +411,13 @@ ...@@ -411,11 +411,13 @@
info_bubble::kBubbleArrowWidth / 2.0, 0); info_bubble::kBubbleArrowWidth / 2.0, 0);
offsets = [[parentWindow_ contentView] convertSize:offsets toView:nil]; offsets = [[parentWindow_ contentView] convertSize:offsets toView:nil];
switch ([bubble_ arrowLocation]) { switch ([bubble_ arrowLocation]) {
case info_bubble::kTopRight: case info_bubble::kTopTrailing:
origin.x -= NSWidth([window frame]) - offsets.width; origin.x -=
isRTL ? offsets.width : NSWidth([window frame]) - offsets.width;
break; break;
case info_bubble::kTopLeft: case info_bubble::kTopLeading:
origin.x -= offsets.width; origin.x -=
isRTL ? NSWidth([window frame]) - offsets.width : offsets.width;
break; break;
case info_bubble::kNoArrow: case info_bubble::kNoArrow:
// FALLTHROUGH. // FALLTHROUGH.
...@@ -431,7 +433,7 @@ ...@@ -431,7 +433,7 @@
// edge aligns with the anchor. If the arrow is to the left then there's // edge aligns with the anchor. If the arrow is to the left then there's
// nothing to do because the left edge is already aligned with the left // nothing to do because the left edge is already aligned with the left
// edge of the anchor. // edge of the anchor.
if ([bubble_ arrowLocation] == info_bubble::kTopRight) { if ([bubble_ arrowLocation] == info_bubble::kTopTrailing) {
origin.x -= NSWidth([window frame]); origin.x -= NSWidth([window frame]);
} }
break; break;
......
...@@ -165,7 +165,7 @@ class BaseBubbleControllerTest : public CocoaTest { ...@@ -165,7 +165,7 @@ class BaseBubbleControllerTest : public CocoaTest {
// Test that kAlignEdgeToAnchorEdge and a left bubble arrow correctly aligns the // Test that kAlignEdgeToAnchorEdge and a left bubble arrow correctly aligns the
// left edge of the buble to the anchor point. // left edge of the buble to the anchor point.
TEST_F(BaseBubbleControllerTest, LeftAlign) { TEST_F(BaseBubbleControllerTest, LeftAlign) {
[[controller_ bubble] setArrowLocation:info_bubble::kTopLeft]; [[controller_ bubble] setArrowLocation:info_bubble::kTopLeading];
[[controller_ bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; [[controller_ bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge];
[controller_ showWindow:nil]; [controller_ showWindow:nil];
...@@ -181,7 +181,7 @@ TEST_F(BaseBubbleControllerTest, LeftAlign) { ...@@ -181,7 +181,7 @@ TEST_F(BaseBubbleControllerTest, LeftAlign) {
// Test that kAlignEdgeToAnchorEdge and a right bubble arrow correctly aligns // Test that kAlignEdgeToAnchorEdge and a right bubble arrow correctly aligns
// the right edge of the buble to the anchor point. // the right edge of the buble to the anchor point.
TEST_F(BaseBubbleControllerTest, RightAlign) { TEST_F(BaseBubbleControllerTest, RightAlign) {
[[controller_ bubble] setArrowLocation:info_bubble::kTopRight]; [[controller_ bubble] setArrowLocation:info_bubble::kTopTrailing];
[[controller_ bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; [[controller_ bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge];
[controller_ showWindow:nil]; [controller_ showWindow:nil];
...@@ -197,7 +197,7 @@ TEST_F(BaseBubbleControllerTest, RightAlign) { ...@@ -197,7 +197,7 @@ TEST_F(BaseBubbleControllerTest, RightAlign) {
// Test that kAlignArrowToAnchor and a left bubble arrow correctly aligns // Test that kAlignArrowToAnchor and a left bubble arrow correctly aligns
// the bubble arrow to the anchor point. // the bubble arrow to the anchor point.
TEST_F(BaseBubbleControllerTest, AnchorAlignLeftArrow) { TEST_F(BaseBubbleControllerTest, AnchorAlignLeftArrow) {
[[controller_ bubble] setArrowLocation:info_bubble::kTopLeft]; [[controller_ bubble] setArrowLocation:info_bubble::kTopLeading];
[[controller_ bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; [[controller_ bubble] setAlignment:info_bubble::kAlignArrowToAnchor];
[controller_ showWindow:nil]; [controller_ showWindow:nil];
...@@ -214,7 +214,7 @@ TEST_F(BaseBubbleControllerTest, AnchorAlignLeftArrow) { ...@@ -214,7 +214,7 @@ TEST_F(BaseBubbleControllerTest, AnchorAlignLeftArrow) {
// Test that kAlignArrowToAnchor and a right bubble arrow correctly aligns // Test that kAlignArrowToAnchor and a right bubble arrow correctly aligns
// the bubble arrow to the anchor point. // the bubble arrow to the anchor point.
TEST_F(BaseBubbleControllerTest, AnchorAlignRightArrow) { TEST_F(BaseBubbleControllerTest, AnchorAlignRightArrow) {
[[controller_ bubble] setArrowLocation:info_bubble::kTopRight]; [[controller_ bubble] setArrowLocation:info_bubble::kTopTrailing];
[[controller_ bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; [[controller_ bubble] setAlignment:info_bubble::kAlignArrowToAnchor];
[controller_ showWindow:nil]; [controller_ showWindow:nil];
...@@ -248,7 +248,7 @@ TEST_F(BaseBubbleControllerTest, AnchorAlignCenterArrow) { ...@@ -248,7 +248,7 @@ TEST_F(BaseBubbleControllerTest, AnchorAlignCenterArrow) {
// ensures offscreen initialization is done using correct screen metrics. // ensures offscreen initialization is done using correct screen metrics.
TEST_F(BaseBubbleControllerTest, PositionedBeforeShow) { TEST_F(BaseBubbleControllerTest, PositionedBeforeShow) {
// Verify default alignment settings, used when initialized in SetUp(). // Verify default alignment settings, used when initialized in SetUp().
EXPECT_EQ(info_bubble::kTopRight, [[controller_ bubble] arrowLocation]); EXPECT_EQ(info_bubble::kTopTrailing, [[controller_ bubble] arrowLocation]);
EXPECT_EQ(info_bubble::kAlignArrowToAnchor, [[controller_ bubble] alignment]); EXPECT_EQ(info_bubble::kAlignArrowToAnchor, [[controller_ bubble] alignment]);
// Verify the default frame (positioned relative to the test_window() origin). // Verify the default frame (positioned relative to the test_window() origin).
......
...@@ -144,7 +144,7 @@ using bookmarks::BookmarkNode; ...@@ -144,7 +144,7 @@ using bookmarks::BookmarkNode;
[BrowserWindowController browserWindowControllerForWindow:parentWindow]; [BrowserWindowController browserWindowControllerForWindow:parentWindow];
InfoBubbleView* bubble = self.bubble; InfoBubbleView* bubble = self.bubble;
[bubble setArrowLocation:info_bubble::kTopRight]; [bubble setArrowLocation:info_bubble::kTopTrailing];
// Insure decent positioning even in the absence of a browser controller, // Insure decent positioning even in the absence of a browser controller,
// which will occur for some unit tests. // which will occur for some unit tests.
......
...@@ -791,7 +791,7 @@ const ContentTypeToNibPath kNibPaths[] = { ...@@ -791,7 +791,7 @@ const ContentTypeToNibPath kNibPaths[] = {
ContentSettingSimpleBubbleModel* simple_bubble = ContentSettingSimpleBubbleModel* simple_bubble =
contentSettingBubbleModel_->AsSimpleBubbleModel(); contentSettingBubbleModel_->AsSimpleBubbleModel();
[[self bubble] setArrowLocation:info_bubble::kTopRight]; [[self bubble] setArrowLocation:info_bubble::kTopTrailing];
// Adapt window size to bottom buttons. Do this before all other layouting. // Adapt window size to bottom buttons. Do this before all other layouting.
if (simple_bubble && !simple_bubble->bubble_content().manage_text.empty()) if (simple_bubble && !simple_bubble->bubble_content().manage_text.empty())
......
...@@ -77,7 +77,7 @@ void ExtensionActionPlatformDelegateCocoa::ShowPopup( ...@@ -77,7 +77,7 @@ void ExtensionActionPlatformDelegateCocoa::ShowPopup(
[ExtensionPopupController host:std::move(host) [ExtensionPopupController host:std::move(host)
inBrowser:controller_->browser() inBrowser:controller_->browser()
anchoredAt:GetPopupPoint() anchoredAt:GetPopupPoint()
arrowLocation:info_bubble::kTopRight arrowLocation:info_bubble::kTopTrailing
devMode:devMode]; devMode:devMode];
} }
......
...@@ -285,9 +285,9 @@ std::unique_ptr<BubbleUi> ExtensionInstalledBubble::BuildBubbleUi() { ...@@ -285,9 +285,9 @@ std::unique_ptr<BubbleUi> ExtensionInstalledBubble::BuildBubbleUi() {
if (installedBubble_ && if (installedBubble_ &&
installedBubble_->anchor_position() == installedBubble_->anchor_position() ==
ExtensionInstalledBubble::ANCHOR_OMNIBOX) { ExtensionInstalledBubble::ANCHOR_OMNIBOX) {
[self.bubble setArrowLocation:info_bubble::kTopLeft]; [self.bubble setArrowLocation:info_bubble::kTopLeading];
} else { } else {
[self.bubble setArrowLocation:info_bubble::kTopRight]; [self.bubble setArrowLocation:info_bubble::kTopTrailing];
} }
// Set appropriate icon, resizing if necessary. // Set appropriate icon, resizing if necessary.
......
...@@ -87,7 +87,7 @@ CGFloat kMinWidth = 320.0; ...@@ -87,7 +87,7 @@ CGFloat kMinWidth = 320.0;
ui::NativeTheme* nativeTheme = ui::NativeTheme::GetInstanceForNativeUi(); ui::NativeTheme* nativeTheme = ui::NativeTheme::GetInstanceForNativeUi();
[[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor];
[[self bubble] setArrowLocation:info_bubble::kTopRight]; [[self bubble] setArrowLocation:info_bubble::kTopTrailing];
[[self bubble] setBackgroundColor: [[self bubble] setBackgroundColor:
skia::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor( skia::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor(
ui::NativeTheme::kColorId_DialogBackground))]; ui::NativeTheme::kColorId_DialogBackground))];
......
...@@ -25,9 +25,9 @@ enum CornerFlags { ...@@ -25,9 +25,9 @@ enum CornerFlags {
}; };
enum BubbleArrowLocation { enum BubbleArrowLocation {
kTopLeft, kTopLeading,
kTopCenter, kTopCenter,
kTopRight, kTopTrailing,
kNoArrow, kNoArrow,
}; };
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#import "chrome/browser/ui/cocoa/info_bubble_window.h" #import "chrome/browser/ui/cocoa/info_bubble_window.h"
#import "chrome/browser/ui/cocoa/l10n_util.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect.h" #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect.h"
@implementation InfoBubbleView @implementation InfoBubbleView
...@@ -17,7 +18,7 @@ ...@@ -17,7 +18,7 @@
- (id)initWithFrame:(NSRect)frameRect { - (id)initWithFrame:(NSRect)frameRect {
if ((self = [super initWithFrame:frameRect])) { if ((self = [super initWithFrame:frameRect])) {
arrowLocation_ = info_bubble::kTopLeft; arrowLocation_ = info_bubble::kTopLeading;
alignment_ = info_bubble::kAlignArrowToAnchor; alignment_ = info_bubble::kAlignArrowToAnchor;
cornerFlags_ = info_bubble::kRoundedAllCorners; cornerFlags_ = info_bubble::kRoundedAllCorners;
backgroundColor_.reset([[NSColor whiteColor] retain]); backgroundColor_.reset([[NSColor whiteColor] retain]);
...@@ -64,14 +65,17 @@ ...@@ -64,14 +65,17 @@
bottomRightCornerRadius:bottomRadius]; bottomRightCornerRadius:bottomRadius];
// Add the bubble arrow. // Add the bubble arrow.
BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
CGFloat dX = 0; CGFloat dX = 0;
CGFloat leftOffset = info_bubble::kBubbleArrowXOffset;
CGFloat rightOffset = NSWidth(bounds) - info_bubble::kBubbleArrowXOffset -
info_bubble::kBubbleArrowWidth;
switch (arrowLocation_) { switch (arrowLocation_) {
case info_bubble::kTopLeft: case info_bubble::kTopLeading:
dX = info_bubble::kBubbleArrowXOffset; dX = isRTL ? rightOffset : leftOffset;
break; break;
case info_bubble::kTopRight: case info_bubble::kTopTrailing:
dX = NSWidth(bounds) - info_bubble::kBubbleArrowXOffset - dX = isRTL ? leftOffset : rightOffset;
info_bubble::kBubbleArrowWidth;
break; break;
case info_bubble::kTopCenter: case info_bubble::kTopCenter:
dX = NSMidX(bounds) - info_bubble::kBubbleArrowWidth / 2.0; dX = NSMidX(bounds) - info_bubble::kBubbleArrowWidth / 2.0;
...@@ -103,12 +107,15 @@ ...@@ -103,12 +107,15 @@
CGFloat tipXOffset = CGFloat tipXOffset =
info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth / 2.0; info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth / 2.0;
CGFloat xOffset = 0.0; CGFloat xOffset = 0.0;
BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
CGFloat leftOffset = NSMaxX(bounds) - tipXOffset;
CGFloat rightOffset = NSMinX(bounds) + tipXOffset;
switch(arrowLocation_) { switch(arrowLocation_) {
case info_bubble::kTopRight: case info_bubble::kTopTrailing:
xOffset = NSMaxX(bounds) - tipXOffset; xOffset = isRTL ? rightOffset : leftOffset;
break; break;
case info_bubble::kTopLeft: case info_bubble::kTopLeading:
xOffset = NSMinX(bounds) + tipXOffset; xOffset = isRTL ? leftOffset : rightOffset;
break; break;
case info_bubble::kTopCenter: case info_bubble::kTopCenter:
xOffset = NSMidX(bounds); xOffset = NSMidX(bounds);
......
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
browserWindowControllerForWindow:[self parentWindow]]; browserWindowControllerForWindow:[self parentWindow]];
anchorPoint = [controller locationBarBridge]->GetBubblePointForDecoration( anchorPoint = [controller locationBarBridge]->GetBubblePointForDecoration(
[self decorationForBubble]); [self decorationForBubble]);
arrow = info_bubble::kTopRight; arrow = info_bubble::kTopTrailing;
} else { } else {
// Center the bubble if there's no location bar. // Center the bubble if there's no location bar.
NSRect contentFrame = [[[self parentWindow] contentView] frame]; NSRect contentFrame = [[[self parentWindow] contentView] frame];
......
...@@ -47,7 +47,7 @@ anchoredAt:(NSPoint)anchorPoint ...@@ -47,7 +47,7 @@ anchoredAt:(NSPoint)anchorPoint
if ((self = [super initWithWindow:window.get() if ((self = [super initWithWindow:window.get()
parentWindow:parentWindow parentWindow:parentWindow
anchoredAt:anchorPoint])) { anchoredAt:anchorPoint])) {
[[self bubble] setArrowLocation:info_bubble::kTopLeft]; [[self bubble] setArrowLocation:info_bubble::kTopLeading];
self.shouldOpenAsKeyWindow = NO; self.shouldOpenAsKeyWindow = NO;
NSView* contentView = [ValidationMessageBubbleController NSView* contentView = [ValidationMessageBubbleController
......
...@@ -246,7 +246,8 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { ...@@ -246,7 +246,8 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
} }
- (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation {
return [self hasLocationBar] ? info_bubble::kTopLeft : info_bubble::kNoArrow; return [self hasLocationBar] ? info_bubble::kTopLeading
: info_bubble::kNoArrow;
} }
- (NSWindow*)getExpectedParentWindow { - (NSWindow*)getExpectedParentWindow {
......
...@@ -479,7 +479,7 @@ const NSInteger kFullscreenLeftOffset = 40; ...@@ -479,7 +479,7 @@ const NSInteger kFullscreenLeftOffset = 40;
} }
- (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation {
return info_bubble::kTopLeft; return info_bubble::kTopLeading;
} }
- (NSWindow*)getExpectedParentWindow { - (NSWindow*)getExpectedParentWindow {
......
...@@ -213,7 +213,7 @@ bool IsInternalURL(const GURL& url) { ...@@ -213,7 +213,7 @@ bool IsInternalURL(const GURL& url) {
if ((self = [super initWithWindow:window.get() if ((self = [super initWithWindow:window.get()
parentWindow:parentWindow parentWindow:parentWindow
anchoredAt:NSZeroPoint])) { anchoredAt:NSZeroPoint])) {
[[self bubble] setArrowLocation:info_bubble::kTopLeft]; [[self bubble] setArrowLocation:info_bubble::kTopLeading];
// Create the container view that uses flipped coordinates. // Create the container view that uses flipped coordinates.
NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300);
......
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