OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_suggestion_container.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | 13 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
14 #include "chrome/browser/ui/chrome_style.h" | 14 #include "chrome/browser/ui/chrome_style.h" |
15 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" | 15 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" |
16 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" | 16 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" |
17 #include "skia/ext/skia_utils_mac.h" | 17 #include "skia/ext/skia_utils_mac.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Horizontal padding between text and other elements (in pixels). | 21 // Horizontal padding between text and other elements (in pixels). |
22 const int kAroundTextPadding = 4; | 22 const int kAroundTextPadding = 4; |
23 | 23 |
24 // Vertical padding between individual elements. | 24 // Vertical padding between individual elements. |
25 const int kVerticalPadding = 8; | 25 const int kVerticalPadding = 8; |
26 | 26 |
27 // Centers |rect2| vertically in |rect1|, on an integral y coordinate. | 27 // Centers |rect2| vertically in |rect1|, on an integral y coordinate. |
28 // Assumes |rect1| has integral origin coordinates. | 28 // Assumes |rect1| has integral origin coordinates. |
29 NSRect CenterVertically(NSRect rect1, NSRect rect2) { | 29 NSRect CenterVertically(NSRect rect1, NSRect rect2) { |
30 DCHECK_LE(NSHeight(rect2), NSHeight(rect1)); | 30 DCHECK_LE(NSHeight(rect2), NSHeight(rect1)); |
31 CGFloat offset = (NSHeight(rect1) - NSHeight(rect2)) / 2.0; | 31 CGFloat offset = (NSHeight(rect1) - NSHeight(rect2)) / 2.0; |
32 rect2.origin.y = std::floor(rect1.origin.y + offset); | 32 rect2.origin.y = std::floor(rect1.origin.y + offset); |
33 return rect2; | 33 return rect2; |
34 } | 34 } |
35 | 35 |
36 } | 36 } |
37 | 37 |
38 @implementation AutofillSuggestionContainer | 38 @implementation AutofillSuggestionContainer |
39 | 39 |
40 - (NSTextField*)makeDetailSectionLabel:(NSString*)labelText { | 40 - (NSTextField*)makeDetailSectionLabel:(NSString*)labelText { |
41 scoped_nsobject<NSTextField> label([[NSTextField alloc] init]); | 41 base::scoped_nsobject<NSTextField> label([[NSTextField alloc] init]); |
42 [label setFont: | 42 [label setFont: |
43 [[NSFontManager sharedFontManager] convertFont:[label font] | 43 [[NSFontManager sharedFontManager] convertFont:[label font] |
44 toHaveTrait:NSBoldFontMask]]; | 44 toHaveTrait:NSBoldFontMask]]; |
45 [label setStringValue:labelText]; | 45 [label setStringValue:labelText]; |
46 [label setEditable:NO]; | 46 [label setEditable:NO]; |
47 [label setBordered:NO]; | 47 [label setBordered:NO]; |
48 [label sizeToFit]; | 48 [label sizeToFit]; |
49 return label.autorelease(); | 49 return label.autorelease(); |
50 } | 50 } |
51 | 51 |
52 - (void)loadView { | 52 - (void)loadView { |
53 label_.reset([[self createLabelWithFrame:NSZeroRect] retain]); | 53 label_.reset([[self createLabelWithFrame:NSZeroRect] retain]); |
54 label2_.reset([[self createLabelWithFrame:NSZeroRect] retain]); | 54 label2_.reset([[self createLabelWithFrame:NSZeroRect] retain]); |
55 | 55 |
56 iconImageView_.reset([[NSImageView alloc] initWithFrame:NSZeroRect]); | 56 iconImageView_.reset([[NSImageView alloc] initWithFrame:NSZeroRect]); |
57 [iconImageView_ setImageFrameStyle:NSImageFrameNone]; | 57 [iconImageView_ setImageFrameStyle:NSImageFrameNone]; |
58 [iconImageView_ setHidden:YES]; | 58 [iconImageView_ setHidden:YES]; |
59 | 59 |
60 inputField_.reset([[AutofillTextField alloc] initWithFrame:NSZeroRect]); | 60 inputField_.reset([[AutofillTextField alloc] initWithFrame:NSZeroRect]); |
61 [inputField_ setHidden:YES]; | 61 [inputField_ setHidden:YES]; |
62 | 62 |
63 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 63 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
64 [view setSubviews: | 64 [view setSubviews: |
65 @[iconImageView_, label_, inputField_, label2_ ]]; | 65 @[iconImageView_, label_, inputField_, label2_ ]]; |
66 [self setView:view]; | 66 [self setView:view]; |
67 } | 67 } |
68 | 68 |
69 - (NSTextField*)createLabelWithFrame:(NSRect)frame { | 69 - (NSTextField*)createLabelWithFrame:(NSRect)frame { |
70 scoped_nsobject<NSTextField> label( | 70 base::scoped_nsobject<NSTextField> label( |
71 [[NSTextField alloc] initWithFrame:frame]); | 71 [[NSTextField alloc] initWithFrame:frame]); |
72 [label setEditable:NO]; | 72 [label setEditable:NO]; |
73 [label setDrawsBackground:NO]; | 73 [label setDrawsBackground:NO]; |
74 [label setBordered:NO]; | 74 [label setBordered:NO]; |
75 return label.autorelease(); | 75 return label.autorelease(); |
76 } | 76 } |
77 | 77 |
78 // TODO(groby): Can we make all the individual setters private and just | 78 // TODO(groby): Can we make all the individual setters private and just |
79 // update state as a whole? | 79 // update state as a whole? |
80 - (void)setIcon:(NSImage*)iconImage { | 80 - (void)setIcon:(NSImage*)iconImage { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 NSWidth(inputfieldFrame) + kAroundTextPadding, NSMaxXEdge); | 167 NSWidth(inputfieldFrame) + kAroundTextPadding, NSMaxXEdge); |
168 } | 168 } |
169 | 169 |
170 [label_ setFrame:labelFrame]; | 170 [label_ setFrame:labelFrame]; |
171 [label2_ setFrameOrigin:NSMakePoint( | 171 [label2_ setFrameOrigin:NSMakePoint( |
172 0, | 172 0, |
173 NSMinY(lineFrame) - kAroundTextPadding - NSHeight([label2_ frame]))]; | 173 NSMinY(lineFrame) - kAroundTextPadding - NSHeight([label2_ frame]))]; |
174 [[self view] setFrameSize:preferredContainerSize]; | 174 [[self view] setFrameSize:preferredContainerSize]; |
175 } | 175 } |
176 | 176 |
177 @end | 177 @end |
OLD | NEW |