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/base/material_design/material_design_controller.h" | |
8 #include "ui/gfx/geometry/insets.h" | 7 #include "ui/gfx/geometry/insets.h" |
9 #include "ui/views/animation/ink_drop.h" | 8 #include "ui/views/animation/ink_drop.h" |
10 #include "ui/views/controls/button/label_button_border.h" | 9 #include "ui/views/controls/button/label_button_border.h" |
11 #include "ui/views/painter.h" | 10 #include "ui/views/painter.h" |
12 | 11 |
13 BackButton::BackButton(Profile* profile, | 12 BackButton::BackButton(Profile* profile, |
14 views::ButtonListener* listener, | 13 views::ButtonListener* listener, |
15 ui::MenuModel* model) | 14 ui::MenuModel* model) |
16 : ToolbarButton(profile, listener, model), margin_leading_(0) {} | 15 : ToolbarButton(profile, listener, model), margin_leading_(0) {} |
17 | 16 |
18 BackButton::~BackButton() {} | 17 BackButton::~BackButton() {} |
19 | 18 |
20 void BackButton::SetLeadingMargin(int margin) { | 19 void BackButton::SetLeadingMargin(int margin) { |
21 margin_leading_ = margin; | 20 margin_leading_ = margin; |
22 | |
23 UpdateThemedBorder(); | 21 UpdateThemedBorder(); |
24 | |
25 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
26 const int inset = LabelButton::kFocusRectInset; | |
Peter Kasting
2016/09/27 20:51:09
Nit: You've removed the last two external uses of
Evan Stade
2016/09/28 01:33:50
Done.
| |
27 const bool is_rtl = base::i18n::IsRTL(); | |
28 const gfx::Insets insets(inset, inset + (is_rtl ? 0 : margin), | |
29 inset, inset + (is_rtl ? margin : 0)); | |
30 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets(insets)); | |
31 } | |
32 InvalidateLayout(); | 22 InvalidateLayout(); |
33 } | 23 } |
34 | 24 |
35 const char* BackButton::GetClassName() const { | 25 const char* BackButton::GetClassName() const { |
36 return "BackButton"; | 26 return "BackButton"; |
37 } | 27 } |
38 | 28 |
39 std::unique_ptr<views::LabelButtonBorder> BackButton::CreateDefaultBorder() | 29 std::unique_ptr<views::LabelButtonBorder> BackButton::CreateDefaultBorder() |
40 const { | 30 const { |
41 std::unique_ptr<views::LabelButtonBorder> border = | 31 std::unique_ptr<views::LabelButtonBorder> border = |
42 ToolbarButton::CreateDefaultBorder(); | 32 ToolbarButton::CreateDefaultBorder(); |
43 | 33 |
44 // Adjust border insets to follow the margin change, | 34 // Adjust border insets to follow the margin change, |
45 // which will be reflected in where the border is painted | 35 // which will be reflected in where the border is painted |
46 // through GetThemePaintRect(). | 36 // through GetThemePaintRect(). |
47 const gfx::Insets insets(border->GetInsets()); | 37 const gfx::Insets insets(border->GetInsets()); |
48 border->set_insets(gfx::Insets(insets.top(), insets.left() + margin_leading_, | 38 border->set_insets(gfx::Insets(insets.top(), insets.left() + margin_leading_, |
49 insets.bottom(), insets.right())); | 39 insets.bottom(), insets.right())); |
50 | 40 |
51 return border; | 41 return border; |
52 } | 42 } |
53 | 43 |
54 gfx::Rect BackButton::GetThemePaintRect() const { | 44 gfx::Rect BackButton::GetThemePaintRect() const { |
55 gfx::Rect rect(LabelButton::GetThemePaintRect()); | 45 gfx::Rect rect(LabelButton::GetThemePaintRect()); |
56 const bool is_rtl = base::i18n::IsRTL(); | 46 const bool is_rtl = base::i18n::IsRTL(); |
57 rect.Inset(is_rtl ? 0 : margin_leading_, 0, is_rtl ? margin_leading_ : 0, 0); | 47 rect.Inset(is_rtl ? 0 : margin_leading_, 0, is_rtl ? margin_leading_ : 0, 0); |
58 return rect; | 48 return rect; |
59 } | 49 } |
60 | 50 |
OLD | NEW |