Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: chrome/browser/chromeos/status/status_area_button.cc

Issue 10056001: chromeos: Remove old status-area related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/chromeos/status/status_area_button.h"
6
7 #include "grit/theme_resources.h"
8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/skbitmap_operations.h"
11 #include "ui/views/border.h"
12 #include "ui/views/view.h"
13
14 namespace {
15
16 // Colors for different text styles.
17 const SkColor kWhitePlainTextColor = 0x99ffffff;
18 const SkColor kGrayPlainTextColor = 0xff666666;
19 const SkColor kWhiteHaloedTextColor = 0xb3ffffff;
20 const SkColor kWhiteHaloedHaloColor = 0xb3000000;
21 const SkColor kGrayEmbossedTextColor = 0xff4c4c4c;
22 const SkColor kGrayEmbossedShadowColor = 0x80ffffff;
23
24 // Status area font is bigger.
25 const int kFontSizeDelta = 3;
26
27 // Pad for status icons.
28 const int kIconHorizontalPad = 2;
29
30 }
31
32 ////////////////////////////////////////////////////////////////////////////////
33 // StatusAreaButton
34
35 StatusAreaButton::StatusAreaButton(Delegate* button_delegate,
36 views::MenuButtonListener* listener)
37 : MenuButton(NULL, string16(), listener, false),
38 menu_active_(true),
39 delegate_(button_delegate) {
40 set_border(NULL);
41
42 light_font_ =
43 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont).
44 DeriveFont(kFontSizeDelta);
45 bold_font_ = light_font_.DeriveFont(0, gfx::Font::BOLD);
46
47 SetShowMultipleIconStates(false);
48 set_alignment(TextButton::ALIGN_CENTER);
49 set_border(views::Border::CreateEmptyBorder(
50 0, kIconHorizontalPad, 0, kIconHorizontalPad));
51
52 // Use an offset that is top aligned with toolbar.
53 set_menu_offset(0, 4);
54
55 UpdateTextStyle();
56 }
57
58 void StatusAreaButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
59 if (state() == BS_PUSHED) {
60 // Apply 10% white when pushed down.
61 canvas->FillRect(GetLocalBounds(), SkColorSetARGB(0x19, 0xFF, 0xFF, 0xFF));
62 }
63
64 views::MenuButton::PaintButton(canvas, mode);
65 }
66
67 void StatusAreaButton::SetText(const string16& 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 (menu_active_)
80 return views::MenuButton::Activate();
81 else
82 return true;
83 }
84
85 gfx::Size StatusAreaButton::GetPreferredSize() {
86 gfx::Insets insets = views::MenuButton::GetInsets();
87 gfx::Size prefsize(icon_width() + insets.width(),
88 icon_height() + insets.height());
89
90 // Adjusts size when use menu button paint.
91 gfx::Size menu_button_size = views::MenuButton::GetPreferredSize();
92 prefsize.SetSize(std::max(prefsize.width(), menu_button_size.width()),
93 std::max(prefsize.height(), menu_button_size.height()));
94
95 // Shift 1-pixel down for odd number of pixels in vertical space.
96 if ((prefsize.height() - menu_button_size.height()) % 2) {
97 insets_.Set(insets.top() + 1, insets.left(),
98 insets.bottom(), insets.right());
99 }
100
101 // Add padding.
102 prefsize.Enlarge(2 * horizontal_padding(), 0);
103
104 return prefsize;
105 }
106
107 gfx::Insets StatusAreaButton::GetInsets() const {
108 return insets_;
109 }
110
111 void StatusAreaButton::OnThemeChanged() {
112 UpdateTextStyle();
113 }
114
115 void StatusAreaButton::SetVisible(bool is_visible) {
116 if (is_visible != visible()) {
117 views::MenuButton::SetVisible(is_visible);
118 delegate_->ButtonVisibilityChanged(this);
119 }
120 }
121
122 bool StatusAreaButton::HitTest(const gfx::Point& l) const {
123 // BrowserFrameViewChromeos adds a few pixels of pad to the top of the
124 // status area. For mouse events in this area to activate the button,
125 // hit testing need to be successful. We do this by clamping y to the
126 // position of the menu button view.
127 gfx::Point point(l.x(), std::max(y(), l.y()));
128 return MenuButton::HitTest(point);
129 }
130
131 void StatusAreaButton::SetMenuActive(bool active) {
132 menu_active_ = active;
133 }
134
135 void StatusAreaButton::UpdateTextStyle() {
136 ClearEmbellishing();
137 switch (delegate_->GetStatusAreaTextStyle()) {
138 case WHITE_PLAIN_BOLD:
139 SetFont(bold_font_);
140 SetEnabledColor(kWhitePlainTextColor);
141 break;
142 case GRAY_PLAIN_LIGHT:
143 SetFont(light_font_);
144 SetEnabledColor(kGrayPlainTextColor);
145 break;
146 case WHITE_HALOED_BOLD:
147 SetFont(bold_font_);
148 SetEnabledColor(kWhiteHaloedTextColor);
149 SetTextHaloColor(kWhiteHaloedHaloColor);
150 break;
151 case GRAY_EMBOSSED_BOLD:
152 SetFont(bold_font_);
153 SetEnabledColor(kGrayEmbossedTextColor);
154 SetTextShadowColors(kGrayEmbossedShadowColor, kGrayEmbossedShadowColor);
155 SetTextShadowOffset(0, 1);
156 break;
157 }
158 SchedulePaint();
159 }
160
161 int StatusAreaButton::icon_height() {
162 return 24;
163 }
164
165 int StatusAreaButton::icon_width() {
166 return 23;
167 }
168
169 int StatusAreaButton::horizontal_padding() {
170 return 1;
171 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/status_area_button.h ('k') | chrome/browser/chromeos/status/status_area_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698