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

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

Issue 2002103003: [Material][Mac] Adjustments to the Omnibox decorations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Shift icon to the right Created 4 years, 6 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/ui/cocoa/location_bar/location_bar_view_mac.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> 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 15
16 namespace { 16 namespace {
17 17
18 // This is used to increase the right margin of this decoration. 18 // This is used to increase the right margin of this decoration.
19 const CGFloat kRightSideMargin = 1.0; 19 const CGFloat kRightSideMargin = 1.0;
20 20
21 // Padding between the icon/label and bubble edges. 21 // Padding between the icon/label and bubble edges.
22 CGFloat BubblePadding() { 22 CGFloat BubblePadding() {
23 return ui::MaterialDesignController::IsModeMaterial() ? 8.0 : 3.0; 23 return ui::MaterialDesignController::IsModeMaterial() ? 8.0 : 3.0;
24 } 24 }
25 25
26 // Additional padding between the divider between the omnibox text and the 26 // 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 27 // divider. The desired value is 8px. We get 3px by subtracting the existing
28 // padding in location_bar_view from 8px. 28 // padding in location_bar_view from 8px.
29 CGFloat DividerPadding() { 29 CGFloat DividerPadding() {
30 return ui::MaterialDesignController::IsModeMaterial() ? 3.0 : 0.0; 30 return ui::MaterialDesignController::IsModeMaterial() ? 2.0 : 0.0;
31 } 31 }
32 32
33 // Padding between the icon and label. 33 // Padding between the icon and label.
34 const CGFloat kIconLabelPadding = 4.0; 34 CGFloat kIconLabelPadding = 4.0;
35 35
36 // Inset for the background. 36 // Inset for the background.
37 const CGFloat kBackgroundYInset = 4.0; 37 const CGFloat kBackgroundYInset = 4.0;
38 38
39 } // namespace 39 } // namespace
40 40
41 BubbleDecoration::BubbleDecoration() : baseline_offset_(0) { 41 BubbleDecoration::BubbleDecoration() : baseline_offset_(0) {
42 attributes_.reset([[NSMutableDictionary alloc] init]); 42 attributes_.reset([[NSMutableDictionary alloc] init]);
43 [attributes_ setObject:LocationBarDecoration::GetFont() 43 [attributes_ setObject:LocationBarDecoration::GetFont()
44 forKey:NSFontAttributeName]; 44 forKey:NSFontAttributeName];
(...skipping 18 matching lines...) Expand all
63 std::floor([label sizeWithAttributes:attributes_].width); 63 std::floor([label sizeWithAttributes:attributes_].width);
64 return BubblePadding() + image_width + kIconLabelPadding + label_width + 64 return BubblePadding() + image_width + kIconLabelPadding + label_width +
65 DividerPadding(); 65 DividerPadding();
66 } 66 }
67 67
68 NSRect BubbleDecoration::GetImageRectInFrame(NSRect frame) { 68 NSRect BubbleDecoration::GetImageRectInFrame(NSRect frame) {
69 NSRect imageRect = NSInsetRect(frame, 0.0, kBackgroundYInset); 69 NSRect imageRect = NSInsetRect(frame, 0.0, kBackgroundYInset);
70 if (image_) { 70 if (image_) {
71 // Center the image vertically. 71 // Center the image vertically.
72 const NSSize imageSize = [image_ size]; 72 const NSSize imageSize = [image_ size];
73
73 imageRect.origin.y += 74 imageRect.origin.y +=
74 std::floor((NSHeight(frame) - imageSize.height) / 2.0); 75 std::floor((NSHeight(frame) - imageSize.height) / 2.0);
75 imageRect.size = imageSize; 76 imageRect.size = imageSize;
76 } 77 }
77 return imageRect; 78 return imageRect;
78 } 79 }
79 80
80 CGFloat BubbleDecoration::GetWidthForSpace(CGFloat width) { 81 CGFloat BubbleDecoration::GetWidthForSpace(CGFloat width) {
81 const CGFloat all_width = GetWidthForImageAndLabel(image_, label_); 82 const CGFloat all_width = GetWidthForImageAndLabel(image_, label_);
82 if (all_width <= width) 83 if (all_width <= width)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName]; 175 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName];
175 } 176 }
176 177
177 void BubbleDecoration::SetFont(NSFont* font) { 178 void BubbleDecoration::SetFont(NSFont* font) {
178 [attributes_ setObject:font forKey:NSFontAttributeName]; 179 [attributes_ setObject:font forKey:NSFontAttributeName];
179 } 180 }
180 181
181 void BubbleDecoration::SetBaselineOffset(CGFloat offset) { 182 void BubbleDecoration::SetBaselineOffset(CGFloat offset) {
182 baseline_offset_ = offset; 183 baseline_offset_ = offset;
183 } 184 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698