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

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_details_container.mm

Issue 82593002: [rAC, OSX] Align bubble arrow based on location. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/autofill/autofill_details_container.h" 5 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" 10 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
11 #import "chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.h" 11 #import "chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.h"
12 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" 12 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"
13 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
13 14
14 @implementation AutofillDetailsContainer 15 @implementation AutofillDetailsContainer
15 16
16 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate { 17 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate {
17 if (self = [super init]) { 18 if (self = [super init]) {
18 delegate_ = delegate; 19 delegate_ = delegate;
19 } 20 }
20 return self; 21 return self;
21 } 22 }
22 23
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 [scrollView_ reflectScrolledClipView:clipView]; 151 [scrollView_ reflectScrolledClipView:clipView];
151 [self updateErrorBubble]; 152 [self updateErrorBubble];
152 } 153 }
153 154
154 - (void)updateErrorBubble { 155 - (void)updateErrorBubble {
155 if (!delegate_->ShouldShowErrorBubble()) { 156 if (!delegate_->ShouldShowErrorBubble()) {
156 [errorBubbleController_ close]; 157 [errorBubbleController_ close];
157 } 158 }
158 } 159 }
159 160
160 - (NSPoint)anchorPointFromView:(NSView*)view {
161 // All math done in window coordinates, since views might be flipped.
162 NSRect viewRect = [view convertRect:[view bounds] toView:nil];
163 NSPoint anchorPoint =
164 NSMakePoint(NSMidX(viewRect), NSMinY(viewRect));
165 return [[view window] convertBaseToScreen:anchorPoint];
166 }
167
168 - (void)errorBubbleWindowWillClose:(NSNotification*)notification { 161 - (void)errorBubbleWindowWillClose:(NSNotification*)notification {
169 DCHECK_EQ([notification object], [errorBubbleController_ window]); 162 DCHECK_EQ([notification object], [errorBubbleController_ window]);
170 163
171 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 164 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
172 [center removeObserver:self 165 [center removeObserver:self
173 name:NSWindowWillCloseNotification 166 name:NSWindowWillCloseNotification
174 object:[errorBubbleController_ window]]; 167 object:[errorBubbleController_ window]];
175 errorBubbleController_ = nil; 168 errorBubbleController_ = nil;
176 } 169 }
177 170
(...skipping 10 matching lines...) Expand all
188 181
189 // Handle bubble self-deleting. 182 // Handle bubble self-deleting.
190 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 183 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
191 [center addObserver:self 184 [center addObserver:self
192 selector:@selector(errorBubbleWindowWillClose:) 185 selector:@selector(errorBubbleWindowWillClose:)
193 name:NSWindowWillCloseNotification 186 name:NSWindowWillCloseNotification
194 object:[errorBubbleController_ window]]; 187 object:[errorBubbleController_ window]];
195 188
196 // Compute anchor point (in window coords - views might be flipped). 189 // Compute anchor point (in window coords - views might be flipped).
197 NSRect viewRect = [field convertRect:[field bounds] toView:nil]; 190 NSRect viewRect = [field convertRect:[field bounds] toView:nil];
198 NSPoint anchorPoint = NSMakePoint(NSMidX(viewRect), NSMinY(viewRect)); 191
192 // If a bubble at maximum size with a left-aligned edge would exceed the
193 // window width, align the right edge of bubble and view. In all other
194 // cases, left edge of bubble and view align.
Ilya Sherman 2013/11/22 04:32:10 nit: Suggested rephrasing: "In all other cases, al
groby-ooo-7-16 2013/11/22 04:50:15 Done.
195 NSPoint anchorPoint;
196 if ((NSMinX(viewRect) + [errorBubbleController_ maxWidth]) >
Ilya Sherman 2013/11/22 04:32:10 Hmm, why maxWidth rather than actual width?
groby-ooo-7-16 2013/11/22 04:50:15 If I don't do that, the arrow/edge alignment might
Ilya Sherman 2013/11/22 04:58:09 I see, that makes sense. Mind recording that as c
groby-ooo-7-16 2013/11/22 19:12:13 Done.
197 NSWidth([parentWindow frame])) {
Ilya Sherman 2013/11/22 04:32:10 Hmm, you're comparing a coordinate to a width. Is
groby-ooo-7-16 2013/11/22 04:50:15 That is indeed intentional. The viewRect is in the
Ilya Sherman 2013/11/22 04:58:09 Ah, I missed that the viewRect was guaranteed to b
groby-ooo-7-16 2013/11/22 19:12:13 Done.
198 anchorPoint = NSMakePoint(NSMaxX(viewRect), NSMinY(viewRect));
199 [[errorBubbleController_ bubble] setArrowLocation:info_bubble::kTopRight];
200 [[errorBubbleController_ bubble] setAlignment:
201 info_bubble::kAlignRightEdgeToAnchorEdge];
202
203 } else {
204 anchorPoint = NSMakePoint(NSMinX(viewRect), NSMinY(viewRect));
205 [[errorBubbleController_ bubble] setArrowLocation:info_bubble::kTopLeft];
206 [[errorBubbleController_ bubble] setAlignment:
207 info_bubble::kAlignLeftEdgeToAnchorEdge];
208 }
199 [errorBubbleController_ setAnchorPoint: 209 [errorBubbleController_ setAnchorPoint:
200 [parentWindow convertBaseToScreen:anchorPoint]]; 210 [parentWindow convertBaseToScreen:anchorPoint]];
201 211
202 [errorBubbleController_ showWindow:self]; 212 [errorBubbleController_ showWindow:self];
203 } 213 }
204 214
205 - (void)hideErrorBubble { 215 - (void)hideErrorBubble {
206 [errorBubble_ setHidden:YES]; 216 [errorBubble_ setHidden:YES];
207 } 217 }
208 218
(...skipping 11 matching lines...) Expand all
220 } 230 }
221 231
222 if ([field invalid]) { 232 if ([field invalid]) {
223 [self showErrorBubbleForField:field]; 233 [self showErrorBubbleForField:field];
224 } else { 234 } else {
225 [errorBubbleController_ close]; 235 [errorBubbleController_ close];
226 } 236 }
227 } 237 }
228 238
229 @end 239 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698