Commit 45ddd51e authored by Kevin Bailey's avatar Kevin Bailey Committed by Commit Bot

[omnibox] Make tab switch button rounded

This CL adds the ability to customize MdTextButton's so that their
corners are rounded. This CL then makes the tab switch button round.

Bug: 780835
Change-Id: I2c46481caef074db009e681491d4f0b6822be861
Reviewed-on: https://chromium-review.googlesource.com/963836
Commit-Queue: Kevin Bailey <krb@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545693}
parent ebb86757
...@@ -133,7 +133,8 @@ OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model, ...@@ -133,7 +133,8 @@ OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model,
keyword_icon_view_->SizeToPreferredSize(); keyword_icon_view_->SizeToPreferredSize();
if (OmniboxFieldTrial::InTabSwitchSuggestionWithButtonTrial()) { if (OmniboxFieldTrial::InTabSwitchSuggestionWithButtonTrial()) {
tab_switch_button_.reset(new OmniboxTabSwitchButton(this)); tab_switch_button_ =
std::make_unique<OmniboxTabSwitchButton>(this, GetTextHeight());
tab_switch_button_->set_owned_by_client(); tab_switch_button_->set_owned_by_client();
} }
} }
...@@ -486,12 +487,13 @@ void OmniboxResultView::Layout() { ...@@ -486,12 +487,13 @@ void OmniboxResultView::Layout() {
icon.Height()); icon.Height());
if (tab_switch_button_ && match_.type == AutocompleteMatchType::TAB_SEARCH) { if (tab_switch_button_ && match_.type == AutocompleteMatchType::TAB_SEARCH) {
const int ts_button_width = tab_switch_button_->GetPreferredSize().width(); const gfx::Size ts_button_size = tab_switch_button_->GetPreferredSize();
const int ts_button_height = height(); tab_switch_button_->SetSize(ts_button_size);
tab_switch_button_->SetSize(gfx::Size(ts_button_width, ts_button_height));
end_x -= ts_button_width; // It looks nice to have the same margin on top, bottom and right side.
tab_switch_button_->SetPosition(gfx::Point(end_x, 0)); const int margin = (height() - ts_button_size.height()) / 2;
end_x -= ts_button_size.width() + margin;
tab_switch_button_->SetPosition(gfx::Point(end_x, margin));
} }
// NOTE: While animating the keyword match, both matches may be visible. // NOTE: While animating the keyword match, both matches may be visible.
......
...@@ -13,21 +13,23 @@ ...@@ -13,21 +13,23 @@
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
OmniboxTabSwitchButton::OmniboxTabSwitchButton(OmniboxResultView* result_view) OmniboxTabSwitchButton::OmniboxTabSwitchButton(OmniboxResultView* result_view,
int text_height)
: MdTextButton(this, views::style::CONTEXT_BUTTON_MD), : MdTextButton(this, views::style::CONTEXT_BUTTON_MD),
text_height_(text_height),
result_view_(result_view) { result_view_(result_view) {
// TODO: SetTooltipText(text); // TODO: SetTooltipText(text);
// SetImageAlignment(ALIGN_CENTER, ALIGN_MIDDLE); // SetImageAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
SetBackground(std::make_unique<BackgroundWith1PxBorder>(GetBackgroundColor(),
SK_ColorBLACK));
SetBgColorOverride(GetBackgroundColor()); SetBgColorOverride(GetBackgroundColor());
SetImage(STATE_NORMAL, SetImage(STATE_NORMAL,
gfx::CreateVectorIcon(omnibox::kSwitchIcon, 16, SK_ColorBLACK)); gfx::CreateVectorIcon(omnibox::kSwitchIcon, 16, SK_ColorBLACK));
SetText(base::ASCIIToUTF16("Switch to open tab")); SetText(base::ASCIIToUTF16("Switch to open tab"));
set_corner_radius(CalculatePreferredSize().height() / 2.f);
} }
gfx::Size OmniboxTabSwitchButton::CalculatePreferredSize() const { gfx::Size OmniboxTabSwitchButton::CalculatePreferredSize() const {
gfx::Size size = MdTextButton::CalculatePreferredSize(); gfx::Size size = MdTextButton::CalculatePreferredSize();
size.set_height(text_height_ + kVerticalPadding);
const int horizontal_padding = const int horizontal_padding =
GetLayoutConstant(LOCATION_BAR_PADDING) + GetLayoutConstant(LOCATION_BAR_PADDING) +
GetLayoutConstant(LOCATION_BAR_ICON_INTERIOR_PADDING); GetLayoutConstant(LOCATION_BAR_ICON_INTERIOR_PADDING);
......
...@@ -12,7 +12,7 @@ class OmniboxResultView; ...@@ -12,7 +12,7 @@ class OmniboxResultView;
class OmniboxTabSwitchButton : public views::MdTextButton, class OmniboxTabSwitchButton : public views::MdTextButton,
public views::ButtonListener { public views::ButtonListener {
public: public:
explicit OmniboxTabSwitchButton(OmniboxResultView* result_view); OmniboxTabSwitchButton(OmniboxResultView* result_view, int text_height);
// views::View // views::View
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
...@@ -24,12 +24,18 @@ class OmniboxTabSwitchButton : public views::MdTextButton, ...@@ -24,12 +24,18 @@ class OmniboxTabSwitchButton : public views::MdTextButton,
void StateChanged(ButtonState old_state) override; void StateChanged(ButtonState old_state) override;
private: private:
// Encapsulates the color look-up, which uses the button state (hovered,
// etc.) and consults the parent result view.
SkColor GetBackgroundColor() const; SkColor GetBackgroundColor() const;
OmniboxResultView* result_view_; // Encapsulates changing the color of the button to display being
// pressed.
void SetPressed(); void SetPressed();
static constexpr int kVerticalPadding = 2;
const int text_height_;
OmniboxResultView* result_view_;
DISALLOW_COPY_AND_ASSIGN(OmniboxTabSwitchButton); DISALLOW_COPY_AND_ASSIGN(OmniboxTabSwitchButton);
}; };
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// found in the LICENSE file. // found in the LICENSE file.
CANVAS_DIMENSIONS, 32, CANVAS_DIMENSIONS, 32,
MOVE_TO, 4, 6, MOVE_TO, 4, 8,
LINE_TO, 26, 6, LINE_TO, 26, 8,
LINE_TO, 26, 24, LINE_TO, 26, 26,
LINE_TO, 4, 24, LINE_TO, 4, 26,
LINE_TO, 4, 8, LINE_TO, 4, 10,
LINE_TO, 5, 8, LINE_TO, 5, 10,
LINE_TO, 5, 23, LINE_TO, 5, 25,
LINE_TO, 25, 23, LINE_TO, 25, 25,
LINE_TO, 25, 13, LINE_TO, 25, 15,
LINE_TO, 16, 13, LINE_TO, 16, 15,
LINE_TO, 16, 7, LINE_TO, 16, 9,
LINE_TO, 4, 7, LINE_TO, 4, 9,
CLOSE CLOSE
...@@ -159,7 +159,7 @@ std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() ...@@ -159,7 +159,7 @@ std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight()
return std::make_unique<InkDropHighlight>( return std::make_unique<InkDropHighlight>(
gfx::RectF(GetLocalBounds()).CenterPoint(), gfx::RectF(GetLocalBounds()).CenterPoint(),
base::WrapUnique(new BorderShadowLayerDelegate( base::WrapUnique(new BorderShadowLayerDelegate(
shadows, GetLocalBounds(), fill_color, kInkDropSmallCornerRadius))); shadows, GetLocalBounds(), fill_color, corner_radius_)));
} }
void MdTextButton::SetEnabledTextColors(SkColor color) { void MdTextButton::SetEnabledTextColors(SkColor color) {
...@@ -179,7 +179,8 @@ void MdTextButton::UpdateStyleToIndicateDefaultStatus() { ...@@ -179,7 +179,8 @@ void MdTextButton::UpdateStyleToIndicateDefaultStatus() {
MdTextButton::MdTextButton(ButtonListener* listener, int button_context) MdTextButton::MdTextButton(ButtonListener* listener, int button_context)
: LabelButton(listener, base::string16(), button_context), : LabelButton(listener, base::string16(), button_context),
is_prominent_(false) { is_prominent_(false),
corner_radius_(kInkDropSmallCornerRadius) {
SetInkDropMode(InkDropMode::ON); SetInkDropMode(InkDropMode::ON);
set_has_ink_drop_action_on_click(true); set_has_ink_drop_action_on_click(true);
SetHorizontalAlignment(gfx::ALIGN_CENTER); SetHorizontalAlignment(gfx::ALIGN_CENTER);
...@@ -330,7 +331,7 @@ void MdTextButton::UpdateColors() { ...@@ -330,7 +331,7 @@ void MdTextButton::UpdateColors() {
DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color)));
SetBackground( SetBackground(
CreateBackgroundFromPainter(Painter::CreateRoundRectWith1PxBorderPainter( CreateBackgroundFromPainter(Painter::CreateRoundRectWith1PxBorderPainter(
bg_color, stroke_color, kInkDropSmallCornerRadius))); bg_color, stroke_color, corner_radius_)));
SchedulePaint(); SchedulePaint();
} }
......
...@@ -34,6 +34,10 @@ class VIEWS_EXPORT MdTextButton : public LabelButton { ...@@ -34,6 +34,10 @@ class VIEWS_EXPORT MdTextButton : public LabelButton {
// See |bg_color_override_|. // See |bg_color_override_|.
void SetBgColorOverride(const base::Optional<SkColor>& color); void SetBgColorOverride(const base::Optional<SkColor>& color);
// Override the default corner radius of the round rect used for the
// background and ink drop effects.
void set_corner_radius(float radius) { corner_radius_ = radius; }
// View: // View:
void OnPaintBackground(gfx::Canvas* canvas) override; void OnPaintBackground(gfx::Canvas* canvas) override;
...@@ -64,6 +68,8 @@ class VIEWS_EXPORT MdTextButton : public LabelButton { ...@@ -64,6 +68,8 @@ class VIEWS_EXPORT MdTextButton : public LabelButton {
// When set, this provides the background color. // When set, this provides the background color.
base::Optional<SkColor> bg_color_override_; base::Optional<SkColor> bg_color_override_;
float corner_radius_;
DISALLOW_COPY_AND_ASSIGN(MdTextButton); DISALLOW_COPY_AND_ASSIGN(MdTextButton);
}; };
......
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