| OLD | NEW |
| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 views::BoxLayout::Orientation orientation = | 238 views::BoxLayout::Orientation orientation = |
| 239 is_horizontal ? views::BoxLayout::kHorizontal | 239 is_horizontal ? views::BoxLayout::kHorizontal |
| 240 : views::BoxLayout::kVertical; | 240 : views::BoxLayout::kVertical; |
| 241 const gfx::Insets insets( | 241 const gfx::Insets insets( |
| 242 ash::MaterialDesignController::IsShelfMaterial() | 242 ash::MaterialDesignController::IsShelfMaterial() |
| 243 ? is_horizontal ? gfx::Insets(0, kHitRegionPadding, 0, | 243 ? is_horizontal ? gfx::Insets(0, kHitRegionPadding, 0, |
| 244 kHitRegionPadding + kSeparatorWidth) | 244 kHitRegionPadding + kSeparatorWidth) |
| 245 : gfx::Insets(kHitRegionPadding, 0, | 245 : gfx::Insets(kHitRegionPadding, 0, |
| 246 kHitRegionPadding + kSeparatorWidth, 0) | 246 kHitRegionPadding + kSeparatorWidth, 0) |
| 247 : gfx::Insets(kBackgroundAdjustPadding)); | 247 : gfx::Insets(kBackgroundAdjustPadding)); |
| 248 const gfx::Insets margin( | 248 SetBorder(views::CreateEmptyBorder(insets)); |
| 249 is_horizontal ? gfx::Insets(cross_axis_margin_, main_axis_margin_) | |
| 250 : gfx::Insets(main_axis_margin_, cross_axis_margin_)); | |
| 251 SetBorder(views::CreateEmptyBorder(insets + margin)); | |
| 252 | 249 |
| 253 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); | 250 int horizontal_margin = main_axis_margin_; |
| 251 int vertical_margin = cross_axis_margin_; |
| 252 if (!is_horizontal) |
| 253 std::swap(horizontal_margin, vertical_margin); |
| 254 views::BoxLayout* layout = |
| 255 new views::BoxLayout(orientation, horizontal_margin, vertical_margin, 0); |
| 256 |
| 254 if (!ash::MaterialDesignController::IsShelfMaterial()) | 257 if (!ash::MaterialDesignController::IsShelfMaterial()) |
| 255 layout->SetDefaultFlex(1); | 258 layout->SetDefaultFlex(1); |
| 256 layout->set_minimum_cross_axis_size(kTrayItemSize); | 259 layout->set_minimum_cross_axis_size(kTrayItemSize); |
| 257 views::View::SetLayoutManager(layout); | 260 views::View::SetLayoutManager(layout); |
| 258 | 261 |
| 259 PreferredSizeChanged(); | 262 PreferredSizeChanged(); |
| 260 } | 263 } |
| 261 | 264 |
| 262 //////////////////////////////////////////////////////////////////////////////// | 265 //////////////////////////////////////////////////////////////////////////////// |
| 263 // TrayBackgroundView | 266 // TrayBackgroundView |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 SetIsActive(false); | 412 SetIsActive(false); |
| 410 } | 413 } |
| 411 } | 414 } |
| 412 ActionableView::OnGestureEvent(event); | 415 ActionableView::OnGestureEvent(event); |
| 413 } | 416 } |
| 414 | 417 |
| 415 void TrayBackgroundView::SetContents(views::View* contents) { | 418 void TrayBackgroundView::SetContents(views::View* contents) { |
| 416 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 419 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 417 AddChildView(contents); | 420 AddChildView(contents); |
| 418 } | 421 } |
| 422 |
| 419 void TrayBackgroundView::SetContentsBackground(bool draws_active) { | 423 void TrayBackgroundView::SetContentsBackground(bool draws_active) { |
| 420 background_ = new TrayBackground(this, draws_active); | 424 background_ = new TrayBackground(this, draws_active); |
| 421 tray_container_->set_background(background_); | 425 tray_container_->set_background(background_); |
| 422 } | 426 } |
| 423 | 427 |
| 424 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { | 428 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
| 425 shelf_alignment_ = alignment; | 429 shelf_alignment_ = alignment; |
| 426 tray_container_->SetAlignment(alignment); | 430 tray_container_->SetAlignment(alignment); |
| 427 } | 431 } |
| 428 | 432 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 449 | 453 |
| 450 void TrayBackgroundView::HideTransformation() { | 454 void TrayBackgroundView::HideTransformation() { |
| 451 gfx::Transform transform; | 455 gfx::Transform transform; |
| 452 if (IsHorizontalAlignment(shelf_alignment_)) | 456 if (IsHorizontalAlignment(shelf_alignment_)) |
| 453 transform.Translate(width(), 0.0f); | 457 transform.Translate(width(), 0.0f); |
| 454 else | 458 else |
| 455 transform.Translate(0.0f, height()); | 459 transform.Translate(0.0f, height()); |
| 456 layer()->SetTransform(transform); | 460 layer()->SetTransform(transform); |
| 457 } | 461 } |
| 458 | 462 |
| 459 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect( | |
| 460 views::Widget* anchor_widget, | |
| 461 TrayBubbleView::AnchorType anchor_type, | |
| 462 TrayBubbleView::AnchorAlignment anchor_alignment) const { | |
| 463 gfx::Rect rect; | |
| 464 if (anchor_widget && anchor_widget->IsVisible()) { | |
| 465 rect = anchor_widget->GetWindowBoundsInScreen(); | |
| 466 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) { | |
| 467 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | |
| 468 bool rtl = base::i18n::IsRTL(); | |
| 469 rect.Inset(rtl ? kBubblePaddingHorizontalSide : 0, | |
| 470 kBubblePaddingHorizontalBottom, | |
| 471 rtl ? 0 : kBubblePaddingHorizontalSide, 0); | |
| 472 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { | |
| 473 rect.Inset(0, 0, kBubblePaddingVerticalSide + 4, | |
| 474 kBubblePaddingVerticalBottom); | |
| 475 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) { | |
| 476 rect.Inset(kBubblePaddingVerticalSide, 0, 0, | |
| 477 kBubblePaddingVerticalBottom); | |
| 478 } else { | |
| 479 // TODO(bruthig) May need to handle other ANCHOR_ALIGNMENT_ values. | |
| 480 // ie. ANCHOR_ALIGNMENT_TOP | |
| 481 DCHECK(false) << "Unhandled anchor alignment."; | |
| 482 } | |
| 483 } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) { | |
| 484 // Invert the offsets to align with the bubble below. | |
| 485 // Note that with the alternate shelf layout the tips are not shown and | |
| 486 // the offsets for left and right alignment do not need to be applied. | |
| 487 int vertical_alignment = 0; | |
| 488 int horizontal_alignment = kBubblePaddingVerticalBottom; | |
| 489 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) | |
| 490 rect.Inset(vertical_alignment, 0, 0, horizontal_alignment); | |
| 491 else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) | |
| 492 rect.Inset(0, 0, vertical_alignment, horizontal_alignment); | |
| 493 } else { | |
| 494 DCHECK(false) << "Unhandled anchor type."; | |
| 495 } | |
| 496 } else { | |
| 497 WmWindow* target_root = anchor_widget | |
| 498 ? WmLookup::Get() | |
| 499 ->GetWindowForWidget(anchor_widget) | |
| 500 ->GetRootWindow() | |
| 501 : WmShell::Get()->GetPrimaryRootWindow(); | |
| 502 rect = target_root->GetBounds(); | |
| 503 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) { | |
| 504 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | |
| 505 rect = gfx::Rect( | |
| 506 base::i18n::IsRTL() | |
| 507 ? kPaddingFromRightEdgeOfScreenBottomAlignment | |
| 508 : rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, | |
| 509 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 0, 0); | |
| 510 rect = target_root->ConvertRectToScreen(rect); | |
| 511 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { | |
| 512 rect = gfx::Rect( | |
| 513 kPaddingFromRightEdgeOfScreenBottomAlignment, | |
| 514 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 1, 1); | |
| 515 rect = target_root->ConvertRectToScreen(rect); | |
| 516 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) { | |
| 517 rect = gfx::Rect( | |
| 518 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, | |
| 519 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 1, 1); | |
| 520 rect = target_root->ConvertRectToScreen(rect); | |
| 521 } else { | |
| 522 // TODO(bruthig) May need to handle other ANCHOR_ALIGNMENT_ values. | |
| 523 // ie. ANCHOR_ALIGNMENT_TOP | |
| 524 DCHECK(false) << "Unhandled anchor alignment."; | |
| 525 } | |
| 526 } else { | |
| 527 rect = gfx::Rect( | |
| 528 base::i18n::IsRTL() | |
| 529 ? kPaddingFromRightEdgeOfScreenBottomAlignment | |
| 530 : rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, | |
| 531 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 0, 0); | |
| 532 } | |
| 533 } | |
| 534 return rect; | |
| 535 } | |
| 536 | |
| 537 TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const { | 463 TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const { |
| 538 if (shelf_alignment_ == SHELF_ALIGNMENT_LEFT) | 464 if (shelf_alignment_ == SHELF_ALIGNMENT_LEFT) |
| 539 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT; | 465 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT; |
| 540 if (shelf_alignment_ == SHELF_ALIGNMENT_RIGHT) | 466 if (shelf_alignment_ == SHELF_ALIGNMENT_RIGHT) |
| 541 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; | 467 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; |
| 542 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; | 468 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; |
| 543 } | 469 } |
| 544 | 470 |
| 545 void TrayBackgroundView::SetIsActive(bool is_active) { | 471 void TrayBackgroundView::SetIsActive(bool is_active) { |
| 546 if (is_active_ == is_active) | 472 if (is_active_ == is_active) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 566 background_->set_alpha(alpha); | 492 background_->set_alpha(alpha); |
| 567 SchedulePaint(); | 493 SchedulePaint(); |
| 568 } | 494 } |
| 569 } | 495 } |
| 570 | 496 |
| 571 void TrayBackgroundView::SetSeparatorVisibility(bool is_shown) { | 497 void TrayBackgroundView::SetSeparatorVisibility(bool is_shown) { |
| 572 is_separator_visible_ = is_shown; | 498 is_separator_visible_ = is_shown; |
| 573 SchedulePaint(); | 499 SchedulePaint(); |
| 574 } | 500 } |
| 575 | 501 |
| 502 views::View* TrayBackgroundView::GetBubbleAnchor() const { |
| 503 return tray_container_; |
| 504 } |
| 505 |
| 506 gfx::Insets TrayBackgroundView::GetBubbleAnchorInsets() const { |
| 507 gfx::Insets anchor_insets = GetBubbleAnchor()->GetInsets(); |
| 508 gfx::Insets tray_bg_insets = GetInsets(); |
| 509 // TODO(estade): for reasons I don't understand, BubbleBorder distances the |
| 510 // bubble by the arrow's "interior" thickness even when the paint type is |
| 511 // PAINT_NONE. |
| 512 const int kBigShadowArrowInteriorThickness = 9; |
| 513 if (GetAnchorAlignment() == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { |
| 514 return gfx::Insets(kBigShadowArrowInteriorThickness - tray_bg_insets.top(), |
| 515 anchor_insets.left(), -tray_bg_insets.bottom(), |
| 516 anchor_insets.right()); |
| 517 } else { |
| 518 return gfx::Insets( |
| 519 anchor_insets.top(), |
| 520 kBigShadowArrowInteriorThickness - tray_bg_insets.left(), |
| 521 anchor_insets.bottom(), |
| 522 kBigShadowArrowInteriorThickness - tray_bg_insets.right()); |
| 523 } |
| 524 } |
| 525 |
| 576 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() | 526 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() |
| 577 const { | 527 const { |
| 578 return base::MakeUnique<views::RoundRectInkDropMask>( | 528 return base::MakeUnique<views::RoundRectInkDropMask>( |
| 579 GetLocalBounds(), | 529 GetLocalBounds(), |
| 580 GetBackgroundBounds(GetContentsBounds(), shelf_alignment_), | 530 GetBackgroundBounds(GetContentsBounds(), shelf_alignment_), |
| 581 kTrayRoundedBorderRadius); | 531 kTrayRoundedBorderRadius); |
| 582 } | 532 } |
| 583 | 533 |
| 584 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { | 534 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { |
| 585 if (is_active_) | 535 if (is_active_) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 paint.setAntiAlias(true); | 582 paint.setAntiAlias(true); |
| 633 | 583 |
| 634 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height) | 584 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height) |
| 635 : gfx::Rect(y, x, height, width); | 585 : gfx::Rect(y, x, height, width); |
| 636 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale)); | 586 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale)); |
| 637 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(), | 587 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(), |
| 638 rect.bottom_right(), paint); | 588 rect.bottom_right(), paint); |
| 639 } | 589 } |
| 640 | 590 |
| 641 } // namespace ash | 591 } // namespace ash |
| OLD | NEW |