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/common/shelf/wm_shelf_util.h" |
7 #include "ash/common/shell_window_ids.h" | 8 #include "ash/common/shell_window_ids.h" |
8 #include "ash/common/wm/shelf/wm_shelf_util.h" | |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
11 #include "ash/shelf/shelf_layout_manager.h" | 11 #include "ash/shelf/shelf_layout_manager.h" |
12 #include "ash/shelf/shelf_util.h" | 12 #include "ash/shelf/shelf_util.h" |
13 #include "ash/shelf/shelf_widget.h" | 13 #include "ash/shelf/shelf_widget.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "ash/system/status_area_widget.h" | 15 #include "ash/system/status_area_widget.h" |
16 #include "ash/system/status_area_widget_delegate.h" | 16 #include "ash/system/status_area_widget_delegate.h" |
17 #include "ash/system/tray/system_tray.h" | 17 #include "ash/system/tray/system_tray.h" |
18 #include "ash/system/tray/tray_constants.h" | 18 #include "ash/system/tray/tray_constants.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 ->Paint(canvas, view->GetLocalBounds()); | 150 ->Paint(canvas, view->GetLocalBounds()); |
151 } | 151 } |
152 | 152 |
153 SkColor color_; | 153 SkColor color_; |
154 // Reference to the TrayBackgroundView for which this is a background. | 154 // Reference to the TrayBackgroundView for which this is a background. |
155 TrayBackgroundView* tray_background_view_; | 155 TrayBackgroundView* tray_background_view_; |
156 | 156 |
157 DISALLOW_COPY_AND_ASSIGN(TrayBackground); | 157 DISALLOW_COPY_AND_ASSIGN(TrayBackground); |
158 }; | 158 }; |
159 | 159 |
160 TrayBackgroundView::TrayContainer::TrayContainer(wm::ShelfAlignment alignment) | 160 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment) |
161 : alignment_(alignment) { | 161 : alignment_(alignment) { |
162 UpdateLayout(); | 162 UpdateLayout(); |
163 } | 163 } |
164 | 164 |
165 void TrayBackgroundView::TrayContainer::SetAlignment( | 165 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) { |
166 wm::ShelfAlignment alignment) { | |
167 if (alignment_ == alignment) | 166 if (alignment_ == alignment) |
168 return; | 167 return; |
169 alignment_ = alignment; | 168 alignment_ = alignment; |
170 UpdateLayout(); | 169 UpdateLayout(); |
171 } | 170 } |
172 | 171 |
173 gfx::Size TrayBackgroundView::TrayContainer::GetPreferredSize() const { | 172 gfx::Size TrayBackgroundView::TrayContainer::GetPreferredSize() const { |
174 if (size_.IsEmpty()) | 173 if (size_.IsEmpty()) |
175 return views::View::GetPreferredSize(); | 174 return views::View::GetPreferredSize(); |
176 return size_; | 175 return size_; |
(...skipping 10 matching lines...) Expand all Loading... |
187 | 186 |
188 void TrayBackgroundView::TrayContainer::ViewHierarchyChanged( | 187 void TrayBackgroundView::TrayContainer::ViewHierarchyChanged( |
189 const ViewHierarchyChangedDetails& details) { | 188 const ViewHierarchyChangedDetails& details) { |
190 if (details.parent == this) | 189 if (details.parent == this) |
191 PreferredSizeChanged(); | 190 PreferredSizeChanged(); |
192 } | 191 } |
193 | 192 |
194 void TrayBackgroundView::TrayContainer::UpdateLayout() { | 193 void TrayBackgroundView::TrayContainer::UpdateLayout() { |
195 // Adjust the size of status tray dark background by adding additional | 194 // Adjust the size of status tray dark background by adding additional |
196 // empty border. | 195 // empty border. |
197 if (wm::IsHorizontalAlignment(alignment_)) { | 196 if (IsHorizontalAlignment(alignment_)) { |
198 SetBorder(views::Border::CreateEmptyBorder( | 197 SetBorder(views::Border::CreateEmptyBorder( |
199 kPaddingFromEdgeOfShelf, | 198 kPaddingFromEdgeOfShelf, |
200 kPaddingFromEdgeOfShelf, | 199 kPaddingFromEdgeOfShelf, |
201 kPaddingFromEdgeOfShelf, | 200 kPaddingFromEdgeOfShelf, |
202 kPaddingFromEdgeOfShelf)); | 201 kPaddingFromEdgeOfShelf)); |
203 | 202 |
204 views::BoxLayout* layout = | 203 views::BoxLayout* layout = |
205 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 204 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
206 layout->SetDefaultFlex(1); | 205 layout->SetDefaultFlex(1); |
207 views::View::SetLayoutManager(layout); | 206 views::View::SetLayoutManager(layout); |
(...skipping 11 matching lines...) Expand all Loading... |
219 } | 218 } |
220 PreferredSizeChanged(); | 219 PreferredSizeChanged(); |
221 } | 220 } |
222 | 221 |
223 //////////////////////////////////////////////////////////////////////////////// | 222 //////////////////////////////////////////////////////////////////////////////// |
224 // TrayBackgroundView | 223 // TrayBackgroundView |
225 | 224 |
226 TrayBackgroundView::TrayBackgroundView(StatusAreaWidget* status_area_widget) | 225 TrayBackgroundView::TrayBackgroundView(StatusAreaWidget* status_area_widget) |
227 : status_area_widget_(status_area_widget), | 226 : status_area_widget_(status_area_widget), |
228 tray_container_(NULL), | 227 tray_container_(NULL), |
229 shelf_alignment_(wm::SHELF_ALIGNMENT_BOTTOM), | 228 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
230 background_(NULL), | 229 background_(NULL), |
231 hide_background_animator_(this, 0, kTrayBackgroundAlpha), | 230 hide_background_animator_(this, 0, kTrayBackgroundAlpha), |
232 hover_background_animator_( | 231 hover_background_animator_( |
233 this, | 232 this, |
234 0, | 233 0, |
235 kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha), | 234 kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha), |
236 hovered_(false), | 235 hovered_(false), |
237 draw_background_as_active_(false), | 236 draw_background_as_active_(false), |
238 widget_observer_(new TrayWidgetObserver(this)) { | 237 widget_observer_(new TrayWidgetObserver(this)) { |
239 set_notify_enter_exit_on_child(true); | 238 set_notify_enter_exit_on_child(true); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 397 |
399 void TrayBackgroundView::SetContentsBackground() { | 398 void TrayBackgroundView::SetContentsBackground() { |
400 background_ = new TrayBackground(this); | 399 background_ = new TrayBackground(this); |
401 tray_container_->set_background(background_); | 400 tray_container_->set_background(background_); |
402 } | 401 } |
403 | 402 |
404 ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() { | 403 ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() { |
405 return status_area_widget()->shelf_widget()->shelf_layout_manager(); | 404 return status_area_widget()->shelf_widget()->shelf_layout_manager(); |
406 } | 405 } |
407 | 406 |
408 void TrayBackgroundView::SetShelfAlignment(wm::ShelfAlignment alignment) { | 407 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
409 shelf_alignment_ = alignment; | 408 shelf_alignment_ = alignment; |
410 SetTrayBorder(); | 409 SetTrayBorder(); |
411 tray_container_->SetAlignment(alignment); | 410 tray_container_->SetAlignment(alignment); |
412 } | 411 } |
413 | 412 |
414 void TrayBackgroundView::SetTrayBorder() { | 413 void TrayBackgroundView::SetTrayBorder() { |
415 views::View* parent = status_area_widget_->status_area_widget_delegate(); | 414 views::View* parent = status_area_widget_->status_area_widget_delegate(); |
416 // Tray views are laid out right-to-left or bottom-to-top | 415 // Tray views are laid out right-to-left or bottom-to-top |
417 bool on_edge = (this == parent->child_at(0)); | 416 bool on_edge = (this == parent->child_at(0)); |
418 int left_edge, top_edge, right_edge, bottom_edge; | 417 int left_edge, top_edge, right_edge, bottom_edge; |
419 if (wm::IsHorizontalAlignment(shelf_alignment())) { | 418 if (IsHorizontalAlignment(shelf_alignment())) { |
420 top_edge = ShelfLayoutManager::kShelfItemInset; | 419 top_edge = ShelfLayoutManager::kShelfItemInset; |
421 left_edge = 0; | 420 left_edge = 0; |
422 bottom_edge = kShelfSize - | 421 bottom_edge = kShelfSize - |
423 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; | 422 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; |
424 right_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; | 423 right_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
425 } else if (shelf_alignment() == wm::SHELF_ALIGNMENT_LEFT) { | 424 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { |
426 top_edge = 0; | 425 top_edge = 0; |
427 left_edge = kShelfSize - | 426 left_edge = kShelfSize - |
428 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; | 427 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; |
429 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; | 428 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
430 right_edge = ShelfLayoutManager::kShelfItemInset; | 429 right_edge = ShelfLayoutManager::kShelfItemInset; |
431 } else { // SHELF_ALIGNMENT_RIGHT | 430 } else { // SHELF_ALIGNMENT_RIGHT |
432 top_edge = 0; | 431 top_edge = 0; |
433 left_edge = ShelfLayoutManager::kShelfItemInset; | 432 left_edge = ShelfLayoutManager::kShelfItemInset; |
434 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; | 433 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
435 right_edge = kShelfSize - | 434 right_edge = kShelfSize - |
(...skipping 20 matching lines...) Expand all Loading... |
456 // This is needed so that OnImplicitAnimationsCompleted() is called even upon | 455 // This is needed so that OnImplicitAnimationsCompleted() is called even upon |
457 // destruction of the animator. This can occure when parallel animations | 456 // destruction of the animator. This can occure when parallel animations |
458 // caused by ScreenRotationAnimator end before the animations of | 457 // caused by ScreenRotationAnimator end before the animations of |
459 // TrayBackgroundView. This allows for a proper update to the visual state of | 458 // TrayBackgroundView. This allows for a proper update to the visual state of |
460 // the view. (crbug.com/476667) | 459 // the view. (crbug.com/476667) |
461 return true; | 460 return true; |
462 } | 461 } |
463 | 462 |
464 void TrayBackgroundView::HideTransformation() { | 463 void TrayBackgroundView::HideTransformation() { |
465 gfx::Transform transform; | 464 gfx::Transform transform; |
466 if (wm::IsHorizontalAlignment(shelf_alignment_)) | 465 if (IsHorizontalAlignment(shelf_alignment_)) |
467 transform.Translate(width(), 0.0f); | 466 transform.Translate(width(), 0.0f); |
468 else | 467 else |
469 transform.Translate(0.0f, height()); | 468 transform.Translate(0.0f, height()); |
470 layer()->SetTransform(transform); | 469 layer()->SetTransform(transform); |
471 } | 470 } |
472 | 471 |
473 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { | 472 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { |
474 return ash::Shell::GetContainer( | 473 return ash::Shell::GetContainer( |
475 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), | 474 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), |
476 ash::kShellWindowId_SettingBubbleContainer); | 475 ash::kShellWindowId_SettingBubbleContainer); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 kPaddingFromRightEdgeOfScreenBottomAlignment : | 551 kPaddingFromRightEdgeOfScreenBottomAlignment : |
553 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, | 552 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, |
554 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, | 553 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, |
555 0, 0); | 554 0, 0); |
556 } | 555 } |
557 } | 556 } |
558 return rect; | 557 return rect; |
559 } | 558 } |
560 | 559 |
561 TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const { | 560 TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const { |
562 if (shelf_alignment_ == wm::SHELF_ALIGNMENT_LEFT) | 561 if (shelf_alignment_ == SHELF_ALIGNMENT_LEFT) |
563 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT; | 562 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT; |
564 if (shelf_alignment_ == wm::SHELF_ALIGNMENT_RIGHT) | 563 if (shelf_alignment_ == SHELF_ALIGNMENT_RIGHT) |
565 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; | 564 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; |
566 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; | 565 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; |
567 } | 566 } |
568 | 567 |
569 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) { | 568 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) { |
570 if (draw_background_as_active_ == visible) | 569 if (draw_background_as_active_ == visible) |
571 return; | 570 return; |
572 draw_background_as_active_ = visible; | 571 draw_background_as_active_ = visible; |
573 if (!background_) | 572 if (!background_) |
574 return; | 573 return; |
575 | 574 |
576 // Do not change gradually, changing color between grey and blue is weird. | 575 // Do not change gradually, changing color between grey and blue is weird. |
577 if (draw_background_as_active_) | 576 if (draw_background_as_active_) |
578 background_->set_color(kTrayBackgroundPressedColor); | 577 background_->set_color(kTrayBackgroundPressedColor); |
579 else if (hovered_) | 578 else if (hovered_) |
580 background_->set_alpha(kTrayBackgroundHoverAlpha); | 579 background_->set_alpha(kTrayBackgroundHoverAlpha); |
581 else | 580 else |
582 background_->set_alpha(kTrayBackgroundAlpha); | 581 background_->set_alpha(kTrayBackgroundAlpha); |
583 SchedulePaint(); | 582 SchedulePaint(); |
584 } | 583 } |
585 | 584 |
586 void TrayBackgroundView::UpdateBubbleViewArrow( | 585 void TrayBackgroundView::UpdateBubbleViewArrow( |
587 views::TrayBubbleView* bubble_view) { | 586 views::TrayBubbleView* bubble_view) { |
588 // Nothing to do here. | 587 // Nothing to do here. |
589 } | 588 } |
590 | 589 |
591 } // namespace ash | 590 } // namespace ash |
OLD | NEW |