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

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

Issue 7138003: Revert 88683 - Change profile menu button to avatar button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 6 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
« no previous file with comments | « chrome/browser/ui/views/avatar_menu_button.h ('k') | chrome/browser/ui/views/frame/browser_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/avatar_menu_button.cc
===================================================================
--- chrome/browser/ui/views/avatar_menu_button.cc (revision 88685)
+++ chrome/browser/ui/views/avatar_menu_button.cc (working copy)
@@ -1,71 +0,0 @@
-// Copyright (c) 2011 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/avatar_menu_button.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 image on the frame. This
-// offset size depends on whether the frame is in glass or opaque mode.
-const int kMenuDisplayOffset = 5;
-
-static inline int Round(double x) {
- return static_cast<int>(floor(x + 0.5));
-}
-
-AvatarMenuButton::AvatarMenuButton(const std::wstring& text,
- ui::MenuModel* menu_model)
- : MenuButton(NULL, text, this, false),
- menu_model_(menu_model) {
- // In RTL mode, the avatar icon should be looking the opposite direction.
- EnableCanvasFlippingForRTLUI(true);
-}
-
-AvatarMenuButton::~AvatarMenuButton() {}
-
-void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) {
- const SkBitmap& icon = GetImageToPaint();
- if (!icon.isNull()) {
- // Scale the image to fit the width of the button.
- int src_width = icon.width();
- int src_x = 0;
- int dst_width = std::min(src_width, width());
- int dst_x = Round((width() - dst_width) / 2.0);
-
- // Scale the height and maintain aspect ratio. This means that the
- // icon may not fit in the view. That's ok, we just center it vertically.
- float scale =
- static_cast<float>(dst_width) / static_cast<float>(icon.width());
- int scaled_height = Round(height() / scale);
- int src_height = std::min(scaled_height, icon.height());
- int src_y = Round((icon.height() - src_height) / 2.0);
- int dst_height = src_height * scale;
- int dst_y = Round((height() - dst_height) / 2.0);
-
- canvas->DrawBitmapInt(icon, src_x, src_y, src_width, src_height,
- dst_x, dst_y, dst_width, dst_height, false);
- }
-}
-
-gfx::Size AvatarMenuButton::GetPreferredAvatarSize() {
- return gfx::Size(38, 31);
-}
-
-// views::ViewMenuDelegate implementation
-void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
- if (!menu_model_.get())
- return;
-
- views::MenuModelAdapter menu_model_adapter(menu_model_.get());
- views::MenuItemView menu(&menu_model_adapter);
- menu_model_adapter.BuildMenu(&menu);
-
- gfx::Point menu_point(pt.x(), pt.y() + kMenuDisplayOffset);
- menu.RunMenuAt(source->GetWindow()->GetNativeWindow(), NULL,
- gfx::Rect(pt, gfx::Size(0, 0)),
- views::MenuItemView::TOPRIGHT,
- true);
-}
« no previous file with comments | « chrome/browser/ui/views/avatar_menu_button.h ('k') | chrome/browser/ui/views/frame/browser_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698