Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: ash/common/system/user/button_from_view.cc

Issue 2678353005: Remove pre-MD code related to tray/menu user profiles. (Closed)
Patch Set: merge conflict Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 12 #include "ash/common/system/tray/tray_utils.h"
14 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
16 #include "ui/accessibility/ax_node_data.h" 15 #include "ui/accessibility/ax_node_data.h"
17 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
18 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" 17 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
19 #include "ui/views/animation/ink_drop.h" 18 #include "ui/views/animation/ink_drop.h"
20 #include "ui/views/animation/ink_drop_highlight.h" 19 #include "ui/views/animation/ink_drop_highlight.h"
21 #include "ui/views/animation/ink_drop_impl.h" 20 #include "ui/views/animation/ink_drop_impl.h"
22 #include "ui/views/animation/ink_drop_mask.h" 21 #include "ui/views/animation/ink_drop_mask.h"
23 #include "ui/views/background.h" 22 #include "ui/views/background.h"
tdanderson 2017/02/08 22:33:41 nit: should be able to remove this now
24 #include "ui/views/border.h" 23 #include "ui/views/border.h"
25 #include "ui/views/layout/box_layout.h" 24 #include "ui/views/layout/box_layout.h"
26 #include "ui/views/layout/fill_layout.h" 25 #include "ui/views/layout/fill_layout.h"
27 26
28 namespace ash { 27 namespace ash {
29 namespace tray { 28 namespace tray {
30 29
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, 30 ButtonFromView::ButtonFromView(views::View* content,
39 views::ButtonListener* listener, 31 views::ButtonListener* listener,
40 TrayPopupInkDropStyle ink_drop_style, 32 TrayPopupInkDropStyle ink_drop_style)
41 bool highlight_on_hover,
42 const gfx::Insets& tab_frame_inset)
43 : CustomButton(listener), 33 : CustomButton(listener),
44 content_(content), 34 content_(content),
45 ink_drop_style_(ink_drop_style), 35 ink_drop_style_(ink_drop_style),
46 highlight_on_hover_(highlight_on_hover),
47 button_hovered_(false), 36 button_hovered_(false),
48 show_border_(false),
49 tab_frame_inset_(tab_frame_inset),
50 ink_drop_container_(nullptr) { 37 ink_drop_container_(nullptr) {
51 set_has_ink_drop_action_on_click(true); 38 set_has_ink_drop_action_on_click(true);
52 set_notify_enter_exit_on_child(true); 39 set_notify_enter_exit_on_child(true);
53 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 40 ink_drop_container_ = new views::InkDropContainerView();
54 ink_drop_container_ = new views::InkDropContainerView(); 41 AddChildView(ink_drop_container_);
55 AddChildView(ink_drop_container_); 42 SetLayoutManager(new views::FillLayout());
56 SetLayoutManager(new views::FillLayout()); 43 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_); 44 AddChildView(content_);
63 ShowActive();
64 // Only make it focusable when we are active/interested in clicks. 45 // Only make it focusable when we are active/interested in clicks.
65 if (listener) 46 if (listener)
66 SetFocusForPlatform(); 47 SetFocusForPlatform();
67 } 48 }
68 49
69 ButtonFromView::~ButtonFromView() {} 50 ButtonFromView::~ButtonFromView() {}
70 51
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) { 52 void ButtonFromView::OnMouseEntered(const ui::MouseEvent& event) {
79 button_hovered_ = true; 53 button_hovered_ = true;
80 ShowActive();
81 } 54 }
82 55
83 void ButtonFromView::OnMouseExited(const ui::MouseEvent& event) { 56 void ButtonFromView::OnMouseExited(const ui::MouseEvent& event) {
84 button_hovered_ = false; 57 button_hovered_ = false;
85 ShowActive();
86 } 58 }
87 59
88 void ButtonFromView::OnPaint(gfx::Canvas* canvas) { 60 void ButtonFromView::OnPaint(gfx::Canvas* canvas) {
89 View::OnPaint(canvas); 61 View::OnPaint(canvas);
90 if (HasFocus()) { 62 if (HasFocus()) {
91 gfx::RectF rect(GetLocalBounds()); 63 gfx::RectF rect(GetLocalBounds());
92 bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial(); 64 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 } 65 }
98 } 66 }
99 67
100 void ButtonFromView::OnFocus() { 68 void ButtonFromView::OnFocus() {
101 View::OnFocus(); 69 View::OnFocus();
102 // Adding focus frame. 70 // Adding focus frame.
103 SchedulePaint(); 71 SchedulePaint();
104 } 72 }
105 73
106 void ButtonFromView::OnBlur() { 74 void ButtonFromView::OnBlur() {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 123
156 std::unique_ptr<views::InkDropHighlight> 124 std::unique_ptr<views::InkDropHighlight>
157 ButtonFromView::CreateInkDropHighlight() const { 125 ButtonFromView::CreateInkDropHighlight() const {
158 return TrayPopupUtils::CreateInkDropHighlight(ink_drop_style_, this); 126 return TrayPopupUtils::CreateInkDropHighlight(ink_drop_style_, this);
159 } 127 }
160 128
161 std::unique_ptr<views::InkDropMask> ButtonFromView::CreateInkDropMask() const { 129 std::unique_ptr<views::InkDropMask> ButtonFromView::CreateInkDropMask() const {
162 return TrayPopupUtils::CreateInkDropMask(ink_drop_style_, this); 130 return TrayPopupUtils::CreateInkDropMask(ink_drop_style_, this);
163 } 131 }
164 132
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 133 } // namespace tray
183 } // namespace ash 134 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698