• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/ui/views/toolbar/back_button.h"
6 
7 #include "ui/gfx/insets.h"
8 #include "ui/views/controls/button/label_button_border.h"
9 #include "ui/views/painter.h"
10 
BackButton(views::ButtonListener * listener,ui::MenuModel * model)11 BackButton::BackButton(views::ButtonListener* listener,
12                        ui::MenuModel* model)
13     : ToolbarButton(listener, model),
14       margin_leading_(0) {}
15 
~BackButton()16 BackButton::~BackButton() {}
17 
GetThemePaintRect() const18 gfx::Rect BackButton::GetThemePaintRect() const  {
19   gfx::Rect rect(LabelButton::GetThemePaintRect());
20   rect.Inset(margin_leading_, 0, 0, 0);
21   return rect;
22 }
23 
SetLeadingMargin(int margin)24 void BackButton::SetLeadingMargin(int margin) {
25   margin_leading_ = margin;
26 
27   UpdateThemedBorder();
28 
29   // Similarly fiddle the focus border. Value consistent with LabelButton
30   // and TextButton.
31   // TODO(gbillock): Refactor this magic number somewhere global to views,
32   // probably a FocusBorder constant.
33   const int kFocusRectInset = 3;
34   SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets(
35                       gfx::Insets(kFocusRectInset, kFocusRectInset + margin,
36                                   kFocusRectInset, kFocusRectInset)));
37 
38   InvalidateLayout();
39 }
40 
CreateDefaultBorder() const41 scoped_ptr<views::LabelButtonBorder> BackButton::CreateDefaultBorder() const {
42   scoped_ptr<views::LabelButtonBorder> border =
43       ToolbarButton::CreateDefaultBorder();
44 
45   // Adjust border insets to follow the margin change,
46   // which will be reflected in where the border is painted
47   // through |GetThemePaintRect|.
48   const gfx::Insets insets(border->GetInsets());
49   border->set_insets(gfx::Insets(insets.top(), insets.left() + margin_leading_,
50                                  insets.bottom(), insets.right()));
51 
52   return border.Pass();
53 }
54