Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1895)

Unified Diff: chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm

Issue 267183002: Password manager: Implement password generation UI for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm b/chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm
index 356f79584bb0b76af00e593ea71c498b0ac036d9..8807dcb3acafc5e3492e51dc92f448ea07ba71be 100644
--- a/chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm
+++ b/chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm
@@ -11,6 +11,7 @@
#include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h"
#include "components/autofill/core/browser/popup_item_ids.h"
#include "grit/ui_resources.h"
+#include "ui/base/cocoa/window_size_constants.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/image/image.h"
@@ -19,47 +20,11 @@
using autofill::AutofillPopupView;
-namespace {
-
-NSColor* BackgroundColor() {
- return [NSColor whiteColor];
-}
-
-// The color of the border around the popup.
-NSColor* BorderColor() {
- return [NSColor colorForControlTint:[NSColor currentControlTint]];
-}
-
-NSColor* SeparatorColor() {
- return [NSColor colorWithCalibratedWhite:220 / 255.0 alpha:1];
-}
-
-NSColor* HighlightColor() {
- return [NSColor selectedControlColor];
-}
-
-NSColor* NameColor() {
- return [NSColor blackColor];
-}
-
-NSColor* WarningColor() {
- return [NSColor grayColor];
-}
-
-NSColor* SubtextColor() {
- return [NSColor grayColor];
-}
-
-} // namespace
+@interface AutofillPopupViewCocoa ()
#pragma mark -
#pragma mark Private methods
-@interface AutofillPopupViewCocoa ()
-
-// Draws a thin separator in the popup UI.
-- (void)drawSeparatorWithBounds:(NSRect)bounds;
-
// Draws an Autofill suggestion in the given |bounds|, labeled with the given
// |name| and |subtext| hint. If the suggestion |isSelected|, then it is drawn
// with a highlight. |index| determines the font to use, as well as the icon,
@@ -88,7 +53,7 @@ NSColor* SubtextColor() {
- (id)initWithController:(autofill::AutofillPopupController*)controller
frame:(NSRect)frame {
- self = [super initWithFrame:frame];
+ self = [super initWithDelegate:controller frame:frame];
if (self)
controller_ = controller;
@@ -98,35 +63,12 @@ NSColor* SubtextColor() {
#pragma mark -
#pragma mark NSView implementation:
-// A slight optimization for drawing:
-// https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaViewsGuide/Optimizing/Optimizing.html
-- (BOOL)isOpaque {
- return YES;
-}
-
-- (BOOL)isFlipped {
- // Flipped so that it's easier to share controller logic with other OSes.
- return YES;
-}
-
- (void)drawRect:(NSRect)dirtyRect {
// If the view is in the process of being destroyed, don't bother drawing.
if (!controller_)
return;
- // Draw the popup's background and border.
- // The inset is needed since the border is centered on the |path|.
- // TODO(isherman): We should consider using asset-based drawing for the
- // border, creating simple bitmaps for the view's border and background, and
- // drawing them using NSDrawNinePartImage().
- CGFloat inset = autofill::kPopupBorderThickness / 2.0;
- NSRect borderRect = NSInsetRect([self bounds], inset, inset);
- NSBezierPath* path = [NSBezierPath bezierPathWithRect:borderRect];
- [BackgroundColor() setFill];
- [path fill];
- [path setLineWidth:autofill::kPopupBorderThickness];
- [BorderColor() setStroke];
- [path stroke];
+ [self drawBackgroundAndBorder];
for (size_t i = 0; i < controller_->names().size(); ++i) {
// Skip rows outside of the dirty rect.
@@ -150,43 +92,6 @@ NSColor* SubtextColor() {
}
}
-- (void)mouseUp:(NSEvent*)theEvent {
- // If the view is in the process of being destroyed, abort.
- if (!controller_)
- return;
-
- NSPoint location = [self convertPoint:[theEvent locationInWindow]
- fromView:nil];
-
- if (NSPointInRect(location, [self bounds])) {
- controller_->SetSelectionAtPoint(gfx::Point(NSPointToCGPoint(location)));
- controller_->AcceptSelectedLine();
- }
-}
-
-- (void)mouseMoved:(NSEvent*)theEvent {
- // If the view is in the process of being destroyed, abort.
- if (!controller_)
- return;
-
- NSPoint location = [self convertPoint:[theEvent locationInWindow]
- fromView:nil];
-
- controller_->SetSelectionAtPoint(gfx::Point(NSPointToCGPoint(location)));
-}
-
-- (void)mouseDragged:(NSEvent*)theEvent {
- [self mouseMoved:theEvent];
-}
-
-- (void)mouseExited:(NSEvent*)theEvent {
- // If the view is in the process of being destroyed, abort.
- if (!controller_)
- return;
-
- controller_->SelectionCleared();
-}
-
#pragma mark -
#pragma mark Public API:
@@ -194,16 +99,18 @@ NSColor* SubtextColor() {
// Since the |controller_| either already has been destroyed or is about to
// be, about the only thing we can safely do with it is to null it out.
controller_ = NULL;
+ [super delegateDestroyed];
+}
+
+- (void)invalidateRow:(size_t)row {
+ NSRect dirty_rect =
+ NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect());
+ [self setNeedsDisplayInRect:dirty_rect];
}
#pragma mark -
#pragma mark Private API:
-- (void)drawSeparatorWithBounds:(NSRect)bounds {
- [SeparatorColor() set];
- [NSBezierPath fillRect:bounds];
-}
-
- (void)drawSuggestionWithName:(NSString*)name
subtext:(NSString*)subtext
index:(size_t)index
@@ -211,14 +118,14 @@ NSColor* SubtextColor() {
selected:(BOOL)isSelected {
// If this row is selected, highlight it.
if (isSelected) {
- [HighlightColor() set];
+ [[self highlightColor] set];
[NSBezierPath fillRect:bounds];
}
BOOL isRTL = controller_->IsRTL();
NSColor* nameColor =
- controller_->IsWarning(index) ? WarningColor() : NameColor();
+ controller_->IsWarning(index) ? [self warningColor] : [self nameColor];
NSDictionary* nameAttributes =
[NSDictionary dictionaryWithObjectsAndKeys:
controller_->GetNameFontListForRow(index).GetPrimaryFont().
@@ -262,7 +169,9 @@ NSColor* SubtextColor() {
NSDictionary* subtextAttributes =
[NSDictionary dictionaryWithObjectsAndKeys:
controller_->subtext_font_list().GetPrimaryFont().GetNativeFont(),
- NSFontAttributeName, SubtextColor(), NSForegroundColorAttributeName,
+ NSFontAttributeName,
+ [self subtextColor],
+ NSForegroundColorAttributeName,
nil];
NSSize subtextSize = [subtext sizeWithAttributes:subtextAttributes];
x += isRTL ? 0 : -subtextSize.width;

Powered by Google App Engine
This is Rietveld 408576698