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/system/tray/tray_background_view.h" | 5 #include "ash/system/tray/tray_background_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
| 10 #include "ash/public/cpp/shell_window_ids.h" | 10 #include "ash/public/cpp/shell_window_ids.h" |
| 11 #include "ash/shelf/shelf.h" | 11 #include "ash/shelf/shelf.h" |
| 12 #include "ash/shelf/shelf_constants.h" | 12 #include "ash/shelf/shelf_constants.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/system/status_area_widget_delegate.h" | 14 #include "ash/system/status_area_widget_delegate.h" |
| 15 #include "ash/system/tray/system_tray_notifier.h" | 15 #include "ash/system/tray/system_tray_notifier.h" |
| 16 #include "ash/system/tray/tray_constants.h" | 16 #include "ash/system/tray/tray_constants.h" |
| 17 #include "ash/system/tray/tray_container.h" | 17 #include "ash/system/tray/tray_container.h" |
| 18 #include "ash/system/tray/tray_event_filter.h" | 18 #include "ash/system/tray/tray_event_filter.h" |
| 19 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
| 19 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 20 #include "ui/accessibility/ax_node_data.h" | 21 #include "ui/accessibility/ax_node_data.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/gfx/animation/tween.h" | 25 #include "ui/gfx/animation/tween.h" |
| 25 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
| 26 #include "ui/gfx/geometry/rect.h" | 27 #include "ui/gfx/geometry/rect.h" |
| 27 #include "ui/gfx/geometry/size.h" | 28 #include "ui/gfx/geometry/size.h" |
| 28 #include "ui/gfx/transform.h" | 29 #include "ui/gfx/transform.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 } | 124 } |
| 124 | 125 |
| 125 // Reference to the TrayBackgroundView for which this is a background. | 126 // Reference to the TrayBackgroundView for which this is a background. |
| 126 TrayBackgroundView* tray_background_view_; | 127 TrayBackgroundView* tray_background_view_; |
| 127 | 128 |
| 128 SkColor color_; | 129 SkColor color_; |
| 129 | 130 |
| 130 DISALLOW_COPY_AND_ASSIGN(TrayBackground); | 131 DISALLOW_COPY_AND_ASSIGN(TrayBackground); |
| 131 }; | 132 }; |
| 132 | 133 |
| 134 // CloseBubbleObserver is used to delay closing the tray bubbles until the | |
| 135 // animation completes. | |
| 136 class CloseBubbleObserver : public ui::ImplicitAnimationObserver { | |
| 137 public: | |
| 138 explicit CloseBubbleObserver(TrayBackgroundView* tray_background_view) | |
| 139 : tray_background_view_(tray_background_view) {} | |
| 140 | |
| 141 ~CloseBubbleObserver() override {} | |
| 142 | |
| 143 void OnImplicitAnimationsCompleted() override { | |
| 144 tray_background_view_->CloseBubble(); | |
| 145 delete this; | |
| 146 } | |
| 147 | |
| 148 private: | |
| 149 TrayBackgroundView* tray_background_view_ = nullptr; | |
| 150 | |
| 151 DISALLOW_COPY_AND_ASSIGN(CloseBubbleObserver); | |
| 152 }; | |
| 153 | |
| 133 //////////////////////////////////////////////////////////////////////////////// | 154 //////////////////////////////////////////////////////////////////////////////// |
| 134 // TrayBackgroundView | 155 // TrayBackgroundView |
| 135 | 156 |
| 136 TrayBackgroundView::TrayBackgroundView(Shelf* shelf) | 157 TrayBackgroundView::TrayBackgroundView(Shelf* shelf) |
| 137 // Note the ink drop style is ignored. | 158 // Note the ink drop style is ignored. |
| 138 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), | 159 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), |
| 139 shelf_(shelf), | 160 shelf_(shelf), |
| 140 tray_container_(new TrayContainer(shelf)), | 161 tray_container_(new TrayContainer(shelf)), |
| 141 background_(new TrayBackground(this)), | 162 background_(new TrayBackground(this)), |
| 142 is_active_(false), | 163 is_active_(false), |
| 143 separator_visible_(true), | 164 separator_visible_(true), |
| 144 widget_observer_(new TrayWidgetObserver(this)) { | 165 widget_observer_(new TrayWidgetObserver(this)) { |
| 145 DCHECK(shelf_); | 166 DCHECK(shelf_); |
| 146 set_notify_enter_exit_on_child(true); | 167 set_notify_enter_exit_on_child(true); |
| 147 set_ink_drop_base_color(kShelfInkDropBaseColor); | 168 set_ink_drop_base_color(kShelfInkDropBaseColor); |
| 148 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); | 169 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); |
| 149 | 170 |
| 150 SetLayoutManager(new views::FillLayout); | 171 SetLayoutManager(new views::FillLayout); |
| 151 | 172 |
| 152 tray_container_->SetBackground( | 173 tray_container_->SetBackground( |
| 153 std::unique_ptr<views::Background>(background_)); | 174 std::unique_ptr<views::Background>(background_)); |
| 154 AddChildView(tray_container_); | 175 AddChildView(tray_container_); |
| 155 | 176 |
| 156 tray_event_filter_.reset(new TrayEventFilter); | 177 tray_event_filter_.reset(new TrayEventFilter); |
| 157 | 178 |
| 158 SetPaintToLayer(); | 179 SetPaintToLayer(); |
| 159 layer()->SetFillsBoundsOpaquely(false); | 180 layer()->SetFillsBoundsOpaquely(false); |
| 160 // Start the tray items not visible, because visibility changes are animated. | 181 // Start the tray items not visible, because visibility changes are animated. |
| 161 views::View::SetVisible(false); | 182 views::View::SetVisible(false); |
| 183 | |
| 184 drag_controller_.reset(new TrayDragController(shelf)); | |
|
msw
2017/07/12 05:04:52
nit: use base::MakeUnique
minch1
2017/07/13 19:10:36
Done.
| |
| 162 } | 185 } |
| 163 | 186 |
| 164 TrayBackgroundView::~TrayBackgroundView() { | 187 TrayBackgroundView::~TrayBackgroundView() { |
| 165 if (GetWidget()) | 188 if (GetWidget()) |
| 166 GetWidget()->RemoveObserver(widget_observer_.get()); | 189 GetWidget()->RemoveObserver(widget_observer_.get()); |
| 167 StopObservingImplicitAnimations(); | 190 StopObservingImplicitAnimations(); |
| 168 } | 191 } |
| 169 | 192 |
| 170 void TrayBackgroundView::Initialize() { | 193 void TrayBackgroundView::Initialize() { |
| 171 GetWidget()->AddObserver(widget_observer_.get()); | 194 GetWidget()->AddObserver(widget_observer_.get()); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 const gfx::Vector2dF vector(0, kTrayItemSize); | 322 const gfx::Vector2dF vector(0, kTrayItemSize); |
| 300 canvas->Draw1pxLine(point, point + vector, color); | 323 canvas->Draw1pxLine(point, point + vector, color); |
| 301 } else { | 324 } else { |
| 302 const gfx::PointF point((kShelfSize - kTrayItemSize) / 2, | 325 const gfx::PointF point((kShelfSize - kTrayItemSize) / 2, |
| 303 local_bounds.height() - kSeparatorWidth); | 326 local_bounds.height() - kSeparatorWidth); |
| 304 const gfx::Vector2dF vector(kTrayItemSize, 0); | 327 const gfx::Vector2dF vector(kTrayItemSize, 0); |
| 305 canvas->Draw1pxLine(point, point + vector, color); | 328 canvas->Draw1pxLine(point, point + vector, color); |
| 306 } | 329 } |
| 307 } | 330 } |
| 308 | 331 |
| 332 bool TrayBackgroundView::HasBubble() { | |
| 333 return false; | |
| 334 } | |
| 335 | |
| 336 TrayBubbleView* TrayBackgroundView::GetBubbleView() { | |
| 337 return nullptr; | |
| 338 } | |
| 339 | |
| 309 void TrayBackgroundView::UpdateAfterShelfAlignmentChange() { | 340 void TrayBackgroundView::UpdateAfterShelfAlignmentChange() { |
| 310 tray_container_->UpdateAfterShelfAlignmentChange(); | 341 tray_container_->UpdateAfterShelfAlignmentChange(); |
| 311 | 342 |
| 312 // The tray itself expands to the right and bottom edge of the screen to make | 343 // The tray itself expands to the right and bottom edge of the screen to make |
| 313 // sure clicking on the edges brings up the popup. However, the focus border | 344 // sure clicking on the edges brings up the popup. However, the focus border |
| 314 // should be only around the container. | 345 // should be only around the container. |
| 315 gfx::Rect paint_bounds(GetBackgroundBounds()); | 346 gfx::Rect paint_bounds(GetBackgroundBounds()); |
| 316 paint_bounds.Inset(gfx::Insets(-kFocusBorderThickness)); | 347 paint_bounds.Inset(gfx::Insets(-kFocusBorderThickness)); |
| 317 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | 348 SetFocusPainter(views::Painter::CreateSolidFocusPainter( |
| 318 kFocusBorderColor, kFocusBorderThickness, | 349 kFocusBorderColor, kFocusBorderThickness, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 gfx::Insets tray_bg_insets = GetInsets(); | 416 gfx::Insets tray_bg_insets = GetInsets(); |
| 386 if (GetAnchorAlignment() == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | 417 if (GetAnchorAlignment() == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { |
| 387 return gfx::Insets(-tray_bg_insets.top(), anchor_insets.left(), | 418 return gfx::Insets(-tray_bg_insets.top(), anchor_insets.left(), |
| 388 -tray_bg_insets.bottom(), anchor_insets.right()); | 419 -tray_bg_insets.bottom(), anchor_insets.right()); |
| 389 } else { | 420 } else { |
| 390 return gfx::Insets(anchor_insets.top(), -tray_bg_insets.left(), | 421 return gfx::Insets(anchor_insets.top(), -tray_bg_insets.left(), |
| 391 anchor_insets.bottom(), -tray_bg_insets.right()); | 422 anchor_insets.bottom(), -tray_bg_insets.right()); |
| 392 } | 423 } |
| 393 } | 424 } |
| 394 | 425 |
| 395 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { | 426 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() { |
| 396 return Shell::GetContainer( | 427 aura::Window* container = Shell::GetContainer( |
| 397 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), | 428 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), |
| 398 kShellWindowId_SettingBubbleContainer); | 429 kShellWindowId_SettingBubbleContainer); |
| 430 | |
| 431 if (Shell::Get() | |
| 432 ->maximize_mode_controller() | |
| 433 ->IsMaximizeModeWindowManagerEnabled()) { | |
| 434 if (!clipping_window_.get()) { | |
| 435 clipping_window_.reset(new aura::Window(nullptr)); | |
|
msw
2017/07/12 05:04:51
nit: use base::MakeUnique
minch1
2017/07/13 19:10:36
Done.
| |
| 436 clipping_window_->Init(ui::LAYER_NOT_DRAWN); | |
| 437 clipping_window_->layer()->SetMasksToBounds(true); | |
| 438 container->AddChild(clipping_window_.get()); | |
| 439 clipping_window_->Show(); | |
| 440 } | |
| 441 clipping_window_->SetBounds(shelf_->GetUserWorkAreaBounds()); | |
| 442 return clipping_window_.get(); | |
| 443 } | |
| 444 return container; | |
| 445 } | |
| 446 | |
| 447 void TrayBackgroundView::AnimateToTargetBounds(const gfx::Rect& target_bounds, | |
| 448 bool close_bubble) { | |
| 449 const int kAnimationDurationMS = 200; | |
| 450 | |
| 451 ui::ScopedLayerAnimationSettings settings( | |
| 452 GetBubbleView()->GetWidget()->GetNativeView()->layer()->GetAnimator()); | |
| 453 settings.SetTransitionDuration( | |
| 454 base::TimeDelta::FromMilliseconds(kAnimationDurationMS)); | |
| 455 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
| 456 settings.SetPreemptionStrategy( | |
| 457 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
| 458 if (close_bubble) | |
| 459 settings.AddObserver(new CloseBubbleObserver(this)); | |
| 460 GetBubbleView()->GetWidget()->SetBounds(target_bounds); | |
| 399 } | 461 } |
| 400 | 462 |
| 401 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() | 463 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() |
| 402 const { | 464 const { |
| 403 return base::MakeUnique<views::RoundRectInkDropMask>( | 465 return base::MakeUnique<views::RoundRectInkDropMask>( |
| 404 size(), GetBackgroundInsets(), kTrayRoundedBorderRadius); | 466 size(), GetBackgroundInsets(), kTrayRoundedBorderRadius); |
| 405 } | 467 } |
| 406 | 468 |
| 407 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { | 469 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { |
| 408 if (is_active_) | 470 if (is_active_) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 438 } | 500 } |
| 439 | 501 |
| 440 gfx::Rect TrayBackgroundView::GetBackgroundBounds() const { | 502 gfx::Rect TrayBackgroundView::GetBackgroundBounds() const { |
| 441 gfx::Insets insets = GetBackgroundInsets(); | 503 gfx::Insets insets = GetBackgroundInsets(); |
| 442 gfx::Rect bounds = GetLocalBounds(); | 504 gfx::Rect bounds = GetLocalBounds(); |
| 443 bounds.Inset(insets); | 505 bounds.Inset(insets); |
| 444 return bounds; | 506 return bounds; |
| 445 } | 507 } |
| 446 | 508 |
| 447 } // namespace ash | 509 } // namespace ash |
| OLD | NEW |