| 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/autofill/autofill_tooltip_controller.h" |
| 18 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 19 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
| 19 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 20 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
| 20 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 21 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.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 { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 [[self view] addSubview:buttonStripImage_]; | 66 [[self view] addSubview:buttonStripImage_]; |
| 66 | 67 |
| 67 // Set up "Save in Chrome" checkbox. | 68 // Set up "Save in Chrome" checkbox. |
| 68 saveInChromeCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); | 69 saveInChromeCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); |
| 69 [saveInChromeCheckbox_ setButtonType:NSSwitchButton]; | 70 [saveInChromeCheckbox_ setButtonType:NSSwitchButton]; |
| 70 [saveInChromeCheckbox_ setTitle: | 71 [saveInChromeCheckbox_ setTitle: |
| 71 base::SysUTF16ToNSString(delegate_->SaveLocallyText())]; | 72 base::SysUTF16ToNSString(delegate_->SaveLocallyText())]; |
| 72 [saveInChromeCheckbox_ sizeToFit]; | 73 [saveInChromeCheckbox_ sizeToFit]; |
| 73 [[self view] addSubview:saveInChromeCheckbox_]; | 74 [[self view] addSubview:saveInChromeCheckbox_]; |
| 74 | 75 |
| 75 saveInChromeTooltip_.reset([[NSImageView alloc] initWithFrame:NSZeroRect]); | 76 saveInChromeTooltip_.reset( |
| 77 [[AutofillTooltipController alloc] init]); |
| 76 [saveInChromeTooltip_ setImage: | 78 [saveInChromeTooltip_ setImage: |
| 77 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 79 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 78 IDR_AUTOFILL_TOOLTIP_ICON).ToNSImage()]; | 80 IDR_AUTOFILL_TOOLTIP_ICON).ToNSImage()]; |
| 79 [saveInChromeTooltip_ setToolTip: | 81 [saveInChromeTooltip_ setMessage: |
| 80 base::SysUTF16ToNSString(delegate_->SaveLocallyTooltip())]; | 82 base::SysUTF16ToNSString(delegate_->SaveLocallyTooltip())]; |
| 81 [saveInChromeTooltip_ setFrameSize:[[saveInChromeTooltip_ image] size]]; | 83 [[self view] addSubview:[saveInChromeTooltip_ view]]; |
| 82 [[self view] addSubview:saveInChromeTooltip_]; | |
| 83 [self updateSaveInChrome]; | 84 [self updateSaveInChrome]; |
| 84 | 85 |
| 85 detailsContainer_.reset( | 86 detailsContainer_.reset( |
| 86 [[AutofillDetailsContainer alloc] initWithDelegate:delegate_]); | 87 [[AutofillDetailsContainer alloc] initWithDelegate:delegate_]); |
| 87 NSSize frameSize = [[detailsContainer_ view] frame].size; | 88 NSSize frameSize = [[detailsContainer_ view] frame].size; |
| 88 [[detailsContainer_ view] setFrameOrigin: | 89 [[detailsContainer_ view] setFrameOrigin: |
| 89 NSMakePoint(0, NSHeight([buttonContainer_ frame]))]; | 90 NSMakePoint(0, NSHeight([buttonContainer_ frame]))]; |
| 90 frameSize.height += NSHeight([buttonContainer_ frame]); | 91 frameSize.height += NSHeight([buttonContainer_ frame]); |
| 91 [[self view] setFrameSize:frameSize]; | 92 [[self view] setFrameSize:frameSize]; |
| 92 [[self view] addSubview:[detailsContainer_ view]]; | 93 [[self view] addSubview:[detailsContainer_ view]]; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 NSPoint walletIconOrigin = | 167 NSPoint walletIconOrigin = |
| 167 NSMakePoint(chrome_style::kHorizontalPadding, buttonFrame.origin.y); | 168 NSMakePoint(chrome_style::kHorizontalPadding, buttonFrame.origin.y); |
| 168 [buttonStripImage_ setFrameOrigin:walletIconOrigin]; | 169 [buttonStripImage_ setFrameOrigin:walletIconOrigin]; |
| 169 currentY = std::max(currentY, NSMaxY([buttonStripImage_ frame])); | 170 currentY = std::max(currentY, NSMaxY([buttonStripImage_ frame])); |
| 170 | 171 |
| 171 NSRect checkboxFrame = [saveInChromeCheckbox_ frame]; | 172 NSRect checkboxFrame = [saveInChromeCheckbox_ frame]; |
| 172 [saveInChromeCheckbox_ setFrameOrigin: | 173 [saveInChromeCheckbox_ setFrameOrigin: |
| 173 NSMakePoint(chrome_style::kHorizontalPadding, | 174 NSMakePoint(chrome_style::kHorizontalPadding, |
| 174 NSMidY(buttonFrame) - NSHeight(checkboxFrame) / 2.0)]; | 175 NSMidY(buttonFrame) - NSHeight(checkboxFrame) / 2.0)]; |
| 175 | 176 |
| 176 NSRect tooltipFrame = [saveInChromeTooltip_ frame]; | 177 NSRect tooltipFrame = [[saveInChromeTooltip_ view] frame]; |
| 177 [saveInChromeTooltip_ setFrameOrigin: | 178 [[saveInChromeTooltip_ view] setFrameOrigin: |
| 178 NSMakePoint(NSMaxX([saveInChromeCheckbox_ frame]) + autofill::kButtonGap, | 179 NSMakePoint(NSMaxX([saveInChromeCheckbox_ frame]) + autofill::kButtonGap, |
| 179 NSMidY(buttonFrame) - (NSHeight(tooltipFrame) / 2.0))]; | 180 NSMidY(buttonFrame) - (NSHeight(tooltipFrame) / 2.0))]; |
| 180 | 181 |
| 181 NSRect notificationFrame = NSZeroRect; | 182 NSRect notificationFrame = NSZeroRect; |
| 182 notificationFrame.size = [notificationContainer_ preferredSizeForWidth: | 183 notificationFrame.size = [notificationContainer_ preferredSizeForWidth: |
| 183 NSWidth(bounds)]; | 184 NSWidth(bounds)]; |
| 184 | 185 |
| 185 // Buttons/checkbox/legal take up lower part of view, notifications the | 186 // Buttons/checkbox/legal take up lower part of view, notifications the |
| 186 // upper part. Adjust the detailsContainer to take up the remainder. | 187 // upper part. Adjust the detailsContainer to take up the remainder. |
| 187 CGFloat remainingHeight = | 188 CGFloat remainingHeight = |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 - (void)setAnchorView:(NSView*)anchorView { | 325 - (void)setAnchorView:(NSView*)anchorView { |
| 325 [notificationContainer_ setAnchorView:anchorView]; | 326 [notificationContainer_ setAnchorView:anchorView]; |
| 326 } | 327 } |
| 327 | 328 |
| 328 - (BOOL)validate { | 329 - (BOOL)validate { |
| 329 return [detailsContainer_ validate]; | 330 return [detailsContainer_ validate]; |
| 330 } | 331 } |
| 331 | 332 |
| 332 - (void)updateSaveInChrome { | 333 - (void)updateSaveInChrome { |
| 333 [saveInChromeCheckbox_ setHidden:!delegate_->ShouldOfferToSaveInChrome()]; | 334 [saveInChromeCheckbox_ setHidden:!delegate_->ShouldOfferToSaveInChrome()]; |
| 334 [saveInChromeTooltip_ setHidden:[saveInChromeCheckbox_ isHidden]]; | 335 [[saveInChromeTooltip_ view] setHidden:[saveInChromeCheckbox_ isHidden]]; |
| 335 [saveInChromeCheckbox_ setState: | 336 [saveInChromeCheckbox_ setState: |
| 336 (delegate_->ShouldSaveInChrome() ? NSOnState : NSOffState)]; | 337 (delegate_->ShouldSaveInChrome() ? NSOnState : NSOffState)]; |
| 337 } | 338 } |
| 338 | 339 |
| 339 - (void)makeFirstInvalidInputFirstResponder { | 340 - (void)makeFirstInvalidInputFirstResponder { |
| 340 NSView* field = [detailsContainer_ firstInvalidField]; | 341 NSView* field = [detailsContainer_ firstInvalidField]; |
| 341 if (!field) | 342 if (!field) |
| 342 return; | 343 return; |
| 343 | 344 |
| 344 [detailsContainer_ scrollToView:field]; | 345 [detailsContainer_ scrollToView:field]; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 364 @implementation AutofillMainContainer (Testing) | 365 @implementation AutofillMainContainer (Testing) |
| 365 | 366 |
| 366 - (NSButton*)saveInChromeCheckboxForTesting { | 367 - (NSButton*)saveInChromeCheckboxForTesting { |
| 367 return saveInChromeCheckbox_.get(); | 368 return saveInChromeCheckbox_.get(); |
| 368 } | 369 } |
| 369 | 370 |
| 370 - (NSImageView*)buttonStripImageForTesting { | 371 - (NSImageView*)buttonStripImageForTesting { |
| 371 return buttonStripImage_.get(); | 372 return buttonStripImage_.get(); |
| 372 } | 373 } |
| 373 | 374 |
| 374 - (NSImageView*)saveInChromeTooltipForTesting { | 375 - (NSButton*)saveInChromeTooltipForTesting { |
| 375 return saveInChromeTooltip_.get(); | 376 return base::mac::ObjCCast<NSButton>([saveInChromeTooltip_ view]); |
| 376 } | 377 } |
| 377 | 378 |
| 378 @end | 379 @end |
| OLD | NEW |