OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/new_avatar_button.h" | |
6 | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "chrome/browser/profiles/profile_metrics.h" | |
9 #include "chrome/browser/themes/theme_properties.h" | |
10 #include "chrome/browser/ui/views/frame/browser_view.h" | |
11 #include "chrome/browser/ui/views/profile_chooser_view.h" | |
12 #include "grit/generated_resources.h" | |
13 #include "grit/theme_resources.h" | |
14 #include "ui/base/l10n/l10n_util.h" | |
15 #include "ui/base/resource/resource_bundle.h" | |
16 #include "ui/base/theme_provider.h" | |
17 #include "ui/gfx/canvas.h" | |
18 #include "ui/gfx/color_utils.h" | |
19 #include "ui/views/border.h" | |
20 #include "ui/views/painter.h" | |
21 | |
22 namespace { | |
23 | |
24 const int kInset = 10; | |
sky
2013/10/03 23:23:11
Description?
noms (inactive)
2013/10/07 21:18:15
Done.
| |
25 | |
26 | |
27 // AvatarGlassButtonBorder ---------------------------------------------------- | |
28 class AvatarGlassButtonBorder : public views::TextButtonDefaultBorder { | |
29 public: | |
30 AvatarGlassButtonBorder() { | |
31 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); | |
32 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER); | |
33 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); | |
34 | |
35 SetInsets(gfx::Insets(kInset, kInset, kInset, kInset)); | |
36 set_normal_painter(views::Painter::CreateImageGridPainter(kNormalImageSet)); | |
37 set_hot_painter(views::Painter::CreateImageGridPainter(kHotImageSet)); | |
38 set_pushed_painter(views::Painter::CreateImageGridPainter(kPushedImageSet)); | |
39 }; | |
40 | |
41 private: | |
42 virtual ~AvatarGlassButtonBorder() { | |
43 }; | |
44 | |
45 DISALLOW_COPY_AND_ASSIGN(AvatarGlassButtonBorder); | |
46 }; | |
47 | |
48 | |
49 // AvatarThemedButtonBorder --------------------------------------------------- | |
50 | |
51 class AvatarThemedButtonBorder : public views::TextButtonDefaultBorder { | |
52 public: | |
53 AvatarThemedButtonBorder() { | |
54 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); | |
55 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); | |
56 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); | |
57 | |
58 SetInsets(gfx::Insets(kInset, kInset, kInset, kInset)); | |
59 set_normal_painter(views::Painter::CreateImageGridPainter(kNormalImageSet)); | |
60 set_hot_painter(views::Painter::CreateImageGridPainter(kHotImageSet)); | |
61 set_pushed_painter(views::Painter::CreateImageGridPainter(kPushedImageSet)); | |
62 }; | |
63 | |
64 private: | |
65 virtual ~AvatarThemedButtonBorder() { | |
66 }; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(AvatarThemedButtonBorder); | |
69 }; | |
70 | |
71 } // namespace | |
72 | |
73 | |
74 // NewAvatarButton ------------------------------------------------------------ | |
75 NewAvatarButton::NewAvatarButton( | |
76 BrowserView* browser_view, | |
77 const string16& profile_name) | |
78 : MenuButton(NULL, string16(), NULL, true), | |
79 browser_view_(browser_view) { | |
80 SetText(profile_name); | |
81 set_animate_on_state_change(false); | |
82 | |
83 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | |
84 SetFont(rb->GetFont(ui::ResourceBundle::BaseFont)); | |
85 | |
86 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.
| |
87 set_border(new AvatarGlassButtonBorder); | |
88 set_menu_marker( | |
89 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia()); | |
90 } else { | |
91 set_border(new AvatarThemedButtonBorder); | |
92 set_menu_marker( | |
93 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); | |
94 } | |
95 SchedulePaint(); | |
96 } | |
97 | |
98 NewAvatarButton::~NewAvatarButton() { | |
99 } | |
100 | |
101 void NewAvatarButton::OnPaint(gfx::Canvas* canvas) { | |
102 // From TextButton::PaintButton, draw everything but the text. | |
103 OnPaintBackground(canvas); | |
104 OnPaintBorder(canvas); | |
105 OnPaintFocusBorder(canvas); | |
106 | |
107 gfx::Rect rect; | |
108 // In RTL languages the marker gets drawn leftmost, so account for its offset. | |
109 if (base::i18n::IsRTL()) | |
110 rect = gfx::Rect(-kInset, 0, size().width(), size().height()); | |
111 else | |
112 rect = gfx::Rect(kInset, 0, size().width(), size().height()); | |
113 // TODO(noms): This should be DrawStringRectWithHalo but that function | |
114 // has a bug at the moment and incorrectly draws the background. | |
115 canvas->DrawStringRectWithFlags( | |
116 text(), | |
117 gfx::FontList(ui::ResourceBundle::GetSharedInstance().GetFont( | |
118 ui::ResourceBundle::BaseFont)), | |
119 SK_ColorBLACK, | |
120 rect, | |
121 gfx::Canvas::NO_SUBPIXEL_RENDERING); | |
122 | |
123 // From MenuButton::PaintButton, paint the marker | |
124 PaintMenuMarker(canvas); | |
125 } | |
126 | |
127 bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) { | |
128 if (!TextButton::OnMousePressed(event)) | |
129 return false; | |
130 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.
| |
131 return true; | |
132 } | |
133 | |
134 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
| |
135 gfx::Point origin; | |
136 views::View::ConvertPointToScreen(this, &origin); | |
137 gfx::Rect bounds(origin, size()); | |
138 | |
139 ProfileChooserView::ShowBubble( | |
140 this, views::BubbleBorder::TOP_RIGHT, | |
141 views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE, bounds, | |
142 browser_view_->browser()); | |
143 | |
144 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); | |
145 } | |
OLD | NEW |