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

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

Issue 2102853002: [Mac][Material Design] Adjust (i) and lock Omnibox icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 5 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
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"
11 #import "chrome/browser/ui/cocoa/themed_window.h" 11 #import "chrome/browser/ui/cocoa/themed_window.h"
12 #include "skia/ext/skia_utils_mac.h" 12 #include "skia/ext/skia_utils_mac.h"
13 #import "ui/base/cocoa/nsview_additions.h" 13 #import "ui/base/cocoa/nsview_additions.h"
14 #include "ui/base/material_design/material_design_controller.h" 14 #include "ui/base/material_design/material_design_controller.h"
15 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
15 16
16 namespace { 17 namespace {
17 18
18 // This is used to increase the right margin of this decoration. 19 // This is used to increase the right margin of this decoration.
19 const CGFloat kRightSideMargin = 1.0; 20 const CGFloat kRightSideMargin = 1.0;
20 21
21 // Padding between the icon/label and bubble edges. 22 // Padding between the icon/label and bubble edges.
22 CGFloat BubblePadding() { 23 CGFloat BubblePadding() {
23 return ui::MaterialDesignController::IsModeMaterial() ? 8.0 : 3.0; 24 return ui::MaterialDesignController::IsModeMaterial() ? 8.0 : 3.0;
24 } 25 }
25 26
26 // Additional padding between the divider between the omnibox text and the 27 // Additional padding between the divider between the omnibox text and the
27 // divider. The desired value is 8px. We get 3px by subtracting the existing 28 // divider. The desired value is 8px. We get 3px by subtracting the existing
28 // padding in location_bar_view from 8px. 29 // padding in location_bar_view from 8px.
29 CGFloat DividerPadding() { 30 CGFloat DividerPadding() {
30 return ui::MaterialDesignController::IsModeMaterial() ? 2.0 : 0.0; 31 return ui::MaterialDesignController::IsModeMaterial() ? 2.0 : 0.0;
31 } 32 }
32 33
33 // Padding between the icon and label. 34 // Padding between the icon and label.
34 CGFloat kIconLabelPadding = 4.0; 35 CGFloat kIconLabelPadding = 4.0;
35 36
36 // Inset for the background. 37 // Inset for the background.
37 const CGFloat kBackgroundYInset = 4.0; 38 const CGFloat kBackgroundYInset = 4.0;
38 39
39 } // namespace 40 } // namespace
40 41
41 BubbleDecoration::BubbleDecoration() : baseline_offset_(0) { 42 BubbleDecoration::BubbleDecoration() : retina_baseline_offset_(0) {
42 attributes_.reset([[NSMutableDictionary alloc] init]); 43 attributes_.reset([[NSMutableDictionary alloc] init]);
43 [attributes_ setObject:LocationBarDecoration::GetFont() 44 [attributes_ setObject:LocationBarDecoration::GetFont()
44 forKey:NSFontAttributeName]; 45 forKey:NSFontAttributeName];
45 } 46 }
46 47
47 BubbleDecoration::~BubbleDecoration() { 48 BubbleDecoration::~BubbleDecoration() {
48 } 49 }
49 50
50 CGFloat BubbleDecoration::GetWidthForImageAndLabel(NSImage* image, 51 CGFloat BubbleDecoration::GetWidthForImageAndLabel(NSImage* image,
51 NSString* label) { 52 NSString* label) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 NSColor* text_color = 126 NSColor* text_color =
126 in_dark_mode 127 in_dark_mode
127 ? skia::SkColorToCalibratedNSColor(kMaterialDarkModeTextColor) 128 ? skia::SkColorToCalibratedNSColor(kMaterialDarkModeTextColor)
128 : GetBackgroundBorderColor(); 129 : GetBackgroundBorderColor();
129 SetTextColor(text_color); 130 SetTextColor(text_color);
130 } 131 }
131 132
132 if (label_) { 133 if (label_) {
133 NSRect textRect = frame; 134 NSRect textRect = frame;
134 textRect.origin.x = textOffset; 135 textRect.origin.x = textOffset;
135 textRect.origin.y += baseline_offset_;
136 textRect.size.width = NSMaxX(decoration_frame) - NSMinX(textRect); 136 textRect.size.width = NSMaxX(decoration_frame) - NSMinX(textRect);
137 // Transform the coordinate system to adjust the baseline on Retina. This is
138 // the only way to get fractional adjustments.
139 gfx::ScopedNSGraphicsContextSaveGState saveGraphicsState;
140 CGFloat lineWidth = [control_view cr_lineWidth];
141 if (lineWidth < 1) {
142 NSAffineTransform* transform = [NSAffineTransform transform];
143 [transform translateXBy:0 yBy:retina_baseline_offset_];
144 [transform concat];
145 }
137 DrawLabel(label_, attributes_, textRect); 146 DrawLabel(label_, attributes_, textRect);
138 } 147 }
139 } 148 }
140 149
141 void BubbleDecoration::DrawWithBackgroundInFrame(NSRect background_frame, 150 void BubbleDecoration::DrawWithBackgroundInFrame(NSRect background_frame,
142 NSRect frame, 151 NSRect frame,
143 NSView* control_view) { 152 NSView* control_view) {
144 NSRect rect = NSInsetRect(background_frame, 0, 1); 153 NSRect rect = NSInsetRect(background_frame, 0, 1);
145 rect.size.width -= kRightSideMargin; 154 rect.size.width -= kRightSideMargin;
146 if (!ui::MaterialDesignController::IsModeMaterial()) { 155 if (!ui::MaterialDesignController::IsModeMaterial()) {
(...skipping 25 matching lines...) Expand all
172 } 181 }
173 182
174 void BubbleDecoration::SetTextColor(NSColor* text_color) { 183 void BubbleDecoration::SetTextColor(NSColor* text_color) {
175 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName]; 184 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName];
176 } 185 }
177 186
178 void BubbleDecoration::SetFont(NSFont* font) { 187 void BubbleDecoration::SetFont(NSFont* font) {
179 [attributes_ setObject:font forKey:NSFontAttributeName]; 188 [attributes_ setObject:font forKey:NSFontAttributeName];
180 } 189 }
181 190
182 void BubbleDecoration::SetBaselineOffset(CGFloat offset) { 191 void BubbleDecoration::SetRetinaBaselineOffset(CGFloat offset) {
183 baseline_offset_ = offset; 192 retina_baseline_offset_ = offset;
184 } 193 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/bubble_decoration.h ('k') | chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698