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

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

Powered by Google App Engine
This is Rietveld 408576698