Skip to content

Commit

Permalink
Modifies layout of the zoom bubble
Browse files Browse the repository at this point in the history
Makes ZoomBubbleView follow the layout from the mock in the bug.
Fixes the vector icons (+ / -) to have sharp edges rather than using a
rounded stroke.

Bug: 651641
Test: Visual (compare to mock)
Change-Id: I23bd9633037cf529e69f5b72ae9810ca5124da96
Reviewed-on: https://chromium-review.googlesource.com/673486
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Valery Arkhangorodsky <varkha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#503578}
  • Loading branch information
Valery Arkhangorodsky authored and Commit Bot committed Sep 21, 2017
1 parent ba35577 commit 98a273d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 44 deletions.
2 changes: 0 additions & 2 deletions chrome/app/vector_icons/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ aggregate_vector_icons("chrome_vector_icons") {
"account_child.icon",
"account_child_circle.icon",
"account_circle.icon",
"add.1x.icon",
"add.icon",
"apps.icon",
"blocked_badge.icon",
Expand Down Expand Up @@ -74,7 +73,6 @@ aggregate_vector_icons("chrome_vector_icons") {
"paintbrush.icon",
"photo_camera.icon",
"profile_switcher_outline.icon",
"remove.1x.icon",
"remove.icon",
"remove_box.icon",
"sad_tab.icon",
Expand Down
11 changes: 0 additions & 11 deletions chrome/app/vector_icons/add.1x.icon

This file was deleted.

13 changes: 7 additions & 6 deletions chrome/app/vector_icons/add.icon
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

CANVAS_DIMENSIONS, 32,
STROKE, 3.5f,
MOVE_TO, 8.75f, 16.f,
R_H_LINE_TO, 14.5f,
MOVE_TO, 16.f, 8.75f,
R_V_LINE_TO, 14.5f,
CANVAS_DIMENSIONS, 16,
STROKE, 2.f,
CAP_SQUARE,
MOVE_TO, 2, 8,
R_H_LINE_TO, 12,
MOVE_TO, 8, 2,
R_V_LINE_TO, 12,
END
9 changes: 0 additions & 9 deletions chrome/app/vector_icons/remove.1x.icon

This file was deleted.

9 changes: 5 additions & 4 deletions chrome/app/vector_icons/remove.icon
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

CANVAS_DIMENSIONS, 32,
STROKE, 3.5f,
MOVE_TO, 8.75f, 16.f,
R_H_LINE_TO, 14.5f,
CANVAS_DIMENSIONS, 16,
STROKE, 2.f,
CAP_SQUARE,
MOVE_TO, 2, 8,
R_H_LINE_TO, 12,
END
57 changes: 45 additions & 12 deletions chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view_properties.h"
#include "ui/views/widget/widget.h"

namespace {
Expand Down Expand Up @@ -78,7 +79,9 @@ class ZoomValue : public views::Label {
: Label(base::string16(),
views::style::CONTEXT_LABEL,
views::style::STYLE_PRIMARY),
max_width_(GetLabelMaxWidth(web_contents)) {}
max_width_(GetLabelMaxWidth(web_contents)) {
SetHorizontalAlignment(gfx::ALIGN_LEFT);
}
~ZoomValue() override {}

// views::Label:
Expand All @@ -88,7 +91,7 @@ class ZoomValue : public views::Label {

private:
int GetLabelMaxWidth(const content::WebContents* web_contents) const {
int border_width = border() ? border()->GetInsets().width() : 0;
const int border_width = border() ? border()->GetInsets().width() : 0;
int max_w = 0;
auto* zoom_controller = zoom::ZoomController::FromWebContents(web_contents);
DCHECK(zoom_controller);
Expand Down Expand Up @@ -268,18 +271,35 @@ void ZoomBubbleView::OnMouseExited(const ui::MouseEvent& event) {

void ZoomBubbleView::Init() {
// Set up the layout of the zoom bubble.
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
const int margin =
provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL);
const ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
const int spacing =
provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL);
views::BoxLayout* box_layout = new views::BoxLayout(
views::BoxLayout::kHorizontal, gfx::Insets(0, margin), margin);

views::BoxLayout::kHorizontal,
provider->GetInsetsMetric(INSETS_TOAST) - margins(), spacing);
box_layout->set_main_axis_alignment(
views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
box_layout->set_cross_axis_alignment(
views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
SetLayoutManager(box_layout);

// Calculate child views margins in |this| client view.
const int label_vertical_spacing =
provider->GetDistanceMetric(DISTANCE_TOAST_LABEL_VERTICAL);
const gfx::Insets label_vertical_margin(
label_vertical_spacing - margins().top(), 0,
label_vertical_spacing - margins().bottom(), 0);

// Account for the apparent margins that vector buttons have around icons.
const int control_vertical_spacing =
provider->GetDistanceMetric(DISTANCE_TOAST_CONTROL_VERTICAL);
const gfx::Insets control_vertical_margin(
control_vertical_spacing - margins().top(), 0,
control_vertical_spacing - margins().bottom(), 0);
const gfx::Insets vector_button_margin(
control_vertical_margin -
provider->GetInsetsMetric(views::INSETS_VECTOR_IMAGE_BUTTON));

// If this zoom change was initiated by an extension, that extension will be
// attributed by showing its icon in the zoom bubble.
if (extension_info_.icon_image) {
Expand All @@ -292,21 +312,34 @@ void ZoomBubbleView::Init() {
AddChildView(image_button_);
}

// Add zoom label with the new zoom percent.
label_ = new ZoomValue(web_contents_);
UpdateZoomPercent();
label_->SetProperty(views::kMarginsKey,
new gfx::Insets(label_vertical_margin));
AddChildView(label_);

// Add extra padding between the zoom percent label and the buttons.
constexpr int kPercentLabelPadding = 64;
auto* label_padding_view = new views::View();
label_padding_view->SetPreferredSize(gfx::Size(
kPercentLabelPadding - spacing * 2, label_->GetPreferredSize().height()));
AddChildView(label_padding_view);

// Add Zoom Out ("-") button.
std::unique_ptr<views::Button> zoom_out_button =
CreateZoomButton(this, kRemoveIcon, IDS_ACCNAME_ZOOM_MINUS2);
zoom_out_button_ = zoom_out_button.get();
zoom_out_button_->SetProperty(views::kMarginsKey,
new gfx::Insets(vector_button_margin));
AddChildView(zoom_out_button.release());

// Add zoom label with the new zoom percent.
label_ = new ZoomValue(web_contents_);
UpdateZoomPercent();
AddChildView(label_);

// Add Zoom In ("+") button.
std::unique_ptr<views::Button> zoom_in_button =
CreateZoomButton(this, kAddIcon, IDS_ACCNAME_ZOOM_PLUS2);
zoom_in_button_ = zoom_in_button.get();
zoom_in_button_->SetProperty(views::kMarginsKey,
new gfx::Insets(vector_button_margin));
AddChildView(zoom_in_button.release());

// Add "Reset" button.
Expand Down

0 comments on commit 98a273d

Please sign in to comment.