| 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" | 7 #include "chrome/browser/profiles/profile_manager.h" |
| 8 #include "chrome/browser/ui/profile_menu_model.h" | 8 #include "chrome/browser/ui/profile_menu_model.h" |
| 9 #include "ui/base/text/text_elider.h" | 9 #include "ui/base/text/text_elider.h" |
| 10 #include "ui/gfx/color_utils.h" | 10 #include "ui/gfx/color_utils.h" |
| 11 #include "views/controls/button/button.h" | 11 #include "views/controls/button/button.h" |
| 12 #include "views/controls/menu/menu_2.h" | 12 #include "views/controls/menu/menu_2.h" |
| 13 #include "views/controls/menu/view_menu_delegate.h" | |
| 14 | 13 |
| 15 // Menu should display below the profile button tag image on the frame. This | 14 // Menu should display below the profile button tag image on the frame. This |
| 16 // offset size depends on whether the frame is in glass or opaque mode. | 15 // offset size depends on whether the frame is in glass or opaque mode. |
| 17 const int kMenuDisplayOffset = 7; | 16 const int kMenuDisplayOffset = 7; |
| 18 | 17 |
| 19 // TextHover is slightly darker than enabled color, for a subtle hover shift. | 18 // TextHover is slightly darker than enabled color, for a subtle hover shift. |
| 20 const SkColor kTextHover = 0xFFDDDDDD; | 19 const SkColor kTextHover = 0xFFDDDDDD; |
| 21 const SkColor kTextEnabled = SK_ColorWHITE; | 20 const SkColor kTextEnabled = SK_ColorWHITE; |
| 22 const SkColor kTextHighlighted = SK_ColorWHITE; | 21 const SkColor kTextHighlighted = SK_ColorWHITE; |
| 23 | 22 |
| 24 // Horizontal padding beside profile menu button, to center it in the | 23 // Horizontal padding beside profile menu button, to center it in the |
| 25 // underlying tag image. | 24 // underlying tag image. |
| 26 const int kProfileButtonBorderSpacing = 10; | 25 const int kProfileButtonBorderSpacing = 10; |
| 27 | 26 |
| 28 // Maximum width for name string in pixels. | 27 // Maximum width for name string in pixels. |
| 29 const int kMaxTextWidth = 200; | 28 const int kMaxTextWidth = 200; |
| 30 | 29 |
| 31 ProfileMenuButton::ProfileMenuButton(views::ButtonListener* listener, | 30 ProfileMenuButton::ProfileMenuButton(const std::wstring& text, Profile* profile) |
| 32 const std::wstring& text, | 31 : MenuButton(NULL, text, this, true) { |
| 33 views::ViewMenuDelegate* menu_delegate, | |
| 34 Profile* profile) | |
| 35 : MenuButton(listener, text, menu_delegate, true) { | |
| 36 // Turn off hover highlighting and position button in the center of the | 32 // Turn off hover highlighting and position button in the center of the |
| 37 // underlying profile tag image. | 33 // underlying profile tag image. |
| 38 set_border(views::Border::CreateEmptyBorder( | 34 set_border(views::Border::CreateEmptyBorder( |
| 39 0, kProfileButtonBorderSpacing, 0, kProfileButtonBorderSpacing)); | 35 0, kProfileButtonBorderSpacing, 0, kProfileButtonBorderSpacing)); |
| 40 SetHoverColor(kTextHover); | 36 SetHoverColor(kTextHover); |
| 41 SetEnabledColor(kTextEnabled); | 37 SetEnabledColor(kTextEnabled); |
| 42 SetHighlightColor(kTextHighlighted); | 38 SetHighlightColor(kTextHighlighted); |
| 43 | 39 |
| 44 profile_menu_model_.reset(new ProfileMenuModel(this)); | 40 profile_menu_model_.reset(new ProfileMenuModel(this)); |
| 45 menu_.reset(new views::Menu2(profile_menu_model_.get())); | 41 menu_.reset(new views::Menu2(profile_menu_model_.get())); |
| 46 } | 42 } |
| 47 | 43 |
| 48 ProfileMenuButton::~ProfileMenuButton() {} | 44 ProfileMenuButton::~ProfileMenuButton() {} |
| 49 | 45 |
| 50 void ProfileMenuButton::SetText(const std::wstring& text) { | 46 void ProfileMenuButton::SetText(const std::wstring& text) { |
| 51 MenuButton::SetText(UTF16ToWideHack(ui::ElideText(WideToUTF16Hack(text), | 47 MenuButton::SetText(UTF16ToWideHack(ui::ElideText(WideToUTF16Hack(text), |
| 52 font(), kMaxTextWidth, false))); | 48 font(), kMaxTextWidth, false))); |
| 53 } | 49 } |
| 54 | 50 |
| 55 void ProfileMenuButton::RunMenuAt(const gfx::Point& pt) { | |
| 56 gfx::Point menu_point(pt.x(), | |
| 57 pt.y() + kMenuDisplayOffset); | |
| 58 menu_->RunMenuAt(menu_point, views::Menu2::ALIGN_TOPRIGHT); | |
| 59 } | |
| 60 | |
| 61 // ui::SimpleMenuModel::Delegate implementation | 51 // ui::SimpleMenuModel::Delegate implementation |
| 62 bool ProfileMenuButton::IsCommandIdChecked(int command_id) const { | 52 bool ProfileMenuButton::IsCommandIdChecked(int command_id) const { |
| 63 return false; | 53 return false; |
| 64 } | 54 } |
| 65 | 55 |
| 66 bool ProfileMenuButton::IsCommandIdEnabled(int command_id) const { | 56 bool ProfileMenuButton::IsCommandIdEnabled(int command_id) const { |
| 67 return true; | 57 return true; |
| 68 } | 58 } |
| 69 | 59 |
| 70 bool ProfileMenuButton::GetAcceleratorForCommandId(int command_id, | 60 bool ProfileMenuButton::GetAcceleratorForCommandId(int command_id, |
| 71 ui::Accelerator* accelerator) { | 61 ui::Accelerator* accelerator) { |
| 72 return false; | 62 return false; |
| 73 } | 63 } |
| 74 | 64 |
| 75 void ProfileMenuButton::ExecuteCommand(int command_id) { | 65 void ProfileMenuButton::ExecuteCommand(int command_id) { |
| 76 switch (command_id) { | 66 switch (command_id) { |
| 77 case ProfileMenuModel::COMMAND_CREATE_NEW_PROFILE: | 67 case ProfileMenuModel::COMMAND_CREATE_NEW_PROFILE: |
| 78 ProfileManager::CreateMultiProfileAsync(); | 68 ProfileManager::CreateMultiProfileAsync(); |
| 79 break; | 69 break; |
| 80 default: | 70 default: |
| 81 NOTREACHED(); | 71 NOTREACHED(); |
| 82 break; | 72 break; |
| 83 } | 73 } |
| 84 } | 74 } |
| 75 |
| 76 // views::ViewMenuDelegate implementation |
| 77 void ProfileMenuButton::RunMenu(views::View* source, const gfx::Point &pt) { |
| 78 gfx::Point menu_point(pt.x(), pt.y() + kMenuDisplayOffset); |
| 79 menu_->RunMenuAt(menu_point, views::Menu2::ALIGN_TOPRIGHT); |
| 80 } |
| OLD | NEW |