OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/user/button_from_view.h" |
| 6 |
| 7 #include "ash/system/tray/tray_constants.h" |
| 8 #include "ui/views/background.h" |
| 9 #include "ui/views/border.h" |
| 10 #include "ui/views/layout/box_layout.h" |
| 11 |
| 12 namespace ash { |
| 13 |
| 14 namespace { |
| 15 |
| 16 // The border color of the user button. |
| 17 const SkColor kBorderColor = 0xffdcdcdc; |
| 18 |
| 19 } // namespace |
| 20 |
| 21 namespace tray { |
| 22 |
| 23 ButtonFromView::ButtonFromView(views::View* content, |
| 24 views::ButtonListener* listener, |
| 25 bool highlight_on_hover) |
| 26 : CustomButton(listener), |
| 27 content_(content), |
| 28 highlight_on_hover_(highlight_on_hover), |
| 29 button_hovered_(false), |
| 30 show_border_(false) { |
| 31 set_notify_enter_exit_on_child(true); |
| 32 SetLayoutManager( |
| 33 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 34 AddChildView(content_); |
| 35 ShowActive(); |
| 36 } |
| 37 |
| 38 ButtonFromView::~ButtonFromView() {} |
| 39 |
| 40 void ButtonFromView::ForceBorderVisible(bool show) { |
| 41 show_border_ = show; |
| 42 ShowActive(); |
| 43 } |
| 44 |
| 45 void ButtonFromView::OnMouseEntered(const ui::MouseEvent& event) { |
| 46 button_hovered_ = true; |
| 47 ShowActive(); |
| 48 } |
| 49 |
| 50 void ButtonFromView::OnMouseExited(const ui::MouseEvent& event) { |
| 51 button_hovered_ = false; |
| 52 ShowActive(); |
| 53 } |
| 54 |
| 55 void ButtonFromView::ShowActive() { |
| 56 bool border_visible = |
| 57 (button_hovered_ && highlight_on_hover_) || show_border_; |
| 58 SkColor border_color = border_visible ? kBorderColor : SK_ColorTRANSPARENT; |
| 59 SetBorder(views::Border::CreateSolidBorder(1, border_color)); |
| 60 if (highlight_on_hover_) { |
| 61 SkColor background_color = |
| 62 button_hovered_ ? kHoverBackgroundColor : kBackgroundColor; |
| 63 content_->set_background( |
| 64 views::Background::CreateSolidBackground(background_color)); |
| 65 set_background(views::Background::CreateSolidBackground(background_color)); |
| 66 } |
| 67 SchedulePaint(); |
| 68 } |
| 69 |
| 70 } // namespace tray |
| 71 } // namespace ash |
OLD | NEW |