Chromium Code Reviews| 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; | |
| 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: | |
|
SteveT
2012/09/11 02:16:25
nit: Indent to line up with virtual methods below.
Roger Tawa OOO till Jul 10th
2012/09/11 19:23:21
Done.
| |
| 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) { | |
| 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 } | |
|
SteveT
2012/09/11 02:16:25
Should the dtor be declared in the class decl abov
Roger Tawa OOO till Jul 10th
2012/09/11 19:23:21
I think its fine the way it is.
| |
| 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 | |
| 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) { | |
|
SteveT
2012/09/11 02:16:25
Optional nit: It's been suggested to me in the pas
Roger Tawa OOO till Jul 10th
2012/09/11 19:23:21
Done.
| |
| 130 OneClickSigninInfoBarDelegate::AlternateColors alt_colors; | |
| 131 one_click_delegate_->GetAlternateColors(&alt_colors); | |
| 132 | |
| 133 const SkColor kDefaultColor = OneClickSigninInfoBarDelegate::kDefaultColor; | |
| 134 | |
| 135 if (alt_colors.infobar_top_color != kDefaultColor && | |
| 136 alt_colors.infobar_bottom_color != kDefaultColor) { | |
| 137 set_background(new InfoBarBackground(alt_colors.infobar_top_color, | |
| 138 alt_colors.infobar_bottom_color)); | |
| 139 } | |
| 140 | |
| 141 if (alt_colors.button_background_color != kDefaultColor && | |
| 142 alt_colors.button_border_color != kDefaultColor) { | |
| 143 ok_button()->set_border(new InfoBarColoredButtonBorder( | |
| 144 alt_colors.button_background_color, | |
| 145 alt_colors.button_border_color)); | |
| 146 } | |
| 147 | |
| 148 if (alt_colors.button_text_color != kDefaultColor) { | |
| 149 ok_button()->SetEnabledColor(alt_colors.button_text_color); | |
| 150 ok_button()->SetHighlightColor(alt_colors.button_text_color); | |
| 151 ok_button()->SetHoverColor(alt_colors.button_text_color); | |
| 152 } | |
| 153 } | |
| 154 } | |
| OLD | NEW |