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

Side by Side Diff: chrome/browser/ui/cocoa/website_settings/website_settings_bubble_controller.mm

Issue 1059333003: Mac: Fix broken website settings bubble when using Right-to-Left languages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@OnWindowWillClose
Patch Set: Created 5 years, 8 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro ller.h" 5 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro ller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #import <AppKit/AppKit.h> 9 #import <AppKit/AppKit.h>
10 10
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 NSDrawThreePartImage(backgroundRect, 217 NSDrawThreePartImage(backgroundRect,
218 tabstripRightImage_, 218 tabstripRightImage_,
219 tabstripCenterImage_, 219 tabstripCenterImage_,
220 nil, 220 nil,
221 /*vertical=*/ NO, 221 /*vertical=*/ NO,
222 NSCompositeSourceOver, 222 NSCompositeSourceOver,
223 1, 223 1,
224 /*flipped=*/ YES); 224 /*flipped=*/ YES);
225 225
226 // Call the superclass method to trigger drawing of the tab labels. 226 // Call the superclass method to trigger drawing of the tab labels.
227 [self drawInteriorWithFrame:cellFrame inView:controlView]; 227 NSRect interiorFrame = cellFrame;
228 interiorFrame.size.width = 0;
229 for (NSInteger i = 0; i < [self segmentCount]; ++i)
230 interiorFrame.size.width += [self widthForSegment:i];
231 [self drawInteriorWithFrame:interiorFrame inView:controlView];
Andre 2015/04/04 00:17:48 Without this fix, the text will draw on the right
232
228 if ([[controlView window] firstResponder] == controlView) 233 if ([[controlView window] firstResponder] == controlView)
229 [self drawFocusRect]; 234 [self drawFocusRect];
230 } 235 }
231 236
232 - (void)drawFocusRect { 237 - (void)drawFocusRect {
233 gfx::ScopedNSGraphicsContextSaveGState scoped_state; 238 gfx::ScopedNSGraphicsContextSaveGState scoped_state;
234 NSSetFocusRingStyle(NSFocusRingOnly); 239 NSSetFocusRingStyle(NSFocusRingOnly);
235 [[NSColor keyboardFocusIndicatorColor] set]; 240 [[NSColor keyboardFocusIndicatorColor] set];
236 NSFrameRect([self hitRectForSegment:keySegment_]); 241 NSFrameRect([self hitRectForSegment:keySegment_]);
237 } 242 }
238 243
244 // Returns the segment number for the left-most positioned segment.
245 // On Right-to-Left languages, segment 0 is on the right.
246 - (NSInteger)leftSegment {
247 BOOL isRTL = [self userInterfaceLayoutDirection] ==
248 NSUserInterfaceLayoutDirectionRightToLeft;
249 return isRTL ? [self segmentCount] - 1 : 0;
250 }
251
239 // Return the hit rect (i.e., the visual bounds of the tab) for 252 // Return the hit rect (i.e., the visual bounds of the tab) for
240 // the given segment. 253 // the given segment.
241 - (NSRect)hitRectForSegment:(NSInteger)segment { 254 - (NSRect)hitRectForSegment:(NSInteger)segment {
242 CGFloat tabstripHeight = [tabCenterImage_ size].height; 255 CGFloat tabstripHeight = [tabCenterImage_ size].height;
243 DCHECK_GT(tabstripHeight, kTabHeight); 256 DCHECK_GT(tabstripHeight, kTabHeight);
244 257 DCHECK([self segmentCount] == 2); // Assume 2 segments to keep things simple.
245 NSRect rect = NSMakeRect(0, tabstripHeight - kTabHeight, 258 NSInteger leftSegment = [self leftSegment];
246 [self widthForSegment:segment], kTabHeight); 259 CGFloat xOrigin = segment == leftSegment ? kTabStripXPadding
247 for (NSInteger i = 0; i < segment; ++i) { 260 : [self widthForSegment:leftSegment];
248 rect.origin.x += [self widthForSegment:i]; 261 NSRect rect = NSMakeRect(xOrigin, tabstripHeight - kTabHeight,
249 } 262 [self widthForSegment:segment] - kTabStripXPadding,
250 int xAdjust = segment == 0 ? kTabStripXPadding : 0; 263 kTabHeight);
251 rect.size.width = std::floor( 264 return NSInsetRect(rect, kTabSpacing / 2, 0);
252 [self widthForSegment:segment] - kTabSpacing - xAdjust);
253 rect.origin.x = std::floor(rect.origin.x + kTabSpacing / 2 + xAdjust);
254
255 return rect;
256 } 265 }
257 266
258 - (void)drawSegment:(NSInteger)segment 267 - (void)drawSegment:(NSInteger)segment
259 inFrame:(NSRect)tabFrame 268 inFrame:(NSRect)tabFrame
260 withView:(NSView*)controlView { 269 withView:(NSView*)controlView {
261 // Adjust the tab's frame so that the label appears centered in the tab. 270 // Adjust the tab's frame so that the label appears centered in the tab.
262 if (segment == 0) { 271 if (segment == [self leftSegment])
263 tabFrame.origin.x += kTabStripXPadding; 272 tabFrame.origin.x += kTabStripXPadding;
264 tabFrame.size.width -= kTabStripXPadding; 273 tabFrame.size.width -= kTabStripXPadding;
265 }
266 tabFrame.origin.y += kTabLabelTopPadding; 274 tabFrame.origin.y += kTabLabelTopPadding;
267 tabFrame.size.height -= kTabLabelTopPadding; 275 tabFrame.size.height -= kTabLabelTopPadding;
268 276
269 // Center the label's frame in the tab's frame. 277 // Center the label's frame in the tab's frame.
270 NSString* label = [self labelForSegment:segment]; 278 NSString* label = [self labelForSegment:segment];
271 NSDictionary* textAttributes = 279 NSDictionary* textAttributes =
272 [WebsiteSettingsTabSegmentedCell textAttributes]; 280 [WebsiteSettingsTabSegmentedCell textAttributes];
273 NSSize textSize = [label sizeWithAttributes:textAttributes]; 281 NSSize textSize = [label sizeWithAttributes:textAttributes];
274 NSRect labelFrame; 282 NSRect labelFrame;
275 labelFrame.size = textSize; 283 labelFrame.size = textSize;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 465
458 DCHECK_EQ([segmentedControl_ segmentCount], WebsiteSettingsUI::NUM_TAB_IDS); 466 DCHECK_EQ([segmentedControl_ segmentCount], WebsiteSettingsUI::NUM_TAB_IDS);
459 467
460 // Make both tabs the width of the widest. The first segment has some 468 // Make both tabs the width of the widest. The first segment has some
461 // additional padding that is not part of the tab, which is used for drawing 469 // additional padding that is not part of the tab, which is used for drawing
462 // the background of the tab strip. 470 // the background of the tab strip.
463 tabWidth = std::max(tabWidth, 471 tabWidth = std::max(tabWidth,
464 textSize.width + 2 * kTabLabelXPadding); 472 textSize.width + 2 * kTabLabelXPadding);
465 [segmentedControl_ setWidth:tabWidth + kTabStripXPadding 473 [segmentedControl_ setWidth:tabWidth + kTabStripXPadding
466 forSegment:WebsiteSettingsUI::TAB_ID_PERMISSIONS]; 474 forSegment:WebsiteSettingsUI::TAB_ID_PERMISSIONS];
467 [segmentedControl_ setWidth:tabWidth 475 [segmentedControl_ setWidth:tabWidth + kTabStripXPadding
Andre 2015/04/04 00:17:49 Give padding to this segment as well, because on R
468 forSegment:WebsiteSettingsUI::TAB_ID_CONNECTION]; 476 forSegment:WebsiteSettingsUI::TAB_ID_CONNECTION];
469 477
470 [segmentedControl_ setFont:[textAttributes objectForKey:NSFontAttributeName]]; 478 [segmentedControl_ setFont:[textAttributes objectForKey:NSFontAttributeName]];
471 [contentView_ addSubview:segmentedControl_]; 479 [contentView_ addSubview:segmentedControl_];
472 480
473 NSRect tabFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); 481 NSRect tabFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300);
474 tabView_.reset([[NSTabView alloc] initWithFrame:tabFrame]); 482 tabView_.reset([[NSTabView alloc] initWithFrame:tabFrame]);
475 [tabView_ setTabViewType:NSNoTabsNoBorder]; 483 [tabView_ setTabViewType:NSNoTabsNoBorder];
476 [tabView_ setDrawsBackground:NO]; 484 [tabView_ setDrawsBackground:NO];
477 [tabView_ setControlSize:NSSmallControlSize]; 485 [tabView_ setControlSize:NSSmallControlSize];
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 [bubble_controller_ setPermissionInfo:permission_info_list]; 1287 [bubble_controller_ setPermissionInfo:permission_info_list];
1280 } 1288 }
1281 1289
1282 void WebsiteSettingsUIBridge::SetFirstVisit(const base::string16& first_visit) { 1290 void WebsiteSettingsUIBridge::SetFirstVisit(const base::string16& first_visit) {
1283 [bubble_controller_ setFirstVisit:first_visit]; 1291 [bubble_controller_ setFirstVisit:first_visit];
1284 } 1292 }
1285 1293
1286 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { 1294 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) {
1287 [bubble_controller_ setSelectedTab:tab_id]; 1295 [bubble_controller_ setSelectedTab:tab_id];
1288 } 1296 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698