| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/toolbar/back_button.h" | 5 #include "chrome/browser/ui/views/toolbar/back_button.h" |
| 6 | 6 |
| 7 #include "ui/gfx/geometry/insets.h" | 7 #include "ui/gfx/geometry/insets.h" |
| 8 #include "ui/views/controls/button/label_button_border.h" | 8 #include "ui/views/controls/button/label_button_border.h" |
| 9 #include "ui/views/painter.h" | 9 #include "ui/views/painter.h" |
| 10 | 10 |
| 11 BackButton::BackButton(views::ButtonListener* listener, | 11 BackButton::BackButton(views::ButtonListener* listener, |
| 12 ui::MenuModel* model) | 12 ui::MenuModel* model) |
| 13 : ToolbarButton(listener, model), | 13 : ToolbarButton(listener, model), |
| 14 margin_leading_(0) {} | 14 margin_leading_(0) {} |
| 15 | 15 |
| 16 BackButton::~BackButton() {} | 16 BackButton::~BackButton() {} |
| 17 | 17 |
| 18 gfx::Rect BackButton::GetThemePaintRect() const { | |
| 19 gfx::Rect rect(LabelButton::GetThemePaintRect()); | |
| 20 rect.Inset(margin_leading_, 0, 0, 0); | |
| 21 return rect; | |
| 22 } | |
| 23 | |
| 24 void BackButton::SetLeadingMargin(int margin) { | 18 void BackButton::SetLeadingMargin(int margin) { |
| 25 margin_leading_ = margin; | 19 margin_leading_ = margin; |
| 26 | 20 |
| 27 UpdateThemedBorder(); | 21 UpdateThemedBorder(); |
| 28 | 22 |
| 29 // Similarly fiddle the focus border. Value consistent with LabelButton. | 23 // Similarly fiddle the focus border. Value consistent with LabelButton. |
| 30 // TODO(gbillock): Refactor this magic number somewhere global to views, | 24 // TODO(gbillock): Refactor this magic number somewhere global to views, |
| 31 // probably a FocusBorder constant. | 25 // probably a FocusBorder constant. |
| 32 const int kFocusRectInset = 3; | 26 const int kFocusRectInset = 3; |
| 33 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets( | 27 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets( |
| 34 gfx::Insets(kFocusRectInset, kFocusRectInset + margin, | 28 gfx::Insets(kFocusRectInset, kFocusRectInset + margin, |
| 35 kFocusRectInset, kFocusRectInset))); | 29 kFocusRectInset, kFocusRectInset))); |
| 36 | 30 |
| 37 InvalidateLayout(); | 31 InvalidateLayout(); |
| 38 } | 32 } |
| 39 | 33 |
| 34 const char* BackButton::GetClassName() const { |
| 35 return "BackButton"; |
| 36 } |
| 37 |
| 40 scoped_ptr<views::LabelButtonBorder> BackButton::CreateDefaultBorder() const { | 38 scoped_ptr<views::LabelButtonBorder> BackButton::CreateDefaultBorder() const { |
| 41 scoped_ptr<views::LabelButtonBorder> border = | 39 scoped_ptr<views::LabelButtonBorder> border = |
| 42 ToolbarButton::CreateDefaultBorder(); | 40 ToolbarButton::CreateDefaultBorder(); |
| 43 | 41 |
| 44 // Adjust border insets to follow the margin change, | 42 // Adjust border insets to follow the margin change, |
| 45 // which will be reflected in where the border is painted | 43 // which will be reflected in where the border is painted |
| 46 // through |GetThemePaintRect|. | 44 // through |GetThemePaintRect|. |
| 47 const gfx::Insets insets(border->GetInsets()); | 45 const gfx::Insets insets(border->GetInsets()); |
| 48 border->set_insets(gfx::Insets(insets.top(), insets.left() + margin_leading_, | 46 border->set_insets(gfx::Insets(insets.top(), insets.left() + margin_leading_, |
| 49 insets.bottom(), insets.right())); | 47 insets.bottom(), insets.right())); |
| 50 | 48 |
| 51 return border.Pass(); | 49 return border.Pass(); |
| 52 } | 50 } |
| 51 |
| 52 gfx::Rect BackButton::GetThemePaintRect() const { |
| 53 gfx::Rect rect(LabelButton::GetThemePaintRect()); |
| 54 rect.Inset(margin_leading_, 0, 0, 0); |
| 55 return rect; |
| 56 } |
| 57 |
| OLD | NEW |