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