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.h" 10 #include "ui/views/border.h" 11 #include "ui/views/controls/label.h" 12 13 namespace ash { 14 namespace internal { 15 16 void SetupLabelForTray(views::Label* label) { 17 // Making label_font static to avoid the time penalty of DeriveFont for 18 // all but the first call. 19 static const gfx::Font label_font(gfx::Font().DeriveFont(1, gfx::Font::BOLD)); 20 label->SetFont(label_font); 21 label->SetAutoColorReadabilityEnabled(false); 22 label->SetEnabledColor(SK_ColorWHITE); 23 label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); 24 label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), 25 SkColorSetARGB(64, 0, 0, 0)); 26 label->SetShadowOffset(0, 1); 27 } 28 29 void SetTrayImageItemBorder(views::View* tray_view, 30 ShelfAlignment alignment) { 31 if (alignment == SHELF_ALIGNMENT_BOTTOM || 32 alignment == SHELF_ALIGNMENT_TOP) { 33 tray_view->set_border(views::Border::CreateEmptyBorder( 34 0, kTrayImageItemHorizontalPaddingBottomAlignment, 35 0, kTrayImageItemHorizontalPaddingBottomAlignment)); 36 } else { 37 tray_view->set_border(views::Border::CreateEmptyBorder( 38 kTrayImageItemVerticalPaddingVerticalAlignment, 39 kTrayImageItemHorizontalPaddingVerticalAlignment, 40 kTrayImageItemVerticalPaddingVerticalAlignment, 41 kTrayImageItemHorizontalPaddingVerticalAlignment)); 42 } 43 } 44 45 void SetTrayLabelItemBorder(TrayItemView* tray_view, 46 ShelfAlignment alignment) { 47 if (alignment == SHELF_ALIGNMENT_BOTTOM || 48 alignment == SHELF_ALIGNMENT_TOP) { 49 tray_view->set_border(views::Border::CreateEmptyBorder( 50 0, kTrayLabelItemHorizontalPaddingBottomAlignment, 51 0, kTrayLabelItemHorizontalPaddingBottomAlignment)); 52 } else { 53 // Center the label for vertical launcher alignment. 54 int horizontal_padding = std::max(0, 55 (tray_view->GetPreferredSize().width() - 56 tray_view->label()->GetPreferredSize().width()) / 2); 57 tray_view->set_border(views::Border::CreateEmptyBorder( 58 kTrayLabelItemVerticalPaddingVerticalAlignment, 59 horizontal_padding, 60 kTrayLabelItemVerticalPaddingVerticalAlignment, 61 horizontal_padding)); 62 } 63 } 64 65 } // namespace internal 66 } // namespace ash 67