| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/common/system/tray/actionable_view.h" | 5 #include "ash/common/system/tray/actionable_view.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_constants.h" | 7 #include "ash/common/ash_constants.h" |
| 8 #include "ash/common/system/tray/system_tray.h" | 8 #include "ash/common/system/tray/system_tray.h" |
| 9 #include "ash/common/system/tray/system_tray_item.h" | 9 #include "ash/common/system/tray/system_tray_item.h" |
| 10 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
| 11 #include "ui/accessibility/ax_node_data.h" | 11 #include "ui/accessibility/ax_node_data.h" |
| 12 #include "ui/events/keycodes/keyboard_codes.h" | 12 #include "ui/events/keycodes/keyboard_codes.h" |
| 13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/geometry/rect_f.h" | 14 #include "ui/gfx/geometry/rect_f.h" |
| 15 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 15 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
| 16 #include "ui/views/animation/ink_drop_highlight.h" | 16 #include "ui/views/animation/ink_drop_highlight.h" |
| 17 #include "ui/views/animation/ink_drop_impl.h" | 17 #include "ui/views/animation/ink_drop_impl.h" |
| 18 | 18 |
| 19 namespace ash { | 19 namespace ash { |
| 20 | 20 |
| 21 // static | 21 // static |
| 22 const char ActionableView::kViewClassName[] = "tray/ActionableView"; | 22 const char ActionableView::kViewClassName[] = "tray/ActionableView"; |
| 23 | 23 |
| 24 ActionableView::ActionableView(SystemTrayItem* owner) | 24 ActionableView::ActionableView(SystemTrayItem* owner) |
| 25 : views::CustomButton(this), destroyed_(nullptr), owner_(owner) { | 25 : views::CustomButton(this), destroyed_(nullptr), owner_(owner) { |
| 26 SetFocusBehavior(FocusBehavior::ALWAYS); | 26 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 27 set_ink_drop_base_color(kTrayPopupInkDropBaseColor); |
| 28 set_ink_drop_visible_opacity(kTrayPopupInkDropRippleOpacity); |
| 27 set_has_ink_drop_action_on_click(false); | 29 set_has_ink_drop_action_on_click(false); |
| 28 set_notify_enter_exit_on_child(true); | 30 set_notify_enter_exit_on_child(true); |
| 29 } | 31 } |
| 30 | 32 |
| 31 ActionableView::~ActionableView() { | 33 ActionableView::~ActionableView() { |
| 32 if (destroyed_) | 34 if (destroyed_) |
| 33 *destroyed_ = true; | 35 *destroyed_ = true; |
| 34 } | 36 } |
| 35 | 37 |
| 36 void ActionableView::OnPaintFocus(gfx::Canvas* canvas) { | 38 void ActionableView::OnPaintFocus(gfx::Canvas* canvas) { |
| 37 gfx::Rect rect(GetFocusBounds()); | 39 gfx::Rect rect(GetFocusBounds()); |
| 38 rect.Inset(1, 1, 3, 2); | 40 rect.Inset(1, 1, 3, 2); |
| 39 canvas->DrawSolidFocusRect(rect, kFocusBorderColor); | 41 canvas->DrawSolidFocusRect(rect, kFocusBorderColor); |
| 40 } | 42 } |
| 41 | 43 |
| 42 gfx::Rect ActionableView::GetFocusBounds() { | 44 gfx::Rect ActionableView::GetFocusBounds() { |
| 43 return GetLocalBounds(); | 45 return GetLocalBounds(); |
| 44 } | 46 } |
| 45 | 47 |
| 48 void ActionableView::HandlePerformActionResult(bool action_performed, |
| 49 const ui::Event& event) { |
| 50 AnimateInkDrop(action_performed ? views::InkDropState::ACTION_TRIGGERED |
| 51 : views::InkDropState::HIDDEN, |
| 52 ui::LocatedEvent::FromIfValid(&event)); |
| 53 } |
| 54 |
| 46 const char* ActionableView::GetClassName() const { | 55 const char* ActionableView::GetClassName() const { |
| 47 return kViewClassName; | 56 return kViewClassName; |
| 48 } | 57 } |
| 49 | 58 |
| 50 bool ActionableView::OnKeyPressed(const ui::KeyEvent& event) { | 59 bool ActionableView::OnKeyPressed(const ui::KeyEvent& event) { |
| 51 if (state() != STATE_DISABLED && event.key_code() == ui::VKEY_SPACE) { | 60 if (state() != STATE_DISABLED && event.key_code() == ui::VKEY_SPACE) { |
| 52 NotifyClick(event); | 61 NotifyClick(event); |
| 53 return true; | 62 return true; |
| 54 } | 63 } |
| 55 return CustomButton::OnKeyPressed(event); | 64 return CustomButton::OnKeyPressed(event); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 86 std::unique_ptr<views::InkDropImpl> ink_drop = | 95 std::unique_ptr<views::InkDropImpl> ink_drop = |
| 87 CreateDefaultFloodFillInkDropImpl(); | 96 CreateDefaultFloodFillInkDropImpl(); |
| 88 ink_drop->SetShowHighlightOnHover(false); | 97 ink_drop->SetShowHighlightOnHover(false); |
| 89 return std::move(ink_drop); | 98 return std::move(ink_drop); |
| 90 } | 99 } |
| 91 | 100 |
| 92 std::unique_ptr<views::InkDropRipple> ActionableView::CreateInkDropRipple() | 101 std::unique_ptr<views::InkDropRipple> ActionableView::CreateInkDropRipple() |
| 93 const { | 102 const { |
| 94 return base::MakeUnique<views::FloodFillInkDropRipple>( | 103 return base::MakeUnique<views::FloodFillInkDropRipple>( |
| 95 GetLocalBounds(), GetInkDropCenterBasedOnLastEvent(), | 104 GetLocalBounds(), GetInkDropCenterBasedOnLastEvent(), |
| 96 kTrayPopupInkDropBaseColor, kTrayPopupInkDropRippleOpacity); | 105 GetInkDropBaseColor(), ink_drop_visible_opacity()); |
| 97 } | 106 } |
| 98 | 107 |
| 99 std::unique_ptr<views::InkDropHighlight> | 108 std::unique_ptr<views::InkDropHighlight> |
| 100 ActionableView::CreateInkDropHighlight() const { | 109 ActionableView::CreateInkDropHighlight() const { |
| 101 std::unique_ptr<views::InkDropHighlight> highlight( | 110 std::unique_ptr<views::InkDropHighlight> highlight( |
| 102 new views::InkDropHighlight(size(), 0, | 111 new views::InkDropHighlight(size(), 0, |
| 103 gfx::RectF(GetLocalBounds()).CenterPoint(), | 112 gfx::RectF(GetLocalBounds()).CenterPoint(), |
| 104 kTrayPopupInkDropBaseColor)); | 113 GetInkDropBaseColor())); |
| 105 highlight->set_visible_opacity(kTrayPopupInkDropHighlightOpacity); | 114 highlight->set_visible_opacity(kTrayPopupInkDropHighlightOpacity); |
| 106 return highlight; | 115 return highlight; |
| 107 } | 116 } |
| 108 | 117 |
| 109 void ActionableView::CloseSystemBubble() { | 118 void ActionableView::CloseSystemBubble() { |
| 110 DCHECK(owner_); | 119 DCHECK(owner_); |
| 111 owner_->system_tray()->CloseSystemBubble(); | 120 owner_->system_tray()->CloseSystemBubble(); |
| 112 } | 121 } |
| 113 | 122 |
| 114 void ActionableView::ButtonPressed(Button* sender, const ui::Event& event) { | 123 void ActionableView::ButtonPressed(Button* sender, const ui::Event& event) { |
| 115 bool destroyed = false; | 124 bool destroyed = false; |
| 116 destroyed_ = &destroyed; | 125 destroyed_ = &destroyed; |
| 117 const bool action_performed = PerformAction(event); | 126 const bool action_performed = PerformAction(event); |
| 118 if (destroyed) | 127 if (destroyed) |
| 119 return; | 128 return; |
| 120 destroyed_ = nullptr; | 129 destroyed_ = nullptr; |
| 121 | 130 |
| 122 if (action_performed) { | 131 HandlePerformActionResult(action_performed, event); |
| 123 AnimateInkDrop(views::InkDropState::ACTION_TRIGGERED, | |
| 124 ui::LocatedEvent::FromIfValid(&event)); | |
| 125 } else { | |
| 126 AnimateInkDrop(views::InkDropState::HIDDEN, | |
| 127 ui::LocatedEvent::FromIfValid(&event)); | |
| 128 } | |
| 129 } | 132 } |
| 130 | 133 |
| 131 ButtonListenerActionableView::ButtonListenerActionableView( | 134 ButtonListenerActionableView::ButtonListenerActionableView( |
| 132 SystemTrayItem* owner, | 135 SystemTrayItem* owner, |
| 133 views::ButtonListener* listener) | 136 views::ButtonListener* listener) |
| 134 : ActionableView(owner), listener_(listener) {} | 137 : ActionableView(owner), listener_(listener) {} |
| 135 | 138 |
| 136 bool ButtonListenerActionableView::PerformAction(const ui::Event& event) { | 139 bool ButtonListenerActionableView::PerformAction(const ui::Event& event) { |
| 137 listener_->ButtonPressed(this, event); | 140 listener_->ButtonPressed(this, event); |
| 138 return true; | 141 return true; |
| 139 } | 142 } |
| 140 | 143 |
| 141 } // namespace ash | 144 } // namespace ash |
| OLD | NEW |