Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1193)

Side by Side Diff: chrome/browser/ui/cocoa/info_bubble_view.mm

Issue 2717603003: [Mac] Make bubble arrow location/position RTL-aware (Closed)
Patch Set: Now with proper enum formatting Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/info_bubble_view.h" 5 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 9 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
10 #import "chrome/browser/ui/cocoa/l10n_util.h"
10 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect .h" 11 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect .h"
11 12
12 @implementation InfoBubbleView 13 @implementation InfoBubbleView
13 14
14 @synthesize arrowLocation = arrowLocation_; 15 @synthesize arrowLocation = arrowLocation_;
15 @synthesize alignment = alignment_; 16 @synthesize alignment = alignment_;
16 @synthesize cornerFlags = cornerFlags_; 17 @synthesize cornerFlags = cornerFlags_;
17 18
18 - (id)initWithFrame:(NSRect)frameRect { 19 - (id)initWithFrame:(NSRect)frameRect {
19 if ((self = [super initWithFrame:frameRect])) { 20 if ((self = [super initWithFrame:frameRect])) {
20 arrowLocation_ = info_bubble::kTopLeft; 21 arrowLocation_ = info_bubble::kTopLeading;
21 alignment_ = info_bubble::kAlignArrowToAnchor; 22 alignment_ = info_bubble::kAlignArrowToAnchor;
22 cornerFlags_ = info_bubble::kRoundedAllCorners; 23 cornerFlags_ = info_bubble::kRoundedAllCorners;
23 backgroundColor_.reset([[NSColor whiteColor] retain]); 24 backgroundColor_.reset([[NSColor whiteColor] retain]);
24 } 25 }
25 return self; 26 return self;
26 } 27 }
27 28
28 - (BOOL)performKeyEquivalent:(NSEvent *)event { 29 - (BOOL)performKeyEquivalent:(NSEvent *)event {
29 InfoBubbleWindow* info_bubble_window = 30 InfoBubbleWindow* info_bubble_window =
30 base::mac::ObjCCast<InfoBubbleWindow>([self window]); 31 base::mac::ObjCCast<InfoBubbleWindow>([self window]);
(...skipping 26 matching lines...) Expand all
57 info_bubble::kBubbleCornerRadius : 0; 58 info_bubble::kBubbleCornerRadius : 0;
58 59
59 NSBezierPath* bezier = 60 NSBezierPath* bezier =
60 [NSBezierPath gtm_bezierPathWithRoundRect:bounds 61 [NSBezierPath gtm_bezierPathWithRoundRect:bounds
61 topLeftCornerRadius:topRadius 62 topLeftCornerRadius:topRadius
62 topRightCornerRadius:topRadius 63 topRightCornerRadius:topRadius
63 bottomLeftCornerRadius:bottomRadius 64 bottomLeftCornerRadius:bottomRadius
64 bottomRightCornerRadius:bottomRadius]; 65 bottomRightCornerRadius:bottomRadius];
65 66
66 // Add the bubble arrow. 67 // Add the bubble arrow.
68 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
67 CGFloat dX = 0; 69 CGFloat dX = 0;
70 CGFloat leftOffset = info_bubble::kBubbleArrowXOffset;
71 CGFloat rightOffset = NSWidth(bounds) - info_bubble::kBubbleArrowXOffset -
72 info_bubble::kBubbleArrowWidth;
68 switch (arrowLocation_) { 73 switch (arrowLocation_) {
69 case info_bubble::kTopLeft: 74 case info_bubble::kTopLeading:
70 dX = info_bubble::kBubbleArrowXOffset; 75 dX = isRTL ? rightOffset : leftOffset;
71 break; 76 break;
72 case info_bubble::kTopRight: 77 case info_bubble::kTopTrailing:
73 dX = NSWidth(bounds) - info_bubble::kBubbleArrowXOffset - 78 dX = isRTL ? leftOffset : rightOffset;
74 info_bubble::kBubbleArrowWidth;
75 break; 79 break;
76 case info_bubble::kTopCenter: 80 case info_bubble::kTopCenter:
77 dX = NSMidX(bounds) - info_bubble::kBubbleArrowWidth / 2.0; 81 dX = NSMidX(bounds) - info_bubble::kBubbleArrowWidth / 2.0;
78 break; 82 break;
79 case info_bubble::kNoArrow: 83 case info_bubble::kNoArrow:
80 break; 84 break;
81 default: 85 default:
82 NOTREACHED(); 86 NOTREACHED();
83 break; 87 break;
84 } 88 }
(...skipping 11 matching lines...) Expand all
96 [bezier closePath]; 100 [bezier closePath];
97 [backgroundColor_ set]; 101 [backgroundColor_ set];
98 [bezier fill]; 102 [bezier fill];
99 } 103 }
100 104
101 - (NSPoint)arrowTip { 105 - (NSPoint)arrowTip {
102 NSRect bounds = [self bounds]; 106 NSRect bounds = [self bounds];
103 CGFloat tipXOffset = 107 CGFloat tipXOffset =
104 info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth / 2.0; 108 info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth / 2.0;
105 CGFloat xOffset = 0.0; 109 CGFloat xOffset = 0.0;
110 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
111 CGFloat leftOffset = NSMaxX(bounds) - tipXOffset;
112 CGFloat rightOffset = NSMinX(bounds) + tipXOffset;
106 switch(arrowLocation_) { 113 switch(arrowLocation_) {
107 case info_bubble::kTopRight: 114 case info_bubble::kTopTrailing:
108 xOffset = NSMaxX(bounds) - tipXOffset; 115 xOffset = isRTL ? rightOffset : leftOffset;
109 break; 116 break;
110 case info_bubble::kTopLeft: 117 case info_bubble::kTopLeading:
111 xOffset = NSMinX(bounds) + tipXOffset; 118 xOffset = isRTL ? leftOffset : rightOffset;
112 break; 119 break;
113 case info_bubble::kTopCenter: 120 case info_bubble::kTopCenter:
114 xOffset = NSMidX(bounds); 121 xOffset = NSMidX(bounds);
115 break; 122 break;
116 default: 123 default:
117 NOTREACHED(); 124 NOTREACHED();
118 break; 125 break;
119 } 126 }
120 NSPoint arrowTip = NSMakePoint(xOffset, NSMaxY(bounds)); 127 NSPoint arrowTip = NSMakePoint(xOffset, NSMaxY(bounds));
121 return arrowTip; 128 return arrowTip;
122 } 129 }
123 130
124 - (NSColor*)backgroundColor { 131 - (NSColor*)backgroundColor {
125 return backgroundColor_; 132 return backgroundColor_;
126 } 133 }
127 134
128 - (void)setBackgroundColor:(NSColor*)backgroundColor { 135 - (void)setBackgroundColor:(NSColor*)backgroundColor {
129 backgroundColor_.reset([backgroundColor retain]); 136 backgroundColor_.reset([backgroundColor retain]);
130 } 137 }
131 138
132 - (void)setArrowLocation:(info_bubble::BubbleArrowLocation)location { 139 - (void)setArrowLocation:(info_bubble::BubbleArrowLocation)location {
133 if (arrowLocation_ == location) 140 if (arrowLocation_ == location)
134 return; 141 return;
135 142
136 arrowLocation_ = location; 143 arrowLocation_ = location;
137 [self setNeedsDisplayInRect:[self bounds]]; 144 [self setNeedsDisplayInRect:[self bounds]];
138 } 145 }
139 146
140 @end 147 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/info_bubble_view.h ('k') | chrome/browser/ui/cocoa/passwords/passwords_bubble_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698