Chromium Code Reviews| 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/animation/ink_drop.h" | 8 #include "ui/views/animation/ink_drop.h" |
| 9 #include "ui/views/controls/button/label_button_border.h" | 9 #include "ui/views/controls/button/label_button_border.h" |
| 10 #include "ui/views/painter.h" | 10 #include "ui/views/painter.h" |
| 11 | 11 |
| 12 BackButton::BackButton(Profile* profile, | 12 BackButton::BackButton(Profile* profile, |
| 13 views::ButtonListener* listener, | 13 views::ButtonListener* listener, |
| 14 ui::MenuModel* model) | 14 ui::MenuModel* model) |
| 15 : ToolbarButton(profile, listener, model), margin_leading_(0) {} | 15 : ToolbarButton(profile, listener, model), margin_leading_(0) {} |
| 16 | 16 |
| 17 BackButton::~BackButton() {} | 17 BackButton::~BackButton() {} |
| 18 | 18 |
| 19 void BackButton::SetLeadingMargin(int margin) { | 19 void BackButton::SetLeadingMargin(int margin) { |
| 20 margin_leading_ = margin; | 20 margin_leading_ = margin; |
| 21 | 21 |
| 22 UpdateThemedBorder(); | 22 UpdateThemedBorder(); |
| 23 | 23 |
| 24 const int inset = LabelButton::kFocusRectInset; | 24 if (focus_painter()) { |
|
Peter Kasting
2016/06/14 17:51:59
Who would be setting this? It reads here a bit li
Evan Stade
2016/06/14 17:57:34
ToolbarButton (the parent class). In my head it re
Peter Kasting
2016/06/14 18:00:21
Does ToolbarButton ever add such a focus painter?
| |
| 25 const bool is_rtl = base::i18n::IsRTL(); | 25 const int inset = LabelButton::kFocusRectInset; |
| 26 const gfx::Insets insets(inset, inset + (is_rtl ? 0 : margin), | 26 const bool is_rtl = base::i18n::IsRTL(); |
| 27 inset, inset + (is_rtl ? margin : 0)); | 27 const gfx::Insets insets(inset, inset + (is_rtl ? 0 : margin), |
| 28 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets(insets)); | 28 inset, inset + (is_rtl ? margin : 0)); |
| 29 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets(insets)); | |
| 30 } | |
| 29 InvalidateLayout(); | 31 InvalidateLayout(); |
| 30 } | 32 } |
| 31 | 33 |
| 32 const char* BackButton::GetClassName() const { | 34 const char* BackButton::GetClassName() const { |
| 33 return "BackButton"; | 35 return "BackButton"; |
| 34 } | 36 } |
| 35 | 37 |
| 36 std::unique_ptr<views::LabelButtonBorder> BackButton::CreateDefaultBorder() | 38 std::unique_ptr<views::LabelButtonBorder> BackButton::CreateDefaultBorder() |
| 37 const { | 39 const { |
| 38 std::unique_ptr<views::LabelButtonBorder> border = | 40 std::unique_ptr<views::LabelButtonBorder> border = |
| 39 ToolbarButton::CreateDefaultBorder(); | 41 ToolbarButton::CreateDefaultBorder(); |
| 40 | 42 |
| 41 // Adjust border insets to follow the margin change, | 43 // Adjust border insets to follow the margin change, |
| 42 // which will be reflected in where the border is painted | 44 // which will be reflected in where the border is painted |
| 43 // through GetThemePaintRect(). | 45 // through GetThemePaintRect(). |
| 44 const gfx::Insets insets(border->GetInsets()); | 46 const gfx::Insets insets(border->GetInsets()); |
| 45 border->set_insets(gfx::Insets(insets.top(), insets.left() + margin_leading_, | 47 border->set_insets(gfx::Insets(insets.top(), insets.left() + margin_leading_, |
| 46 insets.bottom(), insets.right())); | 48 insets.bottom(), insets.right())); |
| 47 | 49 |
| 48 return border; | 50 return border; |
| 49 } | 51 } |
| 50 | 52 |
| 51 gfx::Rect BackButton::GetThemePaintRect() const { | 53 gfx::Rect BackButton::GetThemePaintRect() const { |
| 52 gfx::Rect rect(LabelButton::GetThemePaintRect()); | 54 gfx::Rect rect(LabelButton::GetThemePaintRect()); |
| 53 const bool is_rtl = base::i18n::IsRTL(); | 55 const bool is_rtl = base::i18n::IsRTL(); |
| 54 rect.Inset(is_rtl ? 0 : margin_leading_, 0, is_rtl ? margin_leading_ : 0, 0); | 56 rect.Inset(is_rtl ? 0 : margin_leading_, 0, is_rtl ? margin_leading_ : 0, 0); |
| 55 return rect; | 57 return rect; |
| 56 } | 58 } |
| 57 | 59 |
| OLD | NEW |