Chromium Code Reviews| Index: chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm |
| diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm |
| index db647f8f6cf83e360090cc8347955909ec406ba6..f1ae09893ec1e97529c2f0f37b6b1a9c8f1e4d8a 100644 |
| --- a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm |
| +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm |
| @@ -4,7 +4,10 @@ |
| #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" |
| +#include <algorithm> |
| #include <cmath> |
| +#include "base/i18n/rtl.h" |
| +#include "base/logging.h" |
| namespace { |
| @@ -20,14 +23,41 @@ const CGFloat kCellRoundingRadius = 2.0; |
| NSColor* SelectedBackgroundColor() { |
| return [NSColor selectedControlColor]; |
| } |
| + |
| NSColor* HoveredBackgroundColor() { |
| return [NSColor controlHighlightColor]; |
| } |
| + |
| +// Flips the given |rect| in context of the given |frame|. |
| +NSRect FlipVertical(NSRect rect, NSRect frame) { |
| + NSRect result = rect; |
| + // Translate the right margin of rect inside frame to the left margin. |
| + result.origin.x = frame.origin.x + |
| + ((frame.origin.x + frame.size.width) - (rect.origin.x + rect.size.width)); |
|
Scott Hess - ex-Googler
2013/12/16 22:22:05
Try:
result.origin.x = NSMinX(frame) + (NSMaxX(f
Anuj
2013/12/19 05:36:13
Done.
|
| + return result; |
| +} |
| + |
| } // namespace |
| @implementation OmniboxPopupCell |
| +- (void)setRequiredWidth:(CGFloat)requiredWidth { |
| + requiredWidth_ = requiredWidth; |
| +} |
| + |
| +- (void)setContentsWidth:(CGFloat)contentsWidth { |
| + contentsWidth_ = contentsWidth; |
| +} |
| + |
| +- (void)setMaxRequiredWidth:(CGFloat)maxRequiredWidth { |
| + maxRequiredWidth_ = maxRequiredWidth; |
| +} |
| + |
| +- (void)setMaxContentsWidth:(CGFloat)maxContentsWidth { |
| + maxContentsWidth_ = maxContentsWidth; |
| +} |
| + |
| - (id)init { |
| self = [super init]; |
| if (self) { |
| @@ -41,6 +71,13 @@ NSColor* HoveredBackgroundColor() { |
| return self; |
| } |
| +- (CGFloat)textOffset:(NSRect)cellFrame { |
| + CGFloat offset = (cellFrame.size.width < maxRequiredWidth_ + kTextXOffset) ? |
| + (cellFrame.size.width - maxContentsWidth_) : |
| + (requiredWidth_ - contentsWidth_); |
| + return kTextXOffset + std::max(offset, 0.0f); |
| +} |
| + |
| // The default NSButtonCell drawing leaves the image flush left and |
| // the title next to the image. This spaces things out to line up |
| // with the star button and autocomplete field. |
| @@ -57,6 +94,8 @@ NSColor* HoveredBackgroundColor() { |
| [path fill]; |
| } |
| + bool isRTL = base::i18n::IsRTL(); |
| + |
| // Put the image centered vertically but in a fixed column. |
| NSImage* image = [self image]; |
| if (image) { |
| @@ -65,6 +104,8 @@ NSColor* HoveredBackgroundColor() { |
| imageRect.origin.y += |
| std::floor((NSHeight(cellFrame) - NSHeight(imageRect)) / 2.0); |
| imageRect.origin.x += kImageXOffset; |
| + if (isRTL) |
| + imageRect = FlipVertical(imageRect, cellFrame); |
| [image drawInRect:imageRect |
| fromRect:NSZeroRect // Entire image |
| operation:NSCompositeSourceOver |
| @@ -77,8 +118,12 @@ NSColor* HoveredBackgroundColor() { |
| NSAttributedString* title = [self attributedTitle]; |
| if (title && [title length]) { |
| NSRect titleRect = cellFrame; |
| - titleRect.size.width -= kTextXOffset; |
| - titleRect.origin.x += kTextXOffset; |
| + CGFloat textXOffset = [self textOffset:cellFrame]; |
| + titleRect.size.width -= textXOffset; |
| + titleRect.origin.x += textXOffset; |
| + |
| + if (isRTL) |
| + titleRect = FlipVertical(titleRect, cellFrame); |
| [self drawTitle:title withFrame:titleRect inView:controlView]; |
| } |
| } |