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/animation/ink_drop_animation_controller.h"
9 #include "ui/views/controls/button/label_button_border.h"
10 #include "ui/views/painter.h"
12 BackButton::BackButton(views::ButtonListener
* listener
,
14 : ToolbarButton(listener
, model
),
17 BackButton::~BackButton() {}
19 void BackButton::SetLeadingMargin(int margin
) {
20 margin_leading_
= margin
;
24 // Similarly fiddle the focus border. Value consistent with LabelButton.
25 // TODO(gbillock): Refactor this magic number somewhere global to views,
26 // probably a FocusBorder constant.
27 const int kFocusRectInset
= 3;
28 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets(
29 gfx::Insets(kFocusRectInset
, kFocusRectInset
+ margin
,
30 kFocusRectInset
, kFocusRectInset
)));
35 gfx::Point
BackButton::CalculateInkDropCenter() const {
36 return gfx::Point((width() + margin_leading_
) / 2, height() / 2);
39 const char* BackButton::GetClassName() const {
43 scoped_ptr
<views::LabelButtonBorder
> BackButton::CreateDefaultBorder() const {
44 scoped_ptr
<views::LabelButtonBorder
> border
=
45 ToolbarButton::CreateDefaultBorder();
47 // Adjust border insets to follow the margin change,
48 // which will be reflected in where the border is painted
49 // through |GetThemePaintRect|.
50 const gfx::Insets
insets(border
->GetInsets());
51 border
->set_insets(gfx::Insets(insets
.top(), insets
.left() + margin_leading_
,
52 insets
.bottom(), insets
.right()));
57 gfx::Rect
BackButton::GetThemePaintRect() const {
58 gfx::Rect
rect(LabelButton::GetThemePaintRect());
59 rect
.Inset(margin_leading_
, 0, 0, 0);