OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/status/status_area_button.h" | 5 #include "chrome/browser/chromeos/status/status_area_button.h" |
6 | 6 |
| 7 #include "content/common/notification_service.h" |
7 #include "grit/theme_resources.h" | 8 #include "grit/theme_resources.h" |
| 9 #include "ui/base/resource/resource_bundle.h" |
8 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
9 #include "ui/gfx/skbitmap_operations.h" | 11 #include "ui/gfx/skbitmap_operations.h" |
10 #include "views/border.h" | 12 #include "views/border.h" |
11 #include "views/view.h" | 13 #include "views/view.h" |
12 | 14 |
13 namespace chromeos { | 15 namespace chromeos { |
14 | 16 |
15 // A 0.7 black to decorate status text. Same color is used for icon borders. | 17 // Colors for different text styles. |
16 static const SkColor kStatusTextHaloColor = SkColorSetARGB(0xB3, 0, 0, 0); | 18 static const SkColor kWhitePlainTextColor = 0x99ffffff; |
| 19 static const SkColor kWhiteHaloedTextColor = 0xb3ffffff; |
| 20 static const SkColor kWhiteHaloedHaloColor = 0xb3000000; |
| 21 static const SkColor kGrayEmbossedTextColor = 0xff4c4c4c; |
| 22 static const SkColor kGrayEmbossedShadowColor = 0x80ffffff; |
| 23 |
| 24 // Status area font is bigger. |
| 25 const int kFontSizeDelta = 1; |
17 | 26 |
18 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
19 // StatusAreaButton | 28 // StatusAreaButton |
20 | 29 |
21 StatusAreaButton::StatusAreaButton(views::ViewMenuDelegate* menu_delegate) | 30 StatusAreaButton::StatusAreaButton(StatusAreaHost* host, |
| 31 views::ViewMenuDelegate* menu_delegate) |
22 : MenuButton(NULL, std::wstring(), menu_delegate, false), | 32 : MenuButton(NULL, std::wstring(), menu_delegate, false), |
23 use_menu_button_paint_(false), active_(true) { | 33 use_menu_button_paint_(false), |
| 34 active_(true), |
| 35 host_(host) { |
| 36 set_border(NULL); |
| 37 set_use_menu_button_paint(true); |
| 38 gfx::Font font = |
| 39 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); |
| 40 font = font.DeriveFont(3, gfx::Font::BOLD); |
| 41 SetFont(font); |
| 42 SetShowMultipleIconStates(false); |
| 43 set_alignment(TextButton::ALIGN_CENTER); |
24 set_border(NULL); | 44 set_border(NULL); |
25 | 45 |
26 // Use an offset that is top aligned with toolbar. | 46 // Use an offset that is top aligned with toolbar. |
27 set_menu_offset(0, 2); | 47 set_menu_offset(0, 4); |
28 | 48 |
29 // Use a halo for status text as the icons. | 49 UpdateTextStyle(); |
30 SetTextHaloColor(kStatusTextHaloColor); | |
31 } | 50 } |
32 | 51 |
33 void StatusAreaButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 52 void StatusAreaButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
34 if (state() == BS_PUSHED) { | 53 if (state() == BS_PUSHED) { |
35 // Apply 10% white when pushed down. | 54 // Apply 10% white when pushed down. |
36 canvas->FillRectInt(SkColorSetARGB(0x19, 0xFF, 0xFF, 0xFF), | 55 canvas->FillRectInt(SkColorSetARGB(0x19, 0xFF, 0xFF, 0xFF), |
37 0, 0, width(), height()); | 56 0, 0, width(), height()); |
38 } | 57 } |
39 | 58 |
40 if (use_menu_button_paint_) { | 59 if (use_menu_button_paint_) { |
41 views::MenuButton::PaintButton(canvas, mode); | 60 views::MenuButton::PaintButton(canvas, mode); |
42 } else { | 61 } else { |
43 canvas->DrawBitmapInt(icon(), horizontal_padding(), 0); | 62 canvas->DrawBitmapInt(icon(), horizontal_padding(), 0); |
44 OnPaintFocusBorder(canvas); | 63 OnPaintFocusBorder(canvas); |
45 } | 64 } |
46 } | 65 } |
47 | 66 |
| 67 void StatusAreaButton::SetText(const std::wstring& text) { |
| 68 // TextButtons normally remember the max text size, so the button's preferred |
| 69 // size will always be as large as the largest text ever put in it. |
| 70 // We clear that max text size, so we can adjust the size to fit the text. |
| 71 // The order is important. ClearMaxTextSize sets the size to that of the |
| 72 // current text, so it must be called after SetText. |
| 73 views::MenuButton::SetText(text); |
| 74 ClearMaxTextSize(); |
| 75 PreferredSizeChanged(); |
| 76 } |
| 77 |
| 78 bool StatusAreaButton::Activate() { |
| 79 if (active_) { |
| 80 return views::MenuButton::Activate(); |
| 81 } else { |
| 82 return true; |
| 83 } |
| 84 } |
| 85 |
48 gfx::Size StatusAreaButton::GetPreferredSize() { | 86 gfx::Size StatusAreaButton::GetPreferredSize() { |
49 gfx::Insets insets = views::MenuButton::GetInsets(); | 87 gfx::Insets insets = views::MenuButton::GetInsets(); |
50 gfx::Size prefsize(icon_width() + insets.width(), | 88 gfx::Size prefsize(icon_width() + insets.width(), |
51 icon_height() + insets.height()); | 89 icon_height() + insets.height()); |
52 | 90 |
53 // Adjusts size when use menu button paint. | 91 // Adjusts size when use menu button paint. |
54 if (use_menu_button_paint_) { | 92 if (use_menu_button_paint_) { |
55 gfx::Size menu_button_size = views::MenuButton::GetPreferredSize(); | 93 gfx::Size menu_button_size = views::MenuButton::GetPreferredSize(); |
56 prefsize.SetSize( | 94 prefsize.SetSize( |
57 std::max(prefsize.width(), menu_button_size.width()), | 95 std::max(prefsize.width(), menu_button_size.width()), |
(...skipping 10 matching lines...) Expand all Loading... |
68 // Add padding. | 106 // Add padding. |
69 prefsize.Enlarge(2 * horizontal_padding(), 0); | 107 prefsize.Enlarge(2 * horizontal_padding(), 0); |
70 | 108 |
71 return prefsize; | 109 return prefsize; |
72 } | 110 } |
73 | 111 |
74 gfx::Insets StatusAreaButton::GetInsets() const { | 112 gfx::Insets StatusAreaButton::GetInsets() const { |
75 return insets_; | 113 return insets_; |
76 } | 114 } |
77 | 115 |
78 void StatusAreaButton::SetText(const std::wstring& text) { | 116 void StatusAreaButton::OnThemeChanged() { |
79 // TextButtons normally remember the max text size, so the button's preferred | 117 UpdateTextStyle(); |
80 // size will always be as large as the largest text ever put in it. | |
81 // We clear that max text size, so we can adjust the size to fit the text. | |
82 // The order is important. ClearMaxTextSize sets the size to that of the | |
83 // current text, so it must be called after SetText. | |
84 views::MenuButton::SetText(text); | |
85 ClearMaxTextSize(); | |
86 PreferredSizeChanged(); | |
87 } | 118 } |
88 | 119 |
89 bool StatusAreaButton::Activate() { | 120 void StatusAreaButton::UpdateTextStyle() { |
90 if (active_) { | 121 ClearEmbellishing(); |
91 return views::MenuButton::Activate(); | 122 switch (host_->GetTextStyle()) { |
92 } else { | 123 case StatusAreaHost::kWhitePlain: |
93 return true; | 124 SetEnabledColor(kWhitePlainTextColor); |
| 125 break; |
| 126 case StatusAreaHost::kWhiteHaloed: |
| 127 SetEnabledColor(kWhiteHaloedTextColor); |
| 128 SetTextHaloColor(kWhiteHaloedHaloColor); |
| 129 break; |
| 130 case StatusAreaHost::kGrayEmbossed: |
| 131 SetEnabledColor(kGrayEmbossedTextColor); |
| 132 SetTextShadowColors(kGrayEmbossedShadowColor, kGrayEmbossedShadowColor); |
| 133 SetTextShadowOffset(0, 1); |
| 134 break; |
94 } | 135 } |
95 } | 136 } |
96 | 137 |
97 } // namespace chromeos | 138 } // namespace chromeos |
OLD | NEW |