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

Unified Diff: chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.mm

Issue 123703002: [rAC] Do not re-create bubble window unnecessarily (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix misspelled comment. Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.mm
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.mm b/chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.mm
index 1a26bdce55fedb4bd2f3309a49f58cfd79a41cb1..31aebc1891f9c377e50c562949059d52d151144d 100644
--- a/chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.mm
+++ b/chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.mm
@@ -18,6 +18,12 @@ const CGFloat kMaxLabelWidth =
} // namespace
+@interface AutofillBubbleController ()
+
+// Update the current message, keeping arrow location in place.
+- (void)updateMessage:(NSString*)message display:(BOOL)display;
+
+@end
@implementation AutofillBubbleController
@@ -51,19 +57,9 @@ const CGFloat kMaxLabelWidth =
[label_ setEditable:NO];
[label_ setBordered:NO];
[label_ setDrawsBackground:NO];
- [label_ setStringValue:message];
- NSRect labelFrame = NSMakeRect(inset.width, inset.height, 0, 0);
- labelFrame.size = [[label_ cell] cellSizeForBounds:
- NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)];
- [label_ setFrame:labelFrame];
[[self bubble] addSubview:label_];
- NSRect windowFrame = [[self window] frame];
- windowFrame.size = NSMakeSize(
- NSMaxX([label_ frame]),
- NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight);
- windowFrame = NSInsetRect(windowFrame, -inset.width, -inset.height);
- [[self window] setFrame:windowFrame display:NO];
+ [self updateMessage:message display:NO];
}
return self;
}
@@ -72,4 +68,32 @@ const CGFloat kMaxLabelWidth =
return kMaxLabelWidth + 2 * inset_.width;
}
+- (void)setMessage:(NSString*)message {
+ if ([[label_ stringValue] isEqualToString:message])
+ return;
+ [self updateMessage:message display:YES];
+}
+
+- (void)updateMessage:(NSString*)message display:(BOOL)display {
+ [label_ setStringValue:message];
+
+ NSRect labelFrame = NSMakeRect(inset_.width, inset_.height, 0, 0);
+ labelFrame.size = [[label_ cell] cellSizeForBounds:
+ NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)];
+ [label_ setFrame:labelFrame];
+
+ // Update window's size, but ensure the origin is maintained so that the arrow
+ // still points at the same location.
+ NSRect windowFrame = [[self window] frame];
+ NSPoint origin = windowFrame.origin;
+ origin.y += NSHeight(windowFrame);
+ windowFrame.size = NSMakeSize(
+ NSMaxX([label_ frame]),
+ NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight);
+ windowFrame = NSInsetRect(windowFrame, -inset_.width, -inset_.height);
+ origin.y -= NSHeight(windowFrame);
+ windowFrame.origin = origin;
+ [[self window] setFrame:windowFrame display:display];
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698