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

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

Issue 3017055: Merge 54767 - [Mac] M6 Omnibox positioning changes.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/472/src/
Patch Set: Created 10 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/cocoa/location_bar/image_decoration.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <cmath>
6
5 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" 7 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h"
6 8
7 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
8 #include "app/text_elider.h" 10 #include "app/text_elider.h"
9 #include "base/stl_util-inl.h" 11 #include "base/stl_util-inl.h"
10 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
11 #include "chrome/browser/autocomplete/autocomplete_edit.h" 13 #include "chrome/browser/autocomplete/autocomplete_edit.h"
12 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" 14 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
13 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
14 #include "chrome/browser/cocoa/event_utils.h" 16 #include "chrome/browser/cocoa/event_utils.h"
15 #include "chrome/browser/cocoa/image_utils.h" 17 #include "chrome/browser/cocoa/image_utils.h"
16 #include "gfx/rect.h" 18 #include "gfx/rect.h"
17 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
18 #include "skia/ext/skia_utils_mac.h" 20 #include "skia/ext/skia_utils_mac.h"
19 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" 21 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h"
20 22
21 namespace { 23 namespace {
22 24
23 // The size delta between the font used for the edit and the result 25 // The size delta between the font used for the edit and the result
24 // rows. 26 // rows.
25 const int kEditFontAdjust = -1; 27 const int kEditFontAdjust = -1;
26 28
27 // How much to adjust the cell sizing up from the default determined 29 // How much to adjust the cell sizing up from the default determined
28 // by the font. 30 // by the font.
29 const int kCellHeightAdjust = 7.0; 31 const int kCellHeightAdjust = 6.0;
30 32
31 // How to round off the popup's corners. Goal is to match star and go 33 // How to round off the popup's corners. Goal is to match star and go
32 // buttons. 34 // buttons.
33 const CGFloat kPopupRoundingRadius = 3.5; 35 const CGFloat kPopupRoundingRadius = 3.5;
34 36
35 // Gap between the field and the popup. 37 // Gap between the field and the popup.
36 const CGFloat kPopupFieldGap = 2.0; 38 const CGFloat kPopupFieldGap = 2.0;
37 39
38 // How opaque the popup window should be. This matches Windows (see 40 // How opaque the popup window should be. This matches Windows (see
39 // autocomplete_popup_contents_view.cc, kGlassPopupTransparency). 41 // autocomplete_popup_contents_view.cc, kGlassPopupTransparency).
40 const CGFloat kPopupAlpha = 240.0 / 255.0; 42 const CGFloat kPopupAlpha = 240.0 / 255.0;
41 43
42 // How far to offset image column from the left. 44 // How far to offset image column from the left.
43 const CGFloat kImageXOffset = 4.0; 45 const CGFloat kImageXOffset = 4.0;
44 46
45 // How far to offset the text column from the left. 47 // How far to offset the text column from the left.
46 const CGFloat kTextXOffset = 26.0; 48 const CGFloat kTextXOffset = 27.0;
47 49
48 // Animation duration when animating the popup window smaller. 50 // Animation duration when animating the popup window smaller.
49 const NSTimeInterval kShrinkAnimationDuration = 0.1; 51 const NSTimeInterval kShrinkAnimationDuration = 0.1;
50 52
51 // Maximum fraction of the popup width that can be used to display match 53 // Maximum fraction of the popup width that can be used to display match
52 // contents. 54 // contents.
53 const float kMaxContentsFraction = 0.7; 55 const float kMaxContentsFraction = 0.7;
54 56
55 // NSEvent -buttonNumber for middle mouse button. 57 // NSEvent -buttonNumber for middle mouse button.
56 const static NSInteger kMiddleButtonNumber(2); 58 const static NSInteger kMiddleButtonNumber(2);
57 59
58 // The autocomplete field's visual border is slightly inset from the 60 // The autocomplete field's visual border is slightly inset from the
59 // actual border so that it can spill a glow into the toolbar or 61 // actual border so that it can spill a glow into the toolbar or
60 // something like that. This is how much to inset vertically. 62 // something like that. This is how much to inset vertically.
61 const CGFloat kFieldVisualInset = 1.0; 63 const CGFloat kFieldVisualInset = 1.0;
62 64
63 // The popup window has a single-pixel border in screen coordinates, 65 // The popup window has a single-pixel border in screen coordinates,
64 // which has to be backed out to line the borders up with the field 66 // which has to be backed out to line the borders up with the field
65 // borders. 67 // borders.
66 const CGFloat kWindowBorderWidth = 1.0; 68 const CGFloat kWindowBorderWidth = 1.0;
67 69
68 // |AutocompleteButtonCell| and |AutocompleteTextFieldCell| draw their
69 // text somewhat differently. The image needs to be adjusted slightly
70 // downward to align with the text the same.
71 const CGFloat kImageBaselineAdjust = 1.0;
72
73 // Background colors for different states of the popup elements. 70 // Background colors for different states of the popup elements.
74 NSColor* BackgroundColor() { 71 NSColor* BackgroundColor() {
75 return [[NSColor controlBackgroundColor] colorWithAlphaComponent:kPopupAlpha]; 72 return [[NSColor controlBackgroundColor] colorWithAlphaComponent:kPopupAlpha];
76 } 73 }
77 NSColor* SelectedBackgroundColor() { 74 NSColor* SelectedBackgroundColor() {
78 return [[NSColor selectedControlColor] colorWithAlphaComponent:kPopupAlpha]; 75 return [[NSColor selectedControlColor] colorWithAlphaComponent:kPopupAlpha];
79 } 76 }
80 NSColor* HoveredBackgroundColor() { 77 NSColor* HoveredBackgroundColor() {
81 return [[NSColor controlHighlightColor] colorWithAlphaComponent:kPopupAlpha]; 78 return [[NSColor controlHighlightColor] colorWithAlphaComponent:kPopupAlpha];
82 } 79 }
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 // with the star button and autocomplete field. 509 // with the star button and autocomplete field.
513 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { 510 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
514 [[self backgroundColor] set]; 511 [[self backgroundColor] set];
515 NSRectFill(cellFrame); 512 NSRectFill(cellFrame);
516 513
517 // Put the image centered vertically but in a fixed column. 514 // Put the image centered vertically but in a fixed column.
518 NSImage* image = [self image]; 515 NSImage* image = [self image];
519 if (image) { 516 if (image) {
520 NSRect imageRect = cellFrame; 517 NSRect imageRect = cellFrame;
521 imageRect.size = [image size]; 518 imageRect.size = [image size];
522 imageRect.origin.y += kImageBaselineAdjust + 519 imageRect.origin.y +=
523 floor((NSHeight(cellFrame) - NSHeight(imageRect)) / 2); 520 std::floor((NSHeight(cellFrame) - NSHeight(imageRect)) / 2.0);
524 imageRect.origin.x += kImageXOffset; 521 imageRect.origin.x += kImageXOffset;
525 [image drawInRect:imageRect 522 [image drawInRect:imageRect
526 fromRect:NSZeroRect // Entire image 523 fromRect:NSZeroRect // Entire image
527 operation:NSCompositeSourceOver 524 operation:NSCompositeSourceOver
528 fraction:1.0 525 fraction:1.0
529 neverFlipped:YES]; 526 neverFlipped:YES];
530 } 527 }
531 528
532 // Adjust the title position to be lined up under the field's text. 529 // Adjust the title position to be lined up under the field's text.
533 NSAttributedString* title = [self attributedTitle]; 530 NSAttributedString* title = [self attributedTitle];
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 yRadius:kPopupRoundingRadius]; 728 yRadius:kPopupRoundingRadius];
732 729
733 // Draw the matrix clipped to our border. 730 // Draw the matrix clipped to our border.
734 [NSGraphicsContext saveGraphicsState]; 731 [NSGraphicsContext saveGraphicsState];
735 [path addClip]; 732 [path addClip];
736 [super drawRect:rect]; 733 [super drawRect:rect];
737 [NSGraphicsContext restoreGraphicsState]; 734 [NSGraphicsContext restoreGraphicsState];
738 } 735 }
739 736
740 @end 737 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/cocoa/location_bar/image_decoration.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698