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

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

Issue 2206073002: [Mac] Fix camel case in variable names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | 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> 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // The bubble needs to take up an integral number of pixels. 60 // The bubble needs to take up an integral number of pixels.
61 // Generally -sizeWithAttributes: seems to overestimate rather than 61 // Generally -sizeWithAttributes: seems to overestimate rather than
62 // underestimate, so floor() seems to work better. 62 // underestimate, so floor() seems to work better.
63 const CGFloat label_width = 63 const CGFloat label_width =
64 std::floor([label sizeWithAttributes:attributes_].width); 64 std::floor([label sizeWithAttributes:attributes_].width);
65 return BubblePadding() + image_width + kIconLabelPadding + label_width + 65 return BubblePadding() + image_width + kIconLabelPadding + label_width +
66 DividerPadding(); 66 DividerPadding();
67 } 67 }
68 68
69 NSRect BubbleDecoration::GetImageRectInFrame(NSRect frame) { 69 NSRect BubbleDecoration::GetImageRectInFrame(NSRect frame) {
70 NSRect imageRect = NSInsetRect(frame, 0.0, kBackgroundYInset); 70 NSRect image_rect = NSInsetRect(frame, 0.0, kBackgroundYInset);
71 if (image_) { 71 if (image_) {
72 // Center the image vertically. 72 // Center the image vertically.
73 const NSSize imageSize = [image_ size]; 73 const NSSize image_size = [image_ size];
74 74
75 imageRect.origin.y += 75 image_rect.origin.y +=
76 std::floor((NSHeight(frame) - imageSize.height) / 2.0); 76 std::floor((NSHeight(frame) - image_size.height) / 2.0);
77 imageRect.size = imageSize; 77 image_rect.size = image_size;
78 } 78 }
79 return imageRect; 79 return image_rect;
80 } 80 }
81 81
82 CGFloat BubbleDecoration::GetWidthForSpace(CGFloat width) { 82 CGFloat BubbleDecoration::GetWidthForSpace(CGFloat width) {
83 const CGFloat all_width = GetWidthForImageAndLabel(image_, label_); 83 const CGFloat all_width = GetWidthForImageAndLabel(image_, label_);
84 if (all_width <= width) 84 if (all_width <= width)
85 return all_width; 85 return all_width;
86 86
87 const CGFloat image_width = GetWidthForImageAndLabel(image_, nil); 87 const CGFloat image_width = GetWidthForImageAndLabel(image_, nil);
88 if (image_width <= width) 88 if (image_width <= width)
89 return image_width; 89 return image_width;
90 90
91 return kOmittedWidth; 91 return kOmittedWidth;
92 } 92 }
93 93
94 void BubbleDecoration::DrawInFrame(NSRect frame, NSView* control_view) { 94 void BubbleDecoration::DrawInFrame(NSRect frame, NSView* control_view) {
95 const NSRect decoration_frame = NSInsetRect(frame, 0.0, kBackgroundYInset); 95 const NSRect decoration_frame = NSInsetRect(frame, 0.0, kBackgroundYInset);
96 CGFloat textOffset = NSMinX(decoration_frame); 96 CGFloat text_offset = NSMinX(decoration_frame);
97 if (image_) { 97 if (image_) {
98 // Center the image vertically. 98 // Center the image vertically.
99 const NSSize imageSize = [image_ size]; 99 const NSSize image_size = [image_ size];
100 NSRect imageRect = decoration_frame; 100 NSRect image_rect = decoration_frame;
101 imageRect.origin.y += 101 image_rect.origin.y +=
102 std::floor((NSHeight(decoration_frame) - imageSize.height) / 2.0); 102 std::floor((NSHeight(decoration_frame) - image_size.height) / 2.0);
103 imageRect.size = imageSize; 103 image_rect.size = image_size;
104 [image_ drawInRect:imageRect 104 [image_ drawInRect:image_rect
105 fromRect:NSZeroRect // Entire image 105 fromRect:NSZeroRect // Entire image
106 operation:NSCompositeSourceOver 106 operation:NSCompositeSourceOver
107 fraction:1.0 107 fraction:1.0
108 respectFlipped:YES 108 respectFlipped:YES
109 hints:nil]; 109 hints:nil];
110 textOffset = NSMaxX(imageRect) + kIconLabelPadding; 110 text_offset = NSMaxX(image_rect) + kIconLabelPadding;
111 } 111 }
112 112
113 // Draw the divider and set the text color. 113 // Draw the divider and set the text color.
114 if (ui::MaterialDesignController::IsModeMaterial()) { 114 if (ui::MaterialDesignController::IsModeMaterial()) {
115 NSBezierPath* line = [NSBezierPath bezierPath]; 115 NSBezierPath* line = [NSBezierPath bezierPath];
116 [line setLineWidth:1]; 116 [line setLineWidth:1];
117 [line moveToPoint:NSMakePoint(NSMaxX(decoration_frame) - DividerPadding(), 117 [line moveToPoint:NSMakePoint(NSMaxX(decoration_frame) - DividerPadding(),
118 NSMinY(decoration_frame))]; 118 NSMinY(decoration_frame))];
119 [line lineToPoint:NSMakePoint(NSMaxX(decoration_frame) - DividerPadding(), 119 [line lineToPoint:NSMakePoint(NSMaxX(decoration_frame) - DividerPadding(),
120 NSMaxY(decoration_frame))]; 120 NSMaxY(decoration_frame))];
121 121
122 bool in_dark_mode = [[control_view window] inIncognitoModeWithSystemTheme]; 122 bool in_dark_mode = [[control_view window] inIncognitoModeWithSystemTheme];
123 [GetDividerColor(in_dark_mode) set]; 123 [GetDividerColor(in_dark_mode) set];
124 [line stroke]; 124 [line stroke];
125 125
126 NSColor* text_color = 126 NSColor* text_color =
127 in_dark_mode 127 in_dark_mode
128 ? skia::SkColorToSRGBNSColor(kMaterialDarkModeTextColor) 128 ? skia::SkColorToSRGBNSColor(kMaterialDarkModeTextColor)
129 : GetBackgroundBorderColor(); 129 : GetBackgroundBorderColor();
130 SetTextColor(text_color); 130 SetTextColor(text_color);
131 } 131 }
132 132
133 if (label_) { 133 if (label_) {
134 NSRect textRect = frame; 134 NSRect text_rect = frame;
135 textRect.origin.x = textOffset; 135 text_rect.origin.x = text_offset;
136 textRect.size.width = NSMaxX(decoration_frame) - NSMinX(textRect); 136 text_rect.size.width = NSMaxX(decoration_frame) - NSMinX(text_rect);
137 // Transform the coordinate system to adjust the baseline on Retina. This is 137 // Transform the coordinate system to adjust the baseline on Retina. This is
138 // the only way to get fractional adjustments. 138 // the only way to get fractional adjustments.
139 gfx::ScopedNSGraphicsContextSaveGState saveGraphicsState; 139 gfx::ScopedNSGraphicsContextSaveGState saveGraphicsState;
140 CGFloat lineWidth = [control_view cr_lineWidth]; 140 CGFloat line_width = [control_view cr_lineWidth];
141 if (lineWidth < 1) { 141 if (line_width < 1) {
142 NSAffineTransform* transform = [NSAffineTransform transform]; 142 NSAffineTransform* transform = [NSAffineTransform transform];
143 [transform translateXBy:0 yBy:retina_baseline_offset_]; 143 [transform translateXBy:0 yBy:retina_baseline_offset_];
144 [transform concat]; 144 [transform concat];
145 } 145 }
146 DrawLabel(label_, attributes_, textRect); 146 DrawLabel(label_, attributes_, text_rect);
147 } 147 }
148 } 148 }
149 149
150 void BubbleDecoration::DrawWithBackgroundInFrame(NSRect background_frame, 150 void BubbleDecoration::DrawWithBackgroundInFrame(NSRect background_frame,
151 NSRect frame, 151 NSRect frame,
152 NSView* control_view) { 152 NSView* control_view) {
153 NSRect rect = NSInsetRect(background_frame, 0, 1); 153 NSRect rect = NSInsetRect(background_frame, 0, 1);
154 rect.size.width -= kRightSideMargin; 154 rect.size.width -= kRightSideMargin;
155 if (!ui::MaterialDesignController::IsModeMaterial()) { 155 if (!ui::MaterialDesignController::IsModeMaterial()) {
156 ui::DrawNinePartImage( 156 ui::DrawNinePartImage(
(...skipping 27 matching lines...) Expand all
184 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName]; 184 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName];
185 } 185 }
186 186
187 void BubbleDecoration::SetFont(NSFont* font) { 187 void BubbleDecoration::SetFont(NSFont* font) {
188 [attributes_ setObject:font forKey:NSFontAttributeName]; 188 [attributes_ setObject:font forKey:NSFontAttributeName];
189 } 189 }
190 190
191 void BubbleDecoration::SetRetinaBaselineOffset(CGFloat offset) { 191 void BubbleDecoration::SetRetinaBaselineOffset(CGFloat offset) {
192 retina_baseline_offset_ = offset; 192 retina_baseline_offset_ = offset;
193 } 193 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698