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

Side by Side Diff: ash/common/system/tray/tray_background_view.cc

Issue 2491033006: Adjust positioning of cros tray bubbles. (Closed)
Patch Set: rebase and update bug link Created 4 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/common/system/tray/tray_background_view.h" 5 #include "ash/common/system/tray/tray_background_view.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/shelf/shelf_constants.h" 8 #include "ash/common/shelf/shelf_constants.h"
9 #include "ash/common/shelf/wm_shelf.h" 9 #include "ash/common/shelf/wm_shelf.h"
10 #include "ash/common/shelf/wm_shelf_util.h" 10 #include "ash/common/shelf/wm_shelf_util.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 views::BoxLayout::Orientation orientation = 226 views::BoxLayout::Orientation orientation =
227 is_horizontal ? views::BoxLayout::kHorizontal 227 is_horizontal ? views::BoxLayout::kHorizontal
228 : views::BoxLayout::kVertical; 228 : views::BoxLayout::kVertical;
229 const gfx::Insets insets( 229 const gfx::Insets insets(
230 ash::MaterialDesignController::IsShelfMaterial() 230 ash::MaterialDesignController::IsShelfMaterial()
231 ? is_horizontal ? gfx::Insets(0, kHitRegionPadding, 0, 231 ? is_horizontal ? gfx::Insets(0, kHitRegionPadding, 0,
232 kHitRegionPadding + kSeparatorWidth) 232 kHitRegionPadding + kSeparatorWidth)
233 : gfx::Insets(kHitRegionPadding, 0, 233 : gfx::Insets(kHitRegionPadding, 0,
234 kHitRegionPadding + kSeparatorWidth, 0) 234 kHitRegionPadding + kSeparatorWidth, 0)
235 : gfx::Insets(kBackgroundAdjustPadding)); 235 : gfx::Insets(kBackgroundAdjustPadding));
236 const gfx::Insets margin( 236 SetBorder(views::CreateEmptyBorder(insets));
237 is_horizontal ? gfx::Insets(cross_axis_margin_, main_axis_margin_)
238 : gfx::Insets(main_axis_margin_, cross_axis_margin_));
239 SetBorder(views::CreateEmptyBorder(insets + margin));
240 237
241 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); 238 int horizontal_margin = main_axis_margin_;
239 int vertical_margin = cross_axis_margin_;
240 if (!is_horizontal)
241 std::swap(horizontal_margin, vertical_margin);
242 views::BoxLayout* layout =
243 new views::BoxLayout(orientation, horizontal_margin, vertical_margin, 0);
244
242 if (!ash::MaterialDesignController::IsShelfMaterial()) 245 if (!ash::MaterialDesignController::IsShelfMaterial())
243 layout->SetDefaultFlex(1); 246 layout->SetDefaultFlex(1);
244 layout->set_minimum_cross_axis_size(kTrayItemSize); 247 layout->set_minimum_cross_axis_size(kTrayItemSize);
245 views::View::SetLayoutManager(layout); 248 views::View::SetLayoutManager(layout);
246 249
247 PreferredSizeChanged(); 250 PreferredSizeChanged();
248 } 251 }
249 252
250 //////////////////////////////////////////////////////////////////////////////// 253 ////////////////////////////////////////////////////////////////////////////////
251 // TrayBackgroundView 254 // TrayBackgroundView
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 event->type() == ui::ET_GESTURE_TAP_CANCEL) { 385 event->type() == ui::ET_GESTURE_TAP_CANCEL) {
383 SetDrawBackgroundAsActive(false); 386 SetDrawBackgroundAsActive(false);
384 } 387 }
385 ActionableView::OnGestureEvent(event); 388 ActionableView::OnGestureEvent(event);
386 } 389 }
387 390
388 void TrayBackgroundView::SetContents(views::View* contents) { 391 void TrayBackgroundView::SetContents(views::View* contents) {
389 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 392 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
390 AddChildView(contents); 393 AddChildView(contents);
391 } 394 }
395
392 void TrayBackgroundView::SetContentsBackground() { 396 void TrayBackgroundView::SetContentsBackground() {
393 background_ = new TrayBackground(this); 397 background_ = new TrayBackground(this);
394 tray_container_->set_background(background_); 398 tray_container_->set_background(background_);
395 } 399 }
396 400
397 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { 401 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) {
398 shelf_alignment_ = alignment; 402 shelf_alignment_ = alignment;
399 tray_container_->SetAlignment(alignment); 403 tray_container_->SetAlignment(alignment);
400 } 404 }
401 405
(...skipping 20 matching lines...) Expand all
422 426
423 void TrayBackgroundView::HideTransformation() { 427 void TrayBackgroundView::HideTransformation() {
424 gfx::Transform transform; 428 gfx::Transform transform;
425 if (IsHorizontalAlignment(shelf_alignment_)) 429 if (IsHorizontalAlignment(shelf_alignment_))
426 transform.Translate(width(), 0.0f); 430 transform.Translate(width(), 0.0f);
427 else 431 else
428 transform.Translate(0.0f, height()); 432 transform.Translate(0.0f, height());
429 layer()->SetTransform(transform); 433 layer()->SetTransform(transform);
430 } 434 }
431 435
432 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect(
433 views::Widget* anchor_widget,
434 TrayBubbleView::AnchorType anchor_type,
435 TrayBubbleView::AnchorAlignment anchor_alignment) const {
436 gfx::Rect rect;
437 if (anchor_widget && anchor_widget->IsVisible()) {
438 rect = anchor_widget->GetWindowBoundsInScreen();
439 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) {
440 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
441 bool rtl = base::i18n::IsRTL();
442 rect.Inset(rtl ? kBubblePaddingHorizontalSide : 0,
443 kBubblePaddingHorizontalBottom,
444 rtl ? 0 : kBubblePaddingHorizontalSide, 0);
445 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) {
446 rect.Inset(0, 0, kBubblePaddingVerticalSide + 4,
447 kBubblePaddingVerticalBottom);
448 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) {
449 rect.Inset(kBubblePaddingVerticalSide, 0, 0,
450 kBubblePaddingVerticalBottom);
451 } else {
452 // TODO(bruthig) May need to handle other ANCHOR_ALIGNMENT_ values.
453 // ie. ANCHOR_ALIGNMENT_TOP
454 DCHECK(false) << "Unhandled anchor alignment.";
455 }
456 } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) {
457 // Invert the offsets to align with the bubble below.
458 // Note that with the alternate shelf layout the tips are not shown and
459 // the offsets for left and right alignment do not need to be applied.
460 int vertical_alignment = 0;
461 int horizontal_alignment = kBubblePaddingVerticalBottom;
462 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT)
463 rect.Inset(vertical_alignment, 0, 0, horizontal_alignment);
464 else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT)
465 rect.Inset(0, 0, vertical_alignment, horizontal_alignment);
466 } else {
467 DCHECK(false) << "Unhandled anchor type.";
468 }
469 } else {
470 WmWindow* target_root = anchor_widget
471 ? WmLookup::Get()
472 ->GetWindowForWidget(anchor_widget)
473 ->GetRootWindow()
474 : WmShell::Get()->GetPrimaryRootWindow();
475 rect = target_root->GetBounds();
476 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) {
477 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
478 rect = gfx::Rect(
479 base::i18n::IsRTL()
480 ? kPaddingFromRightEdgeOfScreenBottomAlignment
481 : rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment,
482 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 0, 0);
483 rect = target_root->ConvertRectToScreen(rect);
484 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) {
485 rect = gfx::Rect(
486 kPaddingFromRightEdgeOfScreenBottomAlignment,
487 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 1, 1);
488 rect = target_root->ConvertRectToScreen(rect);
489 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) {
490 rect = gfx::Rect(
491 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment,
492 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 1, 1);
493 rect = target_root->ConvertRectToScreen(rect);
494 } else {
495 // TODO(bruthig) May need to handle other ANCHOR_ALIGNMENT_ values.
496 // ie. ANCHOR_ALIGNMENT_TOP
497 DCHECK(false) << "Unhandled anchor alignment.";
498 }
499 } else {
500 rect = gfx::Rect(
501 base::i18n::IsRTL()
502 ? kPaddingFromRightEdgeOfScreenBottomAlignment
503 : rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment,
504 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 0, 0);
505 }
506 }
507 return rect;
508 }
509
510 TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const { 436 TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const {
511 if (shelf_alignment_ == SHELF_ALIGNMENT_LEFT) 437 if (shelf_alignment_ == SHELF_ALIGNMENT_LEFT)
512 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT; 438 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT;
513 if (shelf_alignment_ == SHELF_ALIGNMENT_RIGHT) 439 if (shelf_alignment_ == SHELF_ALIGNMENT_RIGHT)
514 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; 440 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT;
515 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; 441 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
516 } 442 }
517 443
518 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) { 444 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) {
519 if (draw_background_as_active_ == visible) 445 if (draw_background_as_active_ == visible)
(...skipping 14 matching lines...) Expand all
534 background_->set_alpha(alpha); 460 background_->set_alpha(alpha);
535 SchedulePaint(); 461 SchedulePaint();
536 } 462 }
537 } 463 }
538 464
539 void TrayBackgroundView::SetSeparatorVisibility(bool is_shown) { 465 void TrayBackgroundView::SetSeparatorVisibility(bool is_shown) {
540 is_separator_visible_ = is_shown; 466 is_separator_visible_ = is_shown;
541 SchedulePaint(); 467 SchedulePaint();
542 } 468 }
543 469
470 views::View* TrayBackgroundView::GetBubbleAnchor() const {
471 return tray_container_;
472 }
473
474 gfx::Insets TrayBackgroundView::GetBubbleAnchorInsets() const {
475 gfx::Insets anchor_insets = GetBubbleAnchor()->GetInsets();
476 gfx::Insets tray_bg_insets = GetInsets();
477 const bool bottom =
478 GetAnchorAlignment() == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
479 // TODO(estade): for reasons I don't understand, BubbleBorder distances the
msw 2016/11/15 02:59:38 What's the action on this TODO? Is it worth keepin
Evan Stade 2016/11/15 17:01:29 I think the comment has value to explain what's go
480 // bubble by the arrow's "interior" thickness even when the paint type is
481 // PAINT_NONE.
482 const int kBigShadowArrowInteriorThickness = 9;
483 return gfx::Insets(
msw 2016/11/15 02:59:38 This may be more legible with if (bottom) return .
Evan Stade 2016/11/15 17:01:29 done (still not super legible though :)
484 bottom ? kBigShadowArrowInteriorThickness - tray_bg_insets.top()
485 : anchor_insets.top(),
486 bottom ? anchor_insets.left()
487 : kBigShadowArrowInteriorThickness - tray_bg_insets.left(),
488 bottom ? -tray_bg_insets.bottom() : anchor_insets.bottom(),
489 bottom ? anchor_insets.right()
490 : kBigShadowArrowInteriorThickness - tray_bg_insets.right());
491 }
492
544 void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) { 493 void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) {
545 ActionableView::OnPaint(canvas); 494 ActionableView::OnPaint(canvas);
546 if (!MaterialDesignController::IsShelfMaterial() || 495 if (!MaterialDesignController::IsShelfMaterial() ||
547 shelf()->GetBackgroundType() == 496 shelf()->GetBackgroundType() ==
548 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT || 497 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT ||
549 !is_separator_visible_) { 498 !is_separator_visible_) {
550 return; 499 return;
551 } 500 }
552 // In the given |canvas|, draws a 1x32px separator line 4 pixel to the right 501 // In the given |canvas|, draws a 1x32px separator line 4 pixel to the right
553 // of the TrayBackgroundView. 502 // of the TrayBackgroundView.
(...skipping 12 matching lines...) Expand all
566 paint.setAntiAlias(true); 515 paint.setAntiAlias(true);
567 516
568 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height) 517 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height)
569 : gfx::Rect(y, x, height, width); 518 : gfx::Rect(y, x, height, width);
570 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale)); 519 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale));
571 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(), 520 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(),
572 rect.bottom_right(), paint); 521 rect.bottom_right(), paint);
573 } 522 }
574 523
575 } // namespace ash 524 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698