Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 24 | 24 |
| 25 | 25 |
| 26 // Padding between the icon and label. | 26 // Padding between the icon and label. |
| 27 const CGFloat kIconLabelPadding = 4.0; | 27 const CGFloat kIconLabelPadding = 4.0; |
| 28 | 28 |
| 29 // Inset for the background. | 29 // Inset for the background. |
| 30 const CGFloat kBackgroundYInset = 4.0; | 30 const CGFloat kBackgroundYInset = 4.0; |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 BubbleDecoration::BubbleDecoration() { | 34 BubbleDecoration::BubbleDecoration() |
| 35 : baseline_offset_(0) { | |
|
tapted
2016/04/22 00:41:52
nit: put on the line above? - pretty sure that's w
shrike
2016/04/26 18:03:40
Done.
| |
| 35 attributes_.reset([[NSMutableDictionary alloc] init]); | 36 attributes_.reset([[NSMutableDictionary alloc] init]); |
| 36 [attributes_ setObject:GetFont() forKey:NSFontAttributeName]; | 37 [attributes_ setObject:GetFont() forKey:NSFontAttributeName]; |
| 37 } | 38 } |
| 38 | 39 |
| 39 BubbleDecoration::~BubbleDecoration() { | 40 BubbleDecoration::~BubbleDecoration() { |
| 40 } | 41 } |
| 41 | 42 |
| 42 CGFloat BubbleDecoration::GetWidthForImageAndLabel(NSImage* image, | 43 CGFloat BubbleDecoration::GetWidthForImageAndLabel(NSImage* image, |
| 43 NSString* label) { | 44 NSString* label) { |
| 44 if (!image && !label) | 45 if (!image && !label) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 operation:NSCompositeSourceOver | 96 operation:NSCompositeSourceOver |
| 96 fraction:1.0 | 97 fraction:1.0 |
| 97 respectFlipped:YES | 98 respectFlipped:YES |
| 98 hints:nil]; | 99 hints:nil]; |
| 99 textOffset = NSMaxX(imageRect) + kIconLabelPadding; | 100 textOffset = NSMaxX(imageRect) + kIconLabelPadding; |
| 100 } | 101 } |
| 101 | 102 |
| 102 if (label_) { | 103 if (label_) { |
| 103 NSRect textRect = frame; | 104 NSRect textRect = frame; |
| 104 textRect.origin.x = textOffset; | 105 textRect.origin.x = textOffset; |
| 106 textRect.origin.y += baseline_offset_; | |
| 105 textRect.size.width = NSMaxX(decoration_frame) - NSMinX(textRect); | 107 textRect.size.width = NSMaxX(decoration_frame) - NSMinX(textRect); |
| 106 DrawLabel(label_, attributes_, textRect); | 108 DrawLabel(label_, attributes_, textRect); |
| 107 } | 109 } |
| 108 } | 110 } |
| 109 | 111 |
| 110 void BubbleDecoration::DrawWithBackgroundInFrame(NSRect background_frame, | 112 void BubbleDecoration::DrawWithBackgroundInFrame(NSRect background_frame, |
| 111 NSRect frame, | 113 NSRect frame, |
| 112 NSView* control_view) { | 114 NSView* control_view) { |
| 113 NSRect rect = NSInsetRect(background_frame, 0, 1); | 115 NSRect rect = NSInsetRect(background_frame, 0, 1); |
| 114 rect.size.width -= kRightSideMargin; | 116 rect.size.width -= kRightSideMargin; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 // If the initializer was called with |nil|, then the code cannot | 149 // If the initializer was called with |nil|, then the code cannot |
| 148 // process a label. | 150 // process a label. |
| 149 DCHECK(attributes_); | 151 DCHECK(attributes_); |
| 150 if (attributes_) | 152 if (attributes_) |
| 151 label_.reset([label copy]); | 153 label_.reset([label copy]); |
| 152 } | 154 } |
| 153 | 155 |
| 154 void BubbleDecoration::SetTextColor(NSColor* text_color) { | 156 void BubbleDecoration::SetTextColor(NSColor* text_color) { |
| 155 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName]; | 157 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName]; |
| 156 } | 158 } |
| 159 | |
| 160 void BubbleDecoration::SetFont(NSFont* font) { | |
| 161 [attributes_ setObject:font forKey:NSFontAttributeName]; | |
| 162 } | |
| 163 | |
| 164 void BubbleDecoration::SetBaselineOffset(CGFloat offset) { | |
| 165 baseline_offset_ = offset; | |
| 166 } | |
| OLD | NEW |