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

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

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