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

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

Issue 8438064: Separate StatusAreaView from StatusAreaViewChromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang fixes + fixup Delegate Created 9 years, 1 month 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
1 // Copyright (c) 2011 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 "grit/theme_resources.h" 7 #include "grit/theme_resources.h"
8 #include "ui/base/resource/resource_bundle.h" 8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/skbitmap_operations.h" 10 #include "ui/gfx/skbitmap_operations.h"
(...skipping 11 matching lines...) Expand all
22 const SkColor kGrayEmbossedShadowColor = 0x80ffffff; 22 const SkColor kGrayEmbossedShadowColor = 0x80ffffff;
23 23
24 // Status area font is bigger. 24 // Status area font is bigger.
25 const int kFontSizeDelta = 3; 25 const int kFontSizeDelta = 3;
26 26
27 // Pad for status icons. 27 // Pad for status icons.
28 const int kIconHorizontalPad = 2; 28 const int kIconHorizontalPad = 2;
29 29
30 } 30 }
31 31
32 namespace chromeos {
33
34 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
35 // StatusAreaButton 33 // StatusAreaButton
36 34
37 StatusAreaButton::StatusAreaButton(StatusAreaHost* host, 35 StatusAreaButton::StatusAreaButton(Delegate* button_delegate,
38 views::ViewMenuDelegate* menu_delegate) 36 views::ViewMenuDelegate* menu_delegate)
39 : MenuButton(NULL, string16(), menu_delegate, false), 37 : MenuButton(NULL, string16(), menu_delegate, false),
40 use_menu_button_paint_(false), 38 menu_active_(true),
41 active_(true), 39 delegate_(button_delegate) {
42 host_(host) {
43 set_border(NULL); 40 set_border(NULL);
44 set_use_menu_button_paint(true);
45
46 bool webui_login = host_->GetScreenMode() == StatusAreaHost::kWebUILoginMode;
47 41
48 gfx::Font font = 42 gfx::Font font =
49 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); 43 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
50 font = font.DeriveFont(kFontSizeDelta, webui_login ? font.GetStyle() 44 font = font.DeriveFont(kFontSizeDelta, delegate_->GetFontStyle(font));
51 : gfx::Font::BOLD);
52 SetFont(font); 45 SetFont(font);
53 46
54 SetShowMultipleIconStates(false); 47 SetShowMultipleIconStates(false);
55 set_alignment(TextButton::ALIGN_CENTER); 48 set_alignment(TextButton::ALIGN_CENTER);
56 set_border(views::Border::CreateEmptyBorder( 49 set_border(views::Border::CreateEmptyBorder(
57 0, kIconHorizontalPad, 0, kIconHorizontalPad)); 50 0, kIconHorizontalPad, 0, kIconHorizontalPad));
58 51
59 // Use an offset that is top aligned with toolbar. 52 // Use an offset that is top aligned with toolbar.
60 set_menu_offset(0, 4); 53 set_menu_offset(0, 4);
61 54
62 UpdateTextStyle(); 55 UpdateTextStyle();
63 } 56 }
64 57
65 void StatusAreaButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { 58 void StatusAreaButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
66 if (state() == BS_PUSHED) { 59 if (state() == BS_PUSHED) {
67 // Apply 10% white when pushed down. 60 // Apply 10% white when pushed down.
68 canvas->FillRect(SkColorSetARGB(0x19, 0xFF, 0xFF, 0xFF), GetLocalBounds()); 61 canvas->FillRect(SkColorSetARGB(0x19, 0xFF, 0xFF, 0xFF), GetLocalBounds());
69 } 62 }
70 63
71 if (use_menu_button_paint_) { 64 views::MenuButton::PaintButton(canvas, mode);
72 views::MenuButton::PaintButton(canvas, mode);
73 } else {
74 canvas->DrawBitmapInt(icon(), horizontal_padding(), 0);
75 OnPaintFocusBorder(canvas);
76 }
77 } 65 }
78 66
79 void StatusAreaButton::SetText(const string16& text) { 67 void StatusAreaButton::SetText(const string16& text) {
80 // TextButtons normally remember the max text size, so the button's preferred 68 // TextButtons normally remember the max text size, so the button's preferred
81 // size will always be as large as the largest text ever put in it. 69 // size will always be as large as the largest text ever put in it.
82 // We clear that max text size, so we can adjust the size to fit the text. 70 // We clear that max text size, so we can adjust the size to fit the text.
83 // The order is important. ClearMaxTextSize sets the size to that of the 71 // The order is important. ClearMaxTextSize sets the size to that of the
84 // current text, so it must be called after SetText. 72 // current text, so it must be called after SetText.
85 views::MenuButton::SetText(text); 73 views::MenuButton::SetText(text);
86 ClearMaxTextSize(); 74 ClearMaxTextSize();
87 PreferredSizeChanged(); 75 PreferredSizeChanged();
88 } 76 }
89 77
90 bool StatusAreaButton::Activate() { 78 bool StatusAreaButton::Activate() {
91 if (active_) 79 if (menu_active_)
92 return views::MenuButton::Activate(); 80 return views::MenuButton::Activate();
93 else 81 else
94 return true; 82 return true;
95 } 83 }
96 84
97 gfx::Size StatusAreaButton::GetPreferredSize() { 85 gfx::Size StatusAreaButton::GetPreferredSize() {
98 gfx::Insets insets = views::MenuButton::GetInsets(); 86 gfx::Insets insets = views::MenuButton::GetInsets();
99 gfx::Size prefsize(icon_width() + insets.width(), 87 gfx::Size prefsize(icon_width() + insets.width(),
100 icon_height() + insets.height()); 88 icon_height() + insets.height());
101 89
102 // Adjusts size when use menu button paint. 90 // Adjusts size when use menu button paint.
103 if (use_menu_button_paint_) { 91 gfx::Size menu_button_size = views::MenuButton::GetPreferredSize();
104 gfx::Size menu_button_size = views::MenuButton::GetPreferredSize(); 92 prefsize.SetSize(std::max(prefsize.width(), menu_button_size.width()),
105 prefsize.SetSize( 93 std::max(prefsize.height(), menu_button_size.height()));
106 std::max(prefsize.width(), menu_button_size.width()),
107 std::max(prefsize.height(), menu_button_size.height())
108 );
109 94
110 // Shift 1-pixel down for odd number of pixels in vertical space. 95 // Shift 1-pixel down for odd number of pixels in vertical space.
111 if ((prefsize.height() - menu_button_size.height()) % 2) { 96 if ((prefsize.height() - menu_button_size.height()) % 2) {
112 insets_.Set(insets.top() + 1, insets.left(), 97 insets_.Set(insets.top() + 1, insets.left(),
113 insets.bottom(), insets.right()); 98 insets.bottom(), insets.right());
114 }
115 } 99 }
116 100
117 // Add padding. 101 // Add padding.
118 prefsize.Enlarge(2 * horizontal_padding(), 0); 102 prefsize.Enlarge(2 * horizontal_padding(), 0);
119 103
120 return prefsize; 104 return prefsize;
121 } 105 }
122 106
123 gfx::Insets StatusAreaButton::GetInsets() const { 107 gfx::Insets StatusAreaButton::GetInsets() const {
124 return insets_; 108 return insets_;
125 } 109 }
126 110
127 void StatusAreaButton::OnThemeChanged() { 111 void StatusAreaButton::OnThemeChanged() {
128 UpdateTextStyle(); 112 UpdateTextStyle();
129 } 113 }
130 114
131 void StatusAreaButton::SetVisible(bool visible) { 115 void StatusAreaButton::SetVisible(bool visible) {
132 if (visible != IsVisible()) { 116 if (visible != IsVisible()) {
133 views::MenuButton::SetVisible(visible); 117 views::MenuButton::SetVisible(visible);
134 host_->ButtonVisibilityChanged(this); 118 delegate_->ButtonVisibilityChanged(this);
135 } 119 }
136 } 120 }
137 121
138 bool StatusAreaButton::HitTest(const gfx::Point& l) const { 122 bool StatusAreaButton::HitTest(const gfx::Point& l) const {
139 // BrowserFrameViewChromeos adds a few pixels of pad to the top of the 123 // BrowserFrameViewChromeos adds a few pixels of pad to the top of the
140 // status area. For mouse events in this area to activate the button, 124 // status area. For mouse events in this area to activate the button,
141 // hit testing need to be successful. We do this by clamping y to the 125 // hit testing need to be successful. We do this by clamping y to the
142 // position of the menu button view. 126 // position of the menu button view.
143 gfx::Point point(l.x(), std::max(y(), l.y())); 127 gfx::Point point(l.x(), std::max(y(), l.y()));
144 return MenuButton::HitTest(point); 128 return MenuButton::HitTest(point);
145 } 129 }
146 130
147 int StatusAreaButton::icon_height() { 131 int StatusAreaButton::icon_height() {
148 return 24; 132 return 24;
149 } 133 }
150 134
151 int StatusAreaButton::icon_width() { 135 int StatusAreaButton::icon_width() {
152 return 23; 136 return 23;
153 } 137 }
154 138
155 int StatusAreaButton::horizontal_padding() { 139 int StatusAreaButton::horizontal_padding() {
156 return 1; 140 return 1;
157 } 141 }
158 142
159 void StatusAreaButton::UpdateTextStyle() { 143 void StatusAreaButton::UpdateTextStyle() {
160 ClearEmbellishing(); 144 ClearEmbellishing();
161 switch (host_->GetTextStyle()) { 145 switch (delegate_->GetTextStyle()) {
162 case StatusAreaHost::kWhitePlain: 146 case WHITE_PLAIN:
163 SetEnabledColor(kWhitePlainTextColor); 147 SetEnabledColor(kWhitePlainTextColor);
164 break; 148 break;
165 case StatusAreaHost::kGrayPlain: 149 case GRAY_PLAIN:
166 SetEnabledColor(kGrayPlainTextColor); 150 SetEnabledColor(kGrayPlainTextColor);
167 break; 151 break;
168 case StatusAreaHost::kWhiteHaloed: 152 case WHITE_HALOED:
169 SetEnabledColor(kWhiteHaloedTextColor); 153 SetEnabledColor(kWhiteHaloedTextColor);
170 SetTextHaloColor(kWhiteHaloedHaloColor); 154 SetTextHaloColor(kWhiteHaloedHaloColor);
171 break; 155 break;
172 case StatusAreaHost::kGrayEmbossed: 156 case GRAY_EMBOSSED:
173 SetEnabledColor(kGrayEmbossedTextColor); 157 SetEnabledColor(kGrayEmbossedTextColor);
174 SetTextShadowColors(kGrayEmbossedShadowColor, kGrayEmbossedShadowColor); 158 SetTextShadowColors(kGrayEmbossedShadowColor, kGrayEmbossedShadowColor);
175 SetTextShadowOffset(0, 1); 159 SetTextShadowOffset(0, 1);
176 break; 160 break;
177 } 161 }
178 } 162 }
179
180 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698