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

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

Issue 2763913003: Hide the settings button on a notification in MNC. (Closed)
Patch Set: 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 close_button_->SetImage(views::CustomButton::STATE_NORMAL, 242 close_button_->SetImage(views::CustomButton::STATE_NORMAL,
243 message_center::GetCloseIcon()); 243 message_center::GetCloseIcon());
244 close_button_->SetAccessibleName(l10n_util::GetStringUTF16( 244 close_button_->SetAccessibleName(l10n_util::GetStringUTF16(
245 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); 245 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME));
246 close_button_->SetTooltipText(l10n_util::GetStringUTF16( 246 close_button_->SetTooltipText(l10n_util::GetStringUTF16(
247 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP)); 247 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP));
248 close_button_->set_owned_by_client(); 248 close_button_->set_owned_by_client();
249 control_buttons_view_->AddChildView(close_button_.get()); 249 control_buttons_view_->AddChildView(close_button_.get());
250 } 250 }
251 251
252 void ArcCustomNotificationView::CreateSettingsButton() {
253 DCHECK(control_buttons_view_);
254
255 settings_button_ = new ControlButton(this);
256 settings_button_->SetImage(views::CustomButton::STATE_NORMAL,
257 message_center::GetSettingsIcon());
258 settings_button_->SetAccessibleName(l10n_util::GetStringUTF16(
259 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME));
260 settings_button_->SetTooltipText(l10n_util::GetStringUTF16(
261 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME));
262 control_buttons_view_->AddChildView(settings_button_);
263 }
264
252 void ArcCustomNotificationView::CreateFloatingControlButtons() { 265 void ArcCustomNotificationView::CreateFloatingControlButtons() {
253 // Floating close button is a transient child of |surface_| and also part 266 // Floating close button is a transient child of |surface_| and also part
254 // of the hosting widget's focus chain. It could only be created when both 267 // of the hosting widget's focus chain. It could only be created when both
255 // are present. 268 // are present.
256 if (!surface_ || !GetWidget()) 269 if (!surface_ || !GetWidget())
257 return; 270 return;
258 271
259 // Creates the control_buttons_view_, which collects all control buttons into 272 // Creates the control_buttons_view_, which collects all control buttons into
260 // a horizontal box. 273 // a horizontal box.
261 control_buttons_view_ = new views::View(); 274 control_buttons_view_ = new views::View();
262 control_buttons_view_->SetLayoutManager( 275 control_buttons_view_->SetLayoutManager(
263 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); 276 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
264 277
265 settings_button_ = new ControlButton(this); 278 if (item_ && item_->IsOpeningSettingsSupported())
266 settings_button_->SetImage(views::CustomButton::STATE_NORMAL, 279 CreateSettingsButton();
267 message_center::GetSettingsIcon());
268 settings_button_->SetAccessibleName(l10n_util::GetStringUTF16(
269 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME));
270 settings_button_->SetTooltipText(l10n_util::GetStringUTF16(
271 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME));
272 control_buttons_view_->AddChildView(settings_button_);
273
274 CreateCloseButton(); 280 CreateCloseButton();
275 281
276 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); 282 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
277 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 283 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
278 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 284 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
279 params.parent = surface_->window(); 285 params.parent = surface_->window();
280 286
281 floating_control_buttons_widget_.reset(new views::Widget); 287 floating_control_buttons_widget_.reset(new views::Widget);
282 floating_control_buttons_widget_->Init(params); 288 floating_control_buttons_widget_->Init(params);
283 floating_control_buttons_widget_->SetContentsView(control_buttons_view_); 289 floating_control_buttons_widget_->SetContentsView(control_buttons_view_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 preferred_size.height() * scale); 338 preferred_size.height() * scale);
333 } 339 }
334 340
335 SetPreferredSize(preferred_size); 341 SetPreferredSize(preferred_size);
336 } 342 }
337 343
338 void ArcCustomNotificationView::UpdateControlButtonsVisibility() { 344 void ArcCustomNotificationView::UpdateControlButtonsVisibility() {
339 if (!surface_ || !floating_control_buttons_widget_) 345 if (!surface_ || !floating_control_buttons_widget_)
340 return; 346 return;
341 347
342 const bool target_visiblity = IsMouseHovered() || 348 const bool target_visiblity =
343 (close_button_ && close_button_->HasFocus()) || 349 IsMouseHovered() || (close_button_ && close_button_->HasFocus()) ||
344 settings_button_->HasFocus(); 350 (settings_button_ && settings_button_->HasFocus());
345 if (target_visiblity == floating_control_buttons_widget_->IsVisible()) 351 if (target_visiblity == floating_control_buttons_widget_->IsVisible())
346 return; 352 return;
347 353
348 if (target_visiblity) 354 if (target_visiblity)
349 floating_control_buttons_widget_->Show(); 355 floating_control_buttons_widget_->Show();
350 else 356 else
351 floating_control_buttons_widget_->Hide(); 357 floating_control_buttons_widget_->Hide();
352 } 358 }
353 359
354 void ArcCustomNotificationView::UpdatePinnedState() { 360 void ArcCustomNotificationView::UpdatePinnedState() {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 450
445 // Apply the transform to the surface content so that close button can 451 // Apply the transform to the surface content so that close button can
446 // be positioned without the need to consider the transform. 452 // be positioned without the need to consider the transform.
447 surface_->window()->children()[0]->SetTransform(transform); 453 surface_->window()->children()[0]->SetTransform(transform);
448 454
449 if (!floating_control_buttons_widget_) 455 if (!floating_control_buttons_widget_)
450 return; 456 return;
451 457
452 gfx::Rect control_buttons_bounds(contents_bounds); 458 gfx::Rect control_buttons_bounds(contents_bounds);
453 int buttons_width = 0; 459 int buttons_width = 0;
454 if (close_button_) 460 int buttons_height = 0;
461 if (close_button_) {
455 buttons_width += close_button_->GetPreferredSize().width(); 462 buttons_width += close_button_->GetPreferredSize().width();
456 if (settings_button_) 463 buttons_height = close_button_->GetPreferredSize().height();
464 }
465 if (settings_button_) {
457 buttons_width += settings_button_->GetPreferredSize().width(); 466 buttons_width += settings_button_->GetPreferredSize().width();
467 buttons_height = settings_button_->GetPreferredSize().height();
468 }
458 control_buttons_bounds.set_x(control_buttons_bounds.right() - buttons_width - 469 control_buttons_bounds.set_x(control_buttons_bounds.right() - buttons_width -
459 message_center::kControlButtonPadding); 470 message_center::kControlButtonPadding);
460 control_buttons_bounds.set_y(control_buttons_bounds.y() + 471 control_buttons_bounds.set_y(control_buttons_bounds.y() +
461 message_center::kControlButtonPadding); 472 message_center::kControlButtonPadding);
462 control_buttons_bounds.set_height(
463 settings_button_->GetPreferredSize().height());
464 control_buttons_bounds.set_width(buttons_width); 473 control_buttons_bounds.set_width(buttons_width);
474 control_buttons_bounds.set_height(buttons_height);
465 floating_control_buttons_widget_->SetBounds(control_buttons_bounds); 475 floating_control_buttons_widget_->SetBounds(control_buttons_bounds);
466 476
467 UpdateControlButtonsVisibility(); 477 UpdateControlButtonsVisibility();
468 478
469 ash::wm::SnapWindowToPixelBoundary(surface_->window()); 479 ash::wm::SnapWindowToPixelBoundary(surface_->window());
470 } 480 }
471 481
472 void ArcCustomNotificationView::OnPaint(gfx::Canvas* canvas) { 482 void ArcCustomNotificationView::OnPaint(gfx::Canvas* canvas) {
473 views::NativeViewHost::OnPaint(canvas); 483 views::NativeViewHost::OnPaint(canvas);
474 484
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 599
590 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( 600 void ArcCustomNotificationView::OnNotificationSurfaceRemoved(
591 exo::NotificationSurface* surface) { 601 exo::NotificationSurface* surface) {
592 if (surface->notification_id() != notification_key_) 602 if (surface->notification_id() != notification_key_)
593 return; 603 return;
594 604
595 SetSurface(nullptr); 605 SetSurface(nullptr);
596 } 606 }
597 607
598 } // namespace arc 608 } // namespace arc
OLDNEW
« no previous file with comments | « ui/arc/notification/arc_custom_notification_view.h ('k') | ui/arc/notification/arc_notification_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698