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_overlay_controller.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_overlay_controller.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 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 (const std::vector<autofill::DialogOverlayString>&)messages; | 107 (const std::vector<autofill::DialogOverlayString>&)messages; |
108 @end | 108 @end |
109 | 109 |
110 | 110 |
111 @implementation AutofillMessageStackView | 111 @implementation AutofillMessageStackView |
112 | 112 |
113 - (void)drawRect:(NSRect)dirtyRect { | 113 - (void)drawRect:(NSRect)dirtyRect { |
114 NSColor* shadingColor = gfx::SkColorToCalibratedNSColor(kShadingColor); | 114 NSColor* shadingColor = gfx::SkColorToCalibratedNSColor(kShadingColor); |
115 NSColor* borderColor = gfx::SkColorToCalibratedNSColor(kSubtleBorderColor); | 115 NSColor* borderColor = gfx::SkColorToCalibratedNSColor(kSubtleBorderColor); |
116 | 116 |
117 CGFloat arrowHalfWidth = kArrowWidth / 2.0; | 117 CGFloat arrowHalfWidth = autofill::kArrowWidth / 2.0; |
118 NSRect bounds = [self bounds]; | 118 NSRect bounds = [self bounds]; |
119 CGFloat y = NSMaxY(bounds) - kArrowHeight; | 119 CGFloat y = NSMaxY(bounds) - autofill::kArrowHeight; |
120 | 120 |
121 NSBezierPath* arrow = [NSBezierPath bezierPath]; | 121 NSBezierPath* arrow = [NSBezierPath bezierPath]; |
122 // Note that we purposely draw slightly outside of |bounds| so that the | 122 // Note that we purposely draw slightly outside of |bounds| so that the |
123 // stroke is hidden on the sides and bottom. | 123 // stroke is hidden on the sides and bottom. |
124 NSRect arrowBounds = NSInsetRect(bounds, -1, -1); | 124 NSRect arrowBounds = NSInsetRect(bounds, -1, -1); |
125 arrowBounds.size.height--; | 125 arrowBounds.size.height--; |
126 [arrow moveToPoint:NSMakePoint(NSMinX(arrowBounds), y)]; | 126 [arrow moveToPoint:NSMakePoint(NSMinX(arrowBounds), y)]; |
127 [arrow lineToPoint: | 127 [arrow lineToPoint: |
128 NSMakePoint(NSMidX(arrowBounds) - arrowHalfWidth, y)]; | 128 NSMakePoint(NSMidX(arrowBounds) - arrowHalfWidth, y)]; |
129 [arrow relativeLineToPoint:NSMakePoint(arrowHalfWidth, kArrowHeight)]; | 129 [arrow relativeLineToPoint: |
130 [arrow relativeLineToPoint:NSMakePoint(arrowHalfWidth, -kArrowHeight)]; | 130 NSMakePoint(arrowHalfWidth,autofill::kArrowHeight)]; |
| 131 [arrow relativeLineToPoint: |
| 132 NSMakePoint(arrowHalfWidth, -autofill::kArrowHeight)]; |
131 [arrow lineToPoint:NSMakePoint(NSMaxX(arrowBounds), y)]; | 133 [arrow lineToPoint:NSMakePoint(NSMaxX(arrowBounds), y)]; |
132 [arrow lineToPoint:NSMakePoint(NSMaxX(arrowBounds), NSMinY(arrowBounds))]; | 134 [arrow lineToPoint:NSMakePoint(NSMaxX(arrowBounds), NSMinY(arrowBounds))]; |
133 [arrow lineToPoint:NSMakePoint(NSMinX(arrowBounds), NSMinY(arrowBounds))]; | 135 [arrow lineToPoint:NSMakePoint(NSMinX(arrowBounds), NSMinY(arrowBounds))]; |
134 [arrow closePath]; | 136 [arrow closePath]; |
135 | 137 |
136 [shadingColor setFill]; | 138 [shadingColor setFill]; |
137 [arrow fill]; | 139 [arrow fill]; |
138 [borderColor setStroke]; | 140 [borderColor setStroke]; |
139 [arrow stroke]; | 141 [arrow stroke]; |
140 } | 142 } |
141 | 143 |
142 - (CGFloat)heightForWidth:(CGFloat)width { | 144 - (CGFloat)heightForWidth:(CGFloat)width { |
143 CGFloat height = kOverlayTextInterlineSpacing; | 145 CGFloat height = kOverlayTextInterlineSpacing; |
144 for (NSTextView* label in [self subviews]) { | 146 for (NSTextView* label in [self subviews]) { |
145 height += NSHeight([label frame]); | 147 height += NSHeight([label frame]); |
146 height += kOverlayTextInterlineSpacing; | 148 height += kOverlayTextInterlineSpacing; |
147 } | 149 } |
148 return height + kArrowHeight; | 150 return height + autofill::kArrowHeight; |
149 } | 151 } |
150 | 152 |
151 - (void)setMessages: | 153 - (void)setMessages: |
152 (const std::vector<autofill::DialogOverlayString>&) messages { | 154 (const std::vector<autofill::DialogOverlayString>&) messages { |
153 // We probably want to look at other multi-line messages somewhere. | 155 // We probably want to look at other multi-line messages somewhere. |
154 base::scoped_nsobject<NSMutableArray> labels( | 156 base::scoped_nsobject<NSMutableArray> labels( |
155 [[NSMutableArray alloc] initWithCapacity:messages.size()]); | 157 [[NSMutableArray alloc] initWithCapacity:messages.size()]); |
156 for (size_t i = 0; i < messages.size(); ++i) { | 158 for (size_t i = 0; i < messages.size(); ++i) { |
157 base::scoped_nsobject<NSTextField> label( | 159 base::scoped_nsobject<NSTextField> label( |
158 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 160 [[NSTextField alloc] initWithFrame:NSZeroRect]); |
159 | 161 |
160 NSFont* labelFont = messages[i].font.GetNativeFont(); | 162 NSFont* labelFont = messages[i].font.GetNativeFont(); |
161 [label setEditable:NO]; | 163 [label setEditable:NO]; |
162 [label setBordered:NO]; | 164 [label setBordered:NO]; |
163 [label setDrawsBackground:NO]; | 165 [label setDrawsBackground:NO]; |
164 [label setFont:labelFont]; | 166 [label setFont:labelFont]; |
165 [label setStringValue:base::SysUTF16ToNSString(messages[i].text)]; | 167 [label setStringValue:base::SysUTF16ToNSString(messages[i].text)]; |
166 [label setTextColor:gfx::SkColorToDeviceNSColor(messages[i].text_color)]; | 168 [label setTextColor:gfx::SkColorToDeviceNSColor(messages[i].text_color)]; |
167 DCHECK_EQ(messages[i].alignment, gfx::ALIGN_CENTER); | 169 DCHECK_EQ(messages[i].alignment, gfx::ALIGN_CENTER); |
168 [label setAlignment:NSCenterTextAlignment]; | 170 [label setAlignment:NSCenterTextAlignment]; |
169 [label sizeToFit]; | 171 [label sizeToFit]; |
170 | 172 |
171 [labels addObject:label]; | 173 [labels addObject:label]; |
172 } | 174 } |
173 [self setSubviews:labels]; | 175 [self setSubviews:labels]; |
174 [self setHidden:([labels count] == 0)]; | 176 [self setHidden:([labels count] == 0)]; |
175 } | 177 } |
176 | 178 |
177 - (void)performLayout { | 179 - (void)performLayout { |
178 CGFloat y = | 180 CGFloat y = NSMaxY([self bounds]) - autofill::kArrowHeight - |
179 NSMaxY([self bounds]) - kArrowHeight - kOverlayTextInterlineSpacing; | 181 kOverlayTextInterlineSpacing; |
180 for (NSTextView* label in [self subviews]) { | 182 for (NSTextView* label in [self subviews]) { |
181 DCHECK([label isKindOfClass:[NSTextView class]]); | 183 DCHECK([label isKindOfClass:[NSTextView class]]); |
182 CGFloat labelHeight = NSHeight([label frame]); | 184 CGFloat labelHeight = NSHeight([label frame]); |
183 [label setFrame:NSMakeRect(0, y - labelHeight, | 185 [label setFrame:NSMakeRect(0, y - labelHeight, |
184 NSWidth([self bounds]), labelHeight)]; | 186 NSWidth([self bounds]), labelHeight)]; |
185 y = NSMinY([label frame]) - kOverlayTextInterlineSpacing; | 187 y = NSMinY([label frame]) - kOverlayTextInterlineSpacing; |
186 } | 188 } |
187 DCHECK_GT(0.0, y); | 189 DCHECK_GT(0.0, y); |
188 } | 190 } |
189 | 191 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 334 } |
333 } | 335 } |
334 | 336 |
335 - (void)animationEnded:(const ui::Animation*)animation { | 337 - (void)animationEnded:(const ui::Animation*)animation { |
336 DCHECK_EQ(animation, fadeOutAnimation_.get()); | 338 DCHECK_EQ(animation, fadeOutAnimation_.get()); |
337 [[self view] setHidden:YES]; | 339 [[self view] setHidden:YES]; |
338 fadeOutAnimation_.reset(); | 340 fadeOutAnimation_.reset(); |
339 } | 341 } |
340 | 342 |
341 @end | 343 @end |
OLD | NEW |