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

Unified Diff: chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc

Issue 2064323005: Change IconLabelBubbleView layout to specify padding beside the separator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_constants
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/location_bar/icon_label_bubble_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
index 7f4bd8254ebae0064bafc5a7329f85f740fdf47d..daecd8a9d3af401f291865c5b70341585e7250e0 100644
--- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
+++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
@@ -22,8 +22,12 @@
namespace {
-// Extra padding to place at the end of the chip when the label is showing.
-const int kExtraTrailingPadding = 7;
+// Amount of space on either side of the separator that appears after the label.
+constexpr int kSpaceBesideSeparator = 8;
+
+// We really only want 1 px for the separator, but there's no way to use that to
+// lay out, so the best we can do is to reserve a whole DIP.
Evan Stade 2016/06/15 23:12:58 wouldn't the more correct thing to do be reserve 0
Peter Kasting 2016/06/16 05:12:39 Yeah, that would be better. Changed, though this
+constexpr int kSeparatorWidth = 1;
SkColor CalculateImageColor(gfx::ImageSkia* image) {
// We grab the color of the middle pixel of the image, which we treat as
@@ -229,18 +233,14 @@ gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const {
// is necessary to animate |total_width| even when the background is hidden
// as long as the animation is still shrinking.
if (ShouldShowBackground() || shrinking) {
- const int extra_trailing_padding =
- ui::MaterialDesignController::IsModeMaterial() ? kExtraTrailingPadding
- : 0;
// |multiplier| grows from zero to one, stays equal to one and then shrinks
// to zero again. The view width should correspondingly grow from zero to
// fully showing both label and icon, stay there, then shrink to just large
// enough to show the icon. We don't want to shrink all the way back to
// zero, since this would mean the view would completely disappear and then
// pop back to an icon after the animation finishes.
- const int max_width = MinimumWidthForImageWithBackgroundShown() +
- GetInternalSpacing() + label_width +
- extra_trailing_padding;
+ const int max_width = GetImageTrailingEdge() + GetInternalSpacing() +
+ label_width + GetPostLabelWidth();
const int current_width = WidthMultiplier() * max_width;
size.set_width(shrinking ? std::max(current_width, size.width())
: current_width);
@@ -249,8 +249,7 @@ gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const {
}
int IconLabelBubbleView::MinimumWidthForImageWithBackgroundShown() const {
- return GetOuterPadding(true) + image_->GetPreferredSize().width() +
- GetOuterPadding(false);
+ return GetImageTrailingEdge() + GetOuterPadding(false);
}
void IconLabelBubbleView::SetLabelBackgroundColor(
@@ -276,12 +275,25 @@ int IconLabelBubbleView::GetOuterPadding(bool leading) const {
(leading ? 0 : kTrailingPaddingPreMD);
}
+int IconLabelBubbleView::GetImageTrailingEdge() const {
+ return GetOuterPadding(true) + image_->GetPreferredSize().width();
+}
+
int IconLabelBubbleView::GetInternalSpacing() const {
return image_->GetPreferredSize().IsEmpty()
? 0
: GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
}
+int IconLabelBubbleView::GetPostLabelWidth() const {
+ if (!ui::MaterialDesignController::IsModeMaterial())
+ return GetOuterPadding(false);
+
+ // The location bar will add LOCATION_BAR_HORIZONTAL_PADDING after us.
+ return (kSpaceBesideSeparator * 2) + kSeparatorWidth -
+ GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
+}
+
const char* IconLabelBubbleView::GetClassName() const {
return "IconLabelBubbleView";
}
@@ -301,27 +313,20 @@ void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) {
const SkColor separator_color = SkColorSetA(
plain_text_color, color_utils::IsDark(plain_text_color) ? 0x59 : 0xCC);
- // Amount of padding that is built into the whatever view comes after this
- // one in the location bar (e.g. omnibox textfield).
- int post_chip_spacing =
- GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
- // Amount of space to leave after the separator (dp).
- const int kPostSeparatorSpacing =
(GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) +
- kExtraTrailingPadding + post_chip_spacing) /
- 2 -
- post_chip_spacing;
- // Height of the separator (dp).
- const int kSeparatorHeight = 16;
gfx::Rect bounds(GetLocalBounds());
- bounds.Inset(kPostSeparatorSpacing,
+ const int kSeparatorHeight = 16;
+ bounds.Inset(GetPostLabelWidth() - kSpaceBesideSeparator - kSeparatorWidth,
(bounds.height() - kSeparatorHeight) / 2);
- // 1px at all scale factors.
+ // Draw the 1 px separator.
gfx::ScopedCanvas scoped_canvas(canvas);
const float scale = canvas->UndoDeviceScaleFactor();
+ // Keep the separator aligned on a pixel center, but center it within the
+ // DIP if the scale factor is large enough.
const gfx::RectF pixel_aligned_bounds =
- gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0);
+ gfx::ScaleRect(gfx::RectF(bounds), scale) -
+ gfx::Vector2dF(std::floor((scale - 1) / 2) + 0.5f, 0);
canvas->DrawLine(pixel_aligned_bounds.top_right(),
pixel_aligned_bounds.bottom_right(), separator_color);
}
« no previous file with comments | « chrome/browser/ui/views/location_bar/icon_label_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698