OLD | NEW |
---|---|
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_main_container.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" | 12 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" |
13 #include "chrome/browser/ui/chrome_style.h" | 13 #include "chrome/browser/ui/chrome_style.h" |
14 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" | 14 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" |
15 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 15 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
16 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" | 16 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" |
17 #import "chrome/browser/ui/cocoa/autofill/autofill_notification_container.h" | 17 #import "chrome/browser/ui/cocoa/autofill/autofill_notification_container.h" |
18 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 18 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
19 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 19 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
22 #include "skia/ext/skia_utils_mac.h" | |
22 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 23 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
23 #include "ui/base/cocoa/window_size_constants.h" | 24 #include "ui/base/cocoa/window_size_constants.h" |
24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/gfx/range/range.h" | 26 #include "ui/gfx/range/range.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // Padding between buttons and the last suggestion or details view. The mock | 30 // Padding between buttons and the last suggestion or details view. The mock |
30 // has a total of 30px - but 10px are already provided by details/suggestions. | 31 // has a total of 30px - but 10px are already provided by details/suggestions. |
31 const CGFloat kButtonVerticalPadding = 20.0; | 32 const CGFloat kButtonVerticalPadding = 20.0; |
32 | 33 |
34 // Padding around the text for the legal documents. | |
35 const CGFloat kLegalDocumentsPadding = 20.0; | |
36 | |
37 // The font color for the legal documents text. Set to match the Views | |
38 // implementation. | |
39 const SkColor kLegalDocumentsTextColor = SkColorSetRGB(102, 102, 102); | |
groby-ooo-7-16
2013/11/22 14:03:28
Doesn't this add a static ctor?
Ilya Sherman
2013/11/22 22:13:52
Nope, because SkColor is defined as "typedef uint3
groby-ooo-7-16
2013/11/22 22:23:48
Yes, but SkColorSetRGB is a function - which needs
Ilya Sherman
2013/11/22 22:26:38
Pretty sure that's fine, as there aren't any objec
| |
40 | |
33 } // namespace | 41 } // namespace |
34 | 42 |
35 @interface AutofillMainContainer (Private) | 43 @interface AutofillMainContainer (Private) |
36 - (void)buildWindowButtons; | 44 - (void)buildWindowButtons; |
37 - (void)layoutButtons; | 45 - (void)layoutButtons; |
38 - (void)updateButtons; | 46 - (void)updateButtons; |
39 - (NSSize)preferredLegalDocumentSizeForWidth:(CGFloat)width; | 47 - (NSSize)preferredLegalDocumentSizeForWidth:(CGFloat)width; |
40 @end | 48 @end |
41 | 49 |
42 | 50 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 | 101 |
94 legalDocumentsView_.reset( | 102 legalDocumentsView_.reset( |
95 [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]); | 103 [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]); |
96 [legalDocumentsView_ setEditable:NO]; | 104 [legalDocumentsView_ setEditable:NO]; |
97 [legalDocumentsView_ setBackgroundColor: | 105 [legalDocumentsView_ setBackgroundColor: |
98 [NSColor colorWithCalibratedRed:0.96 | 106 [NSColor colorWithCalibratedRed:0.96 |
99 green:0.96 | 107 green:0.96 |
100 blue:0.96 | 108 blue:0.96 |
101 alpha:1.0]]; | 109 alpha:1.0]]; |
102 [legalDocumentsView_ setDrawsBackground:YES]; | 110 [legalDocumentsView_ setDrawsBackground:YES]; |
111 [legalDocumentsView_ setTextContainerInset: | |
112 NSMakeSize(kLegalDocumentsPadding, kLegalDocumentsPadding)]; | |
103 [legalDocumentsView_ setHidden:YES]; | 113 [legalDocumentsView_ setHidden:YES]; |
104 [legalDocumentsView_ setDelegate:self]; | 114 [legalDocumentsView_ setDelegate:self]; |
105 legalDocumentsSizeDirty_ = YES; | 115 legalDocumentsSizeDirty_ = YES; |
106 [[self view] addSubview:legalDocumentsView_]; | 116 [[self view] addSubview:legalDocumentsView_]; |
107 | 117 |
108 notificationContainer_.reset( | 118 notificationContainer_.reset( |
109 [[AutofillNotificationContainer alloc] initWithDelegate:delegate_]); | 119 [[AutofillNotificationContainer alloc] initWithDelegate:delegate_]); |
110 [[self view] addSubview:[notificationContainer_ view]]; | 120 [[self view] addSubview:[notificationContainer_ view]]; |
111 } | 121 } |
112 | 122 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 // Now use the layout manager to compute layout. | 270 // Now use the layout manager to compute layout. |
261 NSLayoutManager* layoutManager = [legalDocumentsView_ layoutManager]; | 271 NSLayoutManager* layoutManager = [legalDocumentsView_ layoutManager]; |
262 NSTextContainer* textContainer = [legalDocumentsView_ textContainer]; | 272 NSTextContainer* textContainer = [legalDocumentsView_ textContainer]; |
263 [layoutManager ensureLayoutForTextContainer:textContainer]; | 273 [layoutManager ensureLayoutForTextContainer:textContainer]; |
264 NSRect newFrame = [layoutManager usedRectForTextContainer:textContainer]; | 274 NSRect newFrame = [layoutManager usedRectForTextContainer:textContainer]; |
265 | 275 |
266 // And finally, restore old frame. | 276 // And finally, restore old frame. |
267 [legalDocumentsView_ setFrame:currentFrame]; | 277 [legalDocumentsView_ setFrame:currentFrame]; |
268 newFrame.size.width = width; | 278 newFrame.size.width = width; |
269 | 279 |
280 // Account for the padding around the text. | |
281 newFrame.size.height += 2 * kLegalDocumentsPadding; | |
282 | |
270 legalDocumentsSizeDirty_ = NO; | 283 legalDocumentsSizeDirty_ = NO; |
271 legalDocumentsSize_ = newFrame.size; | 284 legalDocumentsSize_ = newFrame.size; |
272 return legalDocumentsSize_; | 285 return legalDocumentsSize_; |
273 } | 286 } |
274 | 287 |
275 - (AutofillSectionContainer*)sectionForId:(autofill::DialogSection)section { | 288 - (AutofillSectionContainer*)sectionForId:(autofill::DialogSection)section { |
276 return [detailsContainer_ sectionForId:section]; | 289 return [detailsContainer_ sectionForId:section]; |
277 } | 290 } |
278 | 291 |
279 - (void)modelChanged { | 292 - (void)modelChanged { |
280 [self updateSaveInChrome]; | 293 [self updateSaveInChrome]; |
281 [self updateWalletIcon]; | 294 [self updateWalletIcon]; |
282 [self updateButtons]; | 295 [self updateButtons]; |
283 [detailsContainer_ modelChanged]; | 296 [detailsContainer_ modelChanged]; |
284 } | 297 } |
285 | 298 |
286 - (BOOL)saveDetailsLocally { | 299 - (BOOL)saveDetailsLocally { |
287 return [saveInChromeCheckbox_ state] == NSOnState; | 300 return [saveInChromeCheckbox_ state] == NSOnState; |
288 } | 301 } |
289 | 302 |
290 - (void)updateLegalDocuments { | 303 - (void)updateLegalDocuments { |
291 NSString* text = base::SysUTF16ToNSString(delegate_->LegalDocumentsText()); | 304 NSString* text = base::SysUTF16ToNSString(delegate_->LegalDocumentsText()); |
292 | 305 |
293 if ([text length]) { | 306 if ([text length]) { |
294 NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; | 307 NSFont* font = |
295 [legalDocumentsView_ setMessage:text | 308 [NSFont labelFontOfSize:[[legalDocumentsView_ font] pointSize]]; |
296 withFont:font | 309 NSColor* color = gfx::SkColorToCalibratedNSColor(kLegalDocumentsTextColor); |
297 messageColor:[NSColor blackColor]]; | 310 [legalDocumentsView_ setMessage:text withFont:font messageColor:color]; |
298 | 311 |
299 const std::vector<gfx::Range>& link_ranges = | 312 const std::vector<gfx::Range>& link_ranges = |
300 delegate_->LegalDocumentLinks(); | 313 delegate_->LegalDocumentLinks(); |
301 for (size_t i = 0; i < link_ranges.size(); ++i) { | 314 for (size_t i = 0; i < link_ranges.size(); ++i) { |
302 NSRange range = link_ranges[i].ToNSRange(); | 315 NSRange range = link_ranges[i].ToNSRange(); |
303 [legalDocumentsView_ addLinkRange:range | 316 [legalDocumentsView_ addLinkRange:range |
304 withName:@(i) | 317 withName:@(i) |
305 linkColor:[NSColor blueColor]]; | 318 linkColor:[NSColor blueColor]]; |
306 } | 319 } |
307 legalDocumentsSizeDirty_ = YES; | 320 legalDocumentsSizeDirty_ = YES; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 | 382 |
370 - (NSImageView*)buttonStripImageForTesting { | 383 - (NSImageView*)buttonStripImageForTesting { |
371 return buttonStripImage_.get(); | 384 return buttonStripImage_.get(); |
372 } | 385 } |
373 | 386 |
374 - (NSImageView*)saveInChromeTooltipForTesting { | 387 - (NSImageView*)saveInChromeTooltipForTesting { |
375 return saveInChromeTooltip_.get(); | 388 return saveInChromeTooltip_.get(); |
376 } | 389 } |
377 | 390 |
378 @end | 391 @end |
OLD | NEW |