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