| 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" |
| 11 #include "ash/common/shell_window_ids.h" | 11 #include "ash/common/shell_window_ids.h" |
| 12 #include "ash/common/system/status_area_widget.h" |
| 12 #include "ash/common/system/tray/system_tray.h" | 13 #include "ash/common/system/tray/system_tray.h" |
| 13 #include "ash/common/system/tray/tray_constants.h" | 14 #include "ash/common/system/tray/tray_constants.h" |
| 14 #include "ash/common/system/tray/tray_event_filter.h" | 15 #include "ash/common/system/tray/tray_event_filter.h" |
| 15 #include "ash/common/wm_lookup.h" | 16 #include "ash/common/wm_lookup.h" |
| 16 #include "ash/common/wm_shell.h" | 17 #include "ash/common/wm_shell.h" |
| 17 #include "ash/common/wm_window.h" | 18 #include "ash/common/wm_window.h" |
| 18 #include "grit/ash_resources.h" | 19 #include "grit/ash_resources.h" |
| 19 #include "ui/accessibility/ax_view_state.h" | 20 #include "ui/accessibility/ax_view_state.h" |
| 20 #include "ui/base/nine_image_painter_factory.h" | 21 #include "ui/base/nine_image_painter_factory.h" |
| 21 #include "ui/compositor/layer.h" | 22 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/layer_animation_element.h" | 23 #include "ui/compositor/layer_animation_element.h" |
| 23 #include "ui/compositor/scoped_layer_animation_settings.h" | 24 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 24 #include "ui/events/event_constants.h" | 25 #include "ui/events/event_constants.h" |
| 25 #include "ui/gfx/animation/tween.h" | 26 #include "ui/gfx/animation/tween.h" |
| 26 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
| 27 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
| 29 #include "ui/gfx/geometry/size.h" |
| 28 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
| 29 #include "ui/gfx/image/image_skia_operations.h" | 31 #include "ui/gfx/image/image_skia_operations.h" |
| 30 #include "ui/gfx/nine_image_painter.h" | 32 #include "ui/gfx/nine_image_painter.h" |
| 33 #include "ui/gfx/scoped_canvas.h" |
| 31 #include "ui/gfx/skia_util.h" | 34 #include "ui/gfx/skia_util.h" |
| 32 #include "ui/gfx/transform.h" | 35 #include "ui/gfx/transform.h" |
| 33 #include "ui/views/background.h" | 36 #include "ui/views/background.h" |
| 34 #include "ui/views/layout/box_layout.h" | 37 #include "ui/views/layout/box_layout.h" |
| 35 #include "ui/wm/core/window_animations.h" | 38 #include "ui/wm/core/window_animations.h" |
| 36 | 39 |
| 37 namespace { | 40 namespace { |
| 38 | 41 |
| 39 const int kAnimationDurationForPopupMs = 200; | 42 const int kAnimationDurationForPopupMs = 200; |
| 40 | 43 |
| 41 // Duration of opacity animation for visibility changes. | 44 // Duration of opacity animation for visibility changes. |
| 42 const int kAnimationDurationForVisibilityMs = 250; | 45 const int kAnimationDurationForVisibilityMs = 250; |
| 43 | 46 |
| 44 // When becoming visible delay the animation so that StatusAreaWidgetDelegate | 47 // When becoming visible delay the animation so that StatusAreaWidgetDelegate |
| 45 // can animate sibling views out of the position to be occuped by the | 48 // can animate sibling views out of the position to be occuped by the |
| 46 // TrayBackgroundView. | 49 // TrayBackgroundView. |
| 47 const int kShowAnimationDelayMs = 100; | 50 const int kShowAnimationDelayMs = 100; |
| 48 | 51 |
| 52 // Additional padding used to adjust the user-visible size of status tray |
| 53 // and overview button dark background. |
| 54 const int kBackgroundAdjustPadding = 3; |
| 55 |
| 49 } // namespace | 56 } // namespace |
| 50 | 57 |
| 51 using views::TrayBubbleView; | 58 using views::TrayBubbleView; |
| 52 | 59 |
| 53 namespace ash { | 60 namespace ash { |
| 54 | 61 |
| 55 // static | 62 // static |
| 56 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; | 63 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; |
| 57 | 64 |
| 58 // Used to track when the anchor widget changes position on screen so that the | 65 // Used to track when the anchor widget changes position on screen so that the |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 101 |
| 95 void set_alpha(int alpha) { alpha_ = alpha; } | 102 void set_alpha(int alpha) { alpha_ = alpha; } |
| 96 | 103 |
| 97 private: | 104 private: |
| 98 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } | 105 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } |
| 99 | 106 |
| 100 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { | 107 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { |
| 101 SkPaint background_paint; | 108 SkPaint background_paint; |
| 102 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | 109 background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 103 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); | 110 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); |
| 104 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, | 111 gfx::Rect bounds; |
| 105 background_paint); | 112 gfx::Rect local_bounds = view->GetLocalBounds(); |
| 113 |
| 114 // The hit region are padded to the |view| as insets, so they are included |
| 115 // in the local bounds. Remove these regions from view because hit region is |
| 116 // invisible. |
| 117 if (IsHorizontalAlignment(GetShelf()->GetAlignment())) { |
| 118 bounds = gfx::Rect(local_bounds.x() + kHitRegionPadding, local_bounds.y(), |
| 119 local_bounds.width() - kHitRegionPadding - |
| 120 kHitRegionPadding - kSeparatorWidth, |
| 121 local_bounds.height()); |
| 122 } else { |
| 123 bounds = gfx::Rect(local_bounds.x(), local_bounds.y() + kHitRegionPadding, |
| 124 local_bounds.width(), |
| 125 local_bounds.height() - kHitRegionPadding - |
| 126 kHitRegionPadding - kSeparatorWidth); |
| 127 } |
| 128 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, background_paint); |
| 106 | 129 |
| 107 if (tray_background_view_->draw_background_as_active()) { | 130 if (tray_background_view_->draw_background_as_active()) { |
| 108 SkPaint highlight_paint; | 131 SkPaint highlight_paint; |
| 109 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); | 132 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 110 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); | 133 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); |
| 111 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, | 134 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, highlight_paint); |
| 112 highlight_paint); | |
| 113 } | 135 } |
| 114 } | 136 } |
| 115 | 137 |
| 116 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const { | 138 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const { |
| 117 const int kGridSizeForPainter = 9; | 139 const int kGridSizeForPainter = 9; |
| 118 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = { | 140 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = { |
| 119 { | 141 { |
| 120 // Horizontal | 142 // Horizontal |
| 121 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ), | 143 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ), |
| 122 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_ONBLACK), | 144 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_ONBLACK), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 if (details.parent == this) | 221 if (details.parent == this) |
| 200 PreferredSizeChanged(); | 222 PreferredSizeChanged(); |
| 201 } | 223 } |
| 202 | 224 |
| 203 void TrayBackgroundView::TrayContainer::UpdateLayout() { | 225 void TrayBackgroundView::TrayContainer::UpdateLayout() { |
| 204 // Adjust the size of status tray dark background by adding additional | 226 // Adjust the size of status tray dark background by adding additional |
| 205 // empty border. | 227 // empty border. |
| 206 views::BoxLayout::Orientation orientation = | 228 views::BoxLayout::Orientation orientation = |
| 207 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal | 229 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal |
| 208 : views::BoxLayout::kVertical; | 230 : views::BoxLayout::kVertical; |
| 209 | 231 const gfx::Insets insets( |
| 210 if (!ash::MaterialDesignController::IsShelfMaterial()) { | 232 ash::MaterialDesignController::IsShelfMaterial() |
| 211 // Additional padding used to adjust the user-visible size of status tray | 233 ? gfx::Insets(IsHorizontalAlignment(alignment_) |
| 212 // dark background. | 234 ? gfx::Insets(0, kHitRegionPadding, 0, |
| 213 const int padding = 3; | 235 kHitRegionPadding + kSeparatorWidth) |
| 214 SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(padding) + margin_)); | 236 : gfx::Insets(kHitRegionPadding, 0, |
| 215 } else { | 237 kHitRegionPadding + kSeparatorWidth, |
| 216 SetBorder(views::Border::CreateEmptyBorder(margin_)); | 238 0)) |
| 217 } | 239 : gfx::Insets(kBackgroundAdjustPadding)); |
| 218 | 240 SetBorder(views::Border::CreateEmptyBorder(insets + margin_)); |
| 219 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); | 241 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); |
| 220 layout->SetDefaultFlex(1); | 242 layout->SetDefaultFlex(1); |
| 221 views::View::SetLayoutManager(layout); | 243 views::View::SetLayoutManager(layout); |
| 222 PreferredSizeChanged(); | 244 PreferredSizeChanged(); |
| 223 } | 245 } |
| 224 | 246 |
| 225 //////////////////////////////////////////////////////////////////////////////// | 247 //////////////////////////////////////////////////////////////////////////////// |
| 226 // TrayBackgroundView | 248 // TrayBackgroundView |
| 227 | 249 |
| 228 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf) | 250 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf) |
| 229 : wm_shelf_(wm_shelf), | 251 : wm_shelf_(wm_shelf), |
| 230 tray_container_(NULL), | 252 tray_container_(NULL), |
| 231 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), | 253 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
| 232 background_(NULL), | 254 background_(NULL), |
| 233 draw_background_as_active_(false), | 255 draw_background_as_active_(false), |
| 256 is_separator_visible_(false), |
| 234 widget_observer_(new TrayWidgetObserver(this)) { | 257 widget_observer_(new TrayWidgetObserver(this)) { |
| 235 DCHECK(wm_shelf_); | 258 DCHECK(wm_shelf_); |
| 236 set_notify_enter_exit_on_child(true); | 259 set_notify_enter_exit_on_child(true); |
| 237 | 260 |
| 238 tray_container_ = new TrayContainer(shelf_alignment_); | 261 tray_container_ = new TrayContainer(shelf_alignment_); |
| 239 SetContents(tray_container_); | 262 SetContents(tray_container_); |
| 240 tray_event_filter_.reset(new TrayEventFilter); | 263 tray_event_filter_.reset(new TrayEventFilter); |
| 241 | 264 |
| 242 SetPaintToLayer(true); | 265 SetPaintToLayer(true); |
| 243 layer()->SetFillsBoundsOpaquely(false); | 266 layer()->SetFillsBoundsOpaquely(false); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 layer()->SetTransform(transform); | 330 layer()->SetTransform(transform); |
| 308 } else { | 331 } else { |
| 309 // Listen only to the hide animation. As we cannot turn off visibility | 332 // Listen only to the hide animation. As we cannot turn off visibility |
| 310 // until the animation is over. | 333 // until the animation is over. |
| 311 animation.AddObserver(this); | 334 animation.AddObserver(this); |
| 312 animation.SetTweenType(gfx::Tween::EASE_IN); | 335 animation.SetTweenType(gfx::Tween::EASE_IN); |
| 313 layer()->SetOpacity(0.0f); | 336 layer()->SetOpacity(0.0f); |
| 314 layer()->SetVisible(false); | 337 layer()->SetVisible(false); |
| 315 HideTransformation(); | 338 HideTransformation(); |
| 316 } | 339 } |
| 340 wm_shelf_->GetStatusAreaWidget()->OnTrayVisibilityChanged(this); |
| 317 } | 341 } |
| 318 | 342 |
| 319 const char* TrayBackgroundView::GetClassName() const { | 343 const char* TrayBackgroundView::GetClassName() const { |
| 320 return kViewClassName; | 344 return kViewClassName; |
| 321 } | 345 } |
| 322 | 346 |
| 323 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { | 347 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { |
| 324 PreferredSizeChanged(); | 348 PreferredSizeChanged(); |
| 325 } | 349 } |
| 326 | 350 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 // Nothing to do here. | 525 // Nothing to do here. |
| 502 } | 526 } |
| 503 | 527 |
| 504 void TrayBackgroundView::UpdateShelfItemBackground(int alpha) { | 528 void TrayBackgroundView::UpdateShelfItemBackground(int alpha) { |
| 505 if (background_) { | 529 if (background_) { |
| 506 background_->set_alpha(alpha); | 530 background_->set_alpha(alpha); |
| 507 SchedulePaint(); | 531 SchedulePaint(); |
| 508 } | 532 } |
| 509 } | 533 } |
| 510 | 534 |
| 535 void TrayBackgroundView::SetSeparatorVisibility(bool is_shown) { |
| 536 is_separator_visible_ = is_shown; |
| 537 SchedulePaint(); |
| 538 } |
| 539 |
| 540 void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) { |
| 541 if (!MaterialDesignController::IsShelfMaterial() || |
| 542 shelf()->GetBackgroundType() == |
| 543 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT || |
| 544 !is_separator_visible_) { |
| 545 return; |
| 546 } |
| 547 // In the given |canvas|, draws a 1x32px separator line 4 pixel to the right |
| 548 // of the TrayBackgroundView. |
| 549 const bool horizontal_shelf = IsHorizontalAlignment(shelf_alignment_); |
| 550 const gfx::Rect local_bounds = GetLocalBounds(); |
| 551 const int height = kTrayItemSize; |
| 552 const int width = kSeparatorWidth; |
| 553 const int x = |
| 554 (horizontal_shelf ? local_bounds.width() : local_bounds.height()) - |
| 555 kSeparatorWidth; |
| 556 const int y = (GetShelfConstant(SHELF_SIZE) - kTrayItemSize) / 2; |
| 557 gfx::ScopedCanvas scoped_canvas(canvas); |
| 558 const float scale = canvas->UndoDeviceScaleFactor(); |
| 559 SkPaint paint; |
| 560 paint.setColor(kSeparatorColor); |
| 561 paint.setAntiAlias(true); |
| 562 |
| 563 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height) |
| 564 : gfx::Rect(y, x, height, width); |
| 565 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale)); |
| 566 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(), |
| 567 rect.bottom_right(), paint); |
| 568 } |
| 569 |
| 511 } // namespace ash | 570 } // namespace ash |
| OLD | NEW |