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

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

Issue 2729533002: Adjust behavior of control buttons of notifications. (Closed)
Patch Set: Add unimplemented method to TestContentViewDelegate Created 3 years, 9 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 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"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 bool IsCloseButtonFocused() const override { 161 bool IsCloseButtonFocused() const override {
162 if (owner_->close_button_ == nullptr) 162 if (owner_->close_button_ == nullptr)
163 return false; 163 return false;
164 return owner_->close_button_->HasFocus(); 164 return owner_->close_button_->HasFocus();
165 } 165 }
166 166
167 void RequestFocusOnCloseButton() override { 167 void RequestFocusOnCloseButton() override {
168 if (owner_->close_button_) 168 if (owner_->close_button_)
169 owner_->close_button_->RequestFocus(); 169 owner_->close_button_->RequestFocus();
170 owner_->UpdateControlButtonsVisiblity(); 170 owner_->UpdateControlButtonsVisibility();
171 } 171 }
172 172
173 bool IsPinned() const override { 173 bool IsPinned() const override {
174 return owner_->item_->pinned(); 174 return owner_->item_->pinned();
175 } 175 }
176 176
177 void UpdateControlButtonsVisibility() override {
178 owner_->UpdateControlButtonsVisibility();
179 }
180
177 private: 181 private:
178 ArcCustomNotificationView* const owner_; 182 ArcCustomNotificationView* const owner_;
179 183
180 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); 184 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate);
181 }; 185 };
182 186
183 class ArcCustomNotificationView::ControlButton 187 class ArcCustomNotificationView::ControlButton
184 : public message_center::PaddedButton { 188 : public message_center::PaddedButton {
185 public: 189 public:
186 explicit ControlButton(ArcCustomNotificationView* owner) 190 explicit ControlButton(ArcCustomNotificationView* owner)
187 : message_center::PaddedButton(owner), owner_(owner) {} 191 : message_center::PaddedButton(owner), owner_(owner) {}
188 192
189 void OnFocus() override { 193 void OnFocus() override {
190 message_center::PaddedButton::OnFocus(); 194 message_center::PaddedButton::OnFocus();
191 owner_->UpdateControlButtonsVisiblity(); 195 owner_->UpdateControlButtonsVisibility();
192 } 196 }
193 197
194 void OnBlur() override { 198 void OnBlur() override {
195 message_center::PaddedButton::OnBlur(); 199 message_center::PaddedButton::OnBlur();
196 owner_->UpdateControlButtonsVisiblity(); 200 owner_->UpdateControlButtonsVisibility();
197 } 201 }
198 202
199 private: 203 private:
200 ArcCustomNotificationView* const owner_; 204 ArcCustomNotificationView* const owner_;
201 }; 205 };
202 206
203 ArcCustomNotificationView::ArcCustomNotificationView( 207 ArcCustomNotificationView::ArcCustomNotificationView(
204 ArcCustomNotificationItem* item) 208 ArcCustomNotificationItem* item)
205 : item_(item), 209 : item_(item),
206 notification_key_(item->notification_key()), 210 notification_key_(item->notification_key()),
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 if (preferred_size.width() != message_center::kNotificationWidth) { 322 if (preferred_size.width() != message_center::kNotificationWidth) {
319 const float scale = static_cast<float>(message_center::kNotificationWidth) / 323 const float scale = static_cast<float>(message_center::kNotificationWidth) /
320 preferred_size.width(); 324 preferred_size.width();
321 preferred_size.SetSize(message_center::kNotificationWidth, 325 preferred_size.SetSize(message_center::kNotificationWidth,
322 preferred_size.height() * scale); 326 preferred_size.height() * scale);
323 } 327 }
324 328
325 SetPreferredSize(preferred_size); 329 SetPreferredSize(preferred_size);
326 } 330 }
327 331
328 void ArcCustomNotificationView::UpdateControlButtonsVisiblity() { 332 void ArcCustomNotificationView::UpdateControlButtonsVisibility() {
329 if (!surface_ || !floating_control_buttons_widget_) 333 if (!surface_ || !floating_control_buttons_widget_)
330 return; 334 return;
331 335
332 const bool target_visiblity = 336 const bool target_visiblity =
333 surface_->window()->GetBoundsInScreen().Contains( 337 surface_->window()->GetBoundsInScreen().Contains(
334 display::Screen::GetScreen()->GetCursorScreenPoint()) || 338 display::Screen::GetScreen()->GetCursorScreenPoint()) ||
335 close_button_->HasFocus() || settings_button_->HasFocus(); 339 close_button_->HasFocus() || settings_button_->HasFocus();
336 if (target_visiblity == floating_control_buttons_widget_->IsVisible()) 340 if (target_visiblity == floating_control_buttons_widget_->IsVisible())
337 return; 341 return;
338 342
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 return; 442 return;
439 443
440 gfx::Rect control_buttons_bounds(contents_bounds); 444 gfx::Rect control_buttons_bounds(contents_bounds);
441 const int buttons_width = close_button_->GetPreferredSize().width() + 445 const int buttons_width = close_button_->GetPreferredSize().width() +
442 settings_button_->GetPreferredSize().width(); 446 settings_button_->GetPreferredSize().width();
443 control_buttons_bounds.set_x(control_buttons_bounds.right() - buttons_width); 447 control_buttons_bounds.set_x(control_buttons_bounds.right() - buttons_width);
444 control_buttons_bounds.set_height(close_button_->GetPreferredSize().height()); 448 control_buttons_bounds.set_height(close_button_->GetPreferredSize().height());
445 control_buttons_bounds.set_width(buttons_width); 449 control_buttons_bounds.set_width(buttons_width);
446 floating_control_buttons_widget_->SetBounds(control_buttons_bounds); 450 floating_control_buttons_widget_->SetBounds(control_buttons_bounds);
447 451
448 UpdateControlButtonsVisiblity(); 452 UpdateControlButtonsVisibility();
449 453
450 ash::wm::SnapWindowToPixelBoundary(surface_->window()); 454 ash::wm::SnapWindowToPixelBoundary(surface_->window());
451 } 455 }
452 456
453 void ArcCustomNotificationView::OnPaint(gfx::Canvas* canvas) { 457 void ArcCustomNotificationView::OnPaint(gfx::Canvas* canvas) {
454 views::NativeViewHost::OnPaint(canvas); 458 views::NativeViewHost::OnPaint(canvas);
455 459
456 // Bail if there is a |surface_| or no item or no snapshot image. 460 // Bail if there is a |surface_| or no item or no snapshot image.
457 if (surface_ || !item_ || item_->snapshot().isNull()) 461 if (surface_ || !item_ || item_->snapshot().isNull())
458 return; 462 return;
(...skipping 12 matching lines...) Expand all
471 void ArcCustomNotificationView::OnGestureEvent(ui::GestureEvent* event) { 475 void ArcCustomNotificationView::OnGestureEvent(ui::GestureEvent* event) {
472 // Forward to parent CustomNotificationView to handle sliding out. 476 // Forward to parent CustomNotificationView to handle sliding out.
473 parent()->OnGestureEvent(event); 477 parent()->OnGestureEvent(event);
474 478
475 // |slide_helper_| could be null before |surface_| is attached. 479 // |slide_helper_| could be null before |surface_| is attached.
476 if (slide_helper_) 480 if (slide_helper_)
477 slide_helper_->Update(); 481 slide_helper_->Update();
478 } 482 }
479 483
480 void ArcCustomNotificationView::OnMouseEntered(const ui::MouseEvent&) { 484 void ArcCustomNotificationView::OnMouseEntered(const ui::MouseEvent&) {
481 UpdateControlButtonsVisiblity(); 485 UpdateControlButtonsVisibility();
482 } 486 }
483 487
484 void ArcCustomNotificationView::OnMouseExited(const ui::MouseEvent&) { 488 void ArcCustomNotificationView::OnMouseExited(const ui::MouseEvent&) {
485 UpdateControlButtonsVisiblity(); 489 UpdateControlButtonsVisibility();
486 } 490 }
487 491
488 void ArcCustomNotificationView::OnFocus() { 492 void ArcCustomNotificationView::OnFocus() {
489 NativeViewHost::OnFocus(); 493 NativeViewHost::OnFocus();
490 static_cast<message_center::CustomNotificationView*>(parent()) 494 static_cast<message_center::CustomNotificationView*>(parent())
491 ->OnContentFocused(); 495 ->OnContentFocused();
492 } 496 }
493 497
494 void ArcCustomNotificationView::OnBlur() { 498 void ArcCustomNotificationView::OnBlur() {
495 NativeViewHost::OnBlur(); 499 NativeViewHost::OnBlur();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 557
554 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( 558 void ArcCustomNotificationView::OnNotificationSurfaceRemoved(
555 exo::NotificationSurface* surface) { 559 exo::NotificationSurface* surface) {
556 if (surface->notification_id() != notification_key_) 560 if (surface->notification_id() != notification_key_)
557 return; 561 return;
558 562
559 SetSurface(nullptr); 563 SetSurface(nullptr);
560 } 564 }
561 565
562 } // namespace arc 566 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698