Chromium Code Reviews| 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_notification_content_view.h" | 5 #include "ui/arc/notification/arc_notification_content_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 "ui/accessibility/ax_action_data.h" | 12 #include "ui/accessibility/ax_action_data.h" |
| 13 #include "ui/accessibility/ax_node_data.h" | 13 #include "ui/accessibility/ax_node_data.h" |
| 14 #include "ui/arc/notification/arc_notification_surface.h" | 14 #include "ui/arc/notification/arc_notification_surface.h" |
| 15 #include "ui/arc/notification/arc_notification_view.h" | 15 #include "ui/arc/notification/arc_notification_view.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
|
yhanada
2017/06/29 04:14:47
It's not related to this change, but this may be a
yoshiki
2017/06/29 06:29:41
Done.
| |
| 18 #include "ui/compositor/layer_animation_observer.h" | |
|
yhanada
2017/06/29 04:14:47
LayerAnimationObserver seems to be still used.
yoshiki
2017/06/29 06:29:41
Done.
| |
| 19 #include "ui/events/event_handler.h" | 18 #include "ui/events/event_handler.h" |
| 20 #include "ui/gfx/animation/linear_animation.h" | 19 #include "ui/gfx/animation/linear_animation.h" |
|
yhanada
2017/06/29 04:14:47
remove?
yoshiki
2017/06/29 06:29:41
Done.
| |
| 21 #include "ui/gfx/animation/tween.h" | |
| 22 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 23 #include "ui/gfx/geometry/insets.h" | 21 #include "ui/gfx/geometry/insets.h" |
| 24 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
| 25 #include "ui/message_center/message_center_style.h" | 23 #include "ui/message_center/message_center_style.h" |
| 24 #include "ui/message_center/views/notification_control_buttons_view.h" | |
| 26 #include "ui/message_center/views/toast_contents_view.h" | 25 #include "ui/message_center/views/toast_contents_view.h" |
| 27 #include "ui/strings/grit/ui_strings.h" | 26 #include "ui/strings/grit/ui_strings.h" |
| 28 #include "ui/views/background.h" | |
| 29 #include "ui/views/focus/focus_manager.h" | 27 #include "ui/views/focus/focus_manager.h" |
| 30 #include "ui/views/layout/box_layout.h" | |
| 31 #include "ui/views/painter.h" | |
| 32 #include "ui/views/widget/root_view.h" | 28 #include "ui/views/widget/root_view.h" |
| 33 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
| 34 #include "ui/wm/core/window_util.h" | 30 #include "ui/wm/core/window_util.h" |
| 35 | 31 |
| 36 namespace arc { | 32 namespace arc { |
| 37 | 33 |
| 38 namespace { | 34 namespace { |
| 39 | 35 |
| 40 // This value should be the same as the duration of reveal animation of | |
| 41 // the settings view of an Android notification. | |
| 42 constexpr int kBackgroundColorChangeDuration = 360; | |
| 43 | |
| 44 SkColor GetControlButtonBackgroundColor( | 36 SkColor GetControlButtonBackgroundColor( |
| 45 const mojom::ArcNotificationShownContents& shown_contents) { | 37 const mojom::ArcNotificationShownContents& shown_contents) { |
| 46 if (shown_contents == mojom::ArcNotificationShownContents::CONTENTS_SHOWN) | 38 if (shown_contents == mojom::ArcNotificationShownContents::CONTENTS_SHOWN) |
| 47 return message_center::kControlButtonBackgroundColor; | 39 return message_center::kControlButtonBackgroundColor; |
| 48 else | 40 else |
| 49 return SK_ColorTRANSPARENT; | 41 return SK_ColorTRANSPARENT; |
| 50 } | 42 } |
| 51 | 43 |
| 52 } // namespace | 44 } // namespace |
| 53 | 45 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 DISALLOW_COPY_AND_ASSIGN(SlideHelper); | 176 DISALLOW_COPY_AND_ASSIGN(SlideHelper); |
| 185 }; | 177 }; |
| 186 | 178 |
| 187 class ArcNotificationContentView::ContentViewDelegate | 179 class ArcNotificationContentView::ContentViewDelegate |
| 188 : public ArcNotificationContentViewDelegate { | 180 : public ArcNotificationContentViewDelegate { |
| 189 public: | 181 public: |
| 190 explicit ContentViewDelegate(ArcNotificationContentView* owner) | 182 explicit ContentViewDelegate(ArcNotificationContentView* owner) |
| 191 : owner_(owner) {} | 183 : owner_(owner) {} |
| 192 | 184 |
| 193 bool IsCloseButtonFocused() const override { | 185 bool IsCloseButtonFocused() const override { |
| 194 if (!owner_->close_button_) | 186 if (!owner_->control_buttons_view_) |
| 195 return false; | 187 return false; |
| 196 return owner_->close_button_->HasFocus(); | 188 return owner_->control_buttons_view_->IsCloseButtonFocused(); |
| 197 } | 189 } |
| 198 | 190 |
| 199 void RequestFocusOnCloseButton() override { | 191 void RequestFocusOnCloseButton() override { |
| 200 if (owner_->close_button_) | 192 if (owner_->control_buttons_view_) |
| 201 owner_->close_button_->RequestFocus(); | 193 owner_->control_buttons_view_->RequestFocusOnCloseButton(); |
| 202 owner_->UpdateControlButtonsVisibility(); | 194 owner_->UpdateControlButtonsVisibility(); |
| 203 } | 195 } |
| 204 | 196 |
| 205 void UpdateControlButtonsVisibility() override { | 197 void UpdateControlButtonsVisibility() override { |
| 206 owner_->UpdateControlButtonsVisibility(); | 198 owner_->UpdateControlButtonsVisibility(); |
| 207 } | 199 } |
| 208 | 200 |
| 209 void OnSlideChanged() override { | 201 void OnSlideChanged() override { |
| 210 if (owner_->slide_helper_) | 202 if (owner_->slide_helper_) |
| 211 owner_->slide_helper_->Update(); | 203 owner_->slide_helper_->Update(); |
| 212 } | 204 } |
| 213 | 205 |
| 214 private: | 206 private: |
| 215 ArcNotificationContentView* const owner_; | 207 ArcNotificationContentView* const owner_; |
| 216 | 208 |
| 217 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); | 209 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); |
| 218 }; | 210 }; |
| 219 | 211 |
| 220 ArcNotificationContentView::ControlButton::ControlButton( | |
| 221 ArcNotificationContentView* owner) | |
| 222 : message_center::PaddedButton(owner), owner_(owner) { | |
| 223 if (owner_->item_) { | |
| 224 SetBackground(views::CreateSolidBackground( | |
| 225 GetControlButtonBackgroundColor(owner_->item_->GetShownContents()))); | |
| 226 } else { | |
| 227 SetBackground(views::CreateSolidBackground( | |
| 228 message_center::kControlButtonBackgroundColor)); | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 void ArcNotificationContentView::ControlButton::OnFocus() { | |
| 233 message_center::PaddedButton::OnFocus(); | |
| 234 owner_->UpdateControlButtonsVisibility(); | |
| 235 } | |
| 236 | |
| 237 void ArcNotificationContentView::ControlButton::OnBlur() { | |
| 238 message_center::PaddedButton::OnBlur(); | |
| 239 owner_->UpdateControlButtonsVisibility(); | |
| 240 } | |
| 241 | |
| 242 // static, for ArcNotificationContentView::GetClassName(). | 212 // static, for ArcNotificationContentView::GetClassName(). |
| 243 const char ArcNotificationContentView::kViewClassName[] = | 213 const char ArcNotificationContentView::kViewClassName[] = |
| 244 "ArcNotificationContentView"; | 214 "ArcNotificationContentView"; |
| 245 | 215 |
| 246 ArcNotificationContentView::ArcNotificationContentView( | 216 ArcNotificationContentView::ArcNotificationContentView( |
| 247 ArcNotificationItem* item) | 217 ArcNotificationItem* item) |
| 248 : item_(item), | 218 : item_(item), |
| 249 notification_key_(item->GetNotificationKey()), | 219 notification_key_(item->GetNotificationKey()), |
| 250 event_forwarder_(new EventForwarder(this)) { | 220 event_forwarder_(new EventForwarder(this)) { |
| 251 SetFocusBehavior(FocusBehavior::ALWAYS); | 221 SetFocusBehavior(FocusBehavior::ALWAYS); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 const char* ArcNotificationContentView::GetClassName() const { | 254 const char* ArcNotificationContentView::GetClassName() const { |
| 285 return kViewClassName; | 255 return kViewClassName; |
| 286 } | 256 } |
| 287 | 257 |
| 288 std::unique_ptr<ArcNotificationContentViewDelegate> | 258 std::unique_ptr<ArcNotificationContentViewDelegate> |
| 289 ArcNotificationContentView::CreateContentViewDelegate() { | 259 ArcNotificationContentView::CreateContentViewDelegate() { |
| 290 return base::MakeUnique<ArcNotificationContentView::ContentViewDelegate>( | 260 return base::MakeUnique<ArcNotificationContentView::ContentViewDelegate>( |
| 291 this); | 261 this); |
| 292 } | 262 } |
| 293 | 263 |
| 294 void ArcNotificationContentView::CreateCloseButton() { | |
| 295 DCHECK(control_buttons_view_); | |
| 296 DCHECK(item_); | |
| 297 | |
| 298 close_button_ = base::MakeUnique<ControlButton>(this); | |
| 299 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | |
| 300 message_center::GetCloseIcon()); | |
| 301 close_button_->SetAccessibleName(l10n_util::GetStringUTF16( | |
| 302 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); | |
| 303 close_button_->SetTooltipText(l10n_util::GetStringUTF16( | |
| 304 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP)); | |
| 305 close_button_->set_owned_by_client(); | |
| 306 control_buttons_view_->AddChildView(close_button_.get()); | |
| 307 } | |
| 308 | |
| 309 void ArcNotificationContentView::CreateSettingsButton() { | |
| 310 DCHECK(control_buttons_view_); | |
| 311 DCHECK(item_); | |
| 312 | |
| 313 settings_button_ = new ControlButton(this); | |
| 314 settings_button_->SetImage(views::CustomButton::STATE_NORMAL, | |
| 315 message_center::GetSettingsIcon()); | |
| 316 settings_button_->SetAccessibleName(l10n_util::GetStringUTF16( | |
| 317 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); | |
| 318 settings_button_->SetTooltipText(l10n_util::GetStringUTF16( | |
| 319 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); | |
| 320 control_buttons_view_->AddChildView(settings_button_); | |
| 321 } | |
| 322 | |
| 323 void ArcNotificationContentView::MaybeCreateFloatingControlButtons() { | 264 void ArcNotificationContentView::MaybeCreateFloatingControlButtons() { |
| 324 // Floating close button is a transient child of |surface_| and also part | 265 // Floating close button is a transient child of |surface_| and also part |
| 325 // of the hosting widget's focus chain. It could only be created when both | 266 // of the hosting widget's focus chain. It could only be created when both |
| 326 // are present. Further, if we are being destroyed (|item_| is null), don't | 267 // are present. Further, if we are being destroyed (|item_| is null), don't |
| 327 // create the control buttons. | 268 // create the control buttons. |
| 328 if (!surface_ || !GetWidget() || !item_) | 269 if (!surface_ || !GetWidget() || !item_) |
| 329 return; | 270 return; |
| 330 | 271 |
| 272 DCHECK(!control_buttons_view_); | |
| 273 DCHECK(!floating_control_buttons_widget_); | |
| 274 | |
| 275 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); | |
| 276 auto* notification_view = static_cast<ArcNotificationView*>(parent()); | |
| 277 | |
| 331 // Creates the control_buttons_view_, which collects all control buttons into | 278 // Creates the control_buttons_view_, which collects all control buttons into |
| 332 // a horizontal box. | 279 // a horizontal box. |
| 333 control_buttons_view_ = new views::View(); | 280 control_buttons_view_ = |
| 334 control_buttons_view_->SetLayoutManager( | 281 new message_center::NotificationControlButtonsView(notification_view); |
| 335 new views::BoxLayout(views::BoxLayout::kHorizontal)); | 282 control_buttons_view_->SetPaintToLayer(ui::LAYER_TEXTURED); |
| 283 control_buttons_view_->layer()->SetFillsBoundsOpaquely(false); | |
| 336 | 284 |
| 337 if (item_->IsOpeningSettingsSupported()) | 285 control_buttons_view_->SetBackgroundColor( |
| 338 CreateSettingsButton(); | 286 GetControlButtonBackgroundColor(item_->GetShownContents())); |
| 339 if (!item_->GetPinned()) | 287 control_buttons_view_->ShowSettingsButton( |
| 340 CreateCloseButton(); | 288 item_->IsOpeningSettingsSupported()); |
| 289 control_buttons_view_->ShowCloseButton(!item_->GetPinned()); | |
| 341 | 290 |
| 342 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 291 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 343 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 292 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 344 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 293 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 345 params.parent = surface_->GetWindow(); | 294 params.parent = surface_->GetWindow(); |
| 346 | 295 |
| 347 floating_control_buttons_widget_.reset(new views::Widget); | 296 floating_control_buttons_widget_.reset(new views::Widget); |
| 348 floating_control_buttons_widget_->Init(params); | 297 floating_control_buttons_widget_->Init(params); |
| 349 floating_control_buttons_widget_->SetContentsView(control_buttons_view_); | 298 floating_control_buttons_widget_->SetContentsView(control_buttons_view_); |
| 350 | 299 |
| 351 // Put the close button into the focus chain. | 300 // Put the close button into the focus chain. |
| 352 floating_control_buttons_widget_->SetFocusTraversableParent( | 301 floating_control_buttons_widget_->SetFocusTraversableParent( |
| 353 GetWidget()->GetFocusTraversable()); | 302 GetWidget()->GetFocusTraversable()); |
| 354 floating_control_buttons_widget_->SetFocusTraversableParentView(this); | 303 floating_control_buttons_widget_->SetFocusTraversableParentView(this); |
| 355 | 304 |
| 356 Layout(); | 305 Layout(); |
| 357 } | 306 } |
| 358 | 307 |
| 359 void ArcNotificationContentView::SetSurface(ArcNotificationSurface* surface) { | 308 void ArcNotificationContentView::SetSurface(ArcNotificationSurface* surface) { |
| 360 if (surface_ == surface) | 309 if (surface_ == surface) |
| 361 return; | 310 return; |
| 362 | 311 |
| 363 // Reset |floating_control_buttons_widget_| when |surface_| is changed. | 312 // Reset |floating_control_buttons_widget_| when |surface_| is changed. |
| 364 floating_control_buttons_widget_.reset(); | 313 floating_control_buttons_widget_.reset(); |
| 365 control_buttons_view_ = nullptr; | 314 control_buttons_view_ = nullptr; |
| 366 settings_button_ = nullptr; | |
| 367 close_button_.reset(); | |
| 368 | 315 |
| 369 if (surface_ && surface_->GetWindow()) { | 316 if (surface_ && surface_->GetWindow()) { |
| 370 surface_->GetWindow()->RemoveObserver(this); | 317 surface_->GetWindow()->RemoveObserver(this); |
| 371 surface_->GetWindow()->RemovePreTargetHandler(event_forwarder_.get()); | 318 surface_->GetWindow()->RemovePreTargetHandler(event_forwarder_.get()); |
| 372 | 319 |
| 373 if (GetWidget() && surface_->IsAttached()) | 320 if (GetWidget() && surface_->IsAttached()) |
| 374 surface_->Detach(); | 321 surface_->Detach(); |
| 375 } | 322 } |
| 376 | 323 |
| 377 surface_ = surface; | 324 surface_ = surface; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 399 const float scale = static_cast<float>(message_center::kNotificationWidth) / | 346 const float scale = static_cast<float>(message_center::kNotificationWidth) / |
| 400 preferred_size.width(); | 347 preferred_size.width(); |
| 401 preferred_size.SetSize(message_center::kNotificationWidth, | 348 preferred_size.SetSize(message_center::kNotificationWidth, |
| 402 preferred_size.height() * scale); | 349 preferred_size.height() * scale); |
| 403 } | 350 } |
| 404 | 351 |
| 405 SetPreferredSize(preferred_size); | 352 SetPreferredSize(preferred_size); |
| 406 } | 353 } |
| 407 | 354 |
| 408 void ArcNotificationContentView::UpdateControlButtonsVisibility() { | 355 void ArcNotificationContentView::UpdateControlButtonsVisibility() { |
| 409 if (!floating_control_buttons_widget_) | 356 if (!control_buttons_view_) |
| 410 return; | 357 return; |
| 411 | 358 |
| 359 DCHECK(floating_control_buttons_widget_); | |
| 360 | |
| 412 const bool target_visiblity = | 361 const bool target_visiblity = |
| 413 IsMouseHovered() || (close_button_ && close_button_->HasFocus()) || | 362 IsMouseHovered() || (control_buttons_view_->IsCloseButtonFocused()) || |
| 414 (settings_button_ && settings_button_->HasFocus()); | 363 (control_buttons_view_->IsSettingsButtonFocused()); |
| 364 | |
| 415 if (target_visiblity == floating_control_buttons_widget_->IsVisible()) | 365 if (target_visiblity == floating_control_buttons_widget_->IsVisible()) |
| 416 return; | 366 return; |
| 417 | 367 |
| 418 if (target_visiblity) | 368 if (target_visiblity) |
| 419 floating_control_buttons_widget_->Show(); | 369 floating_control_buttons_widget_->Show(); |
| 420 else | 370 else |
| 421 floating_control_buttons_widget_->Hide(); | 371 floating_control_buttons_widget_->Hide(); |
| 422 } | 372 } |
| 423 | 373 |
| 424 void ArcNotificationContentView::UpdatePinnedState() { | 374 void ArcNotificationContentView::UpdatePinnedState() { |
| 425 if (!item_) | 375 if (!item_) |
| 426 return; | 376 return; |
| 427 | 377 |
| 428 // Surface is not attached yet. | 378 // Surface is not attached yet. |
| 429 if (!control_buttons_view_) | 379 if (!control_buttons_view_) |
| 430 return; | 380 return; |
| 431 | 381 |
| 432 if (item_->GetPinned() && close_button_) { | 382 control_buttons_view_->ShowCloseButton(!item_->GetPinned()); |
| 433 control_buttons_view_->RemoveChildView(close_button_.get()); | 383 Layout(); |
| 434 close_button_.reset(); | |
| 435 Layout(); | |
| 436 } else if (!item_->GetPinned() && !close_button_) { | |
| 437 CreateCloseButton(); | |
| 438 Layout(); | |
| 439 } | |
| 440 } | 384 } |
| 441 | 385 |
| 442 void ArcNotificationContentView::UpdateSnapshot() { | 386 void ArcNotificationContentView::UpdateSnapshot() { |
| 443 // Bail if we have a |surface_| because it controls the sizes and paints UI. | 387 // Bail if we have a |surface_| because it controls the sizes and paints UI. |
| 444 if (surface_) | 388 if (surface_) |
| 445 return; | 389 return; |
| 446 | 390 |
| 447 UpdatePreferredSize(); | 391 UpdatePreferredSize(); |
| 448 SchedulePaint(); | 392 SchedulePaint(); |
| 449 } | 393 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 465 // Creates slide helper after this view is added to its parent. | 409 // Creates slide helper after this view is added to its parent. |
| 466 slide_helper_.reset(new SlideHelper(this)); | 410 slide_helper_.reset(new SlideHelper(this)); |
| 467 | 411 |
| 468 // Invokes Update() in case surface is attached during a slide. | 412 // Invokes Update() in case surface is attached during a slide. |
| 469 slide_helper_->Update(); | 413 slide_helper_->Update(); |
| 470 | 414 |
| 471 // (Re-)create the floating buttons after |surface_| is attached to a widget. | 415 // (Re-)create the floating buttons after |surface_| is attached to a widget. |
| 472 MaybeCreateFloatingControlButtons(); | 416 MaybeCreateFloatingControlButtons(); |
| 473 } | 417 } |
| 474 | 418 |
| 475 void ArcNotificationContentView::StartControlButtonsColorAnimation() { | |
| 476 if (control_button_color_animation_) | |
| 477 control_button_color_animation_->End(); | |
| 478 control_button_color_animation_.reset(new gfx::LinearAnimation(this)); | |
| 479 control_button_color_animation_->SetDuration(kBackgroundColorChangeDuration); | |
| 480 control_button_color_animation_->Start(); | |
| 481 } | |
| 482 | |
| 483 bool ArcNotificationContentView::ShouldUpdateControlButtonsColor() const { | |
| 484 // Don't update the control button color when we are about to be destroyed. | |
| 485 if (!item_) | |
| 486 return false; | |
| 487 | |
| 488 if (settings_button_ && | |
| 489 settings_button_->background()->get_color() != | |
| 490 GetControlButtonBackgroundColor(item_->GetShownContents())) | |
| 491 return true; | |
| 492 if (close_button_ && | |
| 493 close_button_->background()->get_color() != | |
| 494 GetControlButtonBackgroundColor(item_->GetShownContents())) | |
| 495 return true; | |
| 496 return false; | |
| 497 } | |
| 498 | |
| 499 void ArcNotificationContentView::UpdateAccessibleName() { | 419 void ArcNotificationContentView::UpdateAccessibleName() { |
| 500 // Don't update the accessible name when we are about to be destroyed. | 420 // Don't update the accessible name when we are about to be destroyed. |
| 501 if (!item_) | 421 if (!item_) |
| 502 return; | 422 return; |
| 503 | 423 |
| 504 accessible_name_ = item_->GetAccessibleName(); | 424 accessible_name_ = item_->GetAccessibleName(); |
| 505 } | 425 } |
| 506 | 426 |
| 507 void ArcNotificationContentView::ViewHierarchyChanged( | 427 void ArcNotificationContentView::ViewHierarchyChanged( |
| 508 const views::View::ViewHierarchyChangedDetails& details) { | 428 const views::View::ViewHierarchyChangedDetails& details) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 if (!surface_size.IsEmpty() && !contents_size.IsEmpty()) { | 468 if (!surface_size.IsEmpty() && !contents_size.IsEmpty()) { |
| 549 transform.Scale( | 469 transform.Scale( |
| 550 static_cast<float>(contents_size.width()) / surface_size.width(), | 470 static_cast<float>(contents_size.width()) / surface_size.width(), |
| 551 static_cast<float>(contents_size.height()) / surface_size.height()); | 471 static_cast<float>(contents_size.height()) / surface_size.height()); |
| 552 } | 472 } |
| 553 | 473 |
| 554 // Apply the transform to the surface content so that close button can | 474 // Apply the transform to the surface content so that close button can |
| 555 // be positioned without the need to consider the transform. | 475 // be positioned without the need to consider the transform. |
| 556 surface_->GetContentWindow()->SetTransform(transform); | 476 surface_->GetContentWindow()->SetTransform(transform); |
| 557 | 477 |
| 558 if (!floating_control_buttons_widget_) | 478 if (control_buttons_view_) { |
| 559 return; | 479 DCHECK(floating_control_buttons_widget_); |
| 480 gfx::Rect control_buttons_bounds(contents_bounds); | |
| 481 int buttons_width = control_buttons_view_->GetPreferredSize().width(); | |
| 482 int buttons_height = control_buttons_view_->GetPreferredSize().height(); | |
| 560 | 483 |
| 561 gfx::Rect control_buttons_bounds(contents_bounds); | 484 control_buttons_bounds.set_x(control_buttons_bounds.right() - |
| 562 int buttons_width = 0; | 485 buttons_width - |
| 563 int buttons_height = 0; | 486 message_center::kControlButtonPadding); |
| 564 if (close_button_) { | 487 control_buttons_bounds.set_y(control_buttons_bounds.y() + |
| 565 buttons_width += close_button_->GetPreferredSize().width(); | 488 message_center::kControlButtonPadding); |
| 566 buttons_height = close_button_->GetPreferredSize().height(); | 489 control_buttons_bounds.set_width(buttons_width); |
| 490 control_buttons_bounds.set_height(buttons_height); | |
| 491 floating_control_buttons_widget_->SetBounds(control_buttons_bounds); | |
| 567 } | 492 } |
| 568 if (settings_button_) { | |
| 569 buttons_width += settings_button_->GetPreferredSize().width(); | |
| 570 buttons_height = settings_button_->GetPreferredSize().height(); | |
| 571 } | |
| 572 control_buttons_bounds.set_x(control_buttons_bounds.right() - buttons_width - | |
| 573 message_center::kControlButtonPadding); | |
| 574 control_buttons_bounds.set_y(control_buttons_bounds.y() + | |
| 575 message_center::kControlButtonPadding); | |
| 576 control_buttons_bounds.set_width(buttons_width); | |
| 577 control_buttons_bounds.set_height(buttons_height); | |
| 578 floating_control_buttons_widget_->SetBounds(control_buttons_bounds); | |
| 579 | 493 |
| 580 UpdateControlButtonsVisibility(); | 494 UpdateControlButtonsVisibility(); |
| 581 | 495 |
| 582 ash::wm::SnapWindowToPixelBoundary(surface_->GetWindow()); | 496 ash::wm::SnapWindowToPixelBoundary(surface_->GetWindow()); |
| 583 } | 497 } |
| 584 | 498 |
| 585 void ArcNotificationContentView::OnPaint(gfx::Canvas* canvas) { | 499 void ArcNotificationContentView::OnPaint(gfx::Canvas* canvas) { |
| 586 views::NativeViewHost::OnPaint(canvas); | 500 views::NativeViewHost::OnPaint(canvas); |
| 587 | 501 |
| 588 // Bail if there is a |surface_| or no item or no snapshot image. | 502 // Bail if there is a |surface_| or no item or no snapshot image. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 void ArcNotificationContentView::GetAccessibleNodeData( | 563 void ArcNotificationContentView::GetAccessibleNodeData( |
| 650 ui::AXNodeData* node_data) { | 564 ui::AXNodeData* node_data) { |
| 651 node_data->role = ui::AX_ROLE_BUTTON; | 565 node_data->role = ui::AX_ROLE_BUTTON; |
| 652 node_data->AddStringAttribute( | 566 node_data->AddStringAttribute( |
| 653 ui::AX_ATTR_ROLE_DESCRIPTION, | 567 ui::AX_ATTR_ROLE_DESCRIPTION, |
| 654 l10n_util::GetStringUTF8( | 568 l10n_util::GetStringUTF8( |
| 655 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); | 569 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); |
| 656 node_data->SetName(accessible_name_); | 570 node_data->SetName(accessible_name_); |
| 657 } | 571 } |
| 658 | 572 |
| 659 void ArcNotificationContentView::ButtonPressed(views::Button* sender, | |
| 660 const ui::Event& event) { | |
| 661 if (item_ && !item_->GetPinned() && sender == close_button_.get()) { | |
| 662 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); | |
| 663 static_cast<ArcNotificationView*>(parent())->OnCloseButtonPressed(); | |
| 664 } | |
| 665 if (item_ && settings_button_ && sender == settings_button_) { | |
| 666 item_->OpenSettings(); | |
| 667 } | |
| 668 } | |
| 669 | |
| 670 void ArcNotificationContentView::OnWindowBoundsChanged( | 573 void ArcNotificationContentView::OnWindowBoundsChanged( |
| 671 aura::Window* window, | 574 aura::Window* window, |
| 672 const gfx::Rect& old_bounds, | 575 const gfx::Rect& old_bounds, |
| 673 const gfx::Rect& new_bounds) { | 576 const gfx::Rect& new_bounds) { |
| 674 if (in_layout_) | 577 if (in_layout_) |
| 675 return; | 578 return; |
| 676 | 579 |
| 677 UpdatePreferredSize(); | 580 UpdatePreferredSize(); |
| 678 Layout(); | 581 Layout(); |
| 679 } | 582 } |
| 680 | 583 |
| 681 void ArcNotificationContentView::OnWindowDestroying(aura::Window* window) { | 584 void ArcNotificationContentView::OnWindowDestroying(aura::Window* window) { |
| 682 SetSurface(nullptr); | 585 SetSurface(nullptr); |
| 683 } | 586 } |
| 684 | 587 |
| 685 void ArcNotificationContentView::OnItemDestroying() { | 588 void ArcNotificationContentView::OnItemDestroying() { |
| 686 item_->RemoveObserver(this); | 589 item_->RemoveObserver(this); |
| 687 item_ = nullptr; | 590 item_ = nullptr; |
| 688 | 591 |
| 689 // Reset |surface_| with |item_| since no one is observing the |surface_| | 592 // Reset |surface_| with |item_| since no one is observing the |surface_| |
| 690 // after |item_| is gone and this view should be removed soon. | 593 // after |item_| is gone and this view should be removed soon. |
| 691 SetSurface(nullptr); | 594 SetSurface(nullptr); |
| 692 } | 595 } |
| 693 | 596 |
| 694 void ArcNotificationContentView::OnItemUpdated() { | 597 void ArcNotificationContentView::OnItemUpdated() { |
| 695 UpdateAccessibleName(); | 598 UpdateAccessibleName(); |
| 696 UpdatePinnedState(); | 599 UpdatePinnedState(); |
| 697 UpdateSnapshot(); | 600 UpdateSnapshot(); |
| 698 if (ShouldUpdateControlButtonsColor()) | 601 if (control_buttons_view_) { |
| 699 StartControlButtonsColorAnimation(); | 602 DCHECK(floating_control_buttons_widget_); |
| 603 control_buttons_view_->SetBackgroundColor( | |
| 604 GetControlButtonBackgroundColor(item_->GetShownContents())); | |
| 605 } | |
| 700 } | 606 } |
| 701 | 607 |
| 702 void ArcNotificationContentView::OnNotificationSurfaceAdded( | 608 void ArcNotificationContentView::OnNotificationSurfaceAdded( |
| 703 ArcNotificationSurface* surface) { | 609 ArcNotificationSurface* surface) { |
| 704 if (surface->GetNotificationKey() != notification_key_) | 610 if (surface->GetNotificationKey() != notification_key_) |
| 705 return; | 611 return; |
| 706 | 612 |
| 707 SetSurface(surface); | 613 SetSurface(surface); |
| 708 } | 614 } |
| 709 | 615 |
| 710 void ArcNotificationContentView::OnNotificationSurfaceRemoved( | 616 void ArcNotificationContentView::OnNotificationSurfaceRemoved( |
| 711 ArcNotificationSurface* surface) { | 617 ArcNotificationSurface* surface) { |
| 712 if (surface->GetNotificationKey() != notification_key_) | 618 if (surface->GetNotificationKey() != notification_key_) |
| 713 return; | 619 return; |
| 714 | 620 |
| 715 SetSurface(nullptr); | 621 SetSurface(nullptr); |
| 716 } | 622 } |
| 717 | 623 |
| 718 void ArcNotificationContentView::AnimationEnded( | |
| 719 const gfx::Animation* animation) { | |
| 720 DCHECK_EQ(animation, control_button_color_animation_.get()); | |
| 721 control_button_color_animation_.reset(); | |
| 722 } | |
| 723 | |
| 724 void ArcNotificationContentView::AnimationProgressed( | |
| 725 const gfx::Animation* animation) { | |
| 726 DCHECK_EQ(animation, control_button_color_animation_.get()); | |
| 727 | |
| 728 if (item_) { | |
| 729 const SkColor target = | |
| 730 GetControlButtonBackgroundColor(item_->GetShownContents()); | |
| 731 const SkColor start = | |
| 732 target == message_center::kControlButtonBackgroundColor | |
| 733 ? SK_ColorTRANSPARENT | |
| 734 : message_center::kControlButtonBackgroundColor; | |
| 735 const SkColor current_color = gfx::Tween::ColorValueBetween( | |
| 736 animation->GetCurrentValue(), start, target); | |
| 737 if (settings_button_) { | |
| 738 settings_button_->SetBackground( | |
| 739 views::CreateSolidBackground(current_color)); | |
| 740 settings_button_->SchedulePaint(); | |
| 741 } | |
| 742 if (close_button_) { | |
| 743 close_button_->SetBackground(views::CreateSolidBackground(current_color)); | |
| 744 close_button_->SchedulePaint(); | |
| 745 } | |
| 746 } | |
| 747 } | |
| 748 | |
| 749 } // namespace arc | 624 } // namespace arc |
| OLD | NEW |