| OLD | NEW |
| 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 Loading... |
| 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); |
| 51 : gfx::Font::BOLD); | 45 font = delegate_->GetStatusAreaFont(font); |
| 52 SetFont(font); | 46 SetFont(font); |
| 53 | 47 |
| 54 SetShowMultipleIconStates(false); | 48 SetShowMultipleIconStates(false); |
| 55 set_alignment(TextButton::ALIGN_CENTER); | 49 set_alignment(TextButton::ALIGN_CENTER); |
| 56 set_border(views::Border::CreateEmptyBorder( | 50 set_border(views::Border::CreateEmptyBorder( |
| 57 0, kIconHorizontalPad, 0, kIconHorizontalPad)); | 51 0, kIconHorizontalPad, 0, kIconHorizontalPad)); |
| 58 | 52 |
| 59 // Use an offset that is top aligned with toolbar. | 53 // Use an offset that is top aligned with toolbar. |
| 60 set_menu_offset(0, 4); | 54 set_menu_offset(0, 4); |
| 61 | 55 |
| 62 UpdateTextStyle(); | 56 UpdateTextStyle(); |
| 63 } | 57 } |
| 64 | 58 |
| 65 void StatusAreaButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 59 void StatusAreaButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
| 66 if (state() == BS_PUSHED) { | 60 if (state() == BS_PUSHED) { |
| 67 // Apply 10% white when pushed down. | 61 // Apply 10% white when pushed down. |
| 68 canvas->FillRect(SkColorSetARGB(0x19, 0xFF, 0xFF, 0xFF), GetLocalBounds()); | 62 canvas->FillRect(SkColorSetARGB(0x19, 0xFF, 0xFF, 0xFF), GetLocalBounds()); |
| 69 } | 63 } |
| 70 | 64 |
| 71 if (use_menu_button_paint_) { | 65 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 } | 66 } |
| 78 | 67 |
| 79 void StatusAreaButton::SetText(const string16& text) { | 68 void StatusAreaButton::SetText(const string16& text) { |
| 80 // TextButtons normally remember the max text size, so the button's preferred | 69 // 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. | 70 // 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. | 71 // 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 | 72 // The order is important. ClearMaxTextSize sets the size to that of the |
| 84 // current text, so it must be called after SetText. | 73 // current text, so it must be called after SetText. |
| 85 views::MenuButton::SetText(text); | 74 views::MenuButton::SetText(text); |
| 86 ClearMaxTextSize(); | 75 ClearMaxTextSize(); |
| 87 PreferredSizeChanged(); | 76 PreferredSizeChanged(); |
| 88 } | 77 } |
| 89 | 78 |
| 90 bool StatusAreaButton::Activate() { | 79 bool StatusAreaButton::Activate() { |
| 91 if (active_) | 80 if (menu_active_) |
| 92 return views::MenuButton::Activate(); | 81 return views::MenuButton::Activate(); |
| 93 else | 82 else |
| 94 return true; | 83 return true; |
| 95 } | 84 } |
| 96 | 85 |
| 97 gfx::Size StatusAreaButton::GetPreferredSize() { | 86 gfx::Size StatusAreaButton::GetPreferredSize() { |
| 98 gfx::Insets insets = views::MenuButton::GetInsets(); | 87 gfx::Insets insets = views::MenuButton::GetInsets(); |
| 99 gfx::Size prefsize(icon_width() + insets.width(), | 88 gfx::Size prefsize(icon_width() + insets.width(), |
| 100 icon_height() + insets.height()); | 89 icon_height() + insets.height()); |
| 101 | 90 |
| 102 // Adjusts size when use menu button paint. | 91 // Adjusts size when use menu button paint. |
| 103 if (use_menu_button_paint_) { | 92 gfx::Size menu_button_size = views::MenuButton::GetPreferredSize(); |
| 104 gfx::Size menu_button_size = views::MenuButton::GetPreferredSize(); | 93 prefsize.SetSize(std::max(prefsize.width(), menu_button_size.width()), |
| 105 prefsize.SetSize( | 94 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 | 95 |
| 110 // Shift 1-pixel down for odd number of pixels in vertical space. | 96 // Shift 1-pixel down for odd number of pixels in vertical space. |
| 111 if ((prefsize.height() - menu_button_size.height()) % 2) { | 97 if ((prefsize.height() - menu_button_size.height()) % 2) { |
| 112 insets_.Set(insets.top() + 1, insets.left(), | 98 insets_.Set(insets.top() + 1, insets.left(), |
| 113 insets.bottom(), insets.right()); | 99 insets.bottom(), insets.right()); |
| 114 } | |
| 115 } | 100 } |
| 116 | 101 |
| 117 // Add padding. | 102 // Add padding. |
| 118 prefsize.Enlarge(2 * horizontal_padding(), 0); | 103 prefsize.Enlarge(2 * horizontal_padding(), 0); |
| 119 | 104 |
| 120 return prefsize; | 105 return prefsize; |
| 121 } | 106 } |
| 122 | 107 |
| 123 gfx::Insets StatusAreaButton::GetInsets() const { | 108 gfx::Insets StatusAreaButton::GetInsets() const { |
| 124 return insets_; | 109 return insets_; |
| 125 } | 110 } |
| 126 | 111 |
| 127 void StatusAreaButton::OnThemeChanged() { | 112 void StatusAreaButton::OnThemeChanged() { |
| 128 UpdateTextStyle(); | 113 UpdateTextStyle(); |
| 129 } | 114 } |
| 130 | 115 |
| 131 void StatusAreaButton::SetVisible(bool visible) { | 116 void StatusAreaButton::SetVisible(bool visible) { |
| 132 if (visible != IsVisible()) { | 117 if (visible != IsVisible()) { |
| 133 views::MenuButton::SetVisible(visible); | 118 views::MenuButton::SetVisible(visible); |
| 134 host_->ButtonVisibilityChanged(this); | 119 delegate_->ButtonVisibilityChanged(this); |
| 135 } | 120 } |
| 136 } | 121 } |
| 137 | 122 |
| 138 bool StatusAreaButton::HitTest(const gfx::Point& l) const { | 123 bool StatusAreaButton::HitTest(const gfx::Point& l) const { |
| 139 // BrowserFrameViewChromeos adds a few pixels of pad to the top of the | 124 // 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, | 125 // 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 | 126 // hit testing need to be successful. We do this by clamping y to the |
| 142 // position of the menu button view. | 127 // position of the menu button view. |
| 143 gfx::Point point(l.x(), std::max(y(), l.y())); | 128 gfx::Point point(l.x(), std::max(y(), l.y())); |
| 144 return MenuButton::HitTest(point); | 129 return MenuButton::HitTest(point); |
| 145 } | 130 } |
| 146 | 131 |
| 147 int StatusAreaButton::icon_height() { | 132 int StatusAreaButton::icon_height() { |
| 148 return 24; | 133 return 24; |
| 149 } | 134 } |
| 150 | 135 |
| 151 int StatusAreaButton::icon_width() { | 136 int StatusAreaButton::icon_width() { |
| 152 return 23; | 137 return 23; |
| 153 } | 138 } |
| 154 | 139 |
| 155 int StatusAreaButton::horizontal_padding() { | 140 int StatusAreaButton::horizontal_padding() { |
| 156 return 1; | 141 return 1; |
| 157 } | 142 } |
| 158 | 143 |
| 159 void StatusAreaButton::UpdateTextStyle() { | 144 void StatusAreaButton::UpdateTextStyle() { |
| 160 ClearEmbellishing(); | 145 ClearEmbellishing(); |
| 161 switch (host_->GetTextStyle()) { | 146 switch (delegate_->GetStatusAreaTextStyle()) { |
| 162 case StatusAreaHost::kWhitePlain: | 147 case WHITE_PLAIN: |
| 163 SetEnabledColor(kWhitePlainTextColor); | 148 SetEnabledColor(kWhitePlainTextColor); |
| 164 break; | 149 break; |
| 165 case StatusAreaHost::kGrayPlain: | 150 case GRAY_PLAIN: |
| 166 SetEnabledColor(kGrayPlainTextColor); | 151 SetEnabledColor(kGrayPlainTextColor); |
| 167 break; | 152 break; |
| 168 case StatusAreaHost::kWhiteHaloed: | 153 case WHITE_HALOED: |
| 169 SetEnabledColor(kWhiteHaloedTextColor); | 154 SetEnabledColor(kWhiteHaloedTextColor); |
| 170 SetTextHaloColor(kWhiteHaloedHaloColor); | 155 SetTextHaloColor(kWhiteHaloedHaloColor); |
| 171 break; | 156 break; |
| 172 case StatusAreaHost::kGrayEmbossed: | 157 case GRAY_EMBOSSED: |
| 173 SetEnabledColor(kGrayEmbossedTextColor); | 158 SetEnabledColor(kGrayEmbossedTextColor); |
| 174 SetTextShadowColors(kGrayEmbossedShadowColor, kGrayEmbossedShadowColor); | 159 SetTextShadowColors(kGrayEmbossedShadowColor, kGrayEmbossedShadowColor); |
| 175 SetTextShadowOffset(0, 1); | 160 SetTextShadowOffset(0, 1); |
| 176 break; | 161 break; |
| 177 } | 162 } |
| 178 } | 163 } |
| 179 | |
| 180 } // namespace chromeos | |
| OLD | NEW |