back_button.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 11BackButton::BackButton(views::ButtonListener* listener, 12 ui::MenuModel* model) 13 : ToolbarButton(listener, model), 14 margin_leading_(0) { 15} 16 17BackButton::~BackButton() { 18} 19 20gfx::Rect BackButton::GetThemePaintRect() const { 21 gfx::Rect rect(LabelButton::GetThemePaintRect()); 22 rect.Inset(margin_leading_, 0, 0, 0); 23 return rect; 24} 25 26void BackButton::SetLeadingMargin(int margin) { 27 // Adjust border insets to follow the margin change, 28 // which will be reflected in where the border is painted 29 // through |GetThemePaintRect|. 30 scoped_ptr<views::LabelButtonBorder> border( 31 new views::LabelButtonBorder(style())); 32 const gfx::Insets insets(border->GetInsets()); 33 border->set_insets(gfx::Insets(insets.top(), insets.left() + margin, 34 insets.bottom(), insets.right())); 35 UpdateThemedBorder(border.PassAs<views::Border>()); 36 37 // Similarly fiddle the focus border. Value consistent with LabelButton 38 // and TextButton. 39 // TODO(gbillock): Refactor this magic number somewhere global to views, 40 // probably a FocusBorder constant. 41 const int kFocusRectInset = 3; 42 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets( 43 gfx::Insets(kFocusRectInset, kFocusRectInset + margin, 44 kFocusRectInset, kFocusRectInset))); 45 46 margin_leading_ = margin; 47 InvalidateLayout(); 48} 49