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

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

Issue 2050623004: [Material][Mac] Adjustments to the Omnibox decorations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: 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 #import "ui/base/cocoa/nsview_additions.h" 12 #import "ui/base/cocoa/nsview_additions.h"
13 #include "ui/base/material_design/material_design_controller.h" 13 #include "ui/base/material_design/material_design_controller.h"
14 14
15 namespace { 15 namespace {
16 16
17 // This is used to increase the right margin of this decoration. 17 // This is used to increase the right margin of this decoration.
18 const CGFloat kRightSideMargin = 1.0; 18 const CGFloat kRightSideMargin = 1.0;
19 19
20 // Padding between the icon/label and bubble edges. 20 // Padding between the icon/label and bubble edges.
21 CGFloat BubblePadding() { 21 CGFloat BubblePadding() {
22 return ui::MaterialDesignController::IsModeMaterial() ? 7 : 3; 22 return ui::MaterialDesignController::IsModeMaterial() ? 7 : 3;
23 } 23 }
24 24
25 // Additional padding between the divider between the omnibox text and the
26 // divider. The desired value is 8px. We get 3px by subtracting the existing
27 // padding in location_bar_view from 8px.
28 CGFloat DividerPadding() {
29 return ui::MaterialDesignController::IsModeMaterial() ? 2.0 : 0.0;
30 }
25 31
26 // Padding between the icon and label. 32 // Padding between the icon and label.
27 const CGFloat kIconLabelPadding = 4.0; 33 CGFloat kIconLabelPadding = 4.0;
28 34
29 // Inset for the background. 35 // Inset for the background.
30 const CGFloat kBackgroundYInset = 4.0; 36 const CGFloat kBackgroundYInset = 4.0;
31 37
32 } // namespace 38 } // namespace
33 39
34 BubbleDecoration::BubbleDecoration() : baseline_offset_(0) { 40 BubbleDecoration::BubbleDecoration() : baseline_offset_(0) {
35 attributes_.reset([[NSMutableDictionary alloc] init]); 41 attributes_.reset([[NSMutableDictionary alloc] init]);
36 [attributes_ setObject:LocationBarDecoration::GetFont() 42 [attributes_ setObject:LocationBarDecoration::GetFont()
37 forKey:NSFontAttributeName]; 43 forKey:NSFontAttributeName];
38 } 44 }
39 45
40 BubbleDecoration::~BubbleDecoration() { 46 BubbleDecoration::~BubbleDecoration() {
41 } 47 }
42 48
43 CGFloat BubbleDecoration::GetWidthForImageAndLabel(NSImage* image, 49 CGFloat BubbleDecoration::GetWidthForImageAndLabel(NSImage* image,
44 NSString* label) { 50 NSString* label) {
45 if (!image && !label) 51 if (!image && !label)
46 return kOmittedWidth; 52 return kOmittedWidth;
47 53
48 const CGFloat image_width = image ? [image size].width : 0.0; 54 const CGFloat image_width = image ? [image size].width : 0.0;
49 if (!label) 55 if (!label)
50 return BubblePadding() + image_width; 56 return BubblePadding() + image_width;
51 57
52 // The bubble needs to take up an integral number of pixels. 58 // The bubble needs to take up an integral number of pixels.
53 // Generally -sizeWithAttributes: seems to overestimate rather than 59 // Generally -sizeWithAttributes: seems to overestimate rather than
54 // underestimate, so floor() seems to work better. 60 // underestimate, so floor() seems to work better.
55 const CGFloat label_width = 61 const CGFloat label_width =
56 std::floor([label sizeWithAttributes:attributes_].width); 62 std::floor([label sizeWithAttributes:attributes_].width);
57 return BubblePadding() + image_width + kIconLabelPadding + label_width; 63 return BubblePadding() + image_width + kIconLabelPadding + label_width
64 + DividerPadding();
58 } 65 }
59 66
60 NSRect BubbleDecoration::GetImageRectInFrame(NSRect frame) { 67 NSRect BubbleDecoration::GetImageRectInFrame(NSRect frame) {
61 NSRect imageRect = NSInsetRect(frame, 0.0, kBackgroundYInset); 68 NSRect imageRect = NSInsetRect(frame, 0.0, kBackgroundYInset);
62 if (image_) { 69 if (image_) {
63 // Center the image vertically. 70 // Center the image vertically.
64 const NSSize imageSize = [image_ size]; 71 const NSSize imageSize = [image_ size];
72
65 imageRect.origin.y += 73 imageRect.origin.y +=
66 std::floor((NSHeight(frame) - imageSize.height) / 2.0); 74 std::floor((NSHeight(frame) - imageSize.height) / 2.0);
67 imageRect.size = imageSize; 75 imageRect.size = imageSize;
68 } 76 }
69 return imageRect; 77 return imageRect;
70 } 78 }
71 79
72 CGFloat BubbleDecoration::GetWidthForSpace(CGFloat width) { 80 CGFloat BubbleDecoration::GetWidthForSpace(CGFloat width) {
73 const CGFloat all_width = GetWidthForImageAndLabel(image_, label_); 81 const CGFloat all_width = GetWidthForImageAndLabel(image_, label_);
74 if (all_width <= width) 82 if (all_width <= width)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName]; 169 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName];
162 } 170 }
163 171
164 void BubbleDecoration::SetFont(NSFont* font) { 172 void BubbleDecoration::SetFont(NSFont* font) {
165 [attributes_ setObject:font forKey:NSFontAttributeName]; 173 [attributes_ setObject:font forKey:NSFontAttributeName];
166 } 174 }
167 175
168 void BubbleDecoration::SetBaselineOffset(CGFloat offset) { 176 void BubbleDecoration::SetBaselineOffset(CGFloat offset) {
169 baseline_offset_ = offset; 177 baseline_offset_ = offset;
170 } 178 }
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