Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / toolbar / back_button.cc
blob93e7e12072f5582076081f776a020f1cd6196a66
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,
13 ui::MenuModel* model)
14 : ToolbarButton(listener, model),
15 margin_leading_(0) {}
17 BackButton::~BackButton() {}
19 void BackButton::SetLeadingMargin(int margin) {
20 margin_leading_ = margin;
22 UpdateThemedBorder();
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)));
32 InvalidateLayout();
35 gfx::Point BackButton::CalculateInkDropCenter() const {
36 return gfx::Point((width() + margin_leading_) / 2, height() / 2);
39 const char* BackButton::GetClassName() const {
40 return "BackButton";
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()));
54 return border.Pass();
57 gfx::Rect BackButton::GetThemePaintRect() const {
58 gfx::Rect rect(LabelButton::GetThemePaintRect());
59 rect.Inset(margin_leading_, 0, 0, 0);
60 return rect;