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_ = base::MakeUnique<TrayDragController>(shelf); | |
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 node_data->SetName(GetAccessibleNameForTray()); | 268 node_data->SetName(GetAccessibleNameForTray()); |
246 } | 269 } |
247 | 270 |
248 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { | 271 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { |
249 StatusAreaWidgetDelegate* delegate = | 272 StatusAreaWidgetDelegate* delegate = |
250 StatusAreaWidgetDelegate::GetPrimaryInstance(); | 273 StatusAreaWidgetDelegate::GetPrimaryInstance(); |
251 if (delegate && delegate->ShouldFocusOut(reverse)) | 274 if (delegate && delegate->ShouldFocusOut(reverse)) |
252 Shell::Get()->system_tray_notifier()->NotifyFocusOut(reverse); | 275 Shell::Get()->system_tray_notifier()->NotifyFocusOut(reverse); |
253 } | 276 } |
254 | 277 |
278 void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) { | |
279 if (drag_controller_ && !drag_controller_->ProcessGestureEvent(event, this)) | |
msw
2017/07/17 19:28:01
Change this conditional to run the base impl if th
minch1
2017/07/17 20:41:10
Done.
| |
280 ActionableView::OnGestureEvent(event); | |
281 } | |
282 | |
255 std::unique_ptr<views::InkDropRipple> TrayBackgroundView::CreateInkDropRipple() | 283 std::unique_ptr<views::InkDropRipple> TrayBackgroundView::CreateInkDropRipple() |
256 const { | 284 const { |
257 return base::MakeUnique<views::FloodFillInkDropRipple>( | 285 return base::MakeUnique<views::FloodFillInkDropRipple>( |
258 size(), GetBackgroundInsets(), GetInkDropCenterBasedOnLastEvent(), | 286 size(), GetBackgroundInsets(), GetInkDropCenterBasedOnLastEvent(), |
259 GetInkDropBaseColor(), ink_drop_visible_opacity()); | 287 GetInkDropBaseColor(), ink_drop_visible_opacity()); |
260 } | 288 } |
261 | 289 |
262 std::unique_ptr<views::InkDropHighlight> | 290 std::unique_ptr<views::InkDropHighlight> |
263 TrayBackgroundView::CreateInkDropHighlight() const { | 291 TrayBackgroundView::CreateInkDropHighlight() const { |
264 gfx::Rect bounds = GetBackgroundBounds(); | 292 gfx::Rect bounds = GetBackgroundBounds(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 const gfx::Vector2dF vector(0, kTrayItemSize); | 327 const gfx::Vector2dF vector(0, kTrayItemSize); |
300 canvas->Draw1pxLine(point, point + vector, color); | 328 canvas->Draw1pxLine(point, point + vector, color); |
301 } else { | 329 } else { |
302 const gfx::PointF point((kShelfSize - kTrayItemSize) / 2, | 330 const gfx::PointF point((kShelfSize - kTrayItemSize) / 2, |
303 local_bounds.height() - kSeparatorWidth); | 331 local_bounds.height() - kSeparatorWidth); |
304 const gfx::Vector2dF vector(kTrayItemSize, 0); | 332 const gfx::Vector2dF vector(kTrayItemSize, 0); |
305 canvas->Draw1pxLine(point, point + vector, color); | 333 canvas->Draw1pxLine(point, point + vector, color); |
306 } | 334 } |
307 } | 335 } |
308 | 336 |
337 bool TrayBackgroundView::ProcessGestureEventForBubble(ui::GestureEvent* event) { | |
338 return drag_controller_->ProcessGestureEvent(event, this); | |
339 } | |
340 | |
341 TrayBubbleView* TrayBackgroundView::GetBubbleView() { | |
342 return nullptr; | |
343 } | |
344 | |
309 void TrayBackgroundView::UpdateAfterShelfAlignmentChange() { | 345 void TrayBackgroundView::UpdateAfterShelfAlignmentChange() { |
310 tray_container_->UpdateAfterShelfAlignmentChange(); | 346 tray_container_->UpdateAfterShelfAlignmentChange(); |
311 | 347 |
312 // The tray itself expands to the right and bottom edge of the screen to make | 348 // 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 | 349 // sure clicking on the edges brings up the popup. However, the focus border |
314 // should be only around the container. | 350 // should be only around the container. |
315 gfx::Rect paint_bounds(GetBackgroundBounds()); | 351 gfx::Rect paint_bounds(GetBackgroundBounds()); |
316 paint_bounds.Inset(gfx::Insets(-kFocusBorderThickness)); | 352 paint_bounds.Inset(gfx::Insets(-kFocusBorderThickness)); |
317 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | 353 SetFocusPainter(views::Painter::CreateSolidFocusPainter( |
318 kFocusBorderColor, kFocusBorderThickness, | 354 kFocusBorderColor, kFocusBorderThickness, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 gfx::Insets tray_bg_insets = GetInsets(); | 421 gfx::Insets tray_bg_insets = GetInsets(); |
386 if (GetAnchorAlignment() == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | 422 if (GetAnchorAlignment() == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { |
387 return gfx::Insets(-tray_bg_insets.top(), anchor_insets.left(), | 423 return gfx::Insets(-tray_bg_insets.top(), anchor_insets.left(), |
388 -tray_bg_insets.bottom(), anchor_insets.right()); | 424 -tray_bg_insets.bottom(), anchor_insets.right()); |
389 } else { | 425 } else { |
390 return gfx::Insets(anchor_insets.top(), -tray_bg_insets.left(), | 426 return gfx::Insets(anchor_insets.top(), -tray_bg_insets.left(), |
391 anchor_insets.bottom(), -tray_bg_insets.right()); | 427 anchor_insets.bottom(), -tray_bg_insets.right()); |
392 } | 428 } |
393 } | 429 } |
394 | 430 |
395 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { | 431 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() { |
396 return Shell::GetContainer( | 432 aura::Window* container = Shell::GetContainer( |
397 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), | 433 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), |
398 kShellWindowId_SettingBubbleContainer); | 434 kShellWindowId_SettingBubbleContainer); |
435 | |
436 // Place the bubble in |container|, or in a window clipped to the work area | |
437 // in maximize mode, to avoid tray bubble and shelf overlap. | |
438 if (Shell::Get() | |
439 ->maximize_mode_controller() | |
440 ->IsMaximizeModeWindowManagerEnabled()) { | |
441 if (!clipping_window_.get()) { | |
442 clipping_window_ = base::MakeUnique<aura::Window>(nullptr); | |
443 clipping_window_->Init(ui::LAYER_NOT_DRAWN); | |
444 clipping_window_->layer()->SetMasksToBounds(true); | |
445 container->AddChild(clipping_window_.get()); | |
446 clipping_window_->Show(); | |
447 } | |
448 clipping_window_->SetBounds(shelf_->GetUserWorkAreaBounds()); | |
449 return clipping_window_.get(); | |
450 } | |
451 return container; | |
452 } | |
453 | |
454 void TrayBackgroundView::AnimateToTargetBounds(const gfx::Rect& target_bounds, | |
455 bool close_bubble) { | |
456 const int kAnimationDurationMS = 200; | |
457 | |
458 ui::ScopedLayerAnimationSettings settings( | |
459 GetBubbleView()->GetWidget()->GetNativeView()->layer()->GetAnimator()); | |
460 settings.SetTransitionDuration( | |
461 base::TimeDelta::FromMilliseconds(kAnimationDurationMS)); | |
462 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
463 settings.SetPreemptionStrategy( | |
464 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
465 if (close_bubble) | |
466 settings.AddObserver(new CloseBubbleObserver(this)); | |
467 GetBubbleView()->GetWidget()->SetBounds(target_bounds); | |
399 } | 468 } |
400 | 469 |
401 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() | 470 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() |
402 const { | 471 const { |
403 return base::MakeUnique<views::RoundRectInkDropMask>( | 472 return base::MakeUnique<views::RoundRectInkDropMask>( |
404 size(), GetBackgroundInsets(), kTrayRoundedBorderRadius); | 473 size(), GetBackgroundInsets(), kTrayRoundedBorderRadius); |
405 } | 474 } |
406 | 475 |
407 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { | 476 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { |
408 if (is_active_) | 477 if (is_active_) |
(...skipping 29 matching lines...) Expand all Loading... | |
438 } | 507 } |
439 | 508 |
440 gfx::Rect TrayBackgroundView::GetBackgroundBounds() const { | 509 gfx::Rect TrayBackgroundView::GetBackgroundBounds() const { |
441 gfx::Insets insets = GetBackgroundInsets(); | 510 gfx::Insets insets = GetBackgroundInsets(); |
442 gfx::Rect bounds = GetLocalBounds(); | 511 gfx::Rect bounds = GetLocalBounds(); |
443 bounds.Inset(insets); | 512 bounds.Inset(insets); |
444 return bounds; | 513 return bounds; |
445 } | 514 } |
446 | 515 |
447 } // namespace ash | 516 } // namespace ash |
OLD | NEW |