OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/toolbar/back_button.h" | |
6 | |
7 #include "ui/views/controls/button/label_button_border.h" | |
8 #include "ui/views/focus_border.h" | |
9 | |
10 BackButton::BackButton(views::ButtonListener* listener, | |
11 ui::MenuModel* model) | |
12 : ToolbarButton(listener, model), | |
13 margin_left_(0) { | |
14 } | |
15 | |
16 BackButton::~BackButton() { | |
17 } | |
18 | |
19 gfx::Rect BackButton::GetThemePaintRect() const { | |
20 gfx::Rect rect = LabelButton::GetThemePaintRect(); | |
Peter Kasting
2013/11/26 22:24:31
Nit: Prefer () to = for non-basic types
Greg Billock
2013/11/27 14:22:35
Done.
| |
21 if (margin_left_ > 0) { | |
Peter Kasting
2013/11/26 22:24:31
Nit: It seems like we can just eliminate this cond
Greg Billock
2013/11/27 14:22:35
I think that's safe. I think I was thinking about
| |
22 rect = gfx::Rect(rect.x() + margin_left_, rect.y(), | |
23 rect.width() - margin_left_, rect.height()); | |
Peter Kasting
2013/11/26 22:24:31
Nit: Simpler:
rect.Inset(margin_left_, 0, 0, 0)
Greg Billock
2013/11/27 14:22:35
Done.
| |
24 } | |
25 return rect; | |
26 } | |
27 | |
28 void BackButton::SetLeftMargin(int margin) { | |
29 // Adjust border insets to follow the margin change, | |
30 // which will be reflected in where the border is painted | |
31 // through |GetThemePaintRect|. | |
32 gfx::Insets insets(border()->GetInsets()); | |
33 static_cast<views::LabelButtonBorder*>(border())->set_insets( | |
34 gfx::Insets(insets.top(), insets.left() + margin - margin_left_, | |
35 insets.bottom(), insets.right())); | |
36 | |
37 // Similarly fiddle the focus border. Value consistent with LabelButton | |
38 // and TextButton. | |
39 // TODO(gbillock): Refactor this magic number somewhere global to views, | |
40 // probably a FocusBorder constant. | |
41 const int kFocusRectInset = 3; | |
42 set_focus_border(views::FocusBorder::CreateDashedFocusBorder( | |
43 kFocusRectInset + margin, kFocusRectInset, | |
44 kFocusRectInset, kFocusRectInset)); | |
45 | |
46 margin_left_ = margin; | |
47 InvalidateLayout(); | |
48 } | |
OLD | NEW |