| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ash/system/tray/tray_views.h" | 5 #include "ash/system/tray/tray_views.h" |
| 6 | 6 |
| 7 #include "ash/system/tray/tray_constants.h" | 7 #include "ash/system/tray/tray_constants.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "grit/ash_strings.h" | 9 #include "grit/ash_strings.h" |
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 event.key_code() == ui::VKEY_RETURN) { | 59 event.key_code() == ui::VKEY_RETURN) { |
| 60 return PerformAction(event); | 60 return PerformAction(event); |
| 61 } | 61 } |
| 62 return false; | 62 return false; |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool ActionableView::OnMousePressed(const views::MouseEvent& event) { | 65 bool ActionableView::OnMousePressed(const views::MouseEvent& event) { |
| 66 return PerformAction(event); | 66 return PerformAction(event); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void ActionableView::SetAccessibleName(const string16& name) { |
| 70 accessible_name_ = name; |
| 71 } |
| 72 |
| 69 void ActionableView::OnPaintFocusBorder(gfx::Canvas* canvas) { | 73 void ActionableView::OnPaintFocusBorder(gfx::Canvas* canvas) { |
| 70 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) { | 74 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) { |
| 71 canvas->DrawRect(gfx::Rect(1, 1, width() - 3, height() - 3), | 75 canvas->DrawRect(gfx::Rect(1, 1, width() - 3, height() - 3), |
| 72 kFocusBorderColor); | 76 kFocusBorderColor); |
| 73 } | 77 } |
| 74 } | 78 } |
| 75 | 79 |
| 80 void ActionableView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 81 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 82 state->name = accessible_name_; |
| 83 } |
| 84 |
| 76 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
| 77 // HoverHighlightView | 86 // HoverHighlightView |
| 78 | 87 |
| 79 HoverHighlightView::HoverHighlightView(ViewClickListener* listener) | 88 HoverHighlightView::HoverHighlightView(ViewClickListener* listener) |
| 80 : listener_(listener), | 89 : listener_(listener), |
| 81 highlight_color_(kHoverBackgroundColor), | 90 highlight_color_(kHoverBackgroundColor), |
| 82 default_color_(0), | 91 default_color_(0), |
| 83 fixed_height_(0), | 92 fixed_height_(0), |
| 84 hover_(false) { | 93 hover_(false) { |
| 85 set_notify_enter_exit_on_child(true); | 94 set_notify_enter_exit_on_child(true); |
| 86 } | 95 } |
| 87 | 96 |
| 88 HoverHighlightView::~HoverHighlightView() { | 97 HoverHighlightView::~HoverHighlightView() { |
| 89 } | 98 } |
| 90 | 99 |
| 91 void HoverHighlightView::AddIconAndLabel(const SkBitmap& image, | 100 void HoverHighlightView::AddIconAndLabel(const SkBitmap& image, |
| 92 const string16& text, | 101 const string16& text, |
| 93 gfx::Font::FontStyle style) { | 102 gfx::Font::FontStyle style) { |
| 94 SetLayoutManager(new views::BoxLayout( | 103 SetLayoutManager(new views::BoxLayout( |
| 95 views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); | 104 views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); |
| 96 views::ImageView* image_view = | 105 views::ImageView* image_view = |
| 97 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); | 106 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); |
| 98 image_view->SetImage(image); | 107 image_view->SetImage(image); |
| 99 AddChildView(image_view); | 108 AddChildView(image_view); |
| 100 | 109 |
| 101 views::Label* label = new views::Label(text); | 110 views::Label* label = new views::Label(text); |
| 102 label->SetFont(label->font().DeriveFont(0, style)); | 111 label->SetFont(label->font().DeriveFont(0, style)); |
| 103 AddChildView(label); | 112 AddChildView(label); |
| 104 | 113 |
| 105 accessible_name_ = text; | 114 SetAccessibleName(text); |
| 106 } | 115 } |
| 107 | 116 |
| 108 void HoverHighlightView::AddLabel(const string16& text, | 117 void HoverHighlightView::AddLabel(const string16& text, |
| 109 gfx::Font::FontStyle style) { | 118 gfx::Font::FontStyle style) { |
| 110 SetLayoutManager(new views::FillLayout()); | 119 SetLayoutManager(new views::FillLayout()); |
| 111 views::Label* label = new views::Label(text); | 120 views::Label* label = new views::Label(text); |
| 112 label->set_border(views::Border::CreateEmptyBorder( | 121 label->set_border(views::Border::CreateEmptyBorder( |
| 113 5, kTrayPopupDetailsIconWidth + kIconPaddingLeft, 5, 0)); | 122 5, kTrayPopupDetailsIconWidth + kIconPaddingLeft, 5, 0)); |
| 114 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 123 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 115 label->SetFont(label->font().DeriveFont(0, style)); | 124 label->SetFont(label->font().DeriveFont(0, style)); |
| 116 label->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0)); | 125 label->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0)); |
| 117 AddChildView(label); | 126 AddChildView(label); |
| 118 | 127 |
| 119 accessible_name_ = text; | 128 SetAccessibleName(text); |
| 120 } | |
| 121 | |
| 122 void HoverHighlightView::SetAccessibleName(const string16& name) { | |
| 123 accessible_name_ = name; | |
| 124 } | 129 } |
| 125 | 130 |
| 126 bool HoverHighlightView::PerformAction(const views::Event& event) { | 131 bool HoverHighlightView::PerformAction(const views::Event& event) { |
| 127 if (!listener_) | 132 if (!listener_) |
| 128 return false; | 133 return false; |
| 129 listener_->ClickedOn(this); | 134 listener_->ClickedOn(this); |
| 130 return true; | 135 return true; |
| 131 } | 136 } |
| 132 | 137 |
| 133 gfx::Size HoverHighlightView::GetPreferredSize() { | 138 gfx::Size HoverHighlightView::GetPreferredSize() { |
| 134 gfx::Size size = ActionableView::GetPreferredSize(); | 139 gfx::Size size = ActionableView::GetPreferredSize(); |
| 135 if (fixed_height_) | 140 if (fixed_height_) |
| 136 size.set_height(fixed_height_); | 141 size.set_height(fixed_height_); |
| 137 return size; | 142 return size; |
| 138 } | 143 } |
| 139 | 144 |
| 140 void HoverHighlightView::OnMouseEntered(const views::MouseEvent& event) { | 145 void HoverHighlightView::OnMouseEntered(const views::MouseEvent& event) { |
| 141 hover_ = true; | 146 hover_ = true; |
| 142 SchedulePaint(); | 147 SchedulePaint(); |
| 143 } | 148 } |
| 144 | 149 |
| 145 void HoverHighlightView::OnMouseExited(const views::MouseEvent& event) { | 150 void HoverHighlightView::OnMouseExited(const views::MouseEvent& event) { |
| 146 hover_ = false; | 151 hover_ = false; |
| 147 SchedulePaint(); | 152 SchedulePaint(); |
| 148 } | 153 } |
| 149 | 154 |
| 150 void HoverHighlightView::GetAccessibleState(ui::AccessibleViewState* state) { | |
| 151 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | |
| 152 state->name = accessible_name_; | |
| 153 } | |
| 154 | |
| 155 void HoverHighlightView::OnEnabledChanged() { | 155 void HoverHighlightView::OnEnabledChanged() { |
| 156 for (int i = 0; i < child_count(); ++i) | 156 for (int i = 0; i < child_count(); ++i) |
| 157 child_at(i)->SetEnabled(enabled()); | 157 child_at(i)->SetEnabled(enabled()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { | 160 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { |
| 161 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); | 161 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); |
| 162 } | 162 } |
| 163 | 163 |
| 164 //////////////////////////////////////////////////////////////////////////////// | 164 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 label->SetAutoColorReadabilityEnabled(false); | 340 label->SetAutoColorReadabilityEnabled(false); |
| 341 label->SetEnabledColor(SK_ColorWHITE); | 341 label->SetEnabledColor(SK_ColorWHITE); |
| 342 label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); | 342 label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); |
| 343 label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), | 343 label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), |
| 344 SkColorSetARGB(64, 0, 0, 0)); | 344 SkColorSetARGB(64, 0, 0, 0)); |
| 345 label->SetShadowOffset(0, 1); | 345 label->SetShadowOffset(0, 1); |
| 346 } | 346 } |
| 347 | 347 |
| 348 } // namespace internal | 348 } // namespace internal |
| 349 } // namespace ash | 349 } // namespace ash |
| OLD | NEW |