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
parent 47495ec1
......@@ -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_;
......
......@@ -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.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment