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

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

Issue 2870283002: Move message_center::CustomNotificationView to arc::ArcNotificationView (Closed)
Patch Set: Fixed test 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 DCHECK_EQ(message_center::NOTIFICATION_TYPE_CUSTOM, notification.type());
30 34
31 auto custom_content = notification.delegate()->CreateCustomContent(); 35 contents_view_ = contents_view.release();
hidehiko 2017/05/11 14:22:47 Could you initialize this in the initializer list
yoshiki 2017/05/12 08:42:37 Done.
32
33 contents_view_ = custom_content->view.release();
34 DCHECK(contents_view_); 36 DCHECK(contents_view_);
35 AddChildView(contents_view_); 37 AddChildView(contents_view_);
36 38
37 contents_view_delegate_ = std::move(custom_content->delegate); 39 contents_view_delegate_ = std::move(contents_view_delegate);
hidehiko 2017/05/11 14:22:47 Ditto.
yoshiki 2017/05/12 08:42:37 Done.
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() {}
hidehiko 2017/05/11 14:22:47 As you're here, could you s/{}/= default/?
yoshiki 2017/05/12 08:42:37 Done.
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 gfx::Size CustomNotificationView::GetPreferredSize() const { 89 gfx::Size ArcNotificationView::GetPreferredSize() const {
88 const gfx::Insets insets = GetInsets(); 90 const gfx::Insets insets = GetInsets();
89 const int contents_width = kNotificationWidth - insets.width(); 91 const int contents_width =
92 message_center::kNotificationWidth - insets.width();
90 const int contents_height = contents_view_->GetHeightForWidth(contents_width); 93 const int contents_height = contents_view_->GetHeightForWidth(contents_width);
91 return gfx::Size(kNotificationWidth, contents_height + insets.height()); 94 return gfx::Size(message_center::kNotificationWidth,
95 contents_height + insets.height());
92 } 96 }
93 97
94 void CustomNotificationView::Layout() { 98 void ArcNotificationView::Layout() {
95 MessageView::Layout(); 99 message_center::MessageView::Layout();
96 100
97 contents_view_->SetBoundsRect(GetContentsBounds()); 101 contents_view_->SetBoundsRect(GetContentsBounds());
98 102
99 // If the content view claims focus, defer focus handling to the content view. 103 // If the content view claims focus, defer focus handling to the content view.
100 if (contents_view_->IsFocusable()) 104 if (contents_view_->IsFocusable())
101 SetFocusBehavior(FocusBehavior::NEVER); 105 SetFocusBehavior(FocusBehavior::NEVER);
102 } 106 }
103 107
104 bool CustomNotificationView::HasFocus() const { 108 bool ArcNotificationView::HasFocus() const {
105 // In case that focus handling is defered to the content view, asking the 109 // In case that focus handling is defered to the content view, asking the
106 // content view about focus. 110 // content view about focus.
107 if (contents_view_ && contents_view_->IsFocusable()) 111 if (contents_view_ && contents_view_->IsFocusable())
108 return contents_view_->HasFocus(); 112 return contents_view_->HasFocus();
109 else 113 else
110 return MessageView::HasFocus(); 114 return message_center::MessageView::HasFocus();
111 } 115 }
112 116
113 void CustomNotificationView::RequestFocus() { 117 void ArcNotificationView::RequestFocus() {
114 if (contents_view_ && contents_view_->IsFocusable()) 118 if (contents_view_ && contents_view_->IsFocusable())
115 contents_view_->RequestFocus(); 119 contents_view_->RequestFocus();
116 else 120 else
117 MessageView::RequestFocus(); 121 message_center::MessageView::RequestFocus();
118 } 122 }
119 123
120 void CustomNotificationView::OnPaint(gfx::Canvas* canvas) { 124 void ArcNotificationView::OnPaint(gfx::Canvas* canvas) {
121 MessageView::OnPaint(canvas); 125 MessageView::OnPaint(canvas);
122 if (contents_view_ && contents_view_->IsFocusable()) 126 if (contents_view_ && contents_view_->IsFocusable())
123 views::Painter::PaintFocusPainter(contents_view_, canvas, 127 views::Painter::PaintFocusPainter(contents_view_, canvas,
124 focus_painter_.get()); 128 focus_painter_.get());
125 } 129 }
126 130
127 bool CustomNotificationView::OnKeyPressed(const ui::KeyEvent& event) { 131 bool ArcNotificationView::OnKeyPressed(const ui::KeyEvent& event) {
128 if (contents_view_) { 132 if (contents_view_) {
129 ui::InputMethod* input_method = contents_view_->GetInputMethod(); 133 ui::InputMethod* input_method = contents_view_->GetInputMethod();
130 if (input_method) { 134 if (input_method) {
131 ui::TextInputClient* text_input_client = 135 ui::TextInputClient* text_input_client =
132 input_method->GetTextInputClient(); 136 input_method->GetTextInputClient();
133 if (text_input_client && 137 if (text_input_client &&
134 text_input_client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) { 138 text_input_client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
135 // If the focus is in an edit box, we skip the special key handling for 139 // If the focus is in an edit box, we skip the special key handling for
136 // back space and return keys. So that these key events are sent to the 140 // back space and return keys. So that these key events are sent to the
137 // arc container correctly without being handled by the message center. 141 // arc container correctly without being handled by the message center.
138 return false; 142 return false;
139 } 143 }
140 } 144 }
141 } 145 }
142 146
143 return MessageView::OnKeyPressed(event); 147 return message_center::MessageView::OnKeyPressed(event);
144 } 148 }
145 149
146 void CustomNotificationView::ChildPreferredSizeChanged(View* child) { 150 void ArcNotificationView::ChildPreferredSizeChanged(View* child) {
147 // Notify MessageCenterController when the custom content changes size, 151 // Notify MessageCenterController when the custom content changes size,
148 // as it may need to relayout. 152 // as it may need to relayout.
149 if (controller()) 153 if (controller())
150 controller()->UpdateNotificationSize(notification_id()); 154 controller()->UpdateNotificationSize(notification_id());
151 } 155 }
152 156
153 bool CustomNotificationView::HandleAccessibleAction( 157 bool ArcNotificationView::HandleAccessibleAction(
154 const ui::AXActionData& action) { 158 const ui::AXActionData& action) {
155 if (contents_view_) 159 if (contents_view_)
156 return contents_view_->HandleAccessibleAction(action); 160 return contents_view_->HandleAccessibleAction(action);
157 return false; 161 return false;
158 } 162 }
159 163
160 } // namespace message_center 164 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698