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" |
| 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 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 | 97 |
| 95 void set_alpha(int alpha) { alpha_ = alpha; } | 98 void set_alpha(int alpha) { alpha_ = alpha; } |
| 96 | 99 |
| 97 private: | 100 private: |
| 98 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } | 101 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } |
| 99 | 102 |
| 100 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { | 103 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { |
| 101 SkPaint background_paint; | 104 SkPaint background_paint; |
| 102 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | 105 background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 103 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); | 106 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); |
| 104 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, | 107 gfx::Rect bounds; |
| 105 background_paint); | 108 |
| 109 // The hit region are padded to the |view| as insets, so they are included | |
| 110 // in the local bounds. Remove these regions from view because hit region is | |
| 111 // invisible. | |
| 112 if (IsHorizontalAlignment(GetShelf()->GetAlignment())) { | |
| 113 bounds = gfx::Rect(view->GetLocalBounds().x() + kHitRegionPadding, | |
|
James Cook
2016/08/19 00:55:50
nit: cache the result of view->GetLocalBounds() in
yiyix
2016/08/19 19:07:56
Thanks! After i finally get it working after many
| |
| 114 view->GetLocalBounds().y(), | |
| 115 view->GetLocalBounds().width() - kHitRegionPadding - | |
| 116 kHitRegionPadding - kSeparatorWidth, | |
| 117 view->GetLocalBounds().height()); | |
| 118 } else { | |
| 119 bounds = gfx::Rect(view->GetLocalBounds().x(), | |
| 120 view->GetLocalBounds().y() + kHitRegionPadding, | |
| 121 view->GetLocalBounds().width(), | |
| 122 view->GetLocalBounds().height() - kHitRegionPadding - | |
| 123 kHitRegionPadding - kSeparatorWidth); | |
| 124 } | |
| 125 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, background_paint); | |
| 106 | 126 |
| 107 if (tray_background_view_->draw_background_as_active()) { | 127 if (tray_background_view_->draw_background_as_active()) { |
| 108 SkPaint highlight_paint; | 128 SkPaint highlight_paint; |
| 109 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); | 129 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 110 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); | 130 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); |
| 111 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, | 131 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, highlight_paint); |
| 112 highlight_paint); | |
| 113 } | 132 } |
| 114 } | 133 } |
| 115 | 134 |
| 116 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const { | 135 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const { |
| 117 const int kGridSizeForPainter = 9; | 136 const int kGridSizeForPainter = 9; |
| 118 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = { | 137 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = { |
| 119 { | 138 { |
| 120 // Horizontal | 139 // Horizontal |
| 121 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ), | 140 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ), |
| 122 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_ONBLACK), | 141 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_ONBLACK), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 PreferredSizeChanged(); | 219 PreferredSizeChanged(); |
| 201 } | 220 } |
| 202 | 221 |
| 203 void TrayBackgroundView::TrayContainer::UpdateLayout() { | 222 void TrayBackgroundView::TrayContainer::UpdateLayout() { |
| 204 // Adjust the size of status tray dark background by adding additional | 223 // Adjust the size of status tray dark background by adding additional |
| 205 // empty border. | 224 // empty border. |
| 206 views::BoxLayout::Orientation orientation = | 225 views::BoxLayout::Orientation orientation = |
| 207 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal | 226 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal |
| 208 : views::BoxLayout::kVertical; | 227 : views::BoxLayout::kVertical; |
| 209 | 228 |
| 229 gfx::Insets insets; | |
| 210 if (!ash::MaterialDesignController::IsShelfMaterial()) { | 230 if (!ash::MaterialDesignController::IsShelfMaterial()) { |
| 211 // Additional padding used to adjust the user-visible size of status tray | 231 // Additional padding used to adjust the user-visible size of status tray |
| 212 // dark background. | 232 // dark background. |
| 213 const int padding = 3; | 233 const int padding = 3; |
|
varkha
2016/08/19 16:33:39
nit: can you declare the constant in anonymous nam
yiyix
2016/08/19 19:07:56
Done.
| |
| 214 SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(padding) + margin_)); | 234 insets = gfx::Insets(padding); |
| 215 } else { | 235 } else { |
| 216 SetBorder(views::Border::CreateEmptyBorder(margin_)); | 236 // Extend hit region horizontally or vertically depending on shelf |
| 237 // alignment. | |
| 238 insets = | |
| 239 gfx::Insets(IsHorizontalAlignment(alignment_) | |
| 240 ? gfx::Insets(0, kHitRegionPadding, 0, | |
| 241 kHitRegionPadding + kSeparatorWidth) | |
| 242 : gfx::Insets(kHitRegionPadding, 0, | |
| 243 kHitRegionPadding + kSeparatorWidth, 0)); | |
| 217 } | 244 } |
| 218 | 245 SetBorder(views::Border::CreateEmptyBorder(insets + margin_)); |
| 219 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); | 246 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); |
| 220 layout->SetDefaultFlex(1); | 247 layout->SetDefaultFlex(1); |
| 221 views::View::SetLayoutManager(layout); | 248 views::View::SetLayoutManager(layout); |
| 222 PreferredSizeChanged(); | 249 PreferredSizeChanged(); |
| 223 } | 250 } |
| 224 | 251 |
| 225 //////////////////////////////////////////////////////////////////////////////// | 252 //////////////////////////////////////////////////////////////////////////////// |
| 226 // TrayBackgroundView | 253 // TrayBackgroundView |
| 227 | 254 |
| 228 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf) | 255 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf) |
| 229 : wm_shelf_(wm_shelf), | 256 : wm_shelf_(wm_shelf), |
| 230 tray_container_(NULL), | 257 tray_container_(NULL), |
| 231 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), | 258 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
| 232 background_(NULL), | 259 background_(NULL), |
| 233 draw_background_as_active_(false), | 260 draw_background_as_active_(false), |
| 261 is_separator_visible_(false), | |
| 234 widget_observer_(new TrayWidgetObserver(this)) { | 262 widget_observer_(new TrayWidgetObserver(this)) { |
| 235 DCHECK(wm_shelf_); | 263 DCHECK(wm_shelf_); |
| 236 set_notify_enter_exit_on_child(true); | 264 set_notify_enter_exit_on_child(true); |
| 237 | 265 |
| 238 tray_container_ = new TrayContainer(shelf_alignment_); | 266 tray_container_ = new TrayContainer(shelf_alignment_); |
| 239 SetContents(tray_container_); | 267 SetContents(tray_container_); |
| 240 tray_event_filter_.reset(new TrayEventFilter); | 268 tray_event_filter_.reset(new TrayEventFilter); |
| 241 | 269 |
| 242 SetPaintToLayer(true); | 270 SetPaintToLayer(true); |
| 243 layer()->SetFillsBoundsOpaquely(false); | 271 layer()->SetFillsBoundsOpaquely(false); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 layer()->SetTransform(transform); | 335 layer()->SetTransform(transform); |
| 308 } else { | 336 } else { |
| 309 // Listen only to the hide animation. As we cannot turn off visibility | 337 // Listen only to the hide animation. As we cannot turn off visibility |
| 310 // until the animation is over. | 338 // until the animation is over. |
| 311 animation.AddObserver(this); | 339 animation.AddObserver(this); |
| 312 animation.SetTweenType(gfx::Tween::EASE_IN); | 340 animation.SetTweenType(gfx::Tween::EASE_IN); |
| 313 layer()->SetOpacity(0.0f); | 341 layer()->SetOpacity(0.0f); |
| 314 layer()->SetVisible(false); | 342 layer()->SetVisible(false); |
| 315 HideTransformation(); | 343 HideTransformation(); |
| 316 } | 344 } |
| 345 wm_shelf_->GetStatusAreaWidget()->OnTrayVisibilityChanged(this); | |
| 317 } | 346 } |
| 318 | 347 |
| 319 const char* TrayBackgroundView::GetClassName() const { | 348 const char* TrayBackgroundView::GetClassName() const { |
| 320 return kViewClassName; | 349 return kViewClassName; |
| 321 } | 350 } |
| 322 | 351 |
| 323 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { | 352 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { |
| 324 PreferredSizeChanged(); | 353 PreferredSizeChanged(); |
| 325 } | 354 } |
| 326 | 355 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 // Nothing to do here. | 530 // Nothing to do here. |
| 502 } | 531 } |
| 503 | 532 |
| 504 void TrayBackgroundView::UpdateShelfItemBackground(int alpha) { | 533 void TrayBackgroundView::UpdateShelfItemBackground(int alpha) { |
| 505 if (background_) { | 534 if (background_) { |
| 506 background_->set_alpha(alpha); | 535 background_->set_alpha(alpha); |
| 507 SchedulePaint(); | 536 SchedulePaint(); |
| 508 } | 537 } |
| 509 } | 538 } |
| 510 | 539 |
| 540 void TrayBackgroundView::SetSeparatorVisibility(bool is_shown) { | |
| 541 is_separator_visible_ = is_shown; | |
| 542 SchedulePaint(); | |
| 543 } | |
| 544 | |
| 545 void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) { | |
| 546 if (!MaterialDesignController::IsShelfMaterial() || | |
| 547 shelf()->GetBackgroundType() == | |
| 548 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT || | |
| 549 !is_separator_visible_) { | |
| 550 return; | |
| 551 } | |
| 552 // In the given |canvas|, draws a 1x32px separator line 4 pixel to the right | |
| 553 // of the TrayBackgroundView. | |
| 554 const bool horizontal_shelf = IsHorizontalAlignment(shelf()->GetAlignment()); | |
|
James Cook
2016/08/19 00:55:50
I would use IsHorizontalAlignment(shelf_alignment_
yiyix
2016/08/19 19:07:56
Done.
| |
| 555 const int height = kTrayItemSize; | |
| 556 const int width = kSeparatorWidth; | |
| 557 const int x = horizontal_shelf ? GetLocalBounds().width() - kSeparatorWidth | |
| 558 : GetLocalBounds().height() - kSeparatorWidth; | |
|
varkha
2016/08/19 16:33:39
nit: can you shorten code to (pseudocode):
const i
yiyix
2016/08/19 19:07:56
Done.
| |
| 559 const int y = (GetShelfConstant(SHELF_SIZE) - kTrayItemSize) / 2; | |
| 560 gfx::ScopedCanvas scoped_canvas(canvas); | |
| 561 const float scale = canvas->UndoDeviceScaleFactor(); | |
| 562 SkPaint paint; | |
| 563 paint.setColor(kSeparatorColor); | |
| 564 paint.setAntiAlias(true); | |
| 565 | |
| 566 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height) | |
| 567 : gfx::Rect(y, x, height, width); | |
| 568 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale)); | |
| 569 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(), | |
| 570 rect.bottom_right(), paint); | |
| 571 } | |
| 572 | |
| 511 } // namespace ash | 573 } // namespace ash |
| OLD | NEW |