| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "ash/common/system/user/button_from_view.h" | 7 #include "ash/common/system/user/button_from_view.h" |
| 8 | 8 |
| 9 #include "ash/common/ash_constants.h" | 9 #include "ash/common/ash_constants.h" |
| 10 #include "ash/common/material_design/material_design_controller.h" | |
| 11 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
| 12 #include "ash/common/system/tray/tray_popup_utils.h" | 11 #include "ash/common/system/tray/tray_popup_utils.h" |
| 13 #include "ash/common/system/tray/tray_utils.h" | |
| 14 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 16 #include "ui/accessibility/ax_node_data.h" | 14 #include "ui/accessibility/ax_node_data.h" |
| 17 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 18 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 16 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
| 19 #include "ui/views/animation/ink_drop.h" | 17 #include "ui/views/animation/ink_drop.h" |
| 20 #include "ui/views/animation/ink_drop_highlight.h" | 18 #include "ui/views/animation/ink_drop_highlight.h" |
| 21 #include "ui/views/animation/ink_drop_impl.h" | 19 #include "ui/views/animation/ink_drop_impl.h" |
| 22 #include "ui/views/animation/ink_drop_mask.h" | 20 #include "ui/views/animation/ink_drop_mask.h" |
| 23 #include "ui/views/background.h" | |
| 24 #include "ui/views/border.h" | |
| 25 #include "ui/views/layout/box_layout.h" | |
| 26 #include "ui/views/layout/fill_layout.h" | 21 #include "ui/views/layout/fill_layout.h" |
| 27 | 22 |
| 28 namespace ash { | 23 namespace ash { |
| 29 namespace tray { | 24 namespace tray { |
| 30 | 25 |
| 31 namespace { | |
| 32 | |
| 33 // The border color of the user button. | |
| 34 const SkColor kBorderColor = 0xffdcdcdc; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 ButtonFromView::ButtonFromView(views::View* content, | 26 ButtonFromView::ButtonFromView(views::View* content, |
| 39 views::ButtonListener* listener, | 27 views::ButtonListener* listener, |
| 40 TrayPopupInkDropStyle ink_drop_style, | 28 TrayPopupInkDropStyle ink_drop_style) |
| 41 bool highlight_on_hover, | |
| 42 const gfx::Insets& tab_frame_inset) | |
| 43 : CustomButton(listener), | 29 : CustomButton(listener), |
| 44 content_(content), | 30 content_(content), |
| 45 ink_drop_style_(ink_drop_style), | 31 ink_drop_style_(ink_drop_style), |
| 46 highlight_on_hover_(highlight_on_hover), | |
| 47 button_hovered_(false), | 32 button_hovered_(false), |
| 48 show_border_(false), | |
| 49 tab_frame_inset_(tab_frame_inset), | |
| 50 ink_drop_container_(nullptr) { | 33 ink_drop_container_(nullptr) { |
| 51 set_has_ink_drop_action_on_click(true); | 34 set_has_ink_drop_action_on_click(true); |
| 52 set_notify_enter_exit_on_child(true); | 35 set_notify_enter_exit_on_child(true); |
| 53 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 36 ink_drop_container_ = new views::InkDropContainerView(); |
| 54 ink_drop_container_ = new views::InkDropContainerView(); | 37 AddChildView(ink_drop_container_); |
| 55 AddChildView(ink_drop_container_); | 38 SetLayoutManager(new views::FillLayout()); |
| 56 SetLayoutManager(new views::FillLayout()); | 39 SetInkDropMode(InkDropHostView::InkDropMode::ON); |
| 57 SetInkDropMode(InkDropHostView::InkDropMode::ON); | |
| 58 } else { | |
| 59 SetLayoutManager( | |
| 60 new views::BoxLayout(views::BoxLayout::kHorizontal, 1, 1, 0)); | |
| 61 } | |
| 62 AddChildView(content_); | 40 AddChildView(content_); |
| 63 ShowActive(); | |
| 64 // Only make it focusable when we are active/interested in clicks. | 41 // Only make it focusable when we are active/interested in clicks. |
| 65 if (listener) | 42 if (listener) |
| 66 SetFocusForPlatform(); | 43 SetFocusForPlatform(); |
| 67 } | 44 } |
| 68 | 45 |
| 69 ButtonFromView::~ButtonFromView() {} | 46 ButtonFromView::~ButtonFromView() {} |
| 70 | 47 |
| 71 void ButtonFromView::ForceBorderVisible(bool show) { | |
| 72 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 73 return; | |
| 74 show_border_ = show; | |
| 75 ShowActive(); | |
| 76 } | |
| 77 | |
| 78 void ButtonFromView::OnMouseEntered(const ui::MouseEvent& event) { | 48 void ButtonFromView::OnMouseEntered(const ui::MouseEvent& event) { |
| 79 button_hovered_ = true; | 49 button_hovered_ = true; |
| 80 ShowActive(); | |
| 81 } | 50 } |
| 82 | 51 |
| 83 void ButtonFromView::OnMouseExited(const ui::MouseEvent& event) { | 52 void ButtonFromView::OnMouseExited(const ui::MouseEvent& event) { |
| 84 button_hovered_ = false; | 53 button_hovered_ = false; |
| 85 ShowActive(); | |
| 86 } | 54 } |
| 87 | 55 |
| 88 void ButtonFromView::OnPaint(gfx::Canvas* canvas) { | 56 void ButtonFromView::OnPaint(gfx::Canvas* canvas) { |
| 89 View::OnPaint(canvas); | 57 View::OnPaint(canvas); |
| 90 if (HasFocus()) { | 58 if (HasFocus()) { |
| 91 gfx::RectF rect(GetLocalBounds()); | 59 gfx::RectF rect(GetLocalBounds()); |
| 92 bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial(); | 60 canvas->DrawSolidFocusRect(rect, kFocusBorderColor, kFocusBorderThickness); |
| 93 if (!use_md) | |
| 94 rect.Inset(gfx::InsetsF(tab_frame_inset_)); | |
| 95 canvas->DrawSolidFocusRect(rect, kFocusBorderColor, | |
| 96 use_md ? kFocusBorderThickness : 1); | |
| 97 } | 61 } |
| 98 } | 62 } |
| 99 | 63 |
| 100 void ButtonFromView::OnFocus() { | 64 void ButtonFromView::OnFocus() { |
| 101 View::OnFocus(); | 65 View::OnFocus(); |
| 102 // Adding focus frame. | 66 // Adding focus frame. |
| 103 SchedulePaint(); | 67 SchedulePaint(); |
| 104 } | 68 } |
| 105 | 69 |
| 106 void ButtonFromView::OnBlur() { | 70 void ButtonFromView::OnBlur() { |
| 107 View::OnBlur(); | 71 View::OnBlur(); |
| 108 // Removing focus frame. | 72 // Removing focus frame. |
| 109 SchedulePaint(); | 73 SchedulePaint(); |
| 110 } | 74 } |
| 111 | 75 |
| 112 void ButtonFromView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 76 void ButtonFromView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 113 node_data->role = ui::AX_ROLE_BUTTON; | 77 views::CustomButton::GetAccessibleNodeData(node_data); |
| 114 std::vector<base::string16> labels; | 78 // If no label has been explicitly set via CustomButton::SetAccessibleName(), |
| 115 for (int i = 0; i < child_count(); ++i) | 79 // use the content's label. |
| 116 GetAccessibleLabelFromDescendantViews(child_at(i), labels); | 80 if (node_data->GetStringAttribute(ui::AX_ATTR_NAME).empty()) { |
| 117 node_data->SetName(base::JoinString(labels, base::ASCIIToUTF16(" "))); | 81 ui::AXNodeData content_data; |
| 82 content_->GetAccessibleNodeData(&content_data); |
| 83 node_data->SetName(content_data.GetStringAttribute(ui::AX_ATTR_NAME)); |
| 84 } |
| 118 } | 85 } |
| 119 | 86 |
| 120 void ButtonFromView::Layout() { | 87 void ButtonFromView::Layout() { |
| 121 CustomButton::Layout(); | 88 CustomButton::Layout(); |
| 122 if (ink_drop_container_) | 89 if (ink_drop_container_) |
| 123 ink_drop_container_->SetBoundsRect(GetLocalBounds()); | 90 ink_drop_container_->SetBoundsRect(GetLocalBounds()); |
| 124 } | 91 } |
| 125 | 92 |
| 126 void ButtonFromView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 93 void ButtonFromView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 127 // TODO(bruthig): Rework InkDropHostView so that it can still manage the | 94 // TODO(bruthig): Rework InkDropHostView so that it can still manage the |
| (...skipping 27 matching lines...) Expand all Loading... |
| 155 | 122 |
| 156 std::unique_ptr<views::InkDropHighlight> | 123 std::unique_ptr<views::InkDropHighlight> |
| 157 ButtonFromView::CreateInkDropHighlight() const { | 124 ButtonFromView::CreateInkDropHighlight() const { |
| 158 return TrayPopupUtils::CreateInkDropHighlight(ink_drop_style_, this); | 125 return TrayPopupUtils::CreateInkDropHighlight(ink_drop_style_, this); |
| 159 } | 126 } |
| 160 | 127 |
| 161 std::unique_ptr<views::InkDropMask> ButtonFromView::CreateInkDropMask() const { | 128 std::unique_ptr<views::InkDropMask> ButtonFromView::CreateInkDropMask() const { |
| 162 return TrayPopupUtils::CreateInkDropMask(ink_drop_style_, this); | 129 return TrayPopupUtils::CreateInkDropMask(ink_drop_style_, this); |
| 163 } | 130 } |
| 164 | 131 |
| 165 void ButtonFromView::ShowActive() { | |
| 166 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 167 return; | |
| 168 bool border_visible = | |
| 169 (button_hovered_ && highlight_on_hover_) || show_border_; | |
| 170 SkColor border_color = border_visible ? kBorderColor : SK_ColorTRANSPARENT; | |
| 171 SetBorder(views::CreateSolidBorder(1, border_color)); | |
| 172 if (highlight_on_hover_) { | |
| 173 SkColor background_color = | |
| 174 button_hovered_ ? kHoverBackgroundColor : kBackgroundColor; | |
| 175 content_->set_background( | |
| 176 views::Background::CreateSolidBackground(background_color)); | |
| 177 set_background(views::Background::CreateSolidBackground(background_color)); | |
| 178 } | |
| 179 SchedulePaint(); | |
| 180 } | |
| 181 | |
| 182 } // namespace tray | 132 } // namespace tray |
| 183 } // namespace ash | 133 } // namespace ash |
| OLD | NEW |