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

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

Issue 77283002: [rAc OSX] Factor out AutofillHeader class to contain dialog header elements. (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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/autofill/autofill_header.mm
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_header.mm b/chrome/browser/ui/cocoa/autofill/autofill_header.mm
new file mode 100644
index 0000000000000000000000000000000000000000..4783f278b0d4cc8f8f78a1c50c150049e59f338f
--- /dev/null
+++ b/chrome/browser/ui/cocoa/autofill/autofill_header.mm
@@ -0,0 +1,90 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/ui/cocoa/autofill/autofill_header.h"
+
+#import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h"
+#include "base/strings/sys_string_conversions.h"
+#include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
+#include "chrome/browser/ui/chrome_style.h"
+#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h"
+
+@implementation AutofillHeader
+
+- (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate {
+ if (self = [super initWithFrame:NSZeroRect]) {
+ delegate_ = delegate;
+
+ accountChooser_.reset(
+ [[AutofillAccountChooser alloc] initWithFrame:NSZeroRect
+ delegate:delegate]);
+
+ // Set dialog title.
+ title_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]);
+ [title_ setEditable:NO];
+ [title_ setBordered:NO];
+ [title_ setDrawsBackground:NO];
+ [title_ setFont:[NSFont systemFontOfSize:15.0]];
+ [title_ setStringValue:base::SysUTF16ToNSString(delegate_->DialogTitle())];
+ [title_ sizeToFit];
+
+ [self setSubviews:@[accountChooser_, title_]];
+ }
+ return self;
+}
+
+- (BOOL)isFlipped {
+ return YES;
+}
+
+- (NSView*)anchorView {
+ return [[accountChooser_ subviews] objectAtIndex:1];
+}
+
+- (void)update {
+ [accountChooser_ update];
+}
+
+- (CGFloat)heightForWidth:(int)width {
+ return chrome_style::kTitleTopPadding +
groby-ooo-7-16 2013/11/20 23:51:44 Why? Why not just have preferredSize return the ri
Ilya Sherman 2013/11/22 05:01:13 Well, I could do that right now, but I kept -heigh
groby-ooo-7-16 2013/11/22 14:51:37 If we need it anyways, that'd be kind of silly :)
Ilya Sherman 2013/11/23 00:23:54 Yeah, I was thinking about that too -- maybe heigh
+ autofill::kAccountChooserHeight +
+ autofill::kDetailVerticalPadding;
+}
+
+- (NSSize)preferredSize {
+ NOTREACHED(); // Only implemented as part of AutofillLayout protocol.
+ return NSZeroSize;
+}
+
+- (void)performLayout {
+ NSRect bounds = [self bounds];
+
+ // TODO(isherman): Can updating the title string value be moved into -update:
+ // instead of here?
+ [title_ setStringValue:base::SysUTF16ToNSString(delegate_->DialogTitle())];
groby-ooo-7-16 2013/11/20 23:51:44 Yes. No. Maybe. :) No, because it resizes a dialo
Ilya Sherman 2013/11/22 05:01:13 I'm doin' it! :)
groby-ooo-7-16 2013/11/22 14:51:37 You might want to pay close attention to the redr
+ [title_ sizeToFit];
+
+ // Align baseline of title with bottom of accountChooser.
+ base::scoped_nsobject<NSLayoutManager> layout_manager(
+ [[NSLayoutManager alloc] init]);
+ NSRect titleFrameRect = [title_ frame];
+ titleFrameRect.origin.x = chrome_style::kHorizontalPadding;
+ titleFrameRect.origin.y =
+ chrome_style::kTitleTopPadding + NSHeight(titleFrameRect) -
+ [layout_manager defaultBaselineOffsetForFont:[title_ font]];
+ [title_ setFrameOrigin:titleFrameRect.origin];
+
+ NSRect accountChooserFrameRect =
+ NSMakeRect(NSMaxX(titleFrameRect) + chrome_style::kHorizontalPadding,
+ chrome_style::kTitleTopPadding,
+ 0,
+ autofill::kAccountChooserHeight);
+ accountChooserFrameRect.size.width =
+ NSMaxX(bounds) - NSMinX(accountChooserFrameRect) -
+ chrome_style::kHorizontalPadding;
+ [accountChooser_ setFrame:accountChooserFrameRect];
+ [accountChooser_ performLayout];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698