OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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/infobars/one_click_signin_infobar.h" | |
6 | |
7 #include "chrome/browser/api/infobars/one_click_signin_infobar_delegate.h" | |
8 #include "chrome/browser/defaults.h" | |
9 #include "chrome/browser/infobars/infobar_tab_helper.h" | |
10 #include "chrome/browser/ui/views/infobars/infobar_background.h" | |
11 #include "third_party/skia/include/core/SkColor.h" | |
12 #include "third_party/skia/include/core/SkPaint.h" | |
13 #include "third_party/skia/include/core/SkRect.h" | |
14 #include "third_party/skia/include/core/SkScalar.h" | |
15 #include "ui/gfx/canvas.h" | |
16 #include "ui/gfx/skia_util.h" | |
17 #include "ui/views/border.h" | |
18 #include "ui/views/controls/button/custom_button.h" | |
19 #include "ui/views/controls/button/text_button.h" | |
20 | |
21 namespace { | |
22 | |
23 // Preferred padding between text and edge. | |
24 const int kPreferredPaddingHorizontal = 6; | |
25 const int kPreferredPaddingVertical = 5; | |
Peter Kasting
2012/09/11 23:02:07
Nit: Not used
Roger Tawa OOO till Jul 10th
2012/09/12 15:07:14
Done.
| |
26 | |
27 // A border used for infobar buttons using a custom colour. | |
28 class InfoBarColoredButtonBorder : public views::Border { | |
29 public: | |
30 InfoBarColoredButtonBorder(SkColor background_color, | |
31 SkColor border_color); | |
32 | |
33 private: | |
34 static SkColor DarkenColor(SkColor color); | |
35 | |
36 // Border overrides: | |
37 virtual void Paint(const views::View& view, | |
38 gfx::Canvas* canvas) const OVERRIDE; | |
39 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE; | |
40 | |
41 virtual ~InfoBarColoredButtonBorder(); | |
42 | |
43 const SkColor background_color_; | |
44 const SkColor border_color_; | |
45 const SkColor border_color_hot_; | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(InfoBarColoredButtonBorder); | |
48 }; | |
49 | |
50 InfoBarColoredButtonBorder::InfoBarColoredButtonBorder( | |
51 SkColor background_color, | |
52 SkColor border_color) | |
53 : background_color_(background_color), | |
54 border_color_(border_color), | |
55 border_color_hot_(DarkenColor(border_color_)) { | |
56 } | |
57 | |
58 // static | |
59 SkColor InfoBarColoredButtonBorder::DarkenColor(SkColor color) { | |
Peter Kasting
2012/09/11 23:02:07
Nit: Only called one place, maybe just inline this
Roger Tawa OOO till Jul 10th
2012/09/12 15:07:14
I'd rather leave the type of border_color_hot_ as
Peter Kasting
2012/09/12 17:21:24
Ah. That's fine. Maybe add a comment on the decl
Roger Tawa OOO till Jul 10th
2012/09/12 18:36:55
Done.
| |
60 SkScalar hsv[3]; | |
61 SkColorToHSV(color, hsv); | |
62 hsv[2] *= 0.8f; | |
63 return SkHSVToColor(255, hsv); | |
64 } | |
65 | |
66 void InfoBarColoredButtonBorder::Paint(const views::View& view, | |
67 gfx::Canvas* canvas) const { | |
68 const views::CustomButton* button = | |
69 static_cast<const views::CustomButton*>(&view); | |
70 const views::CustomButton::ButtonState state = button->state(); | |
71 | |
72 const SkScalar kRadius = 2.0; | |
73 | |
74 SkRect bounds(gfx::RectToSkRect(view.GetLocalBounds())); | |
75 bounds.inset(0.5, 0.5); | |
76 | |
77 SkPaint paint; | |
78 paint.setAntiAlias(true); | |
79 | |
80 paint.setStyle(SkPaint::kFill_Style); | |
81 paint.setColor(background_color_); | |
82 canvas->sk_canvas()->drawRoundRect(bounds, kRadius, kRadius, paint); | |
83 | |
84 paint.setStyle(SkPaint::kStroke_Style); | |
85 paint.setColor(state == views::CustomButton::BS_NORMAL ? | |
86 border_color_ : border_color_hot_); | |
87 canvas->sk_canvas()->drawRoundRect(bounds, kRadius, kRadius, paint); | |
88 } | |
89 | |
90 void InfoBarColoredButtonBorder::GetInsets(gfx::Insets* insets) const { | |
91 insets->Set(browser_defaults::kInfoBarBorderPaddingVertical, | |
92 kPreferredPaddingHorizontal, | |
93 browser_defaults::kInfoBarBorderPaddingVertical, | |
94 kPreferredPaddingHorizontal); | |
95 } | |
96 | |
97 InfoBarColoredButtonBorder::~InfoBarColoredButtonBorder() { | |
98 } | |
99 | |
100 } // namespace | |
101 | |
102 | |
103 // OneClickSigninInfoBarDelegate ---------------------------------------------- | |
104 | |
105 InfoBar* OneClickSigninInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { | |
106 return new OneClickLoginInfoBar(static_cast<InfoBarTabHelper*>(owner), this); | |
107 } | |
108 | |
Peter Kasting
2012/09/11 23:02:07
Nit: One more blank line
Roger Tawa OOO till Jul 10th
2012/09/12 15:07:14
Done.
| |
109 // OneClickLoginInfoBar ------------------------------------------------------- | |
110 | |
111 OneClickLoginInfoBar::OneClickLoginInfoBar( | |
112 InfoBarTabHelper* owner, | |
113 OneClickSigninInfoBarDelegate* delegate) | |
114 : ConfirmInfoBar(owner, delegate), | |
115 one_click_delegate_(delegate) { | |
116 CHECK(one_click_delegate_); | |
117 } | |
118 | |
119 OneClickLoginInfoBar::~OneClickLoginInfoBar() { | |
120 } | |
121 | |
122 void OneClickLoginInfoBar::ViewHierarchyChanged(bool is_add, | |
123 views::View* parent, | |
124 views::View* child) { | |
125 const bool fix_color = is_add && child == this && ok_button() == NULL; | |
126 | |
127 ConfirmInfoBar::ViewHierarchyChanged(is_add, parent, child); | |
128 | |
129 if (!fix_color || ok_button() == NULL) | |
130 return; | |
131 | |
132 OneClickSigninInfoBarDelegate::AlternateColors alt_colors; | |
133 one_click_delegate_->GetAlternateColors(&alt_colors); | |
134 | |
135 const SkColor kDefaultColor = OneClickSigninInfoBarDelegate::kDefaultColor; | |
136 | |
137 if (alt_colors.infobar_top_color != kDefaultColor && | |
138 alt_colors.infobar_bottom_color != kDefaultColor) { | |
139 set_background(new InfoBarBackground(alt_colors.infobar_top_color, | |
140 alt_colors.infobar_bottom_color)); | |
141 } | |
142 | |
143 if (alt_colors.button_background_color != kDefaultColor && | |
144 alt_colors.button_border_color != kDefaultColor) { | |
145 ok_button()->set_border(new InfoBarColoredButtonBorder( | |
146 alt_colors.button_background_color, | |
147 alt_colors.button_border_color)); | |
148 } | |
149 | |
150 if (alt_colors.button_text_color != kDefaultColor) { | |
151 ok_button()->SetEnabledColor(alt_colors.button_text_color); | |
152 ok_button()->SetHighlightColor(alt_colors.button_text_color); | |
153 ok_button()->SetHoverColor(alt_colors.button_text_color); | |
154 } | |
155 } | |
OLD | NEW |