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

Side by Side Diff: chrome/browser/ui/views/avatar_menu_button.cc

Issue 7331017: Multi-Profiles: Add icon chooser to profiles menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove debug code Created 9 years, 5 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 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/ui/views/avatar_menu_button.h" 5 #include "chrome/browser/ui/views/avatar_menu_button.h"
6 6
7 #include "chrome/browser/ui/views/avatar_menu.h"
7 #include "ui/gfx/canvas_skia.h" 8 #include "ui/gfx/canvas_skia.h"
8 #include "views/controls/menu/menu_model_adapter.h" 9 #include "views/controls/menu/menu_model_adapter.h"
9 #include "views/widget/widget.h" 10 #include "views/widget/widget.h"
10 11
11 // Menu should display below the image on the frame. This
12 // offset size depends on whether the frame is in glass or opaque mode.
13 const int kMenuDisplayOffset = 5;
14
15 static inline int Round(double x) { 12 static inline int Round(double x) {
16 return static_cast<int>(x + 0.5); 13 return static_cast<int>(x + 0.5);
17 } 14 }
18 15
19 AvatarMenuButton::AvatarMenuButton(const std::wstring& text, 16 AvatarMenuButton::AvatarMenuButton(const std::wstring& text,
20 ui::MenuModel* menu_model) 17 ui::MenuModel* menu_model,
18 Browser* browser)
21 : MenuButton(NULL, text, this, false), 19 : MenuButton(NULL, text, this, false),
20 browser_(browser),
22 menu_model_(menu_model) { 21 menu_model_(menu_model) {
23 // In RTL mode, the avatar icon should be looking the opposite direction. 22 // In RTL mode, the avatar icon should be looking the opposite direction.
24 EnableCanvasFlippingForRTLUI(true); 23 EnableCanvasFlippingForRTLUI(true);
25 } 24 }
26 25
27 AvatarMenuButton::~AvatarMenuButton() {} 26 AvatarMenuButton::~AvatarMenuButton() {}
28 27
29 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { 28 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) {
30 const SkBitmap& icon = GetImageToPaint(); 29 const SkBitmap& icon = GetImageToPaint();
31 if (icon.isNull()) 30 if (icon.isNull())
(...skipping 19 matching lines...) Expand all
51 50
52 canvas->DrawBitmapInt(icon, 0, 0, icon.width(), icon.height(), 51 canvas->DrawBitmapInt(icon, 0, 0, icon.width(), icon.height(),
53 dst_x, dst_y, dst_width, dst_height, false); 52 dst_x, dst_y, dst_width, dst_height, false);
54 } 53 }
55 54
56 // views::ViewMenuDelegate implementation 55 // views::ViewMenuDelegate implementation
57 void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { 56 void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
58 if (!menu_model_.get()) 57 if (!menu_model_.get())
59 return; 58 return;
60 59
61 views::MenuModelAdapter menu_model_adapter(menu_model_.get()); 60 AvatarMenu* avatar_menu = new AvatarMenu(browser_);
62 views::MenuItemView menu(&menu_model_adapter); 61 avatar_menu->Init(menu_model_.get());
63 menu_model_adapter.BuildMenu(&menu); 62 avatar_menu->RunMenu(this);
sky 2011/07/08 21:01:44 Add a comment that AvatarMenu deletes itself.
sail 2011/07/08 21:53:57 Done.
64
65 gfx::Point menu_point(pt.x(), pt.y() + kMenuDisplayOffset);
66 menu.RunMenuAt(source->GetWidget()->GetNativeWindow(), NULL,
67 gfx::Rect(pt, gfx::Size(0, 0)),
68 views::MenuItemView::TOPRIGHT,
69 true);
70 } 63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698