OLD | NEW |
(Empty) | |
| 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/views/controls/button/label_button_border.h" |
| 8 #include "ui/views/focus_border.h" |
| 9 |
| 10 BackButton::BackButton(views::ButtonListener* listener, |
| 11 ui::MenuModel* model) |
| 12 : ToolbarButton(listener, model), |
| 13 margin_leading_(0) { |
| 14 } |
| 15 |
| 16 BackButton::~BackButton() { |
| 17 } |
| 18 |
| 19 gfx::Rect BackButton::GetThemePaintRect() const { |
| 20 gfx::Rect rect(LabelButton::GetThemePaintRect()); |
| 21 rect.Inset(margin_leading_, 0, 0, 0); |
| 22 return rect; |
| 23 } |
| 24 |
| 25 void BackButton::SetLeadingMargin(int margin) { |
| 26 // Adjust border insets to follow the margin change, |
| 27 // which will be reflected in where the border is painted |
| 28 // through |GetThemePaintRect|. |
| 29 gfx::Insets insets(border()->GetInsets()); |
| 30 static_cast<views::LabelButtonBorder*>(border())->set_insets( |
| 31 gfx::Insets(insets.top(), insets.left() + margin - margin_leading_, |
| 32 insets.bottom(), insets.right())); |
| 33 |
| 34 // Similarly fiddle the focus border. Value consistent with LabelButton |
| 35 // and TextButton. |
| 36 // TODO(gbillock): Refactor this magic number somewhere global to views, |
| 37 // probably a FocusBorder constant. |
| 38 const int kFocusRectInset = 3; |
| 39 set_focus_border(views::FocusBorder::CreateDashedFocusBorder( |
| 40 kFocusRectInset + margin, kFocusRectInset, |
| 41 kFocusRectInset, kFocusRectInset)); |
| 42 |
| 43 margin_leading_ = margin; |
| 44 InvalidateLayout(); |
| 45 } |
OLD | NEW |