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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/bubble_decoration.mm

Issue 2478673002: [Mac] Hover/Pressed background for the Omnibox decorations (Closed)
Patch Set: nit Created 4 years, 1 month 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
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> 5 #include <cmath>
6 6
7 #import "chrome/browser/ui/cocoa/location_bar/bubble_decoration.h" 7 #import "chrome/browser/ui/cocoa/location_bar/bubble_decoration.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
(...skipping 13 matching lines...) Expand all
24 24
25 // Additional padding between the divider and the label. 25 // Additional padding between the divider and the label.
26 const CGFloat kDividerPadding = 6.0; 26 const CGFloat kDividerPadding = 6.0;
27 27
28 // Padding between the icon and label. 28 // Padding between the icon and label.
29 const CGFloat kIconLabelPadding = 4.0; 29 const CGFloat kIconLabelPadding = 4.0;
30 30
31 // Inset for the image frame. 31 // Inset for the image frame.
32 const CGFloat kImageFrameYInset = 4.0; 32 const CGFloat kImageFrameYInset = 4.0;
33 33
34 // Inset for the background frame.
35 const CGFloat kBackgroundFrameYInset = 2.0;
36
37 // Left margin for the background frame.
38 const CGFloat kBackgroundFrameLeftMargin = 1.0;
39
34 } // namespace 40 } // namespace
35 41
36 BubbleDecoration::BubbleDecoration() : retina_baseline_offset_(0) { 42 BubbleDecoration::BubbleDecoration() : retina_baseline_offset_(0) {
37 attributes_.reset([[NSMutableDictionary alloc] init]); 43 attributes_.reset([[NSMutableDictionary alloc] init]);
38 [attributes_ setObject:LocationBarDecoration::GetFont() 44 [attributes_ setObject:LocationBarDecoration::GetFont()
39 forKey:NSFontAttributeName]; 45 forKey:NSFontAttributeName];
40 } 46 }
41 47
42 BubbleDecoration::~BubbleDecoration() { 48 BubbleDecoration::~BubbleDecoration() {
43 } 49 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 if (all_width <= width) 92 if (all_width <= width)
87 return all_width; 93 return all_width;
88 94
89 const CGFloat image_width = GetWidthForImageAndLabel(image_, nil); 95 const CGFloat image_width = GetWidthForImageAndLabel(image_, nil);
90 if (image_width <= width) 96 if (image_width <= width)
91 return image_width; 97 return image_width;
92 98
93 return kOmittedWidth; 99 return kOmittedWidth;
94 } 100 }
95 101
102 NSRect BubbleDecoration::GetBackgroundFrame(NSRect frame) {
103 NSRect background_frame = NSInsetRect(frame, 0.0, kBackgroundFrameYInset);
104 background_frame.origin.x += kBackgroundFrameLeftMargin;
105 background_frame.size.width -= kDividerPadding;
106 return background_frame;
107 }
108
96 void BubbleDecoration::DrawInFrame(NSRect frame, NSView* control_view) { 109 void BubbleDecoration::DrawInFrame(NSRect frame, NSView* control_view) {
97 const NSRect decoration_frame = NSInsetRect(frame, 0.0, kImageFrameYInset); 110 const NSRect decoration_frame = NSInsetRect(frame, 0.0, kImageFrameYInset);
98 CGFloat text_offset = NSMinX(decoration_frame); 111 CGFloat text_offset = NSMinX(decoration_frame);
99 if (image_) { 112 if (image_) {
100 // Center the image vertically. 113 // Center the image vertically.
101 const NSSize image_size = [image_ size]; 114 const NSSize image_size = [image_ size];
102 NSRect image_rect = decoration_frame; 115 NSRect image_rect = decoration_frame;
103 image_rect.origin.x += kLeftSidePadding; 116 image_rect.origin.x += kLeftSidePadding;
104 image_rect.origin.y += 117 image_rect.origin.y +=
105 std::floor((NSHeight(decoration_frame) - image_size.height) / 2.0); 118 std::floor((NSHeight(decoration_frame) - image_size.height) / 2.0);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName]; 183 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName];
171 } 184 }
172 185
173 void BubbleDecoration::SetFont(NSFont* font) { 186 void BubbleDecoration::SetFont(NSFont* font) {
174 [attributes_ setObject:font forKey:NSFontAttributeName]; 187 [attributes_ setObject:font forKey:NSFontAttributeName];
175 } 188 }
176 189
177 void BubbleDecoration::SetRetinaBaselineOffset(CGFloat offset) { 190 void BubbleDecoration::SetRetinaBaselineOffset(CGFloat offset) {
178 retina_baseline_offset_ = offset; 191 retina_baseline_offset_ = offset;
179 } 192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698