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

Side by Side Diff: ui/arc/notification/arc_notification_view.cc

Issue 2870283002: Move message_center::CustomNotificationView to arc::ArcNotificationView (Closed)
Patch Set: Addressed comment Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "ui/message_center/views/custom_notification_view.h" 5 #include "ui/arc/notification/arc_notification_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/arc/notification/arc_custom_notification_view.h"
10 #include "ui/arc/notification/arc_notification_item.h"
9 #include "ui/base/ime/input_method.h" 11 #include "ui/base/ime/input_method.h"
10 #include "ui/base/ime/text_input_client.h" 12 #include "ui/base/ime/text_input_client.h"
11 #include "ui/base/ime/text_input_type.h" 13 #include "ui/base/ime/text_input_type.h"
12 #include "ui/gfx/geometry/size.h" 14 #include "ui/gfx/geometry/size.h"
13 #include "ui/message_center/message_center_style.h" 15 #include "ui/message_center/message_center_style.h"
14 #include "ui/message_center/views/message_center_controller.h" 16 #include "ui/message_center/views/message_center_controller.h"
15 #include "ui/views/background.h" 17 #include "ui/views/background.h"
16 #include "ui/views/controls/button/image_button.h" 18 #include "ui/views/controls/button/image_button.h"
17 #include "ui/views/controls/image_view.h" 19 #include "ui/views/controls/image_view.h"
18 #include "ui/views/painter.h" 20 #include "ui/views/painter.h"
19 21
20 namespace message_center { 22 namespace arc {
21 23
22 // static 24 // static
23 const char CustomNotificationView::kViewClassName[] = "CustomNotificationView"; 25 const char ArcNotificationView::kViewClassName[] = "ArcNotificationView";
24 26
25 CustomNotificationView::CustomNotificationView( 27 ArcNotificationView::ArcNotificationView(
26 MessageCenterController* controller, 28 std::unique_ptr<views::View> contents_view,
27 const Notification& notification) 29 std::unique_ptr<ArcNotificationContentViewDelegate> contents_view_delegate,
28 : MessageView(controller, notification) { 30 message_center::MessageCenterController* controller,
29 DCHECK_EQ(NOTIFICATION_TYPE_CUSTOM, notification.type()); 31 const message_center::Notification& notification)
32 : message_center::MessageView(controller, notification),
33 contents_view_(contents_view.get()),
34 contents_view_delegate_(std::move(contents_view_delegate)) {
35 DCHECK_EQ(message_center::NOTIFICATION_TYPE_CUSTOM, notification.type());
30 36
31 auto custom_content = notification.delegate()->CreateCustomContent(); 37 DCHECK(contents_view);
38 AddChildView(contents_view.release());
32 39
33 contents_view_ = custom_content->view.release();
34 DCHECK(contents_view_);
35 AddChildView(contents_view_);
36
37 contents_view_delegate_ = std::move(custom_content->delegate);
38 DCHECK(contents_view_delegate_); 40 DCHECK(contents_view_delegate_);
39 41
40 if (contents_view_->background()) { 42 if (contents_view_->background()) {
41 background_view()->background()->SetNativeControlColor( 43 background_view()->background()->SetNativeControlColor(
42 contents_view_->background()->get_color()); 44 contents_view_->background()->get_color());
43 } 45 }
44 46
45 focus_painter_ = views::Painter::CreateSolidFocusPainter( 47 focus_painter_ = views::Painter::CreateSolidFocusPainter(
46 kFocusBorderColor, gfx::Insets(0, 1, 3, 2)); 48 message_center::kFocusBorderColor, gfx::Insets(0, 1, 3, 2));
47 } 49 }
48 50
49 CustomNotificationView::~CustomNotificationView() {} 51 ArcNotificationView::~ArcNotificationView() = default;
50 52
51 void CustomNotificationView::OnContentFocused() { 53 void ArcNotificationView::OnContentFocused() {
52 SchedulePaint(); 54 SchedulePaint();
53 } 55 }
54 56
55 void CustomNotificationView::OnContentBlured() { 57 void ArcNotificationView::OnContentBlured() {
56 SchedulePaint(); 58 SchedulePaint();
57 } 59 }
58 60
59 void CustomNotificationView::SetDrawBackgroundAsActive(bool active) { 61 void ArcNotificationView::SetDrawBackgroundAsActive(bool active) {
60 // Do nothing if |contents_view_| has a background. 62 // Do nothing if |contents_view_| has a background.
61 if (contents_view_->background()) 63 if (contents_view_->background())
62 return; 64 return;
63 65
64 MessageView::SetDrawBackgroundAsActive(active); 66 message_center::MessageView::SetDrawBackgroundAsActive(active);
65 } 67 }
66 68
67 bool CustomNotificationView::IsCloseButtonFocused() const { 69 bool ArcNotificationView::IsCloseButtonFocused() const {
68 if (!contents_view_delegate_) 70 if (!contents_view_delegate_)
69 return false; 71 return false;
70 return contents_view_delegate_->IsCloseButtonFocused(); 72 return contents_view_delegate_->IsCloseButtonFocused();
71 } 73 }
72 74
73 void CustomNotificationView::RequestFocusOnCloseButton() { 75 void ArcNotificationView::RequestFocusOnCloseButton() {
74 if (contents_view_delegate_) 76 if (contents_view_delegate_)
75 contents_view_delegate_->RequestFocusOnCloseButton(); 77 contents_view_delegate_->RequestFocusOnCloseButton();
76 } 78 }
77 79
78 const char* CustomNotificationView::GetClassName() const { 80 const char* ArcNotificationView::GetClassName() const {
79 return kViewClassName; 81 return kViewClassName;
80 } 82 }
81 83
82 void CustomNotificationView::UpdateControlButtonsVisibility() { 84 void ArcNotificationView::UpdateControlButtonsVisibility() {
83 if (contents_view_delegate_) 85 if (contents_view_delegate_)
84 contents_view_delegate_->UpdateControlButtonsVisibility(); 86 contents_view_delegate_->UpdateControlButtonsVisibility();
85 } 87 }
86 88
87 void CustomNotificationView::OnSlideChanged() { 89 void ArcNotificationView::OnSlideChanged() {
88 if (contents_view_delegate_) 90 if (contents_view_delegate_)
89 contents_view_delegate_->OnSlideChanged(); 91 contents_view_delegate_->OnSlideChanged();
90 } 92 }
91 93
92 gfx::Size CustomNotificationView::GetPreferredSize() const { 94 gfx::Size ArcNotificationView::GetPreferredSize() const {
93 const gfx::Insets insets = GetInsets(); 95 const gfx::Insets insets = GetInsets();
94 const int contents_width = kNotificationWidth - insets.width(); 96 const int contents_width =
97 message_center::kNotificationWidth - insets.width();
95 const int contents_height = contents_view_->GetHeightForWidth(contents_width); 98 const int contents_height = contents_view_->GetHeightForWidth(contents_width);
96 return gfx::Size(kNotificationWidth, contents_height + insets.height()); 99 return gfx::Size(message_center::kNotificationWidth,
100 contents_height + insets.height());
97 } 101 }
98 102
99 void CustomNotificationView::Layout() { 103 void ArcNotificationView::Layout() {
100 MessageView::Layout(); 104 message_center::MessageView::Layout();
101 105
102 contents_view_->SetBoundsRect(GetContentsBounds()); 106 contents_view_->SetBoundsRect(GetContentsBounds());
103 107
104 // If the content view claims focus, defer focus handling to the content view. 108 // If the content view claims focus, defer focus handling to the content view.
105 if (contents_view_->IsFocusable()) 109 if (contents_view_->IsFocusable())
106 SetFocusBehavior(FocusBehavior::NEVER); 110 SetFocusBehavior(FocusBehavior::NEVER);
107 } 111 }
108 112
109 bool CustomNotificationView::HasFocus() const { 113 bool ArcNotificationView::HasFocus() const {
110 // In case that focus handling is defered to the content view, asking the 114 // In case that focus handling is defered to the content view, asking the
111 // content view about focus. 115 // content view about focus.
112 if (contents_view_ && contents_view_->IsFocusable()) 116 if (contents_view_ && contents_view_->IsFocusable())
113 return contents_view_->HasFocus(); 117 return contents_view_->HasFocus();
114 else 118 else
115 return MessageView::HasFocus(); 119 return message_center::MessageView::HasFocus();
116 } 120 }
117 121
118 void CustomNotificationView::RequestFocus() { 122 void ArcNotificationView::RequestFocus() {
119 if (contents_view_ && contents_view_->IsFocusable()) 123 if (contents_view_ && contents_view_->IsFocusable())
120 contents_view_->RequestFocus(); 124 contents_view_->RequestFocus();
121 else 125 else
122 MessageView::RequestFocus(); 126 message_center::MessageView::RequestFocus();
123 } 127 }
124 128
125 void CustomNotificationView::OnPaint(gfx::Canvas* canvas) { 129 void ArcNotificationView::OnPaint(gfx::Canvas* canvas) {
126 MessageView::OnPaint(canvas); 130 MessageView::OnPaint(canvas);
127 if (contents_view_ && contents_view_->IsFocusable()) 131 if (contents_view_ && contents_view_->IsFocusable())
128 views::Painter::PaintFocusPainter(contents_view_, canvas, 132 views::Painter::PaintFocusPainter(contents_view_, canvas,
129 focus_painter_.get()); 133 focus_painter_.get());
130 } 134 }
131 135
132 bool CustomNotificationView::OnKeyPressed(const ui::KeyEvent& event) { 136 bool ArcNotificationView::OnKeyPressed(const ui::KeyEvent& event) {
133 if (contents_view_) { 137 if (contents_view_) {
134 ui::InputMethod* input_method = contents_view_->GetInputMethod(); 138 ui::InputMethod* input_method = contents_view_->GetInputMethod();
135 if (input_method) { 139 if (input_method) {
136 ui::TextInputClient* text_input_client = 140 ui::TextInputClient* text_input_client =
137 input_method->GetTextInputClient(); 141 input_method->GetTextInputClient();
138 if (text_input_client && 142 if (text_input_client &&
139 text_input_client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) { 143 text_input_client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
140 // If the focus is in an edit box, we skip the special key handling for 144 // If the focus is in an edit box, we skip the special key handling for
141 // back space and return keys. So that these key events are sent to the 145 // back space and return keys. So that these key events are sent to the
142 // arc container correctly without being handled by the message center. 146 // arc container correctly without being handled by the message center.
143 return false; 147 return false;
144 } 148 }
145 } 149 }
146 } 150 }
147 151
148 return MessageView::OnKeyPressed(event); 152 return message_center::MessageView::OnKeyPressed(event);
149 } 153 }
150 154
151 void CustomNotificationView::ChildPreferredSizeChanged(View* child) { 155 void ArcNotificationView::ChildPreferredSizeChanged(View* child) {
152 // Notify MessageCenterController when the custom content changes size, 156 // Notify MessageCenterController when the custom content changes size,
153 // as it may need to relayout. 157 // as it may need to relayout.
154 if (controller()) 158 if (controller())
155 controller()->UpdateNotificationSize(notification_id()); 159 controller()->UpdateNotificationSize(notification_id());
156 } 160 }
157 161
158 bool CustomNotificationView::HandleAccessibleAction( 162 bool ArcNotificationView::HandleAccessibleAction(
159 const ui::AXActionData& action) { 163 const ui::AXActionData& action) {
160 if (contents_view_) 164 if (contents_view_)
161 return contents_view_->HandleAccessibleAction(action); 165 return contents_view_->HandleAccessibleAction(action);
162 return false; 166 return false;
163 } 167 }
164 168
165 } // namespace message_center 169 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/arc/notification/arc_notification_view.h ('k') | ui/arc/notification/arc_notification_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698