OLD | NEW |
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/profile_menu_button.h" | 5 #include "chrome/browser/ui/views/profile_menu_button.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile_manager.h" | |
8 #include "chrome/browser/ui/profile_menu_model.h" | 7 #include "chrome/browser/ui/profile_menu_model.h" |
9 #include "ui/base/text/text_elider.h" | 8 #include "ui/base/text/text_elider.h" |
10 #include "ui/gfx/color_utils.h" | 9 #include "ui/gfx/color_utils.h" |
11 #include "views/controls/button/button.h" | 10 #include "views/controls/button/button.h" |
12 #include "views/controls/menu/menu_2.h" | 11 #include "views/controls/menu/menu_2.h" |
13 | 12 |
14 // Menu should display below the profile button tag image on the frame. This | 13 // Menu should display below the profile button tag image on the frame. This |
15 // offset size depends on whether the frame is in glass or opaque mode. | 14 // offset size depends on whether the frame is in glass or opaque mode. |
16 const int kMenuDisplayOffset = 7; | 15 const int kMenuDisplayOffset = 7; |
17 | 16 |
(...skipping 12 matching lines...) Expand all Loading... |
30 ProfileMenuButton::ProfileMenuButton(const std::wstring& text, Profile* profile) | 29 ProfileMenuButton::ProfileMenuButton(const std::wstring& text, Profile* profile) |
31 : MenuButton(NULL, text, this, true) { | 30 : MenuButton(NULL, text, this, true) { |
32 // Turn off hover highlighting and position button in the center of the | 31 // Turn off hover highlighting and position button in the center of the |
33 // underlying profile tag image. | 32 // underlying profile tag image. |
34 set_border(views::Border::CreateEmptyBorder( | 33 set_border(views::Border::CreateEmptyBorder( |
35 0, kProfileButtonBorderSpacing, 0, kProfileButtonBorderSpacing)); | 34 0, kProfileButtonBorderSpacing, 0, kProfileButtonBorderSpacing)); |
36 SetHoverColor(kTextHover); | 35 SetHoverColor(kTextHover); |
37 SetEnabledColor(kTextEnabled); | 36 SetEnabledColor(kTextEnabled); |
38 SetHighlightColor(kTextHighlighted); | 37 SetHighlightColor(kTextHighlighted); |
39 | 38 |
40 profile_menu_model_.reset(new ProfileMenuModel(this)); | 39 profile_menu_model_.reset(new ProfileMenuModel); |
41 menu_.reset(new views::Menu2(profile_menu_model_.get())); | 40 menu_.reset(new views::Menu2(profile_menu_model_.get())); |
42 } | 41 } |
43 | 42 |
44 ProfileMenuButton::~ProfileMenuButton() {} | 43 ProfileMenuButton::~ProfileMenuButton() {} |
45 | 44 |
46 void ProfileMenuButton::SetText(const std::wstring& text) { | 45 void ProfileMenuButton::SetText(const std::wstring& text) { |
47 MenuButton::SetText(UTF16ToWideHack(ui::ElideText(WideToUTF16Hack(text), | 46 MenuButton::SetText(UTF16ToWideHack(ui::ElideText(WideToUTF16Hack(text), |
48 font(), kMaxTextWidth, false))); | 47 font(), kMaxTextWidth, false))); |
49 } | 48 } |
50 | 49 |
51 // ui::SimpleMenuModel::Delegate implementation | |
52 bool ProfileMenuButton::IsCommandIdChecked(int command_id) const { | |
53 return false; | |
54 } | |
55 | |
56 bool ProfileMenuButton::IsCommandIdEnabled(int command_id) const { | |
57 return true; | |
58 } | |
59 | |
60 bool ProfileMenuButton::GetAcceleratorForCommandId(int command_id, | |
61 ui::Accelerator* accelerator) { | |
62 return false; | |
63 } | |
64 | |
65 void ProfileMenuButton::ExecuteCommand(int command_id) { | |
66 switch (command_id) { | |
67 case ProfileMenuModel::COMMAND_CREATE_NEW_PROFILE: | |
68 ProfileManager::CreateMultiProfileAsync(); | |
69 break; | |
70 default: | |
71 NOTREACHED(); | |
72 break; | |
73 } | |
74 } | |
75 | |
76 // views::ViewMenuDelegate implementation | 50 // views::ViewMenuDelegate implementation |
77 void ProfileMenuButton::RunMenu(views::View* source, const gfx::Point &pt) { | 51 void ProfileMenuButton::RunMenu(views::View* source, const gfx::Point &pt) { |
78 gfx::Point menu_point(pt.x(), pt.y() + kMenuDisplayOffset); | 52 gfx::Point menu_point(pt.x(), pt.y() + kMenuDisplayOffset); |
79 menu_->RunMenuAt(menu_point, views::Menu2::ALIGN_TOPRIGHT); | 53 menu_->RunMenuAt(menu_point, views::Menu2::ALIGN_TOPRIGHT); |
80 } | 54 } |
OLD | NEW |