| 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 #include "skia/ext/skia_utils_mac.h" | 23 #include "skia/ext/skia_utils_mac.h" |
| 23 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 24 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 24 #include "ui/base/cocoa/window_size_constants.h" | 25 #include "ui/base/cocoa/window_size_constants.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/gfx/range/range.h" | 27 #include "ui/gfx/range/range.h" |
| 27 | 28 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 [[self view] addSubview:buttonStripImage_]; | 74 [[self view] addSubview:buttonStripImage_]; |
| 74 | 75 |
| 75 // Set up "Save in Chrome" checkbox. | 76 // Set up "Save in Chrome" checkbox. |
| 76 saveInChromeCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); | 77 saveInChromeCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); |
| 77 [saveInChromeCheckbox_ setButtonType:NSSwitchButton]; | 78 [saveInChromeCheckbox_ setButtonType:NSSwitchButton]; |
| 78 [saveInChromeCheckbox_ setTitle: | 79 [saveInChromeCheckbox_ setTitle: |
| 79 base::SysUTF16ToNSString(delegate_->SaveLocallyText())]; | 80 base::SysUTF16ToNSString(delegate_->SaveLocallyText())]; |
| 80 [saveInChromeCheckbox_ sizeToFit]; | 81 [saveInChromeCheckbox_ sizeToFit]; |
| 81 [[self view] addSubview:saveInChromeCheckbox_]; | 82 [[self view] addSubview:saveInChromeCheckbox_]; |
| 82 | 83 |
| 83 saveInChromeTooltip_.reset([[NSImageView alloc] initWithFrame:NSZeroRect]); | 84 saveInChromeTooltip_.reset( |
| 85 [[AutofillTooltipController alloc] init]); |
| 84 [saveInChromeTooltip_ setImage: | 86 [saveInChromeTooltip_ setImage: |
| 85 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 87 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 86 IDR_AUTOFILL_TOOLTIP_ICON).ToNSImage()]; | 88 IDR_AUTOFILL_TOOLTIP_ICON).ToNSImage()]; |
| 87 [saveInChromeTooltip_ setToolTip: | 89 [saveInChromeTooltip_ setMessage: |
| 88 base::SysUTF16ToNSString(delegate_->SaveLocallyTooltip())]; | 90 base::SysUTF16ToNSString(delegate_->SaveLocallyTooltip())]; |
| 89 [saveInChromeTooltip_ setFrameSize:[[saveInChromeTooltip_ image] size]]; | 91 [[self view] addSubview:[saveInChromeTooltip_ view]]; |
| 90 [[self view] addSubview:saveInChromeTooltip_]; | |
| 91 [self updateSaveInChrome]; | 92 [self updateSaveInChrome]; |
| 92 | 93 |
| 93 detailsContainer_.reset( | 94 detailsContainer_.reset( |
| 94 [[AutofillDetailsContainer alloc] initWithDelegate:delegate_]); | 95 [[AutofillDetailsContainer alloc] initWithDelegate:delegate_]); |
| 95 NSSize frameSize = [[detailsContainer_ view] frame].size; | 96 NSSize frameSize = [[detailsContainer_ view] frame].size; |
| 96 [[detailsContainer_ view] setFrameOrigin: | 97 [[detailsContainer_ view] setFrameOrigin: |
| 97 NSMakePoint(0, NSHeight([buttonContainer_ frame]))]; | 98 NSMakePoint(0, NSHeight([buttonContainer_ frame]))]; |
| 98 frameSize.height += NSHeight([buttonContainer_ frame]); | 99 frameSize.height += NSHeight([buttonContainer_ frame]); |
| 99 [[self view] setFrameSize:frameSize]; | 100 [[self view] setFrameSize:frameSize]; |
| 100 [[self view] addSubview:[detailsContainer_ view]]; | 101 [[self view] addSubview:[detailsContainer_ view]]; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 NSPoint walletIconOrigin = | 178 NSPoint walletIconOrigin = |
| 178 NSMakePoint(chrome_style::kHorizontalPadding, buttonFrame.origin.y); | 179 NSMakePoint(chrome_style::kHorizontalPadding, buttonFrame.origin.y); |
| 179 [buttonStripImage_ setFrameOrigin:walletIconOrigin]; | 180 [buttonStripImage_ setFrameOrigin:walletIconOrigin]; |
| 180 currentY = std::max(currentY, NSMaxY([buttonStripImage_ frame])); | 181 currentY = std::max(currentY, NSMaxY([buttonStripImage_ frame])); |
| 181 | 182 |
| 182 NSRect checkboxFrame = [saveInChromeCheckbox_ frame]; | 183 NSRect checkboxFrame = [saveInChromeCheckbox_ frame]; |
| 183 [saveInChromeCheckbox_ setFrameOrigin: | 184 [saveInChromeCheckbox_ setFrameOrigin: |
| 184 NSMakePoint(chrome_style::kHorizontalPadding, | 185 NSMakePoint(chrome_style::kHorizontalPadding, |
| 185 NSMidY(buttonFrame) - NSHeight(checkboxFrame) / 2.0)]; | 186 NSMidY(buttonFrame) - NSHeight(checkboxFrame) / 2.0)]; |
| 186 | 187 |
| 187 NSRect tooltipFrame = [saveInChromeTooltip_ frame]; | 188 NSRect tooltipFrame = [[saveInChromeTooltip_ view] frame]; |
| 188 [saveInChromeTooltip_ setFrameOrigin: | 189 [[saveInChromeTooltip_ view] setFrameOrigin: |
| 189 NSMakePoint(NSMaxX([saveInChromeCheckbox_ frame]) + autofill::kButtonGap, | 190 NSMakePoint(NSMaxX([saveInChromeCheckbox_ frame]) + autofill::kButtonGap, |
| 190 NSMidY(buttonFrame) - (NSHeight(tooltipFrame) / 2.0))]; | 191 NSMidY(buttonFrame) - (NSHeight(tooltipFrame) / 2.0))]; |
| 191 | 192 |
| 192 NSRect notificationFrame = NSZeroRect; | 193 NSRect notificationFrame = NSZeroRect; |
| 193 notificationFrame.size = [notificationContainer_ preferredSizeForWidth: | 194 notificationFrame.size = [notificationContainer_ preferredSizeForWidth: |
| 194 NSWidth(bounds)]; | 195 NSWidth(bounds)]; |
| 195 | 196 |
| 196 // Buttons/checkbox/legal take up lower part of view, notifications the | 197 // Buttons/checkbox/legal take up lower part of view, notifications the |
| 197 // upper part. Adjust the detailsContainer to take up the remainder. | 198 // upper part. Adjust the detailsContainer to take up the remainder. |
| 198 CGFloat remainingHeight = | 199 CGFloat remainingHeight = |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 - (void)setAnchorView:(NSView*)anchorView { | 339 - (void)setAnchorView:(NSView*)anchorView { |
| 339 [notificationContainer_ setAnchorView:anchorView]; | 340 [notificationContainer_ setAnchorView:anchorView]; |
| 340 } | 341 } |
| 341 | 342 |
| 342 - (BOOL)validate { | 343 - (BOOL)validate { |
| 343 return [detailsContainer_ validate]; | 344 return [detailsContainer_ validate]; |
| 344 } | 345 } |
| 345 | 346 |
| 346 - (void)updateSaveInChrome { | 347 - (void)updateSaveInChrome { |
| 347 [saveInChromeCheckbox_ setHidden:!delegate_->ShouldOfferToSaveInChrome()]; | 348 [saveInChromeCheckbox_ setHidden:!delegate_->ShouldOfferToSaveInChrome()]; |
| 348 [saveInChromeTooltip_ setHidden:[saveInChromeCheckbox_ isHidden]]; | 349 [[saveInChromeTooltip_ view] setHidden:[saveInChromeCheckbox_ isHidden]]; |
| 349 [saveInChromeCheckbox_ setState: | 350 [saveInChromeCheckbox_ setState: |
| 350 (delegate_->ShouldSaveInChrome() ? NSOnState : NSOffState)]; | 351 (delegate_->ShouldSaveInChrome() ? NSOnState : NSOffState)]; |
| 351 } | 352 } |
| 352 | 353 |
| 353 - (void)makeFirstInvalidInputFirstResponder { | 354 - (void)makeFirstInvalidInputFirstResponder { |
| 354 NSView* field = [detailsContainer_ firstInvalidField]; | 355 NSView* field = [detailsContainer_ firstInvalidField]; |
| 355 if (!field) | 356 if (!field) |
| 356 return; | 357 return; |
| 357 | 358 |
| 358 [detailsContainer_ scrollToView:field]; | 359 [detailsContainer_ scrollToView:field]; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 378 @implementation AutofillMainContainer (Testing) | 379 @implementation AutofillMainContainer (Testing) |
| 379 | 380 |
| 380 - (NSButton*)saveInChromeCheckboxForTesting { | 381 - (NSButton*)saveInChromeCheckboxForTesting { |
| 381 return saveInChromeCheckbox_.get(); | 382 return saveInChromeCheckbox_.get(); |
| 382 } | 383 } |
| 383 | 384 |
| 384 - (NSImageView*)buttonStripImageForTesting { | 385 - (NSImageView*)buttonStripImageForTesting { |
| 385 return buttonStripImage_.get(); | 386 return buttonStripImage_.get(); |
| 386 } | 387 } |
| 387 | 388 |
| 388 - (NSImageView*)saveInChromeTooltipForTesting { | 389 - (NSButton*)saveInChromeTooltipForTesting { |
| 389 return saveInChromeTooltip_.get(); | 390 return base::mac::ObjCCast<NSButton>([saveInChromeTooltip_ view]); |
| 390 } | 391 } |
| 391 | 392 |
| 392 @end | 393 @end |
| OLD | NEW |