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

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

Issue 2642293003: Revert "Put the close button of a notification into focus chain." (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « ui/arc/notification/arc_custom_notification_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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/arc/notification/arc_custom_notification_view.h" 5 #include "ui/arc/notification/arc_custom_notification_view.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "components/exo/notification_surface.h" 9 #include "components/exo/notification_surface.h"
10 #include "components/exo/surface.h" 10 #include "components/exo/surface.h"
11 #include "third_party/skia/include/core/SkColor.h" 11 #include "third_party/skia/include/core/SkColor.h"
12 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/resource/resource_bundle.h" 13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/compositor/layer_animation_observer.h" 14 #include "ui/compositor/layer_animation_observer.h"
15 #include "ui/display/screen.h" 15 #include "ui/display/screen.h"
16 #include "ui/events/event_handler.h" 16 #include "ui/events/event_handler.h"
17 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/image/image_skia.h" 18 #include "ui/gfx/image/image_skia.h"
19 #include "ui/gfx/transform.h" 19 #include "ui/gfx/transform.h"
20 #include "ui/message_center/message_center_style.h" 20 #include "ui/message_center/message_center_style.h"
21 #include "ui/message_center/views/custom_notification_view.h" 21 #include "ui/message_center/views/custom_notification_view.h"
22 #include "ui/resources/grit/ui_resources.h" 22 #include "ui/resources/grit/ui_resources.h"
23 #include "ui/strings/grit/ui_strings.h" 23 #include "ui/strings/grit/ui_strings.h"
24 #include "ui/views/background.h" 24 #include "ui/views/background.h"
25 #include "ui/views/border.h" 25 #include "ui/views/border.h"
26 #include "ui/views/controls/button/image_button.h" 26 #include "ui/views/controls/button/image_button.h"
27 #include "ui/views/focus/focus_manager.h"
28 #include "ui/views/painter.h" 27 #include "ui/views/painter.h"
29 #include "ui/views/widget/root_view.h"
30 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
31 #include "ui/wm/core/window_util.h" 29 #include "ui/wm/core/window_util.h"
32 30
33 namespace arc { 31 namespace arc {
34 32
35 class ArcCustomNotificationView::EventForwarder : public ui::EventHandler { 33 class ArcCustomNotificationView::EventForwarder : public ui::EventHandler {
36 public: 34 public:
37 explicit EventForwarder(ArcCustomNotificationView* owner) : owner_(owner) {} 35 explicit EventForwarder(ArcCustomNotificationView* owner) : owner_(owner) {}
38 ~EventForwarder() override = default; 36 ~EventForwarder() override = default;
39 37
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 bool IsPinned() const override { 168 bool IsPinned() const override {
171 return owner_->floating_close_button_ == nullptr; 169 return owner_->floating_close_button_ == nullptr;
172 } 170 }
173 171
174 private: 172 private:
175 ArcCustomNotificationView* const owner_; 173 ArcCustomNotificationView* const owner_;
176 174
177 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); 175 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate);
178 }; 176 };
179 177
180 class ArcCustomNotificationView::CloseButton : public views::ImageButton {
181 public:
182 explicit CloseButton(ArcCustomNotificationView* owner)
183 : views::ImageButton(owner), owner_(owner) {
184 set_background(
185 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
186 SetFocusForPlatform();
187 SetFocusPainter(views::Painter::CreateSolidFocusPainter(
188 message_center::kFocusBorderColor, gfx::Insets(1, 2, 2, 2)));
189
190 // The sizes below are in DIPs.
191 constexpr int kPaddingFromBorder = 4;
192 constexpr int kImageSize = 16;
193 constexpr int kTouchExtendedPadding =
194 message_center::kControlButtonSize - kImageSize - kPaddingFromBorder;
195 SetBorder(
196 views::CreateEmptyBorder(kPaddingFromBorder, kTouchExtendedPadding,
197 kTouchExtendedPadding, kPaddingFromBorder));
198
199 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
200 SetImage(views::CustomButton::STATE_NORMAL,
201 rb.GetImageSkiaNamed(IDR_ARC_NOTIFICATION_CLOSE));
202 set_animate_on_state_change(false);
203 SetAccessibleName(l10n_util::GetStringUTF16(
204 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME));
205 SetTooltipText(l10n_util::GetStringUTF16(
206 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP));
207 }
208
209 void OnFocus() override {
210 views::ImageButton::OnFocus();
211 owner_->UpdateCloseButtonVisiblity();
212 }
213
214 void OnBlur() override {
215 views::ImageButton::OnBlur();
216 owner_->UpdateCloseButtonVisiblity();
217 }
218
219 private:
220 ArcCustomNotificationView* const owner_;
221 };
222
223 ArcCustomNotificationView::ArcCustomNotificationView( 178 ArcCustomNotificationView::ArcCustomNotificationView(
224 ArcCustomNotificationItem* item) 179 ArcCustomNotificationItem* item)
225 : item_(item), 180 : item_(item),
226 notification_key_(item->notification_key()), 181 notification_key_(item->notification_key()),
227 event_forwarder_(new EventForwarder(this)) { 182 event_forwarder_(new EventForwarder(this)) {
228 SetFocusBehavior(FocusBehavior::ALWAYS); 183 SetFocusBehavior(FocusBehavior::ALWAYS);
229 184
230 item_->IncrementWindowRefCount(); 185 item_->IncrementWindowRefCount();
231 item_->AddObserver(this); 186 item_->AddObserver(this);
232 187
(...skipping 21 matching lines...) Expand all
254 209
255 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> 210 std::unique_ptr<message_center::CustomNotificationContentViewDelegate>
256 ArcCustomNotificationView::CreateContentViewDelegate() { 211 ArcCustomNotificationView::CreateContentViewDelegate() {
257 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); 212 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this);
258 } 213 }
259 214
260 void ArcCustomNotificationView::CreateFloatingCloseButton() { 215 void ArcCustomNotificationView::CreateFloatingCloseButton() {
261 if (!surface_) 216 if (!surface_)
262 return; 217 return;
263 218
264 floating_close_button_ = new CloseButton(this); 219 // TODO(yhanada): Make the close button get focus after the entire
220 // notification
221 floating_close_button_ = new views::ImageButton(this);
222 floating_close_button_->set_background(
223 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
224 floating_close_button_->SetFocusForPlatform();
225 floating_close_button_->SetFocusPainter(
226 views::Painter::CreateSolidFocusPainter(message_center::kFocusBorderColor,
227 gfx::Insets(1, 2, 2, 2)));
228
229 // The sizes below are in DIPs.
230 constexpr int kPaddingFromBorder = 4;
231 constexpr int kImageSize = 16;
232 constexpr int kTouchExtendedPadding =
233 message_center::kControlButtonSize - kImageSize - kPaddingFromBorder;
234 floating_close_button_->SetBorder(
235 views::CreateEmptyBorder(kPaddingFromBorder, kTouchExtendedPadding,
236 kTouchExtendedPadding, kPaddingFromBorder));
237
238 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
239 floating_close_button_->SetImage(
240 views::CustomButton::STATE_NORMAL,
241 rb.GetImageSkiaNamed(IDR_ARC_NOTIFICATION_CLOSE));
242 floating_close_button_->set_animate_on_state_change(false);
243 floating_close_button_->SetAccessibleName(l10n_util::GetStringUTF16(
244 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME));
245 floating_close_button_->SetTooltipText(l10n_util::GetStringUTF16(
246 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP));
265 247
266 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); 248 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
267 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 249 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
268 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 250 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
269 params.parent = surface_->window(); 251 params.parent = surface_->window();
270 252
271 floating_close_button_widget_.reset(new views::Widget); 253 floating_close_button_widget_.reset(new views::Widget);
272 floating_close_button_widget_->Init(params); 254 floating_close_button_widget_->Init(params);
273 floating_close_button_widget_->SetContentsView(floating_close_button_); 255 floating_close_button_widget_->SetContentsView(floating_close_button_);
274 256
275 // Put the close button into the focus chain.
276 floating_close_button_widget_->SetFocusTraversableParent(
277 GetWidget()->GetFocusTraversable());
278 floating_close_button_widget_->SetFocusTraversableParentView(this);
279
280 Layout(); 257 Layout();
281 } 258 }
282 259
283 void ArcCustomNotificationView::SetSurface(exo::NotificationSurface* surface) { 260 void ArcCustomNotificationView::SetSurface(exo::NotificationSurface* surface) {
284 if (surface_ == surface) 261 if (surface_ == surface)
285 return; 262 return;
286 263
287 // Reset |floating_close_button_widget_| when |surface_| is changed. 264 // Reset |floating_close_button_widget_| when |surface_| is changed.
288 floating_close_button_widget_.reset(); 265 floating_close_button_widget_.reset();
289 266
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 static_cast<message_center::CustomNotificationView*>(parent()) 451 static_cast<message_center::CustomNotificationView*>(parent())
475 ->OnContentFocused(); 452 ->OnContentFocused();
476 } 453 }
477 454
478 void ArcCustomNotificationView::OnBlur() { 455 void ArcCustomNotificationView::OnBlur() {
479 NativeViewHost::OnBlur(); 456 NativeViewHost::OnBlur();
480 static_cast<message_center::CustomNotificationView*>(parent()) 457 static_cast<message_center::CustomNotificationView*>(parent())
481 ->OnContentBlured(); 458 ->OnContentBlured();
482 } 459 }
483 460
484 views::FocusTraversable* ArcCustomNotificationView::GetFocusTraversable() {
485 if (floating_close_button_widget_)
486 return static_cast<views::internal::RootView*>(
487 floating_close_button_widget_->GetRootView());
488 return nullptr;
489 }
490
491 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, 461 void ArcCustomNotificationView::ButtonPressed(views::Button* sender,
492 const ui::Event& event) { 462 const ui::Event& event) {
493 if (item_ && !item_->pinned() && sender == floating_close_button_) { 463 if (item_ && !item_->pinned() && sender == floating_close_button_) {
494 item_->CloseFromCloseButton(); 464 item_->CloseFromCloseButton();
495 } 465 }
496 } 466 }
497 467
498 void ArcCustomNotificationView::OnWindowBoundsChanged( 468 void ArcCustomNotificationView::OnWindowBoundsChanged(
499 aura::Window* window, 469 aura::Window* window,
500 const gfx::Rect& old_bounds, 470 const gfx::Rect& old_bounds,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 504
535 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( 505 void ArcCustomNotificationView::OnNotificationSurfaceRemoved(
536 exo::NotificationSurface* surface) { 506 exo::NotificationSurface* surface) {
537 if (surface->notification_id() != notification_key_) 507 if (surface->notification_id() != notification_key_)
538 return; 508 return;
539 509
540 SetSurface(nullptr); 510 SetSurface(nullptr);
541 } 511 }
542 512
543 } // namespace arc 513 } // namespace arc
OLDNEW
« no previous file with comments | « ui/arc/notification/arc_custom_notification_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698