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

Unified Diff: chrome/browser/ui/views/new_avatar_button.cc

Issue 24647003: Redesign of the avatar menu button. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unbork test Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/new_avatar_button.cc
diff --git a/chrome/browser/ui/views/new_avatar_button.cc b/chrome/browser/ui/views/new_avatar_button.cc
new file mode 100644
index 0000000000000000000000000000000000000000..032c1ae90067b17a3cadf78edad7b6f86cf383ba
--- /dev/null
+++ b/chrome/browser/ui/views/new_avatar_button.cc
@@ -0,0 +1,145 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// 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/new_avatar_button.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/profiles/profile_metrics.h"
+#include "chrome/browser/themes/theme_properties.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "chrome/browser/ui/views/profile_chooser_view.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/theme_provider.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/color_utils.h"
+#include "ui/views/border.h"
+#include "ui/views/painter.h"
+
+namespace {
+
+const int kInset = 10;
sky 2013/10/03 23:23:11 Description?
noms (inactive) 2013/10/07 21:18:15 Done.
+
+
+// AvatarGlassButtonBorder ----------------------------------------------------
+class AvatarGlassButtonBorder : public views::TextButtonDefaultBorder {
+ public:
+ AvatarGlassButtonBorder() {
+ const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
+ const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
+ const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
+
+ SetInsets(gfx::Insets(kInset, kInset, kInset, kInset));
+ set_normal_painter(views::Painter::CreateImageGridPainter(kNormalImageSet));
+ set_hot_painter(views::Painter::CreateImageGridPainter(kHotImageSet));
+ set_pushed_painter(views::Painter::CreateImageGridPainter(kPushedImageSet));
+ };
+
+ private:
+ virtual ~AvatarGlassButtonBorder() {
+ };
+
+ DISALLOW_COPY_AND_ASSIGN(AvatarGlassButtonBorder);
+};
+
+
+// AvatarThemedButtonBorder ---------------------------------------------------
+
+class AvatarThemedButtonBorder : public views::TextButtonDefaultBorder {
+ public:
+ AvatarThemedButtonBorder() {
+ const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
+ const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER);
+ const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED);
+
+ SetInsets(gfx::Insets(kInset, kInset, kInset, kInset));
+ set_normal_painter(views::Painter::CreateImageGridPainter(kNormalImageSet));
+ set_hot_painter(views::Painter::CreateImageGridPainter(kHotImageSet));
+ set_pushed_painter(views::Painter::CreateImageGridPainter(kPushedImageSet));
+ };
+
+ private:
+ virtual ~AvatarThemedButtonBorder() {
+ };
+
+ DISALLOW_COPY_AND_ASSIGN(AvatarThemedButtonBorder);
+};
+
+} // namespace
+
+
+// NewAvatarButton ------------------------------------------------------------
+NewAvatarButton::NewAvatarButton(
+ BrowserView* browser_view,
+ const string16& profile_name)
+ : MenuButton(NULL, string16(), NULL, true),
+ browser_view_(browser_view) {
+ SetText(profile_name);
+ set_animate_on_state_change(false);
+
+ ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
+ SetFont(rb->GetFont(ui::ResourceBundle::BaseFont));
+
+ if (browser_view->frame()->ShouldUseNativeFrame()) {
sky 2013/10/03 23:23:11 I think this code is cleaner if you remove the bro
noms (inactive) 2013/10/08 18:21:15 Done.
+ set_border(new AvatarGlassButtonBorder);
+ set_menu_marker(
+ rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia());
+ } else {
+ set_border(new AvatarThemedButtonBorder);
+ set_menu_marker(
+ rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia());
+ }
+ SchedulePaint();
+}
+
+NewAvatarButton::~NewAvatarButton() {
+}
+
+void NewAvatarButton::OnPaint(gfx::Canvas* canvas) {
+ // From TextButton::PaintButton, draw everything but the text.
+ OnPaintBackground(canvas);
+ OnPaintBorder(canvas);
+ OnPaintFocusBorder(canvas);
+
+ gfx::Rect rect;
+ // In RTL languages the marker gets drawn leftmost, so account for its offset.
+ if (base::i18n::IsRTL())
+ rect = gfx::Rect(-kInset, 0, size().width(), size().height());
+ else
+ rect = gfx::Rect(kInset, 0, size().width(), size().height());
+ // TODO(noms): This should be DrawStringRectWithHalo but that function
+ // has a bug at the moment and incorrectly draws the background.
+ canvas->DrawStringRectWithFlags(
+ text(),
+ gfx::FontList(ui::ResourceBundle::GetSharedInstance().GetFont(
+ ui::ResourceBundle::BaseFont)),
+ SK_ColorBLACK,
+ rect,
+ gfx::Canvas::NO_SUBPIXEL_RENDERING);
+
+ // From MenuButton::PaintButton, paint the marker
+ PaintMenuMarker(canvas);
+}
+
+bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) {
+ if (!TextButton::OnMousePressed(event))
+ return false;
+ ShowAvatarBubble();
sky 2013/10/03 23:23:11 How come you're showing on a press and not release
noms (inactive) 2013/10/07 21:18:15 Done.
+ return true;
+}
+
+void NewAvatarButton::ShowAvatarBubble() {
sky 2013/10/03 23:23:11 Can this be done via a listener and not here?
noms (inactive) 2013/10/07 21:18:15 I'm not sure what you mean by this. I've moved the
sky 2013/10/08 01:56:04 I'm suggesting you make someone implement ButtonLi
noms (inactive) 2013/10/08 18:21:15 Sorry, I had a completely half-a-brain moment ther
+ gfx::Point origin;
+ views::View::ConvertPointToScreen(this, &origin);
+ gfx::Rect bounds(origin, size());
+
+ ProfileChooserView::ShowBubble(
+ this, views::BubbleBorder::TOP_RIGHT,
+ views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE, bounds,
+ browser_view_->browser());
+
+ ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE);
+}

Powered by Google App Engine
This is Rietveld 408576698