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

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

Issue 2594543004: [Mac] Fix bubble anchors in RTL (Closed)
Patch Set: Created 4 years 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/content_setting_decoration.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"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 DividerPadding() + kLeftSidePadding; 71 DividerPadding() + kLeftSidePadding;
72 } 72 }
73 73
74 NSRect BubbleDecoration::GetImageRectInFrame(NSRect frame) { 74 NSRect BubbleDecoration::GetImageRectInFrame(NSRect frame) {
75 NSRect image_rect = NSInsetRect(frame, 0.0, kImageFrameYInset); 75 NSRect image_rect = NSInsetRect(frame, 0.0, kImageFrameYInset);
76 if (image_) { 76 if (image_) {
77 // Center the image vertically. 77 // Center the image vertically.
78 const NSSize image_size = [image_ size]; 78 const NSSize image_size = [image_ size];
79 79
80 image_rect.origin.y += 80 image_rect.origin.y +=
81 std::floor((NSHeight(frame) - image_size.height) / 2.0); 81 std::floor((NSHeight(image_rect) - image_size.height) / 2.0);
82 image_rect.origin.x += kLeftSidePadding;
82 image_rect.size = image_size; 83 image_rect.size = image_size;
84 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) {
85 image_rect.origin.x =
86 NSMaxX(frame) - NSWidth(image_rect) - NSMinX(image_rect);
87 }
83 } 88 }
84 return image_rect; 89 return image_rect;
85 } 90 }
86 91
87 NSColor* BubbleDecoration::GetDarkModeTextColor() { 92 NSColor* BubbleDecoration::GetDarkModeTextColor() {
88 return skia::SkColorToSRGBNSColor(kMaterialDarkModeTextColor); 93 return skia::SkColorToSRGBNSColor(kMaterialDarkModeTextColor);
89 } 94 }
90 95
91 CGFloat BubbleDecoration::GetWidthForSpace(CGFloat width) { 96 CGFloat BubbleDecoration::GetWidthForSpace(CGFloat width) {
92 const CGFloat all_width = GetWidthForImageAndLabel(image_, label_); 97 const CGFloat all_width = GetWidthForImageAndLabel(image_, label_);
(...skipping 14 matching lines...) Expand all
107 return background_frame; 112 return background_frame;
108 } 113 }
109 114
110 void BubbleDecoration::DrawInFrame(NSRect frame, NSView* control_view) { 115 void BubbleDecoration::DrawInFrame(NSRect frame, NSView* control_view) {
111 const NSRect decoration_frame = NSInsetRect(frame, 0.0, kImageFrameYInset); 116 const NSRect decoration_frame = NSInsetRect(frame, 0.0, kImageFrameYInset);
112 CGFloat text_left_offset = NSMinX(decoration_frame); 117 CGFloat text_left_offset = NSMinX(decoration_frame);
113 CGFloat text_right_offset = NSMaxX(decoration_frame); 118 CGFloat text_right_offset = NSMaxX(decoration_frame);
114 const BOOL is_rtl = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); 119 const BOOL is_rtl = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
115 120
116 if (image_) { 121 if (image_) {
117 // Center the image vertically. 122 NSRect image_rect = GetImageRectInFrame(frame);
118 const NSSize image_size = [image_ size];
119 NSRect image_rect = decoration_frame;
120 if (is_rtl) {
121 image_rect.origin.x =
122 NSMaxX(decoration_frame) - image_size.width - kLeftSidePadding;
123 } else {
124 image_rect.origin.x += kLeftSidePadding;
125 }
126 image_rect.origin.y +=
127 std::floor((NSHeight(decoration_frame) - image_size.height) / 2.0);
128 image_rect.size = image_size;
129 [image_ drawInRect:image_rect 123 [image_ drawInRect:image_rect
130 fromRect:NSZeroRect // Entire image 124 fromRect:NSZeroRect // Entire image
131 operation:NSCompositeSourceOver 125 operation:NSCompositeSourceOver
132 fraction:1.0 126 fraction:1.0
133 respectFlipped:YES 127 respectFlipped:YES
134 hints:nil]; 128 hints:nil];
135 if (is_rtl) 129 if (is_rtl)
136 text_right_offset = NSMinX(image_rect) - kIconLabelPadding; 130 text_right_offset = NSMinX(image_rect) - kIconLabelPadding;
137 else 131 else
138 text_left_offset = NSMaxX(image_rect) + kIconLabelPadding; 132 text_left_offset = NSMaxX(image_rect) + kIconLabelPadding;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName]; 191 [attributes_ setObject:text_color forKey:NSForegroundColorAttributeName];
198 } 192 }
199 193
200 void BubbleDecoration::SetFont(NSFont* font) { 194 void BubbleDecoration::SetFont(NSFont* font) {
201 [attributes_ setObject:font forKey:NSFontAttributeName]; 195 [attributes_ setObject:font forKey:NSFontAttributeName];
202 } 196 }
203 197
204 void BubbleDecoration::SetRetinaBaselineOffset(CGFloat offset) { 198 void BubbleDecoration::SetRetinaBaselineOffset(CGFloat offset) {
205 retina_baseline_offset_ = offset; 199 retina_baseline_offset_ = offset;
206 } 200 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/location_bar/content_setting_decoration.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698