diff options
author | macourteau@chromium.org <macourteau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-09 22:00:31 +0000 |
---|---|---|
committer | macourteau@chromium.org <macourteau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-09 22:00:31 +0000 |
commit | 3c66b63829bbcae3f7c999113b1931dc5e5d40ce (patch) | |
tree | 727ae8a661696cb0ae574f27997ba7156e0c97c1 | |
parent | 47495ec191f094419db7cb164de7c39cb0acf722 (diff) | |
download | chromium_src-3c66b63829bbcae3f7c999113b1931dc5e5d40ce.zip chromium_src-3c66b63829bbcae3f7c999113b1931dc5e5d40ce.tar.gz chromium_src-3c66b63829bbcae3f7c999113b1931dc5e5d40ce.tar.bz2 |
Always display the origin chip, even if it won't fit.
BUG=369853
R=shess@chromium.org
Review URL: https://codereview.chromium.org/273883002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269425 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.h | 3 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.mm | 25 |
2 files changed, 15 insertions, 13 deletions
diff --git a/chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.h b/chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.h index 2b0fee9..1c7b5d7 100644 --- a/chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.h +++ b/chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.h @@ -52,6 +52,9 @@ class OriginChipDecoration : public ButtonDecoration, // Returns whether the origin chip should be shown or not. bool ShouldShow() const; + // Returns the width required to display the chip's contents. + CGFloat GetChipWidth() const; + // Contains attributes for drawing the origin string. base::scoped_nsobject<NSMutableDictionary> attributes_; diff --git a/chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.mm b/chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.mm index 43ca9ad..15f62dc 100644 --- a/chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.mm +++ b/chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.mm @@ -125,27 +125,18 @@ void OriginChipDecoration::Update() { } CGFloat OriginChipDecoration::GetWidthForSpace(CGFloat width) { - NSImage* icon = GetIconImage(); - if (!icon || [label_ length] == 0) + if (!GetIconImage() || [label_ length] == 0) return kOmittedWidth; - const CGFloat label_width = [label_ sizeWithAttributes:attributes_].width; - const CGFloat min_width = kInnerLeftPadding + - kIconSize + - kIconLabelPadding + - std::ceil(label_width) + - kInnerRightPadding + - kOuterRightPadding; - - return (width < min_width) ? kOmittedWidth : min_width; + // Clip the chip if it can't fit, rather than hiding it (kOmittedWidth). + return std::min(width, GetChipWidth() + kOuterRightPadding); } void OriginChipDecoration::DrawInFrame(NSRect frame, NSView* control_view) { // The assets are aligned with the location bar assets, so check that we are // being asked to draw against the edge, then draw over the border. DCHECK(NSMinX(frame) == [control_view cr_lineWidth]); - frame = NSMakeRect(0, NSMinY(frame), NSWidth(frame) - kOuterRightPadding, - NSHeight(frame)); + frame = NSMakeRect(0, NSMinY(frame), GetChipWidth(), NSHeight(frame)); const ui::NinePartImageIds image_ids = GetBackgroundImageIds(); @@ -224,6 +215,14 @@ bool OriginChipDecoration::ShouldShow() const { owner_->GetToolbarModel()->origin_chip_enabled()); } +CGFloat OriginChipDecoration::GetChipWidth() const { + return kInnerLeftPadding + + kIconSize + + kIconLabelPadding + + std::ceil([label_ sizeWithAttributes:attributes_].width) + + kInnerRightPadding; +} + // TODO(macourteau): Implement eliding of the host. // TODO(macourteau): Implement dragging support. |