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/avatar_label.h" | 5 #include "chrome/browser/ui/views/avatar_label.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/themes/theme_properties.h" | 8 #include "chrome/browser/themes/theme_properties.h" |
| 9 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" | 9 #include "chrome/browser/ui/views/avatar_menu_bubble_view.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/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/base/theme_provider.h" | 15 #include "ui/base/theme_provider.h" |
| 16 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
| 17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/color_utils.h" | 18 #include "ui/gfx/color_utils.h" |
| 19 #include "ui/views/painter.h" | 19 #include "ui/views/painter.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // A special text button border for the managed user avatar label. | 23 // A special text button border for the managed user avatar label. |
| 24 class AvatarLabelBorder: public views::TextButtonBorder { | 24 class AvatarLabelBorder: public views::TextButtonBorder { |
| 25 public: | 25 public: |
| 26 explicit AvatarLabelBorder(); | 26 explicit AvatarLabelBorder(); |
| 27 | 27 |
| 28 // views::TextButtonBorder: | 28 // views::TextButtonBorder: |
| 29 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; | 29 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; |
| 30 virtual gfx::Size GetMinimumSize() const OVERRIDE; | |
| 30 | 31 |
| 31 private: | 32 private: |
| 32 scoped_ptr<views::Painter> painter_; | 33 scoped_ptr<views::Painter> painter_; |
| 33 | 34 |
| 34 DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder); | 35 DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder); |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 AvatarLabelBorder::AvatarLabelBorder() { | 38 AvatarLabelBorder::AvatarLabelBorder() { |
| 38 const int kHorizontalInsetRight = 10; | 39 const int kHorizontalInsetRight = 10; |
| 39 const int kHorizontalInsetLeft = 43; | 40 const int kHorizontalInsetLeft = 43; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 background_color, SK_ColorBLACK, kAlphaForBlending)); | 76 background_color, SK_ColorBLACK, kAlphaForBlending)); |
| 76 canvas->DrawRoundRect(rect, kRadius, paint); | 77 canvas->DrawRoundRect(rect, kRadius, paint); |
| 77 | 78 |
| 78 // Now paint the inner background using the color provided by the | 79 // Now paint the inner background using the color provided by the |
| 79 // ThemeProvider. | 80 // ThemeProvider. |
| 80 paint.setColor(background_color); | 81 paint.setColor(background_color); |
| 81 rect = gfx::Rect(2, 2, view.size().width() - 4, view.size().height() - 4); | 82 rect = gfx::Rect(2, 2, view.size().width() - 4, view.size().height() - 4); |
| 82 canvas->DrawRoundRect(rect, kRadius, paint); | 83 canvas->DrawRoundRect(rect, kRadius, paint); |
| 83 } | 84 } |
| 84 | 85 |
| 86 gfx::Size AvatarLabelBorder::GetMinimumSize() const { | |
| 87 gfx::Size size(4, 4); | |
|
msw
2013/11/22 18:00:25
nit: should 4 be declared as a file-local constant
Peter Kasting
2013/11/22 22:07:55
We'd declare 2 rather than 4 if we were going to d
| |
| 88 size.SetToMax(painter_->GetMinimumSize()); | |
| 89 return size; | |
| 90 } | |
| 91 | |
| 85 } // namespace | 92 } // namespace |
| 86 | 93 |
| 87 AvatarLabel::AvatarLabel(BrowserView* browser_view) | 94 AvatarLabel::AvatarLabel(BrowserView* browser_view) |
| 88 : TextButton(NULL, | 95 : TextButton(NULL, |
| 89 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)), | 96 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)), |
| 90 browser_view_(browser_view) { | 97 browser_view_(browser_view) { |
| 91 SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | 98 SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( |
| 92 ui::ResourceBundle::BaseFont)); | 99 ui::ResourceBundle::BaseFont)); |
| 93 ClearMaxTextSize(); | 100 ClearMaxTextSize(); |
| 94 set_border(new AvatarLabelBorder); | 101 set_border(new AvatarLabelBorder); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 107 | 114 |
| 108 void AvatarLabel::UpdateLabelStyle() { | 115 void AvatarLabel::UpdateLabelStyle() { |
| 109 SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor( | 116 SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor( |
| 110 ThemeProperties::COLOR_MANAGED_USER_LABEL); | 117 ThemeProperties::COLOR_MANAGED_USER_LABEL); |
| 111 SetEnabledColor(color_label); | 118 SetEnabledColor(color_label); |
| 112 SetHighlightColor(color_label); | 119 SetHighlightColor(color_label); |
| 113 SetHoverColor(color_label); | 120 SetHoverColor(color_label); |
| 114 SetDisabledColor(color_label); | 121 SetDisabledColor(color_label); |
| 115 SchedulePaint(); | 122 SchedulePaint(); |
| 116 } | 123 } |
| OLD | NEW |