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_animation_controller.h" | |
| 8 #include "ui/views/controls/button/label_button_border.h" | 9 #include "ui/views/controls/button/label_button_border.h" |
| 9 #include "ui/views/painter.h" | 10 #include "ui/views/painter.h" |
| 10 | 11 |
| 11 BackButton::BackButton(views::ButtonListener* listener, | 12 BackButton::BackButton(views::ButtonListener* listener, |
| 12 ui::MenuModel* model) | 13 ui::MenuModel* model) |
| 13 : ToolbarButton(listener, model), | 14 : ToolbarButton(listener, model), |
| 14 margin_leading_(0) {} | 15 margin_leading_(0) {} |
| 15 | 16 |
| 16 BackButton::~BackButton() {} | 17 BackButton::~BackButton() {} |
| 17 | 18 |
| 18 void BackButton::SetLeadingMargin(int margin) { | 19 void BackButton::SetLeadingMargin(int margin) { |
| 19 margin_leading_ = margin; | 20 margin_leading_ = margin; |
| 20 | 21 |
| 21 UpdateThemedBorder(); | 22 UpdateThemedBorder(); |
| 22 | 23 |
| 23 // Similarly fiddle the focus border. Value consistent with LabelButton. | 24 // Similarly fiddle the focus border. Value consistent with LabelButton. |
| 24 // TODO(gbillock): Refactor this magic number somewhere global to views, | 25 // TODO(gbillock): Refactor this magic number somewhere global to views, |
| 25 // probably a FocusBorder constant. | 26 // probably a FocusBorder constant. |
| 26 const int kFocusRectInset = 3; | 27 const int kFocusRectInset = 3; |
| 27 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets( | 28 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets( |
| 28 gfx::Insets(kFocusRectInset, kFocusRectInset + margin, | 29 gfx::Insets(kFocusRectInset, kFocusRectInset + margin, |
| 29 kFocusRectInset, kFocusRectInset))); | 30 kFocusRectInset, kFocusRectInset))); |
| 30 | 31 |
| 31 InvalidateLayout(); | 32 InvalidateLayout(); |
| 32 } | 33 } |
| 33 | 34 |
| 35 void BackButton::LayoutInkDrop() { | |
| 36 ink_drop_animation_controller()->SetBounds( | |
| 37 gfx::Rect(margin_leading_, 0, width() - margin_leading_, height())); | |
|
jonross
2015/08/07 17:14:31
Is this something that could be gained by applying
bruthig
2015/08/07 22:00:45
Discussed offline, the inset's track the space bet
| |
| 38 } | |
| 39 | |
| 34 const char* BackButton::GetClassName() const { | 40 const char* BackButton::GetClassName() const { |
| 35 return "BackButton"; | 41 return "BackButton"; |
| 36 } | 42 } |
| 37 | 43 |
| 38 scoped_ptr<views::LabelButtonBorder> BackButton::CreateDefaultBorder() const { | 44 scoped_ptr<views::LabelButtonBorder> BackButton::CreateDefaultBorder() const { |
| 39 scoped_ptr<views::LabelButtonBorder> border = | 45 scoped_ptr<views::LabelButtonBorder> border = |
| 40 ToolbarButton::CreateDefaultBorder(); | 46 ToolbarButton::CreateDefaultBorder(); |
| 41 | 47 |
| 42 // Adjust border insets to follow the margin change, | 48 // Adjust border insets to follow the margin change, |
| 43 // which will be reflected in where the border is painted | 49 // which will be reflected in where the border is painted |
| 44 // through |GetThemePaintRect|. | 50 // through |GetThemePaintRect|. |
| 45 const gfx::Insets insets(border->GetInsets()); | 51 const gfx::Insets insets(border->GetInsets()); |
| 46 border->set_insets(gfx::Insets(insets.top(), insets.left() + margin_leading_, | 52 border->set_insets(gfx::Insets(insets.top(), insets.left() + margin_leading_, |
| 47 insets.bottom(), insets.right())); | 53 insets.bottom(), insets.right())); |
| 48 | 54 |
| 49 return border.Pass(); | 55 return border.Pass(); |
| 50 } | 56 } |
| 51 | 57 |
| 52 gfx::Rect BackButton::GetThemePaintRect() const { | 58 gfx::Rect BackButton::GetThemePaintRect() const { |
| 53 gfx::Rect rect(LabelButton::GetThemePaintRect()); | 59 gfx::Rect rect(LabelButton::GetThemePaintRect()); |
| 54 rect.Inset(margin_leading_, 0, 0, 0); | 60 rect.Inset(margin_leading_, 0, 0, 0); |
| 55 return rect; | 61 return rect; |
| 56 } | 62 } |
| 57 | 63 |
| OLD | NEW |