Chromium Code Reviews| 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" |
| 28 #include "ui/gfx/image/image_skia.h" | 29 #include "ui/gfx/image/image_skia.h" |
| 29 #include "ui/gfx/image/image_skia_operations.h" | 30 #include "ui/gfx/image/image_skia_operations.h" |
| 30 #include "ui/gfx/nine_image_painter.h" | 31 #include "ui/gfx/nine_image_painter.h" |
| 32 #include "ui/gfx/scoped_canvas.h" | |
| 31 #include "ui/gfx/skia_util.h" | 33 #include "ui/gfx/skia_util.h" |
| 32 #include "ui/gfx/transform.h" | 34 #include "ui/gfx/transform.h" |
| 33 #include "ui/views/background.h" | 35 #include "ui/views/background.h" |
| 34 #include "ui/views/layout/box_layout.h" | 36 #include "ui/views/layout/box_layout.h" |
| 35 #include "ui/wm/core/window_animations.h" | 37 #include "ui/wm/core/window_animations.h" |
| 36 | 38 |
| 37 namespace { | 39 namespace { |
| 38 | 40 |
| 39 const int kAnimationDurationForPopupMs = 200; | 41 const int kAnimationDurationForPopupMs = 200; |
| 40 | 42 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 | 96 |
| 95 void set_alpha(int alpha) { alpha_ = alpha; } | 97 void set_alpha(int alpha) { alpha_ = alpha; } |
| 96 | 98 |
| 97 private: | 99 private: |
| 98 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } | 100 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } |
| 99 | 101 |
| 100 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { | 102 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { |
| 101 SkPaint background_paint; | 103 SkPaint background_paint; |
| 102 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | 104 background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 103 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); | 105 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); |
| 104 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, | 106 canvas->DrawRoundRect(view->GetContentsBounds(), kTrayRoundedBorderRadius, |
| 105 background_paint); | 107 background_paint); |
| 106 | 108 |
| 107 if (tray_background_view_->draw_background_as_active()) { | 109 if (tray_background_view_->draw_background_as_active()) { |
| 108 SkPaint highlight_paint; | 110 SkPaint highlight_paint; |
| 109 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); | 111 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 110 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); | 112 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); |
| 111 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, | 113 canvas->DrawRoundRect(view->GetContentsBounds(), kTrayRoundedBorderRadius, |
| 112 highlight_paint); | 114 highlight_paint); |
| 113 } | 115 } |
| 114 } | 116 } |
| 115 | 117 |
| 116 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const { | 118 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const { |
| 117 const int kGridSizeForPainter = 9; | 119 const int kGridSizeForPainter = 9; |
| 118 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = { | 120 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = { |
| 119 { | 121 { |
| 120 // Horizontal | 122 // Horizontal |
| 121 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ), | 123 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ), |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 PreferredSizeChanged(); | 197 PreferredSizeChanged(); |
| 196 } | 198 } |
| 197 | 199 |
| 198 void TrayBackgroundView::TrayContainer::UpdateLayout() { | 200 void TrayBackgroundView::TrayContainer::UpdateLayout() { |
| 199 // Adjust the size of status tray dark background by adding additional | 201 // Adjust the size of status tray dark background by adding additional |
| 200 // empty border. | 202 // empty border. |
| 201 views::BoxLayout::Orientation orientation = | 203 views::BoxLayout::Orientation orientation = |
| 202 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal | 204 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal |
| 203 : views::BoxLayout::kVertical; | 205 : views::BoxLayout::kVertical; |
| 204 | 206 |
| 205 if (!ash::MaterialDesignController::IsShelfMaterial()) { | |
| 206 // Additional padding used to adjust the user-visible size of status tray | |
| 207 // dark background. | |
| 208 const int padding = 3; | |
| 209 SetBorder( | |
| 210 views::Border::CreateEmptyBorder(padding, padding, padding, padding)); | |
| 211 } | |
| 212 | |
| 213 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); | 207 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); |
| 214 layout->SetDefaultFlex(1); | 208 layout->SetDefaultFlex(1); |
| 215 views::View::SetLayoutManager(layout); | 209 views::View::SetLayoutManager(layout); |
| 216 PreferredSizeChanged(); | 210 PreferredSizeChanged(); |
| 217 } | 211 } |
| 218 | 212 |
| 219 //////////////////////////////////////////////////////////////////////////////// | 213 //////////////////////////////////////////////////////////////////////////////// |
| 220 // TrayBackgroundView | 214 // TrayBackgroundView |
| 221 | 215 |
| 222 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf) | 216 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf) |
| 223 : wm_shelf_(wm_shelf), | 217 : wm_shelf_(wm_shelf), |
| 224 tray_container_(NULL), | 218 tray_container_(NULL), |
| 225 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), | 219 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
| 226 background_(NULL), | 220 background_(NULL), |
| 227 draw_background_as_active_(false), | 221 draw_background_as_active_(false), |
| 228 widget_observer_(new TrayWidgetObserver(this)) { | 222 widget_observer_(new TrayWidgetObserver(this)) { |
| 229 DCHECK(wm_shelf_); | 223 DCHECK(wm_shelf_); |
| 230 set_notify_enter_exit_on_child(true); | 224 set_notify_enter_exit_on_child(true); |
| 231 | 225 |
| 232 tray_container_ = new TrayContainer(shelf_alignment_); | 226 tray_container_ = new TrayContainer(shelf_alignment_); |
| 233 SetContents(tray_container_); | 227 SetContents(tray_container_); |
| 234 tray_event_filter_.reset(new TrayEventFilter); | 228 tray_event_filter_.reset(new TrayEventFilter); |
| 229 is_separator_visible_ = false; | |
|
James Cook
2016/08/11 20:36:55
can this be initialized in the member list above?
yiyix
2016/08/18 00:43:00
Done.
| |
| 235 | 230 |
| 236 SetPaintToLayer(true); | 231 SetPaintToLayer(true); |
| 237 layer()->SetFillsBoundsOpaquely(false); | 232 layer()->SetFillsBoundsOpaquely(false); |
| 238 // Start the tray items not visible, because visibility changes are animated. | 233 // Start the tray items not visible, because visibility changes are animated. |
| 239 views::View::SetVisible(false); | 234 views::View::SetVisible(false); |
| 235 CalculateAndSetTrayContainerBorder(); | |
| 240 } | 236 } |
| 241 | 237 |
| 242 TrayBackgroundView::~TrayBackgroundView() { | 238 TrayBackgroundView::~TrayBackgroundView() { |
| 243 if (GetWidget()) | 239 if (GetWidget()) |
| 244 GetWidget()->RemoveObserver(widget_observer_.get()); | 240 GetWidget()->RemoveObserver(widget_observer_.get()); |
| 245 StopObservingImplicitAnimations(); | 241 StopObservingImplicitAnimations(); |
| 246 } | 242 } |
| 247 | 243 |
| 248 void TrayBackgroundView::Initialize() { | 244 void TrayBackgroundView::Initialize() { |
| 249 GetWidget()->AddObserver(widget_observer_.get()); | 245 GetWidget()->AddObserver(widget_observer_.get()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 layer()->SetTransform(transform); | 297 layer()->SetTransform(transform); |
| 302 } else { | 298 } else { |
| 303 // Listen only to the hide animation. As we cannot turn off visibility | 299 // Listen only to the hide animation. As we cannot turn off visibility |
| 304 // until the animation is over. | 300 // until the animation is over. |
| 305 animation.AddObserver(this); | 301 animation.AddObserver(this); |
| 306 animation.SetTweenType(gfx::Tween::EASE_IN); | 302 animation.SetTweenType(gfx::Tween::EASE_IN); |
| 307 layer()->SetOpacity(0.0f); | 303 layer()->SetOpacity(0.0f); |
| 308 layer()->SetVisible(false); | 304 layer()->SetVisible(false); |
| 309 HideTransformation(); | 305 HideTransformation(); |
| 310 } | 306 } |
| 307 // OnTrayVisibilityChanged will only be called if the visibility of the tray | |
|
James Cook
2016/08/11 20:36:55
Is this still true? I don't understand what you're
yiyix
2016/08/18 00:43:00
If the visibility is the same as before, then if s
| |
| 308 // item is changed. | |
| 309 wm_shelf_->GetStatusAreaWidget()->OnTrayVisibilityChanged(this); | |
| 311 } | 310 } |
| 312 | 311 |
| 313 const char* TrayBackgroundView::GetClassName() const { | 312 const char* TrayBackgroundView::GetClassName() const { |
| 314 return kViewClassName; | 313 return kViewClassName; |
| 315 } | 314 } |
| 316 | 315 |
| 317 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { | 316 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { |
| 318 PreferredSizeChanged(); | 317 PreferredSizeChanged(); |
| 319 } | 318 } |
| 320 | 319 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 354 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 356 AddChildView(contents); | 355 AddChildView(contents); |
| 357 } | 356 } |
| 358 void TrayBackgroundView::SetContentsBackground() { | 357 void TrayBackgroundView::SetContentsBackground() { |
| 359 background_ = new TrayBackground(this); | 358 background_ = new TrayBackground(this); |
| 360 tray_container_->set_background(background_); | 359 tray_container_->set_background(background_); |
| 361 } | 360 } |
| 362 | 361 |
| 363 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { | 362 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
| 364 shelf_alignment_ = alignment; | 363 shelf_alignment_ = alignment; |
| 364 CalculateAndSetTrayContainerBorder(); | |
| 365 tray_container_->SetAlignment(alignment); | 365 tray_container_->SetAlignment(alignment); |
| 366 } | 366 } |
| 367 | 367 |
| 368 void TrayBackgroundView::CalculateAndSetTrayContainerBorder() { | |
| 369 if (!MaterialDesignController::IsShelfMaterial()) { | |
| 370 tray_container()->SetBorder(views::Border::NullBorder()); | |
| 371 return; | |
| 372 } | |
| 373 // Extend hit region horizontally or vertically depending on shelf alignment. | |
| 374 const gfx::Insets insets( | |
| 375 IsHorizontalAlignment(shelf()->GetAlignment()) | |
| 376 ? gfx::Insets(0, kHitRegionPadding, 0, | |
| 377 kHitRegionPadding + kSeparatorWidth) | |
| 378 : gfx::Insets(kHitRegionPadding, 0, | |
| 379 kHitRegionPadding + kSeparatorWidth, 0)); | |
| 380 tray_container()->SetBorder(views::Border::CreateEmptyBorder(insets)); | |
| 381 } | |
| 382 | |
| 368 void TrayBackgroundView::OnImplicitAnimationsCompleted() { | 383 void TrayBackgroundView::OnImplicitAnimationsCompleted() { |
| 369 // If there is another animation in the queue, the reverse animation was | 384 // If there is another animation in the queue, the reverse animation was |
| 370 // triggered before the completion of animating to invisible. Do not turn off | 385 // triggered before the completion of animating to invisible. Do not turn off |
| 371 // the visibility so that the next animation may render. The value of | 386 // the visibility so that the next animation may render. The value of |
| 372 // layer()->GetTargetVisibility() can be incorrect if the hide animation was | 387 // layer()->GetTargetVisibility() can be incorrect if the hide animation was |
| 373 // aborted to schedule an animation to become visible. As the new animation | 388 // aborted to schedule an animation to become visible. As the new animation |
| 374 // is not yet added to the queue. crbug.com/374236 | 389 // is not yet added to the queue. crbug.com/374236 |
| 375 if (layer()->GetAnimator()->is_animating() || layer()->GetTargetVisibility()) | 390 if (layer()->GetAnimator()->is_animating() || layer()->GetTargetVisibility()) |
| 376 return; | 391 return; |
| 377 views::View::SetVisible(false); | 392 views::View::SetVisible(false); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 // Nothing to do here. | 510 // Nothing to do here. |
| 496 } | 511 } |
| 497 | 512 |
| 498 void TrayBackgroundView::UpdateShelfItemBackground(int alpha) { | 513 void TrayBackgroundView::UpdateShelfItemBackground(int alpha) { |
| 499 if (background_) { | 514 if (background_) { |
| 500 background_->set_alpha(alpha); | 515 background_->set_alpha(alpha); |
| 501 SchedulePaint(); | 516 SchedulePaint(); |
| 502 } | 517 } |
| 503 } | 518 } |
| 504 | 519 |
| 520 void TrayBackgroundView::SetSeparatorVisibility(bool is_shown) { | |
| 521 is_separator_visible_ = is_shown; | |
| 522 } | |
| 523 | |
| 524 void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) { | |
| 525 if (!MaterialDesignController::IsShelfMaterial() || | |
| 526 shelf()->GetBackgroundType() == | |
| 527 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT || | |
| 528 !is_separator_visible_) { | |
| 529 return; | |
| 530 } | |
| 531 | |
| 532 const int height = kTrayItemSize; | |
| 533 const int width = kSeparatorWidth; | |
| 534 const int x = kTrayItemSize + kHitRegionPadding + kHitRegionPadding; | |
| 535 const int y = (GetShelfConstant(SHELF_SIZE) - kTrayItemSize) / 2; | |
| 536 const float scale = canvas->UndoDeviceScaleFactor(); | |
|
James Cook
2016/08/11 22:39:13
Also, I still think this should go inside the scop
yiyix
2016/08/18 00:43:00
Do you mean change the order of const float scale
| |
| 537 SkPaint paint; | |
| 538 paint.setColor(kSeparatorColor); | |
| 539 paint.setAntiAlias(true); | |
| 540 const bool horizontal_shelf = IsHorizontalAlignment(shelf()->GetAlignment()); | |
| 541 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height) | |
| 542 : gfx::Rect(y, x, height, width); | |
| 543 gfx::ScopedCanvas scoped_canvas(canvas); | |
| 544 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale)); | |
| 545 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(), | |
| 546 rect.bottom_right(), paint); | |
| 547 } | |
| 548 | |
| 505 } // namespace ash | 549 } // namespace ash |
| OLD | NEW |