Index: chrome/browser/ui/views/avatar_menu_button.cc |
=================================================================== |
--- chrome/browser/ui/views/avatar_menu_button.cc (revision 88024) |
+++ chrome/browser/ui/views/avatar_menu_button.cc (working copy) |
@@ -2,55 +2,53 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/views/profile_menu_button.h" |
+#include "chrome/browser/ui/views/avatar_menu_button.h" |
-#include "chrome/browser/ui/profile_menu_model.h" |
-#include "ui/base/text/text_elider.h" |
-#include "ui/gfx/color_utils.h" |
-#include "views/controls/button/button.h" |
-#include "views/controls/menu/menu_item_view.h" |
+#include "ui/gfx/canvas_skia.h" |
#include "views/controls/menu/menu_model_adapter.h" |
#include "views/window/window.h" |
-// Menu should display below the profile button tag image on the frame. This |
+// Menu should display below the image on the frame. This |
// offset size depends on whether the frame is in glass or opaque mode. |
-const int kMenuDisplayOffset = 7; |
+const int kMenuDisplayOffset = 5; |
-// TextHover is slightly darker than enabled color, for a subtle hover shift. |
-const SkColor kTextHover = 0xFFDDDDDD; |
-const SkColor kTextEnabled = SK_ColorWHITE; |
-const SkColor kTextHighlighted = SK_ColorWHITE; |
+AvatarMenuButton::AvatarMenuButton(const std::wstring& text, |
+ ui::MenuModel* menu_model) |
+ : MenuButton(NULL, text, this, false), |
+ menu_model_(menu_model) { |
+} |
-// Horizontal padding beside profile menu button, to center it in the |
-// underlying tag image. |
-const int kProfileButtonBorderSpacing = 10; |
+AvatarMenuButton::~AvatarMenuButton() {} |
-// Maximum width for name string in pixels. |
-const int kMaxTextWidth = 200; |
+void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { |
+ // In RTL mode, the avatar icon should be looking the opposite direction. |
+ canvas->Save(); |
+ if (base::i18n::IsRTL()) { |
Peter Kasting
2011/06/09 18:03:31
You should not need to do this manually. See View
sail
2011/06/10 00:56:20
Done.
|
+ canvas->TranslateInt(width(), 0); |
+ canvas->ScaleInt(-1, 1); |
+ } |
-ProfileMenuButton::ProfileMenuButton(const std::wstring& text, Profile* profile) |
- : MenuButton(NULL, text, this, true) { |
- // Turn off hover highlighting and position button in the center of the |
- // underlying profile tag image. |
- set_border(views::Border::CreateEmptyBorder( |
- 0, kProfileButtonBorderSpacing, 0, kProfileButtonBorderSpacing)); |
- SetHoverColor(kTextHover); |
- SetEnabledColor(kTextEnabled); |
- SetHighlightColor(kTextHighlighted); |
+ SkBitmap icon = GetImageToPaint(); |
+ if (!icon.isNull()) { |
+ int w = icon.width(); |
+ int h = icon.height(); |
+ canvas->DrawBitmapInt(icon, 0, |
+ // Bias the rounding to select a region that's lower rather than higher, |
+ // as the shadows at the image top mean the apparent center is below the |
+ // real center. |
+ ((icon.height() - icon.height()) + 1) / 2, w, h, |
Miranda Callahan
2011/06/09 13:23:07
Looks like you are calculating (x - x) here? (Als
Peter Kasting
2011/06/09 18:03:31
Yeah, I think one of these is supposed to be the b
sail
2011/06/10 00:56:20
Fixed.
I changed the code to be a little more gene
|
+ 0, 0, width(), height(), false); |
+ } |
- profile_menu_model_.reset(new ProfileMenuModel); |
+ canvas->Restore(); |
} |
-ProfileMenuButton::~ProfileMenuButton() {} |
- |
-void ProfileMenuButton::SetText(const std::wstring& text) { |
- MenuButton::SetText(UTF16ToWideHack(ui::ElideText(WideToUTF16Hack(text), |
- font(), kMaxTextWidth, false))); |
-} |
- |
// views::ViewMenuDelegate implementation |
-void ProfileMenuButton::RunMenu(views::View* source, const gfx::Point &pt) { |
- views::MenuModelAdapter menu_model_adapter(profile_menu_model_.get()); |
+void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point &pt) { |
Peter Kasting
2011/06/09 18:03:31
Nit: While here, fix the position of '&'
sail
2011/06/10 00:56:20
Done.
|
+ if (!menu_model_.get()) |
+ return; |
+ |
+ views::MenuModelAdapter menu_model_adapter(menu_model_.get()); |
views::MenuItemView menu(&menu_model_adapter); |
menu_model_adapter.BuildMenu(&menu); |