| 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 <vector> | |
| 8 | |
| 9 #include "ash/common/ash_constants.h" | |
| 10 #include "ash/system/tray/tray_constants.h" | |
| 11 #include "ash/system/tray/tray_popup_utils.h" | |
| 12 #include "base/strings/string_util.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | |
| 14 #include "ui/accessibility/ax_node_data.h" | |
| 15 #include "ui/gfx/canvas.h" | |
| 16 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | |
| 17 #include "ui/views/animation/ink_drop.h" | |
| 18 #include "ui/views/animation/ink_drop_highlight.h" | |
| 19 #include "ui/views/animation/ink_drop_impl.h" | |
| 20 #include "ui/views/animation/ink_drop_mask.h" | |
| 21 #include "ui/views/layout/fill_layout.h" | |
| 22 | |
| 23 namespace ash { | |
| 24 namespace tray { | |
| 25 | |
| 26 ButtonFromView::ButtonFromView(views::View* content, | |
| 27 views::ButtonListener* listener, | |
| 28 TrayPopupInkDropStyle ink_drop_style) | |
| 29 : CustomButton(listener), | |
| 30 content_(content), | |
| 31 ink_drop_style_(ink_drop_style), | |
| 32 button_hovered_(false), | |
| 33 ink_drop_container_(nullptr) { | |
| 34 set_has_ink_drop_action_on_click(true); | |
| 35 set_notify_enter_exit_on_child(true); | |
| 36 ink_drop_container_ = new views::InkDropContainerView(); | |
| 37 AddChildView(ink_drop_container_); | |
| 38 SetLayoutManager(new views::FillLayout()); | |
| 39 SetInkDropMode(InkDropHostView::InkDropMode::ON); | |
| 40 AddChildView(content_); | |
| 41 // Only make it focusable when we are active/interested in clicks. | |
| 42 if (listener) | |
| 43 SetFocusForPlatform(); | |
| 44 } | |
| 45 | |
| 46 ButtonFromView::~ButtonFromView() {} | |
| 47 | |
| 48 void ButtonFromView::OnMouseEntered(const ui::MouseEvent& event) { | |
| 49 button_hovered_ = true; | |
| 50 } | |
| 51 | |
| 52 void ButtonFromView::OnMouseExited(const ui::MouseEvent& event) { | |
| 53 button_hovered_ = false; | |
| 54 } | |
| 55 | |
| 56 void ButtonFromView::OnPaint(gfx::Canvas* canvas) { | |
| 57 View::OnPaint(canvas); | |
| 58 if (HasFocus()) { | |
| 59 gfx::RectF rect(GetLocalBounds()); | |
| 60 canvas->DrawSolidFocusRect(rect, kFocusBorderColor, kFocusBorderThickness); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void ButtonFromView::OnFocus() { | |
| 65 View::OnFocus(); | |
| 66 // Adding focus frame. | |
| 67 SchedulePaint(); | |
| 68 } | |
| 69 | |
| 70 void ButtonFromView::OnBlur() { | |
| 71 View::OnBlur(); | |
| 72 // Removing focus frame. | |
| 73 SchedulePaint(); | |
| 74 } | |
| 75 | |
| 76 void ButtonFromView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | |
| 77 views::CustomButton::GetAccessibleNodeData(node_data); | |
| 78 // If no label has been explicitly set via CustomButton::SetAccessibleName(), | |
| 79 // use the content's label. | |
| 80 if (node_data->GetStringAttribute(ui::AX_ATTR_NAME).empty()) { | |
| 81 ui::AXNodeData content_data; | |
| 82 content_->GetAccessibleNodeData(&content_data); | |
| 83 node_data->SetName(content_data.GetStringAttribute(ui::AX_ATTR_NAME)); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 void ButtonFromView::Layout() { | |
| 88 CustomButton::Layout(); | |
| 89 if (ink_drop_container_) | |
| 90 ink_drop_container_->SetBoundsRect(GetLocalBounds()); | |
| 91 } | |
| 92 | |
| 93 void ButtonFromView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | |
| 94 // TODO(bruthig): Rework InkDropHostView so that it can still manage the | |
| 95 // creation/application of the mask while allowing subclasses to use an | |
| 96 // InkDropContainer. | |
| 97 ink_drop_mask_ = CreateInkDropMask(); | |
| 98 if (ink_drop_mask_) | |
| 99 ink_drop_layer->SetMaskLayer(ink_drop_mask_->layer()); | |
| 100 ink_drop_container_->AddInkDropLayer(ink_drop_layer); | |
| 101 } | |
| 102 | |
| 103 void ButtonFromView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | |
| 104 // TODO(bruthig): Rework InkDropHostView so that it can still manage the | |
| 105 // creation/application of the mask while allowing subclasses to use an | |
| 106 // InkDropContainer. | |
| 107 // Layers safely handle destroying a mask layer before the masked layer. | |
| 108 ink_drop_mask_.reset(); | |
| 109 ink_drop_container_->RemoveInkDropLayer(ink_drop_layer); | |
| 110 } | |
| 111 | |
| 112 std::unique_ptr<views::InkDrop> ButtonFromView::CreateInkDrop() { | |
| 113 return TrayPopupUtils::CreateInkDrop(TrayPopupInkDropStyle::INSET_BOUNDS, | |
| 114 this); | |
| 115 } | |
| 116 | |
| 117 std::unique_ptr<views::InkDropRipple> ButtonFromView::CreateInkDropRipple() | |
| 118 const { | |
| 119 return TrayPopupUtils::CreateInkDropRipple( | |
| 120 ink_drop_style_, this, GetInkDropCenterBasedOnLastEvent()); | |
| 121 } | |
| 122 | |
| 123 std::unique_ptr<views::InkDropHighlight> | |
| 124 ButtonFromView::CreateInkDropHighlight() const { | |
| 125 return TrayPopupUtils::CreateInkDropHighlight(ink_drop_style_, this); | |
| 126 } | |
| 127 | |
| 128 std::unique_ptr<views::InkDropMask> ButtonFromView::CreateInkDropMask() const { | |
| 129 return TrayPopupUtils::CreateInkDropMask(ink_drop_style_, this); | |
| 130 } | |
| 131 | |
| 132 } // namespace tray | |
| 133 } // namespace ash | |
| OLD | NEW |