Home | History | Annotate | Download | only in views
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/views/profile_menu_button.h"
      6 
      7 #include "ui/base/text/text_elider.h"
      8 #include "ui/gfx/color_utils.h"
      9 #include "views/controls/button/button.h"
     10 #include "views/controls/menu/view_menu_delegate.h"
     11 
     12 namespace {
     13 
     14 // ActiveTextShadow is a darkened version of hsl_active_shift.
     15 const SkColor kActiveTextShadow = 0xFF708DB3;
     16 // InactiveTextShadow is slightly darker than grey-white inactive background.
     17 const SkColor kInactiveTextShadow = SK_ColorLTGRAY;
     18 // TextHover is slightly darker than enabled color, for a subtle hover shift.
     19 const SkColor kTextHover = 0xFFDDDDDD;
     20 const SkColor kTextEnabled = SK_ColorWHITE;
     21 const SkColor kTextHighlighted = SK_ColorWHITE;
     22 
     23 // Horizontal padding beside profile menu button, to center it in the
     24 // underlying tag image.
     25 const int kProfileButtonBorderSpacing = 10;
     26 
     27 // Maximum width for name string in pixels.
     28 const int kMaxTextWidth = 200;
     29 }
     30 
     31 namespace views {
     32 
     33 ProfileMenuButton::ProfileMenuButton(ButtonListener* listener,
     34                                      const std::wstring& text,
     35                                      ViewMenuDelegate* menu_delegate) :
     36     MenuButton(listener, text, menu_delegate, true) {
     37   // Turn off hover highlighting and position button in the center of the
     38   // underlying profile tag image.
     39   set_border(views::Border::CreateEmptyBorder(
     40       0, kProfileButtonBorderSpacing, 0, kProfileButtonBorderSpacing));
     41   SetTextShadowColors(kActiveTextShadow, kInactiveTextShadow);
     42   SetHoverColor(kTextHover);
     43   SetEnabledColor(kTextEnabled);
     44   SetHighlightColor(kTextHighlighted);
     45 }
     46 
     47 ProfileMenuButton::~ProfileMenuButton() {}
     48 
     49 void ProfileMenuButton::SetText(const std::wstring& text) {
     50   MenuButton::SetText(ui::ElideText(text, font(), kMaxTextWidth, false));
     51 }
     52 
     53 }  // namespace views
     54 
     55