Home | History | Annotate | Download | only in tray
      1 // Copyright (c) 2012 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 "ash/system/tray/tray_utils.h"
      6 
      7 #include "ash/system/tray/tray_constants.h"
      8 #include "ash/system/tray/tray_item_view.h"
      9 #include "ui/gfx/font_list.h"
     10 #include "ui/views/border.h"
     11 #include "ui/views/controls/label.h"
     12 
     13 namespace ash {
     14 
     15 void SetupLabelForTray(views::Label* label) {
     16   label->SetFontList(gfx::FontList().Derive(1, gfx::Font::BOLD));
     17   label->SetAutoColorReadabilityEnabled(false);
     18   label->SetEnabledColor(SK_ColorWHITE);
     19   label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
     20   label->set_shadows(gfx::ShadowValues(1,
     21       gfx::ShadowValue(gfx::Point(0, 1), 0, SkColorSetARGB(64, 0, 0, 0))));
     22 }
     23 
     24 void SetTrayImageItemBorder(views::View* tray_view,
     25                             ShelfAlignment alignment) {
     26   if (alignment == SHELF_ALIGNMENT_BOTTOM ||
     27       alignment == SHELF_ALIGNMENT_TOP) {
     28     tray_view->SetBorder(views::Border::CreateEmptyBorder(
     29         0,
     30         kTrayImageItemHorizontalPaddingBottomAlignment,
     31         0,
     32         kTrayImageItemHorizontalPaddingBottomAlignment));
     33   } else {
     34     tray_view->SetBorder(views::Border::CreateEmptyBorder(
     35         kTrayImageItemVerticalPaddingVerticalAlignment,
     36         kTrayImageItemHorizontalPaddingVerticalAlignment,
     37         kTrayImageItemVerticalPaddingVerticalAlignment,
     38         kTrayImageItemHorizontalPaddingVerticalAlignment));
     39   }
     40 }
     41 
     42 void SetTrayLabelItemBorder(TrayItemView* tray_view,
     43                             ShelfAlignment alignment) {
     44   if (alignment == SHELF_ALIGNMENT_BOTTOM ||
     45       alignment == SHELF_ALIGNMENT_TOP) {
     46     tray_view->SetBorder(views::Border::CreateEmptyBorder(
     47         0,
     48         kTrayLabelItemHorizontalPaddingBottomAlignment,
     49         0,
     50         kTrayLabelItemHorizontalPaddingBottomAlignment));
     51   } else {
     52     // Center the label for vertical launcher alignment.
     53     int horizontal_padding = std::max(0,
     54         (tray_view->GetPreferredSize().width() -
     55         tray_view->label()->GetPreferredSize().width()) / 2);
     56     tray_view->SetBorder(views::Border::CreateEmptyBorder(
     57         kTrayLabelItemVerticalPaddingVerticalAlignment,
     58         horizontal_padding,
     59         kTrayLabelItemVerticalPaddingVerticalAlignment,
     60         horizontal_padding));
     61   }
     62 }
     63 
     64 }  // namespace ash
     65