| OLD | NEW |
| (Empty) |
| 1 // Copyright 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/common/system/tray/actionable_view.h" | |
| 6 | |
| 7 #include "ash/common/ash_constants.h" | |
| 8 #include "ash/common/system/tray/system_tray.h" | |
| 9 #include "ash/common/system/tray/system_tray_item.h" | |
| 10 #include "ash/common/system/tray/tray_constants.h" | |
| 11 #include "ash/common/system/tray/tray_popup_utils.h" | |
| 12 #include "ui/accessibility/ax_node_data.h" | |
| 13 #include "ui/events/keycodes/keyboard_codes.h" | |
| 14 #include "ui/gfx/canvas.h" | |
| 15 #include "ui/gfx/geometry/rect_f.h" | |
| 16 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | |
| 17 #include "ui/views/animation/ink_drop_highlight.h" | |
| 18 #include "ui/views/animation/ink_drop_impl.h" | |
| 19 #include "ui/views/animation/ink_drop_mask.h" | |
| 20 | |
| 21 namespace ash { | |
| 22 | |
| 23 // static | |
| 24 const char ActionableView::kViewClassName[] = "tray/ActionableView"; | |
| 25 | |
| 26 ActionableView::ActionableView(SystemTrayItem* owner, | |
| 27 TrayPopupInkDropStyle ink_drop_style) | |
| 28 : views::CustomButton(this), | |
| 29 destroyed_(nullptr), | |
| 30 owner_(owner), | |
| 31 ink_drop_style_(ink_drop_style) { | |
| 32 SetFocusBehavior(FocusBehavior::ALWAYS); | |
| 33 set_ink_drop_base_color(kTrayPopupInkDropBaseColor); | |
| 34 set_ink_drop_visible_opacity(kTrayPopupInkDropRippleOpacity); | |
| 35 set_has_ink_drop_action_on_click(false); | |
| 36 set_notify_enter_exit_on_child(true); | |
| 37 } | |
| 38 | |
| 39 ActionableView::~ActionableView() { | |
| 40 if (destroyed_) | |
| 41 *destroyed_ = true; | |
| 42 } | |
| 43 | |
| 44 void ActionableView::OnPaintFocus(gfx::Canvas* canvas) { | |
| 45 gfx::RectF rect(GetLocalBounds()); | |
| 46 canvas->DrawSolidFocusRect(rect, kFocusBorderColor, kFocusBorderThickness); | |
| 47 } | |
| 48 | |
| 49 void ActionableView::HandlePerformActionResult(bool action_performed, | |
| 50 const ui::Event& event) { | |
| 51 AnimateInkDrop(action_performed ? views::InkDropState::ACTION_TRIGGERED | |
| 52 : views::InkDropState::HIDDEN, | |
| 53 ui::LocatedEvent::FromIfValid(&event)); | |
| 54 } | |
| 55 | |
| 56 const char* ActionableView::GetClassName() const { | |
| 57 return kViewClassName; | |
| 58 } | |
| 59 | |
| 60 bool ActionableView::OnKeyPressed(const ui::KeyEvent& event) { | |
| 61 if (state() != STATE_DISABLED && event.key_code() == ui::VKEY_SPACE) { | |
| 62 NotifyClick(event); | |
| 63 return true; | |
| 64 } | |
| 65 return CustomButton::OnKeyPressed(event); | |
| 66 } | |
| 67 | |
| 68 void ActionableView::SetAccessibleName(const base::string16& name) { | |
| 69 accessible_name_ = name; | |
| 70 } | |
| 71 | |
| 72 void ActionableView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | |
| 73 node_data->role = ui::AX_ROLE_BUTTON; | |
| 74 node_data->SetName(accessible_name_); | |
| 75 } | |
| 76 | |
| 77 void ActionableView::OnPaint(gfx::Canvas* canvas) { | |
| 78 CustomButton::OnPaint(canvas); | |
| 79 if (HasFocus()) | |
| 80 OnPaintFocus(canvas); | |
| 81 } | |
| 82 | |
| 83 void ActionableView::OnFocus() { | |
| 84 CustomButton::OnFocus(); | |
| 85 // We render differently when focused. | |
| 86 SchedulePaint(); | |
| 87 } | |
| 88 | |
| 89 void ActionableView::OnBlur() { | |
| 90 CustomButton::OnBlur(); | |
| 91 // We render differently when focused. | |
| 92 SchedulePaint(); | |
| 93 } | |
| 94 | |
| 95 std::unique_ptr<views::InkDrop> ActionableView::CreateInkDrop() { | |
| 96 return TrayPopupUtils::CreateInkDrop(ink_drop_style_, this); | |
| 97 } | |
| 98 | |
| 99 std::unique_ptr<views::InkDropRipple> ActionableView::CreateInkDropRipple() | |
| 100 const { | |
| 101 return TrayPopupUtils::CreateInkDropRipple( | |
| 102 ink_drop_style_, this, GetInkDropCenterBasedOnLastEvent()); | |
| 103 } | |
| 104 | |
| 105 std::unique_ptr<views::InkDropHighlight> | |
| 106 ActionableView::CreateInkDropHighlight() const { | |
| 107 return TrayPopupUtils::CreateInkDropHighlight(ink_drop_style_, this); | |
| 108 } | |
| 109 | |
| 110 std::unique_ptr<views::InkDropMask> ActionableView::CreateInkDropMask() const { | |
| 111 return TrayPopupUtils::CreateInkDropMask(ink_drop_style_, this); | |
| 112 } | |
| 113 | |
| 114 void ActionableView::CloseSystemBubble() { | |
| 115 DCHECK(owner_); | |
| 116 owner_->system_tray()->CloseSystemBubble(); | |
| 117 } | |
| 118 | |
| 119 void ActionableView::ButtonPressed(Button* sender, const ui::Event& event) { | |
| 120 bool destroyed = false; | |
| 121 destroyed_ = &destroyed; | |
| 122 const bool action_performed = PerformAction(event); | |
| 123 if (destroyed) | |
| 124 return; | |
| 125 destroyed_ = nullptr; | |
| 126 | |
| 127 HandlePerformActionResult(action_performed, event); | |
| 128 } | |
| 129 | |
| 130 ButtonListenerActionableView::ButtonListenerActionableView( | |
| 131 SystemTrayItem* owner, | |
| 132 TrayPopupInkDropStyle ink_drop_style, | |
| 133 views::ButtonListener* listener) | |
| 134 : ActionableView(owner, ink_drop_style), listener_(listener) {} | |
| 135 | |
| 136 bool ButtonListenerActionableView::PerformAction(const ui::Event& event) { | |
| 137 listener_->ButtonPressed(this, event); | |
| 138 return true; | |
| 139 } | |
| 140 | |
| 141 } // namespace ash | |
| OLD | NEW |