| 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/system/tray/tray_background_view.h" | 5 #include "ash/system/tray/tray_background_view.h" |
| 6 | 6 |
| 7 #include "ash/material_design/material_design_controller.h" |
| 7 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 8 #include "ash/screen_util.h" | 9 #include "ash/screen_util.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_util.h" | 11 #include "ash/shelf/shelf_util.h" |
| 11 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
| 12 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 13 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
| 14 #include "ash/system/status_area_widget.h" | 15 #include "ash/system/status_area_widget.h" |
| 15 #include "ash/system/status_area_widget_delegate.h" | 16 #include "ash/system/status_area_widget_delegate.h" |
| 16 #include "ash/system/tray/system_tray.h" | 17 #include "ash/system/tray/system_tray.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 188 |
| 188 void TrayBackgroundView::TrayContainer::ViewHierarchyChanged( | 189 void TrayBackgroundView::TrayContainer::ViewHierarchyChanged( |
| 189 const ViewHierarchyChangedDetails& details) { | 190 const ViewHierarchyChangedDetails& details) { |
| 190 if (details.parent == this) | 191 if (details.parent == this) |
| 191 PreferredSizeChanged(); | 192 PreferredSizeChanged(); |
| 192 } | 193 } |
| 193 | 194 |
| 194 void TrayBackgroundView::TrayContainer::UpdateLayout() { | 195 void TrayBackgroundView::TrayContainer::UpdateLayout() { |
| 195 // Adjust the size of status tray dark background by adding additional | 196 // Adjust the size of status tray dark background by adding additional |
| 196 // empty border. | 197 // empty border. |
| 197 if (wm::IsHorizontalAlignment(alignment_)) { | 198 views::BoxLayout::Orientation orientation = |
| 198 SetBorder(views::Border::CreateEmptyBorder( | 199 wm::IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal |
| 199 kPaddingFromEdgeOfShelf, | 200 : views::BoxLayout::kVertical; |
| 200 kPaddingFromEdgeOfShelf, | 201 SetBorder(views::Border::CreateEmptyBorder( |
| 201 kPaddingFromEdgeOfShelf, | 202 kAdjustBackgroundPadding, kAdjustBackgroundPadding, |
| 202 kPaddingFromEdgeOfShelf)); | 203 kAdjustBackgroundPadding, kAdjustBackgroundPadding)); |
| 203 | 204 |
| 204 views::BoxLayout* layout = | 205 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); |
| 205 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 206 layout->SetDefaultFlex(1); |
| 206 layout->SetDefaultFlex(1); | 207 views::View::SetLayoutManager(layout); |
| 207 views::View::SetLayoutManager(layout); | |
| 208 } else { | |
| 209 SetBorder(views::Border::CreateEmptyBorder( | |
| 210 kPaddingFromEdgeOfShelf, | |
| 211 kPaddingFromEdgeOfShelf, | |
| 212 kPaddingFromEdgeOfShelf, | |
| 213 kPaddingFromEdgeOfShelf)); | |
| 214 | |
| 215 views::BoxLayout* layout = | |
| 216 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
| 217 layout->SetDefaultFlex(1); | |
| 218 views::View::SetLayoutManager(layout); | |
| 219 } | |
| 220 PreferredSizeChanged(); | 208 PreferredSizeChanged(); |
| 221 } | 209 } |
| 222 | 210 |
| 223 //////////////////////////////////////////////////////////////////////////////// | 211 //////////////////////////////////////////////////////////////////////////////// |
| 224 // TrayBackgroundView | 212 // TrayBackgroundView |
| 225 | 213 |
| 226 TrayBackgroundView::TrayBackgroundView(StatusAreaWidget* status_area_widget) | 214 TrayBackgroundView::TrayBackgroundView(StatusAreaWidget* status_area_widget) |
| 227 : status_area_widget_(status_area_widget), | 215 : status_area_widget_(status_area_widget), |
| 228 tray_container_(NULL), | 216 tray_container_(NULL), |
| 229 shelf_alignment_(wm::SHELF_ALIGNMENT_BOTTOM), | 217 shelf_alignment_(wm::SHELF_ALIGNMENT_BOTTOM), |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 return status_area_widget()->shelf_widget()->shelf_layout_manager(); | 393 return status_area_widget()->shelf_widget()->shelf_layout_manager(); |
| 406 } | 394 } |
| 407 | 395 |
| 408 void TrayBackgroundView::SetShelfAlignment(wm::ShelfAlignment alignment) { | 396 void TrayBackgroundView::SetShelfAlignment(wm::ShelfAlignment alignment) { |
| 409 shelf_alignment_ = alignment; | 397 shelf_alignment_ = alignment; |
| 410 SetTrayBorder(); | 398 SetTrayBorder(); |
| 411 tray_container_->SetAlignment(alignment); | 399 tray_container_->SetAlignment(alignment); |
| 412 } | 400 } |
| 413 | 401 |
| 414 void TrayBackgroundView::SetTrayBorder() { | 402 void TrayBackgroundView::SetTrayBorder() { |
| 415 views::View* parent = status_area_widget_->status_area_widget_delegate(); | 403 gfx::Insets inset; |
| 416 // Tray views are laid out right-to-left or bottom-to-top | 404 GetHitRegionInsets(inset); |
| 417 bool on_edge = (this == parent->child_at(0)); | 405 |
| 418 int left_edge, top_edge, right_edge, bottom_edge; | 406 SetBorder(views::Border::CreateEmptyBorder(inset.top(), inset.left(), |
| 419 if (wm::IsHorizontalAlignment(shelf_alignment())) { | 407 inset.bottom(), inset.right())); |
| 420 top_edge = ShelfLayoutManager::kShelfItemInset; | |
| 421 left_edge = 0; | |
| 422 bottom_edge = kShelfSize - | |
| 423 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; | |
| 424 right_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; | |
| 425 } else if (shelf_alignment() == wm::SHELF_ALIGNMENT_LEFT) { | |
| 426 top_edge = 0; | |
| 427 left_edge = kShelfSize - | |
| 428 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; | |
| 429 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; | |
| 430 right_edge = ShelfLayoutManager::kShelfItemInset; | |
| 431 } else { // SHELF_ALIGNMENT_RIGHT | |
| 432 top_edge = 0; | |
| 433 left_edge = ShelfLayoutManager::kShelfItemInset; | |
| 434 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; | |
| 435 right_edge = kShelfSize - | |
| 436 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; | |
| 437 } | |
| 438 SetBorder(views::Border::CreateEmptyBorder( | |
| 439 top_edge, left_edge, bottom_edge, right_edge)); | |
| 440 } | 408 } |
| 441 | 409 |
| 442 void TrayBackgroundView::OnImplicitAnimationsCompleted() { | 410 void TrayBackgroundView::OnImplicitAnimationsCompleted() { |
| 443 // If there is another animation in the queue, the reverse animation was | 411 // If there is another animation in the queue, the reverse animation was |
| 444 // triggered before the completion of animating to invisible. Do not turn off | 412 // triggered before the completion of animating to invisible. Do not turn off |
| 445 // the visibility so that the next animation may render. The value of | 413 // the visibility so that the next animation may render. The value of |
| 446 // layer()->GetTargetVisibility() can be incorrect if the hide animation was | 414 // layer()->GetTargetVisibility() can be incorrect if the hide animation was |
| 447 // aborted to schedule an animation to become visible. As the new animation | 415 // aborted to schedule an animation to become visible. As the new animation |
| 448 // is not yet added to the queue. crbug.com/374236 | 416 // is not yet added to the queue. crbug.com/374236 |
| 449 if(layer()->GetAnimator()->is_animating() || | 417 if(layer()->GetAnimator()->is_animating() || |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 else | 549 else |
| 582 background_->set_alpha(kTrayBackgroundAlpha); | 550 background_->set_alpha(kTrayBackgroundAlpha); |
| 583 SchedulePaint(); | 551 SchedulePaint(); |
| 584 } | 552 } |
| 585 | 553 |
| 586 void TrayBackgroundView::UpdateBubbleViewArrow( | 554 void TrayBackgroundView::UpdateBubbleViewArrow( |
| 587 views::TrayBubbleView* bubble_view) { | 555 views::TrayBubbleView* bubble_view) { |
| 588 // Nothing to do here. | 556 // Nothing to do here. |
| 589 } | 557 } |
| 590 | 558 |
| 559 void TrayBackgroundView::GetHitRegionInsets(gfx::Insets& insets) { |
| 560 int top_edge, left_edge, bottom_edge, right_edge; |
| 561 // Tray views are laid out right-to-left or bottom-to-top |
| 562 if (MaterialDesignController::IsShelfMaterial()) { |
| 563 if (wm::IsHorizontalAlignment(shelf_alignment())) { |
| 564 top_edge = (GetShelfLayoutConstant(SHELF_SIZE) - kShelfItemHeight) / 2; |
| 565 left_edge = 0; |
| 566 bottom_edge = (GetShelfLayoutConstant(SHELF_SIZE) - kShelfItemHeight) / 2; |
| 567 right_edge = 0; |
| 568 } else { // SHELF_ALIGNMENT_LEFT || SHELF_ALIGNMENT_RIGHT |
| 569 top_edge = 0; |
| 570 left_edge = (GetShelfLayoutConstant(SHELF_SIZE) - kShelfItemHeight) / 2; |
| 571 bottom_edge = 0; |
| 572 right_edge = (GetShelfLayoutConstant(SHELF_SIZE) - kShelfItemHeight) / 2; |
| 573 } |
| 574 } else { |
| 575 views::View* parent = status_area_widget_->status_area_widget_delegate(); |
| 576 bool on_edge = (this == parent->child_at(0)); |
| 577 |
| 578 if (wm::IsHorizontalAlignment(shelf_alignment())) { |
| 579 top_edge = kShelfItemInset; |
| 580 left_edge = 0; |
| 581 bottom_edge = GetShelfLayoutConstant(SHELF_SIZE) - kShelfItemInset - |
| 582 kShelfItemHeight; |
| 583 right_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0; |
| 584 } else if (shelf_alignment() == wm::SHELF_ALIGNMENT_LEFT) { |
| 585 top_edge = 0; |
| 586 left_edge = GetShelfLayoutConstant(SHELF_SIZE) - kShelfItemInset - |
| 587 kShelfItemHeight; |
| 588 bottom_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0; |
| 589 right_edge = kShelfItemInset; |
| 590 } else { // SHELF_ALIGNMENT_RIGHT |
| 591 top_edge = 0; |
| 592 left_edge = kShelfItemInset; |
| 593 bottom_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0; |
| 594 right_edge = GetShelfLayoutConstant(SHELF_SIZE) - kShelfItemInset - |
| 595 kShelfItemHeight; |
| 596 } |
| 597 } |
| 598 insets.Set(top_edge, left_edge, bottom_edge, right_edge); |
| 599 } |
| 591 } // namespace ash | 600 } // namespace ash |
| OLD | NEW |