Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: ash/common/wm/workspace/phantom_window_controller.cc

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/common/wm/workspace/phantom_window_controller.h"
6
7 #include <math.h>
8
9 #include "ash/common/wm/root_window_finder.h"
10 #include "ash/common/wm_window.h"
11 #include "ash/public/cpp/shell_window_ids.h"
12 #include "ash/resources/grit/ash_resources.h"
13 #include "ash/root_window_controller.h"
14 #include "ui/compositor/layer.h"
15 #include "ui/compositor/scoped_layer_animation_settings.h"
16 #include "ui/views/background.h"
17 #include "ui/views/painter.h"
18 #include "ui/views/view.h"
19 #include "ui/views/widget/widget.h"
20
21 namespace ash {
22 namespace {
23
24 // The duration of the show animation.
25 const int kAnimationDurationMs = 200;
26
27 // The size of the phantom window at the beginning of the show animation in
28 // relation to the size of the phantom window at the end of the animation.
29 const float kStartBoundsRatio = 0.85f;
30
31 // The amount of pixels that the phantom window's shadow should extend past
32 // the bounds passed into Show().
33 const int kShadowThickness = 15;
34
35 // The minimum size of a phantom window including the shadow. The minimum size
36 // is derived from the size of the IDR_AURA_PHANTOM_WINDOW image assets.
37 const int kMinSizeWithShadow = 100;
38
39 // Adjusts the phantom window's bounds so that the bounds:
40 // - Include the size of the shadow.
41 // - Have a size equal to or larger than the minimum phantom window size.
42 gfx::Rect GetAdjustedBounds(const gfx::Rect& bounds) {
43 int x_inset = std::max(
44 static_cast<int>(ceil((kMinSizeWithShadow - bounds.width()) / 2.0f)),
45 kShadowThickness);
46 int y_inset = std::max(
47 static_cast<int>(ceil((kMinSizeWithShadow - bounds.height()) / 2.0f)),
48 kShadowThickness);
49
50 gfx::Rect adjusted_bounds(bounds);
51 adjusted_bounds.Inset(-x_inset, -y_inset);
52 return adjusted_bounds;
53 }
54
55 // Starts an animation of |widget| to |new_bounds_in_screen|. No-op if |widget|
56 // is NULL.
57 void AnimateToBounds(views::Widget* widget,
58 const gfx::Rect& new_bounds_in_screen) {
59 if (!widget)
60 return;
61
62 ui::ScopedLayerAnimationSettings scoped_setter(
63 WmWindow::Get(widget->GetNativeWindow())->GetLayer()->GetAnimator());
64 scoped_setter.SetTweenType(gfx::Tween::EASE_IN);
65 scoped_setter.SetPreemptionStrategy(
66 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
67 scoped_setter.SetTransitionDuration(
68 base::TimeDelta::FromMilliseconds(kAnimationDurationMs));
69 widget->SetBounds(new_bounds_in_screen);
70 }
71
72 } // namespace
73
74 // PhantomWindowController ----------------------------------------------------
75
76 PhantomWindowController::PhantomWindowController(WmWindow* window)
77 : window_(window) {}
78
79 PhantomWindowController::~PhantomWindowController() {}
80
81 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) {
82 gfx::Rect adjusted_bounds_in_screen = GetAdjustedBounds(bounds_in_screen);
83 if (adjusted_bounds_in_screen == target_bounds_in_screen_)
84 return;
85 target_bounds_in_screen_ = adjusted_bounds_in_screen;
86
87 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_;
88 int start_width = std::max(
89 kMinSizeWithShadow,
90 static_cast<int>(start_bounds_in_screen.width() * kStartBoundsRatio));
91 int start_height = std::max(
92 kMinSizeWithShadow,
93 static_cast<int>(start_bounds_in_screen.height() * kStartBoundsRatio));
94 start_bounds_in_screen.Inset(
95 floor((start_bounds_in_screen.width() - start_width) / 2.0f),
96 floor((start_bounds_in_screen.height() - start_height) / 2.0f));
97 phantom_widget_ =
98 CreatePhantomWidget(wm::GetRootWindowMatching(target_bounds_in_screen_),
99 start_bounds_in_screen);
100
101 AnimateToBounds(phantom_widget_.get(), target_bounds_in_screen_);
102 }
103
104 std::unique_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget(
105 WmWindow* root_window,
106 const gfx::Rect& bounds_in_screen) {
107 std::unique_ptr<views::Widget> phantom_widget(new views::Widget);
108 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
109 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
110 // PhantomWindowController is used by FrameMaximizeButton to highlight the
111 // launcher button. Put the phantom in the same window as the launcher so that
112 // the phantom is visible.
113 params.keep_on_top = true;
114 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
115 params.name = "PhantomWindow";
116 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer(
117 phantom_widget.get(), kShellWindowId_ShelfContainer, &params);
118 phantom_widget->set_focus_on_creation(false);
119 phantom_widget->Init(params);
120 phantom_widget->SetVisibilityChangedAnimationsEnabled(false);
121 WmWindow* phantom_widget_window =
122 WmWindow::Get(phantom_widget->GetNativeWindow());
123 phantom_widget_window->SetShellWindowId(kShellWindowId_PhantomWindow);
124 phantom_widget->SetBounds(bounds_in_screen);
125 // TODO(sky): I suspect this is never true, verify that.
126 if (phantom_widget_window->GetParent() == window_->GetParent()) {
127 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window,
128 window_);
129 }
130
131 const int kImages[] = IMAGE_GRID(IDR_AURA_PHANTOM_WINDOW);
132 views::View* content_view = new views::View;
133 content_view->set_background(views::Background::CreateBackgroundPainter(
134 views::Painter::CreateImageGridPainter(kImages)));
135 phantom_widget->SetContentsView(content_view);
136
137 // Show the widget after all the setups.
138 phantom_widget->Show();
139
140 // Fade the window in.
141 ui::Layer* widget_layer = phantom_widget_window->GetLayer();
142 widget_layer->SetOpacity(0);
143 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator());
144 scoped_setter.SetTransitionDuration(
145 base::TimeDelta::FromMilliseconds(kAnimationDurationMs));
146 widget_layer->SetOpacity(1);
147
148 return phantom_widget;
149 }
150
151 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/workspace/phantom_window_controller.h ('k') | ash/common/wm/workspace/two_step_edge_cycler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698