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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_popup_view_mac.mm

Issue 185013: [Mac] Drop shadow for Omnibox popup. (Closed)
Patch Set: Oops, another CL masked something. Created 11 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/cocoa/toolbar_controller.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" 5 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h"
6 6
7 #include "app/gfx/text_elider.h" 7 #include "app/gfx/text_elider.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "base/gfx/rect.h" 9 #include "base/gfx/rect.h"
10 #include "chrome/browser/autocomplete/autocomplete_edit.h" 10 #include "chrome/browser/autocomplete/autocomplete_edit.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 return [popup_ isVisible] ? true : false; 287 return [popup_ isVisible] ? true : false;
288 } 288 }
289 289
290 void AutocompletePopupViewMac::CreatePopupIfNeeded() { 290 void AutocompletePopupViewMac::CreatePopupIfNeeded() {
291 if (!popup_) { 291 if (!popup_) {
292 popup_.reset([[NSWindow alloc] initWithContentRect:NSZeroRect 292 popup_.reset([[NSWindow alloc] initWithContentRect:NSZeroRect
293 styleMask:NSBorderlessWindowMask 293 styleMask:NSBorderlessWindowMask
294 backing:NSBackingStoreBuffered 294 backing:NSBackingStoreBuffered
295 defer:YES]); 295 defer:YES]);
296 [popup_ setMovableByWindowBackground:NO]; 296 [popup_ setMovableByWindowBackground:NO];
297 // The window will have rounded borders. 297 // The window shape is determined by the content view
298 // (AutocompleteMatrix).
298 [popup_ setAlphaValue:1.0]; 299 [popup_ setAlphaValue:1.0];
299 [popup_ setOpaque:NO]; 300 [popup_ setOpaque:NO];
301 [popup_ setBackgroundColor:[NSColor clearColor]];
302 [popup_ setHasShadow:YES];
300 [popup_ setLevel:NSNormalWindowLevel]; 303 [popup_ setLevel:NSNormalWindowLevel];
301 304
302 AutocompleteMatrix* matrix = 305 AutocompleteMatrix* matrix =
303 [[[AutocompleteMatrix alloc] initWithFrame:NSZeroRect] autorelease]; 306 [[[AutocompleteMatrix alloc] initWithFrame:NSZeroRect] autorelease];
304 [matrix setTarget:matrix_target_]; 307 [matrix setTarget:matrix_target_];
305 [matrix setAction:@selector(select:)]; 308 [matrix setAction:@selector(select:)];
306 [matrix setMiddleClickAction:@selector(middleSelect:)]; 309 [matrix setMiddleClickAction:@selector(middleSelect:)];
307 [popup_ setContentView:matrix]; 310 [popup_ setContentView:matrix];
308 311
309 // We need the popup to follow window resize. 312 // We need the popup to follow window resize.
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 return i; 627 return i;
625 } 628 }
626 } 629 }
627 return -1; 630 return -1;
628 } 631 }
629 632
630 - (void)setMiddleClickAction:(SEL)anAction { 633 - (void)setMiddleClickAction:(SEL)anAction {
631 middleClickAction_ = anAction; 634 middleClickAction_ = anAction;
632 } 635 }
633 636
637 - (BOOL)isOpaque {
638 return NO;
639 }
Scott Hess - ex-Googler 2009/09/03 18:45:12 Oops - looks like I had forgotten a bit in my clea
640
634 // This handles drawing the decorations of the rounded popup window, 641 // This handles drawing the decorations of the rounded popup window,
635 // calling on NSMatrix to draw the actual contents. 642 // calling on NSMatrix to draw the actual contents.
636 - (void)drawRect:(NSRect)rect { 643 - (void)drawRect:(NSRect)rect {
637 // Background clear so we can round the corners.
638 [[NSColor clearColor] set];
639 NSRectFill([self frame]);
640
641 // The toolbar items we're mirroring for shape are inset slightly
642 // for width. I don't know why, which is why I didn't make this a
643 // constant, yet. The factor of 0.5 on both dimensions is to put
644 // the stroke down the middle of the pixels.
645 const NSRect border(NSInsetRect([self bounds], 1.5, 0.5));
646 NSBezierPath* path = 644 NSBezierPath* path =
647 [NSBezierPath bezierPathWithRoundedRect:border 645 [NSBezierPath bezierPathWithRoundedRect:[self bounds]
648 xRadius:kPopupRoundingRadius 646 xRadius:kPopupRoundingRadius
649 yRadius:kPopupRoundingRadius]; 647 yRadius:kPopupRoundingRadius];
650 648
651 // Draw the matrix clipped to our border. 649 // Draw the matrix clipped to our border.
652 [NSGraphicsContext saveGraphicsState]; 650 [NSGraphicsContext saveGraphicsState];
653 [path addClip]; 651 [path addClip];
654 [super drawRect:rect]; 652 [super drawRect:rect];
655 [NSGraphicsContext restoreGraphicsState]; 653 [NSGraphicsContext restoreGraphicsState];
656
657 // Put a border over that.
658 // TODO(shess): Theme the color?
659 [[NSColor lightGrayColor] setStroke];
660 [path setLineWidth:1.0];
661 [path stroke];
662 } 654 }
663 655
664 @end 656 @end
665 657
666 @implementation AutocompleteMatrixTarget 658 @implementation AutocompleteMatrixTarget
667 659
668 - initWithPopupView:(AutocompletePopupViewMac*)view { 660 - initWithPopupView:(AutocompletePopupViewMac*)view {
669 self = [super init]; 661 self = [super init];
670 if (self) { 662 if (self) {
671 popup_view_ = view; 663 popup_view_ = view;
(...skipping 20 matching lines...) Expand all
692 DCHECK(popup_view_); 684 DCHECK(popup_view_);
693 685
694 // TODO(shess): UpdatePopupAppearance() is called frequently, so it 686 // TODO(shess): UpdatePopupAppearance() is called frequently, so it
695 // should be really cheap, but in this case we could probably make 687 // should be really cheap, but in this case we could probably make
696 // things even cheaper by refactoring between the popup-placement 688 // things even cheaper by refactoring between the popup-placement
697 // code and the matrix-population code. 689 // code and the matrix-population code.
698 popup_view_->UpdatePopupAppearance(); 690 popup_view_->UpdatePopupAppearance();
699 } 691 }
700 692
701 @end 693 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/cocoa/toolbar_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698