Chromium Code Reviews| Index: chrome/browser/ui/views/toolbar/back_button.cc |
| diff --git a/chrome/browser/ui/views/toolbar/back_button.cc b/chrome/browser/ui/views/toolbar/back_button.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..898299ee5fa10f360db1f00018724972465f5e60 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/toolbar/back_button.cc |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/views/toolbar/back_button.h" |
| + |
| +#include "ui/views/controls/button/label_button_border.h" |
| +#include "ui/views/focus_border.h" |
| + |
| +BackButton::BackButton(views::ButtonListener* listener, |
| + ui::MenuModel* model) |
| + : ToolbarButton(listener, model), |
| + margin_left_(0) { |
| +} |
| + |
| +BackButton::~BackButton() { |
| +} |
| + |
| +gfx::Rect BackButton::GetThemePaintRect() const { |
| + gfx::Rect rect = LabelButton::GetThemePaintRect(); |
|
Peter Kasting
2013/11/26 22:24:31
Nit: Prefer () to = for non-basic types
Greg Billock
2013/11/27 14:22:35
Done.
|
| + if (margin_left_ > 0) { |
|
Peter Kasting
2013/11/26 22:24:31
Nit: It seems like we can just eliminate this cond
Greg Billock
2013/11/27 14:22:35
I think that's safe. I think I was thinking about
|
| + rect = gfx::Rect(rect.x() + margin_left_, rect.y(), |
| + rect.width() - margin_left_, rect.height()); |
|
Peter Kasting
2013/11/26 22:24:31
Nit: Simpler:
rect.Inset(margin_left_, 0, 0, 0)
Greg Billock
2013/11/27 14:22:35
Done.
|
| + } |
| + return rect; |
| +} |
| + |
| +void BackButton::SetLeftMargin(int margin) { |
| + // Adjust border insets to follow the margin change, |
| + // which will be reflected in where the border is painted |
| + // through |GetThemePaintRect|. |
| + gfx::Insets insets(border()->GetInsets()); |
| + static_cast<views::LabelButtonBorder*>(border())->set_insets( |
| + gfx::Insets(insets.top(), insets.left() + margin - margin_left_, |
| + insets.bottom(), insets.right())); |
| + |
| + // Similarly fiddle the focus border. Value consistent with LabelButton |
| + // and TextButton. |
| + // TODO(gbillock): Refactor this magic number somewhere global to views, |
| + // probably a FocusBorder constant. |
| + const int kFocusRectInset = 3; |
| + set_focus_border(views::FocusBorder::CreateDashedFocusBorder( |
| + kFocusRectInset + margin, kFocusRectInset, |
| + kFocusRectInset, kFocusRectInset)); |
| + |
| + margin_left_ = margin; |
| + InvalidateLayout(); |
| +} |