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