| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/profiles/avatar_label.h" | 5 #include "chrome/browser/ui/views/profiles/avatar_label.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/signin/signin_header_helper.h" | 8 #include "chrome/browser/signin/signin_header_helper.h" |
| 9 #include "chrome/browser/themes/theme_properties.h" | 9 #include "chrome/browser/themes/theme_properties.h" |
| 10 #include "chrome/browser/ui/views/frame/browser_view.h" | 10 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/theme_provider.h" | 14 #include "ui/base/theme_provider.h" |
| 15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/color_utils.h" | 16 #include "ui/gfx/color_utils.h" |
| 17 #include "ui/views/painter.h" | 17 #include "ui/views/painter.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // A custom border for the managed user avatar label. | 21 // A custom border for the supervised user avatar label. |
| 22 class AvatarLabelBorder : public views::Border { | 22 class AvatarLabelBorder : public views::Border { |
| 23 public: | 23 public: |
| 24 explicit AvatarLabelBorder(bool label_on_right); | 24 explicit AvatarLabelBorder(bool label_on_right); |
| 25 | 25 |
| 26 // views::Border: | 26 // views::Border: |
| 27 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; | 27 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; |
| 28 virtual gfx::Insets GetInsets() const OVERRIDE; | 28 virtual gfx::Insets GetInsets() const OVERRIDE; |
| 29 virtual gfx::Size GetMinimumSize() const OVERRIDE; | 29 virtual gfx::Size GetMinimumSize() const OVERRIDE; |
| 30 | 30 |
| 31 private: | 31 private: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 57 // Paint the default background using the image assets provided by UI. This | 57 // Paint the default background using the image assets provided by UI. This |
| 58 // includes a border with almost transparent white color. | 58 // includes a border with almost transparent white color. |
| 59 painter_->Paint(canvas, view.size()); | 59 painter_->Paint(canvas, view.size()); |
| 60 | 60 |
| 61 // Repaint the inner part of the background in order to be able to change | 61 // Repaint the inner part of the background in order to be able to change |
| 62 // the colors according to the currently installed theme. | 62 // the colors according to the currently installed theme. |
| 63 gfx::Rect rect(1, 1, view.size().width() - 2, view.size().height() - 2); | 63 gfx::Rect rect(1, 1, view.size().width() - 2, view.size().height() - 2); |
| 64 SkPaint paint; | 64 SkPaint paint; |
| 65 int kRadius = 2; | 65 int kRadius = 2; |
| 66 SkColor background_color = view.GetThemeProvider()->GetColor( | 66 SkColor background_color = view.GetThemeProvider()->GetColor( |
| 67 ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND); | 67 ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND); |
| 68 paint.setStyle(SkPaint::kFill_Style); | 68 paint.setStyle(SkPaint::kFill_Style); |
| 69 | 69 |
| 70 // Paint the inner border with a color slightly darker than the background. | 70 // Paint the inner border with a color slightly darker than the background. |
| 71 SkAlpha kAlphaForBlending = 230; | 71 SkAlpha kAlphaForBlending = 230; |
| 72 paint.setColor(color_utils::AlphaBlend( | 72 paint.setColor(color_utils::AlphaBlend( |
| 73 background_color, SK_ColorBLACK, kAlphaForBlending)); | 73 background_color, SK_ColorBLACK, kAlphaForBlending)); |
| 74 canvas->DrawRoundRect(rect, kRadius, paint); | 74 canvas->DrawRoundRect(rect, kRadius, paint); |
| 75 | 75 |
| 76 // Paint the inner background using the color provided by the ThemeProvider. | 76 // Paint the inner background using the color provided by the ThemeProvider. |
| 77 paint.setColor(background_color); | 77 paint.setColor(background_color); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 signin::GAIA_SERVICE_TYPE_NONE); | 110 signin::GAIA_SERVICE_TYPE_NONE); |
| 111 return true; | 111 return true; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void AvatarLabel::UpdateLabelStyle() { | 114 void AvatarLabel::UpdateLabelStyle() { |
| 115 // |browser_view_| can be NULL in unit tests. | 115 // |browser_view_| can be NULL in unit tests. |
| 116 if (!browser_view_) | 116 if (!browser_view_) |
| 117 return; | 117 return; |
| 118 | 118 |
| 119 SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor( | 119 SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor( |
| 120 ThemeProperties::COLOR_MANAGED_USER_LABEL); | 120 ThemeProperties::COLOR_SUPERVISED_USER_LABEL); |
| 121 for (size_t state = 0; state < STATE_COUNT; ++state) | 121 for (size_t state = 0; state < STATE_COUNT; ++state) |
| 122 SetTextColor(static_cast<ButtonState>(state), color_label); | 122 SetTextColor(static_cast<ButtonState>(state), color_label); |
| 123 SchedulePaint(); | 123 SchedulePaint(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void AvatarLabel::SetLabelOnRight(bool label_on_right) { | 126 void AvatarLabel::SetLabelOnRight(bool label_on_right) { |
| 127 SetBorder(scoped_ptr<views::Border>(new AvatarLabelBorder(label_on_right))); | 127 SetBorder(scoped_ptr<views::Border>(new AvatarLabelBorder(label_on_right))); |
| 128 } | 128 } |
| OLD | NEW |