1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/toolbar/back_button.h"
7 #include "ui/gfx/geometry/insets.h"
8 #include "ui/views/controls/button/label_button_border.h"
9 #include "ui/views/painter.h"
11 BackButton::BackButton(views::ButtonListener
* listener
,
13 : ToolbarButton(listener
, model
),
16 BackButton::~BackButton() {}
18 void BackButton::SetLeadingMargin(int margin
) {
19 margin_leading_
= margin
;
23 // Similarly fiddle the focus border. Value consistent with LabelButton.
24 // TODO(gbillock): Refactor this magic number somewhere global to views,
25 // probably a FocusBorder constant.
26 const int kFocusRectInset
= 3;
27 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets(
28 gfx::Insets(kFocusRectInset
, kFocusRectInset
+ margin
,
29 kFocusRectInset
, kFocusRectInset
)));
34 const char* BackButton::GetClassName() const {
38 scoped_ptr
<views::LabelButtonBorder
> BackButton::CreateDefaultBorder() const {
39 scoped_ptr
<views::LabelButtonBorder
> border
=
40 ToolbarButton::CreateDefaultBorder();
42 // Adjust border insets to follow the margin change,
43 // which will be reflected in where the border is painted
44 // through |GetThemePaintRect|.
45 const gfx::Insets
insets(border
->GetInsets());
46 border
->set_insets(gfx::Insets(insets
.top(), insets
.left() + margin_leading_
,
47 insets
.bottom(), insets
.right()));
52 gfx::Rect
BackButton::GetThemePaintRect() const {
53 gfx::Rect
rect(LabelButton::GetThemePaintRect());
54 rect
.Inset(margin_leading_
, 0, 0, 0);