| OLD | NEW |
| 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" | |
| 29 #include "ui/views/painter.h" | 28 #include "ui/views/painter.h" |
| 30 #include "ui/views/widget/root_view.h" | |
| 31 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
| 32 #include "ui/wm/core/window_util.h" | 30 #include "ui/wm/core/window_util.h" |
| 33 | 31 |
| 34 namespace arc { | 32 namespace arc { |
| 35 | 33 |
| 36 class ArcCustomNotificationView::EventForwarder : public ui::EventHandler { | 34 class ArcCustomNotificationView::EventForwarder : public ui::EventHandler { |
| 37 public: | 35 public: |
| 38 explicit EventForwarder(ArcCustomNotificationView* owner) : owner_(owner) {} | 36 explicit EventForwarder(ArcCustomNotificationView* owner) : owner_(owner) {} |
| 39 ~EventForwarder() override = default; | 37 ~EventForwarder() override = default; |
| 40 | 38 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 bool IsPinned() const override { | 169 bool IsPinned() const override { |
| 172 return owner_->floating_close_button_ == nullptr; | 170 return owner_->floating_close_button_ == nullptr; |
| 173 } | 171 } |
| 174 | 172 |
| 175 private: | 173 private: |
| 176 ArcCustomNotificationView* const owner_; | 174 ArcCustomNotificationView* const owner_; |
| 177 | 175 |
| 178 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); | 176 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); |
| 179 }; | 177 }; |
| 180 | 178 |
| 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 | |
| 224 ArcCustomNotificationView::ArcCustomNotificationView( | 179 ArcCustomNotificationView::ArcCustomNotificationView( |
| 225 ArcCustomNotificationItem* item) | 180 ArcCustomNotificationItem* item) |
| 226 : item_(item), | 181 : item_(item), |
| 227 notification_key_(item->notification_key()), | 182 notification_key_(item->notification_key()), |
| 228 event_forwarder_(new EventForwarder(this)) { | 183 event_forwarder_(new EventForwarder(this)) { |
| 229 SetFocusBehavior(FocusBehavior::ALWAYS); | 184 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 230 | 185 |
| 231 item_->IncrementWindowRefCount(); | 186 item_->IncrementWindowRefCount(); |
| 232 item_->AddObserver(this); | 187 item_->AddObserver(this); |
| 233 | 188 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 255 | 210 |
| 256 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> | 211 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> |
| 257 ArcCustomNotificationView::CreateContentViewDelegate() { | 212 ArcCustomNotificationView::CreateContentViewDelegate() { |
| 258 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); | 213 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); |
| 259 } | 214 } |
| 260 | 215 |
| 261 void ArcCustomNotificationView::CreateFloatingCloseButton() { | 216 void ArcCustomNotificationView::CreateFloatingCloseButton() { |
| 262 if (!surface_) | 217 if (!surface_) |
| 263 return; | 218 return; |
| 264 | 219 |
| 265 floating_close_button_ = new CloseButton(this); | 220 // TODO(yhanada): Make the close button get focus after the entire |
| 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)); |
| 266 | 248 |
| 267 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 249 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 268 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 250 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 269 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 251 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 270 params.parent = surface_->window(); | 252 params.parent = surface_->window(); |
| 271 | 253 |
| 272 floating_close_button_widget_.reset(new views::Widget); | 254 floating_close_button_widget_.reset(new views::Widget); |
| 273 floating_close_button_widget_->Init(params); | 255 floating_close_button_widget_->Init(params); |
| 274 floating_close_button_widget_->SetContentsView(floating_close_button_); | 256 floating_close_button_widget_->SetContentsView(floating_close_button_); |
| 275 | 257 |
| 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 | |
| 281 Layout(); | 258 Layout(); |
| 282 } | 259 } |
| 283 | 260 |
| 284 void ArcCustomNotificationView::SetSurface(exo::NotificationSurface* surface) { | 261 void ArcCustomNotificationView::SetSurface(exo::NotificationSurface* surface) { |
| 285 if (surface_ == surface) | 262 if (surface_ == surface) |
| 286 return; | 263 return; |
| 287 | 264 |
| 288 // Reset |floating_close_button_widget_| when |surface_| is changed. | 265 // Reset |floating_close_button_widget_| when |surface_| is changed. |
| 289 floating_close_button_widget_.reset(); | 266 floating_close_button_widget_.reset(); |
| 290 | 267 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 static_cast<message_center::CustomNotificationView*>(parent()) | 459 static_cast<message_center::CustomNotificationView*>(parent()) |
| 483 ->OnContentFocused(); | 460 ->OnContentFocused(); |
| 484 } | 461 } |
| 485 | 462 |
| 486 void ArcCustomNotificationView::OnBlur() { | 463 void ArcCustomNotificationView::OnBlur() { |
| 487 NativeViewHost::OnBlur(); | 464 NativeViewHost::OnBlur(); |
| 488 static_cast<message_center::CustomNotificationView*>(parent()) | 465 static_cast<message_center::CustomNotificationView*>(parent()) |
| 489 ->OnContentBlured(); | 466 ->OnContentBlured(); |
| 490 } | 467 } |
| 491 | 468 |
| 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 | |
| 499 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, | 469 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, |
| 500 const ui::Event& event) { | 470 const ui::Event& event) { |
| 501 if (item_ && !item_->pinned() && sender == floating_close_button_) { | 471 if (item_ && !item_->pinned() && sender == floating_close_button_) { |
| 502 item_->CloseFromCloseButton(); | 472 item_->CloseFromCloseButton(); |
| 503 } | 473 } |
| 504 } | 474 } |
| 505 | 475 |
| 506 void ArcCustomNotificationView::OnWindowBoundsChanged( | 476 void ArcCustomNotificationView::OnWindowBoundsChanged( |
| 507 aura::Window* window, | 477 aura::Window* window, |
| 508 const gfx::Rect& old_bounds, | 478 const gfx::Rect& old_bounds, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 | 512 |
| 543 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( | 513 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( |
| 544 exo::NotificationSurface* surface) { | 514 exo::NotificationSurface* surface) { |
| 545 if (surface->notification_id() != notification_key_) | 515 if (surface->notification_id() != notification_key_) |
| 546 return; | 516 return; |
| 547 | 517 |
| 548 SetSurface(nullptr); | 518 SetSurface(nullptr); |
| 549 } | 519 } |
| 550 | 520 |
| 551 } // namespace arc | 521 } // namespace arc |
| OLD | NEW |