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" |
| 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() ? 8.0 : 3.0; |
| 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() ? 3.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 const 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) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 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]; |
| 65 imageRect.origin.y += | 72 imageRect.origin.y += |
| 66 std::floor((NSHeight(frame) - imageSize.height) / 2.0); | 73 std::floor((NSHeight(frame) - imageSize.height) / 2.0); |
| 67 imageRect.size = imageSize; | 74 imageRect.size = imageSize; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 93 imageRect.size = imageSize; | 100 imageRect.size = imageSize; |
| 94 [image_ drawInRect:imageRect | 101 [image_ drawInRect:imageRect |
| 95 fromRect:NSZeroRect // Entire image | 102 fromRect:NSZeroRect // Entire image |
| 96 operation:NSCompositeSourceOver | 103 operation:NSCompositeSourceOver |
| 97 fraction:1.0 | 104 fraction:1.0 |
| 98 respectFlipped:YES | 105 respectFlipped:YES |
| 99 hints:nil]; | 106 hints:nil]; |
| 100 textOffset = NSMaxX(imageRect) + kIconLabelPadding; | 107 textOffset = NSMaxX(imageRect) + kIconLabelPadding; |
| 101 } | 108 } |
| 102 | 109 |
| 110 // Draw the divider and set the text color. | |
| 111 if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 112 NSBezierPath* line = [NSBezierPath bezierPath]; | |
| 113 [line setLineWidth:0]; | |
|
shrike
2016/05/19 17:57:11
Change the line width to 1 - we actually want a 1p
spqchan
2016/05/19 23:05:34
Done.
| |
| 114 [line moveToPoint:NSMakePoint(NSMaxX(decoration_frame) - DividerPadding(), | |
| 115 NSMinY(decoration_frame))]; | |
| 116 [line lineToPoint:NSMakePoint(NSMaxX(decoration_frame) - DividerPadding(), | |
| 117 NSMaxY(decoration_frame))]; | |
| 118 | |
| 119 bool in_dark_mode = [[control_view window] inIncognitoModeWithSystemTheme]; | |
| 120 [GetDividerColor(in_dark_mode) set]; | |
| 121 [line stroke]; | |
| 122 | |
| 123 NSColor* text_color = | |
| 124 in_dark_mode ? [NSColor whiteColor] : GetBackgroundBorderColor(); | |
| 125 SetTextColor(text_color); | |
| 126 } | |
| 127 | |
| 103 if (label_) { | 128 if (label_) { |
| 104 NSRect textRect = frame; | 129 NSRect textRect = frame; |
| 105 textRect.origin.x = textOffset; | 130 textRect.origin.x = textOffset; |
| 106 textRect.origin.y += baseline_offset_; | 131 textRect.origin.y += baseline_offset_; |
| 107 textRect.size.width = NSMaxX(decoration_frame) - NSMinX(textRect); | 132 textRect.size.width = NSMaxX(decoration_frame) - NSMinX(textRect); |
| 108 DrawLabel(label_, attributes_, textRect); | 133 DrawLabel(label_, attributes_, textRect); |
| 109 } | 134 } |
| 110 } | 135 } |
| 111 | 136 |
| 112 void BubbleDecoration::DrawWithBackgroundInFrame(NSRect background_frame, | 137 void BubbleDecoration::DrawWithBackgroundInFrame(NSRect background_frame, |
| 113 NSRect frame, | 138 NSRect frame, |
| 114 NSView* control_view) { | 139 NSView* control_view) { |
| 115 NSRect rect = NSInsetRect(background_frame, 0, 1); | 140 NSRect rect = NSInsetRect(background_frame, 0, 1); |
| 116 rect.size.width -= kRightSideMargin; | 141 rect.size.width -= kRightSideMargin; |
| 117 if (ui::MaterialDesignController::IsModeMaterial()) { | 142 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 118 CGFloat lineWidth = [control_view cr_lineWidth]; | |
| 119 rect = NSInsetRect(rect, lineWidth / 2., lineWidth / 2.); | |
| 120 NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:rect | |
| 121 xRadius:3 | |
| 122 yRadius:3]; | |
| 123 [path setLineWidth:lineWidth]; | |
| 124 bool inDarkMode = [[control_view window] inIncognitoModeWithSystemTheme]; | |
| 125 if (inDarkMode) { | |
| 126 [[NSColor whiteColor] set]; | |
| 127 [path fill]; | |
| 128 } else { | |
| 129 [GetBackgroundBorderColor() set]; | |
| 130 [path stroke]; | |
| 131 } | |
| 132 } else { | |
| 133 ui::DrawNinePartImage( | 143 ui::DrawNinePartImage( |
| 134 rect, GetBubbleImageIds(), NSCompositeSourceOver, 1.0, true); | 144 rect, GetBubbleImageIds(), NSCompositeSourceOver, 1.0, true); |
| 135 } | 145 } |
| 136 | 146 |
| 137 DrawInFrame(frame, control_view); | 147 DrawInFrame(frame, control_view); |
| 138 } | 148 } |
| 139 | 149 |
| 140 NSFont* BubbleDecoration::GetFont() const { | 150 NSFont* BubbleDecoration::GetFont() const { |
| 141 return [attributes_ objectForKey:NSFontAttributeName]; | 151 return [attributes_ objectForKey:NSFontAttributeName]; |
| 142 } | 152 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 161 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName]; | 171 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName]; |
| 162 } | 172 } |
| 163 | 173 |
| 164 void BubbleDecoration::SetFont(NSFont* font) { | 174 void BubbleDecoration::SetFont(NSFont* font) { |
| 165 [attributes_ setObject:font forKey:NSFontAttributeName]; | 175 [attributes_ setObject:font forKey:NSFontAttributeName]; |
| 166 } | 176 } |
| 167 | 177 |
| 168 void BubbleDecoration::SetBaselineOffset(CGFloat offset) { | 178 void BubbleDecoration::SetBaselineOffset(CGFloat offset) { |
| 169 baseline_offset_ = offset; | 179 baseline_offset_ = offset; |
| 170 } | 180 } |
| OLD | NEW |